Is there a C debugger that lets you program breakpoints?

I am looking for something like this -

Set Breakpoint 1
Set Breakpoint 2
Disable Breakpoint 2
Set dbg_counter to 0
Increment dbg_counter everytime Breakpoint 1 is reached
If dbg_counter > 100:
   Enable (once) Breakpoint 2
   Set dbg_counter to 0

      

Note that "dbg_counter" is a variable that only the debugger knows about (ie, not part of the program being debugged).

+3


source to share


2 answers


Based on the information provided by @Thomas Padron-McCarthy about convenience variables , I was able to come up with the following GDB batch file to solve my problem -



break file.c:20
break file.c:35
disable 2
set $dbg_count = 0
commands 1
set $dbg_count += 1
if $dbg_count > 100 
enable once 2
set $dbg_count = 0
end
end
run

      

+2


source


From https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Vars.html :

GDB provides convenient variables that GDB can use to store a value and refer to it later. These variables exist entirely within GDB; they are not part of your program and the convenience variable has no direct effect on the further execution of your program.



A convenience variable can be used with a break condition to ignore the breakpoint a specified number of times. But there is an easier way to do it. From https://sourceware.org/gdb/current/onlinedocs/gdb/Conditions.html :

A special case of a breakpoint condition is to stop only when the breakpoint has been hit a certain number of times. This is so useful that there is a special way to do it using the ignore breakpoint count. Each breakpoint has an ignore count, which is an integer. In most cases, the ignore counter is zero and therefore has no effect. But if your program reaches a breakpoint whose ignore count is positive, then instead of stopping, it simply reduces the ignore count by one and continue. As a result, if the value of the ignore count is n, the breakpoint does not stop the next n times your program reaches it.

+6


source







All Articles