]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
commit 9e7800188627afaf57ab34bc74615c36baaf68d2
authorJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 2 Jul 2011 19:59:30 +0000 (19:59 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 2 Jul 2011 19:59:30 +0000 (19:59 +0000)
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Fri Jul 1 19:12:09 2011 +0000

gdb/
* dwarf2read.c (check_physname): New variable.
(dwarf2_physname): Prefer DW_AT_linkage_name over dwarf2_compute_name.
(show_check_physname): New function.
(_initialize_dwarf2_read): Add `check-physname' for check_physname.

gdb/doc/
* gdb.texinfo (Debugging Output): Document set debug
check-physname.

gdb/testsuite/
* gdb.base/break-interp.exp (reach_1, test_ld): Allow also the prefix
__GI_.
* gdb.cp/psymtab-parameter.cc (func): Make it a template function.
(f): New function.
* gdb.cp/psymtab-parameter.exp (complete break 'func(): Rename to ...
(complete p 'func<short>(): ... here.
* gdb.dwarf2/dw2-linkage-name-trust-main.cc: New file.
* gdb.dwarf2/dw2-linkage-name-trust.S: New file.
* gdb.dwarf2/dw2-linkage-name-trust.exp: New file.
* gdb.cp/temargs.exp (test type of F in k3_m, test value of F in k3_m):
Make them KFAIL gcc/49546.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/break-interp.exp
gdb/testsuite/gdb.cp/psymtab-parameter.cc
gdb/testsuite/gdb.cp/psymtab-parameter.exp
gdb/testsuite/gdb.cp/temargs.exp

index fc26e13e2f010090c3e4a403b9960c2c69cdac19..d91f0dca9a37b24c08df2f3ecfd25fc39163d612 100644 (file)
@@ -1,3 +1,11 @@
+2011-07-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
+           Tom Tromey  <tromey@redhat.com>
+
+       * dwarf2read.c (check_physname): New variable.
+       (dwarf2_physname): Prefer DW_AT_linkage_name over dwarf2_compute_name.
+       (show_check_physname): New function.
+       (_initialize_dwarf2_read): Add `check-physname' for check_physname.
+
 2011-07-02  Keith Seitz  <keiths@redhat.com>
 
        * objc-lang.c (find_methods): Increment objfile_csym earlier.
index 02b8e62eb2c55fa3ae0c56b9e5bfc8e2d6d79b24..3d8639b6165c6f5d3a5ab784a5c3cce9b27c446f 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-02  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.texinfo (Debugging Output): Document set debug
+       check-physname.
+
 2011-06-03  Tom Tromey  <tromey@redhat.com>
 
        * gdb.texinfo (GDB/MI Async Records): Document 'exit-code' field.
index e3d824e1750c7a920201f19e18a4237d0b84407a..b6bec6a13aa6a4f57fd749f8aad94b8f172ba473 100644 (file)
@@ -19949,6 +19949,16 @@ Display debugging messages about inner workings of the AIX thread
 module.
 @item show debug aix-thread
 Show the current state of AIX thread debugging info display.
+@item set debug check-physname
+@cindex physname
+Check the results of the ``physname'' computation.  When reading DWARF
+debugging information for C@t{++}, @value{GDBN} attempts to compute
+each entity's name.  @value{GDBN} can do this computation in two
+different ways, depending on exactly what information is present.
+When enabled, this setting causes @value{GDBN} to compute the names
+both ways and display any discrepancies.
+@item show debug check-physname
+Show the current state of ``physname'' checking.
 @item set debug dwarf2-die
 @cindex DWARF2 DIEs
 Dump DWARF2 DIEs after they are read in.
index e93451feee56b0a444652f55a6cd5fe13baceea1..7a2632b79b23a2245ac68705f8ad8e205d7b6ba0 100644 (file)
@@ -119,6 +119,9 @@ _STATEMENT_PROLOGUE;
 /* When non-zero, dump DIEs after they are read in.  */
 static int dwarf2_die_debug = 0;
 
+/* When non-zero, cross-check physname against demangler.  */
+static int check_physname = 0;
+
 static int pagesize;
 
 /* When set, the file that we're processing is known to have debugging
@@ -5115,7 +5118,91 @@ dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
 static const char *
 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
 {
-  return dwarf2_compute_name (name, die, cu, 1);
+  struct attribute *attr;
+  const char *retval, *mangled = NULL, *canon = NULL;
+  struct cleanup *back_to;
+  int need_copy = 1;
+
+  /* In this case dwarf2_compute_name is just a shortcut not building anything
+     on its own.  */
+  if (!die_needs_namespace (die, cu))
+    return dwarf2_compute_name (name, die, cu, 1);
+
+  back_to = make_cleanup (null_cleanup, NULL);
+
+  attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
+  if (!attr)
+    attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
+
+  /* DW_AT_linkage_name is missing in some cases - depend on what GDB
+     has computed.  */
+  if (attr && DW_STRING (attr))
+    {
+      char *demangled;
+
+      mangled = DW_STRING (attr);
+
+      /* Use DMGL_RET_DROP for C++ template functions to suppress their return
+        type.  It is easier for GDB users to search for such functions as
+        `name(params)' than `long name(params)'.  In such case the minimal
+        symbol names do not match the full symbol names but for template
+        functions there is never a need to look up their definition from their
+        declaration so the only disadvantage remains the minimal symbol
+        variant `long name(params)' does not have the proper inferior type.
+        */
+
+      demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
+                                           | (cu->language == language_java
+                                              ? DMGL_JAVA | DMGL_RET_POSTFIX
+                                              : DMGL_RET_DROP)));
+      if (demangled)
+       {
+         make_cleanup (xfree, demangled);
+         canon = demangled;
+       }
+      else
+       {
+         canon = mangled;
+         need_copy = 0;
+       }
+    }
+
+  if (canon == NULL || check_physname)
+    {
+      const char *physname = dwarf2_compute_name (name, die, cu, 1);
+
+      if (canon != NULL && strcmp (physname, canon) != 0)
+       {
+         /* It may not mean a bug in GDB.  The compiler could also
+            compute DW_AT_linkage_name incorrectly.  But in such case
+            GDB would need to be bug-to-bug compatible.  */
+
+         complaint (&symfile_complaints,
+                    _("Computed physname <%s> does not match demangled <%s> "
+                      "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
+                    physname, canon, mangled, die->offset, cu->objfile->name);
+
+         /* Prefer DW_AT_linkage_name (in the CANON form) - when it
+            is available here - over computed PHYSNAME.  It is safer
+            against both buggy GDB and buggy compilers.  */
+
+         retval = canon;
+       }
+      else
+       {
+         retval = physname;
+         need_copy = 0;
+       }
+    }
+  else
+    retval = canon;
+
+  if (need_copy)
+    retval = obsavestring (retval, strlen (retval),
+                          &cu->objfile->objfile_obstack);
+
+  do_cleanups (back_to);
+  return retval;
 }
 
 /* Read the import statement specified by the given die and record it.  */
