Fix Ada crash with .debug_names
authorTom Tromey <tromey@adacore.com>
Thu, 23 Apr 2020 13:19:43 +0000 (07:19 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 23 Apr 2020 13:19:43 +0000 (07:19 -0600)
PR ada/25837 points out a crash in the gdb testsuite when .debug_names
is used.  You can reproduce like:

    runtest --target_board=cc-with-debug-names \
        gdb.ada/big_packed_array.exp

The bug was introduced by commit e0802d599 ("Avoid copying in
lookup_name_info").  The problem is that the return type of
language_lookup_name changed, but in a way that didn't cause existing
callers to trigger a compilation error.  Previously, it returned a
"const string &", but after it returned a "const char *".  This caused
a string to be created in dw2_expand_symtabs_matching_symbol, but one
that had too short of a lifetime; so eventually the matcher cache
would wind up with invalid data.

This patch fixes the problem by updating the callers to use the new
type.

Tested on x86-64 Fedora 30.

gdb/ChangeLog
2020-04-23  Tom Tromey  <tromey@adacore.com>

PR ada/25837:
* dwarf2/read.c (dw2_expand_symtabs_matching_symbol): Store a
"const char *", not a "const std::string &".
<name_and_matcher::operator==>: Update.
* unittests/lookup_name_info-selftests.c: Change type of
"result".

gdb/ChangeLog
gdb/dwarf2/read.c
gdb/unittests/lookup_name_info-selftests.c

index f5b4095083bcdc10de000434679bb9997dd42c5d..cbe2693719835e59005de28d44f5b0031d6ea587 100644 (file)
@@ -1,3 +1,12 @@
+2020-04-23  Tom Tromey  <tromey@adacore.com>
+
+       PR ada/25837:
+       * dwarf2/read.c (dw2_expand_symtabs_matching_symbol): Store a
+       "const char *", not a "const std::string &".
+       <name_and_matcher::operator==>: Update.
+       * unittests/lookup_name_info-selftests.c: Change type of
+       "result".
+
 2020-04-23  Tom Tromey  <tom@tromey.com>
 
        * inferior.h (iterate_over_inferiors): Don't declare.
index c2a9103510f0ff7c7e108e12922a1b3fd9ec74ba..e89ed743543eb47b7b7a641160ff0fc7fa9dc7ae 100644 (file)
@@ -3911,11 +3911,11 @@ dw2_expand_symtabs_matching_symbol
   struct name_and_matcher
   {
     symbol_name_matcher_ftype *matcher;
-    const std::string &name;
+    const char *name;
 
     bool operator== (const name_and_matcher &other) const
     {
-      return matcher == other.matcher && name == other.name;
+      return matcher == other.matcher && strcmp (name, other.name) == 0;
     }
   };
 
index 002fc697955011d6274de5c41bc8e0b00b92f46f..6a617521cb4418b783c397d399aa51ac5f028a64 100644 (file)
@@ -37,14 +37,14 @@ check_make_paramless (const char *file, int line,
 {
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL,
                                completion_mode, true /* ignore_parameters */);
-  const std::string &result = lookup_name.language_lookup_name (lang);
+  const char *result = lookup_name.language_lookup_name (lang);
 
-  if (result != expected)
+  if (strcmp (result, expected) != 0)
     {
       error (_("%s:%d: make-paramless self-test failed: (completion=%d, lang=%d) "
               "\"%s\" -> \"%s\", expected \"%s\""),
             file, line, completion_mode, lang, name,
-            result.c_str (), expected);
+            result, expected);
     }
 }