【问题标题】:Is it possible to capture python gdb variables into the value history?是否可以将 python gdb 变量捕获到值历史记录中?
【发布时间】:2015-11-29 17:56:08
【问题描述】:

我有一个写入gdb.STDOUTpython gdb 脚本,我想将此值捕获到value historyconvenience variable 中,以便于引用。

例如,这个脚本迭代一个链表并转储输出:

(gdb) list MY_OBJECT Links myObjectList 4
(MY_OBJECT *) 0x80f830198
{ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f80fe50, State = 1}, Links = {Next = 0x81182f138, Prev = 0x80f80f5a8}}
(MY_OBJECT *) 0x81182f0d8
{ReferenceCount = 6, Flags = 0, Mutex = {Mutex = 0x811815790, State = 1}, Links = {Next = 0x81182f1f8, Prev = 0x80f8301f8}}
(MY_OBJECT *) 0x81182f198
{ReferenceCount = 2, Flags = 0, Mutex = {Mutex = 0x811816830, State = 1}, Links = {Next = 0x80f8302b8, Prev = 0x81182f138}}
(MY_OBJECT *) 0x80f830258
{ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f8528e0, State = 1}, Links = {Next = 0x80f80f5a8, Prev = 0x81182f1f8}}

是否可以写入 gdb 值历史记录?也许通过gdb.parse_and_eval()

【问题讨论】:

    标签: python c gdb


    【解决方案1】:

    我通过实验发现可以直接从python api命令执行gdb命令,它们会被捕获到值历史中。

    因此,与其使用 python 中的gdb.write("%s" % myObject)print,不如使用gdb.execute("print %s" % myObject),这会产生所需的副作用。

    (gdb) list MY_OBJECT Links myObjectList 4
    $1 = {ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f80fe50, State = 1}, Links = {Next = 0x81182f138, Prev = 0x80f80f5a8}}
    $2 = {ReferenceCount = 6, Flags = 0, Mutex = {Mutex = 0x811815790, State = 1}, Links = {Next = 0x81182f1f8, Prev = 0x80f8301f8}}
    $3 = {ReferenceCount = 2, Flags = 0, Mutex = {Mutex = 0x811816830, State = 1}, Links = {Next = 0x80f8302b8, Prev = 0x81182f138}}
    $4 = {ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f8528e0, State = 1}, Links = {Next = 0x80f80f5a8, Prev = 0x81182f1f8}}
    
    (gdb) print &$1
    $5 = (MY_OBJECT *) 0x80f830198
    

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 1970-01-01
      • 2020-10-16
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多