* [PATCH 0/5] Random dwarf2read.c improvements
@ 2018-04-01 0:04 Simon Marchi
2018-04-01 0:04 ` [PATCH 4/5] Make dwarf2_per_objfile::all_comp_units an std::vector Simon Marchi
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:04 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
I had these changes in a branch, I though I would post them on their
own, instead of part of a more complex series.
Simon Marchi (5):
Remove some unused variables in dwarf2read.c
Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
Remove some usages of get_dwarf2_per_objfile
Make dwarf2_per_objfile::all_comp_units an std::vector
Make dwarf2_per_objfile::all_type_units an std::vector
gdb/dwarf-index-write.c | 29 ++-
gdb/dwarf2read.c | 459 +++++++++++++++++-------------------------------
gdb/dwarf2read.h | 42 +++--
3 files changed, 203 insertions(+), 327 deletions(-)
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/5] Remove some unused variables in dwarf2read.c
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
2018-04-01 0:04 ` [PATCH 4/5] Make dwarf2_per_objfile::all_comp_units an std::vector Simon Marchi
@ 2018-04-01 0:04 ` Simon Marchi
2018-04-02 16:00 ` Joel Brobecker
2018-04-01 0:04 ` [PATCH 3/5] Remove some usages of get_dwarf2_per_objfile Simon Marchi
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:04 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Most of them are obvious. The ones in dwarf2_record_block_ranges are
less obvious, because it is a bit suspicious to have that many
variables unused. But after inspection, it seems like it dates from
commit 5f46c5a54825 ("Code cleanup: Split dwarf2_ranges_read to a
callback"), where dwarf2_record_block_ranges was made to use
dwarf2_ranges_process, which contains the same functionality.
gdb/ChangeLog:
* dwarf2read.c (create_signatured_type_table_from_debug_names):
Remove unused variables.
(dw2_map_symtabs_matching_filename): Likewise.
(dwarf2_record_block_ranges): Likewise.
(dwarf2_read_addr_index): Likewise.
(follow_die_offset): Likewise.
---
gdb/dwarf2read.c | 23 -----------------------
1 file changed, 23 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index fd544a7f9b98..c2fed7f60109 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3118,9 +3118,7 @@ create_signatured_type_table_from_debug_names
for (uint32_t i = 0; i < map.tu_count; ++i)
{
struct signatured_type *sig_type;
- ULONGEST signature;
void **slot;
- cu_offset type_offset_in_tu;
sect_offset sect_off
= (sect_offset) (extract_unsigned_integer
@@ -3838,7 +3836,6 @@ dw2_map_symtabs_matching_filename
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback)
{
- int i;
const char *name_basename = lbasename (name);
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
@@ -14879,24 +14876,6 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
address range list in the .debug_ranges section. */
unsigned long offset = (DW_UNSND (attr)
+ (need_ranges_base ? cu->ranges_base : 0));
- const gdb_byte *buffer;
-
- /* For some target architectures, but not others, the
- read_address function sign-extends the addresses it returns.
- To recognize base address selection entries, we need a
- mask. */
- unsigned int addr_size = cu->header.addr_size;
- CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
-
- /* The base address, to which the next pair is relative. Note
- that this 'base' is a DWARF concept: most entries in a range
- list are relative, to reduce the number of relocs against the
- debugging information. This is separate from this function's
- 'baseaddr' argument, which GDB uses to relocate debugging
- information from a shared library based on the address at
- which the library was loaded. */
- CORE_ADDR base = cu->base_address;
- int base_known = cu->base_known;
dwarf2_ranges_process (offset, cu,
[&] (CORE_ADDR start, CORE_ADDR end)
@@ -19660,7 +19639,6 @@ dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
unsigned int addr_index)
{
struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
- struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwarf2_cu *cu = per_cu->cu;
ULONGEST addr_base;
int addr_size;
@@ -22876,7 +22854,6 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
struct dwarf2_cu *target_cu, *cu = *ref_cu;
struct dwarf2_per_objfile *dwarf2_per_objfile
= cu->per_cu->dwarf2_per_objfile;
- struct objfile *objfile = dwarf2_per_objfile->objfile;
gdb_assert (cu->per_cu != NULL);
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/5] Make dwarf2_per_objfile::all_comp_units an std::vector
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
@ 2018-04-01 0:04 ` Simon Marchi
2018-04-01 0:04 ` [PATCH 1/5] Remove some unused variables in dwarf2read.c Simon Marchi
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:04 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
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.
---
gdb/dwarf-index-write.c | 21 +++---
gdb/dwarf2read.c | 197 ++++++++++++++++--------------------------------
gdb/dwarf2read.h | 5 +-
3 files changed, 75 insertions(+), 148 deletions(-)
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 058712d9e22d..c49f084d61b3 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1251,11 +1251,9 @@ private:
static bool
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;
}
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)
{
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;
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
table. */
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
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
(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
= 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.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,
write_one_signatured_type, &sig_data);
}
@@ -1428,7 +1424,7 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
dwarf5_byte_order);
std::unordered_set<partial_symbol *>
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];
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);
/* 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
list. */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9b77fcfda179..297b06dc17ec 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2137,8 +2137,8 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
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,
@@ -2920,9 +2920,9 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
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;
}
@@ -2935,7 +2935,7 @@ dwarf2_per_objfile::get_cutu (int index)
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];
}
@@ -2981,8 +2981,7 @@ static void
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)
{
@@ -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);
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);
}
}
@@ -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 *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. */
@@ -3181,7 +3178,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
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"),
@@ -3219,9 +3216,8 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
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)
@@ -3620,7 +3616,7 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
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;
}
@@ -3752,8 +3748,7 @@ dw2_find_last_source_symtab (struct objfile *objfile)
{
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)
@@ -3830,21 +3825,17 @@ dw2_map_symtabs_matching_filename
/* 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;
@@ -3975,7 +3966,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
&& 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,
@@ -4084,7 +4075,8 @@ dw2_print_stats (struct objfile *objfile)
{
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)
@@ -4153,7 +4145,7 @@ dw2_expand_all_symtabs (struct objfile *objfile)
{
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)
@@ -4176,21 +4168,17 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
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];
@@ -5095,7 +5083,7 @@ dw2_expand_marked_cus
}
/* 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,
@@ -5135,13 +5123,8 @@ dw_expand_symtabs_matching_file_matcher
/* 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;
@@ -5150,7 +5133,7 @@ dw_expand_symtabs_matching_file_matcher
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;
@@ -5162,7 +5145,7 @@ dw_expand_symtabs_matching_file_matcher
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;
@@ -5187,10 +5170,10 @@ dw_expand_symtabs_matching_file_matcher
}
}
- 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;
}
}
@@ -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
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 (),
@@ -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. */
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. */
@@ -5576,7 +5553,7 @@ static void
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)
@@ -5595,9 +5572,10 @@ create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
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;
}
@@ -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 &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"
@@ -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->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;
}
@@ -5930,7 +5902,7 @@ dw2_debug_names_iterator::next ()
{
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"
@@ -6220,16 +6192,15 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
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);
@@ -8416,18 +8387,14 @@ process_skeletonless_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
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)
@@ -8442,7 +8409,6 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
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)
@@ -8471,12 +8437,8 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
= 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);
@@ -8537,10 +8499,7 @@ static void
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;
@@ -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->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;
}
@@ -8607,33 +8559,14 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
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
@@ -24950,7 +24883,7 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
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;
@@ -24982,7 +24915,7 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
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);
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 24b5ff47e7eb..d0025324a5a3 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -165,10 +165,7 @@ public:
/* Table of all the compilation units. This is used to locate
the target compilation unit of a particular reference. */
- struct dwarf2_per_cu_data **all_comp_units = NULL;
-
- /* The number of compilation units in ALL_COMP_UNITS. */
- int n_comp_units = 0;
+ std::vector<dwarf2_per_cu_data *> all_comp_units;
/* The number of .debug_types-related CUs. */
int n_type_units = 0;
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/5] Remove some usages of get_dwarf2_per_objfile
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
2018-04-01 0:04 ` [PATCH 4/5] Make dwarf2_per_objfile::all_comp_units an std::vector Simon Marchi
2018-04-01 0:04 ` [PATCH 1/5] Remove some unused variables in dwarf2read.c Simon Marchi
@ 2018-04-01 0:04 ` Simon Marchi
2018-04-01 0:16 ` [PATCH 5/5] Make dwarf2_per_objfile::all_type_units an std::vector Simon Marchi
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:04 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
This patch removes some usages of get_dwarf2_per_objfile, where we can
get hold of the dwarf2_per_objfile object in a simpler way. For
example, it's simpler (and slightly less work) to pass
dwarf2_per_objfile and get the objfile from it than to pass the objfile
and call get_dwarf2_per_objfile.
Ideally, get_dwarf2_per_objfile should only be used in the entry points
of the dwarf2 code, where we receive an objfile.
gdb/ChangeLog:
* dwarf2read.c (create_cus_from_index_list): Replace objfile arg
with dwarf2_per_objfile.
(create_cus_from_index): Likewise.
(create_signatured_type_table_from_index): Likewise.
(dwarf2_read_index): Likewise.
(dwarf2_initialize_objfile): Likewise.
(dwarf2_fetch_die_loc_sect_off): Get dwarf2_per_objfile from
per_cu rather than get_dwarf2_per_objfile.
---
gdb/dwarf2read.c | 60 +++++++++++++++++++++++---------------------------------
1 file changed, 25 insertions(+), 35 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 695799e96f4f..9b77fcfda179 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2978,17 +2978,13 @@ create_cu_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
CUs. */
static void
-create_cus_from_index_list (struct objfile *objfile,
+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)
{
- offset_type i;
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
-
- for (i = 0; i < n_elements; i += 2)
+ for (offset_type i = 0; i < n_elements; i += 2)
{
gdb_static_assert (sizeof (ULONGEST) >= 8);
@@ -3007,42 +3003,38 @@ create_cus_from_index_list (struct objfile *objfile,
the CU objects for this objfile. */
static void
-create_cus_from_index (struct objfile *objfile,
+create_cus_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
const gdb_byte *cu_list, offset_type cu_list_elements,
const gdb_byte *dwz_list, offset_type dwz_elements)
{
- struct dwz_file *dwz;
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
+ 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);
- create_cus_from_index_list (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);
if (dwz_elements == 0)
return;
- dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
- create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1,
- cu_list_elements / 2);
+ 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);
}
/* Create the signatured type hash table from the index. */
static void
-create_signatured_type_table_from_index (struct objfile *objfile,
- struct dwarf2_section_info *section,
- const gdb_byte *bytes,
- offset_type elements)
+create_signatured_type_table_from_index
+ (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ struct dwarf2_section_info *section,
+ const gdb_byte *bytes,
+ offset_type elements)
{
- offset_type i;
- htab_t sig_types_hash;
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
dwarf2_per_objfile->n_type_units
= dwarf2_per_objfile->n_allocated_type_units
@@ -3050,9 +3042,9 @@ create_signatured_type_table_from_index (struct objfile *objfile,
dwarf2_per_objfile->all_type_units =
XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
- sig_types_hash = allocate_signatured_type_table (objfile);
+ htab_t sig_types_hash = allocate_signatured_type_table (objfile);
- for (i = 0; i < elements; i += 3)
+ for (offset_type i = 0; i < elements; i += 3)
{
struct signatured_type *sig_type;
ULONGEST signature;
@@ -3559,14 +3551,13 @@ to use the section anyway."),
elements of all the CUs and return 1. Otherwise, return 0. */
static int
-dwarf2_read_index (struct objfile *objfile)
+dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
struct mapped_index local_map, *map;
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 dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
if (!read_index_from_section (objfile, objfile_name (objfile),
use_deprecated_index_sections,
@@ -3601,8 +3592,8 @@ dwarf2_read_index (struct objfile *objfile)
}
}
- create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list,
- dwz_list_elements);
+ create_cus_from_index (dwarf2_per_objfile, cu_list, cu_list_elements,
+ dwz_list, dwz_list_elements);
if (types_list_elements)
{
@@ -3616,8 +3607,8 @@ dwarf2_read_index (struct objfile *objfile)
section = VEC_index (dwarf2_section_info_def,
dwarf2_per_objfile->types, 0);
- create_signatured_type_table_from_index (objfile, section, types_list,
- types_list_elements);
+ create_signatured_type_table_from_index (dwarf2_per_objfile, section,
+ types_list, types_list_elements);
}
create_addrmap_from_index (dwarf2_per_objfile, &local_map);
@@ -6259,7 +6250,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
return true;
}
- if (dwarf2_read_index (objfile))
+ if (dwarf2_read_index (dwarf2_per_objfile))
{
*index_kind = dw_index_kind::GDB_INDEX;
return true;
@@ -22927,9 +22918,8 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
struct die_info *die;
struct attribute *attr;
struct dwarf2_locexpr_baton retval;
- struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
+ struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
if (per_cu->cu == NULL)
load_cu (per_cu);
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/5] Make dwarf2_per_objfile::all_type_units an std::vector
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
` (2 preceding siblings ...)
2018-04-01 0:04 ` [PATCH 3/5] Remove some usages of get_dwarf2_per_objfile Simon Marchi
@ 2018-04-01 0:16 ` Simon Marchi
2018-04-01 0:16 ` [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile Simon Marchi
2018-04-07 18:01 ` [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
5 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:16 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Make all_type_units an std::vector, remove
n_type_units/n_allocated_type_units and some manual memory management.
gdb/ChangeLog:
* dwarf2read.h (struct dwarf2_per_objfile) <n_type_units>:
Remove.
<n_allocated_type_units>: Remove.
<all_type_units>: Change to std::vector.
* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
to std::vector change.
(dwarf2_per_objfile::get_cutu): Likewise.
(dwarf2_per_objfile::get_tu): Likewise.
(create_signatured_type_table_from_index): Likewise.
(create_signatured_type_table_from_debug_names): Likewise.
(dw2_symtab_iter_next): Likewise.
(dw2_print_stats): Likewise.
(dw2_expand_all_symtabs): Likewise.
(dw2_expand_marked_cus): Likewise.
(dw2_debug_names_iterator::next): Likewise.
(dwarf2_initialize_objfile): Likewise.
(add_signatured_type_cu_to_table): Likewise.
(create_all_type_units): Likewise.
(add_type_unit): Likewise.
(struct tu_abbrev_offset): Add constructor.
(build_type_psymtabs_1): Adjust to std::vector change.
(print_tu_stats): Likewise.
* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
(write_debug_names): Likewise.
---
gdb/dwarf-index-write.c | 8 +--
gdb/dwarf2read.c | 129 +++++++++++++++++++-----------------------------
gdb/dwarf2read.h | 12 +----
3 files changed, 57 insertions(+), 92 deletions(-)
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index c49f084d61b3..4c596c2e3eb0 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1256,10 +1256,9 @@ check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile)
if (to_underlying (per_cu->sect_off) >= (static_cast<uint64_t> (1) << 32))
return true;
}
- for (int i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
+ for (const signatured_type *sigtype : dwarf2_per_objfile->all_type_units)
{
- const signatured_type &sigtype = *dwarf2_per_objfile->all_type_units[i];
- const dwarf2_per_cu_data &per_cu = sigtype.per_cu;
+ const dwarf2_per_cu_data &per_cu = sigtype->per_cu;
if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
return true;
@@ -1497,7 +1496,8 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
/* local_type_unit_count - The number of TUs in the local TU
list. */
- header.append_uint (4, dwarf5_byte_order, dwarf2_per_objfile->n_type_units);
+ header.append_uint (4, dwarf5_byte_order,
+ dwarf2_per_objfile->all_type_units.size ());
/* foreign_type_unit_count - The number of TUs in the foreign TU
list. */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 297b06dc17ec..504922efd955 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2140,10 +2140,8 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
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,
- all_type_units[ix]->per_cu.imported_symtabs);
- xfree (all_type_units);
+ for (signatured_type *sig_type : all_type_units)
+ VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs);
VEC_free (dwarf2_section_info_def, types);
@@ -2923,7 +2921,7 @@ dwarf2_per_objfile::get_cutu (int index)
if (index >= this->all_comp_units.size ())
{
index -= this->all_comp_units.size ();
- gdb_assert (index < this->n_type_units);
+ gdb_assert (index < this->all_type_units.size ());
return &this->all_type_units[index]->per_cu;
}
@@ -2945,7 +2943,7 @@ dwarf2_per_objfile::get_cu (int index)
signatured_type *
dwarf2_per_objfile::get_tu (int index)
{
- gdb_assert (index >= 0 && index < this->n_type_units);
+ gdb_assert (index >= 0 && index < this->all_type_units.size ());
return this->all_type_units[index];
}
@@ -3033,11 +3031,8 @@ create_signatured_type_table_from_index
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = elements / 3;
- dwarf2_per_objfile->all_type_units =
- XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (elements / 3);
htab_t sig_types_hash = allocate_signatured_type_table (objfile);
@@ -3072,7 +3067,7 @@ create_signatured_type_table_from_index
slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
*slot = sig_type;
- dwarf2_per_objfile->all_type_units[i / 3] = sig_type;
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
}
dwarf2_per_objfile->signatured_types = sig_types_hash;
@@ -3092,11 +3087,8 @@ create_signatured_type_table_from_debug_names
dwarf2_read_section (objfile, section);
dwarf2_read_section (objfile, abbrev_section);
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = map.tu_count;
- dwarf2_per_objfile->all_type_units
- = XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (map.tu_count);
htab_t sig_types_hash = allocate_signatured_type_table (objfile);
@@ -3132,7 +3124,7 @@ create_signatured_type_table_from_debug_names
slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
*slot = sig_type;
- dwarf2_per_objfile->all_type_units[i] = sig_type;
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
}
dwarf2_per_objfile->signatured_types = sig_types_hash;
@@ -3967,7 +3959,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
/* Don't crash on bad data. */
if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units))
+ + dwarf2_per_objfile->all_type_units.size ()))
{
complaint (&symfile_complaints,
_(".gdb_index entry has bad CU index"
@@ -4076,7 +4068,7 @@ dw2_print_stats (struct objfile *objfile)
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
int total = (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units);
+ + dwarf2_per_objfile->all_type_units.size ());
int count = 0;
for (int i = 0; i < total; ++i)
@@ -4146,7 +4138,7 @@ dw2_expand_all_symtabs (struct objfile *objfile)
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
int total_units = (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units);
+ + dwarf2_per_objfile->all_type_units.size ());
for (int i = 0; i < total_units; ++i)
{
@@ -5084,7 +5076,7 @@ dw2_expand_marked_cus
/* Don't crash on bad data. */
if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units))
+ + dwarf2_per_objfile->all_type_units.size ()))
{
complaint (&symfile_complaints,
_(".gdb_index entry has bad CU index"
@@ -5915,7 +5907,7 @@ dw2_debug_names_iterator::next ()
break;
case DW_IDX_type_unit:
/* Don't crash on bad data. */
- if (ull >= dwarf2_per_objfile->n_type_units)
+ if (ull >= dwarf2_per_objfile->all_type_units.size ())
{
complaint (&symfile_complaints,
_(".debug_names entry has bad TU index %s"
@@ -6200,7 +6192,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
(dwarf2_per_objfile->all_comp_units.size ());
for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units); ++i)
+ + dwarf2_per_objfile->all_type_units.size ()); ++i)
{
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
@@ -6609,10 +6601,10 @@ static int
add_signatured_type_cu_to_table (void **slot, void *datum)
{
struct signatured_type *sigt = (struct signatured_type *) *slot;
- struct signatured_type ***datap = (struct signatured_type ***) datum;
+ std::vector<signatured_type *> *all_type_units
+ = (std::vector<signatured_type *> *) datum;
- **datap = sigt;
- ++*datap;
+ all_type_units->push_back (sigt);
return 1;
}
@@ -6801,7 +6793,6 @@ static int
create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
htab_t types_htab = NULL;
- struct signatured_type **iter;
create_debug_type_hash_table (dwarf2_per_objfile, NULL,
&dwarf2_per_objfile->info, types_htab,
@@ -6816,15 +6807,11 @@ create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
dwarf2_per_objfile->signatured_types = types_htab;
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = htab_elements (types_htab);
- dwarf2_per_objfile->all_type_units =
- XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
- iter = &dwarf2_per_objfile->all_type_units[0];
- htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
- gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
- == dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (htab_elements (types_htab));
+
+ htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table,
+ &dwarf2_per_objfile->all_type_units);
return 1;
}
@@ -6838,27 +6825,15 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig,
void **slot)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- int n_type_units = dwarf2_per_objfile->n_type_units;
- struct signatured_type *sig_type;
- gdb_assert (n_type_units <= dwarf2_per_objfile->n_allocated_type_units);
- ++n_type_units;
- if (n_type_units > dwarf2_per_objfile->n_allocated_type_units)
- {
- if (dwarf2_per_objfile->n_allocated_type_units == 0)
- dwarf2_per_objfile->n_allocated_type_units = 1;
- dwarf2_per_objfile->n_allocated_type_units *= 2;
- dwarf2_per_objfile->all_type_units
- = XRESIZEVEC (struct signatured_type *,
- dwarf2_per_objfile->all_type_units,
- dwarf2_per_objfile->n_allocated_type_units);
- ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs;
- }
- dwarf2_per_objfile->n_type_units = n_type_units;
+ if (dwarf2_per_objfile->all_type_units.size ()
+ == dwarf2_per_objfile->all_type_units.capacity ())
+ ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs;
- sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
- struct signatured_type);
- dwarf2_per_objfile->all_type_units[n_type_units - 1] = sig_type;
+ signatured_type *sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct signatured_type);
+
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
sig_type->signature = sig;
sig_type->per_cu.is_debug_types = 1;
if (dwarf2_per_objfile->using_index)
@@ -8133,7 +8108,11 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
struct tu_abbrev_offset
{
- struct signatured_type *sig_type;
+ tu_abbrev_offset (signatured_type *sig_type_, sect_offset abbrev_offset_)
+ : sig_type (sig_type_), abbrev_offset (abbrev_offset_)
+ {}
+
+ signatured_type *sig_type;
sect_offset abbrev_offset;
};
@@ -8170,12 +8149,11 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
abbrev_table_up abbrev_table;
sect_offset abbrev_offset;
- int i;
/* It's up to the caller to not call us multiple times. */
gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL);
- if (dwarf2_per_objfile->n_type_units == 0)
+ if (dwarf2_per_objfile->all_type_units.empty ())
return;
/* TUs typically share abbrev tables, and there can be way more TUs than
@@ -8202,32 +8180,27 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
/* Sort in a separate table to maintain the order of all_type_units
for .gdb_index: TU indices directly index all_type_units. */
- std::vector<struct tu_abbrev_offset> sorted_by_abbrev
- (dwarf2_per_objfile->n_type_units);
- for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
- {
- struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
+ std::vector<tu_abbrev_offset> sorted_by_abbrev;
+ sorted_by_abbrev.reserve (dwarf2_per_objfile->all_type_units.size ());
+
+ for (signatured_type *sig_type : dwarf2_per_objfile->all_type_units)
+ sorted_by_abbrev.emplace_back
+ (sig_type, read_abbrev_offset (dwarf2_per_objfile,
+ sig_type->per_cu.section,
+ sig_type->per_cu.sect_off));
- sorted_by_abbrev[i].sig_type = sig_type;
- sorted_by_abbrev[i].abbrev_offset =
- read_abbrev_offset (dwarf2_per_objfile,
- sig_type->per_cu.section,
- sig_type->per_cu.sect_off);
- }
std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end (),
sort_tu_by_abbrev_offset);
abbrev_offset = (sect_offset) ~(unsigned) 0;
- for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
+ for (const tu_abbrev_offset &tu : sorted_by_abbrev)
{
- const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i];
-
/* Switch to the next abbrev table if necessary. */
if (abbrev_table == NULL
- || tu->abbrev_offset != abbrev_offset)
+ || tu.abbrev_offset != abbrev_offset)
{
- abbrev_offset = tu->abbrev_offset;
+ abbrev_offset = tu.abbrev_offset;
abbrev_table =
abbrev_table_read_table (dwarf2_per_objfile,
&dwarf2_per_objfile->abbrev,
@@ -8235,7 +8208,7 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
++tu_stats->nr_uniq_abbrev_tables;
}
- init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table.get (),
+ init_cutu_and_read_dies (&tu.sig_type->per_cu, abbrev_table.get (),
0, 0, build_type_psymtabs_reader, NULL);
}
}
@@ -8248,8 +8221,8 @@ print_tu_stats (struct dwarf2_per_objfile *dwarf2_per_objfile)
struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
fprintf_unfiltered (gdb_stdlog, "Type unit statistics:\n");
- fprintf_unfiltered (gdb_stdlog, " %d TUs\n",
- dwarf2_per_objfile->n_type_units);
+ fprintf_unfiltered (gdb_stdlog, " %zu TUs\n",
+ dwarf2_per_objfile->all_type_units.size ());
fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n",
tu_stats->nr_uniq_abbrev_tables);
fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n",
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index d0025324a5a3..8e6c41dc09ef 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -167,16 +167,8 @@ public:
the target compilation unit of a particular reference. */
std::vector<dwarf2_per_cu_data *> all_comp_units;
- /* The number of .debug_types-related CUs. */
- int n_type_units = 0;
-
- /* The number of elements allocated in all_type_units.
- If there are skeleton-less TUs, we add them to all_type_units lazily. */
- int n_allocated_type_units = 0;
-
- /* The .debug_types-related CUs (TUs).
- This is stored in malloc space because we may realloc it. */
- struct signatured_type **all_type_units = NULL;
+ /* The .debug_types-related CUs (TUs). */
+ std::vector<signatured_type *> all_type_units;
/* Table of struct type_unit_group objects.
The hash key is the DW_AT_stmt_list value. */
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
` (3 preceding siblings ...)
2018-04-01 0:16 ` [PATCH 5/5] Make dwarf2_per_objfile::all_type_units an std::vector Simon Marchi
@ 2018-04-01 0:16 ` Simon Marchi
2018-04-02 16:17 ` Joel Brobecker
2018-04-07 18:01 ` [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
5 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2018-04-01 0:16 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Those two functions look like good candidates to become methods of
dwarf2_per_objfile. I did that, and added get_tu as well. When
replacing usages of dw2_get_cutu, I changed some instances to get_cutu
and others to get_cu, when appropriate (when we know we want a CU and
not a TU).
gdb/ChangeLog:
* dwarf2read.h (struct signatured_type): Forward declare.
(struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
New methods.
* dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
(dw2_get_cutu): ...this.
(dwarf2_per_objfile::get_cu): Rename from...
(dw2_get_cu): ...this.
(dwarf2_per_objfile::get_tu): New.
(create_addrmap_from_index): Adjust.
(create_addrmap_from_aranges): Adjust.
(dw2_find_last_source_symtab): Adjust.
(dw2_map_symtabs_matching_filename): Adjust.
(dw2_symtab_iter_next): Adjust.
(dw2_print_stats): Adjust.
(dw2_expand_all_symtabs): Adjust.
(dw2_expand_symtabs_with_fullname): Adjust.
(dw2_expand_marked_cus): Adjust.
(dw_expand_symtabs_matching_file_matcher): Adjust.
(dw2_map_symbol_filenames): Adjust.
(dw2_debug_names_iterator::next): Adjust.
(dwarf2_initialize_objfile): Adjust.
(set_partial_user): Adjust.
(dwarf2_build_psymtabs_hard): Adjust.
---
gdb/dwarf2read.c | 86 +++++++++++++++++++++++++-------------------------------
gdb/dwarf2read.h | 25 ++++++++++++++++
2 files changed, 64 insertions(+), 47 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index c2fed7f60109..695799e96f4f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2915,43 +2915,39 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
return per_cu->v.quick->compunit_symtab;
}
-/* Return the CU/TU given its index.
+/* See declaration. */
- This is intended for loops like:
+dwarf2_per_cu_data *
+dwarf2_per_objfile::get_cutu (int index)
+{
+ if (index >= this->n_comp_units)
+ {
+ index -= this->n_comp_units;
+ gdb_assert (index < this->n_type_units);
+ return &this->all_type_units[index]->per_cu;
+ }
- for (i = 0; i < (dwarf2_per_objfile->n_comp_units
- + dwarf2_per_objfile->n_type_units); ++i)
- {
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
+ return this->all_comp_units[index];
+}
- ...;
- }
-*/
+/* See declaration. */
-static struct dwarf2_per_cu_data *
-dw2_get_cutu (struct dwarf2_per_objfile *dwarf2_per_objfile,
- int index)
+dwarf2_per_cu_data *
+dwarf2_per_objfile::get_cu (int index)
{
- if (index >= dwarf2_per_objfile->n_comp_units)
- {
- index -= dwarf2_per_objfile->n_comp_units;
- gdb_assert (index < dwarf2_per_objfile->n_type_units);
- return &dwarf2_per_objfile->all_type_units[index]->per_cu;
- }
+ gdb_assert (index >= 0 && index < this->n_comp_units);
- return dwarf2_per_objfile->all_comp_units[index];
+ return this->all_comp_units[index];
}
-/* Return the CU given its index.
- This differs from dw2_get_cutu in that it's for when you know INDEX
- refers to a CU. */
+/* See declaration. */
-static struct dwarf2_per_cu_data *
-dw2_get_cu (struct dwarf2_per_objfile *dwarf2_per_objfile, int index)
+signatured_type *
+dwarf2_per_objfile::get_tu (int index)
{
- gdb_assert (index >= 0 && index < dwarf2_per_objfile->n_comp_units);
+ gdb_assert (index >= 0 && index < this->n_type_units);
- return dwarf2_per_objfile->all_comp_units[index];
+ return this->all_type_units[index];
}
/* Return a new dwarf2_per_cu_data allocated on OBJFILE's
@@ -3204,7 +3200,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
addrmap_set_empty (mutable_map, lo, hi - 1,
- dw2_get_cutu (dwarf2_per_objfile, cu_index));
+ dwarf2_per_objfile->get_cu (cu_index));
}
objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
@@ -3233,7 +3229,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
debug_info_offset_to_per_cu;
for (int cui = 0; cui < dwarf2_per_objfile->n_comp_units; ++cui)
{
- dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, cui);
+ 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)
@@ -3766,7 +3762,7 @@ dw2_find_last_source_symtab (struct objfile *objfile)
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 = dw2_get_cutu (dwarf2_per_objfile, index);
+ dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->get_cu (index);
compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu);
if (cust == NULL)
@@ -3846,7 +3842,7 @@ dw2_map_symtabs_matching_filename
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
int j;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, i);
+ 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. */
@@ -3974,7 +3970,6 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
offset_type cu_index_and_attrs =
MAYBE_SWAP (iter->vec[iter->next + 1]);
offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
- struct dwarf2_per_cu_data *per_cu;
int want_static = iter->block_index != GLOBAL_BLOCK;
/* This value is only valid for index versions >= 7. */
int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
@@ -3999,7 +3994,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
continue;
}
- per_cu = dw2_get_cutu (dwarf2_per_objfile, cu_index);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (cu_index);
/* Skip if already read in. */
if (per_cu->v.quick->compunit_symtab)
@@ -4103,7 +4098,7 @@ dw2_print_stats (struct objfile *objfile)
for (int i = 0; i < total; ++i)
{
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
if (!per_cu->v.quick->compunit_symtab)
++count;
@@ -4172,8 +4167,7 @@ dw2_expand_all_symtabs (struct objfile *objfile)
for (int i = 0; i < total_units; ++i)
{
- struct dwarf2_per_cu_data *per_cu
- = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
dw2_instantiate_symtab (per_cu);
}
@@ -4194,7 +4188,7 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
int j;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ 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. */
@@ -5064,7 +5058,6 @@ dw2_expand_marked_cus
vec_len = MAYBE_SWAP (vec[0]);
for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
{
- struct dwarf2_per_cu_data *per_cu;
offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]);
/* This value is only valid for index versions >= 7. */
int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
@@ -5121,7 +5114,7 @@ dw2_expand_marked_cus
continue;
}
- per_cu = dw2_get_cutu (dwarf2_per_objfile, cu_index);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (cu_index);
dw2_expand_symtabs_matching_one (per_cu, file_matcher,
expansion_notify);
}
@@ -5154,7 +5147,7 @@ dw_expand_symtabs_matching_file_matcher
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
int j;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
struct quick_file_names *file_data;
void **slot;
@@ -5318,7 +5311,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
- dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
if (per_cu->v.quick->compunit_symtab)
{
@@ -5332,7 +5325,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
- dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
struct quick_file_names *file_data;
void **slot;
@@ -5955,7 +5948,7 @@ dw2_debug_names_iterator::next ()
objfile_name (dwarf2_per_objfile->objfile));
continue;
}
- per_cu = dw2_get_cutu (dwarf2_per_objfile, ull);
+ per_cu = dwarf2_per_objfile->get_cutu (ull);
break;
case DW_IDX_type_unit:
/* Don't crash on bad data. */
@@ -5968,8 +5961,7 @@ dw2_debug_names_iterator::next ()
objfile_name (dwarf2_per_objfile->objfile));
continue;
}
- per_cu = dw2_get_cutu (dwarf2_per_objfile,
- dwarf2_per_objfile->n_comp_units + ull);
+ per_cu = &dwarf2_per_objfile->get_tu (ull)->per_cu;
break;
case DW_IDX_GNU_internal:
if (!m_map.augmentation_is_gdb)
@@ -6248,7 +6240,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
for (i = 0; i < (dwarf2_per_objfile->n_comp_units
+ dwarf2_per_objfile->n_type_units); ++i)
{
- dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
struct dwarf2_per_cu_quick_data);
@@ -8437,7 +8429,7 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
struct partial_symtab *pst = per_cu->v.psymtab;
int j;
@@ -8490,7 +8482,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
{
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cu (i);
process_psymtab_comp_unit (per_cu, 0, language_minimal);
}
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 46a10520ec2a..24b5ff47e7eb 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -89,6 +89,7 @@ struct tu_stats
struct dwarf2_debug_sections;
struct mapped_index;
struct mapped_debug_names;
+struct signatured_type;
/* Collection of data recorded per objfile.
This hangs off of dwarf2_objfile_data_key. */
@@ -105,6 +106,30 @@ struct dwarf2_per_objfile : public allocate_on_obstack
DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
+ /* Return the CU/TU given its index.
+
+ This is intended for loops like:
+
+ for (i = 0; i < (dwarf2_per_objfile->n_comp_units
+ + dwarf2_per_objfile->n_type_units); ++i)
+ {
+ dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
+
+ ...;
+ }
+ */
+ dwarf2_per_cu_data *get_cutu (int index);
+
+ /* Return the CU given its index.
+ This differs from get_cutu in that it's for when you know INDEX refers to a
+ CU. */
+ dwarf2_per_cu_data *get_cu (int index);
+
+ /* Return the TU given its index.
+ This differs from get_cutu in that it's for when you know INDEX refers to a
+ TU. */
+ signatured_type *get_tu (int index);
+
/* Free all cached compilation units. */
void free_cached_comp_units ();
private:
--
2.16.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/5] Remove some unused variables in dwarf2read.c
2018-04-01 0:04 ` [PATCH 1/5] Remove some unused variables in dwarf2read.c Simon Marchi
@ 2018-04-02 16:00 ` Joel Brobecker
0 siblings, 0 replies; 10+ messages in thread
From: Joel Brobecker @ 2018-04-02 16:00 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
Hi Simon,
> gdb/ChangeLog:
>
> * dwarf2read.c (create_signatured_type_table_from_debug_names):
> Remove unused variables.
> (dw2_map_symtabs_matching_filename): Likewise.
> (dwarf2_record_block_ranges): Likewise.
> (dwarf2_read_addr_index): Likewise.
> (follow_die_offset): Likewise.
FWIW, I took a look and this looks good to me.
--
Joel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
2018-04-01 0:16 ` [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile Simon Marchi
@ 2018-04-02 16:17 ` Joel Brobecker
2018-04-02 17:21 ` Simon Marchi
0 siblings, 1 reply; 10+ messages in thread
From: Joel Brobecker @ 2018-04-02 16:17 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
Hi Simon,
On Sat, Mar 31, 2018 at 08:04:41PM -0400, Simon Marchi wrote:
> Those two functions look like good candidates to become methods of
> dwarf2_per_objfile. I did that, and added get_tu as well. When
> replacing usages of dw2_get_cutu, I changed some instances to get_cutu
> and others to get_cu, when appropriate (when we know we want a CU and
> not a TU).
>
> gdb/ChangeLog:
>
> * dwarf2read.h (struct signatured_type): Forward declare.
> (struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
> New methods.
> * dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
> (dw2_get_cutu): ...this.
> (dwarf2_per_objfile::get_cu): Rename from...
> (dw2_get_cu): ...this.
> (dwarf2_per_objfile::get_tu): New.
> (create_addrmap_from_index): Adjust.
> (create_addrmap_from_aranges): Adjust.
> (dw2_find_last_source_symtab): Adjust.
> (dw2_map_symtabs_matching_filename): Adjust.
> (dw2_symtab_iter_next): Adjust.
> (dw2_print_stats): Adjust.
> (dw2_expand_all_symtabs): Adjust.
> (dw2_expand_symtabs_with_fullname): Adjust.
> (dw2_expand_marked_cus): Adjust.
> (dw_expand_symtabs_matching_file_matcher): Adjust.
> (dw2_map_symbol_filenames): Adjust.
> (dw2_debug_names_iterator::next): Adjust.
> (dwarf2_initialize_objfile): Adjust.
> (set_partial_user): Adjust.
> (dwarf2_build_psymtabs_hard): Adjust.
Got time to look at this one to (and discover the dw2_get_cutu function).
The patch looks good to me. Not only that, I see that you changed some
of the "get_cutu" calls to either ::get_cu or ::get_tu when there was
enough context to know which one it was that we were handling. This is
a very nice enhancement, in my opinion.
That's all the time I have to review this patch series for now.
I may or may not be able to review the rest, so please anyone feel
free to take a look.
--
Joel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
2018-04-02 16:17 ` Joel Brobecker
@ 2018-04-02 17:21 ` Simon Marchi
0 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-02 17:21 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On 2018-04-02 12:17, Joel Brobecker wrote:
> Hi Simon,
>
> On Sat, Mar 31, 2018 at 08:04:41PM -0400, Simon Marchi wrote:
>> Those two functions look like good candidates to become methods of
>> dwarf2_per_objfile. I did that, and added get_tu as well. When
>> replacing usages of dw2_get_cutu, I changed some instances to get_cutu
>> and others to get_cu, when appropriate (when we know we want a CU and
>> not a TU).
>>
>> gdb/ChangeLog:
>>
>> * dwarf2read.h (struct signatured_type): Forward declare.
>> (struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
>> New methods.
>> * dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
>> (dw2_get_cutu): ...this.
>> (dwarf2_per_objfile::get_cu): Rename from...
>> (dw2_get_cu): ...this.
>> (dwarf2_per_objfile::get_tu): New.
>> (create_addrmap_from_index): Adjust.
>> (create_addrmap_from_aranges): Adjust.
>> (dw2_find_last_source_symtab): Adjust.
>> (dw2_map_symtabs_matching_filename): Adjust.
>> (dw2_symtab_iter_next): Adjust.
>> (dw2_print_stats): Adjust.
>> (dw2_expand_all_symtabs): Adjust.
>> (dw2_expand_symtabs_with_fullname): Adjust.
>> (dw2_expand_marked_cus): Adjust.
>> (dw_expand_symtabs_matching_file_matcher): Adjust.
>> (dw2_map_symbol_filenames): Adjust.
>> (dw2_debug_names_iterator::next): Adjust.
>> (dwarf2_initialize_objfile): Adjust.
>> (set_partial_user): Adjust.
>> (dwarf2_build_psymtabs_hard): Adjust.
>
> Got time to look at this one to (and discover the dw2_get_cutu
> function).
> The patch looks good to me. Not only that, I see that you changed some
> of the "get_cutu" calls to either ::get_cu or ::get_tu when there was
> enough context to know which one it was that we were handling. This is
> a very nice enhancement, in my opinion.
>
> That's all the time I have to review this patch series for now.
> I may or may not be able to review the rest, so please anyone feel
> free to take a look.
Thanks, your input is appreciated!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] Random dwarf2read.c improvements
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
` (4 preceding siblings ...)
2018-04-01 0:16 ` [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile Simon Marchi
@ 2018-04-07 18:01 ` Simon Marchi
5 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2018-04-07 18:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
On 2018-03-31 08:04 PM, Simon Marchi wrote:
> I had these changes in a branch, I though I would post them on their
> own, instead of part of a more complex series.
>
> Simon Marchi (5):
> Remove some unused variables in dwarf2read.c
> Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
> Remove some usages of get_dwarf2_per_objfile
> Make dwarf2_per_objfile::all_comp_units an std::vector
> Make dwarf2_per_objfile::all_type_units an std::vector
>
> gdb/dwarf-index-write.c | 29 ++-
> gdb/dwarf2read.c | 459 +++++++++++++++++-------------------------------
> gdb/dwarf2read.h | 42 +++--
> 3 files changed, 203 insertions(+), 327 deletions(-)
>
I pushed these patches it.
Simon
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-04-07 18:01 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-01 0:04 [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
2018-04-01 0:04 ` [PATCH 4/5] Make dwarf2_per_objfile::all_comp_units an std::vector Simon Marchi
2018-04-01 0:04 ` [PATCH 1/5] Remove some unused variables in dwarf2read.c Simon Marchi
2018-04-02 16:00 ` Joel Brobecker
2018-04-01 0:04 ` [PATCH 3/5] Remove some usages of get_dwarf2_per_objfile Simon Marchi
2018-04-01 0:16 ` [PATCH 5/5] Make dwarf2_per_objfile::all_type_units an std::vector Simon Marchi
2018-04-01 0:16 ` [PATCH 2/5] Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile Simon Marchi
2018-04-02 16:17 ` Joel Brobecker
2018-04-02 17:21 ` Simon Marchi
2018-04-07 18:01 ` [PATCH 0/5] Random dwarf2read.c improvements Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).