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] Fix C++ demangling of minsyms with symver


Hi,

this is not for any regressions, just while playing with breakpoints I have
noticed GDB cannot break on some libstdc++ versioned symbols because the
demangler fails due to the `@...' suffix:

00000000000607d0 T std::istream::ignore()@@GLIBCXX_3.4.5
00000000000607d0 T std::istream::ignore()@GLIBCXX_3.4

(gdb) b 'std::istream::ignore()@GLIBCXX_3.4' 
Breakpoint 1 at 0x607d0: file /usr/src/debug/gcc-4.6.0-20110509/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/istream.tcc, line 461.
(gdb) b 'std::istream::ignore()@@GLIBCXX_3.4.5' 
Note: breakpoint 1 also set at pc 0x607d0.
Breakpoint 2 at 0x607d0: file /usr/src/debug/gcc-4.6.0-20110509/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/istream.tcc, line 461.
(gdb) b 'std::istream::ignore()'                
Function "std::istream::ignore()" not defined.

This is not exactly reproducible with FSF GDB HEAD + this patch as it needs
other patches (such as removing DMGL_VERBOSE and others).  But it is
independent enough with a clear testcase so posting it separately for
simplicity.

One can see the default resolving to the @@ variant is not implemented.  Not
sure if it should be but let that be a possible incremental patch in the
future.

No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu.  I will check
it in (not for 7.3) in some time if no comments appear.


Thanks,
Jan


gdb/
2011-06-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* symtab.c (symbol_find_demangled_name): New parameter objfile.  Always
	call bfd_demangle, not cplus_demangle.
	(symbol_set_names): Pass OBJFILE.

gdb/testsuite/
2011-06-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/cp-symver.cc: New file.
	* gdb.cp/cp-symver.exp: New file.

--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -478,7 +478,7 @@ create_demangled_names_hash (struct objfile *objfile)
 
 static char *
 symbol_find_demangled_name (struct general_symbol_info *gsymbol,
-			    const char *mangled)
+			    const char *mangled, struct objfile *objfile)
 {
   char *demangled = NULL;
 
@@ -499,8 +499,8 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
   if (gsymbol->language == language_cplus
       || gsymbol->language == language_auto)
     {
-      demangled =
-        cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
+      demangled = bfd_demangle (objfile->obfd, mangled,
+				DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
       if (demangled != NULL)
 	{
 	  gsymbol->language = language_cplus;
@@ -509,9 +509,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);
+      demangled = bfd_demangle (objfile->obfd, mangled,
+				DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
       if (demangled != NULL)
 	{
 	  gsymbol->language = language_java;
@@ -651,7 +650,8 @@ symbol_set_names (struct general_symbol_info *gsymbol,
   if (*slot == NULL)
     {
       char *demangled_name = symbol_find_demangled_name (gsymbol,
-							 linkage_name_copy);
+							 linkage_name_copy,
+							 objfile);
       int demangled_len = demangled_name ? strlen (demangled_name) : 0;
 
       /* Suppose we have demangled_name==NULL, copy_name==0, and
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/cp-symver.cc
@@ -0,0 +1,33 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2011 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/>.  */
+
+void a () {} /* at-func-a */
+
+/* Give `a' external name `v()' requiring version `VER_A'.  */
+asm (".symver _Z1av, _Z1vv@VER_A");
+
+void b () {} /* at-func-b */
+
+/* Give `b' external name `v()' with default version `VER_B'.  */
+asm (".symver _Z1bv, _Z1vv@@VER_B");
+
+int
+main ()
+{
+  a ();
+  b ();
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/cp-symver.exp
@@ -0,0 +1,38 @@
+# Copyright 2011 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/>.
+
+# Test C++ demangling of versioned symbols.
+
+set testfile cp-symver
+set srcfile ${testfile}.cc
+if [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] {
+    return -1
+}
+
+if ![runto_main] {
+    untested ${testfile}.exp
+    return -1
+}
+
+gdb_test_no_output "set breakpoint pending off"
+
+gdb_breakpoint {'v()@VER_A'}
+gdb_breakpoint {'v()@@VER_B'}
+
+# GDB currently does not support the default version assumption.
+gdb_test "break v()" {Function "v\(\)" not defined\.}
+
+gdb_continue_to_breakpoint "a" ".* at-func-a .*"
+gdb_continue_to_breakpoint "b" ".* at-func-b .*"


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