Make dwarf2_per_objfile::all_comp_units an std::vector

Make all_comp_units an std::vector, remove n_comp_units and some manual
memory management.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise.
	Make an std::vector.
	<n_comp_units>: Remove.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
	to std::vector change.
	(dwarf2_per_objfile::get_cutu): Likewise.
	(dwarf2_per_objfile::get_cu): Likewise.
	(create_cus_from_index): Likewise.
	(create_addrmap_from_index): Likewise.
	(create_addrmap_from_aranges): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_find_last_source_symtab): Likewise.
	(dw2_map_symtabs_matching_filename): Likewise.
	(dw2_symtab_iter_next): Likewise.
	(dw2_print_stats): Likewise.
	(dw2_expand_all_symtabs): Likewise.
	(dw2_expand_symtabs_with_fullname): Likewise.
	(dw2_expand_marked_cus): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(create_cus_from_debug_names): Likewise.
	(dwarf2_read_debug_names): Likewise.
	(dw2_debug_names_iterator::next): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(set_partial_user): Likewise.
	(dwarf2_build_psymtabs_hard): Likewise.
	(read_comp_units_from_section): Remove arguments, adjust to
	std::vector change.
	(create_all_comp_units): Adjust to std::vector and
	read_comp_units_from_section changes.
	(dwarf2_find_containing_comp_unit): Adjust to std::vector
	change.
	* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
This commit is contained in:
Simon Marchi 2018-04-07 13:53:43 -04:00
parent 12359b5e8f
commit b76e467de3
4 changed files with 113 additions and 148 deletions

View File

@ -1,3 +1,41 @@
2018-04-07 Simon Marchi <simon.marchi@polymtl.ca>
* dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise.
Make an std::vector.
<n_comp_units>: Remove.
* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
to std::vector change.
(dwarf2_per_objfile::get_cutu): Likewise.
(dwarf2_per_objfile::get_cu): Likewise.
(create_cus_from_index): Likewise.
(create_addrmap_from_index): Likewise.
(create_addrmap_from_aranges): Likewise.
(dwarf2_read_index): Likewise.
(dw2_find_last_source_symtab): Likewise.
(dw2_map_symtabs_matching_filename): Likewise.
(dw2_symtab_iter_next): Likewise.
(dw2_print_stats): Likewise.
(dw2_expand_all_symtabs): Likewise.
(dw2_expand_symtabs_with_fullname): Likewise.
(dw2_expand_marked_cus): Likewise.
(dw2_map_symbol_filenames): Likewise.
(create_cus_from_debug_names): Likewise.
(dwarf2_read_debug_names): Likewise.
(dw2_debug_names_iterator::next): Likewise.
(dwarf2_initialize_objfile): Likewise.
(set_partial_user): Likewise.
(dwarf2_build_psymtabs_hard): Likewise.
(read_comp_units_from_section): Remove arguments, adjust to
std::vector change.
(create_all_comp_units): Adjust to std::vector and
read_comp_units_from_section changes.
(dwarf2_find_containing_comp_unit): Adjust to std::vector
change.
* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
(psyms_seen_size): Likewise.
(write_gdbindex): Likewise.
(write_debug_names): Likewise.
2018-04-07 Simon Marchi <simon.marchi@polymtl.ca> 2018-04-07 Simon Marchi <simon.marchi@polymtl.ca>
* dwarf2read.c (create_cus_from_index_list): Replace objfile arg * dwarf2read.c (create_cus_from_index_list): Replace objfile arg

View File