@@ -16154,6 +16241,15 @@ show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
                    value);
 }
 
+static void
+show_check_physname (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+                   _("Whether to check \"physname\" is %s.\n"),
+                   value);
+}
+
 void _initialize_dwarf2_read (void);
 
 void
@@ -16209,6 +16305,14 @@ The value is the maximum depth to print."),
                            NULL,
                            &setdebuglist, &showdebuglist);
 
+  add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
+Set cross-checking of \"physname\" code against demangler."), _("\
+Show cross-checking of \"physname\" code against demangler."), _("\
+When enabled, GDB's internal \"physname\" code is checked against\n\
+the demangler."),
+                          NULL, show_check_physname,
+                          &setdebuglist, &showdebuglist);
+
   c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
               _("\
 Save a gdb-index file.\n\
index fcab0026651c804512f0c6cbd7676d0ee7a32dfb..77fd413b4ed852120e1e94f152e8e11044bf7c33 100644 (file)
@@ -1,3 +1,17 @@
+2011-07-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * gdb.base/break-interp.exp (reach_1, test_ld): Allow also the prefix
+       __GI_.
+       * gdb.cp/psymtab-parameter.cc (func): Make it a template function.
+       (f): New function.
+       * gdb.cp/psymtab-parameter.exp (complete break 'func(): Rename to ...
+       (complete p 'func<short>(): ... here.
+       * gdb.dwarf2/dw2-linkage-name-trust-main.cc: New file.
+       * gdb.dwarf2/dw2-linkage-name-trust.S: New file.
+       * gdb.dwarf2/dw2-linkage-name-trust.exp: New file.
+       * gdb.cp/temargs.exp (test type of F in k3_m, test value of F in k3_m):
+       Make them KFAIL gcc/49546.
+
 2011-07-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        Test GCC PR debug/49546.
index fe79cae55348bd26af9dea219691af3eddce4e42..b8519e2295810efdeeee0fc7d0d02081eeea3aee 100644 (file)
@@ -140,14 +140,14 @@ proc reach_1 {func command displacement} {
            }
            exp_continue
        }
-       -re "Breakpoint \[0-9\]+, \\.?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
+       -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
            if {$func == "_dl_debug_state"} {
                fail $test
            } else {
                pass $test
            }
        }
-       -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?$func \\(\\).*\r\n$gdb_prompt $" {
+       -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
            if {$func == "_dl_debug_state"} {
                fail $test
            } else {
@@ -395,7 +395,7 @@ proc test_ld {file ifmain trynosym displacement} {
 
     reach "_dl_debug_state" "run" $displacement
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m_dl_debug_state\\M.*" "dl bt"
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
 
     if $ifmain {
        reach "main" continue "NONE"
index a578c88c531b248cdaab7baa1c6ab123e0d4aad2..c2647d8d5fa74cc54f5abb6f3114245b24a9aad5 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
 
-typedef int typedefed;
-void func (typedefed param)
+template <typename T>
+long
+func ()
 {
 }
+
+void
+f ()
+{
+  func<short> ();
+}
index 7032239b07d77ad162f225d5db09dc26eafeee21..ff421b2233b7d5affc0ade645d98757ad1312ccd 100644 (file)
@@ -35,5 +35,6 @@ gdb_test_no_output "set language c++"
 # XFAIL than FAIL here.  For example -readnow breaks it.
 gdb_test_no_output "maintenance info symtabs"
 
-# GDB has shown only the `func(int)' entry before.
-gdb_test "complete break 'func(" "break 'func\\(int\\)\r\nbreak 'func\\(typedefed\\)"
+# GDB has shown only the `long func<short>()' ELF symbol before, not the DWARF
+# symbol
+gdb_test "complete p 'func<short>(" "p 'func<short>\\(\\)"
index 6ef69c166b0977774e2459f2a6e10fe243d26fb9..cd1eb53134daafc1ab78f7c6e49a8d5f534554af 100644 (file)
@@ -153,9 +153,11 @@ gdb_test "whatis Q" "short" "test type of Q in templ_m"
 
 gdb_continue_to_breakpoint "continue to sixth breakpoint for temargs"
 
-if $have_older_template_gcc { setup_xfail "*-*-*" }
+if $have_older_template_gcc { setup_xfail "*-*-*"
+} else { setup_kfail gcc/49546 "*-*-*" }
 gdb_test "ptype F" {type = void \(\*\)\(int\)} "test type of F in k3_m"
 
-if $have_older_template_gcc { setup_xfail "*-*-*" }
+if $have_older_template_gcc { setup_xfail "*-*-*"
+} else { setup_kfail gcc/49546 "*-*-*" }
 gdb_test "print F" { = \(void \(\*\)\(int\)\) 0x[0-9a-f]+ <S3::m\(int\)>} \
         "test value of F in k3_m"