Re: How to display instructions around the current instuction?

Pedro Alves <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
On 27/01/21 23:12, Peng Yu via Gdb wrote:
> Hi,
> 
> The following command will disply instructions below the current
> instructions. Is there a way to display around the current instruction
> (e.g., 5 instructions above and 5 instructions below)?
> 
> display/10i $rip
> 

From gdb/NEWS:

~~~~
*** Changes in GDB 7.12

* GDB now supports a negative repeat count in the 'x' command to examine
  memory backward from the given address.  For example:

...
    (gdb) x/-5i 0x0000000000400580
       0x40056a <main(int, char**)+8>:      mov    %edi,-0x4(%rbp)
       0x40056d <main(int, char**)+11>:     mov    %rsi,-0x10(%rbp)
       0x400571 <main(int, char**)+15>:     mov    $0x40061c,%esi
       0x400576 <main(int, char**)+20>:     mov    $0x2a,%edi
       0x40057b <main(int, char**)+25>:
        callq  0x400536 <Func1(int, char const*)>
~~~~

There's also this:

~~~~
(gdb) help set disassemble-next-line 
Set whether to disassemble next source line or insn when execution stops.
If ON, GDB will display disassembly of the next source line, in addition
to displaying the source line itself.  If the next source line cannot
be displayed (e.g., source is unavailable or there's no line info), GDB
will display disassembly of next instruction instead of showing the
source line.
If AUTO, display disassembly of next instruction only if the source line
cannot be displayed.
If OFF (which is the default), never display the disassembly of the next
source line.
(gdb) 
~~~~
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.