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 (
curr_inst,
LVDisplay,
@@ -44,6 +44,7 @@ __all__ = [
"decode_selector",
"format_style_value",
"Value",
"ValueInput",
"LVCacheEntry",
"LVCacheLRURB",
"LVCacheLRURBIterator",
+1 -2
View File
@@ -3,7 +3,6 @@ import gdb
from lvglgdb.lvgl import curr_inst
from lvglgdb.lvgl import LVObject, dump_obj_info
from lvglgdb.value import Value
class DumpObj(gdb.Command):
@@ -52,7 +51,7 @@ class DumpObj(gdb.Command):
if args.root:
root = gdb.parse_and_eval(args.root)
root = LVObject(Value(root))
root = LVObject(root)
self.dump_obj(root, limit=args.level)
else:
# dump all displays
+2 -3
View File
@@ -1,7 +1,6 @@
import argparse
import gdb
from lvglgdb.value import Value
from lvglgdb.lvgl import LVStyle, dump_obj_styles
@@ -38,12 +37,12 @@ class InfoStyle(gdb.Command):
if not obj:
print("Invalid obj:", args.obj)
return
dump_obj_styles(Value(obj))
dump_obj_styles(obj)
elif args.style:
style = gdb.parse_and_eval(args.style)
if not style:
print("Invalid style:", args.style)
return
LVStyle(Value(style)).print_entries()
LVStyle(style).print_entries()
else:
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
@@ -29,8 +29,8 @@ class ObjStyle:
class LVObject(Value):
"""LVGL object"""
def __init__(self, obj: Value):
super().__init__(obj.cast("lv_obj_t", ptr=True))
def __init__(self, obj: ValueInput):
super().__init__(Value.normalize(obj, "lv_obj_t"))
@property
def class_name(self):
@@ -102,9 +102,9 @@ def dump_obj_info(obj: LVObject):
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()."""
lv_obj = LVObject(Value(obj))
lv_obj = LVObject(obj)
has_any = False
for obj_style in lv_obj.obj_styles:
@@ -1,13 +1,13 @@
from ..core.lv_obj import LVObject
from ..draw.lv_draw_buf import LVDrawBuf
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
class LVDisplay(Value):
"""LVGL display"""
def __init__(self, disp: Value):
super().__init__(disp)
def __init__(self, disp: ValueInput):
super().__init__(Value.normalize(disp, "lv_display_t"))
@property
def hor_res(self) -> int:
+3 -3
View File
@@ -5,7 +5,7 @@ import gdb
import numpy as np
from PIL import Image
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
class LVDrawBuf(Value):
@@ -25,8 +25,8 @@ class LVDrawBuf(Value):
"XRGB8888": 32,
}
def __init__(self, draw_buf: Value):
super().__init__(draw_buf)
def __init__(self, draw_buf: ValueInput):
super().__init__(Value.normalize(draw_buf, "lv_draw_buf_t"))
self._init_color_formats()
def _init_color_formats(self):
+4 -19
View File
@@ -1,34 +1,21 @@
from typing import Union, List, Optional, Dict
import gdb
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
from .lv_cache_iter_factory import create_cache_iterator
class LVCache(Value):
"""LVGL cache wrapper - focuses on cache-level operations"""
def __init__(
self, cache: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
# 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")
def __init__(self, cache: ValueInput, datatype: Union[gdb.Type, str]):
super().__init__(Value.normalize(cache, "lv_cache_t"))
self.datatype = (
gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str)
else datatype
)
super().__init__(cache)
def print_info(self):
"""Dump cache information"""
print(f"Cache Info:")
@@ -91,9 +78,7 @@ class LVCache(Value):
print(f" ... {cache_entries_cnt - count} more entries not shown")
def dump_cache_info(
cache: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
def dump_cache_info(cache: ValueInput, datatype: Union[gdb.Type, str]):
"""Dump cache information"""
cache_obj = LVCache(cache, datatype)
cache_obj.print_info()
@@ -1,37 +1,22 @@
from typing import Union
import gdb
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
class LVCacheEntry(Value):
"""LVGL cache entry wrapper - focuses on entry-level operations"""
def __init__(
self, entry: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
# 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")
def __init__(self, entry: ValueInput, datatype: Union[gdb.Type, str]):
super().__init__(Value.normalize(entry, "lv_cache_entry_t"))
self.datatype = (
gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str)
else datatype
)
super().__init__(entry)
@classmethod
def from_data_ptr(
cls, data_ptr: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
def from_data_ptr(cls, data_ptr: ValueInput, datatype: Union[gdb.Type, str]):
"""Create LVCacheEntry from data pointer"""
if data_ptr.type == gdb.lookup_type("void").pointer() and datatype is None:
@@ -95,9 +80,7 @@ class LVCacheEntry(Value):
return super().__str__()
def dump_cache_entry_info(
entry: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str]
):
def dump_cache_entry_info(entry: ValueInput, datatype: Union[gdb.Type, str]):
"""Dump cache entry information"""
entry_obj = LVCacheEntry(entry, datatype)
entry_obj.print_info()
@@ -1,7 +1,6 @@
from typing import Union, List, Optional
import gdb
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
from .lv_cache_iter_base import LVCacheIteratorBase
from .lv_rb import LVRedBlackTree
from .lv_cache_entry import LVCacheEntry
@@ -42,18 +41,10 @@ class LVCacheLRURBIterator(LVCacheIteratorBase):
class LVCacheLRURB(LVCache):
"""LVGL LRU-based cache using red-black tree iterator"""
def __init__(self, cache: Union[Value, gdb.Value, int]):
# Convert to Value first if needed
if isinstance(cache, int):
cache = Value(cache).cast("lv_cache_lru_rb_t", ptr=True)
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 __init__(self, cache: ValueInput):
datatype = cache.datatype if isinstance(cache, LVCache) else None
super().__init__(cache, datatype)
self.cache_base = Value(self)
def print_info(self):
"""Dump LRU RB cache information"""
@@ -98,7 +89,7 @@ class LVCacheLRURB(LVCache):
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"""
cache_obj = LVCacheLRURB(cache)
cache_obj.print_info()
+3 -5
View File
@@ -1,16 +1,14 @@
from typing import Union
import gdb
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
class LVList(Value):
"""LVGL linked list iterator"""
def __init__(self, ll: Value, nodetype: Union[gdb.Type, str] = None):
if not ll:
raise ValueError("Invalid linked list")
super().__init__(ll)
def __init__(self, ll: ValueInput, nodetype: Union[gdb.Type, str] = None):
super().__init__(Value.normalize(ll, "lv_ll_t"))
self.nodetype = (
gdb.lookup_type(nodetype).pointer()
+4 -19
View File
@@ -1,28 +1,15 @@
from typing import Union
import gdb
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
class LVRedBlackTree(Value):
"""LVGL red-black tree iterator"""
def __init__(
self, rb: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] = None
):
# 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)
def __init__(self, rb: ValueInput, datatype: Union[gdb.Type, str] = None):
super().__init__(Value.normalize(rb, "lv_rb_t"))
self.lv_rb_node_t = gdb.lookup_type("lv_rb_node_t").pointer()
self.datatype = (
gdb.lookup_type(datatype).pointer()
if isinstance(datatype, str)
@@ -175,9 +162,7 @@ class LVRedBlackTreeIterator:
return f"LVRedBlackTreeIterator(current=0x{int(current):x})"
def dump_rb_info(
rb: Union[Value, gdb.Value, int], datatype: Union[gdb.Type, str] = None
):
def dump_rb_info(rb: ValueInput, datatype: Union[gdb.Type, str] = None):
"""Dump red-black tree information"""
tree = LVRedBlackTree(rb, datatype=datatype)
tree.print_info()
+3 -7
View File
@@ -3,7 +3,7 @@ from typing import Iterator
import gdb
from prettytable import PrettyTable
from lvglgdb.value import Value
from lvglgdb.value import Value, ValueInput
from .lv_style_consts import (
STYLE_PROP_NAMES,
PART_NAMES,
@@ -74,12 +74,8 @@ class StyleEntry:
class LVStyle(Value):
"""LVGL style wrapper for lv_style_t."""
def __init__(self, style: Value):
# Ensure we always hold a lv_style_t* pointer, like LVObject does
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 __init__(self, style: ValueInput):
super().__init__(Value.normalize(style, "lv_style_t"))
def __iter__(self) -> Iterator[StyleEntry]:
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"]):
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):
try:
value = super().__getitem__(key)
@@ -61,3 +102,7 @@ class Value(gdb.Value):
pass
return f"Value({self.__str__()})"
# Type alias for all wrapper class __init__ parameters
ValueInput = Union[int, gdb.Value, Value]