Debug mode output broken
Jonathan Wakely
cow@compsoc.man.ac.uk
Fri Aug 6 09:06:00 GMT 2004
On Wed, Aug 04, 2004 at 03:49:28PM +0200, Kaspar Fischer wrote:
> Hi everybody,
Hi Kaspar,
I get the same result on FreeBSD with mainline and 3.4 from a couple of
weeks ago. My analysis follows.
> I have a problem with the debug mode output on Darwin/PowerPC
> (and also on SunOS 5.9/Sparc). I compiled, using GCC 3.4.1,
> the following program
>
> #include <vector>
>
> int main(int, char **) {
> std::vector<int> v;
> v[3] = 2;
> }
>
> and called it. Two strange things happened: first, the
> program doesn't stop but continues outputting spaces ' ',
> to the error stream. Secondly, the error message (which
> appears before the spaces) lacks some information:
>
> bash$ ./tmp 2>&1 | more
> /Users/hbf/sw/gcc-3.4.1/lib/gcc/powerpc-apple-darwin7.4.0/3.4.1/../../../
> ../include/c++/3.4.1/debug/vector:192:
> error:
> attempt to subscript container with out-of-bounds index %2;, but
> container only holds %3; elements
> to subscript container with out-of-bounds index %2;, but container
> only holds %3; elements
> subscript container with out-of-bounds index %2;, but container only
> holds %3; elements
> *** many more spaces ***
>
> Btw, if I compile the program using Apple's GCC version
> I get a "errorless error" message
>
> /usr/include/gcc/darwin/3.3/c++/debug/dbg_vector.h:193:error: attempt to
> subscript container with out-of-bounds index 3, but container only
> holds 0 elements.
>
> So my conclusion is that I misconfigured GCC 3.4.1
> when I compiled it. Does anybody know what I've done
> wrong? I tried configuring with --enable-__cxa_atexit
> but this didn't help.
The problem seems to be that the error message is passed to
_Error_formatter::_M_print_word() in its entirety, when it should be
split into chunks on the "%n;" params embedded in the string.
(gdb) bt
#0 __gnu_debug::_Error_formatter::_M_print_word(char const*) const
(this=0xbfbff720, __word=0xbfbff5a0 "attempt to subscript container with
out-of-bounds index %2;, but container only holds %3; elements") at
/home/jw/gcc/src/gcc-3.4/libstdc++-v3/src/debug.cc:516
#1 0x28094e2b in __gnu_debug::_Error_formatter::_M_print_string(char
const*) const (this=0xbfbff720, __string=0x280cdcc0 "attempt to
subscript container with out-of-bounds index %2;, but container only
holds %3; elements") at
/home/jw/gcc/src/gcc-3.4/libstdc++-v3/src/debug.cc:578
#2 0x28095459 in __gnu_debug::_Error_formatter::_M_error() const
(this=0xbfbff720) at
/home/jw/gcc/src/gcc-3.4/libstdc++-v3/src/debug.cc:475
#3 0x08048adf in __gnu_debug_def::vector<int, std::allocator<int>
>::operator[](unsigned) (this=0xbfbff8b8, __n=3) at
>/data/development/jw/gcc/3.4/bin/../lib/gcc/i386-unknown-freebsd4.8/3.4.2/../../../../include/c++/3.4.2/debug/vector:192
#4 0x080488b9 in main () at dm.cc:6
#5 0x0804878e in _start ()
(gdb)
GDB gets hopelessly confused at this point, telling big porky pies about
which line I'm on, but basically _M_print_word() is called recursively
and loops forever (or that's what seems to happen, debugging C++ with
GDB is such a mission!)
I think _M_print_word() gets passed the error string over and over,
printing one word from it each time, until it gets to the "%n;" param,
which is interpreted as a format specifier by fprintf(3), and all hell
breaks loose. This is when the string gets printed 3 times and then
whitespace is spewed out endlessly.
I assume that _M_print_string is supposed to break the string up into
chunks, inserting the params where the "%n;" placeholders are, so that
_M_print_word() never sees the placeholders. This isn't working.
More info if I get a chance ...
jon
--
If one tells the truth, one is sure, sooner or later, to be found out.
- Oscar Wilde
More information about the Libstdc++
mailing list