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

时间:2015-09-03 18:56:06

标签: python c gdb

我有一个python gdb脚本写入gdb.STDOUT,我想将此值捕获到value historyconvenience variable中,以便&# 39;易于引用。

例如,此脚本迭代链表并转储输出:

(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()

1 个答案:

答案 0 :(得分: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