• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionf945dedfd3512bfbca0f1405c8ea85684980e69a (tree)
Time2019-09-24 03:36:34
AuthorChristian Biesinger <cbiesinger@goog...>
CommiterChristian Biesinger

Log Message

Make ada_decode not use a static buffer

This makes it safer to use in general, and also allows using it on a
background thread in the future.

Inspired by tromey's patch at:
https://github.com/tromey/gdb/commit/1226cbdfa436297a5dec054d94592c45891afa93
(however, implemented in a different way)

gdb/ChangeLog:

2019-09-23 Christian Biesinger <cbiesinger@google.com>

* ada-exp.y (write_object_remaining): Update.
* ada-lang.c (ada_decode): Return a std::string instead of a char*
and eliminate the static buffer.
(ada_decode_symbol): Update.
(ada_la_decode): Update.
(ada_sniff_from_mangled_name): Update.
(is_valid_name_for_wild_match): Update.
(ada_lookup_name_info::matches): Update and simplify.
(name_matches_regex): Update.
(ada_add_global_exceptions): Update.
* ada-lang.h (ada_decode): Update signature.
* ada-varobj.c (ada_varobj_describe_simple_array_child): Update.
* dwarf-index-write.c (debug_names::insert): Update.

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
1+2019-09-23 Christian Biesinger <cbiesinger@google.com>
2+
3+ * ada-exp.y (write_object_remaining): Update.
4+ * ada-lang.c (ada_decode): Return a std::string instead of a char*
5+ and eliminate the static buffer.
6+ (ada_decode_symbol): Update.
7+ (ada_la_decode): Update.
8+ (ada_sniff_from_mangled_name): Update.
9+ (is_valid_name_for_wild_match): Update.
10+ (ada_lookup_name_info::matches): Update and simplify.
11+ (name_matches_regex): Update.
12+ (ada_add_global_exceptions): Update.
13+ * ada-lang.h (ada_decode): Update signature.
14+ * ada-varobj.c (ada_varobj_describe_simple_array_child): Update.
15+ * dwarf-index-write.c (debug_names::insert): Update.
16+
117 2019-09-21 Simon Marchi <simon.marchi@polymtl.ca>
218
319 * solib-svr4.c (svr4_iterate_over_objfiles_in_search_order): Fix
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -816,7 +816,7 @@ write_object_renaming (struct parser_state *par_state,
816816 renamed_entity_len);
817817 ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
818818 if (sym_info.symbol == NULL)
819- error (_("Could not find renamed variable: %s"), ada_decode (name));
819+ error (_("Could not find renamed variable: %s"), ada_decode (name).c_str ());
820820 else if (SYMBOL_CLASS (sym_info.symbol) == LOC_TYPEDEF)
821821 /* We have a renaming of an old-style renaming symbol. Don't
822822 trust the block information. */
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1105,22 +1105,16 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len)
11051105
11061106 /* If ENCODED follows the GNAT entity encoding conventions, then return
11071107 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
1108- replaced by ENCODED.
1108+ replaced by ENCODED. */
11091109
1110- The resulting string is valid until the next call of ada_decode.
1111- If the string is unchanged by decoding, the original string pointer
1112- is returned. */
1113-
1114-const char *
1110+std::string
11151111 ada_decode (const char *encoded)
11161112 {
11171113 int i, j;
11181114 int len0;
11191115 const char *p;
1120- char *decoded;
11211116 int at_start_name;
1122- static char *decoding_buffer = NULL;
1123- static size_t decoding_buffer_size = 0;
1117+ std::string decoded;
11241118
11251119 /* With function descriptors on PPC64, the value of a symbol named
11261120 ".FN", if it exists, is the entry point of the function "FN". */
@@ -1179,8 +1173,7 @@ ada_decode (const char *encoded)
11791173
11801174 /* Make decoded big enough for possible expansion by operator name. */
11811175
1182- GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
1183- decoded = decoding_buffer;
1176+ decoded.resize (2 * len0 + 1, 'X');
11841177
11851178 /* Remove trailing __{digit}+ or trailing ${digit}+. */
11861179
@@ -1217,7 +1210,7 @@ ada_decode (const char *encoded)
12171210 op_len - 1) == 0)
12181211 && !isalnum (encoded[i + op_len]))
12191212 {
1220- strcpy (decoded + j, ada_opname_table[k].decoded);
1213+ strcpy (&decoded.front() + j, ada_opname_table[k].decoded);
12211214 at_start_name = 0;
12221215 i += op_len;
12231216 j += strlen (ada_opname_table[k].decoded);
@@ -1338,27 +1331,22 @@ ada_decode (const char *encoded)
13381331 j += 1;
13391332 }
13401333 }
1341- decoded[j] = '\000';
1334+ decoded.resize (j);
13421335
13431336 /* Decoded names should never contain any uppercase character.
13441337 Double-check this, and abort the decoding if we find one. */
13451338
1346- for (i = 0; decoded[i] != '\0'; i += 1)
1339+ for (i = 0; i < decoded.length(); ++i)
13471340 if (isupper (decoded[i]) || decoded[i] == ' ')
13481341 goto Suppress;
13491342
1350- if (strcmp (decoded, encoded) == 0)
1351- return encoded;
1352- else
1353- return decoded;
1343+ return decoded;
13541344
13551345 Suppress:
1356- GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
1357- decoded = decoding_buffer;
13581346 if (encoded[0] == '<')
1359- strcpy (decoded, encoded);
1347+ decoded = encoded;
13601348 else
1361- xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
1349+ decoded = '<' + std::string(encoded) + '>';
13621350 return decoded;
13631351
13641352 }
@@ -1389,13 +1377,13 @@ ada_decode_symbol (const struct general_symbol_info *arg)
13891377
13901378 if (!gsymbol->ada_mangled)
13911379 {
1392- const char *decoded = ada_decode (gsymbol->name);
1380+ std::string decoded = ada_decode (gsymbol->name);
13931381 struct obstack *obstack = gsymbol->language_specific.obstack;
13941382
13951383 gsymbol->ada_mangled = 1;
13961384
13971385 if (obstack != NULL)
1398- *resultp = obstack_strdup (obstack, decoded);
1386+ *resultp = obstack_strdup (obstack, decoded.c_str ());
13991387 else
14001388 {
14011389 /* Sometimes, we can't find a corresponding objfile, in
@@ -1404,10 +1392,10 @@ ada_decode_symbol (const struct general_symbol_info *arg)
14041392 significant memory leak (FIXME). */
14051393
14061394 char **slot = (char **) htab_find_slot (decoded_names_store,
1407- decoded, INSERT);
1395+ decoded.c_str (), INSERT);
14081396
14091397 if (*slot == NULL)
1410- *slot = xstrdup (decoded);
1398+ *slot = xstrdup (decoded.c_str ());
14111399 *resultp = *slot;
14121400 }
14131401 }
@@ -1418,7 +1406,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
14181406 static char *
14191407 ada_la_decode (const char *encoded, int options)
14201408 {
1421- return xstrdup (ada_decode (encoded));
1409+ return xstrdup (ada_decode (encoded).c_str ());
14221410 }
14231411
14241412 /* Implement la_sniff_from_mangled_name for Ada. */
@@ -1426,11 +1414,11 @@ ada_la_decode (const char *encoded, int options)
14261414 static int
14271415 ada_sniff_from_mangled_name (const char *mangled, char **out)
14281416 {
1429- const char *demangled = ada_decode (mangled);
1417+ std::string demangled = ada_decode (mangled);
14301418
14311419 *out = NULL;
14321420
1433- if (demangled != mangled && demangled != NULL && demangled[0] != '<')
1421+ if (demangled != mangled && demangled[0] != '<')
14341422 {
14351423 /* Set the gsymbol language to Ada, but still return 0.
14361424 Two reasons for that:
@@ -5993,7 +5981,7 @@ is_name_suffix (const char *str)
59935981 static int
59945982 is_valid_name_for_wild_match (const char *name0)
59955983 {
5996- const char *decoded_name = ada_decode (name0);
5984+ std::string decoded_name = ada_decode (name0);
59975985 int i;
59985986
59995987 /* If the decoded name starts with an angle bracket, it means that
@@ -6233,19 +6221,16 @@ ada_lookup_name_info::matches
62336221 if (strncmp (sym_name, text, text_len) == 0)
62346222 match = true;
62356223
6224+ std::string decoded_name = ada_decode (sym_name);
62366225 if (match && !m_encoded_p)
62376226 {
62386227 /* One needed check before declaring a positive match is to verify
62396228 that iff we are doing a verbatim match, the decoded version
62406229 of the symbol name starts with '<'. Otherwise, this symbol name
62416230 is not a suitable completion. */
6242- const char *sym_name_copy = sym_name;
6243- bool has_angle_bracket;
62446231
6245- sym_name = ada_decode (sym_name);
6246- has_angle_bracket = (sym_name[0] == '<');
6232+ bool has_angle_bracket = (decoded_name[0] == '<');
62476233 match = (has_angle_bracket == m_verbatim_p);
6248- sym_name = sym_name_copy;
62496234 }
62506235
62516236 if (match && !m_verbatim_p)
@@ -6269,7 +6254,7 @@ ada_lookup_name_info::matches
62696254 /* Since we are doing wild matching, this means that TEXT
62706255 may represent an unqualified symbol name. We therefore must
62716256 also compare TEXT against the unqualified name of the symbol. */
6272- sym_name = ada_unqualified_name (ada_decode (sym_name));
6257+ sym_name = ada_unqualified_name (decoded_name.c_str ());
62736258
62746259 if (strncmp (sym_name, text, text_len) == 0)
62756260 match = true;
@@ -13494,7 +13479,7 @@ static bool
1349413479 name_matches_regex (const char *name, compiled_regex *preg)
1349513480 {
1349613481 return (preg == NULL
13497- || preg->exec (ada_decode (name), 0, NULL, 0) == 0);
13482+ || preg->exec (ada_decode (name).c_str (), 0, NULL, 0) == 0);
1349813483 }
1349913484
1350013485 /* Add all exceptions defined globally whose name name match
@@ -13527,8 +13512,8 @@ ada_add_global_exceptions (compiled_regex *preg,
1352713512 lookup_name_info::match_any (),
1352813513 [&] (const char *search_name)
1352913514 {
13530- const char *decoded = ada_decode (search_name);
13531- return name_matches_regex (decoded, preg);
13515+ std::string decoded = ada_decode (search_name);
13516+ return name_matches_regex (decoded.c_str (), preg);
1353213517 },
1353313518 NULL,
1353413519 VARIABLES_DOMAIN);
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -227,7 +227,7 @@ extern struct type *ada_get_decoded_type (struct type *type);
227227
228228 extern const char *ada_decode_symbol (const struct general_symbol_info *);
229229
230-extern const char *ada_decode (const char*);
230+extern std::string ada_decode (const char*);
231231
232232 extern enum language ada_update_initial_language (enum language);
233233
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -624,6 +624,7 @@ ada_varobj_describe_simple_array_child (struct value *parent_value,
624624 of the array index type when such type qualification is
625625 needed. */
626626 const char *index_type_name = NULL;
627+ std::string decoded;
627628
628629 /* If the index type is a range type, find the base type. */
629630 while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
@@ -634,7 +635,10 @@ ada_varobj_describe_simple_array_child (struct value *parent_value,
634635 {
635636 index_type_name = ada_type_name (index_type);
636637 if (index_type_name)
637- index_type_name = ada_decode (index_type_name);
638+ {
639+ decoded = ada_decode (index_type_name);
640+ index_type_name = decoded.c_str ();
641+ }
638642 }
639643
640644 if (index_type_name != NULL)
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -714,13 +714,14 @@ public:
714714 name (of the form "<MumBle>") must be entered without the
715715 angle brackets. Note that the current index is unusual,
716716 see PR symtab/24820 for details. */
717- const char *decoded = ada_decode (name);
717+ std::string decoded = ada_decode (name);
718718 if (decoded[0] == '<')
719719 name = (char *) obstack_copy0 (&m_string_obstack,
720- decoded + 1,
721- strlen (decoded + 1) - 1);
720+ decoded.c_str () + 1,
721+ decoded.length () - 2);
722722 else
723- name = obstack_strdup (&m_string_obstack, ada_encode (decoded));
723+ name = obstack_strdup (&m_string_obstack,
724+ ada_encode (decoded.c_str ()));
724725 }
725726
726727 const auto insertpair