bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with gdb and C++ namespaes


From: Geoff Alexander
Subject: Problem with gdb and C++ namespaes
Date: Wed, 18 Apr 2001 11:50:48 -0400

I'm having a problem with gdb and C++ namespaces as illustrated by the
following example:

---
namespace test_ns1
{
  class Test
  {
    public:
      static int i;
  };
}

namespace test_ns2
{
  class Test
  {
    public:
      static int i;
  };
}

int test_ns1::Test::i = 0;
int test_ns2::Test::i = 3;

int main(int argc, char* argv)
{
  test_ns1::Test::i = 1;
  test_ns2::Test::i = 4;
}
---
I compile the code as

    gcc -g -o Test Test.cpp

I use gdb to debug Test by setting a breakpoint a line 24 and running
the code.  When I try to print test_ns1::Test::i, I get a "No symbol
"test_ns1" in current context." error.  I also get a similar error when
trying to print test_ns2::Test::i.  I can print Test::i, which seems to
show the value of test_ns1::Test::i.  Here's the output from gdb:

---
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 "i386-suse-linux"...
(gdb) list 1,50
1       namespace test_ns1
2       {
3         class Test
4         {
5           public:
6             static int i;
7         };
8       }
9
10      namespace test_ns2
11      {
12        class Test
13        {
14          public:
15            static int i;
16        };
17      }
18
19      int test_ns1::Test::i = 0;
20      int test_ns2::Test::i = 3;
21
22      int main(int argc, char* argv)
23      {
24        test_ns1::Test::i = 1;
25        test_ns2::Test::i = 4;
26      }
(gdb) break 24
Breakpoint 1 at 0x80483d3: file Test.cpp, line 24.
(gdb) run
Starting program: /home/gdlxn/gdb-bugs/001/Test

Breakpoint 1, main (argc=1, argv=0xbffff714 "¤øÿ¿") at Test.cpp:24
24        test_ns1::Test::i = 1;
(gdb) print test_ns1::Test::i
No symbol "test_ns1" in current context.
(gdb) print Test::i
$1 = 0
(gdb) print test_ns2::Test::i
No symbol "test_ns2" in current context.
---

Is this a known problem? What do I need to do to print the value of
test_ns2::Test::i?
I'm using gdb 5.0 and gcc 2.95.2 on SuSE Linux 7.0 for i386.

Thanks,
Geoff Alexander, Ph.D.
919/254-5216 T/L 444-5216
CMVC95 WebDAV Development
IBM Corporation
RTP, NC





reply via email to

[Prev in Thread] Current Thread [Next in Thread]