Can gdb print a specific variable every time it breaks?

I need to check the variable to see if it is set correctly, which can happen after several cycles.

What I'm doing now is as follows:

(gdb) b myfile.cpp:180 (gdb) c (gdb) p decoder.m_msg (gdb) c (gdb) p decoder.m_msg (gdb) c ... 

Is it possible to automatically print this variable decoder.m_msg at each program break?

+8
gdb
source share
2 answers

Yes, with a list of breakpoint commands :

 $ break myfile.cpp:180 Breakpoint 1 at 0x46ba0e: file myfile.cpp, line 180. $ commands 1 > print decoder.m_msg > end $ 
+10
source share

Use the display command:

 (gdb> display decoder.m_msg 

This will cause decoder.m_msg be printed every time the prompt is displayed (not just after the breakpoint).

+17
source share

All Articles