Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB structure output

Tags:

c

gdb

I haven't worked with gdb for a long time and this feels like a basic question.

I am trying to observe a structure as it changes but rather than break at a specific point and print it out I'd rather let the application run as normal and give me a snapshot of the structure at a specific point. Think a breakpoint that performs an action (print struct) rather than pausing execution.

I am interested in looking at the changes to the structure all at once rather than incrementally. I can get what I want through printf, but gdb is much more elegant.

Update: Thank you for all the responses. I want to watch one struct at a particular point and the commands solution is just what I needed. This has been very helpful.

like image 397
Elsporko Avatar asked Dec 29 '22 13:12

Elsporko


1 Answers

A nice approach is to set a breakpoint with associated commands, e.g:

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

This runs the two commands print data_structure and continue whenever breakpoint 1 is reached.

like image 143
Cascabel Avatar answered Jan 05 '23 10:01

Cascabel