GDB structure output

I have not worked with gdb for a long time, and this seems like a basic question.

I try to observe the structure as it changes, but instead of breaking down at a specific point and printing it out, I would rather have the application run as usual and give me a snapshot of the structure at a specific point. Think of a breakpoint that executes an action (print struct) rather than pausing execution.

I am interested in looking at changes in structure immediately, rather than gradually. I can get what I want through printf, but gdb is much more elegant.

Update: Thanks for all the answers. I want to look at one structure in a certain place, and the decision of the teams is what I need. It was very helpful.

+4
source share
2 answers

A good approach is to set a breakpoint with the appropriate commands, for example:

break main.c:100 commands 1 print data_structure continue end 

Executes two print data_structure and continue commands when breakpoint 1 is reached.

+8
source

If the information stored in your data structure can be changed with a few lines of code, you can also use gdb watch . Note that this is terribly slow, so it should be used carefully. Some teams are the same.

 (gdb) break main Breakpoint 1 at 0x80483b5: (gdb) run Breakpoint 1, main () (gdb) watch data_structure Hardware watchpoint 2: data_structure (gdb) commands 2 Type commands for when breakpoint 2 is hit, one per line. End with a line saying just "end". > print data_structure > continue > end (gdb) continue 
+2
source

All Articles