This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a4e5689c7f6329a98ad7ac7dd9f3ebd23ea2227c Author: Zhe Weng <[email protected]> AuthorDate: Wed Sep 25 17:46:28 2024 +0800 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 <[email protected]> --- tools/gdb/nuttxgdb/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/gdb/nuttxgdb/utils.py b/tools/gdb/nuttxgdb/utils.py index e40070e2e4..baed0871a0 100644 --- a/tools/gdb/nuttxgdb/utils.py +++ b/tools/gdb/nuttxgdb/utils.py @@ -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()
