public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* How to display instructions around the current instuction?
@ 2021-01-27 23:12 Peng Yu
  2021-01-28  8:48 ` Andreas Schwab
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-27 23:12 UTC (permalink / raw)
  To: gdb

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

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-27 23:12 How to display instructions around the current instuction? Peng Yu
@ 2021-01-28  8:48 ` Andreas Schwab
  2021-01-28 17:08   ` Peng Yu
  2021-01-28  9:19 ` Stefan Puiu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 27+ messages in thread
From: Andreas Schwab @ 2021-01-28  8:48 UTC (permalink / raw)
  To: Peng Yu via Gdb

On Jan 27 2021, Peng Yu via Gdb wrote:

> 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)?

How do you know where the five instructions start?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-27 23:12 How to display instructions around the current instuction? Peng Yu
  2021-01-28  8:48 ` Andreas Schwab
@ 2021-01-28  9:19 ` Stefan Puiu
  2021-01-28 17:06   ` Peng Yu
  2021-01-28 13:11 ` Christian Biesinger
  2021-01-28 18:27 ` Pedro Alves
  3 siblings, 1 reply; 27+ messages in thread
From: Stefan Puiu @ 2021-01-28  9:19 UTC (permalink / raw)
  To: Peng Yu; +Cc: gdb

Hi,

On Thu, Jan 28, 2021 at 1:31 AM Peng Yu via Gdb <gdb@sourceware.org> 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

Have you tried something using '$rip-10' in your command?

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.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-27 23:12 How to display instructions around the current instuction? Peng Yu
  2021-01-28  8:48 ` Andreas Schwab
  2021-01-28  9:19 ` Stefan Puiu
@ 2021-01-28 13:11 ` Christian Biesinger
  2021-01-28 16:50   ` Peng Yu
  2021-01-28 18:27 ` Pedro Alves
  3 siblings, 1 reply; 27+ messages in thread
From: Christian Biesinger @ 2021-01-28 13:11 UTC (permalink / raw)
  To: Peng Yu; +Cc: Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 12:13 AM Peng Yu via Gdb <gdb@sourceware.org> 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)?

I believe "disas" should work:

Breakpoint 1, main () at a.cpp:5

5     std::cout << "Miau\n";

(gdb) disas
Dump of assembler code for function main():
   0x0000555555555155 <+0>: push   %rbp
   0x0000555555555156 <+1>: mov    %rsp,%rbp
=> 0x0000555555555159 <+4>: lea    0xea5(%rip),%rsi        # 0x555555556005
   0x0000555555555160 <+11>: lea    0x2ed9(%rip),%rdi        #
0x555555558040 <_ZSt4cout@GLIBCXX_3.4>
   0x0000555555555167 <+18>: call   0x555555555040
<_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt>
   0x000055555555516c <+23>: mov    $0x0,%eax
   0x0000555555555171 <+28>: pop    %rbp
   0x0000555555555172 <+29>: ret
End of assembler dump.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  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:00     ` Sterling Augustine
  0 siblings, 2 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-28 16:50 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Reuben Thomas via Gdb

> I believe "disas" should work:

I need at each si, it automatically print the commands. I don't want
to type disas each time when I type si.

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  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:00     ` Sterling Augustine
  1 sibling, 1 reply; 27+ messages in thread
From: Christian Biesinger @ 2021-01-28 16:53 UTC (permalink / raw)
  To: Peng Yu; +Cc: Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 5:50 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> > I believe "disas" should work:
>
> I need at each si, it automatically print the commands. I don't want
> to type disas each time when I type si.

Maybe:

define hook-stop
  disas
end

?

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 16:50   ` Peng Yu
  2021-01-28 16:53     ` Christian Biesinger
@ 2021-01-28 17:00     ` Sterling Augustine
       [not found]       ` <CAGOmfbFh+6AJZFsDP8nFH1bs6kntC4khO+YmPkn3LUfcLAspZw@mail.gmail.com>
  1 sibling, 1 reply; 27+ messages in thread
