#include "defs.h"
#include "dwarf2read.h"
+#include "dwarf-index-cache.h"
#include "dwarf-index-common.h"
#include "bfd.h"
#include "elf-bfd.h"
/* The dwz's BFD. */
gdb_bfd_ref_ptr dwz_bfd;
+
+ /* If we loaded the index from an external file, this contains the
+ resources associated to the open file, memory mapping, etc. */
+ std::unique_ptr<index_cache_resource> index_cache_res;
};
/* Struct used to pass misc. parameters to read_die_and_children, et
continue;
}
- lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
- hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
+ lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseaddr;
+ hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - baseaddr;
addrmap_set_empty (mutable_map, lo, hi - 1,
dwarf2_per_objfile->get_cu (cu_index));
}
continue;
}
ULONGEST end = start + length;
- start = gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr);
- end = gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr);
+ start = (gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr)
+ - baseaddr);
+ end = (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr)
+ - baseaddr);
addrmap_set_empty (mutable_map, start, end - 1, per_cu);
}
}
}
}
-/* A helper function that reads the .gdb_index from SECTION and fills
- in MAP. FILENAME is the name of the file containing the section;
+/* A helper function that reads the .gdb_index from BUFFER and fills
+ in MAP. FILENAME is the name of the file containing the data;
it is used for error reporting. DEPRECATED_OK is true if it is
ok to use deprecated sections.
out parameters that are filled in with information about the CU and
TU lists in the section.
- Returns 1 if all went well, 0 otherwise. */
+ Returns true if all went well, false otherwise. */
static bool
-read_gdb_index_from_section (struct objfile *objfile,
- const char *filename,
- bool deprecated_ok,
- struct dwarf2_section_info *section,
- struct mapped_index *map,
- const gdb_byte **cu_list,
- offset_type *cu_list_elements,
- const gdb_byte **types_list,
- offset_type *types_list_elements)
-{
- const gdb_byte *addr;
- offset_type version;
- offset_type *metadata;
- int i;
-
- if (dwarf2_section_empty_p (section))
- return 0;
-
- /* Older elfutils strip versions could keep the section in the main
- executable while splitting it for the separate debug info file. */
- if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
- return 0;
-
- dwarf2_read_section (objfile, section);
+read_gdb_index_from_buffer (struct objfile *objfile,
+ const char *filename,
+ bool deprecated_ok,
+ gdb::array_view<const gdb_byte> buffer,
+ struct mapped_index *map,
+ const gdb_byte **cu_list,
+ offset_type *cu_list_elements,
+ const gdb_byte **types_list,
+ offset_type *types_list_elements)
+{
+ const gdb_byte *addr = &buffer[0];
- addr = section->buffer;
/* Version check. */
- version = MAYBE_SWAP (*(offset_type *) addr);
+ offset_type version = MAYBE_SWAP (*(offset_type *) addr);
/* Versions earlier than 3 emitted every copy of a psymbol. This
causes the index to behave very poorly for certain requests. Version 3
contained incomplete addrmap. So, it seems better to just ignore such
map->version = version;
- metadata = (offset_type *) (addr + sizeof (offset_type));
+ offset_type *metadata = (offset_type *) (addr + sizeof (offset_type));
- i = 0;
+ int i = 0;
*cu_list = addr + MAYBE_SWAP (metadata[i]);
*cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
/ 8);
return 1;
}
+/* Callback types for dwarf2_read_gdb_index. */
+
+typedef gdb::function_view
+ <gdb::array_view<const gdb_byte>(objfile *, dwarf2_per_objfile *)>
+ get_gdb_index_contents_ftype;
+typedef gdb::function_view
+ <gdb::array_view<const gdb_byte>(objfile *, dwz_file *)>
+ get_gdb_index_contents_dwz_ftype;
+
/* Read .gdb_index. If everything went ok, initialize the "quick"
elements of all the CUs and return 1. Otherwise, return 0. */
static int
-dwarf2_read_gdb_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_read_gdb_index
+ (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ get_gdb_index_contents_ftype get_gdb_index_contents,
+ get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
{
const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
struct dwz_file *dwz;
struct objfile *objfile = dwarf2_per_objfile->objfile;
+ gdb::array_view<const gdb_byte> main_index_contents
+ = get_gdb_index_contents (objfile, dwarf2_per_objfile);
+
+ if (main_index_contents.empty ())
+ return 0;
+
std::unique_ptr<struct mapped_index> map (new struct mapped_index);
- if (!read_gdb_index_from_section (objfile, objfile_name (objfile),
- use_deprecated_index_sections,
- &dwarf2_per_objfile->gdb_index, map.get (),
- &cu_list, &cu_list_elements,
- &types_list, &types_list_elements))
+ if (!read_gdb_index_from_buffer (objfile, objfile_name (objfile),
+ use_deprecated_index_sections,
+ main_index_contents, map.get (), &cu_list,
+ &cu_list_elements, &types_list,
+ &types_list_elements))
return 0;
/* Don't use the index if it's empty. */
const gdb_byte *dwz_types_ignore;
offset_type dwz_types_elements_ignore;
- if (!read_gdb_index_from_section (objfile,
- bfd_get_filename (dwz->dwz_bfd), 1,
- &dwz->gdb_index, &dwz_map,
- &dwz_list, &dwz_list_elements,
- &dwz_types_ignore,
- &dwz_types_elements_ignore))
+ gdb::array_view<const gdb_byte> dwz_index_content
+ = get_gdb_index_contents_dwz (objfile, dwz);
+
+ if (dwz_index_content.empty ())
+ return 0;
+
+ if (!read_gdb_index_from_buffer (objfile,
+ bfd_get_filename (dwz->dwz_bfd), 1,
+ dwz_index_content, &dwz_map,
+ &dwz_list, &dwz_list_elements,
+ &dwz_types_ignore,
+ &dwz_types_elements_ignore))
{
warning (_("could not read '.gdb_index' section from %s; skipping"),
bfd_get_filename (dwz->dwz_bfd));
printf_filtered ("\n");
}
-static void
-dw2_relocate (struct objfile *objfile,
- const struct section_offsets *new_offsets,
- const struct section_offsets *delta)
-{
- /* There's nothing to relocate here. */
-}
-
static void
dw2_expand_symtabs_for_function (struct objfile *objfile,
const char *func_name)
if (!objfile->psymtabs_addrmap)
return NULL;
+ CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+ SECT_OFF_TEXT (objfile));
data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->psymtabs_addrmap,
- pc);
+ pc - baseaddr);
if (!data)
return NULL;
dw2_lookup_symbol,
dw2_print_stats,
dw2_dump,
- dw2_relocate,
dw2_expand_symtabs_for_function,
dw2_expand_all_symtabs,
dw2_expand_symtabs_with_fullname,
dw2_debug_names_lookup_symbol,
dw2_print_stats,
dw2_debug_names_dump,
- dw2_relocate,
dw2_debug_names_expand_symtabs_for_function,
dw2_expand_all_symtabs,
dw2_expand_symtabs_with_fullname,
dw2_map_symbol_filenames
};
+/* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
+ to either a dwarf2_per_objfile or dwz_file object. */
+
+template <typename T>
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_section (objfile *obj, T *section_owner)
+{
+ dwarf2_section_info *section = §ion_owner->gdb_index;
+
+ if (dwarf2_section_empty_p (section))
+ return {};
+
+ /* Older elfutils strip versions could keep the section in the main
+ executable while splitting it for the separate debug info file. */
+ if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
+ return {};
+
+ dwarf2_read_section (obj, section);
+
+ return {section->buffer, section->size};
+}
+
+/* Lookup the index cache for the contents of the index associated to
+ DWARF2_OBJ. */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache (objfile *obj, dwarf2_per_objfile *dwarf2_obj)
+{
+ const bfd_build_id *build_id = build_id_bfd_get (obj->obfd);
+ if (build_id == nullptr)
+ return {};
+
+ return global_index_cache.lookup_gdb_index (build_id,
+ &dwarf2_obj->index_cache_res);
+}
+
+/* Same as the above, but for DWZ. */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz)
+{
+ const bfd_build_id *build_id = build_id_bfd_get (dwz->dwz_bfd.get ());
+ if (build_id == nullptr)
+ return {};
+
+ return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
+}
+
/* See symfile.h. */
bool
return true;
}
- if (dwarf2_read_gdb_index (dwarf2_per_objfile))
+ if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+ get_gdb_index_contents_from_section<struct dwarf2_per_objfile>,
+ get_gdb_index_contents_from_section<dwz_file>))
+ {
+ *index_kind = dw_index_kind::GDB_INDEX;
+ return true;
+ }
+
+ /* ... otherwise, try to find the index in the index cache. */
+ if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+ get_gdb_index_contents_from_cache,
+ get_gdb_index_contents_from_cache_dwz))
{
+ global_index_cache.hit ();
*index_kind = dw_index_kind::GDB_INDEX;
return true;
}
+ global_index_cache.miss ();
return false;
}
psymtab_discarder psymtabs (objfile);
dwarf2_build_psymtabs_hard (dwarf2_per_objfile);
psymtabs.keep ();
+
+ /* (maybe) store an index in the cache. */
+ global_index_cache.store (dwarf2_per_objfile);
}
CATCH (except, RETURN_MASK_ERROR)
{
subpst->dirname = pst->dirname;
}
- subpst->textlow = 0;
- subpst->texthigh = 0;
-
subpst->dependencies
= XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
subpst->dependencies[0] = pst;
if (lh == NULL)
return; /* No linetable, so no includes. */
- /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
- dwarf_decode_lines (lh.get (), pst->dirname, cu, pst, pst->textlow, 1);
+ /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
+ that we pass in the raw text_low here; that is ok because we're
+ only decoding the line table to make include partial symtabs, and
+ so the addresses aren't really used. */
+ dwarf_decode_lines (lh.get (), pst->dirname, cu, pst,
+ pst->raw_text_low (), 1);
}
static hashval_t
{
unsigned int line_offset = to_underlying (line_offset_struct);
struct partial_symtab *pst;
- char *name;
+ std::string name;
/* Give the symtab a useful name for debug purposes. */
if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
- name = xstrprintf ("<type_units_%d>",
- (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
+ name = string_printf ("<type_units_%d>",
+ (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
else
- name = xstrprintf ("<type_units_at_0x%x>", line_offset);
+ name = string_printf ("<type_units_at_0x%x>", line_offset);
- pst = create_partial_symtab (per_cu, name);
+ pst = create_partial_symtab (per_cu, name.c_str ());
pst->anonymous = 1;
-
- xfree (name);
}
tu_group->hash.dwo_unit = cu->dwo_unit;
cu_bounds_kind = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
&best_highpc, cu, pst);
if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
- /* Store the contiguous range if it is not empty; it can be empty for
- CUs with no code. */
- addrmap_set_empty (objfile->psymtabs_addrmap,
- gdbarch_adjust_dwarf2_addr (gdbarch,
- best_lowpc + baseaddr),
- gdbarch_adjust_dwarf2_addr (gdbarch,
- best_highpc + baseaddr) - 1,
- pst);
+ {
+ CORE_ADDR low
+ = (gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr)
+ - baseaddr);
+ CORE_ADDR high
+ = (gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr)
+ - baseaddr - 1);
+ /* Store the contiguous range if it is not empty; it can be
+ empty for CUs with no code. */
+ addrmap_set_empty (objfile->psymtabs_addrmap, low, high, pst);
+ }
/* Check if comp unit has_children.
If so, read the rest of the partial symbols from this comp unit.
best_highpc = highpc;
}
}
- pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr);
- pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr);
+ pst->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch,
+ best_lowpc + baseaddr)
+ - baseaddr);
+ pst->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch,
+ best_highpc + baseaddr)
+ - baseaddr);
end_psymtab_common (objfile, pst);
", %d global, %d static syms\n",
per_cu->is_debug_types ? "type" : "comp",
sect_offset_str (per_cu->sect_off),
- paddress (gdbarch, pst->textlow),
- paddress (gdbarch, pst->texthigh),
+ paddress (gdbarch, pst->text_low (objfile)),
+ paddress (gdbarch, pst->text_high (objfile)),
pst->n_global_syms, pst->n_static_syms);
}
}
{
case DW_TAG_inlined_subroutine:
case DW_TAG_subprogram:
- addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr);
+ addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr)
+ - baseaddr);
if (pdi->is_external || cu->language == language_ada)
{
/* brobecker/2007-12-26: Normally, only "external" DIEs are part
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
+ SECT_OFF_TEXT (objfile),
&objfile->global_psymbols,
- addr, cu->language, objfile);
+ addr,
+ cu->language, objfile);
}
else
{
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
+ SECT_OFF_TEXT (objfile),
&objfile->static_psymbols,
addr, cu->language, objfile);
}
list = &objfile->static_psymbols;
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
- list, 0, cu->language, objfile);
+ -1, list, 0, cu->language, objfile);
}
break;
case DW_TAG_variable:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
+ SECT_OFF_TEXT (objfile),
&objfile->global_psymbols,
- addr + baseaddr,
- cu->language, objfile);
+ addr, cu->language, objfile);
}
else
{
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
+ SECT_OFF_TEXT (objfile),
&objfile->static_psymbols,
- has_loc ? addr + baseaddr : (CORE_ADDR) 0,
+ has_loc ? addr : 0,
cu->language, objfile);
}
break;
case DW_TAG_subrange_type:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
- VAR_DOMAIN, LOC_TYPEDEF,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
&objfile->static_psymbols,
0, cu->language, objfile);
break;
case DW_TAG_namespace:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
- VAR_DOMAIN, LOC_TYPEDEF,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
&objfile->global_psymbols,
0, cu->language, objfile);
break;
case DW_TAG_module:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
- MODULE_DOMAIN, LOC_TYPEDEF,
+ MODULE_DOMAIN, LOC_TYPEDEF, -1,
&objfile->global_psymbols,
0, cu->language, objfile);
break;
static vs. global. */
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
- STRUCT_DOMAIN, LOC_TYPEDEF,
+ STRUCT_DOMAIN, LOC_TYPEDEF, -1,
cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
case DW_TAG_enumerator:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
- VAR_DOMAIN, LOC_CONST,
+ VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
baseaddr = ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
- lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- pdi->lowpc + baseaddr);
- highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- pdi->highpc + baseaddr);
+ lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->lowpc + baseaddr)
+ - baseaddr);
+ highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->highpc + baseaddr)
+ - baseaddr);
addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
cu->per_cu->v.psymtab);
}
cu->method_list.clear ();
}
+/* A wrapper for add_symbol_to_list to ensure that SYMBOL's language is
+ the same as all other symbols in LISTHEAD. If a new symbol is added
+ with a different language, this function asserts. */
+
+static inline void
+dw2_add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
+{
+ /* Only assert if LISTHEAD already contains symbols of a different
+ language (dict_create_hashed/insert_symbol_hashed requires that all
+ symbols in this list are of the same language). */
+ gdb_assert ((*listhead) == NULL
+ || (SYMBOL_LANGUAGE ((*listhead)->symbol[0])
+ == SYMBOL_LANGUAGE (symbol)));
+
+ add_symbol_to_list (symbol, listhead);
+}
+
/* Go objects should be embedded in a DW_TAG_module DIE,
and it's not clear if/how imported objects will appear.
To keep Go support simple until that's worked out,
SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
SYMBOL_TYPE (sym) = type;
- add_symbol_to_list (sym, cu->builder->get_global_symbols ());
+ dw2_add_symbol_to_list (sym, cu->builder->get_global_symbols ());
xfree (package_name);
}
struct die_info *child_die;
CORE_ADDR baseaddr;
+ prepare_one_comp_unit (cu, die, cu->language);
baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
get_scope_pc_bounds (die, &lowpc, &highpc, cu);
file_and_directory fnd = find_file_and_directory (die, cu);
- prepare_one_comp_unit (cu, die, cu->language);
-
/* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
standardised yet. As a workaround for the language detection we fall
back to the DW_AT_producer string. */
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
}
}
- new_symbol (die, NULL, cu, storage);
+ struct symbol *res = new_symbol (die, NULL, cu, storage);
+ struct attribute *abstract_origin
+ = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+ struct attribute *loc = dwarf2_attr (die, DW_AT_location, cu);
+ if (res == NULL && loc && abstract_origin)
+ {
+ /* We have a variable without a name, but with a location and an abstract
+ origin. This may be a concrete instance of an abstract variable
+ referenced from an DW_OP_GNU_variable_value, so save it to find it back
+ later. */
+ struct dwarf2_cu *origin_cu = cu;
+ struct die_info *origin_die
+ = follow_die_ref (die, abstract_origin, &origin_cu);
+ dwarf2_per_objfile *dpo = cu->per_cu->dwarf2_per_objfile;
+ dpo->abstract_to_concrete[origin_die].push_back (die);
+ }
}
/* Call CALLBACK from DW_AT_ranges attribute value OFFSET
CORE_ADDR lowpc;
CORE_ADDR highpc;
- lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- range_beginning + baseaddr);
- highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- range_end + baseaddr);
+ lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ range_beginning + baseaddr)
+ - baseaddr);
+ highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ range_end + baseaddr)
+ - baseaddr);
addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
ranges_pst);
}
unsigned long offset = (DW_UNSND (attr)
+ (need_ranges_base ? cu->ranges_base : 0));
+ std::vector<blockrange> blockvec;
dwarf2_ranges_process (offset, cu,
[&] (CORE_ADDR start, CORE_ADDR end)
{
start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
cu->builder->record_block_range (block, start, end - 1);
+ blockvec.emplace_back (start, end);
});
+
+ BLOCK_RANGES(block) = make_blockranges (objfile, blockvec);
}
}
fp->type = get_die_type (die, cu);
fp->artificial = 1;
fp->name = "<<variant>>";
+
+ /* Normally a DW_TAG_variant_part won't have a size, but our
+ representation requires one, so set it to the maximum of the
+ child sizes. */
+ if (TYPE_LENGTH (fp->type) == 0)
+ {
+ unsigned max = 0;
+ for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i)
+ if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)) > max)
+ max = TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i));
+ TYPE_LENGTH (fp->type) = max;
+ }
}
else
gdb_assert_not_reached ("missing case in dwarf2_add_field");
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,
sect_offset_str (die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
- attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
+ struct attribute *attr_ub, *attr_count;
+ attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
if (!attr_to_dynamic_prop (attr, die, cu, &high))
{
- attr = dwarf2_attr (die, DW_AT_count, cu);
+ attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
if (attr_to_dynamic_prop (attr, die, cu, &high))
{
/* If bounds are constant do the final calculation here. */
else
high_bound_is_count = 1;
}
+ else
+ {
+ if (attr_ub != NULL)
+ complaint (_("Unresolved DW_AT_upper_bound "
+ "- DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ if (attr_count != NULL)
+ complaint (_("Unresolved DW_AT_count "
+ "- DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ }
+
}
/* Dwarf-2 specifications explicitly allows to create subrange types
{
if (building_psymtab && pdi.name != NULL)
add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
- VAR_DOMAIN, LOC_TYPEDEF,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
&objfile->static_psymbols,
0, cu->language, objfile);
info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
complaint (_("malformed enumerator DIE ignored"));
else if (building_psymtab)
add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
- VAR_DOMAIN, LOC_CONST,
+ VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
- add_symbol_to_list (sym, cu->list_in_scope);
+ dw2_add_symbol_to_list (sym, cu->list_in_scope);
break;
case DW_TAG_subprogram:
/* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
case DW_TAG_common_block:
SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
- add_symbol_to_list (sym, cu->list_in_scope);
+ dw2_add_symbol_to_list (sym, cu->list_in_scope);
break;
default:
/* Not a tag we recognize. Hopefully we aren't processing
}
if (list_to_add != NULL)
- add_symbol_to_list (sym, list_to_add);
+ dw2_add_symbol_to_list (sym, list_to_add);
/* For the benefit of old versions of GCC, check for anonymous
namespaces based on the demangled name. */
struct dwarf2_per_objfile *dwarf2_per_objfile
= cu->per_cu->dwarf2_per_objfile;
struct objfile *objfile = dwarf2_per_objfile->objfile;
- char *message, *saved;
+ char *saved;
- message = xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
- objfile_name (objfile),
- sect_offset_str (cu->header.sect_off),
- sect_offset_str (die->sect_off));
+ std::string message
+ = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
+ objfile_name (objfile),
+ sect_offset_str (cu->header.sect_off),
+ sect_offset_str (die->sect_off));
saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
- message, strlen (message));
- xfree (message);
+ message.c_str (), message.length ());
return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
}
dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
struct dwarf2_per_cu_data *per_cu,
CORE_ADDR (*get_frame_pc) (void *baton),
- void *baton)
+ void *baton, bool resolve_abstract_p)
{
struct dwarf2_cu *cu;
struct die_info *die;
sect_offset_str (sect_off), objfile_name (objfile));
attr = dwarf2_attr (die, DW_AT_location, cu);
+ if (!attr && resolve_abstract_p
+ && (dwarf2_per_objfile->abstract_to_concrete.find (die)
+ != dwarf2_per_objfile->abstract_to_concrete.end ()))
+ {
+ CORE_ADDR pc = (*get_frame_pc) (baton);
+
+ for (const auto &cand : dwarf2_per_objfile->abstract_to_concrete[die])
+ {
+ if (!cand->parent
+ || cand->parent->tag != DW_TAG_subprogram)
+ continue;
+
+ CORE_ADDR pc_low, pc_high;
+ get_scope_pc_bounds (cand->parent, &pc_low, &pc_high, cu);
+ if (pc_low == ((CORE_ADDR) -1)
+ || !(pc_low <= pc && pc < pc_high))
+ continue;
+
+ die = cand;
+ attr = dwarf2_attr (die, DW_AT_location, cu);
+ break;
+ }
+ }
+
if (!attr)
{
/* DWARF: "If there is no such attribute, then there is no effect.".
return part_die_lhs->sect_off == part_die_rhs->sect_off;
}
-static struct cmd_list_element *set_dwarf_cmdlist;
-static struct cmd_list_element *show_dwarf_cmdlist;
+struct cmd_list_element *set_dwarf_cmdlist;
+struct cmd_list_element *show_dwarf_cmdlist;
static void
set_dwarf_cmd (const char *args, int from_tty)