if (line_header_hash)
htab_delete (line_header_hash);
- for (int ix = 0; ix < n_comp_units; ++ix)
- VEC_free (dwarf2_per_cu_ptr, all_comp_units[ix]->imported_symtabs);
+ for (dwarf2_per_cu_data *per_cu : all_comp_units)
+ VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs);
for (int ix = 0; ix < n_type_units; ++ix)
VEC_free (dwarf2_per_cu_ptr,
dwarf2_per_cu_data *
dwarf2_per_objfile::get_cutu (int index)
{
- if (index >= this->n_comp_units)
+ if (index >= this->all_comp_units.size ())
{
- index -= this->n_comp_units;
+ index -= this->all_comp_units.size ();
gdb_assert (index < this->n_type_units);
return &this->all_type_units[index]->per_cu;
}
dwarf2_per_cu_data *
dwarf2_per_objfile::get_cu (int index)
{
- gdb_assert (index >= 0 && index < this->n_comp_units);
+ gdb_assert (index >= 0 && index < this->all_comp_units.size ());
return this->all_comp_units[index];
}
create_cus_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
const gdb_byte *cu_list, offset_type n_elements,
struct dwarf2_section_info *section,
- int is_dwz,
- int base_offset)
+ int is_dwz)
{
for (offset_type i = 0; i < n_elements; i += 2)
{
ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE);
cu_list += 2 * 8;
- dwarf2_per_objfile->all_comp_units[base_offset + i / 2]
+ dwarf2_per_cu_data *per_cu
= create_cu_from_index_list (dwarf2_per_objfile, section, is_dwz,
sect_off, length);
+ dwarf2_per_objfile->all_comp_units.push_back (per_cu);
}
}
const gdb_byte *cu_list, offset_type cu_list_elements,
const gdb_byte *dwz_list, offset_type dwz_elements)
{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
- dwarf2_per_objfile->all_comp_units =
- XOBNEWVEC (&objfile->objfile_obstack, struct dwarf2_per_cu_data *,
- dwarf2_per_objfile->n_comp_units);
+ gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
+ dwarf2_per_objfile->all_comp_units.reserve
+ ((cu_list_elements + dwz_elements) / 2);
create_cus_from_index_list (dwarf2_per_objfile, cu_list, cu_list_elements,
- &dwarf2_per_objfile->info, 0, 0);
+ &dwarf2_per_objfile->info, 0);
if (dwz_elements == 0)
return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements,
- &dwz->info, 1, cu_list_elements / 2);
+ &dwz->info, 1);
}
/* Create the signatured type hash table from the index. */
continue;
}
- if (cu_index >= dwarf2_per_objfile->n_comp_units)
+ if (cu_index >= dwarf2_per_objfile->all_comp_units.size ())
{
complaint (&symfile_complaints,
_(".gdb_index address table has invalid CU number %u"),
dwarf2_per_cu_data *,
gdb::hash_enum<sect_offset>>
debug_info_offset_to_per_cu;
- for (int cui = 0; cui < dwarf2_per_objfile->n_comp_units; ++cui)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (cui);
const auto insertpair
= debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu);
if (!insertpair.second)
dwarf2_per_objfile->index_table = map;
dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table =
- create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
+ create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ());
return 1;
}
{
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- int index = dwarf2_per_objfile->n_comp_units - 1;
- dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->get_cu (index);
+ dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->all_comp_units.back ();
compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu);
if (cust == NULL)
/* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- int j;
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
- struct quick_file_names *file_data;
-
/* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab)
continue;
- file_data = dw2_get_file_names (per_cu);
+ quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL)
continue;
- for (j = 0; j < file_data->num_file_names; ++j)
+ for (int j = 0; j < file_data->num_file_names; ++j)
{
const char *this_name = file_data->file_names[j];
const char *this_real_name;
&& symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
/* Don't crash on bad data. */
- if (cu_index >= (dwarf2_per_objfile->n_comp_units
+ if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
+ dwarf2_per_objfile->n_type_units))
{
complaint (&symfile_complaints,
{
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- int total = dwarf2_per_objfile->n_comp_units + dwarf2_per_objfile->n_type_units;
+ int total = (dwarf2_per_objfile->all_comp_units.size ()
+ + dwarf2_per_objfile->n_type_units);
int count = 0;
for (int i = 0; i < total; ++i)
{
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- int total_units = (dwarf2_per_objfile->n_comp_units
+ int total_units = (dwarf2_per_objfile->all_comp_units.size ()
+ dwarf2_per_objfile->n_type_units);
for (int i = 0; i < total_units; ++i)
There can be an order of magnitude (or more) more type units
than comp units, and we avoid them if we can. */
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- int j;
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
- struct quick_file_names *file_data;
-
/* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab)
continue;
- file_data = dw2_get_file_names (per_cu);
+ quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL)
continue;
- for (j = 0; j < file_data->num_file_names; ++j)
+ for (int j = 0; j < file_data->num_file_names; ++j)
{
const char *this_fullname = file_data->file_names[j];
}
/* Don't crash on bad data. */
- if (cu_index >= (dwarf2_per_objfile->n_comp_units
+ if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
+ dwarf2_per_objfile->n_type_units))
{
complaint (&symfile_complaints,
/* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- int j;
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
- struct quick_file_names *file_data;
- void **slot;
-
QUIT;
per_cu->v.quick->mark = 0;
if (per_cu->v.quick->compunit_symtab)
continue;
- file_data = dw2_get_file_names (per_cu);
+ quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL)
continue;
continue;
}
- for (j = 0; j < file_data->num_file_names; ++j)
+ for (int j = 0; j < file_data->num_file_names; ++j)
{
const char *this_real_name;
}
}
- slot = htab_find_slot (per_cu->v.quick->mark
- ? visited_found.get ()
- : visited_not_found.get (),
- file_data, INSERT);
+ void **slot = htab_find_slot (per_cu->v.quick->mark
+ ? visited_found.get ()
+ : visited_not_found.get (),
+ file_data, INSERT);
*slot = file_data;
}
}
by any TU, so there's no need to scan TUs here. We can
ignore file names coming from already-expanded CUs. */
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
-
if (per_cu->v.quick->compunit_symtab)
{
void **slot = htab_find_slot (visited.get (),
}
}
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
- struct quick_file_names *file_data;
- void **slot;
-
/* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab)
continue;
- file_data = dw2_get_file_names (per_cu);
+ quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL)
continue;
- slot = htab_find_slot (visited.get (), file_data, INSERT);
+ void **slot = htab_find_slot (visited.get (), file_data, INSERT);
if (*slot)
{
/* Already visited. */
create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
const mapped_debug_names &map,
dwarf2_section_info §ion,
- bool is_dwz, int base_offset)
+ bool is_dwz)
{
sect_offset sect_off_prev;
for (uint32_t i = 0; i <= map.cu_count; ++i)
if (i >= 1)
{
const ULONGEST length = sect_off_next - sect_off_prev;
- dwarf2_per_objfile->all_comp_units[base_offset + (i - 1)]
+ dwarf2_per_cu_data *per_cu
= create_cu_from_index_list (dwarf2_per_objfile, §ion, is_dwz,
sect_off_prev, length);
+ dwarf2_per_objfile->all_comp_units.push_back (per_cu);
}
sect_off_prev = sect_off_next;
}
const mapped_debug_names &map,
const mapped_debug_names &dwz_map)
{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- dwarf2_per_objfile->n_comp_units = map.cu_count + dwz_map.cu_count;
- dwarf2_per_objfile->all_comp_units
- = XOBNEWVEC (&objfile->objfile_obstack, struct dwarf2_per_cu_data *,
- dwarf2_per_objfile->n_comp_units);
+ gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
+ dwarf2_per_objfile->all_comp_units.reserve (map.cu_count + dwz_map.cu_count);
create_cus_from_debug_names_list (dwarf2_per_objfile, map,
dwarf2_per_objfile->info,
- false /* is_dwz */,
- 0 /* base_offset */);
+ false /* is_dwz */);
if (dwz_map.cu_count == 0)
return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
- true /* is_dwz */,
- map.cu_count /* base_offset */);
+ true /* is_dwz */);
}
/* Read .debug_names. If everything went ok, initialize the "quick"
*dwarf2_per_objfile->debug_names_table = std::move (local_map);
dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table =
- create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
+ create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ());
return true;
}
{
case DW_IDX_compile_unit:
/* Don't crash on bad data. */
- if (ull >= dwarf2_per_objfile->n_comp_units)
+ if (ull >= dwarf2_per_objfile->all_comp_units.size ())
{
complaint (&symfile_complaints,
_(".debug_names entry has bad CU index %s"
expanded anyway. */
if ((objfile->flags & OBJF_READNOW))
{
- int i;
-
dwarf2_per_objfile->using_index = 1;
create_all_comp_units (dwarf2_per_objfile);
create_all_type_units (dwarf2_per_objfile);
- dwarf2_per_objfile->quick_file_names_table =
- create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
+ dwarf2_per_objfile->quick_file_names_table
+ = create_quick_file_names_table
+ (dwarf2_per_objfile->all_comp_units.size ());
- for (i = 0; i < (dwarf2_per_objfile->n_comp_units
- + dwarf2_per_objfile->n_type_units); ++i)
+ for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size ()
+ + dwarf2_per_objfile->n_type_units); ++i)
{
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
static void
set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- int i;
-
- for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
struct partial_symtab *pst = per_cu->v.psymtab;
- int j;
if (pst == NULL)
continue;
- for (j = 0; j < pst->number_of_dependencies; ++j)
+ for (int j = 0; j < pst->number_of_dependencies; ++j)
{
/* Set the 'user' field only if it is not already set. */
if (pst->dependencies[j]->user == NULL)
static void
dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- int i;
struct objfile *objfile = dwarf2_per_objfile->objfile;
if (dwarf_read_debug)
= make_scoped_restore (&objfile->psymtabs_addrmap,
addrmap_create_mutable (&temp_obstack));
- for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
- {
- dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
-
- process_psymtab_comp_unit (per_cu, 0, language_minimal);
- }
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
+ process_psymtab_comp_unit (per_cu, 0, language_minimal);
/* This has to wait until we read the CUs, we need the list of DWOs. */
process_skeletonless_type_units (dwarf2_per_objfile);
read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
struct dwarf2_section_info *section,
struct dwarf2_section_info *abbrev_section,
- unsigned int is_dwz,
- int *n_allocated,
- int *n_comp_units,
- struct dwarf2_per_cu_data ***all_comp_units)
+ unsigned int is_dwz)
{
const gdb_byte *info_ptr;
struct objfile *objfile = dwarf2_per_objfile->objfile;
this_cu->dwarf2_per_objfile = dwarf2_per_objfile;
this_cu->section = section;
- if (*n_comp_units == *n_allocated)
- {
- *n_allocated *= 2;
- *all_comp_units = XRESIZEVEC (struct dwarf2_per_cu_data *,
- *all_comp_units, *n_allocated);
- }
- (*all_comp_units)[*n_comp_units] = this_cu;
- ++*n_comp_units;
+ dwarf2_per_objfile->all_comp_units.push_back (this_cu);
info_ptr = info_ptr + this_cu->length;
}
static void
create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- int n_allocated;
- int n_comp_units;
- struct dwarf2_per_cu_data **all_comp_units;
- struct dwz_file *dwz;
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- n_comp_units = 0;
- n_allocated = 10;
- all_comp_units = XNEWVEC (struct dwarf2_per_cu_data *, n_allocated);
-
+ gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->info,
- &dwarf2_per_objfile->abbrev, 0,
- &n_allocated, &n_comp_units, &all_comp_units);
+ &dwarf2_per_objfile->abbrev, 0);
- dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+ dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
if (dwz != NULL)
read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
- 1, &n_allocated, &n_comp_units,
- &all_comp_units);
-
- dwarf2_per_objfile->all_comp_units = XOBNEWVEC (&objfile->objfile_obstack,
- struct dwarf2_per_cu_data *,
- n_comp_units);
- memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
- n_comp_units * sizeof (struct dwarf2_per_cu_data *));
- xfree (all_comp_units);
- dwarf2_per_objfile->n_comp_units = n_comp_units;
+ 1);
}
/* Process all loaded DIEs for compilation unit CU, starting at
const sect_offset *cu_off;
low = 0;
- high = dwarf2_per_objfile->n_comp_units - 1;
+ high = dwarf2_per_objfile->all_comp_units.size () - 1;
while (high > low)
{
struct dwarf2_per_cu_data *mid_cu;
else
{
this_cu = dwarf2_per_objfile->all_comp_units[low];
- if (low == dwarf2_per_objfile->n_comp_units - 1
+ if (low == dwarf2_per_objfile->all_comp_units.size () - 1
&& sect_off >= this_cu->sect_off + this_cu->length)
error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
gdb_assert (sect_off < this_cu->sect_off + this_cu->length);