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]

[3/10] RFC: fix PR c++/11990


This patch fixes PR c++/11990.

The bug is that in some cases the user can see:

warning: can't find linker symbol for virtual table for `blahblah' value

This can happen when the vtable symbol has a version suffix.

This fixes the problem by first changing gdb to use bfd_demangle
everywhere (via a new wrapper function, gdb_demangle).  bfd_demangle
handles the version suffix for us.

Also this adds some code to gnuv3_rtti_type to strip the @plt or version
suffix before looking up the symbol.

Built and regtested on x86-64 Fedora 16.

Tom

	PR c++/11990
	* c-lang.c (cplus_language_defn): Use gdb_demangle.
	* c-typeprint.c (c_type_print_base): Use gdb_demangle.
	* cp-support.c (mangled_name_to_comp): Use gdb_demangle.
	(gdb_demangle): New function.
	* cp-support.h (gdb_demangle): Declare.
	* dwarf2read.c (dwarf2_physname, fixup_partial_die)
	(dwarf2_name): Use gdb_demangle.
	* gdbtypes.c (check_stub_method): Use gdb_demangle.
	* gnu-v3-abi.c (gnuv3_rtti_type): Strip @plt and version
	suffixes from name.
	(gnuv3_print_method_ptr): Use gdb_demangle.
	* jv-lang.c (java_demangle): Use gdb_demangle.
	* jv-typeprint.c (java_type_print_base): Use gdb_demangle.
	* language.c (unk_lang_demangle): Use gdb_demangle.
	* symtab.c (symbol_find_demangled_name)
	(demangle_for_lookup): Use gdb_demangle.
---
 gdb/c-lang.c       |    2 +-
 gdb/c-typeprint.c  |    4 ++--
 gdb/cp-support.c   |   10 +++++++++-
 gdb/cp-support.h   |    4 ++++
 gdb/dwarf2read.c   |   14 +++++++-------
 gdb/gdbtypes.c     |    5 +++--
 gdb/gnu-v3-abi.c   |   17 +++++++++++++++--
 gdb/jv-lang.c      |    3 ++-
 gdb/jv-typeprint.c |    5 +++--
 gdb/language.c     |    3 ++-
 gdb/symtab.c       |   12 ++++++------
 11 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 91cb21e..0d234b2 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -959,7 +959,7 @@ const struct language_defn cplus_language_defn =
   "this",                       /* name_of_this */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   cp_lookup_transparent_type,   /* lookup_transparent_type */
-  cplus_demangle,		/* Language specific symbol demangler */
+  gdb_demangle,			/* Language specific symbol demangler */
   cp_class_name_from_physname,  /* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index ca8d89b..bf4564f 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1227,8 +1227,8 @@ c_type_print_base (struct type *type, struct ui_file *stream,
 		    mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
 
 		  demangled_name =
-		    cplus_demangle (mangled_name,
-				    DMGL_ANSI | DMGL_PARAMS);
+		    gdb_demangle (mangled_name,
+				  DMGL_ANSI | DMGL_PARAMS);
 		  if (demangled_name == NULL)
 		    {
 		      /* In some cases (for instance with the HP
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 22e8fc4..3c1442d 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -635,7 +635,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
 
   /* If it doesn't, or if that failed, then try to demangle the
      name.  */
-  demangled_name = cplus_demangle (mangled_name, options);
+  demangled_name = gdb_demangle (mangled_name, options);
   if (demangled_name == NULL)
    return NULL;
   
@@ -1476,6 +1476,14 @@ cp_lookup_rtti_type (const char *name, struct block *block)
   return rtti_type;
 }
 
+/* A wrapper for bfd_demangle.  */
+
+char *
+gdb_demangle (const char *name, int options)
+{
+  return bfd_demangle (NULL, name, options);
+}
+
 /* Don't allow just "maintenance cplus".  */
 
 static  void
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index c7141d5..0f2cebb 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -241,4 +241,8 @@ extern struct demangle_parse_info *cp_new_demangle_parse_info (void);
 
 extern struct cmd_list_element *maint_cplus_cmd_list;
 
