Say I want to disassemble lines m-n of file x, where file x is not in the current context. Is this operation possible, and if so, how? Note: I am working on x86 Linux.
-
I'm sure it depends on the optimization flags, and you'll only really be able to do this at `-O0`. – Dietrich Epp Jul 01 '12 at 22:03
3 Answers
You can use the disassemble command with the /m
key to display original C lines in front of their assembly counterparts:
disassemble /m 'my_file.c'::my_function
This does not require any preliminary steps, although it doesn't seem to accept source line ranges as you asked.

- 529
- 5
- 17
As a quite late and maybe redundant answer, but hopefully useful for someone like me, I would like to put together a complete response to this and your other question on getting the address of a line number.
The disassemble
command can disassemble address ranges: disassemble [Start],[End]
. But you want to disassemble line ranges.
To get the addresses of the source code lines you can use the info line
command: info line [File]:[Line]
.

- 4,224
- 4
- 27
- 36
Here's a kludgy way to do it: set a breakpoint on the line you're interested in, and the breakpoint acknowledgement gives you an address. Then clear the breakpoint and run disas
or x/20i
on that address.

- 14,255
- 3
- 32
- 33