I need to check a variable to find out if it is set correctly, which might be happening after several loops.
What I am doing now is something like follows:
(gdb) b myfile.cpp:180
(gdb) c
(gdb) p decoder.m_msg
(gdb) c
(gdb) p decoder.m_msg
(gdb) c
...
Can I have this variable decoder.m_msg
automatically printed every time the program breaks?
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).
Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.
With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers. It is not necessary to delete a breakpoint to proceed past it.
You can create variables in the context of gdb for your convenience, like set $foo = ... and later reference $foo . Obviously such variables are in no way visible to the running code, however. it's not only for inspection. you can change variable values in gdb: stackoverflow.com/questions/3305164/….
Use the display
command:
(gdb> display decoder.m_msg
This will cause decoder.m_msg
to be printed every time that the prompt is shown (not only after a breakpoint).
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