For example, I have a function NamespaceA::ClassB::FunctionC() in my program. I know I can ask GDB to break there, by "break NamespaceA::ClassB::FunctionC". But what should I do if I only want GDB to break there, after this function is called, say, 100 times?
I think a workaround solution is adding one more variable in the program, and then there is "break ... if cond" command in GDB i can use. But can i achieve the same thing without adding variables to my program?
Thank you.
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.
You should interrupt the process that is attached by gdb. Do not interrupt gdb itself. Interrupt the process by either ctrl-c in the terminal in which the process was started or send the process the SIGINT by kill -2 procid. With procid the id of the process being attached.
Like you can cancel a program on the command line, GDB lets you use ctrl-c to stop a program wherever it currently is. Hit ctrl-c now to break the infinite loop.
It is often useful to do ' display/i $pc ' when stepping by machine instructions. This makes GDB automatically display the next instruction to be executed, each time your program stops. See Automatic Display.
(gdb) continue 100
should do the trick
(gdb) help continue Continue program being debugged, after signal or breakpoint. If proceeding from breakpoint, a number N may be used as an argument, which means to set the ignore count of that breakpoint to N – 1 (so that the breakpoint won’t break until the Nth time it is reached).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With