Re: How to display instructions around the current instuction?
Stefan Puiu via Gdb <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CACKs7VDRxAVXXag6yxwFfqriHQMtJf9_B2EK-z8XDjkfrRS3wg@mail.gmail.com> |
On Thu, Jan 28, 2021 at 7:06 PM Peng Yu <[email protected]> wrote: > > Hi Stefan, > > > display/10i $rip-10 > > > > I don't think x86-64 instructions have fixed width, so that won't > > always print the same number of instructions before the current one, > > but it's probably a good approximation. > > Have you tried it? If $rip-5 is not right at the start of an Well, I said "Have you tried...?", not "here, that's the answer". But since you ask so nicely, yes, I've tried it. It's something I use often on Linux, and it works. In fact, I've just tried it with a simple program and it works. On my Linux (Ubuntu 20.04 x86-64). But wait, you have MacOS; you didn't mention that in your initial email. > instruction, it does not even disassmble correctly. Please test your > recommendation before sending it out. It is not appropriate to waste > other people's time. Please don't be rude to people who are trying to help you. And what do you know, there's plenty of wrong answers on stackoverflow, and plenty that haven't been deleted. You still have to figure them out. > > (gdb) 1: x/10i $rip-5 > <error: No registers.> > (gdb) Temporary breakpoint 1 at 0x401134 > Starting program: /mnt/macosx/pengy/mrrdir/test/gnu/gdb/cmd/display/main.exe > > Temporary breakpoint 1, 0x0000000000401134 in main () > 1: x/10i $rip-5 > 0x40112f <frame_dummy+15>: add BYTE PTR [rbp+0x48],dl > 0x401132 <main+2>: mov ebp,esp > => 0x401134 <main+4>: sub rsp,0x10 > 0x401138 <main+8>: movabs rdi,0x402004 > 0x401142 <main+18>: mov al,0x0 > 0x401144 <main+20>: call 0x401030 <printf@plt> > 0x401149 <main+25>: xor ecx,ecx > 0x40114b <main+27>: mov DWORD PTR [rbp-0x4],eax > 0x40114e <main+30>: mov eax,ecx > 0x401150 <main+32>: add rsp,0x10 > (gdb) 0x0000000000401138 in main () > 1: x/10i $rip-5 > 0x401133 <main+3>: in eax,0x48 > 0x401135 <main+5>: sub esp,0x10 > => 0x401138 <main+8>: movabs rdi,0x402004 > 0x401142 <main+18>: mov al,0x0 > 0x401144 <main+20>: call 0x401030 <printf@plt> > 0x401149 <main+25>: xor ecx,ecx > 0x40114b <main+27>: mov DWORD PTR [rbp-0x4],eax > 0x40114e <main+30>: mov eax,ecx > 0x401150 <main+32>: add rsp,0x10 > 0x401154 <main+36>: pop rbp > (gdb) 0x0000000000401142 in main () > 1: x/10i $rip-5 > 0x40113d <main+13>: add BYTE PTR [rax],al > 0x40113f <main+15>: add BYTE PTR [rax],al > 0x401141 <main+17>: add BYTE PTR [rax-0x1181800],dh > 0x401147 <main+23>: (bad) > 0x401148 <main+24>: push QWORD PTR [rcx] > 0x40114a <main+26>: leave > 0x40114b <main+27>: mov DWORD PTR [rbp-0x4],eax > 0x40114e <main+30>: mov eax,ecx > 0x401150 <main+32>: add rsp,0x10 > 0x401154 <main+36>: pop rbp > > -- > Regards, > Peng