chore(gdb): unify value init with Value.normalize and ValueInput type alias (#9784)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled

This commit is contained in:
Benign X
2026-03-02 14:50:39 +08:00
committed by GitHub
parent 9e08caf1cb
commit 9be625b9ec
13 changed files with 86 additions and 104 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
from .value import Value from .value import Value, ValueInput
from .lvgl import ( from .lvgl import (
curr_inst, curr_inst,
LVDisplay, LVDisplay,
@@ -44,6 +44,7 @@ __all__ = [
"decode_selector", "decode_selector",
"format_style_value", "format_style_value",
"Value", "Value",
"ValueInput",
"LVCacheEntry", "LVCacheEntry",
"LVCacheLRURB", "LVCacheLRURB",
"LVCacheLRURBIterator", "LVCacheLRURBIterator",
+1 -2
View File
@@ -3,7 +3,6 @@ import gdb
from lvglgdb.lvgl import curr_inst from lvglgdb.lvgl import curr_inst
from lvglgdb.lvgl import LVObject, dump_obj_info from lvglgdb.lvgl import LVObject, dump_obj_info
from lvglgdb.value import Value
class DumpObj(gdb.Command): class DumpObj(gdb.Command):
@@ -52,7 +51,7 @@ class DumpObj(gdb.Command):
if args.root: if args.root:
root = gdb.parse_and_eval(args.root) root = gdb.parse_and_eval(args.root)
root = LVObject(Value(root)) root = LVObject(root)
self.dump_obj(root, limit=args.level) self.dump_obj(root, limit=args.level)
else: else:
# dump all displays # dump all displays
+2 -3
View File
@@ -1,7 +1,6 @@
import argparse import argparse
import gdb import gdb
from lvglgdb.value import Value
from lvglgdb.lvgl import LVStyle, dump_obj_styles from lvglgdb.lvgl import LVStyle, dump_obj_styles
@@ -38,12 +37,12 @@ class InfoStyle(gdb.Command):
if not obj: if not obj:
print("Invalid obj:", args.obj) print("Invalid obj:", args.obj)
return return
dump_obj_styles(Value(obj)) dump_obj_styles(obj)
elif args.style: elif args.style:
style = gdb.parse_and_eval(args.style) style = gdb.parse_and_eval(args.style)
if not style: if not style:
print("Invalid style:", args.style) print("Invalid style:", args.style)
return return
LVStyle(Value(style)).print_entries() LVStyle(style).print_entries()
else: else:
print("Usage: info style <style_var> or info style --obj <obj_var>") print("Usage: info style <style_var> or info style --obj <obj_var>")
+5 -5
View File
@@ -1,4 +1,4 @@
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
from lvglgdb.lvgl.misc.lv_style import LVStyle, StyleEntry, decode_selector from lvglgdb.lvgl.misc.lv_style import LVStyle, StyleEntry, decode_selector
@@ -29,8 +29,8 @@ class ObjStyle:
class LVObject(Value): class LVObject(Value):
"""LVGL object""" """LVGL object"""
def __init__(self, obj: Value): def __init__(self, obj: ValueInput):
super().__init__(obj.cast("lv_obj_t", ptr=True)) super().__init__(Value.normalize(obj, "lv_obj_t"))
@property @property
def class_name(self): def class_name(self):
@@ -102,9 +102,9 @@ def dump_obj_info(obj: LVObject):
print(f"{clzname}@{hex(obj)} {coords}") print(f"{clzname}@{hex(obj)} {coords}")
def dump_obj_styles(obj: Value): def dump_obj_styles(obj: ValueInput):
"""Print all styles of an object, reusing LVStyle.print_entries().""" """Print all styles of an object, reusing LVStyle.print_entries()."""
lv_obj = LVObject(Value(obj)) lv_obj = LVObject(obj)
has_any = False has_any = False
for obj_style in lv_obj.obj_styles: for obj_style in lv_obj.obj_styles:
@@ -1,13 +1,13 @@
from ..core.lv_obj import LVObject from ..core.lv_obj import LVObject
from ..draw.lv_draw_buf import LVDrawBuf from ..draw.lv_draw_buf import LVDrawBuf
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
class LVDisplay(Value): class LVDisplay(Value):
"""LVGL display""" """LVGL display"""
def __init__(self, disp: Value): def __init__(self, disp: ValueInput):
super().__init__(disp) super().__init__(Value.normalize(disp, "lv_display_t"))
@property @property
def hor_res(self) -> int: def hor_res(self) -> int:
+3 -3
View File
@@ -5,7 +5,7 @@ import gdb
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
class LVDrawBuf(Value): class LVDrawBuf(Value):
@@ -25,8 +25,8 @@ class LVDrawBuf(Value):
"XRGB8888": 32, "XRGB8888": 32,
} }
def __init__(self, draw_buf: Value): def __init__(self, draw_buf: ValueInput):
super().__init__(draw_buf) super().__init__(Value.normalize(draw_buf, "lv_draw_buf_t"))
self._init_color_formats() self._init_color_formats()
def _init_color_formats(self): def _init_color_formats(self):
+4 -19
View File
@@ -1,34 +1,21 @@
from typing import Union, List, Optional, Dict from typing import Union, List, Optional, Dict
import gdb import gdb
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
from .lv_cache_iter_factory import create_cache_iterator from .lv_cache_iter_factory import create_cache_iterator
class LVCache(Value): class LVCache(Value):
"""LVGL cache wrapper - focuses on cache-level operations""" """LVGL cache wrapper - focuses on cache-level operations"""
def __init__( def __init__(self, cache: ValueInput, datatype: Union[gdb.Type, str]):
self, cache: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] super().__init__(Value.normalize(cache, "lv_cache_t"))
):
# Convert to Value first if needed
if isinstance(cache, int):
cache = Value(cache).cast("lv_cache_t", ptr=True)
if cache is None:
raise ValueError("Failed to cast pointer to lv_cache_t")
elif isinstance(cache, gdb.Value) and not isinstance(cache, Value):
cache = Value(cache)
elif not cache:
raise ValueError("Invalid cache")
self.datatype = ( self.datatype = (
gdb.lookup_type(datatype).pointer() gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str) if isinstance(datatype, str)
else datatype else datatype
) )
super().__init__(cache)
def print_info(self): def print_info(self):
"""Dump cache information""" """Dump cache information"""
print(f"Cache Info:") print(f"Cache Info:")
@@ -91,9 +78,7 @@ class LVCache(Value):
print(f" ... {cache_entries_cnt - count} more entries not shown") print(f" ... {cache_entries_cnt - count} more entries not shown")
def dump_cache_info( def dump_cache_info(cache: ValueInput, datatype: Union[gdb.Type, str]):
cache: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
"""Dump cache information""" """Dump cache information"""
cache_obj = LVCache(cache, datatype) cache_obj = LVCache(cache, datatype)
cache_obj.print_info() cache_obj.print_info()
@@ -1,37 +1,22 @@
from typing import Union from typing import Union
import gdb import gdb
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
class LVCacheEntry(Value): class LVCacheEntry(Value):
"""LVGL cache entry wrapper - focuses on entry-level operations""" """LVGL cache entry wrapper - focuses on entry-level operations"""
def __init__( def __init__(self, entry: ValueInput, datatype: Union[gdb.Type, str]):
self, entry: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] super().__init__(Value.normalize(entry, "lv_cache_entry_t"))
):
# Convert to Value first if needed
if isinstance(entry, int):
entry = Value(entry).cast("lv_cache_entry_t", ptr=True)
if entry is None:
raise ValueError("Failed to cast pointer to lv_cache_entry_t")
elif isinstance(entry, gdb.Value) and not isinstance(entry, Value):
entry = Value(entry)
elif not entry:
raise ValueError("Invalid cache entry")
self.datatype = ( self.datatype = (
gdb.lookup_type(datatype).pointer() gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str) if isinstance(datatype, str)
else datatype else datatype
) )
super().__init__(entry)
@classmethod @classmethod
def from_data_ptr( def from_data_ptr(cls, data_ptr: ValueInput, datatype: Union[gdb.Type, str]):
cls, data_ptr: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
"""Create LVCacheEntry from data pointer""" """Create LVCacheEntry from data pointer"""
if data_ptr.type == gdb.lookup_type("void").pointer() and datatype is None: if data_ptr.type == gdb.lookup_type("void").pointer() and datatype is None:
@@ -95,9 +80,7 @@ class LVCacheEntry(Value):
return super().__str__() return super().__str__()
def dump_cache_entry_info( def dump_cache_entry_info(entry: ValueInput, datatype: Union[gdb.Type, str]):
entry: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
"""Dump cache entry information""" """Dump cache entry information"""
entry_obj = LVCacheEntry(entry, datatype) entry_obj = LVCacheEntry(entry, datatype)
entry_obj.print_info() entry_obj.print_info()
@@ -1,7 +1,6 @@
from typing import Union, List, Optional
import gdb import gdb
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
from .lv_cache_iter_base import LVCacheIteratorBase from .lv_cache_iter_base import LVCacheIteratorBase
from .lv_rb import LVRedBlackTree from .lv_rb import LVRedBlackTree
from .lv_cache_entry import LVCacheEntry from .lv_cache_entry import LVCacheEntry
@@ -42,18 +41,10 @@ class LVCacheLRURBIterator(LVCacheIteratorBase):
class LVCacheLRURB(LVCache): class LVCacheLRURB(LVCache):
"""LVGL LRU-based cache using red-black tree iterator""" """LVGL LRU-based cache using red-black tree iterator"""
def __init__(self, cache: Union[Value, gdb.Value, int]): def __init__(self, cache: ValueInput):
# Convert to Value first if needed datatype = cache.datatype if isinstance(cache, LVCache) else None
if isinstance(cache, int): super().__init__(cache, datatype)
cache = Value(cache).cast("lv_cache_lru_rb_t", ptr=True) self.cache_base = Value(self)
if cache is None:
raise ValueError("Failed to cast pointer to lv_cache_lru_rb_t")
elif isinstance(cache, gdb.Value) and not isinstance(cache, Value):
cache = Value(cache)
elif not cache:
raise ValueError("Invalid cache")
self.cache_base = cache
super().__init__(cache, cache.datatype)
def print_info(self): def print_info(self):
"""Dump LRU RB cache information""" """Dump LRU RB cache information"""
@@ -98,7 +89,7 @@ class LVCacheLRURB(LVCache):
return entries return entries
def dump_lru_rb_cache_info(cache: Union[Value, gdb.Value, int]): def dump_lru_rb_cache_info(cache: ValueInput):
"""Dump LRU RB cache information""" """Dump LRU RB cache information"""
cache_obj = LVCacheLRURB(cache) cache_obj = LVCacheLRURB(cache)
cache_obj.print_info() cache_obj.print_info()
+3 -5
View File
@@ -1,16 +1,14 @@
from typing import Union from typing import Union
import gdb import gdb
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
class LVList(Value): class LVList(Value):
"""LVGL linked list iterator""" """LVGL linked list iterator"""
def __init__(self, ll: Value, nodetype: Union[gdb.Type, str] = None): def __init__(self, ll: ValueInput, nodetype: Union[gdb.Type, str] = None):
if not ll: super().__init__(Value.normalize(ll, "lv_ll_t"))
raise ValueError("Invalid linked list")
super().__init__(ll)
self.nodetype = ( self.nodetype = (
gdb.lookup_type(nodetype).pointer() gdb.lookup_type(nodetype).pointer()
+4 -19
View File
@@ -1,28 +1,15 @@
from typing import Union from typing import Union
import gdb import gdb
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
class LVRedBlackTree(Value): class LVRedBlackTree(Value):
"""LVGL red-black tree iterator""" """LVGL red-black tree iterator"""
def __init__( def __init__(self, rb: ValueInput, datatype: Union[gdb.Type, str] = None):
self, rb: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] = None super().__init__(Value.normalize(rb, "lv_rb_t"))
):
# Convert to Value first if needed
if isinstance(rb, int):
rb = Value(rb).cast("lv_rb_t", ptr=True)
if rb is None:
raise ValueError("Failed to cast pointer to lv_rb_t")
elif isinstance(rb, gdb.Value) and not isinstance(rb, Value):
rb = Value(rb)
elif not rb:
raise ValueError("Invalid red-black tree")
super().__init__(rb)
self.lv_rb_node_t = gdb.lookup_type("lv_rb_node_t").pointer() self.lv_rb_node_t = gdb.lookup_type("lv_rb_node_t").pointer()
self.datatype = ( self.datatype = (
gdb.lookup_type(datatype).pointer() gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str) if isinstance(datatype, str)
@@ -175,9 +162,7 @@ class LVRedBlackTreeIterator:
return f"LVRedBlackTreeIterator(current=0x{int(current):x})" return f"LVRedBlackTreeIterator(current=0x{int(current):x})"
def dump_rb_info( def dump_rb_info(rb: ValueInput, datatype: Union[gdb.Type, str] = None):
rb: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] = None
):
"""Dump red-black tree information""" """Dump red-black tree information"""
tree = LVRedBlackTree(rb, datatype=datatype) tree = LVRedBlackTree(rb, datatype=datatype)
tree.print_info() tree.print_info()
+3 -7
View File
@@ -3,7 +3,7 @@ from typing import Iterator
import gdb import gdb
from prettytable import PrettyTable from prettytable import PrettyTable
from lvglgdb.value import Value from lvglgdb.value import Value, ValueInput
from .lv_style_consts import ( from .lv_style_consts import (
STYLE_PROP_NAMES, STYLE_PROP_NAMES,
PART_NAMES, PART_NAMES,
@@ -74,12 +74,8 @@ class StyleEntry:
class LVStyle(Value): class LVStyle(Value):
"""LVGL style wrapper for lv_style_t.""" """LVGL style wrapper for lv_style_t."""
def __init__(self, style: Value): def __init__(self, style: ValueInput):
# Ensure we always hold a lv_style_t* pointer, like LVObject does super().__init__(Value.normalize(style, "lv_style_t"))
typ = style.type.strip_typedefs()
if typ.code != gdb.TYPE_CODE_PTR:
style = Value(style.address)
super().__init__(style.cast("lv_style_t", ptr=True))
def __iter__(self) -> Iterator[StyleEntry]: def __iter__(self) -> Iterator[StyleEntry]:
prop_cnt = int(self.prop_cnt) prop_cnt = int(self.prop_cnt)
+45
View File
@@ -7,6 +7,47 @@ class Value(gdb.Value):
def __init__(self, value: Union[gdb.Value, "Value"]): def __init__(self, value: Union[gdb.Value, "Value"]):
super().__init__(value) super().__init__(value)
@staticmethod
def normalize(val: "ValueInput", target_type: Optional[str] = None) -> "Value":
"""Normalize input to a typed Value pointer.
Args:
val: Input value - int (address), gdb.Value, or Value instance
target_type: C type name (e.g. "lv_obj_t"). If provided,
result is cast to target_type*
Returns:
Value instance, optionally cast to target_type*
Raises:
ValueError: If target_type lookup fails or cast fails
"""
if isinstance(val, int):
val = gdb.Value(val)
if not isinstance(val, Value):
val = Value(val)
if target_type is not None:
try:
gdb.lookup_type(target_type)
except gdb.error:
raise ValueError(f"Type not found: {target_type}")
typ = val.type.strip_typedefs()
if typ.code != gdb.TYPE_CODE_PTR:
if typ.code in (gdb.TYPE_CODE_INT, gdb.TYPE_CODE_ENUM):
val = Value(val.cast(gdb.lookup_type(target_type).pointer()))
else:
val = Value(val.address)
result = val.cast(target_type, ptr=True)
if result is None:
raise ValueError(f"Failed to cast to {target_type}*")
val = result
return val
def __getitem__(self, key): def __getitem__(self, key):
try: try:
value = super().__getitem__(key) value = super().__getitem__(key)
@@ -61,3 +102,7 @@ class Value(gdb.Value):
pass pass
return f"Value({self.__str__()})" return f"Value({self.__str__()})"
# Type alias for all wrapper class __init__ parameters
ValueInput = Union[int, gdb.Value, Value]