+/* A wrapper for bfd_demangle.  */
+
+char *gdb_demangle (const char *name, int options);
+
 #endif /* CP_SUPPORT_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index df6298b..3cd655b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -7653,11 +7653,11 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
 	}
       else
 	{
-	  demangled = cplus_demangle (mangled,
-				      (DMGL_PARAMS | DMGL_ANSI
-				       | (cu->language == language_java
-					  ? DMGL_JAVA | DMGL_RET_POSTFIX
-					  : DMGL_RET_DROP)));
+	  demangled = gdb_demangle (mangled,
+				    (DMGL_PARAMS | DMGL_ANSI
+				     | (cu->language == language_java
+					? DMGL_JAVA | DMGL_RET_POSTFIX
+					: DMGL_RET_DROP)));
 	}
       if (demangled)
 	{
@@ -13979,7 +13979,7 @@ fixup_partial_die (struct partial_die_info *part_die,
     {
       char *demangled;
 
-      demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
+      demangled = gdb_demangle (part_die->linkage_name, DMGL_TYPES);
       if (demangled)
 	{
 	  const char *base;
@@ -17033,7 +17033,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
 	  /* Avoid demangling DW_STRING (attr) the second time on a second
 	     call for the same DIE.  */
 	  if (!DW_STRING_IS_CANONICAL (attr))
-	    demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
+	    demangled = gdb_demangle (DW_STRING (attr), DMGL_TYPES);
 
 	  if (demangled)
 	    {
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 12730d7..e7a22cc 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -37,6 +37,7 @@
 #include "gdb_assert.h"
 #include "hashtab.h"
 #include "exceptions.h"
+#include "cp-support.h"
 
 /* Initialize BADNESS constants.  */
 
@@ -1764,8 +1765,8 @@ check_stub_method (struct type *type, int method_id, int signature_id)
   struct gdbarch *gdbarch = get_type_arch (type);
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
-  char *demangled_name = cplus_demangle (mangled_name,
-					 DMGL_PARAMS | DMGL_ANSI);
+  char *demangled_name = gdb_demangle (mangled_name,
+				       DMGL_PARAMS | DMGL_ANSI);
   char *argtypetext, *p;
   int depth = 0, argcount = 1;
   struct field *argtypes;
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 3265663..d02f95d 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -283,6 +283,7 @@ gnuv3_rtti_type (struct value *value,
   const char *class_name;
   struct type *run_time_type;
   LONGEST offset_to_top;
+  char *atsign;
 
   /* We only have RTTI for class objects.  */
   if (TYPE_CODE (values_type) != TYPE_CODE_CLASS)
@@ -327,6 +328,18 @@ gnuv3_rtti_type (struct value *value,
     }
   class_name = vtable_symbol_name + 11;
 
+  /* Strip off @plt and version suffixes.  */
+  atsign = strchr (class_name, '@');
+  if (atsign != NULL)
+    {
+      char *copy;
+
+      copy = alloca (atsign - class_name + 1);
+      memcpy (copy, class_name, atsign - class_name);
+      copy[atsign - class_name] = '\0';
+      class_name = copy;
+    }
+
   /* Try to look up the class name as a type name.  */
   /* FIXME: chastain/2003-11-26: block=NULL is bogus.  See pr gdb/1465.  */
   run_time_type = cp_lookup_rtti_type (class_name, NULL);
@@ -593,8 +606,8 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
 	 possible paths to the method based on the adjustment.  */
       if (physname)
 	{
-	  char *demangled_name = cplus_demangle (physname,
-						 DMGL_ANSI | DMGL_PARAMS);
+	  char *demangled_name = gdb_demangle (physname,
+					       DMGL_ANSI | DMGL_PARAMS);
 
 	  fprintf_filtered (stream, "&virtual ");
 	  if (demangled_name == NULL)
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 48b5b3c..b0e9b42 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -39,6 +39,7 @@
 #include "gdb_assert.h"
 #include "charset.h"
 #include "valprint.h"
+#include "cp-support.h"
 
 /* Local functions */
 
@@ -1012,7 +1013,7 @@ nosideret:
 
 static char *java_demangle (const char *mangled, int options)
 {
-  return cplus_demangle (mangled, options | DMGL_JAVA);
+  return gdb_demangle (mangled, options | DMGL_JAVA);
 }
 
 /* Find the member function name of the demangled name NAME.  NAME
diff --git a/gdb/jv-typeprint.c b/gdb/jv-typeprint.c
index 69ebf5a..23b3f4e 100644
--- a/gdb/jv-typeprint.c
+++ b/gdb/jv-typeprint.c
@@ -28,6 +28,7 @@
 #include "typeprint.h"
 #include "c-lang.h"
 #include "cp-abi.h"
+#include "cp-support.h"
 #include "gdb_assert.h"
 
 /* Local functions */
@@ -286,8 +287,8 @@ java_type_print_base (struct type *type, struct ui_file *stream, int show,
 		    mangled_name = physname;
 
 		  demangled_name =
-		    cplus_demangle (mangled_name,
-				    DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
+		    gdb_demangle (mangled_name,
+				  DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
 
 		  if (demangled_name == NULL)
 		    demangled_name = xstrdup (mangled_name);
diff --git a/gdb/language.c b/gdb/language.c
index c873f2e..10073e1 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -43,6 +43,7 @@
 #include "jv-lang.h"
 #include "demangle.h"
 #include "symfile.h"
+#include "cp-support.h"
 
 extern void _initialize_language (void);
 
@@ -764,7 +765,7 @@ static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
 /* Unknown languages just use the cplus demangler.  */
 static char *unk_lang_demangle (const char *mangled, int options)
 {
-  return cplus_demangle (mangled, options);
+  return gdb_demangle (mangled, options);
 }
 
 static char *unk_lang_class_name (const char *mangled)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 57441c1..572db3f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -567,7 +567,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
       || gsymbol->language == language_auto)
     {
       demangled =
-        cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
+        gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
       if (demangled != NULL)
 	{
 	  gsymbol->language = language_cplus;
@@ -577,8 +577,8 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
   if (gsymbol->language == language_java)
     {
       demangled =
-        cplus_demangle (mangled,
-                        DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
+        gdb_demangle (mangled,
+		      DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
       if (demangled != NULL)
 	{
 	  gsymbol->language = language_java;
@@ -1128,7 +1128,7 @@ demangle_for_lookup (const char *name, enum language lang,
      lookup, so we can always binary search.  */
   if (lang == language_cplus)
     {
-      demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
+      demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
       if (demangled_name)
 	{
 	  modified_name = demangled_name;
@@ -1148,8 +1148,8 @@ demangle_for_lookup (const char *name, enum language lang,
     }
   else if (lang == language_java)
     {
-      demangled_name = cplus_demangle (name,
-		      		       DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
+      demangled_name = gdb_demangle (name,
+				     DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
       if (demangled_name)
 	{
 	  modified_name = demangled_name;
-- 
1.7.7.6


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