/* DWARF 2 debugging format support for GDB.
- Copyright (C) 1994-2018 Free Software Foundation, Inc.
+ Copyright (C) 1994-2019 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
#include "defs.h"
#include "dwarf2read.h"
+#include "dwarf-index-cache.h"
#include "dwarf-index-common.h"
#include "bfd.h"
#include "elf-bfd.h"
std::vector<struct type *> rust_unions;
/* Mark used when releasing cached dies. */
- unsigned int mark : 1;
+ bool mark : 1;
/* This CU references .debug_loc. See the symtab->locations_valid field.
This test is imperfect as there may exist optimized debug code not using
any location list and still facing inlining issues if handled as
unoptimized code. For a future better test see GCC PR other/32998. */
- unsigned int has_loclist : 1;
+ bool has_loclist : 1;
- /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
+ /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
if all the producer_is_* fields are valid. This information is cached
because profiling CU expansion showed excessive time spent in
producer_is_gxx_lt_4_6. */
- unsigned int checked_producer : 1;
- unsigned int producer_is_gxx_lt_4_6 : 1;
- unsigned int producer_is_gcc_lt_4_3 : 1;
- unsigned int producer_is_icc_lt_14 : 1;
-
- /* When set, the file that we're processing is known to have
+ bool checked_producer : 1;
+ bool producer_is_gxx_lt_4_6 : 1;
+ bool producer_is_gcc_lt_4_3 : 1;
+ bool producer_is_icc : 1;
+ bool producer_is_icc_lt_14 : 1;
+ bool producer_is_codewarrior : 1;
+
+ /* When true, the file that we're processing is known to have
debugging info for C++ namespaces. GCC 3.3.x did not produce
this information, but later versions do. */
- unsigned int processing_has_namespace_info : 1;
+ bool processing_has_namespace_info : 1;
struct partial_die_info *find_partial_die (sect_offset sect_off);
};
/* 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
}
}
-/* 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;
+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];
- 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);
-
- 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));
const gdb_byte *abbrev_table_start = addr;
for (;;)
{
- unsigned int bytes_read;
const ULONGEST index_num = read_unsigned_leb128 (abfd, addr, &bytes_read);
addr += bytes_read;
if (index_num == 0)
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);
+
+ /* dwarf2_section_info::size is a bfd_size_type, while
+ gdb::array_view works with size_t. On 32-bit hosts, with
+ --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
+ is 32-bit. So we need an explicit narrowing conversion here.
+ This is fine, because it's impossible to allocate or mmap an
+ array/buffer larger than what size_t can represent. */
+ return gdb::make_array_view (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;
}
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- if (objfile->global_psymbols.capacity () == 0
- && objfile->static_psymbols.capacity () == 0)
- init_psymbol_list (objfile, 1024);
+ init_psymbol_list (objfile, 1024);
TRY
{
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->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
- subpst->globals_offset = 0;
- subpst->n_global_syms = 0;
- subpst->statics_offset = 0;
- subpst->n_static_syms = 0;
- subpst->compunit_symtab = NULL;
subpst->read_symtab = pst->read_symtab;
- subpst->readin = 0;
/* No private part is necessary for include psymtabs. This property
can be used to differentiate between such include psymtabs and
{
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;
struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
struct partial_symtab *pst;
- pst = start_psymtab_common (objfile, name, 0,
- objfile->global_psymbols,
- objfile->static_psymbols);
+ pst = start_psymtab_common (objfile, name, 0);
pst->psymtabs_addrmap_supported = 1;
dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
if (dwarf_read_debug)
- {
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
-
- fprintf_unfiltered (gdb_stdlog,
- "Psymtab for %s unit @%s: %s - %s"
- ", %d global, %d static syms\n",
- per_cu->is_debug_types ? "type" : "comp",
- sect_offset_str (per_cu->sect_off),
- paddress (gdbarch, pst->text_low (objfile)),
- paddress (gdbarch, pst->text_high (objfile)),
- pst->n_global_syms, pst->n_static_syms);
- }
+ fprintf_unfiltered (gdb_stdlog,
+ "Psymtab for %s unit @%s: %s - %s"
+ ", %d global, %d static syms\n",
+ per_cu->is_debug_types ? "type" : "comp",
+ sect_offset_str (per_cu->sect_off),
+ paddress (gdbarch, pst->text_low (objfile)),
+ paddress (gdbarch, pst->text_high (objfile)),
+ pst->n_global_syms, pst->n_static_syms);
}
/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
SECT_OFF_TEXT (objfile),
- &objfile->global_psymbols,
+ psymbol_placement::GLOBAL,
addr,
cu->language, objfile);
}
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
SECT_OFF_TEXT (objfile),
- &objfile->static_psymbols,
+ psymbol_placement::STATIC,
addr, cu->language, objfile);
}
set_objfile_main_name (objfile, actual_name, cu->language);
break;
case DW_TAG_constant:
- {
- std::vector<partial_symbol *> *list;
-
- if (pdi->is_external)
- list = &objfile->global_psymbols;
- else
- list = &objfile->static_psymbols;
- add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
- -1, list, 0, cu->language, objfile);
- }
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
+ -1, (pdi->is_external
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC),
+ 0, cu->language, objfile);
break;
case DW_TAG_variable:
if (pdi->d.locdesc)
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
SECT_OFF_TEXT (objfile),
- &objfile->global_psymbols,
+ psymbol_placement::GLOBAL,
addr, cu->language, objfile);
}
else
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
SECT_OFF_TEXT (objfile),
- &objfile->static_psymbols,
+ psymbol_placement::STATIC,
has_loc ? addr : 0,
cu->language, objfile);
}
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_TYPEDEF, -1,
- &objfile->static_psymbols,
+ psymbol_placement::STATIC,
0, cu->language, objfile);
break;
case DW_TAG_imported_declaration:
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_TYPEDEF, -1,
- &objfile->global_psymbols,
+ psymbol_placement::GLOBAL,
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, -1,
- &objfile->global_psymbols,
+ psymbol_placement::GLOBAL,
0, cu->language, objfile);
break;
case DW_TAG_class_type:
built_actual_name != NULL,
STRUCT_DOMAIN, LOC_TYPEDEF, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
break;
built_actual_name != NULL,
VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
break;
default:
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
CORE_ADDR baseaddr;
- CORE_ADDR highpc;
- CORE_ADDR lowpc;
+ CORE_ADDR this_highpc;
+ CORE_ADDR this_lowpc;
baseaddr = ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
- 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,
+ this_lowpc
+ = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->lowpc + baseaddr)
+ - baseaddr);
+ this_highpc
+ = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->highpc + baseaddr)
+ - baseaddr);
+ addrmap_set_empty (objfile->psymtabs_addrmap,
+ this_lowpc, this_highpc - 1,
cu->per_cu->v.psymtab);
}
}
included by PER_CU. */
static void
-recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
+recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
htab_t all_children, htab_t all_type_symtabs,
struct dwarf2_per_cu_data *per_cu,
struct compunit_symtab *immediate_parent)
if (*slot == NULL)
{
*slot = cust;
- VEC_safe_push (compunit_symtab_ptr, *result, cust);
+ result->push_back (cust);
if (cust->user == NULL)
cust->user = immediate_parent;
}
}
else
{
- VEC_safe_push (compunit_symtab_ptr, *result, cust);
+ result->push_back (cust);
if (cust->user == NULL)
cust->user = immediate_parent;
}
{
int ix, len;
struct dwarf2_per_cu_data *per_cu_iter;
- struct compunit_symtab *compunit_symtab_iter;
- VEC (compunit_symtab_ptr) *result_symtabs = NULL;
+ std::vector<compunit_symtab *> result_symtabs;
htab_t all_children, all_type_symtabs;
struct compunit_symtab *cust = get_compunit_symtab (per_cu);
}
/* Now we have a transitive closure of all the included symtabs. */
- len = VEC_length (compunit_symtab_ptr, result_symtabs);
+ len = result_symtabs.size ();
cust->includes
= XOBNEWVEC (&per_cu->dwarf2_per_objfile->objfile->objfile_obstack,
struct compunit_symtab *, len + 1);
- for (ix = 0;
- VEC_iterate (compunit_symtab_ptr, result_symtabs, ix,
- compunit_symtab_iter);
- ++ix)
- cust->includes[ix] = compunit_symtab_iter;
+ memcpy (cust->includes, result_symtabs.data (),
+ len * sizeof (compunit_symtab *));
cust->includes[len] = NULL;
- VEC_free (compunit_symtab_ptr, result_symtabs);
htab_delete (all_children);
htab_delete (all_type_symtabs);
}
case DW_TAG_common_inclusion:
break;
case DW_TAG_namespace:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
read_namespace (die, cu);
break;
case DW_TAG_module:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
read_module (die, cu);
break;
case DW_TAG_imported_declaration:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
if (read_namespace_alias (die, cu))
break;
/* The declaration is not a global namespace alias. */
/* Fall through. */
case DW_TAG_imported_module:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
|| cu->language != language_fortran))
complaint (_("Tag '%s' has unexpected children"),
types, but gives them a size of zero. Starting with version 14,
ICC is compatible with GCC. */
-static int
+static bool
producer_is_icc_lt_14 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
return cu->producer_is_icc_lt_14;
}
+/* ICC generates a DW_AT_type for C void functions. This was observed on
+ ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
+ which says that void functions should not have a DW_AT_type. */
+
+static bool
+producer_is_icc (struct dwarf2_cu *cu)
+{
+ if (!cu->checked_producer)
+ check_producer (cu);
+
+ return cu->producer_is_icc;
+}
+
/* Check for possibly missing DW_AT_comp_dir with relative .debug_line
directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
this, it was first present in GCC release 4.3.0. */
-static int
+static bool
producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
{
const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
int *ids = htab->section_pool.v2.section_ids;
+ size_t sizeof_ids = sizeof (htab->section_pool.v2.section_ids);
/* Reverse map for error checking. */
int ids_seen[DW_SECT_MAX + 1];
int i;
" in section table [in module %s]"),
dwp_file->name);
}
- memset (ids, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
- memset (ids_seen, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
+ memset (ids, 255, sizeof_ids);
+ memset (ids_seen, 255, sizeof (ids_seen));
for (i = 0; i < nr_columns; ++i)
{
int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
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 (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
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);
}
}
cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
}
else if (producer_is_icc (cu->producer, &major, &minor))
- cu->producer_is_icc_lt_14 = major < 14;
+ {
+ cu->producer_is_icc = true;
+ cu->producer_is_icc_lt_14 = major < 14;
+ }
+ else if (startswith (cu->producer, "CodeWarrior S12/L-ISA"))
+ cu->producer_is_codewarrior = true;
else
{
/* For other non-GCC compilers, expect their behavior is DWARF version
compliant. */
}
- cu->checked_producer = 1;
+ cu->checked_producer = true;
}
/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
during 4.6.0 experimental. */
-static int
+static bool
producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
return cu->producer_is_gxx_lt_4_6;
}
+
+/* Codewarrior (at least as of version 5.0.40) generates dwarf line information
+ with incorrect is_stmt attributes. */
+
+static bool
+producer_is_codewarrior (struct dwarf2_cu *cu)
+{
+ if (!cu->checked_producer)
+ check_producer (cu);
+
+ return cu->producer_is_codewarrior;
+}
+
/* Return the default accessibility type if it is not overriden by
DW_AT_accessibility. */
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,
return type;
}
+/* Allocate an integer type of size BITS and name NAME. */
+
+static struct type *
+dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
+ int bits, int unsigned_p, const char *name)
+{
+ struct type *type;
+
+ /* Versions of Intel's C Compiler generate an integer type called "void"
+ instead of using DW_TAG_unspecified_type. This has been seen on
+ at least versions 14, 17, and 18. */
+ if (bits == 0 && producer_is_icc (cu) && name != nullptr
+ && strcmp (name, "void") == 0)
+ type = objfile_type (objfile)->builtin_void;
+ else
+ type = init_integer_type (objfile, bits, unsigned_p, name);
+
+ return type;
+}
+
/* Find a representation of a given base type and install
it in the TYPE field of the die. */
type = dwarf2_init_float_type (objfile, bits, name, name);
break;
case DW_ATE_signed:
- type = init_integer_type (objfile, bits, 0, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
break;
case DW_ATE_unsigned:
if (cu->language == language_fortran
&& startswith (name, "character("))
type = init_character_type (objfile, bits, 1, name);
else
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
break;
case DW_ATE_signed_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_fortran)
type = init_character_type (objfile, bits, 0, name);
else
- type = init_integer_type (objfile, bits, 0, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
break;
case DW_ATE_unsigned_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_rust)
type = init_character_type (objfile, bits, 1, name);
else
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
break;
case DW_ATE_UTF:
{
{
complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
bits);
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
}
return set_die_type (die, type, cu);
}
int low_default_is_valid;
int high_bound_is_count = 0;
const char *name;
- LONGEST negative_mask;
+ ULONGEST negative_mask;
orig_base_type = die_type (die, cu);
/* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
the bounds as signed, and thus sign-extend their values, when
the base type is signed. */
negative_mask =
- -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
+ -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
if (low.kind == PROP_CONST
&& !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
low.data.const_val |= negative_mask;
if (building_psymtab && pdi.name != NULL)
add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
VAR_DOMAIN, LOC_TYPEDEF, -1,
- &objfile->static_psymbols,
+ psymbol_placement::STATIC,
0, cu->language, objfile);
info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
continue;
add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
unsigned int *bytes_read_ptr)
{
- LONGEST result;
+ ULONGEST result;
int shift, num_read;
unsigned char byte;
byte = bfd_get_8 (abfd, buf);
buf++;
num_read++;
- result |= ((LONGEST) (byte & 127) << shift);
+ result |= ((ULONGEST) (byte & 127) << shift);
shift += 7;
if ((byte & 128) == 0)
{
}
}
if ((shift < 8 * sizeof (result)) && (byte & 0x40))
- result |= -(((LONGEST) 1) << shift);
+ result |= -(((ULONGEST) 1) << shift);
*bytes_read_ptr = num_read;
return result;
}
/* Read directory table. */
read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
&cu->header,
- [] (struct line_header *lh, const char *name,
+ [] (struct line_header *header, const char *name,
dir_index d_index, unsigned int mod_time,
unsigned int length)
{
- lh->add_include_dir (name);
+ header->add_include_dir (name);
});
/* Read file name table. */
read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
&cu->header,
- [] (struct line_header *lh, const char *name,
+ [] (struct line_header *header, const char *name,
dir_index d_index, unsigned int mod_time,
unsigned int length)
{
- lh->add_file_name (name, d_index, mod_time, length);
+ header->add_file_name (name, d_index, mod_time, length);
});
}
else
else if (m_op_index == 0 || end_sequence)
{
fe->included_p = 1;
- if (m_record_lines_p && m_is_stmt)
+ if (m_record_lines_p && (producer_is_codewarrior (m_cu) || m_is_stmt))
{
if (m_last_subfile != m_cu->builder->get_current_subfile ()
|| end_sequence)
cu->builder->record_debugformat ("DWARF 2");
cu->builder->record_producer (cu->producer);
- cu->processing_has_namespace_info = 0;
+ cu->processing_has_namespace_info = false;
return cu->builder->get_compunit_symtab ();
}
dwarf2_symbol_mark_computed (attr, sym, cu, 0);
if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
- cu->has_loclist = 1;
+ cu->has_loclist = true;
}
/* Given a pointer to a DWARF information entry, figure out if we need
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.".
{
struct dwarf2_per_cu_data *this_cu;
int low, high;
- const sect_offset *cu_off;
low = 0;
high = dwarf2_per_objfile->all_comp_units.size () - 1;
int mid = low + (high - low) / 2;
mid_cu = dwarf2_per_objfile->all_comp_units[mid];
- cu_off = &mid_cu->sect_off;
if (mid_cu->is_dwz > offset_in_dwz
- || (mid_cu->is_dwz == offset_in_dwz && *cu_off >= sect_off))
+ || (mid_cu->is_dwz == offset_in_dwz
+ && mid_cu->sect_off + mid_cu->length >= sect_off))
high = mid;
else
low = mid + 1;
}
gdb_assert (low == high);
this_cu = dwarf2_per_objfile->all_comp_units[low];
- cu_off = &this_cu->sect_off;
- if (this_cu->is_dwz != offset_in_dwz || *cu_off > sect_off)
+ if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
{
if (low == 0 || this_cu->is_dwz != offset_in_dwz)
error (_("Dwarf Error: could not find partial DIE containing "
dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data *per_cu_)
: per_cu (per_cu_),
- mark (0),
- has_loclist (0),
- checked_producer (0),
- producer_is_gxx_lt_4_6 (0),
- producer_is_gcc_lt_4_3 (0),
- producer_is_icc_lt_14 (0),
- processing_has_namespace_info (0)
+ mark (false),
+ has_loclist (false),
+ checked_producer (false),
+ producer_is_gxx_lt_4_6 (false),
+ producer_is_gcc_lt_4_3 (false),
+ producer_is_icc (false),
+ producer_is_icc_lt_14 (false),
+ producer_is_codewarrior (false),
+ processing_has_namespace_info (false)
{
per_cu->cu = this;
}
if (per_cu->cu->mark)
return 1;
- per_cu->cu->mark = 1;
+ per_cu->cu->mark = true;
if (per_cu->cu->dependencies != NULL)
htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
{
if (cu->mark)
return;
- cu->mark = 1;
+ cu->mark = true;
if (cu->dependencies != NULL)
htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
}
{
while (per_cu)
{
- per_cu->cu->mark = 0;
+ per_cu->cu->mark = false;
per_cu = per_cu->cu->read_in_chain;
}
}