Note: This web page was automatically created from a PalmOS "pedit32" memo.

Debugger notes


Nice gdb command: thread apply all bt
(gdb) where #0 0x405743df in strftime (s=0xbfffeaf0 "8\uffff \b\uffffo!\b\030\uffff\uffff\uffffG@E\002", maxsize=100, format=0x0, tp=0x40612380) at strftime.c:603 #1 0x080944c2 in jp_strftime (s=0xbfffeaf0 "8\uffff \b\uffffo!\b\030\uffff\uffff\uffffG@E\002", max=100, format=0xbfffea80 "\u7bc1\212\uffff\227\u30e3\201\uffff %A, %B%d\u65e5,%Y\u5e74 %I:%M:%S %p", tm=0x40612380) at utils.c:3003 #2 0x0808ffe3 in timeout_date (data=0x0) at utils.c:202 #3 0x0806ae31 in datebook_gui (vbox=0x8220800, hbox=0x82105c8) at datebook_gui.c:4089 #4 0x080755d4 in main (argc=1, argv=0xbffff984) at jpilot.c:2675 #5 0x404eec1f in __libc_start_main (main=0x8073cd8 <main>, argc=1, ubp_av=0x1, init=0x8095274 <__libc_csu_init>, fini=0x80952bc <__libc_csu_fini>, rtld_fini=0x400144a0 <_rtld_local>, stack_end=0x0) at ../sysdeps/generic/libc-start.c:225
1) If your program is not already compiled with debugging symbols in it, please add them, in one of the following ways: 1a) If you are using a vendor C compiler, like xlc, then please add "-g" to all of your xlc invocations, both compile and link. 1b) If you are using gcc, please do the same, but you can use -g or -ggdb in most cases. -ggdb is supposed to provide better information, I believe 2) Run your program again. 3) Locate the resulting core file. If none was produced, you may have to use "ulimit -c 8192" in a POSIX shell (sh/ksh/bash) to get a core file to be created. csh/tcsh can do the same, but the syntax is different. 4) cd to the directory containing the core file 5) Run one of the following commands: 5a) gdb myprog core 5b) dbx myprog core 6) Get a "backtrace" using one of the following commands: 6a) Under gdb, use "thread apply all bt" and/or "where" 6b) Under dbx, use "where" and "dump" 6c) In both of these debuggers, you can examine variables
Single stepping in AIX 5.1 dbx: esmf04m-strombrg> dbx ./t Type 'help' for help. reading symbolic information ... (dbx) list 1 #include <stdio.h> 2 3 int main() 4 { 5 fn1(); 6 return 0; 7 } 8 9 int fn1() 10 { (dbx) stop 5 expected variable, found 5 (dbx) stop at 5 [1] stop at 5 (dbx) run [1] stopped in main at line 5 5 fn1(); (dbx) list 6 return 0; 7 } 8 9 int fn1() 10 { 11 fn2(); 12 } 13 14 int fn2() 15 { (dbx) step stopped in fn1 at line 11 11 fn2(); (dbx) list 1,100 1 #include <stdio.h> 2 3 int main() 4 { 5 fn1(); 6 return 0; 7 } 8 9 int fn1() 10 { 11 fn2(); 12 } 13 14 int fn2() 15 { 16 int i; 17 char *p=NULL; 18 printf("hello\n"); 19 for (i=0; i<100; i++) 20 { 21 if (i > 50) 22 { 23 *(p) = '\0'; 24 } 25 } 26 } 27 28 (dbx) step stopped in fn2 at line 17 17 char *p=NULL; (dbx) step stopped in fn2 at line 18 18 printf("hello\n"); (dbx) print p (nil) (dbx) print i -1159983106 (dbx)
oracle's opensource projects page has a "gdb pstack" that can get a stack trace of a running program
Nice table comparing gdb and sun dbx: http://www.fortran-2000.com/ArnaudRecipes/CompGdbDbx.html
Using dbx to break at a specific point in a large C++ program: esmf04m-root> dbx ../../netcdf-handler/src/dap_nc_handler Type 'help' for help. reading symbolic information ... (dbx) help file file file <filename> Change the current source file name to <filename>. If none is specified then the current source file name is printed. (dbx) file InternalErr.cc (dbx) stop in InternalErr::InternalErr 1. InternalErr.InternalErr::InternalErr(const InternalErr&) 2. InternalErr.InternalErr::InternalErr() 3. InternalErr.InternalErr::InternalErr(std::basic_string<char,std::char_traits<char>,std::allocator<char> >,ProgramType,char*) 4. InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&,const int&,const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) 5. InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) Select one or more of [1 - 5]: 1,2,3,4,5 [1] stop in InternalErr.InternalErr::InternalErr(const InternalErr&) [2] stop in InternalErr.InternalErr::InternalErr() [3] stop in InternalErr.InternalErr::InternalErr(std::basic_string<char,std::char_traits<char>,std::allocator<char> >,ProgramType,char*) [4] stop in InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&,const int&,const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) [5] stop in InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) (dbx) run -v DAP2/3.5.1 -o dds -u http://esmf.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata/in.nc /usr/local/apache-2.0.55/htdocs/dodsdata/in.nc -r /usr/tmp [5] stopped in InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) at line 55 in file "InternalErr.cc" ($t1) 55 InternalErr::InternalErr(const string &msg) : Error() (dbx) list 50,60 50 InternalErr::InternalErr() : Error() 51 { 52 _error_code=internal_error; 53 } 54 55 InternalErr::InternalErr(const string &msg) : Error() 56 { 57 _error_code=internal_error; 58 _error_message=""; 59 _error_message+="An internal error was encountered:\n"; 60 _error_message+=msg+"\n"; (dbx) where InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&)(this = 0x0ffffffffff60510, msg = &(...)), line 55 in "InternalErr.cc" unnamed block $b2885, line 501 in "BaseType.cc" unnamed block $b2884, line 501 in "BaseType.cc" set_parent(BaseType*)(0x110223390, 0x110223230), line 501 in "BaseType.cc" unnamed block $b3163, line 897 in "Vector.cc" unnamed block $b3161, line 897 in "Vector.cc" add_var(BaseType*,Part)(0x110223230, 0x110223130, 0x0), line 897 in "Vector.cc" add_var(BaseType*,Part)(0x110223230, 0x110223130, 0x0), line 173 in "Array.cc" unnamed block $b190, line 228 in "ncdds.cc" unnamed block $b188, line 228 in "ncdds.cc" read_class(DDS&,int,int,std::basic_string<char,std::char_traits<char>,std::allocator<char> >*)(0xfffffffffffefe8, 0x300000003, 0x1600000016, 0x9000000014f7eb0), line 228 in "ncdds.cc" unnamed block $b201, line 304 in "ncdds.cc" read_descriptors(DDS&,const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&)(0xfffffffffffefe8, 0xffffffffffff110), line 304 in "ncdds.cc" unnamed block $b216, line 71 in "nc_handler.cc" unnamed block $b213, line 71 in "nc_handler.cc" main(argc = 10, argv = 0x0ffffffffffff668), line 71 in "nc_handler.cc" (dbx) dump InternalErr.InternalErr::InternalErr(const std::basic_string<char,std::char_traits<char>,std::allocator<char> >&)(this = 0x0ffffffffff60510, msg = _String_base:() _String_val<char,std::allocator<char> >:(_Alval = ()) (_Ptr = "Call to set_parent with incorrect variable type.", _Len = 48, _Res = 63)), line 55 in "InternalErr.cc" (dbx)


Back to Dan's palm memos