From: Stefan Puiu via Gdb <gdb@sourceware.org>
To: Peng Yu <pengyu.ut@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: How to display instructions around the current instuction?
Date: Thu, 28 Jan 2021 20:00:40 +0200 [thread overview]
Message-ID: <CACKs7VDRxAVXXag6yxwFfqriHQMtJf9_B2EK-z8XDjkfrRS3wg@mail.gmail.com> (raw)
In-Reply-To: <CABrM6wkPGb4FTUosXqjRN65t+x-N327Hc+29Rt=3Eho=n+QiVw@mail.gmail.com>
On Thu, Jan 28, 2021 at 7:06 PM Peng Yu <pengyu.ut@gmail.com> 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
next prev parent reply other threads:[~2021-01-28 18:00 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-27 23:12 Peng Yu via Gdb
2021-01-28 8:48 ` Andreas Schwab
2021-01-28 17:08 ` Peng Yu via Gdb
2021-01-28 18:44 ` Andreas Schwab
2021-01-29 17:38 ` Tavis Ormandy via Gdb
2021-01-28 9:19 ` Stefan Puiu via Gdb
2021-01-28 17:06 ` Peng Yu via Gdb
2021-01-28 17:26 ` Eli Zaretskii via Gdb
2021-01-28 17:37 ` Peng Yu via Gdb
2021-01-28 17:41 ` Christian Biesinger via Gdb
2021-01-29 2:07 ` Peng Yu via Gdb
2021-01-29 2:22 ` Sterling Augustine via Gdb
2021-01-29 2:32 ` Peng Yu via Gdb
2021-01-29 2:47 ` Sterling Augustine via Gdb
2021-01-28 17:57 ` Eli Zaretskii via Gdb
2021-01-28 18:00 ` Stefan Puiu via Gdb [this message]
2021-01-29 2:15 ` Peng Yu via Gdb
2021-01-28 13:11 ` Christian Biesinger via Gdb
2021-01-28 16:50 ` Peng Yu via Gdb
2021-01-28 16:53 ` Christian Biesinger via Gdb
2021-01-28 17:16 ` Peng Yu via Gdb
2021-01-28 17:16 ` Christian Biesinger via Gdb
2021-01-28 17:00 ` Sterling Augustine via Gdb
[not found] ` <CAGOmfbFh+6AJZFsDP8nFH1bs6kntC4khO+YmPkn3LUfcLAspZw@mail.gmail.com>
2021-01-28 17:45 ` Peng Yu via Gdb
2021-01-28 18:27 ` Pedro Alves
2021-01-29 1:58 ` Peng Yu via Gdb
2021-01-29 7:18 ` Eli Zaretskii via Gdb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACKs7VDRxAVXXag6yxwFfqriHQMtJf9_B2EK-z8XDjkfrRS3wg@mail.gmail.com \
--to=gdb@sourceware.org \
--cc=pengyu.ut@gmail.com \
--cc=stefan.puiu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox