GNU Binutils with patches for OS216
Révision | 3e1d3d8c2494c021718ba957e83395958ee08a0f (tree) |
---|---|
l'heure | 2018-08-03 07:12:42 |
Auteur | Tom Tromey <tom@trom...> |
Commiter | Tom Tromey |
Allow "info address" of a template parameter
PR symtab/16842 shows that gdb will crash when the user tries to
invoke "info address" of a template parameter.
The bug here is that dwarf2read.c does not set the symtab on the
template parameter symbols. This is pedantically correct, given that
the template symbols do not appear in a symtab. However, gdb
primarily uses the symtab backlink to find the symbol's objfile. So,
this patch simply sets the symtab on these symbols.
Tested by the buildbot.
gdb/ChangeLog
2018-08-02 Tom Tromey <tom@tromey.com>
PR symtab/16842.
* dwarf2read.c (read_func_scope): Set symtab on template parameter
symbols.
(process_structure_scope): Likewise.
gdb/testsuite/ChangeLog
2018-08-02 Tom Tromey <tom@tromey.com>
PR symtab/16842.
* gdb.cp/temargs.exp: Test "info address" of a template
parameter.
@@ -1,3 +1,10 @@ | ||
1 | +2018-08-02 Tom Tromey <tom@tromey.com> | |
2 | + | |
3 | + PR symtab/16842. | |
4 | + * dwarf2read.c (read_func_scope): Set symtab on template parameter | |
5 | + symbols. | |
6 | + (process_structure_scope): Likewise. | |
7 | + | |
1 | 8 | 2018-08-02 Xavier Roirand <roirand@adacore.com> |
2 | 9 | |
3 | 10 | PR gdb/22629: |
@@ -13753,6 +13753,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) | ||
13753 | 13753 | memcpy (templ_func->template_arguments, |
13754 | 13754 | template_args.data (), |
13755 | 13755 | (templ_func->n_template_arguments * sizeof (struct symbol *))); |
13756 | + | |
13757 | + /* Make sure that the symtab is set on the new symbols. Even | |
13758 | + though they don't appear in this symtab directly, other parts | |
13759 | + of gdb assume that symbols do, and this is reasonably | |
13760 | + true. */ | |
13761 | + for (struct symbol *sym : template_args) | |
13762 | + symbol_set_symtab (sym, symbol_symtab (templ_func)); | |
13756 | 13763 | } |
13757 | 13764 | |
13758 | 13765 | /* In C++, we can have functions nested inside functions (e.g., when |
@@ -15873,6 +15880,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | ||
15873 | 15880 | discriminant_info. */ |
15874 | 15881 | bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type); |
15875 | 15882 | sect_offset discr_offset; |
15883 | + bool has_template_parameters = false; | |
15876 | 15884 | |
15877 | 15885 | if (is_variant_part) |
15878 | 15886 | { |
@@ -15920,6 +15928,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | ||
15920 | 15928 | /* Attach template arguments to type. */ |
15921 | 15929 | if (!template_args.empty ()) |
15922 | 15930 | { |
15931 | + has_template_parameters = true; | |
15923 | 15932 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
15924 | 15933 | TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size (); |
15925 | 15934 | TYPE_TEMPLATE_ARGUMENTS (type) |
@@ -16069,7 +16078,20 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | ||
16069 | 16078 | attribute, and a declaration attribute. */ |
16070 | 16079 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL |
16071 | 16080 | || !die_is_declaration (die, cu)) |
16072 | - new_symbol (die, type, cu); | |
16081 | + { | |
16082 | + struct symbol *sym = new_symbol (die, type, cu); | |
16083 | + | |
16084 | + if (has_template_parameters) | |
16085 | + { | |
16086 | + /* Make sure that the symtab is set on the new symbols. | |
16087 | + Even though they don't appear in this symtab directly, | |
16088 | + other parts of gdb assume that symbols do, and this is | |
16089 | + reasonably true. */ | |
16090 | + for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i) | |
16091 | + symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i), | |
16092 | + symbol_symtab (sym)); | |
16093 | + } | |
16094 | + } | |
16073 | 16095 | } |
16074 | 16096 | |
16075 | 16097 | /* Assuming DIE is an enumeration type, and TYPE is its associated type, |
@@ -1,3 +1,9 @@ | ||
1 | +2018-08-02 Tom Tromey <tom@tromey.com> | |
2 | + | |
3 | + PR symtab/16842. | |
4 | + * gdb.cp/temargs.exp: Test "info address" of a template | |
5 | + parameter. | |
6 | + | |
1 | 7 | 2018-07-31 Jan Vrany <jan.vrany@fit.cvut.cz> |
2 | 8 | |
3 | 9 | * gdb.python/py-mi-var-info-path-expression.c: New file. |
@@ -133,6 +133,10 @@ gdb_test "ptype T" "unsigned char" "test type of T in func" | ||
133 | 133 | if $have_older_template_gcc { setup_xfail "*-*-*" } |
134 | 134 | gdb_test "print I" " = 91" "test value of I in func" |
135 | 135 | |
136 | +# PR symtab/16842 - gdb used to crash here. | |
137 | +if $have_older_template_gcc { setup_xfail "*-*-*" } | |
138 | +gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m" | |
139 | + | |
136 | 140 | if $have_older_template_gcc { setup_xfail "*-*-*" } |
137 | 141 | gdb_test "print P == &a_global" " = true" "test value of P in func" |
138 | 142 |
@@ -151,6 +155,10 @@ gdb_test "ptype T" "double" "test type of T in templ_m" | ||
151 | 155 | if $have_older_template_gcc { setup_xfail "*-*-*" } |
152 | 156 | gdb_test "print I" " = 23" "test value of I in templ_m" |
153 | 157 | |
158 | +# PR symtab/16842 - gdb used to crash here. | |
159 | +if $have_older_template_gcc { setup_xfail "*-*-*" } | |
160 | +gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m" | |
161 | + | |
154 | 162 | if $have_older_template_gcc { setup_xfail "*-*-*" } |
155 | 163 | gdb_test "print P == &a_global" " = true" "test value of P in templ_m" |
156 | 164 |