public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Peng Yu <pengyu.ut@gmail.com>
To: Stefan Puiu <stefan.puiu@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: How to display instructions around the current instuction?
Date: Thu, 28 Jan 2021 11:06:55 -0600	[thread overview]
Message-ID: <CABrM6wkPGb4FTUosXqjRN65t+x-N327Hc+29Rt=3Eho=n+QiVw@mail.gmail.com> (raw)
In-Reply-To: <CACKs7VAc7tYS-NR8yDnCjDr0z39_-M=QDqbS7O0Lzz-eLk9Rng@mail.gmail.com>

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

(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

  reply	other threads:[~2021-01-28 17:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 23:12 Peng Yu
2021-01-28  8:48 ` Andreas Schwab
2021-01-28 17:08   ` Peng Yu
2021-01-28 18:44     ` Andreas Schwab
2021-01-29 17:38       ` Tavis Ormandy
2021-01-28  9:19 ` Stefan Puiu
2021-01-28 17:06   ` Peng Yu [this message]
2021-01-28 17:26     ` Eli Zaretskii
2021-01-28 17:37       ` Peng Yu
2021-01-28 17:41         ` Christian Biesinger
2021-01-29  2:07           ` Peng Yu
2021-01-29  2:22             ` Sterling Augustine
2021-01-29  2:32               ` Peng Yu
2021-01-29  2:47                 ` Sterling Augustine
2021-01-28 17:57         ` Eli Zaretskii
2021-01-28 18:00     ` Stefan Puiu
2021-01-29  2:15       ` Peng Yu
2021-01-28 13:11 ` Christian Biesinger
2021-01-28 16:50   ` Peng Yu
2021-01-28 16:53     ` Christian Biesinger
2021-01-28 17:16       ` Peng Yu
2021-01-28 17:16         ` Christian Biesinger
2021-01-28 17:00     ` Sterling Augustine
     [not found]       ` <CAGOmfbFh+6AJZFsDP8nFH1bs6kntC4khO+YmPkn3LUfcLAspZw@mail.gmail.com>
2021-01-28 17:45         ` Peng Yu
2021-01-28 18:27 ` Pedro Alves
2021-01-29  1:58   ` Peng Yu
2021-01-29  7:18     ` Eli Zaretskii

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='CABrM6wkPGb4FTUosXqjRN65t+x-N327Hc+29Rt=3Eho=n+QiVw@mail.gmail.com' \
    --to=pengyu.ut@gmail.com \
    --cc=gdb@sourceware.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).