From 64e78045741c2bb695f79faaf2ae1f53df9fba33 Mon Sep 17 00:00:00 2001 From: Benign X <1341398182@qq.com> Date: Fri, 6 Mar 2026 14:36:20 +0800 Subject: [PATCH] chore(gdb): fix coord type mask, cast safety and dedup parse_enum --- docs/src/debugging/gdb_plugin.rst | 13 +++++++++++++ scripts/gdb/lvglgdb/cmds/draw/lv_draw.py | 9 ++++----- scripts/gdb/lvglgdb/lvgl/misc/lv_anim.py | 6 +++--- scripts/gdb/lvglgdb/lvgl/misc/lv_utils.py | 18 +++++++++++++----- scripts/gdb/scripts/gen_draw_consts.py | 3 +++ scripts/gdb/scripts/gen_subject_consts.py | 1 - 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/docs/src/debugging/gdb_plugin.rst b/docs/src/debugging/gdb_plugin.rst index 95cf8ca53b..9025775241 100644 --- a/docs/src/debugging/gdb_plugin.rst +++ b/docs/src/debugging/gdb_plugin.rst @@ -200,9 +200,22 @@ Inspect Object Class Example: +.. code-block:: none + + (gdb) info obj_class lv_button_class + ObjClass: lv_button -> lv_obj -> lv_obj + size=... editable=0 group_def=2 + default_size=(CONTENT, CONTENT) theme_inheritable=True + Inspect Subject *************** ``info subject ``: Show a subject's type and all its observers. Example: + +.. code-block:: none + + (gdb) info subject &my_subject + Subject: type=INT subscribers=2 + Observer: cb=0x... target=0x... for_obj=True diff --git a/scripts/gdb/lvglgdb/cmds/draw/lv_draw.py b/scripts/gdb/lvglgdb/cmds/draw/lv_draw.py index 3342fb8a59..787c1f4639 100644 --- a/scripts/gdb/lvglgdb/cmds/draw/lv_draw.py +++ b/scripts/gdb/lvglgdb/cmds/draw/lv_draw.py @@ -27,8 +27,7 @@ class InfoDrawUnit(gdb.Command): except gdb.error: target_type = gdb.lookup_type("lv_draw_unit_t") - print( - unit.cast(target_type, ptr=True) - .dereference() - .format_string(pretty_structs=True, symbols=True) - ) + casted = unit.cast(target_type, ptr=True) + if casted is None: + casted = unit.cast("lv_draw_unit_t", ptr=True) + print(casted.dereference().format_string(pretty_structs=True, symbols=True)) diff --git a/scripts/gdb/lvglgdb/lvgl/misc/lv_anim.py b/scripts/gdb/lvglgdb/lvgl/misc/lv_anim.py index a20a9d13ee..2973cde040 100644 --- a/scripts/gdb/lvglgdb/lvgl/misc/lv_anim.py +++ b/scripts/gdb/lvglgdb/lvgl/misc/lv_anim.py @@ -103,7 +103,7 @@ class LVAnim(Value): def print_info(self): """Print detailed info for a single animation.""" - print(f"Animation @{hex(int(self.address))}") + print(f"Animation @{hex(int(self))}") print(f" var = {self.var}") print(f" exec_cb = {_fmt_cb(self.exec_cb)}") print(f" path_cb = {_fmt_cb(self.path_cb)}") @@ -115,7 +115,7 @@ class LVAnim(Value): f" value = {self.start_value} -> {self.current_value} -> {self.end_value}" ) print(f" duration = {self.duration}ms act_time={self.act_time}ms") - repeat = "inf" if self.repeat_cnt == 0xFFFF else str(self.repeat_cnt) + repeat = "inf" if self.repeat_cnt == 0xFFFFFFFF else str(self.repeat_cnt) print(f" repeat = {repeat} repeat_delay={self.repeat_delay}ms") print( f" reverse = dur={self.reverse_duration}ms delay={self.reverse_delay}ms" @@ -140,7 +140,7 @@ class LVAnim(Value): for i, anim in enumerate(anims): cb_str = _fmt_cb(anim.exec_cb) - repeat = "inf" if anim.repeat_cnt == 0xFFFF else str(anim.repeat_cnt) + repeat = "inf" if anim.repeat_cnt == 0xFFFFFFFF else str(anim.repeat_cnt) value_str = f"{anim.start_value}/{anim.current_value}/{anim.end_value}" table.add_row( [ diff --git a/scripts/gdb/lvglgdb/lvgl/misc/lv_utils.py b/scripts/gdb/lvglgdb/lvgl/misc/lv_utils.py index c10154113a..dad6e674a8 100644 --- a/scripts/gdb/lvglgdb/lvgl/misc/lv_utils.py +++ b/scripts/gdb/lvglgdb/lvgl/misc/lv_utils.py @@ -69,7 +69,10 @@ def build_global_field_map(field_type_name): # LVGL coordinate type constants (from lv_area.h) _COORD_TYPE_SHIFT = 29 +_COORD_TYPE_MASK = 3 << _COORD_TYPE_SHIFT +_COORD_TYPE_PX = 0 << _COORD_TYPE_SHIFT _COORD_TYPE_SPEC = 1 << _COORD_TYPE_SHIFT +_COORD_TYPE_PX_NEG = 3 << _COORD_TYPE_SHIFT _COORD_MAX = (1 << _COORD_TYPE_SHIFT) - 1 _SIZE_CONTENT = _COORD_MAX | _COORD_TYPE_SPEC _PCT_POS_MAX = (_COORD_MAX - 1) // 2 @@ -79,16 +82,21 @@ def format_coord(val): """Format an lv_coord_t value into a human-readable string. Decodes special LVGL coordinate encodings: - - LV_SIZE_CONTENT -> "CONTENT" - - LV_PCT(x) -> "x%" - - plain pixel -> "123" + - LV_SIZE_CONTENT -> "CONTENT" + - LV_PCT(x) -> "x%" + - LV_COORD_TYPE_PX_NEG -> negative pixel + - plain pixel -> "123" """ val = int(val) if val == _SIZE_CONTENT: return "CONTENT" - if val & _COORD_TYPE_SPEC: - plain = val & ~_COORD_TYPE_SPEC + coord_type = val & _COORD_TYPE_MASK + if coord_type == _COORD_TYPE_SPEC: + plain = val & ~_COORD_TYPE_MASK if plain <= _PCT_POS_MAX: return f"{plain}%" return f"{_PCT_POS_MAX - plain}%" + if coord_type == _COORD_TYPE_PX_NEG: + plain = val & ~_COORD_TYPE_MASK + return str(-plain) if plain else "0" return str(val) diff --git a/scripts/gdb/scripts/gen_draw_consts.py b/scripts/gdb/scripts/gen_draw_consts.py index b6e6e5eda8..dfe0682ce1 100644 --- a/scripts/gdb/scripts/gen_draw_consts.py +++ b/scripts/gdb/scripts/gen_draw_consts.py @@ -10,6 +10,7 @@ Usage: """ import re +import sys from pathlib import Path SCRIPT_DIR = Path(__file__).parent @@ -20,6 +21,8 @@ OUTPUT = GDB_ROOT / "lvglgdb" / "lvgl" / "draw" / "lv_draw_consts.py" DRAW_H = LVGL_SRC / "draw" / "lv_draw.h" DRAW_DIR = LVGL_SRC / "draw" +sys.path.insert(0, str(SCRIPT_DIR)) + def parse_enum(path: Path, enum_type: str, prefix: str) -> dict[int, str]: """Parse a C enum from a header file.""" diff --git a/scripts/gdb/scripts/gen_subject_consts.py b/scripts/gdb/scripts/gen_subject_consts.py index 992834d1d3..f8379b3af3 100644 --- a/scripts/gdb/scripts/gen_subject_consts.py +++ b/scripts/gdb/scripts/gen_subject_consts.py @@ -8,7 +8,6 @@ Usage: python3 scripts/gen_subject_consts.py """ -import re import sys from pathlib import Path