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
538 views
in Technique[技术] by (71.8m points)

gdb scripting: execute commands at selected breakpoint

I'd like to predefine some breakpoints in a gdb script and to invoke some special commands at these breakpoints and afterwards to automatically continue the program execution. So, ideally, I'd like to have a gdb script like the following:

b someFunction
...
if breakpoint from above reached do:
  print var1
  call someOtherFunction
  continue
done

Additionally an unfortunate fact is, that I can't rely on the python interface for using breakpoints, as the gdb version at the server I currently work at is too old!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You should take a look at the command command, which enables you to add gdb commands as a breakpoint is hit. See the breakpoint command list section of the gdb manual.

For example:

break someFunction
commands
print var1
end

will, when the breakpoint on someFunction is hit, automatically print var1.


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

...