From: Sterling Augustine @ 2021-01-28 17:00 UTC (permalink / raw)
  To: Peng Yu; +Cc: Christian Biesinger, Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 8:50 AM Peng Yu via Gdb <gdb@sourceware.org> wrote:
>
> > I believe "disas" should work:
>
> I need at each si, it automatically print the commands. I don't want
> to type disas each time when I type si.

You might find the TUI assembly layout helpful.

(gdb) tui enable
(gdb) layout asm

Remember here that everyone is trying to help you out of kindness.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28  9:19 ` Stefan Puiu
@ 2021-01-28 17:06   ` Peng Yu
  2021-01-28 17:26     ` Eli Zaretskii
  2021-01-28 18:00     ` Stefan Puiu
  0 siblings, 2 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-28 17:06 UTC (permalink / raw)
  To: Stefan Puiu; +Cc: gdb

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28  8:48 ` Andreas Schwab
@ 2021-01-28 17:08   ` Peng Yu
  2021-01-28 18:44     ` Andreas Schwab
  0 siblings, 1 reply; 27+ messages in thread
From: Peng Yu @ 2021-01-28 17:08 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Peng Yu via Gdb

Hi Andreas,

> How do you know where the five instructions start?

I don't know. But gdb could figure it out if this feature is
available. There could be a syntax to go back a given number of
instructions. But it seems that this feature is not available in gdb?

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 16:53     ` Christian Biesinger
@ 2021-01-28 17:16       ` Peng Yu
  2021-01-28 17:16         ` Christian Biesinger
  0 siblings, 1 reply; 27+ messages in thread
From: Peng Yu @ 2021-01-28 17:16 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Reuben Thomas via Gdb

Hi Christian,

> define hook-stop
>   disas
> end

This works by printing the current block. It looks good.

Is there a way to make the three lines into one line? Thanks.

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:16       ` Peng Yu
@ 2021-01-28 17:16         ` Christian Biesinger
  0 siblings, 0 replies; 27+ messages in thread
From: Christian Biesinger @ 2021-01-28 17:16 UTC (permalink / raw)
  To: Peng Yu; +Cc: Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 6:16 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Hi Christian,
>
> > define hook-stop
> >   disas
> > end
>
> This works by printing the current block. It looks good.
>
> Is there a way to make the three lines into one line? Thanks.

Sorry, I don't know.

Christian

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:06   ` Peng Yu
@ 2021-01-28 17:26     ` Eli Zaretskii
  2021-01-28 17:37       ` Peng Yu
  2021-01-28 18:00     ` Stefan Puiu
  1 sibling, 1 reply; 27+ messages in thread
From: Eli Zaretskii @ 2021-01-28 17:26 UTC (permalink / raw)
  To: Peng Yu; +Cc: stefan.puiu, gdb

> Date: Thu, 28 Jan 2021 11:06:55 -0600
> From: Peng Yu via Gdb <gdb@sourceware.org>
> Cc: gdb@sourceware.org
> 
> Please test your recommendation before sending it out. It is not
> appropriate to waste other people's time.

Hey, no one here works for you, you know!  So please appreciate that
people are "wasting their time" on helping you achieve your goals, and
be thankful.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:26     ` Eli Zaretskii
@ 2021-01-28 17:37       ` Peng Yu
  2021-01-28 17:41         ` Christian Biesinger
  2021-01-28 17:57         ` Eli Zaretskii
  0 siblings, 2 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-28 17:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: stefan.puiu, gdb

I have already thanked other people who send correct answers. But
helping by definition should making sure the answers are correctly. It
is not a valid excuse to say to post untested wrong results are OK
because of "helping".

If an answers is not correct, it should not be sent in the first
place. In stackoverflow, wrong answers can be deleted. But mailing
lists don't have this options. Therefore, the senders should make sure
the correctness of the answers before sending them out.

On 1/28/21, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Thu, 28 Jan 2021 11:06:55 -0600
>> From: Peng Yu via Gdb <gdb@sourceware.org>
>> Cc: gdb@sourceware.org
>>
>> Please test your recommendation before sending it out. It is not
>> appropriate to waste other people's time.
>
> Hey, no one here works for you, you know!  So please appreciate that
> people are "wasting their time" on helping you achieve your goals, and
> be thankful.
>


