是否可以将 python gdb 变量捕获到值历史记录中?

Is it possible to capture python gdb variables into the value history?

我有一个 python gdb script which writes to gdb.STDOUT, and I'd like to capture this value into the value history or a convenience 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 api 命令执行 gdb 命令,它们将被捕获到值历史记录中。

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

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

(gdb) print &
 = (MY_OBJECT *) 0x80f830198