GNU Binutils with patches for OS216
Revision | f945dedfd3512bfbca0f1405c8ea85684980e69a (tree) |
---|---|
Time | 2019-09-24 03:36:34 |
Author | Christian Biesinger <cbiesinger@goog...> |
Commiter | Christian Biesinger |
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.
@@ -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 | + | |
1 | 17 | 2019-09-21 Simon Marchi <simon.marchi@polymtl.ca> |
2 | 18 | |
3 | 19 | * solib-svr4.c (svr4_iterate_over_objfiles_in_search_order): Fix |
@@ -816,7 +816,7 @@ write_object_renaming (struct parser_state *par_state, | ||
816 | 816 | renamed_entity_len); |
817 | 817 | ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info); |
818 | 818 | 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 ()); | |
820 | 820 | else if (SYMBOL_CLASS (sym_info.symbol) == LOC_TYPEDEF) |
821 | 821 | /* We have a renaming of an old-style renaming symbol. Don't |
822 | 822 | trust the block information. */ |
@@ -1105,22 +1105,16 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len) | ||
1105 | 1105 | |
1106 | 1106 | /* If ENCODED follows the GNAT entity encoding conventions, then return |
1107 | 1107 | the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is |
1108 | - replaced by ENCODED. | |
1108 | + replaced by ENCODED. */ | |
1109 | 1109 | |
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 | |
1115 | 1111 | ada_decode (const char *encoded) |
1116 | 1112 | { |
1117 | 1113 | int i, j; |
1118 | 1114 | int len0; |
1119 | 1115 | const char *p; |
1120 | - char *decoded; | |
1121 | 1116 | int at_start_name; |
1122 | - static char *decoding_buffer = NULL; | |
1123 | - static size_t decoding_buffer_size = 0; | |
1117 | + std::string decoded; | |
1124 | 1118 | |
1125 | 1119 | /* With function descriptors on PPC64, the value of a symbol named |
1126 | 1120 | ".FN", if it exists, is the entry point of the function "FN". */ |
@@ -1179,8 +1173,7 @@ ada_decode (const char *encoded) | ||
1179 | 1173 | |
1180 | 1174 | /* Make decoded big enough for possible expansion by operator name. */ |
1181 | 1175 | |
1182 | - GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1); | |
1183 | - decoded = decoding_buffer; | |
1176 | + decoded.resize (2 * len0 + 1, 'X'); | |
1184 | 1177 | |
1185 | 1178 | /* Remove trailing __{digit}+ or trailing ${digit}+. */ |
1186 | 1179 |
@@ -1217,7 +1210,7 @@ ada_decode (const char *encoded) | ||
1217 | 1210 | op_len - 1) == 0) |
1218 | 1211 | && !isalnum (encoded[i + op_len])) |
1219 | 1212 | { |
1220 | - strcpy (decoded + j, ada_opname_table[k].decoded); | |
1213 | + strcpy (&decoded.front() + j, ada_opname_table[k].decoded); | |
1221 | 1214 | at_start_name = 0; |
1222 | 1215 | i += op_len; |
1223 | 1216 | j += strlen (ada_opname_table[k].decoded); |
@@ -1338,27 +1331,22 @@ ada_decode (const char *encoded) | ||
1338 | 1331 | j += 1; |
1339 | 1332 | } |
1340 | 1333 | } |
1341 | - decoded[j] = '\000'; | |
1334 | + decoded.resize (j); | |
1342 | 1335 | |
1343 | 1336 | /* Decoded names should never contain any uppercase character. |
1344 | 1337 | Double-check this, and abort the decoding if we find one. */ |
1345 | 1338 | |
1346 | - for (i = 0; decoded[i] != '\0'; i += 1) | |
1339 | + for (i = 0; i < decoded.length(); ++i) | |
1347 | 1340 | if (isupper (decoded[i]) || decoded[i] == ' ') |
1348 | 1341 | goto Suppress; |
1349 | 1342 | |
1350 | - if (strcmp (decoded, encoded) == 0) | |
1351 | - return encoded; | |
1352 | - else | |
1353 | - return decoded; | |
1343 | + return decoded; | |
1354 | 1344 | |
1355 | 1345 | Suppress: |
1356 | - GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3); | |
1357 | - decoded = decoding_buffer; | |
1358 | 1346 | if (encoded[0] == '<') |
1359 | - strcpy (decoded, encoded); | |
1347 | + decoded = encoded; | |
1360 | 1348 | else |
1361 | - xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded); | |
1349 | + decoded = '<' + std::string(encoded) + '>'; | |
1362 | 1350 | return decoded; |
1363 | 1351 | |
1364 | 1352 | } |
@@ -1389,13 +1377,13 @@ ada_decode_symbol (const struct general_symbol_info *arg) | ||
1389 | 1377 | |
1390 | 1378 | if (!gsymbol->ada_mangled) |
1391 | 1379 | { |
1392 | - const char *decoded = ada_decode (gsymbol->name); | |
1380 | + std::string decoded = ada_decode (gsymbol->name); | |
1393 | 1381 | struct obstack *obstack = gsymbol->language_specific.obstack; |
1394 | 1382 | |
1395 | 1383 | gsymbol->ada_mangled = 1; |
1396 | 1384 | |
1397 | 1385 | if (obstack != NULL) |
1398 | - *resultp = obstack_strdup (obstack, decoded); | |
1386 | + *resultp = obstack_strdup (obstack, decoded.c_str ()); | |
1399 | 1387 | else |
1400 | 1388 | { |
1401 | 1389 | /* Sometimes, we can't find a corresponding objfile, in |
@@ -1404,10 +1392,10 @@ ada_decode_symbol (const struct general_symbol_info *arg) | ||
1404 | 1392 | significant memory leak (FIXME). */ |
1405 | 1393 | |
1406 | 1394 | char **slot = (char **) htab_find_slot (decoded_names_store, |
1407 | - decoded, INSERT); | |
1395 | + decoded.c_str (), INSERT); | |
1408 | 1396 | |
1409 | 1397 | if (*slot == NULL) |
1410 | - *slot = xstrdup (decoded); | |
1398 | + *slot = xstrdup (decoded.c_str ()); | |
1411 | 1399 | *resultp = *slot; |
1412 | 1400 | } |
1413 | 1401 | } |
@@ -1418,7 +1406,7 @@ ada_decode_symbol (const struct general_symbol_info *arg) | ||
1418 | 1406 | static char * |
1419 | 1407 | ada_la_decode (const char *encoded, int options) |
1420 | 1408 | { |
1421 | - return xstrdup (ada_decode (encoded)); | |
1409 | + return xstrdup (ada_decode (encoded).c_str ()); | |
1422 | 1410 | } |
1423 | 1411 | |
1424 | 1412 | /* Implement la_sniff_from_mangled_name for Ada. */ |
@@ -1426,11 +1414,11 @@ ada_la_decode (const char *encoded, int options) | ||
1426 | 1414 | static int |
1427 | 1415 | ada_sniff_from_mangled_name (const char *mangled, char **out) |
1428 | 1416 | { |
1429 | - const char *demangled = ada_decode (mangled); | |
1417 | + std::string demangled = ada_decode (mangled); | |
1430 | 1418 | |
1431 | 1419 | *out = NULL; |
1432 | 1420 | |
1433 | - if (demangled != mangled && demangled != NULL && demangled[0] != '<') | |
1421 | + if (demangled != mangled && demangled[0] != '<') | |
1434 | 1422 | { |
1435 | 1423 | /* Set the gsymbol language to Ada, but still return 0. |
1436 | 1424 | Two reasons for that: |
@@ -5993,7 +5981,7 @@ is_name_suffix (const char *str) | ||
5993 | 5981 | static int |
5994 | 5982 | is_valid_name_for_wild_match (const char *name0) |
5995 | 5983 | { |
5996 | - const char *decoded_name = ada_decode (name0); | |
5984 | + std::string decoded_name = ada_decode (name0); | |
5997 | 5985 | int i; |
5998 | 5986 | |
5999 | 5987 | /* If the decoded name starts with an angle bracket, it means that |
@@ -6233,19 +6221,16 @@ ada_lookup_name_info::matches | ||
6233 | 6221 | if (strncmp (sym_name, text, text_len) == 0) |
6234 | 6222 | match = true; |
6235 | 6223 | |
6224 | + std::string decoded_name = ada_decode (sym_name); | |
6236 | 6225 | if (match && !m_encoded_p) |
6237 | 6226 | { |
6238 | 6227 | /* One needed check before declaring a positive match is to verify |
6239 | 6228 | that iff we are doing a verbatim match, the decoded version |
6240 | 6229 | of the symbol name starts with '<'. Otherwise, this symbol name |
6241 | 6230 | is not a suitable completion. */ |
6242 | - const char *sym_name_copy = sym_name; | |
6243 | - bool has_angle_bracket; | |
6244 | 6231 | |
6245 | - sym_name = ada_decode (sym_name); | |
6246 | - has_angle_bracket = (sym_name[0] == '<'); | |
6232 | + bool has_angle_bracket = (decoded_name[0] == '<'); | |
6247 | 6233 | match = (has_angle_bracket == m_verbatim_p); |
6248 | - sym_name = sym_name_copy; | |
6249 | 6234 | } |
6250 | 6235 | |
6251 | 6236 | if (match && !m_verbatim_p) |
@@ -6269,7 +6254,7 @@ ada_lookup_name_info::matches | ||
6269 | 6254 | /* Since we are doing wild matching, this means that TEXT |
6270 | 6255 | may represent an unqualified symbol name. We therefore must |
6271 | 6256 | 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 ()); | |
6273 | 6258 | |
6274 | 6259 | if (strncmp (sym_name, text, text_len) == 0) |
6275 | 6260 | match = true; |
@@ -13494,7 +13479,7 @@ static bool | ||
13494 | 13479 | name_matches_regex (const char *name, compiled_regex *preg) |
13495 | 13480 | { |
13496 | 13481 | 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); | |
13498 | 13483 | } |
13499 | 13484 | |
13500 | 13485 | /* Add all exceptions defined globally whose name name match |
@@ -13527,8 +13512,8 @@ ada_add_global_exceptions (compiled_regex *preg, | ||
13527 | 13512 | lookup_name_info::match_any (), |
13528 | 13513 | [&] (const char *search_name) |
13529 | 13514 | { |
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); | |
13532 | 13517 | }, |
13533 | 13518 | NULL, |
13534 | 13519 | VARIABLES_DOMAIN); |
@@ -227,7 +227,7 @@ extern struct type *ada_get_decoded_type (struct type *type); | ||
227 | 227 | |
228 | 228 | extern const char *ada_decode_symbol (const struct general_symbol_info *); |
229 | 229 | |
230 | -extern const char *ada_decode (const char*); | |
230 | +extern std::string ada_decode (const char*); | |
231 | 231 | |
232 | 232 | extern enum language ada_update_initial_language (enum language); |
233 | 233 |
@@ -624,6 +624,7 @@ ada_varobj_describe_simple_array_child (struct value *parent_value, | ||
624 | 624 | of the array index type when such type qualification is |
625 | 625 | needed. */ |
626 | 626 | const char *index_type_name = NULL; |
627 | + std::string decoded; | |
627 | 628 | |
628 | 629 | /* If the index type is a range type, find the base type. */ |
629 | 630 | while (TYPE_CODE (index_type) == TYPE_CODE_RANGE) |
@@ -634,7 +635,10 @@ ada_varobj_describe_simple_array_child (struct value *parent_value, | ||
634 | 635 | { |
635 | 636 | index_type_name = ada_type_name (index_type); |
636 | 637 | 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 | + } | |
638 | 642 | } |
639 | 643 | |
640 | 644 | if (index_type_name != NULL) |
@@ -714,13 +714,14 @@ public: | ||
714 | 714 | name (of the form "<MumBle>") must be entered without the |
715 | 715 | angle brackets. Note that the current index is unusual, |
716 | 716 | see PR symtab/24820 for details. */ |
717 | - const char *decoded = ada_decode (name); | |
717 | + std::string decoded = ada_decode (name); | |
718 | 718 | if (decoded[0] == '<') |
719 | 719 | name = (char *) obstack_copy0 (&m_string_obstack, |
720 | - decoded + 1, | |
721 | - strlen (decoded + 1) - 1); | |
720 | + decoded.c_str () + 1, | |
721 | + decoded.length () - 2); | |
722 | 722 | else |
723 | - name = obstack_strdup (&m_string_obstack, ada_encode (decoded)); | |
723 | + name = obstack_strdup (&m_string_obstack, | |
724 | + ada_encode (decoded.c_str ())); | |
724 | 725 | } |
725 | 726 | |
726 | 727 | const auto insertpair |