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 0cda6278d39874ad2bc9d74bbaf59a65602bf3fb
Author: Zhe Weng <[email protected]>
AuthorDate: Wed Sep 25 20:07:37 2024 +0800

    tools/gdb: Use ptr's value instead of ptr's adderess in container_of
    
    We're using `ptr.cast(get_long_type())` a week ago to get the pointer's 
value, it's alright, but `ptr.address` is not, the `ptr.address` will return 
**the address of the pointer**.
    
    These values are the address of first element in the queue:
        - `int(g_sigfreeaction["head"])`
        - `g_sigfreeaction["head"].cast(get_long_type())`
        - `g_sigfreeaction["head"].dereference().address`
    But:
        `int(g_sigfreeaction["head"].address)` is the address of the "head" 
member, which equals to the address of `g_sigfreeaction`
    
    It's happening in NxSQueue:
        g_sigfreeaction = gdb.parse_and_eval("g_sigfreeaction")
        print(["%x" % (node) for node in NxSQueue(g_sigfreeaction)])
        print(["%x" % (node) for node in NxSQueue(g_sigfreeaction, "sigactq_t", 
"flink")])
    Without this patch:
        ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']
        ['55db90a0', 'f3c0aa10', 'f3c0aa2c']
    With this patch:
        ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']
        ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']
    
    Signed-off-by: Zhe Weng <[email protected]>
---
 tools/gdb/nuttxgdb/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/gdb/nuttxgdb/utils.py b/tools/gdb/nuttxgdb/utils.py
index baed0871a0..e38c88a64f 100644
--- a/tools/gdb/nuttxgdb/utils.py
+++ b/tools/gdb/nuttxgdb/utils.py
@@ -100,7 +100,7 @@ def container_of(
     """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(
+    return gdb.Value(int(ptr.dereference().address) - offset_of(typeobj, 
member)).cast(
         typeobj.pointer()
     )
 

Reply via email to