7.4. Source and Machine Code

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 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.

info line linespec

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 Section 7.1).

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 176 of "whetstone.adb" starts at address 0xc9a <whetstone__log10<
   and ends at 0xca4 <whetstone__log10+10>.
(gdb)

We can also inquire (using *addr as the form for linespec) what source line covers a particular address:

(gdb) info line *0xc9a
Line 176 of "whetstone.adb" starts at address 0xc9a <whetstone__log10<
   and ends at 0xca4 <whetstone__log10+10>.
(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 8.5). Also, this address is saved as the value of the convenience variable $_ (see Section 8.9).

disassemble

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 0xc9a 0xca0
Dump of assembler code from 0xc9a to 0xca0:
0xc9a <whetstone__log10>:       sisp   r15,1
0xc9c <whetstone__log10+2>:     pshm   r14,r14
0xc9e <whetstone__log10+4>:     lr     r14,r15
End of assembler dump.
(gdb)