-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:37       ` Peng Yu
@ 2021-01-28 17:41         ` Christian Biesinger
  2021-01-29  2:07           ` Peng Yu
  2021-01-28 17:57         ` Eli Zaretskii
  1 sibling, 1 reply; 27+ messages in thread
From: Christian Biesinger @ 2021-01-28 17:41 UTC (permalink / raw)
  To: Peng Yu; +Cc: Eli Zaretskii, Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 6:37 PM Peng Yu via Gdb <gdb@sourceware.org> wrote:
>
> I have already thanked other people who send correct answers. But
> helping by definition should making sure the answers are correctly. It
> is not a valid excuse to say to post untested wrong results are OK
> because of "helping".
>
> If an answers is not correct, it should not be sent in the first
> place. In stackoverflow, wrong answers can be deleted. But mailing
> lists don't have this options. Therefore, the senders should make sure
> the correctness of the answers before sending them out.

I hate to take this further offtopic but would like you to consider
that if people were required to test all suggestions first, many
responses would not be sent in the first place. For example, I did not
test my hook-stop suggestion. I am not sure that people would be
better off in such a world.

Christian

>
> On 1/28/21, Eli Zaretskii <eliz@gnu.org> wrote:
> >> Date: Thu, 28 Jan 2021 11:06:55 -0600
> >> From: Peng Yu via Gdb <gdb@sourceware.org>
> >> Cc: gdb@sourceware.org
> >>
> >> Please test your recommendation before sending it out. It is not
> >> appropriate to waste other people's time.
> >
> > Hey, no one here works for you, you know!  So please appreciate that
> > people are "wasting their time" on helping you achieve your goals, and
> > be thankful.
> >
>
>
> --
> Regards,
> Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
       [not found]       ` <CAGOmfbFh+6AJZFsDP8nFH1bs6kntC4khO+YmPkn3LUfcLAspZw@mail.gmail.com>
@ 2021-01-28 17:45         ` Peng Yu
  0 siblings, 0 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-28 17:45 UTC (permalink / raw)
  To: Christo Crause; +Cc: gdb

Hi Christo,

> Another possibility could be: set disassemble-next-line on

This does not correctly answer the question. It just show the current
line but not the context.

Also, how to just show the disassembled code but the hex numbers.

I know the doc is here. But is there is a way to check its helpage
withing gdb command line? Thanks.

https://visualgdb.com/gdbreference/commands/set_disassemble-next-line

Temporary breakpoint 1, 0x0000000000401134 in main ()
=> 0x0000000000401134 <main+4>:	48 83 ec 10	sub    rsp,0x10
(gdb) 0x0000000000401138 in main ()
=> 0x0000000000401138 <main+8>:	c7 45 fc 00 00 00 00	mov    DWORD PTR
[rbp-0x4],0x0
(gdb) 0x000000000040113f in main ()
=> 0x000000000040113f <main+15>:	48 bf 04 20 40 00 00 00 00 00	movabs
rdi,0x402004

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:37       ` Peng Yu
  2021-01-28 17:41         ` Christian Biesinger
