From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlo Wood To: Jim Blandy Cc: gdb@sources.redhat.com Subject: Re: RFC c++ debugging thread (fwd) Date: Tue, 31 Jul 2001 21:31:00 -0000 Message-id: <20010801063059.A12350@alinoe.com> References: <20010704141527.B17190@alinoe.com> X-SW-Source: 2001-07/msg00424.html Hi again... here's a typical gdb session; I am trying to find a bug (obviously) and getting VERY frustrated at the moment. Problem at hand: ~/c++/libcw/src/libcwd/MegaHALv9r1/objs>./MegaHAL++ IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.org __ __ _ _ _ _ ___ | \/ | ___ __ _ __ _| | | | / \ | | __ __/ _ \ | |\/| |/ _ \/ _` |/ _` | |_| | / _ \ | | \ \ / / (_) | | | | | __/ (_| | (_| | _ |/ ___ \| |___ \ V / \__, | |_| |_|\___|\__, |\__,_|_| |_/_/ \_\_____| \_/ /_/r1 |___/ Copyright(C) 1998 Jason Jutchens Copyright(C) 2000 Orlando Bassotto -Logo Designed by Daniele Nicolucci- ------------------------------------------------------------ BFD : Calling libcw::debug::dlopen "(nil)". MALLOC : malloc(13) = BFD : Warning: Address 0x400073b1 in section .text does not have a line number, perhaps the unit containing the function `_dl_dst_substitute' wasn't compiled with flag -g MALLOC : 0x813f440 MALLOC : calloc(416, 1) = BFD : Warning: Address 0x4000bcfc in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x8248de0 MALLOC : malloc(25) = BFD : Warning: Address 0x4000bd0d in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81ff670 MALLOC : malloc(141) = BFD : Warning: Address 0x4000be49 in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81fed80 MALLOC : malloc(212) = BFD : address 0x4000cfcc corresponds to dl-deps.c:495 MALLOC : 0x8248f90 MALLOC : calloc(6, 16) = BFD : address 0x4000ef89 corresponds to dl-version.c:286 MALLOC : 0x804f280 MALLOC : malloc(84) = BFD : Warning: Address 0x40366d57 in section .text does not have a line number, perhaps the unit containing the function `getutmpx' wasn't compiled with flag -g MALLOC : 0x8200648 Segmentation fault (core dumped) Now I start the gdb session: ~/c++/libcw/src/libcwd/MegaHALv9r1/objs>gdb ./MegaHAL++ core GNU gdb 5.0rh-5 Red Hat Linux 7.1 Copyright 2001 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"... Core was generated by `./MegaHAL++ IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o'. Program terminated with signal 11, Segmentation fault. Error while mapping shared library sections: libMegaHAL++.so: Success. Error while mapping shared library sections: IRCPlugin.so: Success. Reading symbols from /usr/lib/libreadline.so.4.1...done. Loaded symbols for /usr/lib/libreadline.so.4.1 Reading symbols from /usr/lib/libncurses.so.5...done. Loaded symbols for /usr/lib/libncurses.so.5 Reading symbols from libMegaHAL++.so...done. Loaded symbols for libMegaHAL++.so Reading symbols from /lib/libdl.so.2...done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /home/carlo/c++/libcw/src/libcwd/.libs/libcwd.so.0...done. Loaded symbols for /home/carlo/c++/libcw/src/libcwd/.libs/libcwd.so.0 Reading symbols from /usr/lib/libbfd-2.10.91.0.2.so...done. Loaded symbols for /usr/lib/libbfd-2.10.91.0.2.so Reading symbols from /usr/local/gcc-3.0/lib/libstdc++.so.3...done. Loaded symbols for /usr/local/gcc-3.0/lib/libstdc++.so.3 Reading symbols from /lib/libm.so.6...done. Loaded symbols for /lib/libm.so.6 Reading symbols from /usr/local/gcc-3.0/lib/libgcc_s.so.1...done. Loaded symbols for /usr/local/gcc-3.0/lib/libgcc_s.so.1 Reading symbols from /lib/libc.so.6...done. Loaded symbols for /lib/libc.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Reading symbols from IRCPlugin.so...done. Loaded symbols for IRCPlugin.so #0 0x400ed869 in std::ostream::sentry::sentry(std::ostream&) (this=0xbffff290, __os=@0x10) at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:39 39 : _M_ok(__os.good()), _M_os(__os) The reason for the core dump is no doubt that __os==@0x10. Question: Why? (gdb) up #1 0x400eefe2 in std::ostream::flush() (this=0x10) at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:385 385 sentry __cerb(*this); (gdb) up #2 0x400ed8c5 in std::ostream::sentry::sentry(std::ostream&) (this=0xbffff2f8, __os=@0x820a9e0) at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:43 43 __os.tie()->flush(); Apparently tie() returns 0x10. Question: Why? (gdb) p __os $1 = (basic_ostream > &) @0x820a9e0: { >> = , _vptr. = 0x81ffa58} Well, that didn't help. Lets try stepping to this point. (gdb) b 43 Breakpoint 1 at 0x400ed8a6: file /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc, line 43. (gdb) r IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o Starting program: /home/carlo/c++/libcw/src/libcwd/MegaHALv9r1/objs/./MegaHAL++ IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o Error while mapping shared library sections: libMegaHAL++.so: Success. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. __ __ _ _ _ _ ___ | \/ | ___ __ _ __ _| | | | / \ | | __ __/ _ \ | |\/| |/ _ \/ _` |/ _` | |_| | / _ \ | | \ \ / / (_) | | | | | __/ (_| | (_| | _ |/ ___ \| |___ \ V / \__, | |_| |_|\___|\__, |\__,_|_| |_/_/ \_\_____| \_/ /_/r1 |___/ Copyright(C) 1998 Jason Jutchens Copyright(C) 2000 Orlando Bassotto -Logo Designed by Daniele Nicolucci- ------------------------------------------------------------ BFD : Calling libcw::debug::dlopen "(nil)". MALLOC : malloc(13) = BFD : Warning: Address 0x400073b1 in section .text does not have a line number, perhaps the unit containing the function `_dl_dst_substitute' wasn't compiled with flag -g MALLOC : 0x81e6dc8 MALLOC : calloc(416, 1) = BFD : Warning: Address 0x4000bcfc in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x8253e00 MALLOC : malloc(25) = BFD : Warning: Address 0x4000bd0d in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81fcee8 MALLOC : malloc(141) = BFD : Warning: Address 0x4000be49 in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81fc5f8 MALLOC : malloc(212) = BFD : address 0x4000cfcc corresponds to dl-deps.c:495 MALLOC : 0x8253fb0 MALLOC : calloc(6, 16) = BFD : address 0x4000ef89 corresponds to dl-version.c:286 MALLOC : 0x804f280 Error while mapping shared library sections: IRCPlugin.so: Success. MALLOC : malloc(84) = BFD : Warning: Address 0x40366d57 in section .text does not have a line number, perhaps the unit containing the function `getutmpx' wasn't compiled with flag -g MALLOC : 0x80508d0 Program received signal SIGSEGV, Segmentation fault. 0x400ed869 in std::ostream::sentry::sentry(std::ostream&) (this=0xbffff270, __os=@0x10) at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:39 39 : _M_ok(__os.good()), _M_os(__os) Ok, what happened with my breakpoint? Perhaps I need to do it in steps? (gdb) d 1 (gdb) b main Breakpoint 2 at 0x8049c33: file src/MegaHAL++.cpp, line 129. (gdb) r IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/carlo/c++/libcw/src/libcwd/MegaHALv9r1/objs/./MegaHAL++ IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o Error while mapping shared library sections: libMegaHAL++.so: Success. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Error in re-setting breakpoint 1: No source file named /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc. Breakpoint 2, main (argc=8, argv=0xbffff5bc) at src/MegaHAL++.cpp:129 129 Debug( dc::notice.on() ); // Turn on the NOTICE Debug Channel (gdb) b ostream.tcc:43 Breakpoint 3 at 0x400ed8a6: file /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc, line 43. (gdb) c Continuing. __ __ _ _ _ _ ___ | \/ | ___ __ _ __ _| | | | / \ | | __ __/ _ \ | |\/| |/ _ \/ _` |/ _` | |_| | / _ \ | | \ \ / / (_) | | | | | __/ (_| | (_| | _ |/ ___ \| |___ \ V / \__, | |_| |_|\___|\__, |\__,_|_| |_/_/ \_\_____| \_/ /_/r1 |___/ Copyright(C) 1998 Jason Jutchens Copyright(C) 2000 Orlando Bassotto -Logo Designed by Daniele Nicolucci- ------------------------------------------------------------ BFD : Calling libcw::debug::dlopen "(nil)". MALLOC : malloc(13) = BFD : Warning: Address 0x400073b1 in section .text does not have a line number, perhaps the unit containing the function `_dl_dst_substitute' wasn't compiled with flag -g MALLOC : 0x81e6dc8 MALLOC : calloc(416, 1) = BFD : Warning: Address 0x4000bcfc in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x8253e00 MALLOC : malloc(25) = BFD : Warning: Address 0x4000bd0d in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81fcee8 MALLOC : malloc(141) = BFD : Warning: Address 0x4000be49 in section .text does not have a line number, perhaps the unit containing the function `_dl_lookup_versioned_symbol_skip' wasn't compiled with flag -g MALLOC : 0x81fc5f8 MALLOC : malloc(212) = BFD : address 0x4000cfcc corresponds to dl-deps.c:495 MALLOC : 0x8253fb0 MALLOC : calloc(6, 16) = BFD : address 0x4000ef89 corresponds to dl-version.c:286 MALLOC : 0x804f280 Error while mapping shared library sections: IRCPlugin.so: Success. MALLOC : malloc(84) = BFD : Warning: Address 0x40366d57 in section .text does not have a line number, perhaps the unit containing the function `getutmpx' wasn't compiled with flag -g MALLOC : 0x80508d0 Breakpoint 3, std::ostream::sentry::sentry(std::ostream&) (this=0xbffff2d8, __os=@0x8207fd8) at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:43 43 __os.tie()->flush(); Ok, that worked. (gdb) p __os $2 = (basic_ostream > &) @0x8207fd8: { >> = , _vptr. = 0x81fd2d0} Still no luck. Not wanting to take any risk, lets use 'si': (gdb) si 0x400ed8a9 43 __os.tie()->flush(); (gdb) 0x400ed8ac 43 __os.tie()->flush(); (gdb) 0x400ed8ae 43 __os.tie()->flush(); (gdb) 0x400ed8b1 43 __os.tie()->flush(); (gdb) 0x400ed8b3 43 __os.tie()->flush(); (gdb) 0x400ed8b6 43 __os.tie()->flush(); (gdb) 0x400ed8b7 43 __os.tie()->flush(); (gdb) 0x400d16a8 in _init () from /home/carlo/c++/libcw/src/libcwd/.libs/libcwd.so.0 (gdb) std::basic_ios >::tie() const (this=0xbffff2d8) at /usr/local/gcc-3.0/include/g++-v3/bits/basic_ios.h:145 145 { return _M_tie; } (gdb) p _M_tie $3 = (basic_ostream > *) 0x10 (gdb) p *this $4 = { = {static boolalpha = Cannot access memory at address 0x0 Still no luck getting any overview of this object. Perhaps when I start a bit higher in the stack frame? (gdb) bt #0 std::basic_ios >::tie() const (this=0xbffff2d8) at /usr/local/gcc-3.0/include/g++-v3/bits/basic_ios.h:145 #1 0x400f62f8 in std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char) (__out=@0x8207fd8, __c=40 '(') at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:577 #2 0x400d81f0 in libcw::debug::cwbfd::object_file_ct::object_file_ct(char const*, void*) (this=0x81fd2d0, filename=0xbffff78a "IRCPlugin.so", base=0xffffffff) at bfd.cc:403 #3 0x400dade9 in libcw::debug::dlopen(char const*, int) (name=0xbffff78a "IRCPlugin.so", flags=258) at bfd.cc:1133 #4 0x08049d1c in main (argc=8, argv=0xbffff5bc) at src/MegaHAL++.cpp:151 #5 0x40276f31 in __libc_start_main (main=0x8049c20
, argc=8, ubp_av=0xbffff5bc, init=0x8049528 <_init>, fini=0x804a890 <_fini>, rtld_fini=0x4000e274 <_dl_fini>, stack_end=0xbffff5b4) at ../sysdeps/generic/libc-start.c:129 (gdb) up #1 0x400f62f8 in std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char) (__out=@0x8207fd8, __c=40 '(') at /usr/local/gcc-3.0/include/g++-v3/bits/ostream.tcc:577 577 typename __ostream_type::sentry __cerb(__out); (gdb) p __out $5 = (basic_ostream > &) @0x8207fd8: { >> = , _vptr. = 0x81fd2d0} As expected. (gdb) up #2 0x400d81f0 in libcw::debug::cwbfd::object_file_ct::object_file_ct(char const*, void*) (this=0x81fd2d0, filename=0xbffff78a "IRCPlugin.so", base=0xffffffff) at bfd.cc:403 403 Dout(dc::continued, '(' << hex << lbase << ") "); Now that sucks, Dout() is a macro that does: #define DEBUGCHANNELS ::libcw::debug::channels #define Dout(cntrl, data) LibcwDout(DEBUGCHANNELS, ::libcw::debug::libcw_do, cntrl, data) #define LibcwDout( dc_namespace, debug_obj, cntrl, data ) \ do \ { \ DEBUGDEBUGLIBCWDOUTMARKER \ if (debug_obj._off < 0) \ { \ using namespace ::libcw::debug; \ bool on; \ { \ using namespace dc_namespace; \ on = (debug_obj|cntrl).on; \ } \ if (on) \ { \ debug_obj.start(); \ (*debug_obj.current_oss) << data; \ debug_obj.finish(); \ } \ } \ } while(0) And apparently we are here inside "(*debug_obj.current_oss) << data;". Lets have a look at the global object 'debug_obj': (gdb) p '::libcw::debug::libcw_do' No symbol "::libcw::debug::libcw_do" in current context. Right (gdb) p 'libcw::debug::libcw_do' $6 = {_off = -1, current = 0x8207fd0, current_oss = 0x8207fd8, {channel_set = { = {label = 0x0, mask = 8192, on = true, debug_object = 0x40138640}, }, continued_channel_set = { = {label = 0x0, mask = 8192, on = true, debug_object = 0x40138640}, }}, orig_os = 0x4022e0c0, os = 0x4022e0c0, start_expected = true, unfinished_expected = false, laf_stack = {st = {0x8207fd0, 0x0 }, p = 0x40138664, end = 0x40138764}, off_count = 0, continued_stack = {st = {0 }, p = 0x40138770, end = 0x40138870}, margin = {len = 0, str = 0x4010d588 "", orig_str = 0x4010d588 "", str_is_allocated = false}, marker = {len = 2, str = 0x4010d486 ": ", orig_str = 0x4010d486 ": ", str_is_allocated = false}, indent = 0, saved_os = 0x0, interactive = true, initialized = true} Slightly better. Now there is 'current_oss': 0x8207fd8. So this must be the problem: current_oss->tie() returns 0x10. (gdb) p 'libcw::debug::libcw_do'.current_oss $7 = (basic_ostream > *) 0x8207fd8 (gdb) p *'libcw::debug::libcw_do'.current_oss virtual baseclass botch I think I'll have to catch this at the moment it is assigned... (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/carlo/c++/libcw/src/libcwd/MegaHALv9r1/objs/./MegaHAL++ IRCPlugin.so -n botcrashx -c bottestchan -s diemen.nl.eu.undernet.o Error while mapping shared library sections: libMegaHAL++.so: Success. Error in re-setting breakpoint 3: No source file named ostream.tcc. Error in re-setting breakpoint 3: No source file named ostream.tcc. Error in re-setting breakpoint 3: No source file named ostream.tcc. Error in re-setting breakpoint 3: No source file named ostream.tcc. Breakpoint 2, main (argc=8, argv=0xbffff5bc) at src/MegaHAL++.cpp:129 129 Debug( dc::notice.on() ); // Turn on the NOTICE Debug Channel (gdb) d 3 (gdb) watch 'libcw::debug::libcw_do'.current_oss Hardware watchpoint 4: libcw::debug::libcw_do.current_oss (gdb) c Continuing. __ __ _ _ _ _ ___ | \/ | ___ __ _ __ _| | | | / \ | | __ __/ _ \ | |\/| |/ _ \/ _` |/ _` | |_| | / _ \ | | \ \ / / (_) | | | | | __/ (_| | (_| | _ |/ ___ \| |___ \ V / \__, | |_| |_|\___|\__, |\__,_|_| |_/_/ \_\_____| \_/ /_/r1 |___/ Copyright(C) 1998 Jason Jutchens Copyright(C) 2000 Orlando Bassotto -Logo Designed by Daniele Nicolucci- ------------------------------------------------------------ Hardware watchpoint 4: libcw::debug::libcw_do.current_oss Old value = ( *) 0x40138968 New value = ( *) 0x8207fd8 libcw::debug::debug_ct::start() (this=0x40138640) at debug.cc:277 277 if (!(channel_set.mask & (noprefix_cf|nolabel_cf|blank_margin_cf|blank_label_cf|blank_marker_cf))) (gdb) p 'libcw::debug::libcw_do'.current_oss->_M_tie Segmentation fault (core dumped) Great, now gdb core dumped... Ok, sorry for the long mail :/ I guess this is all related to the same bug/problem. Is it known? Anything I can do/upgrade to fix it? I am using i686-pc-gnu-linux, g++-3.0, binutils-2.10.91.0.2... -- Carlo Wood