Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to control number of disassembly lines displayed when single-stepping

4 views
Skip to first unread message

Frank

unread,
Feb 1, 2012, 2:38:22 PM2/1/12
to
Dear GDB users/hackers,

I was wondering if anyone could help with the following problem.

I have a short script that generates an instruction-by-instruction
execution trace of a program. However, as the script executes the
"stepi" command in a loop, GDB displays several lines of disassembled
machine code at each step instead of just the precise intruction being
executed (which is indicated by a =>). I understand this is precisely
what is desired in most cases, but I would like to get GDB to only
display the line being executed (this makes for a smaller execution
log file).

So, is there a way to control the number of context lines given when
stepping through disassembled code? An environmental variable or
control parameter of some sort? Much appreciated if you have the
answer.

So you know, I have googled this in depth, but was unsuccessful
finding an answer.

The script and a segment of the output are below.

Thanks in advance,

F.

SCRIPT:

set disassemble-next-line on
set arm disassembler std

break main
enable 1
info break

continue

while (1)
si
end

OUTPUT:

557 Next_Ptr_Glob = (Rec_Pointer) &x;
=> 0x000082ec <main+20>: 2c 32 04 e3 movw r3,
#16940 ; 0x422c
0x000082f0 <main+24>: 01 30 40 e3 movt r3, #1
0x000082f4 <main+28>: 90 20 4b e2 sub r2, r11,
#144 ; 0x90
0x000082f8 <main+32>: 00 20 83 e5 str r2, [r3]
0x000082f0 557 Next_Ptr_Glob = (Rec_Pointer) &x;
0x000082ec <main+20>: 2c 32 04 e3 movw r3,
#16940 ; 0x422c
=> 0x000082f0 <main+24>: 01 30 40 e3 movt r3, #1
0x000082f4 <main+28>: 90 20 4b e2 sub r2, r11,
#144 ; 0x90
0x000082f8 <main+32>: 00 20 83 e5 str r2, [r3]
0x000082f4 557 Next_Ptr_Glob = (Rec_Pointer) &x;
0x000082ec <main+20>: 2c 32 04 e3 movw r3,
#16940 ; 0x422c
0x000082f0 <main+24>: 01 30 40 e3 movt r3, #1
=> 0x000082f4 <main+28>: 90 20 4b e2 sub r2, r11,
#144 ; 0x90
0x000082f8 <main+32>: 00 20 83 e5 str r2, [r3]
0x000082f8 557 Next_Ptr_Glob = (Rec_Pointer) &x;
0x000082ec <main+20>: 2c 32 04 e3 movw r3,
#16940 ; 0x422c
0x000082f0 <main+24>: 01 30 40 e3 movt r3, #1
0x000082f4 <main+28>: 90 20 4b e2 sub r2, r11,
#144 ; 0x90
=> 0x000082f8 <main+32>: 00 20 83 e5 str r2, [r3]
558 Ptr_Glob = (Rec_Pointer) &y;
=> 0x000082fc <main+36>: 38 32 04 e3 movw r3,
#16952 ; 0x4238
0x00008300 <main+40>: 01 30 40 e3 movt r3, #1
0x00008304 <main+44>: c0 20 4b e2 sub r2, r11,
#192 ; 0xc0
0x00008308 <main+48>: 00 20 83 e5 str r2, [r3]
0x00008300 558 Ptr_Glob = (Rec_Pointer) &y;
0x000082fc <main+36>: 38 32 04 e3 movw r3,
#16952 ; 0x4238
=> 0x00008300 <main+40>: 01 30 40 e3 movt r3, #1
0x00008304 <main+44>: c0 20 4b e2 sub r2, r11,
#192 ; 0xc0
0x00008308 <main+48>: 00 20 83 e5 str r2, [r3]

etc....

Pedro Alves

unread,
Mar 29, 2012, 5:04:59 AM3/29/12
to Frank, bug...@gnu.org
On 02/01/2012 07:38 PM, Frank wrote:

> I have a short script that generates an instruction-by-instruction
> execution trace of a program. However, as the script executes the
> "stepi" command in a loop, GDB displays several lines of disassembled
> machine code at each step instead of just the precise intruction being
> executed (which is indicated by a =>). I understand this is precisely
> what is desired in most cases, but I would like to get GDB to only
> display the line being executed (this makes for a smaller execution
> log file).
>
> So, is there a way to control the number of context lines given when
> stepping through disassembled code? An environmental variable or
> control parameter of some sort? Much appreciated if you have the
> answer.


There's no such knob.

But instead of disassemble-next-line, you can do:

(gdb) display /i $pc

This only prints the insn at the current PC, but, also prints "1: x/i $pc" at
every step.

The best solution I can think of is to use the hook-stop (a hook that runs
every time the program stops)

(gdb) define hook-stop
> x/i $pc
>end

(gdb) si
=> 0x455197 <main+19>: movq $0x0,(%rax)
0x0000000000455197 29 memset (&args, 0, sizeof args);
(gdb) <enter>
=> 0x45519e <main+26>: movq $0x0,0x8(%rax)
0x000000000045519e 29 memset (&args, 0, sizeof args);
(gdb) <enter>
=> 0x4551a6 <main+34>: movq $0x0,0x10(%rax)
0x00000000004551a6 29 memset (&args, 0, sizeof args);
(gdb) <enter>
=> 0x4551ae <main+42>: movq $0x0,0x18(%rax)
0x00000000004551ae 29 memset (&args, 0, sizeof args);
(gdb)

--
Pedro Alves

0 new messages