[commit/c++] Make some namespace variables private to dwarf2read

Daniel Jacobowitz drow@false.org
Thu Aug 21 18:40:00 GMT 2008


This patch has no effect on GDB's behavior.  I've just moved two
global variables from cp-namespace.c to static in dwarf2read.c, and
moved two calls from buildsym.c to the dwarf2 and stabs readers.

My next patch will eliminate the variables, which used to be set only
for C++.  And I find this much clearer, since the global state is used
only indirectly.

Tested on x86_64-linux and committed.

-- 
Daniel Jacobowitz
CodeSourcery

2008-08-21  Daniel Jacobowitz  <dan@codesourcery.com>

	* buildsym.c (add_symbol_to_list): Do not call
	cp_scan_for_anonymous_namespaces here.
	(finish_block): Do not call cp_set_block_scope here.
	* cp-namespace.c (processing_has_namespace_info)
	(processing_current_prefix): Delete.
	(cp_initialize_namespace): Do not initialize
	processing_has_namespace_info.
	(cp_scan_for_anonymous_namespaces): Use SYMBOL_DEMANGLED_NAME.  Do
	not check processing_has_namespace_info.
	(cp_set_block_scope): Take prefix and namespace info flag as
	arguments.  Honor namespaces regardless of a demangled name.
	* cp-support.h (processing_has_namespace_info)
	(processing_current_prefix): Delete declarations.
	(cp_set_block_scope): Update prototype.
	* dbxread.c (process_one_symbol): Call cp_set_block_scope for C++.
	* dwarf2read.c (processing_has_namespace_info)
	(processing_current_prefix): New static variables.
	(read_file_scope): Initialize processing_has_namespace_info.
	(read_func_scope): Call cp_set_block_scope for C++.
	(new_symbol): Call cp_scan_for_anonymous_namespaces for C++.
	* stabsread.c (define_symbol): Call cp_scan_for_anonymous_namespaces
	for C++.
	* symtab.c (symbol_demangled_name): Accept a const argument.
	* symtab.h (symbol_demangled_name): Update prototype.

