5

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.

Bhubhu Hbuhdbus
  • 1,489
  • 6
  • 24
  • 31

3 Answers3

8

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.

undercat
  • 529
  • 5
  • 17
3

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

xealits
  • 4,224
  • 4
  • 27
  • 36
1

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.

Alan Curry
  • 14,255
  • 3
  • 32
  • 33