7

假设我已将 gdb 附加到一个进程,并且在其内存布局中有一个文件和行号,我想要它的内存地址。如何获取文件 x 中第 n 行的内存地址?这是在 Linux x86 上。

4

1 回答 1

15
(gdb) info line test.c:56
Line 56 of "test.c" starts at address 0x4005ae <main+37>
   and ends at 0x4005ba <main+49>.

另外,使用 python,您可以使用 Symbol-Tables-In-Python中的“last”属性,这目前需要来自 cvs 的最新版本的 gdb,但我想在 7.5 中将具有普遍可用性

(gdb) py x = gdb.find_pc_line(gdb.decode_line("test.c:56")[1][0].pc); gdb.execute("p/x " + str(x.pc)); gdb.execute("p/x " + str(x.last))
$15 = 0x4005ae
$16 = 0x4005b9
于 2012-07-02T03:27:52.750 回答