I wondered to a colleague if there is a way to get GDB to print the value of a variable when it changes or when a certain program location is reached without breaking; in effect, placing printfs in my program automatically.
His Google-foo was better than mine he and found a stackoverflow solution. For example, something like
set pagination off break foo.c:42 commands silent print x cont end
prints the value of x whenever line 42 in file foo.c is reached, but just keeps running the program. You can stick a little script like this in your .gdbinit file, which you can reload with
source .gdbinit
This is particularly useful if you’re debugging a remote target that doesn’t support print statements. It’s a cool trick for embedded systems debugging.