chore(gdb): fix coord type mask, cast safety and dedup parse_enum

This commit is contained in:
Benign X
2026-03-06 14:36:20 +08:00
committed by VIFEX
parent 7e784e98ec
commit 64e7804574
6 changed files with 36 additions and 14 deletions
+13
View File
@@ -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 <expr>``: 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... <my_cb> target=0x... for_obj=True
+4 -5
View File
@@ -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))
+3 -3
View File
@@ -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(
[
+13 -5
View File
@@ -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)
+3
View File
@@ -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."""
@@ -8,7 +8,6 @@ Usage:
python3 scripts/gen_subject_consts.py
"""
import re
import sys
from pathlib import Path