Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 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 Reply

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...