---
 buildsym.c     |   12 -------
 cp-namespace.c |   86 +++++++++++++++++----------------------------------------
 cp-support.h   |    8 +----
 dwarf2read.c   |   38 +++++++++++++++++++++++++
 symtab.c       |    2 -
 symtab.h       |    2 -
 6 files changed, 70 insertions(+), 78 deletions(-)

Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2008-08-21 13:22:27.000000000 -0400
+++ gdb/buildsym.c	2008-08-21 13:22:27.000000000 -0400
@@ -147,12 +147,6 @@ add_symbol_to_list (struct symbol *symbo
     }
 
   (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
-
-  /* Check to see if we might need to look for a mention of anonymous
-     namespaces.  */
-  
-  if (SYMBOL_LANGUAGE (symbol) == language_cplus)
-    cp_scan_for_anonymous_namespaces (symbol);
 }
 
 /* Find a symbol named NAME on a LIST.  NAME need not be
@@ -307,12 +301,6 @@ finish_block (struct symbol *symbol, str
 		}
 	    }
 	}
-
-      /* If we're in the C++ case, set the block's scope.  */
-      if (SYMBOL_LANGUAGE (symbol) == language_cplus)
-	{
-	  cp_set_block_scope (symbol, block, &objfile->objfile_obstack);
-	}
     }
   else
     {
Index: gdb/cp-namespace.c
===================================================================
--- gdb.orig/cp-namespace.c	2008-08-21 13:16:26.000000000 -0400
+++ gdb/cp-namespace.c	2008-08-21 13:37:35.000000000 -0400
@@ -31,32 +31,6 @@
 #include "command.h"
 #include "frame.h"
 
-/* When set, the file that we're processing is known to have debugging
-   info for C++ namespaces.  */
-
-/* NOTE: carlton/2004-01-13: No currently released version of GCC (the
-   latest of which is 3.3.x at the time of this writing) produces this
-   debug info.  GCC 3.4 should, however.  */
-
-unsigned char processing_has_namespace_info;
-
-/* This contains our best guess as to the name of the current
-   enclosing namespace(s)/class(es), if any.  For example, if we're
-   within the method foo() in the following code:
-
-    namespace N {
-      class C {
-	void foo () {
-	}
-      };
-    }
-
-   then processing_current_prefix should be set to "N::C".  If
-   processing_has_namespace_info is false, then this variable might
-   not be reliable.  */
-
-const char *processing_current_prefix;
-
 /* List of using directives that are active in the current file.  */
 
 static struct using_direct *using_list;
@@ -109,7 +83,6 @@ static void maintenance_cplus_namespace 
 
 void cp_initialize_namespace ()
 {
-  processing_has_namespace_info = 0;
   using_list = NULL;
 }
 
@@ -140,10 +113,9 @@ cp_finalize_namespace (struct block *sta
 void
 cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
 {
-  if (!processing_has_namespace_info
-      && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
+  if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
     {
-      const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
+      const char *name = SYMBOL_DEMANGLED_NAME (symbol);
       unsigned int previous_component;
       unsigned int next_component;
       const char *len;
@@ -217,38 +189,34 @@ cp_add_using_directive (const char *name
 void
 cp_set_block_scope (const struct symbol *symbol,
 		    struct block *block,
-		    struct obstack *obstack)
+		    struct obstack *obstack,
+		    const char *processing_current_prefix,
+		    int processing_has_namespace_info)
 {
-  /* Make sure that the name was originally mangled: if not, there
-     certainly isn't any namespace information to worry about!  */
-
-  if (SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
+  if (processing_has_namespace_info)
     {
-      if (processing_has_namespace_info)
-	{
-	  block_set_scope
-	    (block, obsavestring (processing_current_prefix,
-				  strlen (processing_current_prefix),
-				  obstack),
-	     obstack);
-	}
-      else
-	{
-	  /* Try to figure out the appropriate namespace from the
-	     demangled name.  */
+      block_set_scope
+	(block, obsavestring (processing_current_prefix,
+			      strlen (processing_current_prefix),
+			      obstack),
+	 obstack);
+    }
+  else if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
+    {
+      /* Try to figure out the appropriate namespace from the
+	 demangled name.  */
 
-	  /* FIXME: carlton/2003-04-15: If the function in question is
-	     a method of a class, the name will actually include the
-	     name of the class as well.  This should be harmless, but
-	     is a little unfortunate.  */
-
-	  const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
-	  unsigned int prefix_len = cp_entire_prefix_len (name);
-
-	  block_set_scope (block,
-			   obsavestring (name, prefix_len, obstack),
-			   obstack);
-	}
+      /* FIXME: carlton/2003-04-15: If the function in question is
+	 a method of a class, the name will actually include the
+	 name of the class as well.  This should be harmless, but
+	 is a little unfortunate.  */
+
+      const char *name = SYMBOL_DEMANGLED_NAME (symbol);
+      unsigned int prefix_len = cp_entire_prefix_len (name);
+
+      block_set_scope (block,
+		       obsavestring (name, prefix_len, obstack),
+		       obstack);
     }
 }
 
Index: gdb/cp-support.h
===================================================================
--- gdb.orig/cp-support.h	2008-08-21 13:22:27.000000000 -0400
+++ gdb/cp-support.h	2008-08-21 13:22:27.000000000 -0400
@@ -74,10 +74,6 @@ extern struct type *cp_lookup_rtti_type 
 
 /* Functions/variables from cp-namespace.c.  */
 
-extern unsigned char processing_has_namespace_info;
-
-extern const char *processing_current_prefix;
-
 extern int cp_is_anonymous (const char *namespace);
 
 extern void cp_add_using_directive (const char *name,
@@ -91,7 +87,9 @@ extern void cp_finalize_namespace (struc
 
 extern void cp_set_block_scope (const struct symbol *symbol,
 				struct block *block,
-				struct obstack *obstack);
+				struct obstack *obstack,
+				const char *processing_current_prefix,
+				int processing_has_namespace_info);
 
 extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol);
 
Index: gdb/dwarf2read.c
===================================================================
--- gdb.orig/dwarf2read.c	2008-08-21 13:22:27.000000000 -0400
+++ gdb/dwarf2read.c	2008-08-21 13:37:01.000000000 -0400
@@ -141,6 +141,29 @@ typedef struct statement_prologue
   }
 _STATEMENT_PROLOGUE;
 
+/* When set, the file that we're processing is known to have debugging
+   info for C++ namespaces.  GCC 3.3.x did not produce this information,
+   but later versions do.  */
+
+static int processing_has_namespace_info;
+
+/* This contains our best guess as to the name of the current
+   enclosing namespace(s)/class(es), if any.  For example, if we're
+   within the method foo() in the following code:
+
+    namespace N {
+      class C {
+	void foo () {
+	}
+      };
+    }
+
+   then processing_current_prefix should be set to "N::C".  If
+   processing_has_namespace_info is false, then this variable might
+   not be reliable.  */
+
+static const char *processing_current_prefix;
+
 static const struct objfile_data *dwarf2_objfile_data_key;
 
 struct dwarf2_per_objfile
@@ -2850,6 +2873,8 @@ read_file_scope (struct die_info *die, s
   /* We assume that we're processing GCC output. */
   processing_gcc_compilation = 2;
 
+  processing_has_namespace_info = 0;
+
   start_symtab (name, comp_dir, lowpc);
   record_debugformat ("DWARF 2");
   record_producer (cu->producer);
@@ -3020,6 +3045,12 @@ read_func_scope (struct die_info *die, s
   block = finish_block (new->name, &local_symbols, new->old_blocks,
                         lowpc, highpc, objfile);
 
+  /* For C++, set the block's scope.  */
+  if (cu->language == language_cplus)
+    cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
+			processing_current_prefix,
+			processing_has_namespace_info);
+
   /* If we have address ranges, record them.  */
   dwarf2_record_block_ranges (die, block, baseaddr, cu);
   
@@ -7606,6 +7637,13 @@ new_symbol (struct die_info *die, struct
 		     dwarf_tag_name (die->tag));
 	  break;
 	}
+
+      /* For the benefit of old versions of GCC, check for anonymous
+	 namespaces based on the demangled name.  */
+      if (!processing_has_namespace_info
+	  && cu->language == language_cplus
+	  && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
+	cp_scan_for_anonymous_namespaces (sym);
     }
   return (sym);
 }
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2008-08-21 13:16:26.000000000 -0400
+++ gdb/symtab.c	2008-08-21 13:22:27.000000000 -0400
@@ -651,7 +651,7 @@ symbol_natural_name (const struct genera
 /* Return the demangled name for a symbol based on the language for
    that symbol.  If no demangled name exists, return NULL. */
 char *
-symbol_demangled_name (struct general_symbol_info *gsymbol)
+symbol_demangled_name (const struct general_symbol_info *gsymbol)
 {
   switch (gsymbol->language) 
     {
Index: gdb/symtab.h
===================================================================
--- gdb.orig/symtab.h	2008-08-21 13:22:27.000000000 -0400
+++ gdb/symtab.h	2008-08-21 13:22:27.000000000 -0400
@@ -224,7 +224,7 @@ extern char *symbol_natural_name (const 
    that symbol.  If no demangled name exists, return NULL. */
 #define SYMBOL_DEMANGLED_NAME(symbol) \
   (symbol_demangled_name (&(symbol)->ginfo))
-extern char *symbol_demangled_name (struct general_symbol_info *symbol);
+extern char *symbol_demangled_name (const struct general_symbol_info *symbol);
 
 /* Macro that returns a version of the name of a symbol that is
    suitable for output.  In C++ this is the "demangled" form of the



More information about the Gdb-patches mailing list