I have gdb-4.5 up on the RS/6000, and I am having problems using the "print"
command to look at String variables.
Environment: IBM RS/6000 550, AIX 3.1.6, g++-2.1, libg++-2.0, gdb-4.5.
Problem: When I use the "print" command in gdb on a variable of class String,
gdb says "$1 = <unknown struct>".
Question: Can I use the gdb "print" command to look at variables of class
String?
[ Please e-mail any responses, in addition to any posts. My news server has ]
[ been very undependable as of late. ]
Example program:
thunder> cat test9.cc
#include <stream.h>
#include <String.h>
#include <stddef.h>
String s1 = "Hello";
String s2 = " world!\n";
main()
{
for (int i = 0; i < 5; i++)
cout << i << " " << s1 << s2;
----------------------------------------Quote:}
Compile the program:
thunder> g++ -v -g test9.cc -o t9
Reading specs from /stor/gnu/aix/lib/gcc-lib/rs6000/2.1/specs
gcc version 2.1
/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/cpp -lang-c++ -v -undef -D__GNUC__=2
-D__GNUG__=2 -D__cplusplus -D_IBMR2 -D_AIX -D___IBMR2__ -D___AIX__ -D___IBMR2
-D___AIX -D__CHAR_UNSIGNED__ -g test9.cc /tmp/ccMYsCb8.i
GNU CPP version 2.1
/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/cc1plus /tmp/ccMYsCb8.i -quiet -dumpbase
test9.cc -g -version -o /tmp/ccMYsCb8.s
GNU C++ version 2.1 compiled by GNU C version 2.1.
as -u -o test9.o /tmp/ccMYsCb8.s
/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/ld -T512 -H512 -btextro -bhalt:4
-bnodelcsect -o t9 /lib/crt0.o -L/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/
-L/stor/gnu/aix/lib/ test9.o -lg++ -lm
/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/libgcc.a -lc
/stor/gnu/aix/lib/gcc-lib/rs6000/2.1/libgcc.a
----------------------------------------
Program output:
thunder> t9
0 Hello world!
1 Hello world!
2 Hello world!
3 Hello world!
4 Hello world!
----------------------------------------
gdb session:
thunder> gdb t9
GDB is free software and you are welcome to 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.
GDB 4.5, Copyright 1992 Free Software Foundation, Inc...
(gdb) l 1,30
1 #include <stream.h>
2 #include <String.h>
3 #include <stddef.h>
4
5 String s1 = "Hello";
6 String s2 = " world!\n";
7
8 main()
9 {
10 for (int i = 0; i < 5; i++)
11 cout << i << " " << s1 << s2;
12 }
(gdb) b 11
Breakpoint 1 at 0x308: file test9.cc, line 11.
(gdb) run
Starting program: /a/eng/eng6/tmcconne/source/t9
Breakpoint 1, main () at test9.cc:11
11 cout << i << " " << s1 << s2;
Current Language: auto; currently c++
Type checking: auto; currently off
Range checking: auto; currently off
(gdb) p i
$1 = 0
(gdb) p s1
$2 = <unknown struct>
(gdb) info locals
i = 0
(gdb) info v s1
All variables matching regular expression "s1":
File test9.cc:
int _GLOBAL_.D.s1;
int _GLOBAL_.I.s1;
StrTmp s1;
----------------------------------------
So, does this mean that gdb does not understand "StrTmp"? By the way, String.h
defines StrTmp like this:
typedef String StrTmp; // for backward compatibility
This same behavior is seen with gdb-4.4, gcc-2.1, libg++-2.0 on VAX ultrix
3.1, and Sun SPARC SunOS 4.1.1. The only difference is that on the Sun, gdb says
this about "s1":
(gdb) info v s1
All variables matching regular expression "s1":
File test9.cc:
struct String s1;
Thanks for any help.
Cheers,
Tom McConnell
--
Intel, Corp. C3-21 | Phone: (602)-554-8229
5000 W. Chandler Blvd. | The opinions expressed are my own. No one in
Chandler, AZ 85226 | their right mind would claim them.