From: Tom Tromey Date: Mon, 17 May 2021 20:16:06 +0000 (-0600) Subject: Change dwarf2_cu marking to use methods X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=347212b81930f9afb9e2885656f897cf3821881c;p=binutils-gdb.git Change dwarf2_cu marking to use methods This changes the dwarf2_cu marking functions to be methods on dwarf2_cu. gdb/ChangeLog 2021-05-17 Tom Tromey * dwarf2/read.c (maybe_queue_comp_unit) (dwarf2_per_objfile::age_comp_units): Update. (dwarf2_add_dependence, dwarf2_mark_helper, dwarf2_mark): Move to dwarf2_cu methods. * dwarf2/cu.h (struct dwarf2_cu) : New methods. : Add "m_" prefix. Now private. : Add "m_" prefix. * dwarf2/cu.c (dwarf2_cu::dwarf2_cu): Update. (dwarf2_mark_helper): New function. (dwarf2_cu::mark, dwarf2_cu::add_dependence): New methods. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9ff54451340..7ca4738be02 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2021-05-17 Tom Tromey + + * dwarf2/read.c (maybe_queue_comp_unit) + (dwarf2_per_objfile::age_comp_units): Update. + (dwarf2_add_dependence, dwarf2_mark_helper, dwarf2_mark): Move to + dwarf2_cu methods. + * dwarf2/cu.h (struct dwarf2_cu) : New methods. + : Add "m_" prefix. Now private. + : Add "m_" prefix. + * dwarf2/cu.c (dwarf2_cu::dwarf2_cu): Update. + (dwarf2_mark_helper): New function. + (dwarf2_cu::mark, dwarf2_cu::add_dependence): New methods. + 2021-05-17 Tom Tromey * dwarf2/read.c (dwarf2_cu::addr_sized_int_type) diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 4f13f4f9677..2451df4f5b6 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -27,7 +27,7 @@ dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile) : per_cu (per_cu), per_objfile (per_objfile), - mark (false), + m_mark (false), has_loclist (false), checked_producer (false), producer_is_gxx_lt_4_6 (false), @@ -87,3 +87,53 @@ dwarf2_cu::addr_type () const addr_type = addr_sized_int_type (addr_type->is_unsigned ()); return addr_type; } + +/* A hashtab traversal function that marks the dependent CUs. */ + +static int +dwarf2_mark_helper (void **slot, void *data) +{ + dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot; + dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data; + dwarf2_cu *cu = per_objfile->get_cu (per_cu); + + /* cu->m_dependencies references may not yet have been ever read if + QUIT aborts reading of the chain. As such dependencies remain + valid it is not much useful to track and undo them during QUIT + cleanups. */ + if (cu != nullptr) + cu->mark (); + return 1; +} + +/* See dwarf2/cu.h. */ + +void +dwarf2_cu::mark () +{ + if (!m_mark) + { + m_mark = true; + if (m_dependencies != nullptr) + htab_traverse (m_dependencies, dwarf2_mark_helper, per_objfile); + } +} + +/* See dwarf2/cu.h. */ + +void +dwarf2_cu::add_dependence (struct dwarf2_per_cu_data *ref_per_cu) +{ + void **slot; + + if (m_dependencies == nullptr) + m_dependencies + = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, + NULL, &comp_unit_obstack, + hashtab_obstack_allocate, + dummy_obstack_deallocate); + + slot = htab_find_slot (m_dependencies, ref_per_cu, INSERT); + if (*slot == nullptr) + *slot = ref_per_cu; +} diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 9fb2d61163a..83a4aac3f08 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -78,6 +78,24 @@ struct dwarf2_cu the integer is unsigned or not. */ struct type *addr_sized_int_type (bool unsigned_p) const; + /* Mark this CU as used. */ + void mark (); + + /* Clear the mark on this CU. */ + void clear_mark () + { + m_mark = false; + } + + /* True if this CU has been marked. */ + bool is_marked () const + { + return m_mark; + } + + /* Add a dependence relationship from this cu to REF_PER_CU. */ + void add_dependence (struct dwarf2_per_cu_data *ref_per_cu); + /* The header of the compilation unit. */ struct comp_unit_head header {}; @@ -95,6 +113,11 @@ private: symbols are being read. */ std::unique_ptr m_builder; + /* A set of pointers to dwarf2_per_cu_data objects for compilation + units referenced by this one. Only set during full symbol processing; + partial symbol tables do not have dependencies. */ + htab_t m_dependencies = nullptr; + public: /* The generic symbol table building routines have separate lists for file scope symbols and all all other scopes (local scopes). So @@ -131,11 +154,6 @@ public: /* Full DIEs if read in. */ struct die_info *dies = nullptr; - /* A set of pointers to dwarf2_per_cu_data objects for compilation - units referenced by this one. Only set during full symbol processing; - partial symbol tables do not have dependencies. */ - htab_t dependencies = nullptr; - /* Header data from the line table, during full symbol processing. */ struct line_header *line_header = nullptr; /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise, @@ -221,7 +239,7 @@ public: gdb::optional str_offsets_base; /* Mark used when releasing cached dies. */ - bool mark : 1; + bool m_mark : 1; /* This CU references .debug_loc. See the symtab->locations_valid field. This test is imperfect as there may exist optimized debug code not using diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 0faa682f738..7a321c14d45 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1458,11 +1458,6 @@ static void process_full_comp_unit (dwarf2_cu *cu, static void process_full_type_unit (dwarf2_cu *cu, enum language pretend_language); -static void dwarf2_add_dependence (struct dwarf2_cu *, - struct dwarf2_per_cu_data *); - -static void dwarf2_mark (struct dwarf2_cu *); - static struct type *get_die_type_at_offset (sect_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile); @@ -8453,7 +8448,7 @@ maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu, /* Mark the dependence relation so that we don't flush PER_CU too early. */ if (dependent_cu != NULL) - dwarf2_add_dependence (dependent_cu, per_cu); + dependent_cu->add_dependence (per_cu); /* If it's already on the queue, we have nothing to do. */ if (per_cu->queued) @@ -24469,7 +24464,7 @@ dwarf2_per_objfile::age_comp_units () /* Start by clearing all marks. */ for (auto pair : m_dwarf2_cus) - pair.second->mark = false; + pair.second->clear_mark (); /* Traverse all CUs, mark them and their dependencies if used recently enough. */ @@ -24479,7 +24474,7 @@ dwarf2_per_objfile::age_comp_units () cu->last_used++; if (cu->last_used <= dwarf_max_cache_age) - dwarf2_mark (cu); + cu->mark (); } /* Delete all CUs still not marked. */ @@ -24487,7 +24482,7 @@ dwarf2_per_objfile::age_comp_units () { dwarf2_cu *cu = it->second; - if (!cu->mark) + if (!cu->is_marked ()) { dwarf_read_debug_printf_v ("deleting old CU %s", sect_offset_str (cu->per_cu->sect_off)); @@ -24688,71 +24683,6 @@ get_die_type (struct die_info *die, struct dwarf2_cu *cu) return get_die_type_at_offset (die->sect_off, cu->per_cu, cu->per_objfile); } -/* Add a dependence relationship from CU to REF_PER_CU. */ - -static void -dwarf2_add_dependence (struct dwarf2_cu *cu, - struct dwarf2_per_cu_data *ref_per_cu) -{ - void **slot; - - if (cu->dependencies == NULL) - cu->dependencies - = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, - NULL, &cu->comp_unit_obstack, - hashtab_obstack_allocate, - dummy_obstack_deallocate); - - slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); - if (*slot == NULL) - *slot = ref_per_cu; -} - -/* Subroutine of dwarf2_mark to pass to htab_traverse. - Set the mark field in every compilation unit in the - cache that we must keep because we are keeping CU. - - DATA is the dwarf2_per_objfile object in which to look up CUs. */ - -static int -dwarf2_mark_helper (void **slot, void *data) -{ - dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot; - dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data; - dwarf2_cu *cu = per_objfile->get_cu (per_cu); - - /* cu->dependencies references may not yet have been ever read if QUIT aborts - reading of the chain. As such dependencies remain valid it is not much - useful to track and undo them during QUIT cleanups. */ - if (cu == nullptr) - return 1; - - if (cu->mark) - return 1; - - cu->mark = true; - - if (cu->dependencies != nullptr) - htab_traverse (cu->dependencies, dwarf2_mark_helper, per_objfile); - - return 1; -} - -/* Set the mark field in CU and in every other compilation unit in the - cache that we must keep because we are keeping CU. */ - -static void -dwarf2_mark (struct dwarf2_cu *cu) -{ - if (cu->mark) - return; - - cu->mark = true; - - if (cu->dependencies != nullptr) - htab_traverse (cu->dependencies, dwarf2_mark_helper, cu->per_objfile); -} - /* Trivial hash function for partial_die_info: the hash value of a DIE is its offset in .debug_info for this objfile. */