gdb.execute (command [, from_tty [, to_string]])
是什麼你(我們:D)尋求。你可以看看function decription。第一個參數是引用GDB命令,第二個我沒有真正理解,我想因爲我不需要它,只是保留它虛假。第三個決定命令輸出將在哪裏傳輸。如果假(默認),它只是要打印,如果true,輸出將被包裝爲字符串並返回給您,因此您可以將其分配給一個變量。
一個例子:
(gdb) py MyVar = gdb.execute("info f",False,True)
(gdb) py print(MyVar)
Stack level 0, frame at 0x7fffffffdda0:
rip = 0x4006a6 in [email protected]; saved rip 0x4007b9
called by frame at 0x7fffffffddc0
Arglist at 0x7fffffffdd90, args:
Locals at 0x7fffffffdd90, Previous frame's sp is 0x7fffffffdda0
Saved registers:
rip at 0x7fffffffdd98
(gdb)
您還可能有興趣在gdb.parse_and_eval (expression)
。它提供了使用所謂舒適變量GDB的一個簡單的方法:
(gdb) set $MyVar = "PinkyPie is the best!"
(gdb) pi
>>> MyStr = gdb.parse_and_eval("$MyVar")
>>> print(MyStr)
"PinkyPie is the best!"
>>>
(gdb)
是否有人知道做到這一點的呢?謝謝!!!!!這是一項任務,我必須使用gdb和python腳本。 – user1118486 2012-01-07 23:18:52