You can use the command info line to map source lines to program addresses (and vice versa), and the command disassemble to display a range of addresses as machine instructions. When run under GNU Emacs mode, the info line command now causes the arrow to point to the line specified. Also, info line prints addresses in symbolic form as well as hex.
Print the starting and ending addresses of the compiled code for source line linespec. You can specify source lines in any of the ways understood by the list command (see Printing source lines: List.).
For example, we can use info line to discover the location of the object code for the first line of function log10 in Whetstone:
(gdb) info line log10 Line 226 of "whetstone.c" starts at address 0x102f6 <log10+6> and ends at 0x102fe <log10+14>. (gdb)
We can also inquire (using *addr as the form for linespec) what source line covers a particular address:
(gdb) info line *0x102f6 Line 226 of "whetstone.c" starts at address 0x102f6 <log10+6> and ends at 0x102fe <log10+14>. (gdb)
After info line, the default address for the x command is changed to the starting address of the line, so that x/i is sufficient to begin examining the machine code (see Section 14.5.). Also, this address is saved as the value of the convenience variable $_ (see Section 14.9.).
This specialized command dumps a range of memory as machine instructions. The default memory range is the function surrounding the program counter of the selected frame. A single argument to this command is a program counter value; the debugger dumps the function surrounding this value. Two arguments specify a range of addresses (first inclusive, second exclusive) to dump.
We can use disassemble to inspect the object code range shown in the last info line.
(gdb) disassemble 0x102f6 0x102fe Dump of assembler code from 0x102f6 to 0x102fe: 0x102f6 <log10+6>: dl r8,37501 0x102fa <log10+10>: dst r8,1,r15 End of assembler dump. (gdb)