Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

dynamic - How to print the next N executed lines automatically in GDB?

I have been trying to find a way for some time to automate the progress in GDB of tracing the control flow of a program.

Even just a simple way of automating the n command so you can see in what order routines are called.

I realise that you can issues n x where x is the number of times GDB steps through, but the trouble with that is that it shows the command but not the address of the routine! But if you press n manually in GDB (then press return to issue the previous command) it shows the address.

I have tried the following in GDB:

(after setting a breakpoint at say 0x0123456)
b *0x0123456

GDB says <breakpoint 1 at 0x123456>. I type:

commands 1
n 1000
c
end

but it doesn't loop as expected, and it doesn't show the address location :-(.

Any help would be appreciated! Surely it must be simple to automatically log the order routines are called??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is easy, actually. I'll give you the bare bones, and you can modify to suit.

(gdb) define nstep
> set $foo = $arg0
> while ($foo--)
>  step
>  end
> end
(gdb) nstep 100

I've done this many times. Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...