Take the 2-minute tour ×

Say I have attached gdb to a process and within the its memory layout there is a file and line number which I would like the memory address of. How can I get the memory address of line n in file x? This is on Linux x86.

share|improve this question
More or less a duplicate of gdb disassemble by line number - the answer to that question is a perfectly good answer to this one as well. –  duskwuff Jul 2 '12 at 3:25
add comment

1 Answer

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

additionally with python you may be able to use the 'last' attribute from Symbol-Tables-In-Python this currently requires a very recent version of gdb from cvs, but i imagine will have general availability in 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
share|improve this answer
thanks for the help. –  Bhubhu Hbuhdbus Jul 2 '12 at 3:28
info line! That's what we needed on that other question. –  Alan Curry Jul 2 '12 at 3:31
add comment

Your Answer