@ 2021-01-28 17:57         ` Eli Zaretskii
  1 sibling, 0 replies; 27+ messages in thread
From: Eli Zaretskii @ 2021-01-28 17:57 UTC (permalink / raw)
  To: Peng Yu; +Cc: stefan.puiu, gdb

> From: Peng Yu <pengyu.ut@gmail.com>
> Date: Thu, 28 Jan 2021 11:37:20 -0600
> Cc: stefan.puiu@gmail.com, gdb@sourceware.org
> 
> I have already thanked other people who send correct answers. But
> helping by definition should making sure the answers are correctly. It
> is not a valid excuse to say to post untested wrong results are OK
> because of "helping".
> 
> If an answers is not correct, it should not be sent in the first
> place. In stackoverflow, wrong answers can be deleted. But mailing
> lists don't have this options. Therefore, the senders should make sure
> the correctness of the answers before sending them out.

With such an attitude, don't expect anyone to help you when you ask
next time.  You have a lot to learn about politeness and humility
(rudeness you already learned only too well).

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:06   ` Peng Yu
  2021-01-28 17:26     ` Eli Zaretskii
@ 2021-01-28 18:00     ` Stefan Puiu
  2021-01-29  2:15       ` Peng Yu
  1 sibling, 1 reply; 27+ messages in thread
From: Stefan Puiu @ 2021-01-28 18:00 UTC (permalink / raw)
  To: Peng Yu; +Cc: gdb

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-27 23:12 How to display instructions around the current instuction? Peng Yu
                   ` (2 preceding siblings ...)
  2021-01-28 13:11 ` Christian Biesinger
@ 2021-01-28 18:27 ` Pedro Alves
  2021-01-29  1:58   ` Peng Yu
  3 siblings, 1 reply; 27+ messages in thread
From: Pedro Alves @ 2021-01-28 18:27 UTC (permalink / raw)
  To: gdb


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) 
~~~~

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:08   ` Peng Yu
@ 2021-01-28 18:44     ` Andreas Schwab
  2021-01-29 17:38       ` Tavis Ormandy
  0 siblings, 1 reply; 27+ messages in thread
From: Andreas Schwab @ 2021-01-28 18:44 UTC (permalink / raw)
  To: Peng Yu; +Cc: Peng Yu via Gdb

On Jan 28 2021, Peng Yu wrote:

> There could be a syntax to go back a given number of instructions.

How do you know how long each instruction is?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 18:27 ` Pedro Alves
@ 2021-01-29  1:58   ` Peng Yu
  2021-01-29  7:18     ` Eli Zaretskii
  0 siblings, 1 reply; 27+ messages in thread
From: Peng Yu @ 2021-01-29  1:58 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb

On 1/28/21, Pedro Alves <pedro@palves.net> wrote:
>
> 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*)>
> ~~~~

Is there a documentation problem in gdb regarding this feature. I
don't see this feature is documented.

$ gdb --version
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

(gdb) help display
Print value of expression EXP each time the program stops.
Usage: display[/FMT] EXP
/FMT may be used before EXP as in the "print" command.
/FMT "i" or "s" or including a size-letter is allowed,
as in the "x" command, and then EXP is used to get the address to examine
and examining is done as in the "x" command.

With no argument, display all currently requested auto-display expressions.
Use "undisplay" to cancel display requests previously made.
(gdb) help print
...
EXP may be preceded with /FMT, where FMT is a format letter
but no count or size letter (see "x" command).

> 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)
> ~~~~
>


-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 17:41         ` Christian Biesinger
@ 2021-01-29  2:07           ` Peng Yu
  2021-01-29  2:22             ` Sterling Augustine
  0 siblings, 1 reply; 27+ messages in thread
From: Peng Yu @ 2021-01-29  2:07 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Eli Zaretskii, Reuben Thomas via Gdb

> I hate to take this further offtopic but would like you to consider
> that if people were required to test all suggestions first,

That is not what I meant. See below.

> many
> responses would not be sent in the first place. For example, I did not
> test my hook-stop suggestion. I am not sure that people would be
> better off in such a world.

The point is the answer is better to be correct. If it is known to be
correct, of course, there is no need to test it. But if the sender is
not sure, it is better to test it to make sure. If a sender sends out
a wrong answer, s/he does show respect to the recipient.

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 18:00     ` Stefan Puiu
@ 2021-01-29  2:15       ` Peng Yu
  0 siblings, 0 replies; 27+ messages in thread
From: Peng Yu @ 2021-01-29  2:15 UTC (permalink / raw)
  To: Stefan Puiu; +Cc: gdb

> But wait, you have MacOS; you didn't mention that in your initial email.

Don't change the topic. I've already shown you that it did not work in
some cases and the test was on Linux. A path containing the word
"macos" does not mean that the OS was MacOS.

