This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Perform a namespace lookup at every block level


Now that import information is stored in the nearest block,
this patch changes things so that a namespace lookup is correctly
performed at every block level.

2009-07-09 Sami Wagiaalla <swagiaal@redhat.com>

	* symtab.c: Import cp-support.h.
	(lookup_symbol_aux_local): Continue lookup through static block
	and stop at global block.
	Do a namespace at each block level via lookup_namespace_scope.
	Now takes 'enum language' argument.
	* cp-support.h: Added extern lookup_namespace_scope prototype.
	* cp-namespace.c (lookup_namespace_scope): Removed static qualifier.
	(cp_lookup_symbol_nonlocal): Calls lookup_symbol_file if call to
	lookup_namespace_scope fails.
	(cp_lookup_symbol_namespace): Return NULL if no namespace is
	specified.


2009-07-09 Sami Wagiaalla <swagiaal@redhat.com>


	* gdb.cp/namespace-using.exp: Add test for printing of namespaces
	imported into file scope.
	* gdb.cp/namespace-using.cc (marker5): New function.


diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index d2d8f2e..75cac01 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -35,13 +35,6 @@ static struct using_direct *cp_copy_usings (struct using_direct *using, struct obstack *obstack);

-static struct symbol *lookup_namespace_scope (const char *name,
-					      const char *linkage_name,
-					      const struct block *block,
-					      const domain_enum domain,
-					      const char *scope,
-					      int scope_len);
-
 static struct symbol *lookup_symbol_file (const char *name,
 					  const char *linkage_name,
 					  const struct block *block,
@@ -265,8 +258,15 @@ cp_lookup_symbol_nonlocal (const char *name,
 			   const struct block *block,
 			   const domain_enum domain)
 {
-  return lookup_namespace_scope (name, linkage_name, block, domain,
+  struct symbol *sym;
+
+  sym =  lookup_namespace_scope (name, linkage_name, block, domain,
 				 block_scope (block), 0);
+  if ( sym != NULL)
+    return sym;
+
+  return lookup_symbol_file (name, linkage_name, block,
+                             domain, 0);
 }

 /* Lookup NAME at namespace scope (or, in C terms, in static and
@@ -284,7 +284,7 @@ cp_lookup_symbol_nonlocal (const char *name,
    "A::x", and if that call fails, then the first call looks for
    "x".  */

-static struct symbol *
+struct symbol *
 lookup_namespace_scope (const char *name,
 			const char *linkage_name,
 			const struct block *block,
@@ -364,8 +364,7 @@ cp_lookup_symbol_namespace (const char *namespace,

   if (namespace[0] == '\0')
     {
-      return lookup_symbol_file (name, linkage_name, block,
-				 domain, 0);
+      return NULL;
     }
   else
     {
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index b5a5c5f..2016024 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -101,6 +101,13 @@ extern struct symbol *cp_lookup_symbol_nonlocal (const char *name,
 						 const struct block *block,
 						 const domain_enum domain);

+extern struct symbol *lookup_namespace_scope (const char *name,
+                                              const char *linkage_name,
+                                              const struct block *block,
+                                              const domain_enum domain,
+                                              const char *scope,
+                                              int scope_len);
+
 extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
 						  const char *name,
 						  const char *linkage_name,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 009c52d..ca6a476 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -42,6 +42,7 @@
 #include "ada-lang.h"
 #include "p-lang.h"
 #include "addrmap.h"
+#include "cp-support.h"

#include "hashtab.h"

@@ -95,7 +96,8 @@ static
 struct symbol *lookup_symbol_aux_local (const char *name,
 					const char *linkage_name,
 					const struct block *block,
-					const domain_enum domain);
+					const domain_enum domain,
+					enum language language);

 static
 struct symbol *lookup_symbol_aux_symtabs (int block_index,
@@ -1291,7 +1293,7 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
   /* Search specified block and its superiors.  Don't search
      STATIC_BLOCK or GLOBAL_BLOCK.  */

-  sym = lookup_symbol_aux_local (name, linkage_name, block, domain);
+  sym = lookup_symbol_aux_local (name, linkage_name, block, domain, language);
   if (sym != NULL)
     return sym;

@@ -1361,27 +1363,41 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
 }

 /* Check to see if the symbol is defined in BLOCK or its superiors.
-   Don't search STATIC_BLOCK or GLOBAL_BLOCK.  */
+   Don't search GLOBAL_BLOCK.
+   In the case of C++ perform a namespace lookup and every block.  */

 static struct symbol *
 lookup_symbol_aux_local (const char *name, const char *linkage_name,
 			 const struct block *block,
-			 const domain_enum domain)
+			 const domain_enum domain,
+			 enum language language)
 {
   struct symbol *sym;
-  const struct block *static_block = block_static_block (block);
+  const struct block *global_block = block_global_block (block);
+  const struct language_defn *langdef;
+
+  langdef = language_def (language);

/* Check if either no block is specified or it's a global block. */

-  if (static_block == NULL)
+  if (global_block == NULL)
     return NULL;

-  while (block != static_block)
+  while (block != global_block)
     {
       sym = lookup_symbol_aux_block (name, linkage_name, block, domain);
       if (sym != NULL)
 	return sym;

+      if ( language == language_cplus )
+        {
+          sym = lookup_namespace_scope (name, linkage_name, block, domain,
+                                        block_scope (block), 0);
+
+          if (sym != NULL)
+            return sym;
+        }
+
       if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block))
 	break;
       block = BLOCK_SUPERBLOCK (block);
diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc
index 4786fd5..00fd47f 100644
--- a/gdb/testsuite/gdb.cp/namespace-using.cc
+++ b/gdb/testsuite/gdb.cp/namespace-using.cc
@@ -4,12 +4,26 @@ namespace A
   int x = 2;
 }

-int marker4(){
-	using A::x;
-	return 0;
+namespace C
+{
+  int cc = 3;
+}
+
+using namespace C;
+int marker5()
+{
+  cc;
+  return 0;
 }

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

diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp
index f24973f..210bfd7 100644
--- a/gdb/testsuite/gdb.cp/namespace-using.exp
+++ b/gdb/testsuite/gdb.cp/namespace-using.exp
@@ -28,6 +28,10 @@ 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 +77,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 +95,15 @@ 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"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]