Lord Bo
Lord Bo

Reputation: 3298

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!

Upvotes: 47

Views: 41007

Answers (1)

borrible
borrible

Reputation: 17336

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.

Upvotes: 64

Related Questions