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
discriminant_info. */
bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type);
sect_offset discr_offset;
+ bool has_template_parameters = false;
if (is_variant_part)
{
/* 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)
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,
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"
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"