Debug mode output broken

Jonathan Wakely cow@compsoc.man.ac.uk
Fri Aug 6 10:57:00 GMT 2004


On Fri, Aug 06, 2004 at 11:08:54AM +0100, Jonathan Wakely wrote:

> On Fri, Aug 06, 2004 at 10:57:30AM +0100, Jonathan Wakely wrote:
> 
> > > Sorry for the trivial observation: are you building both the library and 
> > > your
> > > executable '-O0 -g'?
> > 
> > I did check that :-)
> > 
> > I configured the library with --enable-libstdcxx-debug and am compiling
> > the exe with -g3 ... but I think gdb has been looking at the non-debug
> > version of libstdc++.so, so I'm trying again and trying to make sure GDB
> > looks in the right place. It might help  :-)
> 
> And now GDB bails because v5.3 can't handle DWARF2, which is the format
> specified by the default --enable-libstdcxx-debug-flags configuration.
> 
> I might just wait until I'm at home, try it on Linux and then give up
> 'cause it works there  ;-)
> 
> I'll report back when I've figured out what I can use to make GDB happy,
> rebuilt and retested. Might take some time before I get the chance to do
> that.

(gdb) p __start
macroscope.c:48: gdb-internal-error:
the symtab `/home/jw/gcc/src/gcc-3.4/libstdc++-v3/src/debug.cc' refers to a preprocessor macro table which doesn't
have any record of processing a file by that name.

An internal GDB error was detected.  This may make further
debugging unreliable.  Quit this debugging session? (y or n) y

*sigh*

I finally had more luck with GDB 5.21

The reason it works on linux and not elsewhere seems to be this:

  template<typename _Tp>
    void
    _Error_formatter::_M_format_word(char* __buf,
                     int __n __attribute__((__unused__)),
                     const char* __fmt, _Tp __s) const
    {
#ifdef _GLIBCXX_USE_C99
      std::snprintf(__buf, __n, __fmt, __s);
#else
      std::sprintf(__buf, __fmt, __s);
#endif
    }

If sprintf is used the whole string is copied to the buffer, not just
the first word (or more correctly, the first __n chars).

When the contents of the buffer are printed with _M_print_word() the
buffer contains more than just the word that should be printed.

The attached patch seems to fix it, I get the expected output:

/data/development/jw/gcc/3.4s/bin/../lib/gcc/i386-unknown-freebsd4.8/3.4.2/../../../../include/c++/3.4.2/debug/vector:192:
    error: attempt to subscript container with out-of-bounds index 3, but
    container only holds 0 elements.

Objects involved in the operation:
sequence "this" @ 0x0xbfbff898 {
  type = N15__gnu_debug_def6vectorIiSaIiEEE;
}
Abort trap (core dumped)


Shall I commit this to 3.4 and mainline?

2004-08-06  Jonathan Wakely  <redi@gcc.gnu.org>

	* src/debug.cc: NULL-terminate string if sprintf() used instead
	of snprintf().

jon

-- 
"Outside of a dog, a man's best friend is a book.  Inside of a dog,
 it's too dark to read."
           -Groucho Marx
-------------- next part --------------
Index: src/debug.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/debug.cc,v
retrieving revision 1.3.10.2
diff -u -p -b -B -r1.3.10.2 debug.cc
--- src/debug.cc	15 May 2004 21:17:59 -0000	1.3.10.2
+++ src/debug.cc	6 Aug 2004 10:54:15 -0000
@@ -506,6 +506,7 @@ namespace __gnu_debug
       std::snprintf(__buf, __n, __fmt, __s);
 #else
       std::sprintf(__buf, __fmt, __s);
+      __buf[__n-1] = '\0';
 #endif
     }
 


More information about the Libstdc++ mailing list