Please do not give excuses for the fact that you did not test your
suggestions properly.

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-29  2:07           ` Peng Yu
@ 2021-01-29  2:22             ` Sterling Augustine
  2021-01-29  2:32               ` Peng Yu
  0 siblings, 1 reply; 27+ messages in thread
From: Sterling Augustine @ 2021-01-29  2:22 UTC (permalink / raw)
  To: Peng Yu; +Cc: Christian Biesinger, Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 6:07 PM Peng Yu via Gdb <gdb@sourceware.org> wrote:
>
> > I hate to take this further offtopic but would like you to consider
> > that if people were required to test all suggestions first,
>
> That is not what I meant. See below.
>
> > many
> > responses would not be sent in the first place. For example, I did not
> > test my hook-stop suggestion. I am not sure that people would be
> > better off in such a world.
>
> The point is the answer is better to be correct.

Remind me: How many contributions have you made to gdb?

> If it is known to be
> correct, of course, there is no need to test it. But if the sender is
> not sure, it is better to test it to make sure. If a sender sends out
> a wrong answer, s/he does show respect to the recipient.

You have a strange, rather binary view, of "correct" vs "incorrect".
Every single idea here does something approximately like what you
want. Many people in the past asking similar questions would have been
perfectly fine with a wide variety of answers. You might not like it,
but you don't get to decide what the proper etiquette in this mailing
list.

If you decide they aren't exact enough, then, well, not much we can
do. But most people who come begging for help from people who are just
trying to be kind are willing to at least work with the possible
answers, and see if they can adapt them, rather than playing like they
are proctoring a test.

 It is not our job to give you technical support--nor is it this
mailing list's reason for existence. You are lucky people are
answering at all.

I would rather people try to help than refrain from answering in case
it isn't exactly what the beggar wanted. That is how this list has
always worked in the two-decades I've been a part of it.

In fact, you have really no room to insist people help you in any
particular way. We have all worked on gdb for years--maybe decades. We
have all been active on this list for as long. So insisting we follow
your preferences rather than ours is incredibly rude.

How many patches do have in gdb again?

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-29  2:22             ` Sterling Augustine
@ 2021-01-29  2:32               ` Peng Yu
  2021-01-29  2:47                 ` Sterling Augustine
  0 siblings, 1 reply; 27+ messages in thread
From: Peng Yu @ 2021-01-29  2:32 UTC (permalink / raw)
  To: Sterling Augustine; +Cc: Christian Biesinger, Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 8:22 PM Sterling Augustine
<saugustine@google.com> wrote:
>
> On Thu, Jan 28, 2021 at 6:07 PM Peng Yu via Gdb <gdb@sourceware.org> wrote:
> >
> > > I hate to take this further offtopic but would like you to consider
> > > that if people were required to test all suggestions first,
> >
> > That is not what I meant. See below.
> >
> > > many
> > > responses would not be sent in the first place. For example, I did not
> > > test my hook-stop suggestion. I am not sure that people would be
> > > better off in such a world.
> >
> > The point is the answer is better to be correct.
>
> Remind me: How many contributions have you made to gdb?
>
> > If it is known to be
> > correct, of course, there is no need to test it. But if the sender is
> > not sure, it is better to test it to make sure. If a sender sends out
> > a wrong answer, s/he does show respect to the recipient.
>
> You have a strange, rather binary view, of "correct" vs "incorrect".
> Every single idea here does something approximately like what you
> want. Many people in the past asking similar questions would have been
> perfectly fine with a wide variety of answers. You might not like it,
> but you don't get to decide what the proper etiquette in this mailing
> list.

So, you get to decide it?

> If you decide they aren't exact enough, then, well, not much we can
> do. But most people who come begging for help from people who are just
> trying to be kind are willing to at least work with the possible
> answers, and see if they can adapt them, rather than playing like they
> are proctoring a test.
>
>  It is not our job to give you technical support--nor is it this
> mailing list's reason for existence. You are lucky people are
> answering at all.
>
> I would rather people try to help than refrain from answering in case
> it isn't exactly what the beggar wanted. That is how this list has
> always worked in the two-decades I've been a part of it.
>
> In fact, you have really no room to insist people help you in any
> particular way. We have all worked on gdb for years--maybe decades. We
> have all been active on this list for as long. So insisting we follow
> your preferences rather than ours is incredibly rude.
>
> How many patches do have in gdb again?

