- Compile your program using debug. If you want to use gdb, you have to compile your code using '-g' flag. It will tell the compiler to store the debug information in object file. It describes the data type of each variable or function.
g++ -g test.cxx -o test - Run your program.
Quit your program.
gdb test
quit ; or Ctrl + D - Set up break points.
> b 19 // break at line 19 at a file
> b func1 // break at func1
> b testClass::testFunc(int) // C++ is polymorphic. you must tell break which version of the function you want to break on
> info breakpoints // can print out all the break points - Use backtrace.
backtrace
You can see many frames related the point.
#0 std::string::assign (this=0xd3d704c, __str=@0xfd0d05)
#1 0x00e4e524 in std::string::operator= (this=0xd3d704c, __str=@0xfd0d05)
#2 0x065692d4 in IssueSeverity (this=0xd3d7048, rhs=@0xfd0d01)
#3 0x0656831f in StatusCode::cloneSeverity (sev=0xfd0d01) at ../src/Lib/StatusCode.cpp:28
#4 0x0317eb29 in StatusCode (this=0xbff07888, rhs=@0xbff077a4)
#5 0xb7947250 in ?? ()
#6 0xbff07888 in ?? ()
#7 0xbff077a4 in ?? ()
#8 0x00000000 in ?? ()
You can take a look at the detail of one frame.
frame 1
info frame
info locals
info args
links