public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace
@ 2009-11-09 15:40 egor at sun dot com
  2009-11-11 20:01 ` [Bug c++/10929] " swagiaal at redhat dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: egor at sun dot com @ 2009-11-09 15:40 UTC (permalink / raw)
  To: gdb-prs

try this code:

namespace {
    int foo() {
        int a = 5;
    }
};

int main() {
    int a = foo();
    return a;
}

in gdb 7.0:

(gdb) b main
Breakpoint 1 at 0x8050d48: file welcome.cc, line 8.
(gdb) r
Starting program:
/home/eu155513/NetBeansProjects/Welcome_74/dist/Debug/GNU-Solaris-x86/welcome_74 
[Thread debugging using libthread_db enabled]
[New Thread 1 (LWP 1)]
[Switching to Thread 1 (LWP 1)]

Breakpoint 1, main () at welcome.cc:8
8	    int a = foo();
(gdb) b foo
Function "foo" not defined.
Make breakpoint pending on future shared library load? (y or [n]) 

in gdb 6.6:

(gdb) b main
Breakpoint 1 at 0x8050d48: file welcome.cc, line 8.
(gdb) r
Starting program:
/home/eu155513/NetBeansProjects/Welcome_74/dist/Debug/GNU-Solaris-x86/welcome_74 
warning: Temporarily disabling breakpoints for unloaded shared library
"/usr/lib/ld.so.1"

Breakpoint 1, main () at welcome.cc:8
8	    int a = foo();
(gdb) b foo
Breakpoint 2 at 0x8050d22: file welcome.cc, line 3.
(gdb)

-- 
           Summary: Unable to set a function breakpoint in unnamed namespace
           Product: gdb
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: egor at sun dot com
                CC: gdb-prs at sourceware dot org


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
@ 2009-11-11 20:01 ` swagiaal at redhat dot com
  2009-11-12 10:37 ` egor at sun dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: swagiaal at redhat dot com @ 2009-11-11 20:01 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From swagiaal at redhat dot com  2009-11-11 20:01 -------
Hmm.. I cannot reproduce.

Here is what I get:

$ ./gdb/gdb ../../tests/break-anonymous -ex 'list' -ex 'b main' -ex 'r' -ex 'b
foo' -ex 'q'
GNU gdb (GDB) 7.0
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /notnfs/swagiaal/src/tests/break-anonymous...done.
1	namespace {
2	  int foo() {
3	    int a = 5;
4	  }
5	};
6	
7	int main() {
8	  int a = foo();
9	  return a;
10	}
Breakpoint 1 at 0x400581: file break-anonymous.c, line 8.
[Thread debugging using libthread_db enabled]

Breakpoint 1, main () at break-anonymous.c:8
8	  int a = foo();
Current language:  auto
The current source language is "auto; currently c++".
Breakpoint 2 at 0x400570: file break-anonymous.c, line 3.


Maybe it is a compiler issue. Which compiler and which version are you using ?
Could you post the result of:
  readelf --debug-dump <your/test/program> 


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
  2009-11-11 20:01 ` [Bug c++/10929] " swagiaal at redhat dot com
@ 2009-11-12 10:37 ` egor at sun dot com
  2009-11-12 10:38 ` egor at sun dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: egor at sun dot com @ 2009-11-12 10:37 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From egor at sun dot com  2009-11-12 10:37 -------
I'm using OpenSolaris build 111b,
gcc version 3.4.3 (csl-sol210-3_4-20050802)
output of the dwarfdump attached


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
  2009-11-11 20:01 ` [Bug c++/10929] " swagiaal at redhat dot com
  2009-11-12 10:37 ` egor at sun dot com
@ 2009-11-12 10:38 ` egor at sun dot com
  2009-11-13 21:08 ` swagiaal at redhat dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: egor at sun dot com @ 2009-11-12 10:38 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From egor at sun dot com  2009-11-12 10:38 -------
