mirror of
https://github.com/apache/nuttx.git
synced 2026-09-13 14:10:18 +00:00
tools/gdb: Allow utils.container_of with str input
After we introduced NxDQueue and NxSQueue, we're using them like `NxDQueue(g_active_connections, "struct socket_conn_s", "node")` and leads to `utils.container_of(ptr, str, str)`, so maybe we need to allow str input for `utils.container_of` Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
bb461b532b
commit
a4e5689c7f
1 changed files with 6 additions and 4 deletions
|
|
@ -94,8 +94,12 @@ def offset_of(typeobj: gdb.Type, field: str) -> Union[int, None]:
|
|||
return None
|
||||
|
||||
|
||||
def container_of(ptr: gdb.Value, typeobj: gdb.Type, member: str) -> gdb.Value:
|
||||
def container_of(
|
||||
ptr: gdb.Value, typeobj: Union[gdb.Type, str], member: str
|
||||
) -> gdb.Value:
|
||||
"""Return pointer to containing data structure"""
|
||||
if isinstance(typeobj, str):
|
||||
typeobj = lookup_type(typeobj)
|
||||
return gdb.Value(int(ptr.address) - offset_of(typeobj, member)).cast(
|
||||
typeobj.pointer()
|
||||
)
|
||||
|
|
@ -112,9 +116,7 @@ class ContainerOf(gdb.Function):
|
|||
super().__init__("container_of")
|
||||
|
||||
def invoke(self, ptr, typename, elementname):
|
||||
return container_of(
|
||||
ptr, gdb.lookup_type(typename.string()).pointer(), elementname.string()
|
||||
)
|
||||
return container_of(ptr, typename.string(), elementname.string())
|
||||
|
||||
|
||||
ContainerOf()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue