diff options
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/attribute.c | 16 | ||||
-rw-r--r-- | gdb/dwarf2/attribute.h | 19 | ||||
-rw-r--r-- | gdb/dwarf2/call-site.h | 2 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index-entry.c | 4 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index-worker.c | 2 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index-worker.h | 30 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index.c | 7 | ||||
-rw-r--r-- | gdb/dwarf2/cu.h | 13 | ||||
-rw-r--r-- | gdb/dwarf2/dwz.c | 60 | ||||
-rw-r--r-- | gdb/dwarf2/frame-tailcall.c | 4 | ||||
-rw-r--r-- | gdb/dwarf2/frame.c | 4 | ||||
-rw-r--r-- | gdb/dwarf2/frame.h | 61 | ||||
-rw-r--r-- | gdb/dwarf2/index-cache.c | 4 | ||||
-rw-r--r-- | gdb/dwarf2/index-write.c | 4 | ||||
-rw-r--r-- | gdb/dwarf2/loc.c | 6 | ||||
-rw-r--r-- | gdb/dwarf2/loc.h | 70 | ||||
-rw-r--r-- | gdb/dwarf2/public.h | 25 | ||||
-rw-r--r-- | gdb/dwarf2/read-debug-names.c | 26 | ||||
-rw-r--r-- | gdb/dwarf2/read-gdb-index.c | 9 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 500 | ||||
-rw-r--r-- | gdb/dwarf2/read.h | 19 | ||||
-rw-r--r-- | gdb/dwarf2/section.h | 2 |
22 files changed, 502 insertions, 385 deletions
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 8ff0353..d2b5364 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -216,6 +216,22 @@ attribute::signed_constant () const /* See attribute.h. */ +std::optional<LONGEST> +attribute::confused_constant () const +{ + if (form_is_strictly_signed ()) + return u.snd; + else if (form_is_constant ()) + return u.unsnd; + + /* For DW_FORM_data16 see attribute::form_is_constant. */ + complaint (_("Attribute value is not a constant (%s)"), + dwarf_form_name (form)); + return {}; +} + +/* See attribute.h. */ + bool attribute::form_is_unsigned () const { diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 31ff018..234de4e 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -123,6 +123,25 @@ struct attribute empty value is returned. */ std::optional<LONGEST> signed_constant () const; + /* Return a signed constant value. However, for narrow forms like + DW_FORM_data1, sign extension is not done. + + DWARF advises compilers to generally use DW_FORM_[su]data to + avoid ambiguity. However, both GCC and LLVM ignore this for + certain attributes. Furthermore in DWARF, whether a narrower + form causes sign-extension depends on the attribute -- for + attributes that can only assume non-negative values, sign + extension is not done. + + Unfortunately, both compilers also emit certain attributes in a + "confused" way, using DW_FORM_sdata for signed values, and + possibly choosing a narrow form (e.g., DW_FORM_data1) otherwise + -- assuming that sign-extension will not be done. + + This method should only be called when this "confused" treatment + is necessary. */ + std::optional<LONGEST> confused_constant () const; + /* Return non-zero if ATTR's value falls in the 'constant' class, or zero otherwise. When this function returns true, you can apply the constant_value method to it. diff --git a/gdb/dwarf2/call-site.h b/gdb/dwarf2/call-site.h index e02cc5e..2cc4883 100644 --- a/gdb/dwarf2/call-site.h +++ b/gdb/dwarf2/call-site.h @@ -198,7 +198,7 @@ struct call_site struct call_site *tail_call_next = nullptr; /* * Describe DW_AT_call_target. Missing attribute uses - FIELD_LOC_KIND_DWARF_BLOCK with FIELD_DWARF_BLOCK == NULL. */ + m_loc_kind == DWARF_BLOCK with m_loc.dwarf_block == nullptr. */ struct call_site_target target {}; diff --git a/gdb/dwarf2/cooked-index-entry.c b/gdb/dwarf2/cooked-index-entry.c index 52db851..863ddd6 100644 --- a/gdb/dwarf2/cooked-index-entry.c +++ b/gdb/dwarf2/cooked-index-entry.c @@ -33,6 +33,7 @@ to_string (cooked_index_flag flags) MAP_ENUM_FLAG (IS_LINKAGE), MAP_ENUM_FLAG (IS_TYPE_DECLARATION), MAP_ENUM_FLAG (IS_PARENT_DEFERRED), + MAP_ENUM_FLAG (IS_SYNTHESIZED), }; return flags.to_string (mapping); @@ -233,8 +234,7 @@ cooked_index_entry::write_scope (struct obstack *storage, obstack_grow (storage, sep, strlen (sep)); } -void _initialize_dwarf2_entry (); -void _initialize_dwarf2_entry () +INIT_GDB_FILE (dwarf2_entry) { #if GDB_SELF_TEST selftests::register_test ("cooked_index_entry::compare", test_compare); diff --git a/gdb/dwarf2/cooked-index-worker.c b/gdb/dwarf2/cooked-index-worker.c index 5d7fc46..09d80ef 100644 --- a/gdb/dwarf2/cooked-index-worker.c +++ b/gdb/dwarf2/cooked-index-worker.c @@ -246,7 +246,7 @@ void cooked_index_worker::done_reading () { { - scoped_time_it time_it ("DWARF add parent map"); + scoped_time_it time_it ("DWARF add parent map", m_per_command_time); for (auto &one_result : m_results) m_all_parents_map.add_map (*one_result.get_parent_map ()); diff --git a/gdb/dwarf2/cooked-index-worker.h b/gdb/dwarf2/cooked-index-worker.h index df5c31d..8b9766c 100644 --- a/gdb/dwarf2/cooked-index-worker.h +++ b/gdb/dwarf2/cooked-index-worker.h @@ -25,6 +25,8 @@ #include "dwarf2/cooked-index-shard.h" #include "dwarf2/types.h" #include "dwarf2/read.h" +#include "maint.h" +#include "run-on-main-thread.h" #if CXX_STD_THREAD #include <mutex> @@ -107,11 +109,20 @@ public: return &m_parent_map; } - /* Add an exception to the list of exceptions caught while reading. - These are passed forward and printed by the main thread. */ - void note_error (gdb_exception &&except) + /* Catch exceptions from calling F (), and add them to the list of caught + exceptions. These are passed forward and printed by the main thread. */ + template <typename F> + void + catch_error (F &&f) { - m_exceptions.push_back (std::move (except)); + try + { + f (); + } + catch (gdb_exception &ex) + { + m_exceptions.push_back (std::move (ex)); + } } /* Called when the thread using this object is done with its work. @@ -207,8 +218,12 @@ public: explicit cooked_index_worker (dwarf2_per_objfile *per_objfile) : m_per_objfile (per_objfile), - m_cache_store (global_index_cache, per_objfile->per_bfd) - { } + m_cache_store (global_index_cache, per_objfile->per_bfd), + m_per_command_time (per_command_time) + { + /* Make sure we capture per_command_time from the main thread. */ + gdb_assert (is_main_thread ()); + } virtual ~cooked_index_worker () { } DISABLE_COPY_AND_ASSIGN (cooked_index_worker); @@ -298,6 +313,9 @@ protected: std::optional<gdb_exception> m_failed; /* An object used to write to the index cache. */ index_cache_store_context m_cache_store; + + /* Captured value of per_command_time. */ + bool m_per_command_time; }; using cooked_index_worker_up = std::unique_ptr<cooked_index_worker>; diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 2c7e31e..6209590 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -104,7 +104,8 @@ cooked_index::set_contents () const parent_map_map *parent_maps = m_state->get_parent_map_map (); finalizers.add_task ([=] () { - scoped_time_it time_it ("DWARF finalize worker"); + scoped_time_it time_it ("DWARF finalize worker", + m_state->m_per_command_time); this_shard->finalize (parent_maps); }); } @@ -326,9 +327,7 @@ maintenance_wait_for_index_cache (const char *args, int from_tty) wait_for_index_cache (0); } -void _initialize_cooked_index (); -void -_initialize_cooked_index () +INIT_GDB_FILE (cooked_index) { add_cmd ("wait-for-index-cache", class_maintenance, maintenance_wait_for_index_cache, _("\ diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 9f76789..69f396c 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -27,8 +27,6 @@ #include "gdbsupport/unordered_set.h" #include "dwarf2/die.h" -struct field_info; - /* Type used for delaying computation of method physnames. See comments for compute_delayed_physnames. */ struct delayed_method_info @@ -371,7 +369,7 @@ public: right place. And since the DW_TAG_compile_unit DIE in the split-unit can't have a DW_AT_ranges attribute, we can use the - die->tag != DW_AT_compile_unit + die->tag != DW_TAG_compile_unit to determine whether the base should be added or not. */ ULONGEST gnu_ranges_base = 0; @@ -401,15 +399,6 @@ public: .debug_str_offsets section (8 or 4, depending on the address size). */ std::optional<ULONGEST> str_offsets_base; - /* We may encounter a DIE where a property refers to a field in some - outer type. For example, in Ada, an array length may depend on a - field in some outer record. In this case, we need to be able to - stash a pointer to the 'struct field' into the appropriate - dynamic property baton. However, the fields aren't created until - the type has been fully processed, so we need a temporary - back-link to this object. */ - struct field_info *field_info = nullptr; - /* Mark used when releasing cached dies. */ bool m_mark : 1; diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index 583103b..1aa0d03 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -56,35 +56,37 @@ dwz_file::read_string (struct objfile *objfile, LONGEST str_offset) /* A helper function to find the sections for a .dwz file. */ static void -locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp, - dwz_file *dwz_file) +locate_dwz_sections (objfile *objfile, dwz_file &dwz_file) { - dwarf2_section_info *sect = nullptr; + for (asection *sec : gdb_bfd_sections (dwz_file.dwz_bfd)) + { + dwarf2_section_info *sect = nullptr; - /* Note that we only support the standard ELF names, because .dwz + /* Note that we only support the standard ELF names, because .dwz is ELF-only (at the time of writing). */ - if (dwarf2_elf_names.abbrev.matches (sectp->name)) - sect = &dwz_file->abbrev; - else if (dwarf2_elf_names.info.matches (sectp->name)) - sect = &dwz_file->info; - else if (dwarf2_elf_names.str.matches (sectp->name)) - sect = &dwz_file->str; - else if (dwarf2_elf_names.line.matches (sectp->name)) - sect = &dwz_file->line; - else if (dwarf2_elf_names.macro.matches (sectp->name)) - sect = &dwz_file->macro; - else if (dwarf2_elf_names.gdb_index.matches (sectp->name)) - sect = &dwz_file->gdb_index; - else if (dwarf2_elf_names.debug_names.matches (sectp->name)) - sect = &dwz_file->debug_names; - else if (dwarf2_elf_names.types.matches (sectp->name)) - sect = &dwz_file->types; - - if (sect != nullptr) - { - sect->s.section = sectp; - sect->size = bfd_section_size (sectp); - sect->read (objfile); + if (dwarf2_elf_names.abbrev.matches (sec->name)) + sect = &dwz_file.abbrev; + else if (dwarf2_elf_names.info.matches (sec->name)) + sect = &dwz_file.info; + else if (dwarf2_elf_names.str.matches (sec->name)) + sect = &dwz_file.str; + else if (dwarf2_elf_names.line.matches (sec->name)) + sect = &dwz_file.line; + else if (dwarf2_elf_names.macro.matches (sec->name)) + sect = &dwz_file.macro; + else if (dwarf2_elf_names.gdb_index.matches (sec->name)) + sect = &dwz_file.gdb_index; + else if (dwarf2_elf_names.debug_names.matches (sec->name)) + sect = &dwz_file.debug_names; + else if (dwarf2_elf_names.types.matches (sec->name)) + sect = &dwz_file.types; + + if (sect != nullptr) + { + sect->s.section = sec; + sect->size = bfd_section_size (sec); + sect->read (objfile); + } } } @@ -341,7 +343,7 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile) { gdb::unique_xmalloc_ptr<char> abs = gdb_realpath (per_bfd->filename ()); - filename = ldirname (abs.get ()) + SLASH_STRING + filename; + filename = gdb_ldirname (abs.get ()) + SLASH_STRING + filename; } /* First try the file name given in the section. If that doesn't @@ -392,9 +394,7 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile) dwz_file_up result (new dwz_file (std::move (dwz_bfd))); - for (asection *sec : gdb_bfd_sections (result->dwz_bfd)) - locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (), - sec, result.get ()); + locate_dwz_sections (per_objfile->objfile, *result); gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ()); bfd_cache_close (result->dwz_bfd.get ()); diff --git a/gdb/dwarf2/frame-tailcall.c b/gdb/dwarf2/frame-tailcall.c index 6464ffb..e31ae10 100644 --- a/gdb/dwarf2/frame-tailcall.c +++ b/gdb/dwarf2/frame-tailcall.c @@ -478,9 +478,7 @@ const struct frame_unwind_legacy dwarf2_tailcall_frame_unwind ( tailcall_frame_prev_arch ); -void _initialize_tailcall_frame (); -void -_initialize_tailcall_frame () +INIT_GDB_FILE (tailcall_frame) { cache_htab = htab_create_alloc (50, cache_hash, cache_eq, NULL, xcalloc, xfree); diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index 1b4de0d..7a37285 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -2247,9 +2247,7 @@ dwarf2_build_frame_info (struct objfile *objfile) set_comp_unit (objfile, unit.release ()); } -void _initialize_dwarf2_frame (); -void -_initialize_dwarf2_frame () +INIT_GDB_FILE (dwarf2_frame) { #if GDB_SELF_TEST selftests::register_test_foreach_arch ("execute_cfa_program", diff --git a/gdb/dwarf2/frame.h b/gdb/dwarf2/frame.h index f8fd8e8..9357cc1 100644 --- a/gdb/dwarf2/frame.h +++ b/gdb/dwarf2/frame.h @@ -198,6 +198,15 @@ struct dwarf2_frame_state bool armcc_cfa_offsets_reversed = false; }; +/* If DWARF supoprt was requested, create the real prototype for the + append_unwinders function. Otherwise, create a fake inline function. + + There is no need to emit a warning for some of these, because they aren't + actively reading DWARF when this is called, they're just initializing GDB. + + These should probably be moved to dwarf2/public.h. */ +#if defined(DWARF_FORMAT_AVAILABLE) + /* Set the architecture-specific register state initialization function for GDBARCH to INIT_REG. */ @@ -287,4 +296,56 @@ extern void *dwarf2_frame_get_fn_data (const frame_info_ptr &this_frame, void **this_cache, fn_prev_register cookie); +#else /* DWARF_FORMAT_AVAILABLE */ + +static inline void dwarf2_append_unwinders (struct gdbarch *gdbarch) { } + +static inline void dwarf2_frame_set_init_reg ( + gdbarch *gdbarch, void (*init_reg) (struct gdbarch *,int, + dwarf2_frame_state_reg *, + const frame_info_ptr &)) { } + +static inline const struct frame_base * + dwarf2_frame_base_sniffer (const frame_info_ptr &this_frame) +{ + warning (_("No dwarf support available.")); + return nullptr; +} + +static inline void dwarf2_frame_set_signal_frame_p + (gdbarch *gdbarch, int (*signal_frame_p) (struct gdbarch *, + const frame_info_ptr &)) { } + +static inline void *dwarf2_frame_get_fn_data (const frame_info_ptr &this_frame, + void **this_cache, + fn_prev_register cookie) +{ + return nullptr; +} + +static inline void *dwarf2_frame_allocate_fn_data + (const frame_info_ptr &this_frame, void **this_cache, + fn_prev_register cookie, unsigned long size) +{ + return nullptr; +} + +static inline int dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc, + struct dwarf2_per_cu_data *data, + int *regnum_out, LONGEST *offset_out, + CORE_ADDR *text_offset_out, + const gdb_byte **cfa_start_out, + const gdb_byte **cfa_end_out) +{ + return 0; +} + +static inline void + dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch, + int (*adjust_regnum) (struct gdbarch *, + int, int)) +{} + +#endif /* DWARF_FORMAT_AVAILABLE */ + #endif /* GDB_DWARF2_FRAME_H */ diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 1715beb..cfe8ce9 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -342,9 +342,7 @@ show_index_cache_stats_command (const char *arg, int from_tty) indent, global_index_cache.n_misses ()); } -void _initialize_index_cache (); -void -_initialize_index_cache () +INIT_GDB_FILE (index_cache) { /* Set the default index cache directory. */ std::string cache_dir = get_standard_cache_dir (); diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 614bdcd..0a3b9d0 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1768,9 +1768,7 @@ gdb_index () } /* selftests namespace. */ #endif -void _initialize_dwarf_index_write (); -void -_initialize_dwarf_index_write () +INIT_GDB_FILE (dwarf_index_write) { #if GDB_SELF_TEST selftests::register_test ("gdb_index", selftests::gdb_index); diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index fa1b4eb..37c85d8 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1747,7 +1747,7 @@ dwarf2_evaluate_property (const dynamic_prop *prop, if (pinfo == NULL) error (_("cannot find reference address for offset property")); - struct field resolved_field = *baton->field; + struct field resolved_field = baton->field; resolve_dynamic_field (resolved_field, pinfo, initial_frame); /* Storage for memory if we need to read it. */ @@ -4154,9 +4154,7 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = { loclist_generate_c_location }; -void _initialize_dwarf2loc (); -void -_initialize_dwarf2loc () +INIT_GDB_FILE (dwarf2loc) { add_setshow_zuinteger_cmd ("entry-values", class_maintenance, &entry_values_debug, diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index ebe5c31..c672320 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -20,6 +20,7 @@ #ifndef GDB_DWARF2_LOC_H #define GDB_DWARF2_LOC_H +#include "gdbtypes.h" #include "dwarf2/expr.h" struct symbol_computed_ops; @@ -102,28 +103,6 @@ struct property_addr_info const property_addr_info *next; }; -/* Converts a dynamic property into a static one. FRAME is the frame in which - the property is evaluated; if NULL, the selected frame (if any) is used - instead. - - ADDR_STACK is the stack of addresses that might be needed to evaluate the - property. When evaluating a property that is not related to a type, it can - be NULL. - - Returns true if PROP could be converted and the static value is passed - back into VALUE, otherwise returns false. - - Any values in PUSH_VALUES will be pushed before evaluating the location - expression, PUSH_VALUES[0] will be pushed first, then PUSH_VALUES[1], - etc. This means the during evaluation PUSH_VALUES[0] will be at the - bottom of the stack. */ - -bool dwarf2_evaluate_property (const struct dynamic_prop *prop, - const frame_info_ptr &frame, - const property_addr_info *addr_stack, - CORE_ADDR *value, - gdb::array_view<CORE_ADDR> push_values = {}); - /* A helper for the compiler interface that compiles a single dynamic property to C code. @@ -245,7 +224,7 @@ struct dwarf2_property_baton struct dwarf2_loclist_baton loclist; /* The location is stored in a field of PROPERTY_TYPE. */ - struct field *field; + struct field field; }; }; @@ -310,8 +289,53 @@ extern struct value *indirect_synthetic_pointer Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it cannot resolve the parameter for any reason. */ +#if defined(DWARF_FORMAT_AVAILABLE) + +/* Converts a dynamic property into a static one. FRAME is the frame in which + the property is evaluated; if NULL, the selected frame (if any) is used + instead. + + ADDR_STACK is the stack of addresses that might be needed to evaluate the + property. When evaluating a property that is not related to a type, it can + be NULL. + + Returns true if PROP could be converted and the static value is passed + back into VALUE, otherwise returns false. + + Any values in PUSH_VALUES will be pushed before evaluating the location + expression, PUSH_VALUES[0] will be pushed first, then PUSH_VALUES[1], + etc. This means the during evaluation PUSH_VALUES[0] will be at the + bottom of the stack. */ + +bool dwarf2_evaluate_property (const struct dynamic_prop *prop, + const frame_info_ptr &frame, + const property_addr_info *addr_stack, + CORE_ADDR *value, + gdb::array_view<CORE_ADDR> push_values = {}); + extern struct value *value_of_dwarf_reg_entry (struct type *type, const frame_info_ptr &frame, enum call_site_parameter_kind kind, union call_site_parameter_u kind_u); + +#else /* DWARF_FORMAT_AVAILABLE */ + +static inline bool +dwarf2_evaluate_property (const struct dynamic_prop *, const frame_info_ptr &, + const property_addr_info *, CORE_ADDR *, + gdb::array_view<CORE_ADDR> = {}) +{ + return false; +} + +static inline struct value * +value_of_dwarf_reg_entry (struct type *type, const frame_info_ptr &frame, + enum call_site_parameter_kind kind, + union call_site_parameter_u kind_u) +{ + error (_("No dwarf support available.")); +} + +#endif /* DWARF_FORMAT_AVAILABLE */ + #endif /* GDB_DWARF2_LOC_H */ diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index ed504c6..f9e7488 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -30,6 +30,8 @@ enum class dw_index_kind DEBUG_NAMES, }; +#if defined(DWARF_FORMAT_AVAILABLE) + /* Try to locate the sections we need for DWARF 2 debugging information. If these are found, begin reading the DWARF and return true. Otherwise, return false. NAMES points to the dwarf2 @@ -44,4 +46,27 @@ extern bool dwarf2_initialize_objfile extern void dwarf2_build_frame_info (struct objfile *); +/* Append the DWARF-2 frame unwinders to GDBARCH's list. */ + +void dwarf2_append_unwinders (struct gdbarch *gdbarch); + +#else /* DWARF_FORMAT_AVAILABLE */ + +static inline bool +dwarf2_initialize_objfile (struct objfile *, + const struct dwarf2_debug_sections * = nullptr, + bool = false) +{ + warning (_("No dwarf support available.")); + return false; +} + +static inline void +dwarf2_build_frame_info (struct objfile *) +{ + warning (_("No dwarf support available.")); +} + +#endif /* DWARF_FORMAT_AVAILABLE */ + #endif /* GDB_DWARF2_PUBLIC_H */ diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index 11de986..4b3f385 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -241,7 +241,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, continue; } } - per_cu = per_objfile->per_bfd->get_cu (ull); + per_cu = per_objfile->per_bfd->get_unit (ull); break; case DW_IDX_type_unit: /* Don't crash on bad data. */ @@ -255,7 +255,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, } { int nr_cus = per_objfile->per_bfd->all_comp_units.size (); - per_cu = per_objfile->per_bfd->get_cu (nr_cus + ull); + per_cu = per_objfile->per_bfd->get_unit (nr_cus + ull); } break; case DW_IDX_die_offset: @@ -263,7 +263,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, /* In a per-CU index (as opposed to a per-module index), index entries without CU attribute implicitly refer to the single CU. */ if (per_cu == NULL) - per_cu = per_objfile->per_bfd->get_cu (0); + per_cu = per_objfile->per_bfd->get_unit (0); break; case DW_IDX_parent: parent = ull; @@ -416,15 +416,11 @@ cooked_index_worker_debug_names::do_reading () { complaint_interceptor complaint_handler; - try + /* Arbitrarily put all exceptions into the first result. */ + m_map.indices[0].catch_error ([&] () { m_map.scan_all_names (); - } - catch (gdb_exception &exc) - { - /* Arbitrarily put all exceptions into the first result. */ - m_map.indices[0].note_error (std::move (exc)); - } + }); bool first = true; for (auto &iter : m_map.indices) @@ -470,7 +466,7 @@ check_signatured_type_table_from_debug_names bool found = false; for (; j < nr_cus_tus; j++) - if (per_bfd->get_cu (j)->sect_off == sect_off) + if (per_bfd->get_unit (j)->sect_off == sect_off) { found = true; break; @@ -481,7 +477,7 @@ check_signatured_type_table_from_debug_names " ignoring .debug_names.")); return false; } - per_bfd->all_comp_units_index_tus.push_back (per_bfd->get_cu (j)); + per_bfd->all_comp_units_index_tus.push_back (per_bfd->get_unit (j)); } return true; } @@ -723,7 +719,7 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, map.dwarf5_byte_order)); bool found = false; for (; j < nr_cus; j++) - if (per_bfd->get_cu (j)->sect_off == sect_off) + if (per_bfd->get_unit (j)->sect_off == sect_off) { found = true; break; @@ -734,7 +730,7 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, " ignoring .debug_names.")); return false; } - per_bfd->all_comp_units_index_cus.push_back (per_bfd->get_cu (j)); + per_bfd->all_comp_units_index_cus.push_back (per_bfd->get_unit (j)); } return true; } @@ -753,7 +749,7 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, (map.cu_table_reordered + i * map.offset_size, map.offset_size, map.dwarf5_byte_order)); - if (sect_off != per_bfd->get_cu (i)->sect_off) + if (sect_off != per_bfd->get_unit (i)->sect_off) { warning (_("Section .debug_names has incorrect entry in CU table," " ignoring .debug_names.")); diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c index 2029c3e..464fbdd 100644 --- a/gdb/dwarf2/read-gdb-index.c +++ b/gdb/dwarf2/read-gdb-index.c @@ -1113,7 +1113,7 @@ dw2_expand_marked_cus (dwarf2_per_objfile *per_objfile, offset_type idx, continue; } - dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_cu (cu_index); + dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_unit (cu_index); if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher, expansion_notify, lang_matcher)) @@ -1426,7 +1426,7 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile, continue; } - mutable_map.set_empty (lo, hi - 1, per_bfd->get_cu (cu_index)); + mutable_map.set_empty (lo, hi - 1, per_bfd->get_unit (cu_index)); } index->index_addrmap @@ -1562,10 +1562,7 @@ dwarf2_read_gdb_index return true; } -void _initialize_read_gdb_index (); - -void -_initialize_read_gdb_index () +INIT_GDB_FILE (read_gdb_index) { add_setshow_boolean_cmd ("use-deprecated-index-sections", no_class, &use_deprecated_index_sections, _("\ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 71fa793..5e18e45 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -289,24 +289,29 @@ struct dwo_sections struct dwo_unit { /* Backlink to the containing struct dwo_file. */ - struct dwo_file *dwo_file; + struct dwo_file *dwo_file = nullptr; /* The "id" that distinguishes this CU/TU. .debug_info calls this "dwo_id", .debug_types calls this "signature". Since signatures came first, we stick with it for consistency. */ - ULONGEST signature; + ULONGEST signature = 0; /* The section this CU/TU lives in, in the DWO file. */ - struct dwarf2_section_info *section; + dwarf2_section_info *section = nullptr; + + /* This is set if SECTION is owned by this dwo_unit. */ + dwarf2_section_info_up section_holder; /* Same as dwarf2_per_cu::{sect_off,length} but in the DWO section. */ - sect_offset sect_off; - unsigned int length; + sect_offset sect_off {}; + unsigned int length = 0; /* For types, offset in the type's DIE of the type defined by this TU. */ cu_offset type_offset_in_tu; }; +using dwo_unit_up = std::unique_ptr<dwo_unit>; + /* Hash function for dwo_unit objects, based on the signature. */ struct dwo_unit_hash @@ -316,7 +321,7 @@ struct dwo_unit_hash std::size_t operator() (ULONGEST signature) const noexcept { return signature; } - std::size_t operator() (const dwo_unit *unit) const noexcept + std::size_t operator() (const dwo_unit_up &unit) const noexcept { return (*this) (unit->signature); } }; @@ -330,16 +335,16 @@ struct dwo_unit_eq { using is_transparent = void; - bool operator() (ULONGEST sig, const dwo_unit *unit) const noexcept + bool operator() (ULONGEST sig, const dwo_unit_up &unit) const noexcept { return sig == unit->signature; } - bool operator() (const dwo_unit *a, const dwo_unit *b) const noexcept + bool operator() (const dwo_unit_up &a, const dwo_unit_up &b) const noexcept { return (*this) (a->signature, b); } }; /* Set of dwo_unit object, using their signature as identity. */ -using dwo_unit_set = gdb::unordered_set<dwo_unit *, dwo_unit_hash, dwo_unit_eq>; +using dwo_unit_set = gdb::unordered_set<dwo_unit_up, dwo_unit_hash, dwo_unit_eq>; /* include/dwarf2.h defines the DWP section codes. It defines a max value but it doesn't define a min value, which we @@ -599,6 +604,11 @@ struct dwp_file dwo_unit_set loaded_cus; dwo_unit_set loaded_tus; +#if CXX_STD_THREAD + /* Mutex to synchronize access to LOADED_CUS and LOADED_TUS. */ + std::mutex loaded_cutus_lock; +#endif + /* Table to map ELF section numbers to their sections. This is only needed for the DWP V1 file format. */ unsigned int num_sections = 0; @@ -698,12 +708,6 @@ struct field_info we're reading. */ std::vector<variant_part_builder> variant_parts; - /* All the field batons that must be updated. This is only used - when a type's property depends on a field of this structure; for - example in Ada when an array's length may come from a field of an - enclosing record. */ - gdb::unordered_map<dwarf2_property_baton *, sect_offset> field_batons; - /* Return the total number of fields (including baseclasses). */ int nfields () const { @@ -1897,13 +1901,13 @@ dwarf2_base_index_functions::print_stats (struct objfile *objfile, for (int i = 0; i < total; ++i) { - dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_cu (i); + dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_unit (i); if (!per_objfile->symtab_set_p (per_cu)) ++count; } - gdb_printf (_(" Number of read CUs: %d\n"), total - count); - gdb_printf (_(" Number of unread CUs: %d\n"), count); + gdb_printf (_(" Number of read units: %d\n"), total - count); + gdb_printf (_(" Number of unread units: %d\n"), count); } void @@ -2493,7 +2497,7 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) if (it == dwo_file->tus.end ()) return nullptr; - dwo_unit *dwo_entry = *it; + dwo_unit *dwo_entry = it->get (); /* If the global table doesn't have an entry for this TU, add one. */ if (sig_type_it == per_bfd->signatured_types.end ()) @@ -2783,13 +2787,6 @@ dwo_unit * cutu_reader::lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name) { -#if CXX_STD_THREAD - /* We need a lock here to handle the DWO hash table. */ - static std::mutex dwo_lock; - - std::lock_guard<std::mutex> guard (dwo_lock); -#endif - dwarf2_per_cu *per_cu = cu->per_cu; struct dwo_unit *dwo_unit; const char *comp_dir; @@ -3428,7 +3425,10 @@ cooked_index_worker_debug_info::process_type_units abbrev_table.get (), nullptr, false, language_minimal); if (!reader.is_dummy ()) - process_type_unit (&reader, storage); + storage->catch_error ([&] () + { + process_type_unit (&reader, storage); + }); } } @@ -3464,13 +3464,16 @@ void cooked_index_worker_debug_info::process_skeletonless_type_units (dwarf2_per_objfile *per_objfile, cooked_index_worker_result *storage) { - scoped_time_it time_it ("DWARF skeletonless type units"); + scoped_time_it time_it ("DWARF skeletonless type units", m_per_command_time); /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */ if (per_objfile->per_bfd->dwp_file == nullptr) for (const dwo_file_up &file : per_objfile->per_bfd->dwo_files) - for (dwo_unit *unit : file->tus) - process_skeletonless_type_unit (unit, per_objfile, storage); + for (const dwo_unit_up &unit : file->tus) + storage->catch_error ([&] () + { + process_skeletonless_type_unit (unit.get (), per_objfile, storage); + }); } void @@ -3489,14 +3492,10 @@ cooked_index_worker_debug_info::process_units (size_t task_number, { dwarf2_per_cu *per_cu = inner->get (); - try + thread_storage.catch_error ([&] () { process_unit (per_cu, m_per_objfile, &thread_storage); - } - catch (gdb_exception &except) - { - thread_storage.note_error (std::move (except)); - } + }); } thread_storage.done_reading (complaint_handler.release ()); @@ -3574,7 +3573,7 @@ cooked_index_worker_debug_info::do_reading () gdb_assert (iter != last); workers.add_task ([this, task_count, iter, last] () { - scoped_time_it time_it ("DWARF indexing worker"); + scoped_time_it time_it ("DWARF indexing worker", m_per_command_time); process_units (task_count, iter, last); }); @@ -5859,7 +5858,7 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) && res.get_name () != nullptr && IS_ABSOLUTE_PATH (res.get_name ())) { - res.set_comp_dir (ldirname (res.get_name ())); + res.set_comp_dir (gdb_ldirname (res.get_name ())); res.set_name (make_unique_xstrdup (lbasename (res.get_name ()))); } @@ -6206,11 +6205,33 @@ static dwo_file * lookup_dwo_file (dwarf2_per_bfd *per_bfd, const char *dwo_name, const char *comp_dir) { +#if CXX_STD_THREAD + std::lock_guard<std::mutex> guard (per_bfd->dwo_files_lock); +#endif + auto it = per_bfd->dwo_files.find (dwo_file_search {dwo_name, comp_dir}); return it != per_bfd->dwo_files.end () ? it->get() : nullptr; } +/* Add DWO_FILE to the per-BFD DWO file hash table. + + Return the dwo_file actually kept in the hash table. + + If another thread raced with this one, opening the exact same DWO file and + inserting it first in the hash table, then keep that other thread's copy + and DWO_FILE gets freed. */ + +static dwo_file * +add_dwo_file (dwarf2_per_bfd *per_bfd, dwo_file_up dwo_file) +{ +#if CXX_STD_THREAD + std::lock_guard<std::mutex> lock (per_bfd->dwo_files_lock); +#endif + + return per_bfd->dwo_files.emplace (std::move (dwo_file)).first->get (); +} + void cutu_reader::create_dwo_unit_hash_tables (dwo_file &dwo_file, dwarf2_cu &skeleton_cu, @@ -6289,7 +6310,7 @@ cutu_reader::create_dwo_unit_hash_tables (dwo_file &dwo_file, else signature = header.signature; - dwo_unit *dwo_unit = OBSTACK_ZALLOC (&per_bfd.obstack, struct dwo_unit); + auto dwo_unit = std::make_unique<struct dwo_unit> (); /* Set the fields common to compile and type units. */ dwo_unit->dwo_file = &dwo_file; @@ -6307,7 +6328,7 @@ cutu_reader::create_dwo_unit_hash_tables (dwo_file &dwo_file, sect_offset_str (sect_off), hex_string (dwo_unit->signature)); - auto [it, inserted] = dwo_file.cus.emplace (dwo_unit); + auto [it, inserted] = dwo_file.cus.emplace (std::move (dwo_unit)); if (!inserted) complaint (_("debug cu entry at offset %s is duplicate to" " the entry at offset %s, signature %s"), @@ -6326,7 +6347,7 @@ cutu_reader::create_dwo_unit_hash_tables (dwo_file &dwo_file, sect_offset_str (sect_off), hex_string (dwo_unit->signature)); - auto [it, inserted] = dwo_file.tus.emplace (dwo_unit); + auto [it, inserted] = dwo_file.tus.emplace (std::move (dwo_unit)); if (!inserted) complaint (_("debug type entry at offset %s is duplicate to" " the entry at offset %s, signature %s"), @@ -6807,7 +6828,7 @@ locate_v1_virtual_dwo_sections (asection *sectp, COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. This is for DWP version 1 files. */ -static struct dwo_unit * +static dwo_unit_up create_dwo_unit_in_dwp_v1 (dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file, uint32_t unit_index, @@ -6930,19 +6951,17 @@ create_dwo_unit_in_dwp_v1 (dwarf2_per_bfd *per_bfd, types we'll grow the vector and eventually have to reallocate space for it, invalidating all copies of pointers into the previous contents. */ - auto [it, inserted] - = per_bfd->dwo_files.emplace (std::move (new_dwo_file)); - gdb_assert (inserted); - dwo_file = it->get (); + dwo_file = add_dwo_file (per_bfd, std::move (new_dwo_file)); } else dwarf_read_debug_printf ("Using existing virtual DWO: %s", virtual_dwo_name.c_str ()); - dwo_unit *dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack, struct dwo_unit); + auto dwo_unit = std::make_unique<struct dwo_unit> (); dwo_unit->dwo_file = dwo_file; dwo_unit->signature = signature; - dwo_unit->section = XOBNEW (&per_bfd->obstack, struct dwarf2_section_info); + dwo_unit->section_holder = std::make_unique<dwarf2_section_info> (); + dwo_unit->section = dwo_unit->section_holder.get (); *dwo_unit->section = sections.info_or_types; /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */ @@ -7000,7 +7019,7 @@ create_dwp_v2_or_v5_section (dwarf2_per_bfd *per_bfd, COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. This is for DWP version 2 files. */ -static struct dwo_unit * +static dwo_unit_up create_dwo_unit_in_dwp_v2 (dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file, uint32_t unit_index, @@ -7135,19 +7154,17 @@ create_dwo_unit_in_dwp_v2 (dwarf2_per_bfd *per_bfd, types we'll grow the vector and eventually have to reallocate space for it, invalidating all copies of pointers into the previous contents. */ - auto [it, inserted] - = per_bfd->dwo_files.emplace (std::move (new_dwo_file)); - gdb_assert (inserted); - dwo_file = it->get (); + dwo_file = add_dwo_file (per_bfd, std::move (new_dwo_file)); } else dwarf_read_debug_printf ("Using existing virtual DWO: %s", virtual_dwo_name.c_str ()); - dwo_unit *dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack, struct dwo_unit); + auto dwo_unit = std::make_unique<struct dwo_unit> (); dwo_unit->dwo_file = dwo_file; dwo_unit->signature = signature; - dwo_unit->section = XOBNEW (&per_bfd->obstack, struct dwarf2_section_info); + dwo_unit->section_holder = std::make_unique<dwarf2_section_info> (); + dwo_unit->section = dwo_unit->section_holder.get (); *dwo_unit->section = create_dwp_v2_or_v5_section (per_bfd, is_debug_types @@ -7165,7 +7182,7 @@ create_dwo_unit_in_dwp_v2 (dwarf2_per_bfd *per_bfd, COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. This is for DWP version 5 files. */ -static struct dwo_unit * +static dwo_unit_up create_dwo_unit_in_dwp_v5 (dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file, uint32_t unit_index, @@ -7305,16 +7322,13 @@ create_dwo_unit_in_dwp_v5 (dwarf2_per_bfd *per_bfd, types we'll grow the vector and eventually have to reallocate space for it, invalidating all copies of pointers into the previous contents. */ - auto [it, inserted] - = per_bfd->dwo_files.emplace (std::move (new_dwo_file)); - gdb_assert (inserted); - dwo_file = it->get (); + dwo_file = add_dwo_file (per_bfd, std::move (new_dwo_file)); } else dwarf_read_debug_printf ("Using existing virtual DWO: %s", virtual_dwo_name.c_str ()); - dwo_unit *dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack, struct dwo_unit); + auto dwo_unit = std::make_unique<struct dwo_unit> (); dwo_unit->dwo_file = dwo_file; dwo_unit->signature = signature; dwo_unit->section @@ -7345,9 +7359,15 @@ lookup_dwo_unit_in_dwp (dwarf2_per_bfd *per_bfd, auto &dwo_unit_set = is_debug_types ? dwp_file->loaded_tus : dwp_file->loaded_cus; - if (auto it = dwo_unit_set.find (signature); - it != dwo_unit_set.end ()) - return *it; + { +#if CXX_STD_THREAD + std::lock_guard<std::mutex> guard (dwp_file->loaded_cutus_lock); +#endif + + if (auto it = dwo_unit_set.find (signature); + it != dwo_unit_set.end ()) + return it->get (); + } /* Use a for loop so that we don't loop forever on bad debug info. */ for (unsigned int i = 0; i < dwp_htab->nr_slots; ++i) @@ -7361,7 +7381,7 @@ lookup_dwo_unit_in_dwp (dwarf2_per_bfd *per_bfd, uint32_t unit_index = read_4_bytes (dbfd, dwp_htab->unit_table + hash * sizeof (uint32_t)); - dwo_unit *dwo_unit; + dwo_unit_up dwo_unit; if (dwp_file->version == 1) dwo_unit @@ -7376,9 +7396,14 @@ lookup_dwo_unit_in_dwp (dwarf2_per_bfd *per_bfd, = create_dwo_unit_in_dwp_v5 (per_bfd, dwp_file, unit_index, comp_dir, signature, is_debug_types); - auto [it, inserted] = dwo_unit_set.emplace (dwo_unit); - gdb_assert (inserted); - return *it; + /* If another thread raced with this one, opening the exact same + DWO unit, then we'll keep that other thread's copy. */ +#if CXX_STD_THREAD + std::lock_guard<std::mutex> guard (dwp_file->loaded_cutus_lock); +#endif + + auto it = dwo_unit_set.emplace (std::move (dwo_unit)).first; + return it->get (); } if (signature_in_table == 0) @@ -7434,7 +7459,7 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp, search_path = per_bfd->captured_debug_dir.c_str (); /* Add the path for the executable binary to the list of search paths. */ - std::string objfile_dir = ldirname (per_bfd->filename ()); + std::string objfile_dir = gdb_ldirname (per_bfd->filename ()); search_path_holder.reset (concat (objfile_dir.c_str (), dirname_separator_string, search_path, nullptr)); @@ -7455,14 +7480,23 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp, if (sym_bfd == NULL) return NULL; - if (!bfd_check_format (sym_bfd.get (), bfd_object)) - return NULL; + { +#if CXX_STD_THREAD + /* The operations below are not thread-safe, use a lock to synchronize + concurrent accesses. */ + static std::mutex mutex; + std::lock_guard<std::mutex> lock (mutex); +#endif + + if (!bfd_check_format (sym_bfd.get (), bfd_object)) + return NULL; - /* Success. Record the bfd as having been included by the objfile's bfd. + /* Success. Record the bfd as having been included by the objfile's bfd. This is important because things like demangled_names_hash lives in the objfile's per_bfd space and may have references to things like symbol names that live in the DWO/DWP file's per_bfd space. PR 16426. */ - gdb_bfd_record_inclusion (per_bfd->obfd, sym_bfd.get ()); + gdb_bfd_record_inclusion (per_bfd->obfd, sym_bfd.get ()); + } return sym_bfd; } @@ -7512,45 +7546,66 @@ cutu_reader::open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name, size of each of the DWO debugging sections we are interested in. */ void -cutu_reader::locate_dwo_sections (struct objfile *objfile, bfd *abfd, - asection *sectp, dwo_sections *dwo_sections) +cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file) { const struct dwop_section_names *names = &dwop_section_names; + dwo_sections &dwo_sections = dwo_file.sections; + bool complained_about_macro_already = false; + + for (asection *sec : gdb_bfd_sections (dwo_file.dbfd)) + { + struct dwarf2_section_info *dw_sect = nullptr; + + if (names->abbrev_dwo.matches (sec->name)) + dw_sect = &dwo_sections.abbrev; + else if (names->info_dwo.matches (sec->name)) + dw_sect = &dwo_sections.infos.emplace_back (dwarf2_section_info {}); + else if (names->line_dwo.matches (sec->name)) + dw_sect = &dwo_sections.line; + else if (names->loc_dwo.matches (sec->name)) + dw_sect = &dwo_sections.loc; + else if (names->loclists_dwo.matches (sec->name)) + dw_sect = &dwo_sections.loclists; + else if (names->macinfo_dwo.matches (sec->name)) + dw_sect = &dwo_sections.macinfo; + else if (names->macro_dwo.matches (sec->name)) + { + /* gcc versions <= 13 generate multiple .debug_macro.dwo sections with + some unresolved links between them. It's not usable, so do as if + there were not there. */ + if (!complained_about_macro_already) + { + if (dwo_sections.macro.s.section == nullptr) + dw_sect = &dwo_sections.macro; + else + { + warning (_("Multiple .debug_macro.dwo sections found in " + "%s, ignoring them."), dwo_file.dbfd->filename); - struct dwarf2_section_info *dw_sect = nullptr; - - if (names->abbrev_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->abbrev; - else if (names->info_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->infos.emplace_back (dwarf2_section_info {}); - else if (names->line_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->line; - else if (names->loc_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->loc; - else if (names->loclists_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->loclists; - else if (names->macinfo_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->macinfo; - else if (names->macro_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->macro; - else if (names->rnglists_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->rnglists; - else if (names->str_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->str; - else if (names->str_offsets_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->str_offsets; - else if (names->types_dwo.matches (sectp->name)) - dw_sect = &dwo_sections->types.emplace_back (dwarf2_section_info {}); - - if (dw_sect != nullptr) - { - /* Make sure we don't overwrite a section info that has been filled in + dwo_sections.macro = dwarf2_section_info {}; + complained_about_macro_already = true; + } + } + } + else if (names->rnglists_dwo.matches (sec->name)) + dw_sect = &dwo_sections.rnglists; + else if (names->str_dwo.matches (sec->name)) + dw_sect = &dwo_sections.str; + else if (names->str_offsets_dwo.matches (sec->name)) + dw_sect = &dwo_sections.str_offsets; + else if (names->types_dwo.matches (sec->name)) + dw_sect = &dwo_sections.types.emplace_back (dwarf2_section_info {}); + + if (dw_sect != nullptr) + { + /* Make sure we don't overwrite a section info that has been filled in already. */ - gdb_assert (!dw_sect->readin); + gdb_assert (!dw_sect->readin); - dw_sect->s.section = sectp; - dw_sect->size = bfd_section_size (sectp); - dw_sect->read (objfile); + dw_sect->s.section = sec; + dw_sect->size = bfd_section_size (sec); + dw_sect->read (objfile); + } } } @@ -7578,15 +7633,8 @@ cutu_reader::open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name, dwo_file->comp_dir = comp_dir; dwo_file->dbfd = std::move (dbfd); - for (asection *sec : gdb_bfd_sections (dwo_file->dbfd)) - this->locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (), sec, - &dwo_file->sections); + this->locate_dwo_sections (per_objfile->objfile, *dwo_file); - /* There is normally just one .debug_info.dwo section in a DWO file. But when - building with -fdebug-types-section, gcc produces multiple .debug_info.dwo - sections. One for each produced type unit and one for the compile unit. - This is not expected, but we can easily enough deal with what gcc - produces. This behavior has been observed with gcc 14.2.1. */ for (dwarf2_section_info §ion : dwo_file->sections.infos) create_dwo_unit_hash_tables (*dwo_file, *cu, section, ruh_kind::COMPILE); @@ -7788,7 +7836,7 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile) struct objfile *backlink = objfile->separate_debug_objfile_backlink; const char *backlink_basename = lbasename (backlink->original_name); - dwp_name = ldirname (objfile->original_name) + SLASH_STRING + backlink_basename; + dwp_name = gdb_ldirname (objfile->original_name) + SLASH_STRING + backlink_basename; } else dwp_name = objfile->original_name; @@ -7938,12 +7986,7 @@ cutu_reader::lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, = open_and_init_dwo_file (cu, dwo_name, comp_dir); if (new_dwo_file != nullptr) - { - auto [it, inserted] - = per_bfd->dwo_files.emplace (std::move (new_dwo_file)); - gdb_assert (inserted); - dwo_file = (*it).get (); - } + dwo_file = add_dwo_file (per_bfd, std::move (new_dwo_file)); } if (dwo_file != NULL) @@ -7954,13 +7997,13 @@ cutu_reader::lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, { if (auto it = dwo_file->tus.find (signature); it != dwo_file->tus.end ()) - dwo_cutu = *it; + dwo_cutu = it->get (); } else if (!is_debug_types && !dwo_file->cus.empty ()) { if (auto it = dwo_file->cus.find (signature); it != dwo_file->cus.end ()) - dwo_cutu = *it; + dwo_cutu = it->get (); } if (dwo_cutu != NULL) @@ -8067,8 +8110,8 @@ queue_and_load_all_dwo_tus (dwarf2_cu *cu) dwo_file = dwo_unit->dwo_file; - for (struct dwo_unit *unit : dwo_file->tus) - queue_and_load_dwo_tu (unit, cu); + for (const dwo_unit_up &unit : dwo_file->tus) + queue_and_load_dwo_tu (unit.get (), cu); } /* Read in various DIEs. */ @@ -9888,7 +9931,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, if (attr2 != nullptr && attr2->form_is_constant ()) { has_bit_offset = true; - bit_offset = attr2->unsigned_constant ().value_or (0); + bit_offset = attr2->confused_constant ().value_or (0); attr2 = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr2 != nullptr && attr2->form_is_constant ()) { @@ -9901,7 +9944,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, if (attr->form_is_constant ()) { - LONGEST offset = attr->unsigned_constant ().value_or (0); + LONGEST offset = attr->confused_constant ().value_or (0); /* Work around this GCC 11 bug, where it would erroneously use -1 data member locations, instead of 0: @@ -9951,7 +9994,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, dlbaton->per_objfile = per_objfile; dlbaton->per_cu = cu->per_cu; - field->set_loc_dwarf_block (dlbaton); + field->set_loc_dwarf_block_addr (dlbaton); } } else @@ -9962,10 +10005,54 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, { attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); if (attr != nullptr) - field->set_loc_bitpos (attr->unsigned_constant ().value_or (0)); + { + if (attr->form_is_constant ()) + field->set_loc_bitpos (attr->unsigned_constant ().value_or (0)); + else if (attr->form_is_block ()) + { + /* This is a DWARF extension. See + https://dwarfstd.org/issues/250501.1.html. */ + dwarf2_per_objfile *per_objfile = cu->per_objfile; + dwarf2_locexpr_baton *dlbaton + = OBSTACK_ZALLOC (&per_objfile->objfile->objfile_obstack, + dwarf2_locexpr_baton); + dlbaton->data = attr->as_block ()->data; + dlbaton->size = attr->as_block ()->size; + dlbaton->per_objfile = per_objfile; + dlbaton->per_cu = cu->per_cu; + + field->set_loc_dwarf_block_bitpos (dlbaton); + } + else + complaint (_("Unsupported form %s for DW_AT_data_bit_offset"), + dwarf_form_name (attr->form)); + } } } +/* A helper that computes the location of a field. The CU and the + DW_TAG_member DIE are passed in. The results are stored in + *FP. */ + +static void +compute_field_location (dwarf2_cu *cu, die_info *die, field *fp) +{ + /* Get type of field. */ + fp->set_type (die_type (die, cu)); + + fp->set_loc_bitpos (0); + + /* Get bit size of field (zero if none). */ + attribute *attr = dwarf2_attr (die, DW_AT_bit_size, cu); + if (attr != nullptr) + fp->set_bitsize (attr->unsigned_constant ().value_or (0)); + else + fp->set_bitsize (0); + + /* Get bit offset of field. */ + handle_member_location (die, cu, fp); +} + /* Add an aggregate field to the field list. */ static void @@ -10021,20 +10108,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, } /* Data member other than a C++ static data member. */ - /* Get type of field. */ - fp->set_type (die_type (die, cu)); - - fp->set_loc_bitpos (0); - - /* Get bit size of field (zero if none). */ - attr = dwarf2_attr (die, DW_AT_bit_size, cu); - if (attr != nullptr) - fp->set_bitsize (attr->unsigned_constant ().value_or (0)); - else - fp->set_bitsize (0); - - /* Get bit offset of field. */ - handle_member_location (die, cu, fp); + compute_field_location (cu, die, fp); /* Get name of field. */ fieldname = dwarf2_name (die, cu); @@ -11213,54 +11287,19 @@ handle_struct_member_die (struct die_info *child_die, struct type *type, handle_variant (child_die, type, fi, template_args, cu); } -/* Create a property baton for a field of the struct type currently - being processed. OFFSET is the DIE offset of the field in the - structure. If OFFSET is found among the fields that have already - been seen, then a new property baton is allocated on the objfile - obstack and returned. The baton isn't fully filled in -- it will - be post-processed once the fields are finally created; see - update_field_batons. If OFFSET is not found, NULL is returned. */ +/* Create a property baton for a field. DIE is the field's DIE. The + baton's "field" member is filled in, but the other members of the + baton are not. The new property baton is returned. */ static dwarf2_property_baton * -find_field_create_baton (dwarf2_cu *cu, sect_offset offset) +find_field_create_baton (dwarf2_cu *cu, die_info *die) { - field_info *fi = cu->field_info; - /* Defensive programming in case we see unusual DWARF. */ - if (fi == nullptr) - return nullptr; - for (const auto &fld : fi->fields) - if (fld.offset == offset) - { - dwarf2_property_baton *result - = XOBNEW (&cu->per_objfile->objfile->objfile_obstack, - struct dwarf2_property_baton); - fi->field_batons[result] = offset; - return result; - } - return nullptr; -} - -/* Update all the stored field property batons. FI is the field info - for the structure being created. TYPE is the corresponding struct - type with its fields already filled in. This fills in the correct - field for each baton that was stored while processing this - type. */ - -static void -update_field_batons (field_info *fi, struct type *type) -{ - int n_bases = fi->baseclasses.size (); - for (auto &[baton, offset] : fi->field_batons) - { - for (int i = 0; i < fi->fields.size (); ++i) - { - if (fi->fields[i].offset == offset) - { - baton->field = &type->field (n_bases + i); - break; - } - } - } + dwarf2_property_baton *result + = XOBNEW (&cu->per_objfile->objfile->objfile_obstack, + struct dwarf2_property_baton); + memset (&result->field, 0, sizeof (result->field)); + compute_field_location (cu, die, &result->field); + return result; } /* Finish creating a structure or union type, including filling in its @@ -11284,9 +11323,6 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) struct field_info fi; std::vector<struct symbol *> template_args; - scoped_restore save_field_info - = make_scoped_restore (&cu->field_info, &fi); - for (die_info *child_die : die->children ()) handle_struct_member_die (child_die, type, &fi, &template_args, cu); @@ -11308,11 +11344,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) /* Attach fields and member functions to the type. */ if (fi.nfields () > 0) - { - dwarf2_attach_fields_to_type (&fi, type, cu); - update_field_batons (&fi, type); - } - + dwarf2_attach_fields_to_type (&fi, type, cu); if (!fi.fnfieldlists.empty ()) { dwarf2_attach_fn_fields_to_type (&fi, type, cu); @@ -13927,13 +13959,12 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, case DW_AT_data_member_location: case DW_AT_data_bit_offset: { - baton = find_field_create_baton (cu, target_die->sect_off); + baton = find_field_create_baton (cu, target_die); if (baton == nullptr) return 0; baton->property_type = read_type_die (target_die->parent, target_cu); - baton->field = nullptr; prop->set_field (baton); break; } @@ -17172,29 +17203,6 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, return (sym); } -/* Given an attr with a DW_FORM_dataN value in host byte order, - zero-extend it as appropriate for the symbol's type. The DWARF - standard (v4) is not entirely clear about the meaning of using - DW_FORM_dataN for a constant with a signed type, where the type is - wider than the data. The conclusion of a discussion on the DWARF - list was that this is unspecified. We choose to always zero-extend - because that is the interpretation long in use by GCC. */ - -static void -dwarf2_const_value_data (const struct attribute *attr, LONGEST *value, - int bits) -{ - LONGEST l = attr->constant_value (0); - - if (bits < sizeof (*value) * 8) - { - l &= ((LONGEST) 1 << bits) - 1; - *value = l; - } - else - *value = l; -} - /* Read a constant value from an attribute. Either set *VALUE, or if the value does not fit in *VALUE, set *BYTES - either already allocated on the objfile obstack, or newly allocated on OBSTACK, @@ -17278,25 +17286,13 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type, converted to host endianness, so we just need to sign- or zero-extend it as appropriate. */ case DW_FORM_data1: - dwarf2_const_value_data (attr, value, 8); - break; case DW_FORM_data2: - dwarf2_const_value_data (attr, value, 16); - break; case DW_FORM_data4: - dwarf2_const_value_data (attr, value, 32); - break; case DW_FORM_data8: - dwarf2_const_value_data (attr, value, 64); - break; - case DW_FORM_sdata: case DW_FORM_implicit_const: - *value = attr->as_signed (); - break; - case DW_FORM_udata: - *value = attr->as_unsigned (); + *value = attr->confused_constant ().value_or (0); break; default: @@ -18488,39 +18484,19 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off, symbol's value "represented as it would be on the target architecture." By the time we get here, it's already been converted to host endianness, so we just need to sign- or - zero-extend it as appropriate. */ + zero-extend it as appropriate. + + Both GCC and LLVM agree that these are always signed, though. */ case DW_FORM_data1: - type = die_type (die, cu); - dwarf2_const_value_data (attr, &value, 8); - result = write_constant_as_bytes (obstack, byte_order, type, value, len); - break; case DW_FORM_data2: - type = die_type (die, cu); - dwarf2_const_value_data (attr, &value, 16); - result = write_constant_as_bytes (obstack, byte_order, type, value, len); - break; case DW_FORM_data4: - type = die_type (die, cu); - dwarf2_const_value_data (attr, &value, 32); - result = write_constant_as_bytes (obstack, byte_order, type, value, len); - break; case DW_FORM_data8: - type = die_type (die, cu); - dwarf2_const_value_data (attr, &value, 64); - result = write_constant_as_bytes (obstack, byte_order, type, value, len); - break; - case DW_FORM_sdata: case DW_FORM_implicit_const: - type = die_type (die, cu); - result = write_constant_as_bytes (obstack, byte_order, - type, attr->as_signed (), len); - break; - case DW_FORM_udata: type = die_type (die, cu); - result = write_constant_as_bytes (obstack, byte_order, - type, attr->as_unsigned (), len); + value = attr->confused_constant ().value_or (0); + result = write_constant_as_bytes (obstack, byte_order, type, value, len); break; default: @@ -19718,9 +19694,7 @@ show_check_physname (struct ui_file *file, int from_tty, value); } -void _initialize_dwarf2_read (); -void -_initialize_dwarf2_read () +INIT_GDB_FILE (dwarf2_read) { add_setshow_prefix_cmd ("dwarf", class_maintenance, _("\ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 5b4c8f6..a5cfb31 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -20,6 +20,9 @@ #ifndef GDB_DWARF2_READ_H #define GDB_DWARF2_READ_H +#if CXX_STD_THREAD +#include <mutex> +#endif #include <queue> #include "dwarf2/abbrev.h" #include "dwarf2/unit-head.h" @@ -512,8 +515,8 @@ struct dwarf2_per_bfd const char *filename () const { return bfd_get_filename (this->obfd); } - /* Return the CU given its index. */ - dwarf2_per_cu *get_cu (int index) const + /* Return the unit given its index. */ + dwarf2_per_cu *get_unit (int index) const { return this->all_units[index].get (); } @@ -522,7 +525,7 @@ struct dwarf2_per_bfd dwarf2_per_cu *get_index_cu (int index) const { if (this->all_comp_units_index_cus.empty ()) - return get_cu (index); + return get_unit (index); return this->all_comp_units_index_cus[index]; } @@ -634,6 +637,11 @@ public: /* Set of dwo_file objects. */ dwo_file_up_set dwo_files; +#if CXX_STD_THREAD + /* Mutex to synchronize access to DWO_FILES. */ + std::mutex dwo_files_lock; +#endif + /* The DWP file if there is one, or NULL. */ dwp_file_up dwp_file; @@ -702,7 +710,7 @@ public: dwarf2_per_cu *operator* () const { - return m_per_bfd->get_cu (m_index); + return m_per_bfd->get_unit (m_index); } bool operator== (const all_units_iterator &other) const @@ -1029,8 +1037,7 @@ private: dwo_file_up open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir); - void locate_dwo_sections (struct objfile *objfile, bfd *abfd, asection *sectp, - struct dwo_sections *dwo_sections); + void locate_dwo_sections (objfile *objfile, dwo_file &dwo_file); void create_dwo_unit_hash_tables (dwo_file &dwo_file, dwarf2_cu &skeleton_cu, dwarf2_section_info §ion, diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h index b9d3c31..fd6e34d 100644 --- a/gdb/dwarf2/section.h +++ b/gdb/dwarf2/section.h @@ -112,4 +112,6 @@ struct dwarf2_section_info bool is_virtual; }; +using dwarf2_section_info_up = std::unique_ptr<dwarf2_section_info>; + #endif /* GDB_DWARF2_SECTION_H */ |