aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-07-19 11:24:49 -0600
committerTom Tromey <tom@tromey.com>2018-08-02 16:12:42 -0600
commit3e1d3d8c2494c021718ba957e83395958ee08a0f (patch)
treeb0836b010bf5cb9f9d70729a404725cd44ec36dc
parent1584354913285389063622a39f845851f332eb9a (diff)
downloadgdb-3e1d3d8c2494c021718ba957e83395958ee08a0f.zip
gdb-3e1d3d8c2494c021718ba957e83395958ee08a0f.tar.gz
gdb-3e1d3d8c2494c021718ba957e83395958ee08a0f.tar.bz2
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.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/dwarf2read.c24
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.cp/temargs.exp8
4 files changed, 44 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 661ad16..227e3ff 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
2018-08-02 Xavier Roirand <roirand@adacore.com>
PR gdb/22629:
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2c82d81..a758212 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13753,6 +13753,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
memcpy (templ_func->template_arguments,
template_args.data (),
(templ_func->n_template_arguments * sizeof (struct symbol *)));
+
+ /* Make sure that the symtab is set on the new symbols. Even
+ though they don't appear in this symtab directly, other parts
+ of gdb assume that symbols do, and this is reasonably
+ true. */
+ for (struct symbol *sym : template_args)
+ symbol_set_symtab (sym, symbol_symtab (templ_func));
}
/* 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)
discriminant_info. */
bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type);
sect_offset discr_offset;
+ bool has_template_parameters = false;
if (is_variant_part)
{
@@ -15920,6 +15928,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
/* Attach template arguments to type. */
if (!template_args.empty ())
{
+ has_template_parameters = true;
ALLOCATE_CPLUS_STRUCT_TYPE (type);
TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
TYPE_TEMPLATE_ARGUMENTS (type)
@@ -16069,7 +16078,20 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
attribute, and a declaration attribute. */
if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
|| !die_is_declaration (die, cu))
- new_symbol (die, type, cu);
+ {
+ struct symbol *sym = new_symbol (die, type, cu);
+
+ if (has_template_parameters)
+ {
+ /* Make sure that the symtab is set on the new symbols.
+ Even though they don't appear in this symtab directly,
+ other parts of gdb assume that symbols do, and this is
+ reasonably true. */
+ for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
+ symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i),
+ symbol_symtab (sym));
+ }
+ }
}
/* Assuming DIE is an enumeration type, and TYPE is its associated type,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8011ff1..4f4d8a2 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-08-02 Tom Tromey <tom@tromey.com>
+
+ PR symtab/16842.
+ * gdb.cp/temargs.exp: Test "info address" of a template
+ parameter.
+
2018-07-31 Jan Vrany <jan.vrany@fit.cvut.cz>
* gdb.python/py-mi-var-info-path-expression.c: New file.
diff --git a/gdb/testsuite/gdb.cp/temargs.exp b/gdb/testsuite/gdb.cp/temargs.exp
index 8c87872..5a10910 100644
--- a/gdb/testsuite/gdb.cp/temargs.exp
+++ b/gdb/testsuite/gdb.cp/temargs.exp
@@ -133,6 +133,10 @@ gdb_test "ptype T" "unsigned char" "test type of T in func"
if $have_older_template_gcc { setup_xfail "*-*-*" }
gdb_test "print I" " = 91" "test value of I in func"
+# PR symtab/16842 - gdb used to crash here.
+if $have_older_template_gcc { setup_xfail "*-*-*" }
+gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m"
+
if $have_older_template_gcc { setup_xfail "*-*-*" }
gdb_test "print P == &a_global" " = true" "test value of P in func"
@@ -151,6 +155,10 @@ gdb_test "ptype T" "double" "test type of T in templ_m"
if $have_older_template_gcc { setup_xfail "*-*-*" }
gdb_test "print I" " = 23" "test value of I in templ_m"
+# PR symtab/16842 - gdb used to crash here.
+if $have_older_template_gcc { setup_xfail "*-*-*" }
+gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m"
+
if $have_older_template_gcc { setup_xfail "*-*-*" }
gdb_test "print P == &a_global" " = true" "test value of P in templ_m"