How to write commands in a GDB script that are executed every time a particular brkpt hits?

I need to debug a specific set of commands every time I call gdb, so I decided to put them in my .gdbinit. Everything was fine as long as I decided to use commands(to execute a specific set of gdb commands every time a specific brkpt hits). My view of the script 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

, he behaves strangely after commands (does not do what was done earlier).

Can anyone help?

+3
source share
1 answer

You probably are not placing the teams at the breakpoint you are thinking about.

If I were you, I would change the script to the following:

define setup
   handle SIGTRAP noprint nostop
   br 'Class1::Fun1(void)'
   run
   br 'Class2::Run(void)'
   c
   br Function2
   commands
     return 0 
     c
   end
end

, commands . , , gdb, Function2.

+1

Source: https://habr.com/ru/post/1731976/


All Articles