@ -1251,11 +1251,9 @@ private:
static bool static bool
check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile) check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile)
{ {
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)
{ {
const dwarf2_per_cu_data &per_cu = *dwarf2_per_objfile->all_comp_units[i]; if (to_underlying (per_cu->sect_off) >= (static_cast<uint64_t> (1) << 32))
if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
return true; return true;
} }
for (int i = 0; i < dwarf2_per_objfile->n_type_units; ++i) for (int i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
@ -1279,10 +1277,8 @@ static size_t
psyms_seen_size (struct dwarf2_per_objfile *dwarf2_per_objfile) psyms_seen_size (struct dwarf2_per_objfile *dwarf2_per_objfile)
{ {
size_t psyms_count = 0; size_t psyms_count = 0;
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)
{ {
struct dwarf2_per_cu_data *per_cu
= dwarf2_per_objfile->all_comp_units[i];
struct partial_symtab *psymtab = per_cu->v.psymtab; struct partial_symtab *psymtab = per_cu->v.psymtab;
if (psymtab != NULL && psymtab->user == NULL) if (psymtab != NULL && psymtab->user == NULL)
@ -1308,7 +1304,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file)
in the index file). This will later be needed to write the address in the index file). This will later be needed to write the address
table. */ table. */
psym_index_map cu_index_htab; psym_index_map cu_index_htab;
cu_index_htab.reserve (dwarf2_per_objfile->n_comp_units); cu_index_htab.reserve (dwarf2_per_objfile->all_comp_units.size ());
/* The CU list is already sorted, so we don't need to do additional /* The CU list is already sorted, so we don't need to do additional
work here. Also, the debug_types entries do not appear in work here. Also, the debug_types entries do not appear in
@ -1316,7 +1312,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file)
std::unordered_set<partial_symbol *> psyms_seen std::unordered_set<partial_symbol *> psyms_seen
(psyms_seen_size (dwarf2_per_objfile)); (psyms_seen_size (dwarf2_per_objfile));
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) for (int i = 0; i < dwarf2_per_objfile->all_comp_units.size (); ++i)
{ {
struct dwarf2_per_cu_data *per_cu struct dwarf2_per_cu_data *per_cu
= dwarf2_per_objfile->all_comp_units[i]; = dwarf2_per_objfile->all_comp_units[i];
@ -1353,7 +1349,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file)
sig_data.objfile = objfile; sig_data.objfile = objfile;
sig_data.symtab = &symtab; sig_data.symtab = &symtab;
sig_data.cu_index = dwarf2_per_objfile->n_comp_units; sig_data.cu_index = dwarf2_per_objfile->all_comp_units.size ();
htab_traverse_noresize (dwarf2_per_objfile->signatured_types, htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
write_one_signatured_type, &sig_data); write_one_signatured_type, &sig_data);
} }
@ -1428,7 +1424,7 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
dwarf5_byte_order); dwarf5_byte_order);
std::unordered_set<partial_symbol *> std::unordered_set<partial_symbol *>
psyms_seen (psyms_seen_size (dwarf2_per_objfile)); psyms_seen (psyms_seen_size (dwarf2_per_objfile));
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) for (int i = 0; i < dwarf2_per_objfile->all_comp_units.size (); ++i)
{ {
const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i]; const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
partial_symtab *psymtab = per_cu->v.psymtab; partial_symtab *psymtab = per_cu->v.psymtab;
@ -1496,7 +1492,8 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
header.append_uint (2, dwarf5_byte_order, 0); header.append_uint (2, dwarf5_byte_order, 0);
/* comp_unit_count - The number of CUs in the CU list. */ /* comp_unit_count - The number of CUs in the CU list. */
header.append_uint (4, dwarf5_byte_order, dwarf2_per_objfile->n_comp_units); header.append_uint (4, dwarf5_byte_order,
dwarf2_per_objfile->all_comp_units.size ());
/* local_type_unit_count - The number of TUs in the local TU /* local_type_unit_count - The number of TUs in the local TU
list. */ list. */

View File

@ -2137,8 +2137,8 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
if (line_header_hash) if (line_header_hash)
htab_delete (line_header_hash); htab_delete (line_header_hash);
for (int ix = 0; ix < n_comp_units; ++ix) for (dwarf2_per_cu_data *per_cu : all_comp_units)
VEC_free (dwarf2_per_cu_ptr, all_comp_units[ix]->imported_symtabs); VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs);
for (int ix = 0; ix < n_type_units; ++ix) for (int ix = 0; ix < n_type_units; ++ix)
VEC_free (dwarf2_per_cu_ptr, VEC_free (dwarf2_per_cu_ptr,
@ -2920,9 +2920,9 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
dwarf2_per_cu_data * dwarf2_per_cu_data *
dwarf2_per_objfile::get_cutu (int index) 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); gdb_assert (index < this->n_type_units);
return &this->all_type_units[index]->per_cu; return &this->all_type_units[index]->per_cu;
} }
@ -2935,7 +2935,7 @@ dwarf2_per_objfile::get_cutu (int index)
dwarf2_per_cu_data * dwarf2_per_cu_data *
dwarf2_per_objfile::get_cu (int index) 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]; return this->all_comp_units[index];
} }
@ -2981,8 +2981,7 @@ static void
create_cus_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile, create_cus_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
const gdb_byte *cu_list, offset_type n_elements, const gdb_byte *cu_list, offset_type n_elements,
struct dwarf2_section_info *section, struct dwarf2_section_info *section,
int is_dwz, int is_dwz)
int base_offset)
{ {
for (offset_type i = 0; i < n_elements; i += 2) for (offset_type i = 0; i < n_elements; i += 2)
{ {
@ -2993,9 +2992,10 @@ create_cus_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE); ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE);
cu_list += 2 * 8; 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, = create_cu_from_index_list (dwarf2_per_objfile, section, is_dwz,
sect_off, length); sect_off, length);
dwarf2_per_objfile->all_comp_units.push_back (per_cu);
} }
} }
@ -3007,22 +3007,19 @@ create_cus_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
const gdb_byte *cu_list, offset_type cu_list_elements, const gdb_byte *cu_list, offset_type cu_list_elements,
const gdb_byte *dwz_list, offset_type dwz_elements) const gdb_byte *dwz_list, offset_type dwz_elements)
{ {
struct objfile *objfile = dwarf2_per_objfile->objfile; gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
dwarf2_per_objfile->all_comp_units.reserve
dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2; ((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);
create_cus_from_index_list (dwarf2_per_objfile, cu_list, cu_list_elements, 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) if (dwz_elements == 0)
return; return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements, 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. */ /* Create the signatured type hash table from the index. */
@ -3181,7 +3178,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
continue; continue;
} }
if (cu_index >= dwarf2_per_objfile->n_comp_units) if (cu_index >= dwarf2_per_objfile->all_comp_units.size ())
{ {
complaint (&symfile_complaints, complaint (&symfile_complaints,
_(".gdb_index address table has invalid CU number %u"), _(".gdb_index address table has invalid CU number %u"),
@ -3219,9 +3216,8 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
dwarf2_per_cu_data *, dwarf2_per_cu_data *,
gdb::hash_enum<sect_offset>> gdb::hash_enum<sect_offset>>
debug_info_offset_to_per_cu; 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 const auto insertpair
= debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu); = debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu);
if (!insertpair.second) if (!insertpair.second)
@ -3620,7 +3616,7 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
dwarf2_per_objfile->index_table = map; dwarf2_per_objfile->index_table = map;
dwarf2_per_objfile->using_index = 1; dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table = 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; return 1;
} }
@ -3752,8 +3748,7 @@ dw2_find_last_source_symtab (struct objfile *objfile)
{ {
struct dwarf2_per_objfile *dwarf2_per_objfile struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile); = get_dwarf2_per_objfile (objfile);
int index = dwarf2_per_objfile->n_comp_units - 1; dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->all_comp_units.back ();
dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->get_cu (index);
compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu); compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu);
if (cust == NULL) if (cust == NULL)
@ -3830,21 +3825,17 @@ dw2_map_symtabs_matching_filename
/* The rule is CUs specify all the files, including those used by /* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */ 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. */ /* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab) if (per_cu->v.quick->compunit_symtab)
continue; continue;
file_data = dw2_get_file_names (per_cu); quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL) 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_name = file_data->file_names[j]; const char *this_name = file_data->file_names[j];
const char *this_real_name; const char *this_real_name;
@ -3975,7 +3966,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
&& symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
/* Don't crash on bad data. */ /* 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)) + dwarf2_per_objfile->n_type_units))
{ {
complaint (&symfile_complaints, complaint (&symfile_complaints,
@ -4084,7 +4075,8 @@ dw2_print_stats (struct objfile *objfile)
{ {
struct dwarf2_per_objfile *dwarf2_per_objfile struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (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; int count = 0;
for (int i = 0; i < total; ++i) for (int i = 0; i < total; ++i)
@ -4153,7 +4145,7 @@ dw2_expand_all_symtabs (struct objfile *objfile)
{ {
struct dwarf2_per_objfile *dwarf2_per_objfile struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (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); + dwarf2_per_objfile->n_type_units);
for (int i = 0; i < total_units; ++i) for (int i = 0; i < total_units; ++i)
@ -4176,21 +4168,17 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
There can be an order of magnitude (or more) more type units There can be an order of magnitude (or more) more type units
than comp units, and we avoid them if we can. */ 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. */ /* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab) if (per_cu->v.quick->compunit_symtab)
continue; continue;
file_data = dw2_get_file_names (per_cu); quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL) 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_fullname = file_data->file_names[j]; const char *this_fullname = file_data->file_names[j];
@ -5095,7 +5083,7 @@ dw2_expand_marked_cus
} }
/* Don't crash on bad data. */ /* 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)) + dwarf2_per_objfile->n_type_units))
{ {
complaint (&symfile_complaints, complaint (&symfile_complaints,
@ -5135,13 +5123,8 @@ dw_expand_symtabs_matching_file_matcher
/* The rule is CUs specify all the files, including those used by /* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */ 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; QUIT;
per_cu->v.quick->mark = 0; per_cu->v.quick->mark = 0;
@ -5150,7 +5133,7 @@ dw_expand_symtabs_matching_file_matcher
if (per_cu->v.quick->compunit_symtab) if (per_cu->v.quick->compunit_symtab)
continue; continue;
file_data = dw2_get_file_names (per_cu); quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL) if (file_data == NULL)
continue; continue;
@ -5162,7 +5145,7 @@ dw_expand_symtabs_matching_file_matcher
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; const char *this_real_name;
@ -5187,10 +5170,10 @@ dw_expand_symtabs_matching_file_matcher
} }
} }
slot = htab_find_slot (per_cu->v.quick->mark void **slot = htab_find_slot (per_cu->v.quick->mark
? visited_found.get () ? visited_found.get ()
: visited_not_found.get (), : visited_not_found.get (),
file_data, INSERT); file_data, INSERT);
*slot = file_data; *slot = file_data;
} }
} }
@ -5300,10 +5283,8 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
by any TU, so there's no need to scan TUs here. We can by any TU, so there's no need to scan TUs here. We can
ignore file names coming from already-expanded CUs. */ 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) if (per_cu->v.quick->compunit_symtab)
{ {
void **slot = htab_find_slot (visited.get (), void **slot = htab_find_slot (visited.get (),
@ -5314,21 +5295,17 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
} }
} }
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. */ /* We only need to look at symtabs not already expanded. */
if (per_cu->v.quick->compunit_symtab) if (per_cu->v.quick->compunit_symtab)
continue; continue;
file_data = dw2_get_file_names (per_cu); quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL) if (file_data == NULL)
continue; continue;
slot = htab_find_slot (visited.get (), file_data, INSERT); void **slot = htab_find_slot (visited.get (), file_data, INSERT);
if (*slot) if (*slot)
{ {
/* Already visited. */ /* Already visited. */
@ -5576,7 +5553,7 @@ static void
create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile, create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
const mapped_debug_names &map, const mapped_debug_names &map,
dwarf2_section_info &section, dwarf2_section_info &section,
bool is_dwz, int base_offset) bool is_dwz)
{ {
sect_offset sect_off_prev; sect_offset sect_off_prev;
for (uint32_t i = 0; i <= map.cu_count; ++i) for (uint32_t i = 0; i <= map.cu_count; ++i)
@ -5595,9 +5572,10 @@ create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
if (i >= 1) if (i >= 1)
{ {
const ULONGEST length = sect_off_next - sect_off_prev; 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, &section, is_dwz, = create_cu_from_index_list (dwarf2_per_objfile, &section, is_dwz,
sect_off_prev, length); sect_off_prev, length);
dwarf2_per_objfile->all_comp_units.push_back (per_cu);
} }
sect_off_prev = sect_off_next; sect_off_prev = sect_off_next;
} }
@ -5611,25 +5589,19 @@ create_cus_from_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
const mapped_debug_names &map, const mapped_debug_names &map,
const mapped_debug_names &dwz_map) const mapped_debug_names &dwz_map)
{ {
struct objfile *objfile = dwarf2_per_objfile->objfile; gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
dwarf2_per_objfile->all_comp_units.reserve (map.cu_count + dwz_map.cu_count);
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);
create_cus_from_debug_names_list (dwarf2_per_objfile, map, create_cus_from_debug_names_list (dwarf2_per_objfile, map,
dwarf2_per_objfile->info, dwarf2_per_objfile->info,
false /* is_dwz */, false /* is_dwz */);
0 /* base_offset */);
if (dwz_map.cu_count == 0) if (dwz_map.cu_count == 0)
return; return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info, create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
true /* is_dwz */, true /* is_dwz */);
map.cu_count /* base_offset */);
} }
/* Read .debug_names. If everything went ok, initialize the "quick" /* Read .debug_names. If everything went ok, initialize the "quick"
@ -5690,7 +5662,7 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
*dwarf2_per_objfile->debug_names_table = std::move (local_map); *dwarf2_per_objfile->debug_names_table = std::move (local_map);
dwarf2_per_objfile->using_index = 1; dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table = 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; return true;
} }
@ -5930,7 +5902,7 @@ dw2_debug_names_iterator::next ()
{ {
case DW_IDX_compile_unit: case DW_IDX_compile_unit:
/* Don't crash on bad data. */ /* 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, complaint (&symfile_complaints,
_(".debug_names entry has bad CU index %s" _(".debug_names entry has bad CU index %s"
@ -6220,16 +6192,15 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
expanded anyway. */ expanded anyway. */
if ((objfile->flags & OBJF_READNOW)) if ((objfile->flags & OBJF_READNOW))
{ {
int i;
dwarf2_per_objfile->using_index = 1; dwarf2_per_objfile->using_index = 1;
create_all_comp_units (dwarf2_per_objfile); create_all_comp_units (dwarf2_per_objfile);
create_all_type_units (dwarf2_per_objfile); create_all_type_units (dwarf2_per_objfile);
dwarf2_per_objfile->quick_file_names_table = 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 ());
for (i = 0; i < (dwarf2_per_objfile->n_comp_units for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size ()
+ dwarf2_per_objfile->n_type_units); ++i) + dwarf2_per_objfile->n_type_units); ++i)
{ {
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i); dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
@ -8416,18 +8387,14 @@ process_skeletonless_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
static void static void
set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile) set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
{ {
int i; for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{ {
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
struct partial_symtab *pst = per_cu->v.psymtab; struct partial_symtab *pst = per_cu->v.psymtab;
int j;
if (pst == NULL) if (pst == NULL)
continue; 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. */ /* Set the 'user' field only if it is not already set. */
if (pst->dependencies[j]->user == NULL) if (pst->dependencies[j]->user == NULL)
@ -8442,7 +8409,6 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
static void static void
dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile) dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
{ {
int i;
struct objfile *objfile = dwarf2_per_objfile->objfile; struct objfile *objfile = dwarf2_per_objfile->objfile;
if (dwarf_read_debug) if (dwarf_read_debug)
@ -8471,12 +8437,8 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
= make_scoped_restore (&objfile->psymtabs_addrmap, = make_scoped_restore (&objfile->psymtabs_addrmap,
addrmap_create_mutable (&temp_obstack)); addrmap_create_mutable (&temp_obstack));
for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{ process_psymtab_comp_unit (per_cu, 0, language_minimal);
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
process_psymtab_comp_unit (per_cu, 0, language_minimal);
}
/* This has to wait until we read the CUs, we need the list of DWOs. */ /* This has to wait until we read the CUs, we need the list of DWOs. */
process_skeletonless_type_units (dwarf2_per_objfile); process_skeletonless_type_units (dwarf2_per_objfile);
@ -8537,10 +8499,7 @@ static void
read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile, read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
struct dwarf2_section_info *section, struct dwarf2_section_info *section,
struct dwarf2_section_info *abbrev_section, struct dwarf2_section_info *abbrev_section,
unsigned int is_dwz, unsigned int is_dwz)
int *n_allocated,
int *n_comp_units,
struct dwarf2_per_cu_data ***all_comp_units)
{ {
const gdb_byte *info_ptr; const gdb_byte *info_ptr;
struct objfile *objfile = dwarf2_per_objfile->objfile; struct objfile *objfile = dwarf2_per_objfile->objfile;
@ -8588,14 +8547,7 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
this_cu->dwarf2_per_objfile = dwarf2_per_objfile; this_cu->dwarf2_per_objfile = dwarf2_per_objfile;
this_cu->section = section; this_cu->section = section;
if (*n_comp_units == *n_allocated) dwarf2_per_objfile->all_comp_units.push_back (this_cu);
{
*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;
info_ptr = info_ptr + this_cu->length; info_ptr = info_ptr + this_cu->length;
} }
@ -8607,33 +8559,14 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
static void static void
create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile) create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
{ {
int n_allocated; gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
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);
read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->info, read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->info,
&dwarf2_per_objfile->abbrev, 0, &dwarf2_per_objfile->abbrev, 0);
&n_allocated, &n_comp_units, &all_comp_units);
dwz = dwarf2_get_dwz_file (dwarf2_per_objfile); dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
if (dwz != NULL) if (dwz != NULL)
read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev, read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
1, &n_allocated, &n_comp_units, 1);
&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;
} }
/* Process all loaded DIEs for compilation unit CU, starting at /* Process all loaded DIEs for compilation unit CU, starting at
@ -24949,7 +24882,7 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
const sect_offset *cu_off; const sect_offset *cu_off;
low = 0; low = 0;
high = dwarf2_per_objfile->n_comp_units - 1; high = dwarf2_per_objfile->all_comp_units.size () - 1;
while (high > low) while (high > low)
{ {
struct dwarf2_per_cu_data *mid_cu; struct dwarf2_per_cu_data *mid_cu;
@ -24981,7 +24914,7 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
else else
{ {
this_cu = dwarf2_per_objfile->all_comp_units[low]; 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) && sect_off >= this_cu->sect_off + this_cu->length)
error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off)); error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
gdb_assert (sect_off < this_cu->sect_off + this_cu->length); gdb_assert (sect_off < this_cu->sect_off + this_cu->length);

View File

@ -165,10 +165,7 @@ public:
/* Table of all the compilation units. This is used to locate /* Table of all the compilation units. This is used to locate
the target compilation unit of a particular reference. */ the target compilation unit of a particular reference. */
struct dwarf2_per_cu_data **all_comp_units = NULL; std::vector<dwarf2_per_cu_data *> all_comp_units;
/* The number of compilation units in ALL_COMP_UNITS. */
int n_comp_units = 0;
/* The number of .debug_types-related CUs. */ /* The number of .debug_types-related CUs. */
int n_type_units = 0; int n_type_units = 0;