4

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,419
  • 6
  • 21
  • 30

3 Answers3

7

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
  • 479
  • 3
  • 16
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
  • 3,754
  • 2
  • 25
  • 33
0

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
  • 13,505
  • 3
  • 30
  • 33