Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 467
Lord Bo Avatar asked Dec 18 '12 14:12

Lord Bo


People also ask

How do you set a breakpoint in GDB at a specific line?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

Which GDB command can be used to put a breakpoint at the beginning of the program?

Explanation: None. 8. Which GDB command can be used to put a breakpoint at the beginning of the program? Explanation: None.

What is the GDB command to set a breakpoint in line 7?

c file listed in Example 7.1, “Compiling a C Program With Debugging Information” with debugging information, you can set a new breakpoint at line 7 by running the following command: (gdb) break 7 Breakpoint 2 at 0x4004e3: file fibonacci.

What does breakpoint do in GDB?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.


1 Answers

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.

like image 80
borrible Avatar answered Nov 09 '22 10:11

borrible