August 2, 2006 - Debugging session with Ralf ***************************************************************************** gdb *** gdb executable_file_name (gdb RuleRefinement) OR BETTER: open emacs window and run gdb from there: M-x gdb [ENTER] Run gdb (like this): gdb RuleRefinement [ENTER] run In general, after the first enter, type the ExecutableFileName and [enter] and then type "run" on the command line Split emacs window into two (Ctrl-x 2) and if the program has crashed, start typing "up" until a function name is called, and gdb will automatically open the right file indicating where it crashed on the other partition! Useful Commands: run up (to see what function called this) down (to continue running one step at a time) break function_name | file_name: line-num print variable_name (*this) GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: - Start your program, specifying anything that might affect its behavior. - Make your program stop on specified conditions. - Examine what has happened, when your program has stopped. - Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. Example: ... break 'CorrectionInstance::GetCTLSentence()' Function "CorrectionInstance::GetCTLSentence()" not defined. (gdb) up #1 0x400acf4c in std::string::string(std::string const&) () from /usr/lib/libstdc++.so.5 (gdb) up #2 0x080622dc in CorrectionInstance::GetCTLSentence() const (this=0x826c130) at CorrectionInstance.cpp:1664 (gdb) #3 0x0804eccb in main (argc=1, argv=0xbffff974) at RuleRefinement.cpp:338 warning: Source file is more recent than executable. (gdb) down #2 0x080622dc in CorrectionInstance::GetCTLSentence() const (this=0x826c130) at CorrectionInstance.cpp:1664 (gdb) print *this $1 = { = {_vptr.RefCountedObject = 0x8270b18, m_cRef = 0}, Parse = {static npos = 4294967295, _M_dataplus = {> = {}, _M_p = 0x826c130 "\030\v'\b"}, static _S_empty_rep_storage = {0, 0, 0, 0}}, m_tree = {Tokenize = {}, Root = 0x8280e64, m_CStructure = {static npos = 4294967295, _M_dataplus = {> = {}, _M_p = 0x826c8c0 "(\204$\b"}, static _S_empty_rep_storage = {0, 0, 0, 0}}, m_vLeaves = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x0, _M_finish = 0x52, _M_end_of_storage = 0x12}, }, }}, SLS = {static npos = 4294967295, _M_dataplus = {> = {}, _M_p = 0x12
}, static _S_empty_rep_storage = {0, 0, 0, 0}}, SLWords = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x2, _M_finish = 0x20756f79, _M_end_of_storage = 0x20776173}, }, }, TLS = {static npos = 4294967295, _M_dataplus = {> = {}, _M_p = 0x20656874
}, static _S_empty_rep_storage = {0, 0, 0, 0}}, TLWords = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x616d6f77, _M_finish = 0x206e, _M_end_of_storage = 0x826fd10}, }, }, CTLS = {static npos = 4294967295, _M_dataplus = {> = {}, _M_p = 0x0}, static _S_empty_rep_storage = {0, 0, 0, 0}}, CTLWords = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x826c170, _M_finish = 0x826c170, _M_end_of_storage = 0x827d7fc}, }, }, Actions = {<_Vector_base >> = {<_Vector_alloc_base,true>> = {_M_start = 0x827c400, _M_finish = 0x0, _M_end_of_storage = 0x0}, }, }, m_IDs = {<_Vector_base, std::allocator >,std::allocator, std::allocator > > >> = {<_Vector_alloc_base, std::allocator >,std::allocator, std::allocator > >,true>> = { _M_start = 0x826b670, _M_finish = 0x0, _M_end_of_storage = 0x826c190}, }, }, m_fLeadToRefinement = 144, m_fIncreasedMTAccuracy = 193, m_fContainsDependentErrors = 38, m_fCDEDirty = 8, m_cNumNonAlignActions = 136775572} (gdb) _M_dataplus = {> = {}, _M_p = 0x0}, Undefined command: "". Try "help". (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y ***************************************************************************** tags: easy way to find fucntions and files while debugging **** M-x visit-tags-table M-x find-tag: FileName|FuntionName ***************************************************************************** valgrind ******** Valgrind is a GPL'd system for debugging and profiling Linux programs. With Valgrind's tool suite you can automatically detect many memory management and threading bugs, avoiding hours of frustrating bug-hunting, making your programs more stable. You can also perform detailed profiling to help speed up your programs. downloaded, compiled and installed valgrind, which is a program to check memory leaks (/usr0/aria/RuleRefinement/bin), added it to the V0.07 path [aria@avenue V0.07]$ ../bin/valgrind-3.2.0/coregrind/valgrind --leak-check=full --show-reachable=yes ./RuleRefinement > & ! OutputValgrind