Created an attachment (id=4381)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=4381&action=view)
dwarfdump


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
                   ` (2 preceding siblings ...)
  2009-11-12 10:38 ` egor at sun dot com
@ 2009-11-13 21:08 ` swagiaal at redhat dot com
  2009-11-16 19:35 ` swagiaal at redhat dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: swagiaal at redhat dot com @ 2009-11-13 21:08 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From swagiaal at redhat dot com  2009-11-13 21:08 -------
Ok I reproduced this with gcc34. I don't know why; nothing jumps at me form the
dwarf info. I am working on a fix.

Thanks Egor

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at sourceware dot|swagiaal at redhat dot com
                   |org                         |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|                            |1


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
                   ` (3 preceding siblings ...)
  2009-11-13 21:08 ` swagiaal at redhat dot com
@ 2009-11-16 19:35 ` swagiaal at redhat dot com
  2010-01-26 15:48 ` cvs-commit at gcc dot gnu dot org
  2010-07-20 19:42 ` tromey at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: swagiaal at redhat dot com @ 2009-11-16 19:35 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From swagiaal at redhat dot com  2009-11-16 19:35 -------
I have a patch upstream pending review that fixes this problem:

 2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
       * dwarf2read.c (read_lexical_block_scope): Create blocks for scopes
       which contain using directives even if they contain no declarations.
       * symtab.c (lookup_symbol_aux): Pass lowest level
       block to la_lookup_symbol_nonlocal.
       * cp-namespace.c (cp_lookup_symbol_nonlocal): call
       cp_lookup_symbol_namespace.
       (cp_lookup_symbol_namespace): Perform an import lookup at every block
       level.
       (cp_lookup_symbol_imports): New function.
       (cp_lookup_symbol_in_namespace): New function.

 2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
       * gdb.cp/namespace-using.exp: Add test for printing of namespaces
       imported into file scope.
       Marked test as xfail.
       * gdb.cp/namespace-using.cc (marker5): New function.
       * gdb.cp/shadowing.exp: New test.
       * gdb.cp/shadowing.cc: New test program.
       * gdb.cp/namespace-multiple-imports.exp: New test.
       * gdb.cp/namespace-multiple-imports.cc: New test program.

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index d2d8f2e..1980681 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -265,8 +265,114 @@ cp_lookup_symbol_nonlocal (const char *name,
               const struct block *block,
               const domain_enum domain)
{
-  return lookup_namespace_scope (name, linkage_name, block, domain,
-                 block_scope (block), 0);
+  struct symbol *sym;
+  const char *scope = block_scope (block);
+
+  sym = lookup_namespace_scope (name, linkage_name, block, domain, scope, 0);
+  if (sym != NULL)
+    return sym;
+
+  return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain);
+}
+
+/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
+   cp_lookup_symbol_nonlocal.  */
+
+static struct symbol *
+cp_lookup_symbol_in_namespace (const char *namespace,
+                   const char *name,
+                   const char *linkage_name,
+                   const struct block *block,
+                   const domain_enum domain)
+{
+  if (namespace[0] == '\0')
+    {
+      return lookup_symbol_file (name, linkage_name, block,
+                                 domain, 0);
+    }
+  else
+    {
+      char *concatenated_name = alloca (strlen (namespace) + 2 +
+                                        strlen (name+ 1));
+      strcpy (concatenated_name, namespace);
+      strcat (concatenated_name, "::");
+      strcat (concatenated_name, name);
+      return lookup_symbol_file (concatenated_name, linkage_name,
+                                 block, domain,cp_is_anonymous (namespace));
+    }
+}
+
+/* Search for NAME by applying all import statements belonging
+   to BLOCK which are applicable in SCOPE.  */
+
+static struct symbol *
+cp_lookup_symbol_imports (const char *scope,
+                          const char *name,
+                          const char *linkage_name,
+                          const struct block *block,
+                          const domain_enum domain)
+{
+  const struct using_direct *current;
+  struct symbol *sym;
+  int len;
+  +  /* First, try to find the symbol in the given namespace.  */
+  sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block,
+                                       domain);
+  if (sym != NULL)
+    return sym;
+
+  /* Go through the using directives.  If any of them add new
+     names to the namespace we're searching in, see if we can find a
+     match by applying them.  */
+
+  for (current = block_using (block);
+       current != NULL;
+       current = current->next)
+    {
+
+      /* If the import destination is the current scope or one of its ancestors
then
+         it is applicable.  */
+      len = strlen (current->import_dest);
+      if (strncmp (scope, current->import_dest, len) == 0 +      && (scope[len]
== ':' || scope[len] == '\0'))
+    {
+      sym = cp_lookup_symbol_in_namespace (current->import_src, name,
+                           linkage_name, block, domain);
+      if (sym != NULL)
+        return sym;
+    }
+    }
+
+  return NULL;
+}
+
+
+ /* Searches for NAME in the current namespace, and by applying relevant import
+    statements belonging to BLOCK and its parents. SCOPE is the namespace scope
+    of the context in which the search is being evaluated.  */
+
+struct symbol*
+cp_lookup_symbol_namespace (const char *scope,
+                            const char *name,
+                            const char *linkage_name,
+                            const struct block *block,
+                            const domain_enum domain)
+{
+  struct symbol *sym;
+
+  /* Search for name in namespaces imported to this and parent blocks.  */
+  while (block != NULL)
+    {
+      sym = cp_lookup_symbol_imports (scope,name, linkage_name, block, domain);
+
+      if (sym)
+    return sym;
+
+      block = BLOCK_SUPERBLOCK (block);
+    }
+
+  return NULL;
}

/* Lookup NAME at namespace scope (or, in C terms, in static and
@@ -320,65 +426,8 @@ lookup_namespace_scope (const char *name,
  namespace = alloca (scope_len + 1);
  strncpy (namespace, scope, scope_len);
  namespace[scope_len] = '\0';
-  return cp_lookup_symbol_namespace (namespace, name, linkage_name,
-                     block, domain);
-}
-
-/* Look up NAME in the C++ namespace NAMESPACE, applying the using
-   directives that are active in BLOCK.  Other arguments are as in
-   cp_lookup_symbol_nonlocal.  */
-
-struct symbol *
-cp_lookup_symbol_namespace (const char *namespace,
-                const char *name,
-                const char *linkage_name,
-                const struct block *block,
-                const domain_enum domain)
-{
-  const struct using_direct *current;
-  struct symbol *sym;
-
-  /* First, go through the using directives.  If any of them add new
-     names to the namespace we're searching in, see if we can find a
-     match by applying them.  */
-
-  for (current = block_using (block);
-       current != NULL;
-       current = current->next)
-    {
-      if (strcmp (namespace, current->import_dest) == 0)
-    {
-      sym = cp_lookup_symbol_namespace (current->import_src,
-                        name,
-                        linkage_name,
-                        block,
-                        domain);
-      if (sym != NULL)
-        return sym;
-    }
-    }
-
-  /* We didn't find anything by applying any of the using directives
-     that are still applicable; so let's see if we've got a match
-     using the current namespace.  */
-  -  if (namespace[0] == '\0')
-    {
-      return lookup_symbol_file (name, linkage_name, block,
-                 domain, 0);
-    }
-  else
-    {
-      char *concatenated_name
-    = alloca (strlen (namespace) + 2 + strlen (name) + 1);
-      strcpy (concatenated_name, namespace);
-      strcat (concatenated_name, "::");
-      strcat (concatenated_name, name);
-      sym = lookup_symbol_file (concatenated_name, linkage_name,
-                block, domain, -                cp_is_anonymous (namespace));
-      return sym;
-    }
+  return cp_lookup_symbol_in_namespace (namespace, name, linkage_name,
+                                        block, domain);
}

/* Look up NAME in BLOCK's static block and in global blocks.  If
@@ -461,11 +510,11 @@ cp_lookup_nested_type (struct type *parent_type,
       lookup_symbol_namespace works when looking them up.  */

    const char *parent_name = TYPE_TAG_NAME (parent_type);
-    struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
-                             nested_name,
-                             NULL,
-                             block,
-                             VAR_DOMAIN);
+    struct symbol *sym = cp_lookup_symbol_in_namespace (parent_name,
+                                                        nested_name,
+                                                        NULL,
+                                                        block,
+                                                        VAR_DOMAIN);
    if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
      return NULL;
    else
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 69a7242..c2b2e3c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3920,7 +3920,7 @@ read_lexical_block_scope (struct die_info *die, struct
dwarf2_cu *cu)
    }
  new = pop_context ();

-  if (local_symbols != NULL)
+  if (local_symbols != NULL || using_directives != NULL)
    {
      struct block *block
        = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8d9d72c..dfa8f48 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1304,13 +1304,14 @@ lookup_symbol_aux (const char *name, const char
*linkage_name,
      && block != NULL)
    {
      struct symbol *sym = NULL;
+      const struct block *function_block = block;
      /* 'this' is only defined in the function's block, so find the
     enclosing function block.  */
-      for (; block && !BLOCK_FUNCTION (block);
-       block = BLOCK_SUPERBLOCK (block));
+      for (; function_block && !BLOCK_FUNCTION (function_block);
+       function_block = BLOCK_SUPERBLOCK (function_block));

-      if (block && !dict_empty (BLOCK_DICT (block)))
-    sym = lookup_block_symbol (block, langdef->la_name_of_this,
+      if (function_block && !dict_empty (BLOCK_DICT (function_block)))
+    sym = lookup_block_symbol (function_block, langdef->la_name_of_this,
                   NULL, VAR_DOMAIN);
      if (sym)
    {
diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
new file mode 100644
index 0000000..6b180d6
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
@@ -0,0 +1,20 @@
+namespace A {
+  int x = 11;
+  namespace{
+    int xx = 22;
+  }
+}
+
+using namespace A;
+
+namespace{
+  int xxx = 33;
+};
+
+int main()
+{
+  x;
+  xx;
+  xxx;
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
new file mode 100644
index 0000000..e4bb9f8
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
@@ -0,0 +1,49 @@
+# Copyright 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile namespace-multiple-imports
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable
{debug c++}] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+############################################
+# test printing of namespace imported within
+# the function.
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint main"
+    continue
+}
+
+gdb_test "print x" "\\$\[0-9\].* = 11"
+gdb_test "print xx" "\\$\[0-9\].* = 22"
+gdb_test "print xxx" "\\$\[0-9\].* = 33"
diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc
b/gdb/testsuite/gdb.cp/namespace-using.cc
index 4786fd5..8d9ea67 100644
--- a/gdb/testsuite/gdb.cp/namespace-using.cc
+++ b/gdb/testsuite/gdb.cp/namespace-using.cc
@@ -1,3 +1,35 @@
+namespace O
+{
+  int ox = 4;
+}
+
+namespace PQ
+{
+  int marker6 ()
+  {
+    return 0;
+  }
+}
+
+namespace P
+{
+  using namespace O;
+}
+
+//--------------
+namespace C
+{
+  int cc = 3;
+}
+
+using namespace C;
+int marker5 ()
+{
+  cc;
+  return PQ::marker6 ();
+}
+
+
namespace A
{
  int _a = 1;
@@ -6,7 +38,7 @@ namespace A

int marker4(){
    using A::x;
-    return 0;
+    return marker5 ();
}

int marker3(){
diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc.orig
b/gdb/testsuite/gdb.cp/namespace-using.cc.orig
new file mode 100644
index 0000000..4786fd5
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-using.cc.orig
@@ -0,0 +1,45 @@
+namespace A
+{
+  int _a = 1;
+  int x = 2;
+}
+
+int marker4(){
+    using A::x;
+    return 0;
+}
+
+int marker3(){
+    return marker4();
+}
+
+int marker2()
+{
+  namespace B = A;
+  B::_a;
+  return marker3();
+}
+
+int marker1()
+{
+  int total = 0;
+  {
+    int b = 1;
+    {
+      using namespace A;
+      int c = 2;
+      {
+        int d = 3;
+        total = _a + b + c + d + marker2(); // marker1 stop
+      }
+    }
+  }
+  return total;
+}
+
+int main()
+{
+  using namespace A;
+  _a;
+  return marker1();
+}
diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp
b/gdb/testsuite/gdb.cp/namespace-using.exp
index f24973f..0dd2067 100644
--- a/gdb/testsuite/gdb.cp/namespace-using.exp
+++ b/gdb/testsuite/gdb.cp/namespace-using.exp
@@ -28,6 +28,11 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}"
"${binfile}" executable {deb
    return -1
}

+if [get_compiler_info ${binfile}] {
+    return -1
+}
+
+
# Get things started.

gdb_exit
@@ -73,7 +78,13 @@ gdb_test "print B::a" "= 1"
gdb_breakpoint "marker3"
gdb_continue_to_breakpoint "marker3"

-gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import"
+# gcc-4-3 puts import statements for aliases in
+# the global scope instead of the corresponding
+# function scope. These wrong import statements throw
+# this test off. This is fixed in gcc-4-4.
+if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
+
+gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without
import"

############################################
# Test printing of individually imported elements
@@ -85,3 +96,25 @@ if ![runto marker4] then {
}

gdb_test "print x" "= 2"
+
+############################################
+# test printing of namespace imported into
+# file scope.
+
+if ![runto marker5] then {
+    perror "couldn't run to marker5"
+    continue
+}
+
+gdb_test "print cc" "= 3"
+
+############################################
+# test printing of namespace imported into
+# file scope.
+
+if ![runto PQ::marker6] then {
+    perror "couldn't run to PQ::marker6"
+    continue
+}
+
+gdb_test "print ox" "No symbol \"ox\" in current context."
diff --git a/gdb/testsuite/gdb.cp/shadowing.cc b/gdb/testsuite/gdb.cp/shadowing.cc
new file mode 100644
index 0000000..1651510
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/shadowing.cc
@@ -0,0 +1,45 @@
+namespace A
+{
+  int x = 11;
+}
+
+int x = 22;
+int y = 0;
+
+class B
+{
+public:
+  int x;
+
+  int
+  func()
+  {
+    x = 33;
+    y++; // marker1
+
+      {
+        int x = 44;
+        y++; // marker2
+
+          {
+            int x = 55;
+            y++; // marker3
+
+              {
+                using namespace A;
+                y++; // marker4
+
+                using A::x;
+                y++; // marker5
+              }
+          }
+      }
+  }
+};
+
+int
+main()
+{
+  B theB;
+  return theB.func();
+}
diff --git a/gdb/testsuite/gdb.cp/shadowing.exp b/gdb/testsuite/gdb.cp/shadowing.exp
new file mode 100644
index 0000000..443881e
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/shadowing.exp
@@ -0,0 +1,86 @@
+# Copyright 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile shadowing
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable
{debug c++}] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint main"
+    continue
+}
+
+############################################
+# Test printing of class variable is not shadowed
+# by global variable
+
+gdb_breakpoint [gdb_get_line_number "marker1"]
+gdb_continue_to_breakpoint "marker1"
+
+gdb_test "print x" "= 33" "Print class x shadowing global x"
+
+
+############################################
+# Test printing local variable is not shadowed
+# by class variable
+
+gdb_breakpoint [gdb_get_line_number "marker2"]
+gdb_continue_to_breakpoint "marker2"
+
+gdb_test "print x" "= 44" "Print local x shadowing class x"
+
+############################################
+# Test inner scope x is printed not outer scope
+
+gdb_breakpoint [gdb_get_line_number "marker3"]
+gdb_continue_to_breakpoint "marker3"
+
+gdb_test "print x" "= 55" "Print inner scope x"
+
+############################################
+# Test printing local variable is not shadowed
+# by namespace variable
+
+gdb_breakpoint [gdb_get_line_number "marker4"]
+gdb_continue_to_breakpoint "marker4"
+
+gdb_test "print x" "= 55" "Print local x not namespace x"
+
+############################################
+# Test imported namespace element is printed
+
+gdb_breakpoint [gdb_get_line_number "marker5"]
+gdb_continue_to_breakpoint "marker5"
+
+setup_kfail "gdb/7936" "*-*-*"
+gdb_test "print x" "= 11" "Print imported namespace x" 

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
                   ` (4 preceding siblings ...)
  2009-11-16 19:35 ` swagiaal at redhat dot com
@ 2010-01-26 15:48 ` cvs-commit at gcc dot gnu dot org
  2010-07-20 19:42 ` tromey at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2010-01-26 15:48 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2010-01-26 15:48 -------
Subject: Bug 10929

CVSROOT:	/cvs/src
Module name:	src
Changes by:	swagiaal@sourceware.org	2010-01-26 15:48:26

Modified files:
	gdb            : ChangeLog cp-namespace.c dwarf2read.c symtab.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: namespace-using.cc namespace-using.exp 
Added files:
	gdb/testsuite/gdb.cp: nsimport.cc nsimport.exp shadow.cc 
	                      shadow.exp 

Log message:
	2010-01-26  Sami Wagiaalla  <swagiaal@redhat.com>
	
	* gdb.cp/namespace-using.exp: Add test for printing of namespaces
	imported into file scope.
	Marked test as xfail.
	* gdb.cp/namespace-using.cc (marker5): New function.
	* gdb.cp/shadow.exp: New test.
	* gdb.cp/shadow.cc: New test program.
	* gdb.cp/nsimport.exp: New test.
	* gdb.cp/nsimport.cc: New test program.
	
	2010-01-26  Sami Wagiaalla  <swagiaal@redhat.com>
	
	PR gdb/10929:
	* dwarf2read.c (read_lexical_block_scope): Create blocks for
	scopes which contain using directives even if they contain no
	declarations.
	* symtab.c (lookup_symbol_aux): Pass lowest level block to
	la_lookup_symbol_nonlocal.
	* cp-namespace.c (cp_lookup_symbol_nonlocal): call
	cp_lookup_symbol_namespace.
	(cp_lookup_symbol_namespace): Perform an import lookup at every
	block level.
	(cp_lookup_symbol_imports): New function.
	(cp_lookup_symbol_in_namespace): New function.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11289&r2=1.11290
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/cp-namespace.c.diff?cvsroot=src&r1=1.31&r2=1.32
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.351&r2=1.352
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/symtab.c.diff?cvsroot=src&r1=1.223&r2=1.224
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2101&r2=1.2102
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/nsimport.cc.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/nsimport.exp.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/shadow.cc.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/shadow.exp.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/namespace-using.cc.diff?cvsroot=src&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/namespace-using.exp.diff?cvsroot=src&r1=1.2&r2=1.3



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/10929] Unable to set a function breakpoint in unnamed namespace
  2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
                   ` (5 preceding siblings ...)
  2010-01-26 15:48 ` cvs-commit at gcc dot gnu dot org
@ 2010-07-20 19:42 ` tromey at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at redhat dot com @ 2010-07-20 19:42 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From tromey at redhat dot com  2010-07-20 19:42 -------
Fixed in 7.1.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=10929

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-20 19:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-09 15:40 [Bug c++/10929] New: Unable to set a function breakpoint in unnamed namespace egor at sun dot com
2009-11-11 20:01 ` [Bug c++/10929] " swagiaal at redhat dot com
2009-11-12 10:37 ` egor at sun dot com
2009-11-12 10:38 ` egor at sun dot com
2009-11-13 21:08 ` swagiaal at redhat dot com
2009-11-16 19:35 ` swagiaal at redhat dot com
2010-01-26 15:48 ` cvs-commit at gcc dot gnu dot org
2010-07-20 19:42 ` tromey at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).