System: Athlon Linux 2.2.16 (SuSE 6.4 distribution)

Compiler: GCC 2.95.2 (used on test program and gdb)

Debugger: GDB 5.0

When the following code is compiled with the '-O0 -ggdb -lstdc++'
flags...

----
#include <iostream>

class Fred {
public:
        void print_to(ostream &os) const { os << "I'm Fred.\n"; }
};

int main() {
        Fred fred;
        fred.print_to(cout);
        return 0;
}
----

... and gdb is run with the following commands...

----
(gdb) b main
Breakpoint 1 at 0x804ac36: file main.cc, line 10.
(gdb) r
Starting program: /home/dickrp/proj/test/test 

Breakpoint 1, main () at main.cc:10
(gdb) s
0x80518cc in Fred::print_to (this=0x400ff618, os=@0x4000aa20) at main.cc:5
(gdb) p os
$1 = (ostream &) @0x4000aa20: {
  <ios> = {
    <_ios_fields> = {

Debugger segmentation fault
----

... gdb crashes.

When it's run on the same code with the following commands...

----
(gdb) b main
Breakpoint 1 at 0x804ac36: file main.cc, line 10.
(gdb) r
Starting program: /home/dickrp/proj/test/test 

Breakpoint 1, main () at main.cc:10
(gdb) n
I'm Fred.
(gdb) p fred.print_to(cout)

Program received signal SIGSEGV, Segmentation fault.
0x804cad0 in ostream::flush (this=0x40014000) at iostream.cc:915
915     iostream.cc: No such file or directory.
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (Fred::print_to(ostream &) const) 
will be abandoned.
(gdb) 
----

... it fails.  Note that the code printed "I'm Fred." just fine.
However, trying to call the function from within gdb failed.

An 'uninstall' target for the gdb makefile would be useful.

-Robert Dick-

Reply via email to