• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

GNU Binutils with patches for OS216


コミットメタ情報

リビジョンe61b4af73de761ca2b877b09c1ad710f44ba0f54 (tree)
日時2018-02-05 12:21:08
作者Simon Marchi <simon.marchi@poly...>
コミッターSimon Marchi

ログメッセージ

Don't trust templates from DW_AT_name

With gcc 8 (and clang?) the non-type template arguments (constants)
don't include the integer suffixes anymore. For example, with

template <unsigned int X>
class foo
{
...
};
foo<10u>

used to generate foo<10u> as the DW_AT_name, now it generates foo<10>.
This is a problem when things look up "foo<10u>" and don't find it. For
example, when trying to print an instance of that class through a base
class pointer, GDB would first demangle the symbol for that class'
vtable, which would give "vtable for foo<10u>". GDB would then take the
"foo<10u>" from that string and try to look up the type. With the new
DW_AT_name, it would fail to look it up, and fail to print the value.

This patch makes it so GDB doesn't trust the templates contained in
DW_AT_name. Instead, it re-builds the name from the DW_AT_template_*
DIES in the format that it expects (with the integer suffixes).

変更サマリ

差分

--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -454,6 +454,21 @@ c_val_print_int (struct type *type, struct type *unresolved_type,
454454 : options->output_format);
455455 val_print_scalar_formatted (type, embedded_offset,
456456 original_value, &opts, 0, stream);
457+
458+ if (opts.print_suffix)
459+ {
460+ struct type *t = check_typedef (type);
461+
462+ if (TYPE_UNSIGNED (t))
463+ fputc_filtered ('u', stream);
464+
465+ /* Is there a better way to do this? Just looking at the size doesn't
466+ work. */
467+ if (strstr (TYPE_NAME (t), "long long") != NULL)
468+ fputs_filtered ("ll", stream);
469+ else if (strstr (TYPE_NAME (t), "long") != NULL)
470+ fputc_filtered ('l', stream);
471+ }
457472 }
458473 else
459474 {
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -9211,7 +9211,7 @@ partial_die_full_name (struct partial_die_info *pdi,
92119211 {
92129212 fixup_partial_die (pdi, cu);
92139213
9214- if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
9214+ if (pdi->name != NULL)
92159215 {
92169216 struct die_info *die;
92179217 struct attribute attr;
@@ -10875,6 +10875,22 @@ dwarf2_compute_name (const char *name,
1087510875 if (name == NULL)
1087610876 name = dwarf2_name (die, cu);
1087710877
10878+ /* If there is a template in the name, strip it and let the code below
10879+ re-compute it. */
10880+ gdb::unique_xmalloc_ptr<char> holder;
10881+ if (name != NULL)
10882+ {
10883+ const char *opening = strchr (name, '<');
10884+ if (opening != NULL)
10885+ {
10886+ /* In this case, name will get copied/modified and re-assigned,
10887+ so we can free this copy. */
10888+ holder.reset (xstrdup (name));
10889+ holder.get ()[opening - name] = '\0';
10890+ name = holder.get ();
10891+ }
10892+ }
10893+
1087810894 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
1087910895 but otherwise compute it by typename_concat inside GDB.
1088010896 FIXME: Actually this is not really true, or at least not always true.
@@ -10942,7 +10958,7 @@ dwarf2_compute_name (const char *name,
1094210958 templates; two instantiated function templates are allowed to
1094310959 differ only by their return types, which we do not add here. */
1094410960
10945- if (cu->language == language_cplus && strchr (name, '<') == NULL)
10961+ if (cu->language == language_cplus)
1094610962 {
1094710963 struct attribute *attr;
1094810964 struct die_info *child;
@@ -11026,6 +11042,7 @@ dwarf2_compute_name (const char *name,
1102611042 the radix. */
1102711043 get_formatted_print_options (&opts, 'd');
1102811044 opts.raw = 1;
11045+ opts.print_suffix = true;
1102911046 value_print (v, &buf, &opts);
1103011047 release_value (v);
1103111048 value_free (v);
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -109,7 +109,8 @@ struct value_print_options user_print_options =
109109 1, /* pascal_static_field_print */
110110 0, /* raw */
111111 0, /* summary */
112- 1 /* symbol_print */
112+ 1, /* symbol_print */
113+ false, /* print_suffix */
113114 };
114115
115116 /* Initialize *OPTS to be a copy of the user print options. */
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -92,6 +92,10 @@ struct value_print_options
9292 /* If nonzero, when printing a pointer, print the symbol to which it
9393 points, if any. */
9494 int symbol_print;
95+
96+ /* If true, print the integer suffixes (u for unsigned, l for long, ll for
97+ long long). */
98+ bool print_suffix;
9599 };
96100
97101 /* The global print options set by the user. In general this should