I don't see this is a relevant question here. If you want to ask that
question, go to gdb-patches.

gdb (archives) A list for general discussion about GDB. Any
GDB-related subject not covered by another list is appropriate here;
in practice, most of the discussions are about ideas for future
changes. Patches should be sent to the gdb-patches mailing-list (see
below). Bugs should be reported using the Bug Database.

gdb-patches (archives) For patch submissions and discussion. All patch
submissions and submission discussion should go through this list.
-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-29  2:32               ` Peng Yu
@ 2021-01-29  2:47                 ` Sterling Augustine
  0 siblings, 0 replies; 27+ messages in thread
From: Sterling Augustine @ 2021-01-29  2:47 UTC (permalink / raw)
  To: Peng Yu; +Cc: Christian Biesinger, Reuben Thomas via Gdb

On Thu, Jan 28, 2021 at 6:33 PM Peng Yu <pengyu.ut@gmail.com> wrote:
> > You have a strange, rather binary view, of "correct" vs "incorrect".
> > Every single idea here does something approximately like what you
> > want. Many people in the past asking similar questions would have been
> > perfectly fine with a wide variety of answers. You might not like it,
> > but you don't get to decide what the proper etiquette in this mailing
> > list.
>
> So, you get to decide it?

The community gets to decide it. Not you. The community responded in
the typical way it has for years. If that is unacceptable to you, then
you don't seem to be a part of the community.
> > How many patches do have in gdb again?
>
> I don't see this is a relevant question here. If you want to ask that
> question, go to gdb-patches.

The relevance is that you have not been a part of the community in the
past, but you expect it to work in a very particular way, and it has
never worked that way. Why should it change now, just for you? Someone
who has never contributed in any way to the community?

You seem to be confusing Peng's problem with "other people's problem".
You came to the mailing list with a problem. That was Peng's problem.
We would like to help you with your problem, but whether we can or
can't doesn't make it our problem.

Someone gives you an answer that doesn't solve your problem? That's
your problem, not the answerer's problem. Your problem is not our
problem. How we answer doesn't make it our problem.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-29  1:58   ` Peng Yu
@ 2021-01-29  7:18     ` Eli Zaretskii
  0 siblings, 0 replies; 27+ messages in thread
From: Eli Zaretskii @ 2021-01-29  7:18 UTC (permalink / raw)
  To: Peng Yu; +Cc: pedro, gdb

> Date: Thu, 28 Jan 2021 19:58:11 -0600
> From: Peng Yu via Gdb <gdb@sourceware.org>
> Cc: gdb@sourceware.org
> 
> >> 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*)>
> > ~~~~
> 
> Is there a documentation problem in gdb regarding this feature. I
> don't see this feature is documented.

You are looking up help on a wrong command.  Pedro suggested to use

   x/-5i ADDRESS

And the help for 'x' says:

  The specified number of objects of the specified size are printed
  according to the format.  If a negative number is specified, memory is
  examined backward from the address.

Note the last sentence.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to display instructions around the current instuction?
  2021-01-28 18:44     ` Andreas Schwab
@ 2021-01-29 17:38       ` Tavis Ormandy
  0 siblings, 0 replies; 27+ messages in thread
From: Tavis Ormandy @ 2021-01-29 17:38 UTC (permalink / raw)
  To: gdb

On 2021-01-28, Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Jan 28 2021, Peng Yu wrote:
>
>> There could be a syntax to go back a given number of instructions.
>
> How do you know how long each instruction is?
>

I just learned about the x/-5i syntax and had the same question. I
didn't look at the code but it does seem to know where the boundaries
are (e.g. if you start in the middle of an instruction).

I guess it must disassemble forward from a previous known location to
learn all the boundaries first?

Tavis.


-- 
 _o)            $ lynx lock.cmpxchg8b.com
 /\\  _o)  _o)  $ finger taviso@sdf.org
_\_V _( ) _( )  @taviso


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2021-01-29 17:40 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 23:12 How to display instructions around the current instuction? 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
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

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