I need to debug a certain set of commands each time i invoke gdb – so I decided to put them in my .gdbinit. Everything was fine , till i decided to use commands (to execute a certain set of gdb commands each time a certain brkpt is hit). My script looks is as follows:
define setup
handle SIGTRAP noprint nostop
br 'Class1::Fun1(void)'
run
br 'Class2::Run(void)'
c
br Function2
commands 3
return 0
c
end
end
Problem is , whenever I execute them one by one , it behaves perfectly , but when i source the script and run setup , it behaves weirdly after the commands (does not do what was previously doing).
Can anyone help ?
You are probably not placing the commands on the breakpoint you think you are.
If I were you, I’d modify the script to the following:
If no breakpoint target is given,
commandsassociates with the most recent breakpoint. This way, no matter what other breakpoints you have in your gdb session, your commands will be associated with the breakpoint at Function2.