On my Pentium-based RedHat 6.2 machine, gdb 5.0 cannot print
the contents of a C++ string variable.  It displays this:

  $1 = {static npos = Cannot access memory at address 0x0

This bug was reported for gdb 4.18 in this message:

  http://www.bg.debian.org/Bugs/db/47/47482-b.html

I compiled and installed g++ 2.95.2 and gdb 5.0 from the sources.


Here are the details.

$ uname -a
Linux dev.machina.com 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown

$ ls /lib/libc-*
/lib/libc-2.1.3.so

$ g++ -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)

$ ls -l /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/libstdc++.so
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/libstdc++.so
    -> ../../../libstdc++-libc6.1-2.so.3

$ cat test.cc
#include <string>

int main()
{
  string s;

  s = "a";  // line 7
}

$ g++ -g -o test test.cc

$ ldd test
        libstdc++-libc6.1-2.so.3 => /usr/local/lib/libstdc++-libc6.1-2.so.3 
(0x4001a000)
        libm.so.6 => /lib/libm.so.6 (0x40061000)
        libc.so.6 => /lib/libc.so.6 (0x4007e000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

$ gdb test
GNU gdb 5.0
Copyright 2000 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 "i686-pc-linux-gnu"...
(gdb) b 7
Breakpoint 1 at 0x8049975: file test.cc, line 7.
(gdb) r
Starting program: /home/sarrazip/pgm/bug-gdb-string/test 

Breakpoint 1, main () at test.cc:7
7         s = "a";
(gdb) p s
$1 = {static npos = Cannot access memory at address 0x0
(gdb) n
8       }
(gdb) p s
$2 = {static npos = Cannot access memory at address 0x0
(gdb) c
Continuing.

Program exited normally.
(gdb) q

-- 
Pierre Sarrazin <sarrazip at machinasapiens dot com>

Reply via email to