[rfa] set demangled names of partial symbols

David Carlton carlton@math.stanford.edu
Mon Dec 23 12:13:00 GMT 2002


Currently, partial symbols don't have their demangled names set.  It's
remarkable that GDB still seems to work just fine without having
demangled names set; as far as I can tell, the basic reason why it
works is that mangled names exist for the sake of the linker, so this
failing is frequently covered up by minimal symbols.

Nonetheless, it's not a good idea.  Here's a patch; it updates
add_psymbol_to_list to set the mangled name of the partial symbol.  I
also noticed a comment in search_symbols that needed to be updated
because of this change.

I've tested this on i686-pc-linux-gnu/gcc-3.1/dwarf-2, both with and
without my latest patch to lookupup_symbol_aux_minsyms.  I also ran
GDB on itself to verify that demangled names weren't getting set
before this patch but are getting set after this patch.

David Carlton
carlton@math.stanford.edu

2002-12-23  David Carlton  <carlton@math.stanford.edu>

	* symfile.c (psymbol_init_demangled_name): New function.
	(add_psymbol_to_list): Call psymbol_init_demangled_name instead of
	INIT_LANGUAGE_SPECIFIC.
	* symtab.c (search_symbols): Update comment.

Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.75
diff -u -p -r1.75 symfile.c
--- symfile.c	9 Dec 2002 00:59:26 -0000	1.75
+++ symfile.c	23 Dec 2002 19:04:41 -0000
@@ -114,6 +114,9 @@ static void find_sym_fns (struct objfile
 
 static void decrement_reading_symtab (void *);
 
+static void psymbol_init_demangled_name (struct partial_symbol *psymbol,
+					 struct bcache *bcache);
+
 static void overlay_invalidate_all (void);
 
 static int overlay_is_mapped (struct obj_section *);
@@ -2396,7 +2399,7 @@ add_psymbol_to_list (char *name, int nam
   SYMBOL_LANGUAGE (&psymbol) = language;
   PSYMBOL_NAMESPACE (&psymbol) = namespace;
   PSYMBOL_CLASS (&psymbol) = class;
-  SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
+  psymbol_init_demangled_name (&psymbol, objfile->psymbol_cache);
 
   /* Stash the partial symbol away in the cache */
   psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
@@ -2408,6 +2411,50 @@ add_psymbol_to_list (char *name, int nam
     }
   *list->next++ = psym;
   OBJSTAT (objfile, n_psyms++);
+}
+
+/* Initialize the demangled name for PSYMBOL, using bcache CACHE to
+   store the demangle name if necessary.  */
+
+static void
+psymbol_init_demangled_name (struct partial_symbol *psymbol,
+			     struct bcache *cache)
+{
+  char *demangled;
+
+  SYMBOL_CPLUS_DEMANGLED_NAME (psymbol) = NULL;
+
+  if (SYMBOL_LANGUAGE (psymbol) == language_unknown)
+    SYMBOL_LANGUAGE (psymbol) = language_auto;
+
+  switch (SYMBOL_LANGUAGE (psymbol))
+    {
+    case language_cplus:
+    case language_auto:
+      demangled = cplus_demangle (SYMBOL_NAME (psymbol),
+				  DMGL_PARAMS | DMGL_ANSI);
+      if (demangled != NULL)
+	{
+	  SYMBOL_LANGUAGE (psymbol) = language_cplus;
+	  SYMBOL_CPLUS_DEMANGLED_NAME (psymbol)
+	    = bcache (demangled, strlen (demangled) + 1, cache);
+	  xfree (demangled);
+	}
+      break;
+    case language_java:
+      demangled =
+	cplus_demangle (SYMBOL_NAME (psymbol),
+			DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
+      if (demangled != NULL)
+	{
+	  SYMBOL_LANGUAGE (psymbol) = language_java;
+	  SYMBOL_CPLUS_DEMANGLED_NAME (psymbol)
+	    = bcache (demangled, strlen (demangled) + 1, cache);
+	  xfree (demangled);
+	}
+    default:
+      break;
+    }
 }
 
 /* Add a symbol with a long value to a psymtab. This differs from
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.83
diff -u -p -r1.83 symtab.c
--- symtab.c	23 Dec 2002 16:43:18 -0000	1.83
+++ symtab.c	23 Dec 2002 19:06:01 -0000
@@ -2872,8 +2872,6 @@ search_symbols (char *regexp, namespace_
 
   /* Here, we search through the minimal symbol tables for functions
      and variables that match, and force their symbols to be read.
-     This is in particular necessary for demangled variable names,
-     which are no longer put into the partial symbol tables.
      The symbol will then be found during the scan of symtabs below.
 
      For functions, find_pc_symtab should succeed if we have debug info



More information about the Gdb-patches mailing list