/* DWARF 2 debugging format support for GDB.
- Copyright (C) 1994-2018 Free Software Foundation, Inc.
+ Copyright (C) 1994-2020 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
E.g., load_partial_dies, read_partial_die. */
#include "defs.h"
+#include "dwarf2read.h"
+#include "dwarf-index-cache.h"
+#include "dwarf-index-common.h"
#include "bfd.h"
#include "elf-bfd.h"
#include "symtab.h"
#include "buildsym.h"
#include "demangle.h"
#include "gdb-demangle.h"
-#include "expression.h"
#include "filenames.h" /* for DOSish file names */
#include "macrotab.h"
#include "language.h"
#include "complaints.h"
-#include "bcache.h"
#include "dwarf2expr.h"
#include "dwarf2loc.h"
#include "cp-support.h"
#include "addrmap.h"
#include "typeprint.h"
#include "psympriv.h"
-#include <sys/stat.h>
-#include "completer.h"
-#include "vec.h"
#include "c-lang.h"
#include "go-lang.h"
#include "valprint.h"
#include "gdbcore.h" /* for gnutarget */
#include "gdb/gdb-index.h"
-#include <ctype.h>
#include "gdb_bfd.h"
#include "f-lang.h"
#include "source.h"
-#include "filestuff.h"
#include "build-id.h"
#include "namespace.h"
-#include "common/gdb_unlinker.h"
-#include "common/function-view.h"
-#include "common/gdb_optional.h"
-#include "common/underlying.h"
-#include "common/byte-vector.h"
-#include "common/hash_enum.h"
+#include "gdbsupport/function-view.h"
+#include "gdbsupport/gdb_optional.h"
+#include "gdbsupport/underlying.h"
+#include "gdbsupport/hash_enum.h"
#include "filename-seen-cache.h"
#include "producer.h"
#include <fcntl.h>
-#include <sys/types.h>
#include <algorithm>
-#include <unordered_set>
#include <unordered_map>
-#include "selftest.h"
-#include <cmath>
-#include <set>
-#include <forward_list>
+#include "gdbsupport/selftest.h"
#include "rust-lang.h"
-#include "common/pathstuff.h"
+#include "gdbsupport/pathstuff.h"
/* When == 1, print basic high level tracing messages.
When > 1, be more verbose.
/* When non-zero, dump line number entries as they are read in. */
static unsigned int dwarf_line_debug = 0;
-/* When non-zero, cross-check physname against demangler. */
-static int check_physname = 0;
+/* When true, cross-check physname against demangler. */
+static bool check_physname = false;
-/* When non-zero, do not reject deprecated .gdb_index sections. */
-static int use_deprecated_index_sections = 0;
+/* When true, do not reject deprecated .gdb_index sections. */
+static bool use_deprecated_index_sections = false;
-static const struct objfile_data *dwarf2_objfile_data_key;
+static const struct objfile_key<dwarf2_per_objfile> dwarf2_objfile_data_key;
/* The "aclass" indices for various kinds of computed DWARF symbols. */
static int dwarf2_locexpr_block_index;
static int dwarf2_loclist_block_index;
-/* A descriptor for dwarf sections.
-
- S.ASECTION, SIZE are typically initialized when the objfile is first
- scanned. BUFFER, READIN are filled in later when the section is read.
- If the section contained compressed data then SIZE is updated to record
- the uncompressed size of the section.
-
- DWP file format V2 introduces a wrinkle that is easiest to handle by
- creating the concept of virtual sections contained within a real section.
- In DWP V2 the sections of the input DWO files are concatenated together
- into one section, but section offsets are kept relative to the original
- input section.
- If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
- the real section this "virtual" section is contained in, and BUFFER,SIZE
- describe the virtual section. */
-
-struct dwarf2_section_info
-{
- union
- {
- /* If this is a real section, the bfd section. */
- asection *section;
- /* If this is a virtual section, pointer to the containing ("real")
- section. */
- struct dwarf2_section_info *containing_section;
- } s;
- /* Pointer to section data, only valid if readin. */
- const gdb_byte *buffer;
- /* The size of the section, real or virtual. */
- bfd_size_type size;
- /* If this is a virtual section, the offset in the real section.
- Only valid if is_virtual. */
- bfd_size_type virtual_offset;
- /* True if we have tried to read this section. */
- char readin;
- /* True if this is a virtual section, False otherwise.
- This specifies which of s.section and s.containing_section to use. */
- char is_virtual;
-};
-
-typedef struct dwarf2_section_info dwarf2_section_info_def;
-DEF_VEC_O (dwarf2_section_info_def);
-
-/* All offsets in the index are of this type. It must be
- architecture-independent. */
-typedef uint32_t offset_type;
-
-/* Ensure only legit values are used. */
-#define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
- do { \
- gdb_assert ((unsigned int) (value) <= 1); \
- GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
- } while (0)
-
-/* Ensure only legit values are used. */
-#define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
- do { \
- gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
- && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
- GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
- } while (0)
-
-/* Ensure we don't use more than the alloted nuber of bits for the CU. */
-#define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
- do { \
- gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
- GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
- } while (0)
-
-#if WORDS_BIGENDIAN
-
-/* Convert VALUE between big- and little-endian. */
-
-static offset_type
-byte_swap (offset_type value)
-{
- offset_type result;
-
- result = (value & 0xff) << 24;
- result |= (value & 0xff00) << 8;
- result |= (value & 0xff0000) >> 8;
- result |= (value & 0xff000000) >> 24;
- return result;
-}
-
-#define MAYBE_SWAP(V) byte_swap (V)
-
-#else
-#define MAYBE_SWAP(V) static_cast<offset_type> (V)
-#endif /* WORDS_BIGENDIAN */
-
/* An index into a (C++) symbol name component in a symbol name as
recorded in the mapped_index's symbol table. For each C++ symbol
in the symbol table, we record one entry for the start of each
struct mapped_index_base
{
+ mapped_index_base () = default;
+ DISABLE_COPY_AND_ASSIGN (mapped_index_base);
+
/* The name_component table (a sorted vector). See name_component's
description above. */
std::vector<name_component> name_components;
vector. */
std::pair<std::vector<name_component>::const_iterator,
std::vector<name_component>::const_iterator>
- find_name_components_bounds (const lookup_name_info &ln_no_params) const;
+ find_name_components_bounds (const lookup_name_info &ln_no_params,
+ enum language lang) const;
/* Prevent deleting/destroying via a base class pointer. */
protected:
};
/* Index data format version. */
- int version;
-
- /* The total length of the buffer. */
- off_t total_size;
+ int version = 0;
/* The address table data. */
gdb::array_view<const gdb_byte> address_table;
gdb::array_view<symbol_table_slot> symbol_table;
/* A pointer to the constant pool. */
- const char *constant_pool;
+ const char *constant_pool = nullptr;
bool symbol_name_slot_invalid (offset_type idx) const override
{
const auto &bucket = this->symbol_table[idx];
- return bucket.name == 0 && bucket.vec;
+ return bucket.name == 0 && bucket.vec == 0;
}
/* Convenience method to get at the name of the symbol at IDX in the
{ return this->name_count; }
};
-typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
-DEF_VEC_P (dwarf2_per_cu_ptr);
-
-struct tu_stats
-{
- int nr_uniq_abbrev_tables;
- int nr_symtabs;
- int nr_symtab_sharers;
- int nr_stmt_less_type_units;
- int nr_all_type_units_reallocs;
-};
-
-/* Collection of data recorded per objfile.
- This hangs off of dwarf2_objfile_data_key. */
-
-struct dwarf2_per_objfile : public allocate_on_obstack
-{
- /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
- dwarf2 section names, or is NULL if the standard ELF names are
- used. */
- dwarf2_per_objfile (struct objfile *objfile,
- const dwarf2_debug_sections *names);
-
- ~dwarf2_per_objfile ();
-
- DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
-
- /* Free all cached compilation units. */
- void free_cached_comp_units ();
-private:
- /* This function is mapped across the sections and remembers the
- offset and size of each of the debugging sections we are
- interested in. */
- void locate_sections (bfd *abfd, asection *sectp,
- const dwarf2_debug_sections &names);
-
-public:
- dwarf2_section_info info {};
- dwarf2_section_info abbrev {};
- dwarf2_section_info line {};
- dwarf2_section_info loc {};
- dwarf2_section_info loclists {};
- dwarf2_section_info macinfo {};
- dwarf2_section_info macro {};
- dwarf2_section_info str {};
- dwarf2_section_info line_str {};
- dwarf2_section_info ranges {};
- dwarf2_section_info rnglists {};
- dwarf2_section_info addr {};
- dwarf2_section_info frame {};
- dwarf2_section_info eh_frame {};
- dwarf2_section_info gdb_index {};
- dwarf2_section_info debug_names {};
- dwarf2_section_info debug_aranges {};
-
- VEC (dwarf2_section_info_def) *types = NULL;
-
- /* Back link. */
- struct objfile *objfile = NULL;
-
- /* 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;
-
- /* 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;
-
- /* Table of struct type_unit_group objects.
- The hash key is the DW_AT_stmt_list value. */
- htab_t type_unit_groups {};
-
- /* A table mapping .debug_types signatures to its signatured_type entry.
- This is NULL if the .debug_types section hasn't been read in yet. */
- htab_t signatured_types {};
-
- /* Type unit statistics, to see how well the scaling improvements
- are doing. */
- struct tu_stats tu_stats {};
-
- /* A chain of compilation units that are currently read in, so that
- they can be freed later. */
- dwarf2_per_cu_data *read_in_chain = NULL;
-
- /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
- This is NULL if the table hasn't been allocated yet. */
- htab_t dwo_files {};
-
- /* True if we've checked for whether there is a DWP file. */
- bool dwp_checked = false;
-
- /* The DWP file if there is one, or NULL. */
- struct dwp_file *dwp_file = NULL;
-
- /* The shared '.dwz' file, if one exists. This is used when the
- original data was compressed using 'dwz -m'. */
- struct dwz_file *dwz_file = NULL;
-
- /* A flag indicating whether this objfile has a section loaded at a
- VMA of 0. */
- bool has_section_at_zero = false;
-
- /* True if we are using the mapped index,
- or we are faking it for OBJF_READNOW's sake. */
- bool using_index = false;
-
- /* The mapped index, or NULL if .gdb_index is missing or not being used. */
- mapped_index *index_table = NULL;
-
- /* The mapped index, or NULL if .debug_names is missing or not being used. */
- std::unique_ptr<mapped_debug_names> debug_names_table;
-
- /* When using index_table, this keeps track of all quick_file_names entries.
- TUs typically share line table entries with a CU, so we maintain a
- separate table of all line table entries to support the sharing.
- Note that while there can be way more TUs than CUs, we've already
- sorted all the TUs into "type unit groups", grouped by their
- DW_AT_stmt_list value. Therefore the only sharing done here is with a
- CU and its associated TU group if there is one. */
- htab_t quick_file_names_table {};
-
- /* Set during partial symbol reading, to prevent queueing of full
- symbols. */
- bool reading_partial_symbols = false;
-
- /* Table mapping type DIEs to their struct type *.
- This is NULL if not allocated yet.
- The mapping is done via (CU/TU + DIE offset) -> type. */
- htab_t die_type_hash {};
-
- /* The CUs we recently read. */
- VEC (dwarf2_per_cu_ptr) *just_read_cus = NULL;
-
- /* Table containing line_header indexed by offset and offset_in_dwz. */
- htab_t line_header_hash {};
-
- /* Table containing all filenames. This is an optional because the
- table is lazily constructed on first access. */
- gdb::optional<filename_seen_cache> filenames_cache;
-};
-
-/* Get the dwarf2_per_objfile associated to OBJFILE. */
+/* See dwarf2read.h. */
-struct dwarf2_per_objfile *
+dwarf2_per_objfile *
get_dwarf2_per_objfile (struct objfile *objfile)
{
- return ((struct dwarf2_per_objfile *)
- objfile_data (objfile, dwarf2_objfile_data_key));
-}
-
-/* Set the dwarf2_per_objfile associated to OBJFILE. */
-
-void
-set_dwarf2_per_objfile (struct objfile *objfile,
- struct dwarf2_per_objfile *dwarf2_per_objfile)
-{
- gdb_assert (get_dwarf2_per_objfile (objfile) == NULL);
- set_objfile_data (objfile, dwarf2_objfile_data_key, dwarf2_per_objfile);
+ return dwarf2_objfile_data_key.get (objfile);
}
/* Default names of the debugging sections. */
This will be the first byte following the compilation unit header. */
cu_offset first_die_cu_offset;
- /* 64-bit signature of this type unit - it is valid only for
- UNIT_TYPE DW_UT_type. */
+
+ /* 64-bit signature of this unit. For type units, it denotes the signature of
+ the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
+ Also used in DWARF 5, to denote the dwo id when the unit type is
+ DW_UT_skeleton or DW_UT_split_compile. */
ULONGEST signature;
/* For types, offset in the type's DIE of the type defined by this TU. */
DISABLE_COPY_AND_ASSIGN (dwarf2_cu);
+ /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
+ Create the set of symtabs used by this TU, or if this TU is sharing
+ symtabs with another TU and the symtabs have already been created
+ then restore those symtabs in the line header.
+ We don't need the pc/line-number mapping for type units. */
+ void setup_type_unit_groups (struct die_info *die);
+
+ /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
+ buildsym_compunit constructor. */
+ struct compunit_symtab *start_symtab (const char *name,
+ const char *comp_dir,
+ CORE_ADDR low_pc);
+
+ /* Reset the builder. */
+ void reset_builder () { m_builder.reset (); }
+
/* The header of the compilation unit. */
struct comp_unit_head header {};
const char *producer = nullptr;
+private:
+ /* The symtab builder for this CU. This is only non-NULL when full
+ symbols are being read. */
+ std::unique_ptr<buildsym_compunit> m_builder;
+
+public:
/* The generic symbol table building routines have separate lists for
file scope symbols and all all other scopes (local scopes). So
we need to select the right one to pass to add_symbol_to_list().
std::vector<struct type *> rust_unions;
/* Mark used when releasing cached dies. */
- unsigned int mark : 1;
+ bool 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
any location list and still facing inlining issues if handled as
unoptimized code. For a future better test see GCC PR other/32998. */
- unsigned int has_loclist : 1;
+ bool has_loclist : 1;
- /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
+ /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
if all the producer_is_* fields are valid. This information is cached
because profiling CU expansion showed excessive time spent in
producer_is_gxx_lt_4_6. */
- unsigned int checked_producer : 1;
- unsigned int producer_is_gxx_lt_4_6 : 1;
- unsigned int producer_is_gcc_lt_4_3 : 1;
- unsigned int producer_is_icc_lt_14 : 1;
-
- /* When set, the file that we're processing is known to have
+ bool checked_producer : 1;
+ bool producer_is_gxx_lt_4_6 : 1;
+ bool producer_is_gcc_lt_4_3 : 1;
+ bool producer_is_icc : 1;
+ bool producer_is_icc_lt_14 : 1;
+ bool producer_is_codewarrior : 1;
+
+ /* When true, the file that we're processing is known to have
debugging info for C++ namespaces. GCC 3.3.x did not produce
this information, but later versions do. */
- unsigned int processing_has_namespace_info : 1;
+ bool processing_has_namespace_info : 1;
struct partial_die_info *find_partial_die (sect_offset sect_off);
-};
-
-/* Persistent data held for a compilation unit, even when not
- processing it. We put a pointer to this structure in the
- read_symtab_private field of the psymtab. */
-
-struct dwarf2_per_cu_data
-{
- /* The start offset and length of this compilation unit.
- NOTE: Unlike comp_unit_head.length, this length includes
- initial_length_size.
- If the DIE refers to a DWO file, this is always of the original die,
- not the DWO file. */
- sect_offset sect_off;
- unsigned int length;
-
- /* DWARF standard version this data has been read from (such as 4 or 5). */
- short dwarf_version;
-
- /* Flag indicating this compilation unit will be read in before
- any of the current compilation units are processed. */
- unsigned int queued : 1;
-
- /* This flag will be set when reading partial DIEs if we need to load
- absolutely all DIEs for this compilation unit, instead of just the ones
- we think are interesting. It gets set if we look for a DIE in the
- hash table and don't find it. */
- unsigned int load_all_dies : 1;
-
- /* Non-zero if this CU is from .debug_types.
- Struct dwarf2_per_cu_data is contained in struct signatured_type iff
- this is non-zero. */
- unsigned int is_debug_types : 1;
-
- /* Non-zero if this CU is from the .dwz file. */
- unsigned int is_dwz : 1;
-
- /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
- This flag is only valid if is_debug_types is true.
- We can't read a CU directly from a DWO file: There are required
- attributes in the stub. */
- unsigned int reading_dwo_directly : 1;
-
- /* Non-zero if the TU has been read.
- This is used to assist the "Stay in DWO Optimization" for Fission:
- When reading a DWO, it's faster to read TUs from the DWO instead of
- fetching them from random other DWOs (due to comdat folding).
- If the TU has already been read, the optimization is unnecessary
- (and unwise - we don't want to change where gdb thinks the TU lives
- "midflight").
- This flag is only valid if is_debug_types is true. */
- unsigned int tu_read : 1;
-
- /* The section this CU/TU lives in.
- If the DIE refers to a DWO file, this is always the original die,
- not the DWO file. */
- struct dwarf2_section_info *section;
-
- /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
- of the CU cache it gets reset to NULL again. This is left as NULL for
- dummy CUs (a CU header, but nothing else). */
- struct dwarf2_cu *cu;
- /* The corresponding dwarf2_per_objfile. */
- struct dwarf2_per_objfile *dwarf2_per_objfile;
+ /* If this CU was inherited by another CU (via specification,
+ abstract_origin, etc), this is the ancestor CU. */
+ dwarf2_cu *ancestor;
- /* When dwarf2_per_objfile->using_index is true, the 'quick' field
- is active. Otherwise, the 'psymtab' field is active. */
- union
+ /* Get the buildsym_compunit for this CU. */
+ buildsym_compunit *get_builder ()
{
- /* The partial symbol table associated with this compilation unit,
- or NULL for unread partial units. */
- struct partial_symtab *psymtab;
-
- /* Data needed by the "quick" functions. */
- struct dwarf2_per_cu_quick_data *quick;
- } v;
-
- /* The CUs we import using DW_TAG_imported_unit. This is filled in
- while reading psymtabs, used to compute the psymtab dependencies,
- and then cleared. Then it is filled in again while reading full
- symbols, and only deleted when the objfile is destroyed.
-
- This is also used to work around a difference between the way gold
- generates .gdb_index version <=7 and the way gdb does. Arguably this
- is a gold bug. For symbols coming from TUs, gold records in the index
- the CU that includes the TU instead of the TU itself. This breaks
- dw2_lookup_symbol: It assumes that if the index says symbol X lives
- in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
- will find X. Alas TUs live in their own symtab, so after expanding CU Y
- we need to look in TU Z to find X. Fortunately, this is akin to
- DW_TAG_imported_unit, so we just use the same mechanism: For
- .gdb_index version <=7 this also records the TUs that the CU referred
- to. Concurrently with this change gdb was modified to emit version 8
- indices so we only pay a price for gold generated indices.
- http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
- VEC (dwarf2_per_cu_ptr) *imported_symtabs;
-};
-
-/* Entry in the signatured_types hash table. */
-
-struct signatured_type
-{
- /* The "per_cu" object of this type.
- This struct is used iff per_cu.is_debug_types.
- N.B.: This is the first member so that it's easy to convert pointers
- between them. */
- struct dwarf2_per_cu_data per_cu;
+ /* If this CU has a builder associated with it, use that. */
+ if (m_builder != nullptr)
+ return m_builder.get ();
- /* The type's signature. */
- ULONGEST signature;
-
- /* Offset in the TU of the type's DIE, as read from the TU header.
- If this TU is a DWO stub and the definition lives in a DWO file
- (specified by DW_AT_GNU_dwo_name), this value is unusable. */
- cu_offset type_offset_in_tu;
-
- /* Offset in the section of the type's DIE.
- If the definition lives in a DWO file, this is the offset in the
- .debug_types.dwo section.
- The value is zero until the actual value is known.
- Zero is otherwise not a valid section offset. */
- sect_offset type_offset_in_section;
+ /* Otherwise, search ancestors for a valid builder. */
+ if (ancestor != nullptr)
+ return ancestor->get_builder ();
- /* Type units are grouped by their DW_AT_stmt_list entry so that they
- can share them. This points to the containing symtab. */
- struct type_unit_group *type_unit_group;
-
- /* The type.
- The first time we encounter this type we fully read it in and install it
- in the symbol tables. Subsequent times we only need the type. */
- struct type *type;
-
- /* Containing DWO unit.
- This field is valid iff per_cu.reading_dwo_directly. */
- struct dwo_unit *dwo_unit;
+ return nullptr;
+ }
};
-typedef struct signatured_type *sig_type_ptr;
-DEF_VEC_P (sig_type_ptr);
-
/* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
This includes type_unit_group and quick_file_names. */
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- VEC (sig_type_ptr) *tus;
+ std::vector<signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
struct dwarf2_section_info str_offsets;
/* In the case of a virtual DWO file, these two are unused. */
struct dwarf2_section_info info;
- VEC (dwarf2_section_info_def) *types;
+ std::vector<dwarf2_section_info> types;
};
/* CUs/TUs in DWP/DWO files. */
struct dwo_file
{
+ dwo_file () = default;
+ DISABLE_COPY_AND_ASSIGN (dwo_file);
+
/* The DW_AT_GNU_dwo_name attribute.
For virtual DWO files the name is constructed from the section offsets
of abbrev,line,loc,str_offsets so that we combine virtual DWO files
from related CU+TUs. */
- const char *dwo_name;
+ const char *dwo_name = nullptr;
/* The DW_AT_comp_dir attribute. */
- const char *comp_dir;
+ const char *comp_dir = nullptr;
/* The bfd, when the file is open. Otherwise this is NULL.
This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
- bfd *dbfd;
+ gdb_bfd_ref_ptr dbfd;
/* The sections that make up this DWO file.
Remember that for virtual DWO files in DWP V2, these are virtual
sections (for lack of a better name). */
- struct dwo_sections sections;
+ struct dwo_sections sections {};
/* The CUs in the file.
Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
an extension to handle LLVM's Link Time Optimization output (where
multiple source files may be compiled into a single object/dwo pair). */
- htab_t cus;
+ htab_t cus {};
/* Table of TUs in the file.
Each element is a struct dwo_unit. */
- htab_t tus;
+ htab_t tus {};
};
/* These sections are what may appear in a DWP file. */
struct dwp_file
{
+ dwp_file (const char *name_, gdb_bfd_ref_ptr &&abfd)
+ : name (name_),
+ dbfd (std::move (abfd))
+ {
+ }
+
/* Name of the file. */
const char *name;
/* File format version. */
- int version;
+ int version = 0;
/* The bfd. */
- bfd *dbfd;
+ gdb_bfd_ref_ptr dbfd;
/* Section info for this file. */
- struct dwp_sections sections;
+ struct dwp_sections sections {};
/* Table of CUs in the file. */
- const struct dwp_hash_table *cus;
+ const struct dwp_hash_table *cus = nullptr;
/* Table of TUs in the file. */
- const struct dwp_hash_table *tus;
+ const struct dwp_hash_table *tus = nullptr;
/* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
- htab_t loaded_cus;
- htab_t loaded_tus;
+ htab_t loaded_cus {};
+ htab_t loaded_tus {};
/* Table to map ELF section numbers to their sections.
This is only needed for the DWP V1 file format. */
- unsigned int num_sections;
- asection **elf_sections;
-};
-
-/* This represents a '.dwz' file. */
-
-struct dwz_file
-{
- /* A dwz file can only contain a few sections. */
- struct dwarf2_section_info abbrev;
- struct dwarf2_section_info info;
- struct dwarf2_section_info str;
- struct dwarf2_section_info line;
- struct dwarf2_section_info macro;
- struct dwarf2_section_info gdb_index;
- struct dwarf2_section_info debug_names;
-
- /* The dwz's BFD. */
- bfd *dwz_bfd;
+ unsigned int num_sections = 0;
+ asection **elf_sections = nullptr;
};
/* Struct used to pass misc. parameters to read_die_and_children, et
int has_children,
void *data);
-/* A 1-based directory index. This is a strong typedef to prevent
- accidentally using a directory index as a 0-based index into an
- array/vector. */
-enum class dir_index : unsigned int {};
+/* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
+ later. */
+typedef int dir_index;
-/* Likewise, a 1-based file name index. */
-enum class file_name_index : unsigned int {};
+/* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
+ and later. */
+typedef int file_name_index;
struct file_entry
{
void add_file_name (const char *name, dir_index d_index,
unsigned int mod_time, unsigned int length);
- /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
- is out of bounds. */
+ /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
+ Returns NULL if INDEX is out of bounds. */
const char *include_dir_at (dir_index index) const
{
- /* Convert directory index number (1-based) to vector index
- (0-based). */
- size_t vec_index = to_underlying (index) - 1;
-
- if (vec_index >= include_dirs.size ())
+ int vec_index;
+ if (version >= 5)
+ vec_index = index;
+ else
+ vec_index = index - 1;
+ if (vec_index < 0 || vec_index >= m_include_dirs.size ())
return NULL;
- return include_dirs[vec_index];
+ return m_include_dirs[vec_index];
}
- /* Return the file name at INDEX (1-based). Returns NULL if INDEX
- is out of bounds. */
- file_entry *file_name_at (file_name_index index)
+ bool is_valid_file_index (int file_index)
{
- /* Convert file name index number (1-based) to vector index
- (0-based). */
- size_t vec_index = to_underlying (index) - 1;
-
- if (vec_index >= file_names.size ())
- return NULL;
- return &file_names[vec_index];
+ if (version >= 5)
+ return 0 <= file_index && file_index < file_names_size ();
+ return 1 <= file_index && file_index <= file_names_size ();
}
- /* Const version of the above. */
- const file_entry *file_name_at (unsigned int index) const
+ /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
+ Returns NULL if INDEX is out of bounds. */
+ file_entry *file_name_at (file_name_index index)
{
- if (index >= file_names.size ())
+ int vec_index;
+ if (version >= 5)
+ vec_index = index;
+ else
+ vec_index = index - 1;
+ if (vec_index < 0 || vec_index >= m_file_names.size ())
return NULL;
- return &file_names[index];
+ return &m_file_names[vec_index];
}
+ /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
+ this method should only be used to iterate through all file entries in an
+ index-agnostic manner. */
+ std::vector<file_entry> &file_names ()
+ { return m_file_names; }
+
/* Offset of line number information in .debug_line section. */
sect_offset sect_off {};
element is standard_opcode_lengths[opcode_base - 1]. */
std::unique_ptr<unsigned char[]> standard_opcode_lengths;
- /* The include_directories table. Note these are observing
- pointers. The memory is owned by debug_line_buffer. */
- std::vector<const char *> include_dirs;
-
- /* The file_names table. */
- std::vector<file_entry> file_names;
+ int file_names_size ()
+ { return m_file_names.size(); }
/* The start and end of the statement program following this
header. These point into dwarf2_per_objfile->line_buffer. */
const gdb_byte *statement_program_start {}, *statement_program_end {};
+
+ private:
+ /* The include_directories table. Note these are observing
+ pointers. The memory is owned by debug_line_buffer. */
+ std::vector<const char *> m_include_dirs;
+
+ /* The file_names table. This is private because the meaning of indexes
+ differs among DWARF versions (The first valid index is 1 in DWARF 4 and
+ before, and is 0 in DWARF 5 and later). So the client should use
+ file_name_at method for access. */
+ std::vector<file_entry> m_file_names;
};
typedef std::unique_ptr<line_header> line_header_up;
const gdb_byte *data;
};
-#ifndef ATTR_ALLOC_CHUNK
-#define ATTR_ALLOC_CHUNK 4
-#endif
-
-/* Allocate fields for structs, unions and enums in this size. */
-#ifndef DW_FIELD_ALLOC_CHUNK
-#define DW_FIELD_ALLOC_CHUNK 4
-#endif
-
/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
but this would require a corresponding change in unpack_field_as_long
and friends. */
/* Number of fields (including baseclasses). */
int nfields = 0;
- /* Set if the accesibility of one of the fields is not public. */
+ /* Set if the accessibility of one of the fields is not public. */
int non_public_fields = 0;
/* Member function fieldlist array, contains name of possibly overloaded
static struct partial_die_info *load_partial_dies
(const struct die_reader_specs *, const gdb_byte *, int);
-static struct partial_die_info *find_partial_die (sect_offset, int,
- struct dwarf2_cu *);
+/* A pair of partial_die_info and compilation unit. */
+struct cu_partial_die_info
+{
+ /* The compilation unit of the partial_die_info. */
+ struct dwarf2_cu *cu;
+ /* A partial_die_info. */
+ struct partial_die_info *pdi;
+
+ cu_partial_die_info (struct dwarf2_cu *cu, struct partial_die_info *pdi)
+ : cu (cu),
+ pdi (pdi)
+ { /* Nothing. */ }
+
+private:
+ cu_partial_die_info () = delete;
+};
+
+static const struct cu_partial_die_info find_partial_die (sect_offset, int,
+ struct dwarf2_cu *);
static const gdb_byte *read_attribute (const struct die_reader_specs *,
struct attribute *, struct attr_abbrev *,
static unsigned int read_2_bytes (bfd *, const gdb_byte *);
+/* Read the next three bytes (little-endian order) as an unsigned integer. */
+static unsigned int read_3_bytes (bfd *, const gdb_byte *);
+
static unsigned int read_4_bytes (bfd *, const gdb_byte *);
static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
struct dwarf2_cu *cu);
+static const char *dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu);
+
static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
struct dwarf2_cu *cu);
struct dwarf2_cu *, struct partial_symtab *,
CORE_ADDR, int decode_mapping);
-static void dwarf2_start_subfile (const char *, const char *);
-
-static struct compunit_symtab *dwarf2_start_symtab (struct dwarf2_cu *,
- const char *, const char *,
- CORE_ADDR);
+static void dwarf2_start_subfile (struct dwarf2_cu *, const char *,
+ const char *);
static struct symbol *new_symbol (struct die_info *, struct type *,
struct dwarf2_cu *, struct symbol * = NULL);
static void read_module (struct die_info *die, struct dwarf2_cu *cu);
-static struct using_direct **using_directives (enum language);
+static struct using_direct **using_directives (struct dwarf2_cu *cu);
static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
static const char *dwarf_attr_name (unsigned int);
+static const char *dwarf_unit_type_name (int unit_type);
+
static const char *dwarf_form_name (unsigned int);
static const char *dwarf_bool_name (unsigned int);
static int attr_to_dynamic_prop (const struct attribute *attr,
struct die_info *die, struct dwarf2_cu *cu,
- struct dynamic_prop *prop);
+ struct dynamic_prop *prop, struct type *type);
/* memory allocation interface */
struct die_info *comp_unit_die,
enum language pretend_language);
-static void free_cached_comp_units (void *);
-
static void age_cached_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
static int create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
-static void load_full_comp_unit (struct dwarf2_per_cu_data *,
+static void load_full_comp_unit (struct dwarf2_per_cu_data *, bool,
enum language);
static void process_full_comp_unit (struct dwarf2_per_cu_data *,
static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static struct type *dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu);
+static struct type *dwarf2_per_cu_addr_sized_int_type
+ (struct dwarf2_per_cu_data *per_cu, bool unsigned_p);
+static struct type *dwarf2_per_cu_int_type
+ (struct dwarf2_per_cu_data *per_cu, int size_in_bytes,
+ bool unsigned_p);
+
/* Class, the destructor of which frees all allocated queue entries. This
will only have work to do if an error was thrown while processing the
dwarf. If no error was thrown then the queue entries should have all
static void init_cutu_and_read_dies
(struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
- int use_existing_cu, int keep,
+ int use_existing_cu, int keep, bool skip_partial,
die_reader_func_ftype *die_reader_func, void *data);
static void init_cutu_and_read_dies_simple
static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *);
-static void free_dwo_file_cleanup (void *);
+/* A unique pointer to a dwo_file. */
-struct free_dwo_file_cleanup_data
-{
- struct dwo_file *dwo_file;
- struct dwarf2_per_objfile *dwarf2_per_objfile;
-};
+typedef std::unique_ptr<struct dwo_file> dwo_file_up;
static void process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile);
static void
dwarf2_statement_list_fits_in_line_number_section_complaint (void)
{
- complaint (&symfile_complaints,
- _("statement list doesn't fit in .debug_line section"));
+ complaint (_("statement list doesn't fit in .debug_line section"));
}
static void
dwarf2_debug_line_missing_file_complaint (void)
{
- complaint (&symfile_complaints,
- _(".debug_line section has line data without a file"));
+ complaint (_(".debug_line section has line data without a file"));
}
static void
dwarf2_debug_line_missing_end_sequence_complaint (void)
{
- complaint (&symfile_complaints,
- _(".debug_line section has line "
+ complaint (_(".debug_line section has line "
"program sequence without an end"));
}
static void
dwarf2_complex_location_expr_complaint (void)
{
- complaint (&symfile_complaints, _("location expression too complex"));
+ complaint (_("location expression too complex"));
}
static void
dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
int arg3)
{
- complaint (&symfile_complaints,
- _("const value length mismatch for '%s', got %d, expected %d"),
+ complaint (_("const value length mismatch for '%s', got %d, expected %d"),
arg1, arg2, arg3);
}
static void
dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
{
- complaint (&symfile_complaints,
- _("debug info runs off end of %s section"
+ complaint (_("debug info runs off end of %s section"
" [in module %s]"),
get_section_name (section),
get_section_file_name (section));
static void
dwarf2_macro_malformed_definition_complaint (const char *arg1)
{
- complaint (&symfile_complaints,
- _("macro debug info contains a "
+ complaint (_("macro debug info contains a "
"malformed macro definition:\n`%s'"),
arg1);
}
static void
dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
{
- complaint (&symfile_complaints,
- _("invalid attribute class or form for '%s' in '%s'"),
+ complaint (_("invalid attribute class or form for '%s' in '%s'"),
arg1, arg2);
}
{
CORE_ADDR addr;
- if (attr->form != DW_FORM_addr && attr->form != DW_FORM_GNU_addr_index)
+ if (attr->form != DW_FORM_addr && attr->form != DW_FORM_addrx
+ && attr->form != DW_FORM_GNU_addr_index)
{
/* Aside from a few clearly defined exceptions, attributes that
contain an address must always be in DW_FORM_addr form.
return addr;
}
-/* The suffix for an index file. */
-#define INDEX4_SUFFIX ".gdb-index"
-#define INDEX5_SUFFIX ".debug_names"
-#define DEBUG_STR_SUFFIX ".debug_str"
-
/* See declaration. */
dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_,
- const dwarf2_debug_sections *names)
- : objfile (objfile_)
+ const dwarf2_debug_sections *names,
+ bool can_copy_)
+ : objfile (objfile_),
+ can_copy (can_copy_)
{
if (names == NULL)
names = &dwarf2_elf_names;
locate_sections (obfd, sec, *names);
}
-static void free_dwo_files (htab_t dwo_files, struct objfile *objfile);
-
dwarf2_per_objfile::~dwarf2_per_objfile ()
{
/* Cached DIE trees use xmalloc and the comp_unit_obstack. */
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 (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 (dwarf2_per_cu_data *per_cu : all_comp_units)
+ per_cu->imported_symtabs_free ();
- VEC_free (dwarf2_section_info_def, types);
-
- if (dwo_files != NULL)
- free_dwo_files (dwo_files, objfile);
- if (dwp_file != NULL)
- gdb_bfd_unref (dwp_file->dbfd);
-
- if (dwz_file != NULL && dwz_file->dwz_bfd)
- gdb_bfd_unref (dwz_file->dwz_bfd);
-
- if (index_table != NULL)
- index_table->~mapped_index ();
+ for (signatured_type *sig_type : all_type_units)
+ sig_type->per_cu.imported_symtabs_free ();
/* Everything else should be on the objfile obstack. */
}
}
}
+/* A helper class that calls free_cached_comp_units on
+ destruction. */
+
+class free_cached_comp_units
+{
+public:
+
+ explicit free_cached_comp_units (dwarf2_per_objfile *per_objfile)
+ : m_per_objfile (per_objfile)
+ {
+ }
+
+ ~free_cached_comp_units ()
+ {
+ m_per_objfile->free_cached_comp_units ();
+ }
+
+ DISABLE_COPY_AND_ASSIGN (free_cached_comp_units);
+
+private:
+
+ dwarf2_per_objfile *m_per_objfile;
+};
+
/* Try to locate the sections we need for DWARF 2 debugging
information and return true if we have enough to do something.
NAMES points to the dwarf2 section names, or is NULL if the standard
- ELF names are used. */
+ ELF names are used. CAN_COPY is true for formats where symbol
+ interposition is possible and so symbol values must follow copy
+ relocation rules. */
int
dwarf2_has_info (struct objfile *objfile,
- const struct dwarf2_debug_sections *names)
+ const struct dwarf2_debug_sections *names,
+ bool can_copy)
{
if (objfile->flags & OBJF_READNEVER)
return 0;
= get_dwarf2_per_objfile (objfile);
if (dwarf2_per_objfile == NULL)
- {
- /* Initialize per-objfile state. */
- dwarf2_per_objfile
- = new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile,
- names);
- set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
- }
+ dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile,
+ names,
+ can_copy);
+
return (!dwarf2_per_objfile->info.is_virtual
&& dwarf2_per_objfile->info.s.section != NULL
&& !dwarf2_per_objfile->abbrev.is_virtual
asection *sectp = get_section_bfd_section (section);
gdb_assert (sectp != NULL);
- return bfd_section_name (get_section_bfd_owner (section), sectp);
+ return bfd_section_name (sectp);
}
/* Return the name of the file SECTION is in. */
asection *sectp = get_section_bfd_section (section);
gdb_assert (sectp != NULL);
- return bfd_get_section_flags (sectp->owner, sectp);
+ return bfd_section_flags (sectp);
}
/* When loading sections, we look either for uncompressed section or for
dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp,
const dwarf2_debug_sections &names)
{
- flagword aflag = bfd_get_section_flags (abfd, sectp);
+ flagword aflag = bfd_section_flags (sectp);
if ((aflag & SEC_HAS_CONTENTS) == 0)
{
}
+ else if (elf_section_data (sectp)->this_hdr.sh_size
+ > bfd_get_file_size (abfd))
+ {
+ bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size;
+ warning (_("Discarding section %s which has a section size (%s"
+ ") larger than the file size [in module %s]"),
+ bfd_section_name (sectp), phex_nz (size, sizeof (size)),
+ bfd_get_filename (abfd));
+ }
else if (section_is_p (sectp->name, &names.info))
{
this->info.s.section = sectp;
- this->info.size = bfd_get_section_size (sectp);
+ this->info.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.abbrev))
{
this->abbrev.s.section = sectp;
- this->abbrev.size = bfd_get_section_size (sectp);
+ this->abbrev.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.line))
{
this->line.s.section = sectp;
- this->line.size = bfd_get_section_size (sectp);
+ this->line.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.loc))
{
this->loc.s.section = sectp;
- this->loc.size = bfd_get_section_size (sectp);
+ this->loc.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.loclists))
{
this->loclists.s.section = sectp;
- this->loclists.size = bfd_get_section_size (sectp);
+ this->loclists.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.macinfo))
{
this->macinfo.s.section = sectp;
- this->macinfo.size = bfd_get_section_size (sectp);
+ this->macinfo.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.macro))
{
this->macro.s.section = sectp;
- this->macro.size = bfd_get_section_size (sectp);
+ this->macro.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.str))
{
this->str.s.section = sectp;
- this->str.size = bfd_get_section_size (sectp);
+ this->str.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.line_str))
{
this->line_str.s.section = sectp;
- this->line_str.size = bfd_get_section_size (sectp);
+ this->line_str.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.addr))
{
this->addr.s.section = sectp;
- this->addr.size = bfd_get_section_size (sectp);
+ this->addr.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.frame))
{
this->frame.s.section = sectp;
- this->frame.size = bfd_get_section_size (sectp);
+ this->frame.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.eh_frame))
{
this->eh_frame.s.section = sectp;
- this->eh_frame.size = bfd_get_section_size (sectp);
+ this->eh_frame.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.ranges))
{
this->ranges.s.section = sectp;
- this->ranges.size = bfd_get_section_size (sectp);
+ this->ranges.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.rnglists))
{
this->rnglists.s.section = sectp;
- this->rnglists.size = bfd_get_section_size (sectp);
+ this->rnglists.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.types))
{
memset (&type_section, 0, sizeof (type_section));
type_section.s.section = sectp;
- type_section.size = bfd_get_section_size (sectp);
+ type_section.size = bfd_section_size (sectp);
- VEC_safe_push (dwarf2_section_info_def, this->types,
- &type_section);
+ this->types.push_back (type_section);
}
else if (section_is_p (sectp->name, &names.gdb_index))
{
this->gdb_index.s.section = sectp;
- this->gdb_index.size = bfd_get_section_size (sectp);
+ this->gdb_index.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.debug_names))
{
this->debug_names.s.section = sectp;
- this->debug_names.size = bfd_get_section_size (sectp);
+ this->debug_names.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names.debug_aranges))
{
this->debug_aranges.s.section = sectp;
- this->debug_aranges.size = bfd_get_section_size (sectp);
+ this->debug_aranges.size = bfd_section_size (sectp);
}
- if ((bfd_get_section_flags (abfd, sectp) & (SEC_LOAD | SEC_ALLOC))
- && bfd_section_vma (abfd, sectp) == 0)
+ if ((bfd_section_flags (sectp) & (SEC_LOAD | SEC_ALLOC))
+ && bfd_section_vma (sectp) == 0)
this->has_section_at_zero = true;
}
return section->s.section == NULL || section->size == 0;
}
-/* Read the contents of the section INFO.
- OBJFILE is the main object file, but not necessarily the file where
- the section comes from. E.g., for DWO files the bfd of INFO is the bfd
- of the DWO file.
- If the section is compressed, uncompress it before returning. */
+/* See dwarf2read.h. */
-static void
-dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
+void
+dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
{
asection *sectp;
bfd *abfd;
if (info->readin)
return;
info->buffer = NULL;
- info->readin = 1;
+ info->readin = true;
if (dwarf2_section_empty_p (info))
return;
{
error (_("Dwarf Error: Can't read DWARF data"
" in section %s [in module %s]"),
- bfd_section_name (abfd, sectp), bfd_get_filename (abfd));
+ bfd_section_name (sectp), bfd_get_filename (abfd));
}
}
asection **sectp, const gdb_byte **bufp,
bfd_size_type *sizep)
{
- struct dwarf2_per_objfile *data
- = (struct dwarf2_per_objfile *) objfile_data (objfile,
- dwarf2_objfile_data_key);
+ struct dwarf2_per_objfile *data = dwarf2_objfile_data_key.get (objfile);
struct dwarf2_section_info *info;
/* We may see an objfile without any DWARF, in which case we just
if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
{
dwz_file->abbrev.s.section = sectp;
- dwz_file->abbrev.size = bfd_get_section_size (sectp);
+ dwz_file->abbrev.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
{
dwz_file->info.s.section = sectp;
- dwz_file->info.size = bfd_get_section_size (sectp);
+ dwz_file->info.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
{
dwz_file->str.s.section = sectp;
- dwz_file->str.size = bfd_get_section_size (sectp);
+ dwz_file->str.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
{
dwz_file->line.s.section = sectp;
- dwz_file->line.size = bfd_get_section_size (sectp);
+ dwz_file->line.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
{
dwz_file->macro.s.section = sectp;
- dwz_file->macro.size = bfd_get_section_size (sectp);
+ dwz_file->macro.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
{
dwz_file->gdb_index.s.section = sectp;
- dwz_file->gdb_index.size = bfd_get_section_size (sectp);
+ dwz_file->gdb_index.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &dwarf2_elf_names.debug_names))
{
dwz_file->debug_names.s.section = sectp;
- dwz_file->debug_names.size = bfd_get_section_size (sectp);
+ dwz_file->debug_names.size = bfd_section_size (sectp);
}
}
-/* Open the separate '.dwz' debug file, if needed. Return NULL if
- there is no .gnu_debugaltlink section in the file. Error if there
- is such a section but the file cannot be found. */
+/* See dwarf2read.h. */
-static struct dwz_file *
+struct dwz_file *
dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
const char *filename;
- struct dwz_file *result;
bfd_size_type buildid_len_arg;
size_t buildid_len;
bfd_byte *buildid;
if (dwarf2_per_objfile->dwz_file != NULL)
- return dwarf2_per_objfile->dwz_file;
+ return dwarf2_per_objfile->dwz_file.get ();
bfd_set_error (bfd_error_no_error);
gdb::unique_xmalloc_ptr<char> data
if (dwz_bfd != NULL)
{
if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
- dwz_bfd.release ();
+ dwz_bfd.reset (nullptr);
}
if (dwz_bfd == NULL)
error (_("could not find '.gnu_debugaltlink' file for %s"),
objfile_name (dwarf2_per_objfile->objfile));
- result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
- struct dwz_file);
- result->dwz_bfd = dwz_bfd.release ();
+ std::unique_ptr<struct dwz_file> result
+ (new struct dwz_file (std::move (dwz_bfd)));
- bfd_map_over_sections (result->dwz_bfd, locate_dwz_sections, result);
+ bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
+ result.get ());
- gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, result->dwz_bfd);
- dwarf2_per_objfile->dwz_file = result;
- return result;
+ gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd,
+ result->dwz_bfd.get ());
+ dwarf2_per_objfile->dwz_file = std::move (result);
+ return dwarf2_per_objfile->dwz_file.get ();
}
\f
/* DWARF quick_symbols_functions support. */
processing PER_CU->CU. dw2_setup must have been already called. */
static void
-load_cu (struct dwarf2_per_cu_data *per_cu)
+load_cu (struct dwarf2_per_cu_data *per_cu, bool skip_partial)
{
if (per_cu->is_debug_types)
load_full_type_unit (per_cu);
else
- load_full_comp_unit (per_cu, language_minimal);
+ load_full_comp_unit (per_cu, skip_partial, language_minimal);
if (per_cu->cu == NULL)
return; /* Dummy CU. */
/* Read in the symbols for PER_CU. */
static void
-dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
+dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial)
{
struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
: (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
{
queue_comp_unit (per_cu, language_minimal);
- load_cu (per_cu);
+ load_cu (per_cu, skip_partial);
/* If we just loaded a CU from a DWO, and we're working with an index
that may badly handle TUs, load all the TUs in that DWO as well.
table. */
static struct compunit_symtab *
-dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
+dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial)
{
struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
gdb_assert (dwarf2_per_objfile->using_index);
if (!per_cu->v.quick->compunit_symtab)
{
- struct cleanup *back_to = make_cleanup (free_cached_comp_units,
- dwarf2_per_objfile);
+ free_cached_comp_units freer (dwarf2_per_objfile);
scoped_restore decrementer = increment_reading_symtab ();
- dw2_do_instantiate_symtab (per_cu);
+ dw2_do_instantiate_symtab (per_cu, skip_partial);
process_cu_includes (dwarf2_per_objfile);
- do_cleanups (back_to);
}
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->all_comp_units.size ())
+ {
+ index -= this->all_comp_units.size ();
+ gdb_assert (index < this->all_type_units.size ());
+ 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->all_comp_units.size ());
- 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->all_type_units.size ());
- 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
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)
+ int is_dwz)
{
- 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);
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);
}
}
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);
-
- 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 (objfile, cu_list, cu_list_elements,
- &dwarf2_per_objfile->info, 0, 0);
+ create_cus_from_index_list (dwarf2_per_objfile, cu_list, cu_list_elements,
+ &dwarf2_per_objfile->info, 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);
}
/* 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
- = 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);
- 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;
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;
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);
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
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;
iter = index->address_table.data ();
end = iter + index->address_table.size ();
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
while (iter < end)
{
if (lo > hi)
{
- complaint (&symfile_complaints,
- _(".gdb_index address table has invalid range (%s - %s)"),
+ complaint (_(".gdb_index address table has invalid range (%s - %s)"),
hex_string (lo), hex_string (hi));
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"),
+ complaint (_(".gdb_index address table has invalid CU number %u"),
(unsigned) cu_index);
continue;
}
- lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
- hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
+ lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseaddr;
+ hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - 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,
- &objfile->objfile_obstack);
+ objfile->partial_symtabs->psymtabs_addrmap
+ = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
}
/* Read the address map data from DWARF-5 .debug_aranges, and use it to
struct objfile *objfile = dwarf2_per_objfile->objfile;
bfd *abfd = objfile->obfd;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
- SECT_OFF_TEXT (objfile));
+ const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
auto_obstack temp_obstack;
addrmap *mutable_map = addrmap_create_mutable (&temp_obstack);
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 = dw2_get_cutu (dwarf2_per_objfile, cui);
const auto insertpair
= debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu);
if (!insertpair.second)
const uint8_t offset_size = dwarf5_is_dwarf64 ? 8 : 4;
if (addr + entry_length > section->buffer + section->size)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"length %s exceeds section length %s, "
"ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer,
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
plongest (bytes_read + entry_length),
pulongest (section->size));
return;
addr += 2;
if (version != 2)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"has unsupported version %d, ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer,
- version);
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer), version);
return;
}
= debug_info_offset_to_per_cu.find (sect_offset (debug_info_offset));
if (per_cu_it == debug_info_offset_to_per_cu.cend ())
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"debug_info_offset %s does not exists, "
"ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer,
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
pulongest (debug_info_offset));
return;
}
const uint8_t address_size = *addr++;
if (address_size < 1 || address_size > 8)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"address_size %u is invalid, ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer,
- address_size);
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer), address_size);
return;
}
const uint8_t segment_selector_size = *addr++;
if (segment_selector_size != 0)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"segment_selector_size %u is not supported, "
"ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer,
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
segment_selector_size);
return;
}
padding > 0; padding--)
if (*addr++ != 0)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"padding is not zero, ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer);
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer));
return;
}
{
if (addr + 2 * address_size > entry_end)
{
- warning (_("Section .debug_aranges in %s entry at offset %zu "
+ warning (_("Section .debug_aranges in %s entry at offset %s "
"address list is not properly terminated, "
"ignoring .debug_aranges."),
- objfile_name (objfile), entry_addr - section->buffer);
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer));
return;
}
ULONGEST start = extract_unsigned_integer (addr, address_size,
continue;
}
ULONGEST end = start + length;
- start = gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr);
- end = gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr);
+ start = (gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr)
+ - baseaddr);
+ end = (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr)
+ - baseaddr);
addrmap_set_empty (mutable_map, start, end - 1, per_cu);
}
}
- objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
- &objfile->objfile_obstack);
-}
-
-/* The hash function for strings in the mapped index. This is the same as
- SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
- implementation. This is necessary because the hash function is tied to the
- format of the mapped index file. The hash values do not have to match with
- SYMBOL_HASH_NEXT.
-
- Use INT_MAX for INDEX_VERSION if you generate the current index format. */
-
-static hashval_t
-mapped_index_string_hash (int index_version, const void *p)
-{
- const unsigned char *str = (const unsigned char *) p;
- hashval_t r = 0;
- unsigned char c;
-
- while ((c = *str++) != 0)
- {
- if (index_version >= 5)
- c = tolower (c);
- r = r * 67 + c - 113;
- }
-
- return r;
+ objfile->partial_symtabs->psymtabs_addrmap
+ = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
}
/* Find a slot in the mapped index INDEX for the object named NAME.
}
}
-/* A helper function that reads the .gdb_index from SECTION and fills
- in MAP. FILENAME is the name of the file containing the section;
- it is used for error reporting. DEPRECATED_OK is nonzero if it is
+/* A helper function that reads the .gdb_index from BUFFER and fills
+ in MAP. FILENAME is the name of the file containing the data;
+ it is used for error reporting. DEPRECATED_OK is true if it is
ok to use deprecated sections.
CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
out parameters that are filled in with information about the CU and
TU lists in the section.
- Returns 1 if all went well, 0 otherwise. */
-
-static int
-read_index_from_section (struct objfile *objfile,
- const char *filename,
- int deprecated_ok,
- struct dwarf2_section_info *section,
- struct mapped_index *map,
- const gdb_byte **cu_list,
- offset_type *cu_list_elements,
- const gdb_byte **types_list,
- offset_type *types_list_elements)
-{
- const gdb_byte *addr;
- offset_type version;
- offset_type *metadata;
- int i;
-
- if (dwarf2_section_empty_p (section))
- return 0;
-
- /* Older elfutils strip versions could keep the section in the main
- executable while splitting it for the separate debug info file. */
- if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
- return 0;
+ Returns true if all went well, false otherwise. */
- dwarf2_read_section (objfile, section);
+static bool
+read_gdb_index_from_buffer (struct objfile *objfile,
+ const char *filename,
+ bool deprecated_ok,
+ gdb::array_view<const gdb_byte> buffer,
+ struct mapped_index *map,
+ const gdb_byte **cu_list,
+ offset_type *cu_list_elements,
+ const gdb_byte **types_list,
+ offset_type *types_list_elements)
+{
+ const gdb_byte *addr = &buffer[0];
- addr = section->buffer;
/* Version check. */
- version = MAYBE_SWAP (*(offset_type *) addr);
+ offset_type version = MAYBE_SWAP (*(offset_type *) addr);
/* Versions earlier than 3 emitted every copy of a psymbol. This
causes the index to behave very poorly for certain requests. Version 3
contained incomplete addrmap. So, it seems better to just ignore such
return 0;
map->version = version;
- map->total_size = section->size;
- metadata = (offset_type *) (addr + sizeof (offset_type));
+ offset_type *metadata = (offset_type *) (addr + sizeof (offset_type));
- i = 0;
+ int i = 0;
*cu_list = addr + MAYBE_SWAP (metadata[i]);
*cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
/ 8);
return 1;
}
+/* Callback types for dwarf2_read_gdb_index. */
+
+typedef gdb::function_view
+ <gdb::array_view<const gdb_byte>(objfile *, dwarf2_per_objfile *)>
+ get_gdb_index_contents_ftype;
+typedef gdb::function_view
+ <gdb::array_view<const gdb_byte>(objfile *, dwz_file *)>
+ get_gdb_index_contents_dwz_ftype;
+
/* Read .gdb_index. If everything went ok, initialize the "quick"
elements of all the CUs and return 1. Otherwise, return 0. */
static int
-dwarf2_read_index (struct objfile *objfile)
+dwarf2_read_gdb_index
+ (struct dwarf2_per_objfile *dwarf2_per_objfile,
+ get_gdb_index_contents_ftype get_gdb_index_contents,
+ get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
{
- 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;
+
+ gdb::array_view<const gdb_byte> main_index_contents
+ = get_gdb_index_contents (objfile, dwarf2_per_objfile);
- if (!read_index_from_section (objfile, objfile_name (objfile),
- use_deprecated_index_sections,
- &dwarf2_per_objfile->gdb_index, &local_map,
- &cu_list, &cu_list_elements,
- &types_list, &types_list_elements))
+ if (main_index_contents.empty ())
+ return 0;
+
+ std::unique_ptr<struct mapped_index> map (new struct mapped_index);
+ if (!read_gdb_index_from_buffer (objfile, objfile_name (objfile),
+ use_deprecated_index_sections,
+ main_index_contents, map.get (), &cu_list,
+ &cu_list_elements, &types_list,
+ &types_list_elements))
return 0;
/* Don't use the index if it's empty. */
- if (local_map.symbol_table.empty ())
+ if (map->symbol_table.empty ())
return 0;
/* If there is a .dwz file, read it so we can get its CU list as
const gdb_byte *dwz_types_ignore;
offset_type dwz_types_elements_ignore;
- if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
- 1,
- &dwz->gdb_index, &dwz_map,
- &dwz_list, &dwz_list_elements,
- &dwz_types_ignore,
- &dwz_types_elements_ignore))
+ gdb::array_view<const gdb_byte> dwz_index_content
+ = get_gdb_index_contents_dwz (objfile, dwz);
+
+ if (dwz_index_content.empty ())
+ return 0;
+
+ if (!read_gdb_index_from_buffer (objfile,
+ bfd_get_filename (dwz->dwz_bfd.get ()),
+ 1, dwz_index_content, &dwz_map,
+ &dwz_list, &dwz_list_elements,
+ &dwz_types_ignore,
+ &dwz_types_elements_ignore))
{
warning (_("could not read '.gdb_index' section from %s; skipping"),
- bfd_get_filename (dwz->dwz_bfd));
+ bfd_get_filename (dwz->dwz_bfd.get ()));
return 0;
}
}
- 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)
{
- struct dwarf2_section_info *section;
-
/* We can only handle a single .debug_types when we have an
index. */
- if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
+ if (dwarf2_per_objfile->types.size () != 1)
return 0;
- section = VEC_index (dwarf2_section_info_def,
- dwarf2_per_objfile->types, 0);
+ dwarf2_section_info *section = &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);
+ create_addrmap_from_index (dwarf2_per_objfile, map.get ());
- map = XOBNEW (&objfile->objfile_obstack, struct mapped_index);
- map = new (map) mapped_index ();
- *map = local_map;
-
- dwarf2_per_objfile->index_table = map;
+ dwarf2_per_objfile->index_table = std::move (map);
dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table =
- create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
+ create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ());
return 1;
}
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwarf2_per_cu_data *lh_cu;
struct attribute *attr;
- int i;
void **slot;
struct quick_file_names *qfn;
sect_offset line_offset {};
attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
- if (attr)
+ if (attr != nullptr)
{
struct quick_file_names find_entry;
file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
- qfn->num_file_names = lh->file_names.size ();
+ int offset = 0;
+ if (strcmp (fnd.name, "<unknown>") != 0)
+ ++offset;
+
+ qfn->num_file_names = offset + lh->file_names_size ();
qfn->file_names =
- XOBNEWVEC (&objfile->objfile_obstack, const char *, lh->file_names.size ());
- for (i = 0; i < lh->file_names.size (); ++i)
- qfn->file_names[i] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
+ XOBNEWVEC (&objfile->objfile_obstack, const char *, qfn->num_file_names);
+ if (offset != 0)
+ qfn->file_names[0] = xstrdup (fnd.name);
+ for (int i = 0; i < lh->file_names_size (); ++i)
+ qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
qfn->real_names = NULL;
lh_cu->v.quick->file_names = qfn;
{
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);
- compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu);
+ dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->all_comp_units.back ();
+ compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu, false);
if (cust == NULL)
return NULL;
/* This may expand more than one symtab, and we want to iterate over
all of them. */
- dw2_instantiate_symtab (per_cu);
+ dw2_instantiate_symtab (per_cu, false);
return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
last_made, callback);
(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);
/* 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;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, 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;
{
/* The dwarf2_per_objfile owning the CUs we are iterating on. */
struct dwarf2_per_objfile *dwarf2_per_objfile;
- /* If non-zero, only look for symbols that match BLOCK_INDEX. */
- int want_specific_block;
- /* One of GLOBAL_BLOCK or STATIC_BLOCK.
- Unused if !WANT_SPECIFIC_BLOCK. */
- int block_index;
+ /* If set, only look for symbols that match that block. Valid values are
+ GLOBAL_BLOCK and STATIC_BLOCK. */
+ gdb::optional<block_enum> block_index;
/* The kind of symbol we're looking for. */
domain_enum domain;
/* The list of CUs from the index entry of the symbol,
int global_seen;
};
-/* Initialize the index symtab iterator ITER.
- If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
- in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
+/* Initialize the index symtab iterator ITER. */
static void
dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
struct dwarf2_per_objfile *dwarf2_per_objfile,
- int want_specific_block,
- int block_index,
+ gdb::optional<block_enum> block_index,
domain_enum domain,
const char *name)
{
iter->dwarf2_per_objfile = dwarf2_per_objfile;
- iter->want_specific_block = want_specific_block;
iter->block_index = block_index;
iter->domain = domain;
iter->next = 0;
iter->global_seen = 0;
- mapped_index *index = dwarf2_per_objfile->index_table;
+ mapped_index *index = dwarf2_per_objfile->index_table.get ();
/* index is NULL if OBJF_READNOW. */
if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec))
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);
gdb_index_symbol_kind symbol_kind =
GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
/* Only check the symbol attributes if they're present.
&& symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
/* Don't crash on bad data. */
- if (cu_index >= (dwarf2_per_objfile->n_comp_units
- + dwarf2_per_objfile->n_type_units))
+ if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
+ + dwarf2_per_objfile->all_type_units.size ()))
{
- complaint (&symfile_complaints,
- _(".gdb_index entry has bad CU index"
+ complaint (_(".gdb_index entry has bad CU index"
" [in module %s]"),
objfile_name (dwarf2_per_objfile->objfile));
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)
/* Check static vs global. */
if (attrs_valid)
{
- if (iter->want_specific_block
- && want_static != is_static)
- continue;
+ bool is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
+
+ if (iter->block_index.has_value ())
+ {
+ bool want_static = *iter->block_index == STATIC_BLOCK;
+
+ if (is_static != want_static)
+ continue;
+ }
+
/* Work around gold/15646. */
if (!is_static && iter->global_seen)
continue;
if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
continue;
break;
+ case MODULE_DOMAIN:
+ if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
+ continue;
+ break;
default:
break;
}
}
static struct compunit_symtab *
-dw2_lookup_symbol (struct objfile *objfile, int block_index,
+dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
const char *name, domain_enum domain)
{
struct compunit_symtab *stab_best = NULL;
struct dw2_symtab_iterator iter;
struct dwarf2_per_cu_data *per_cu;
- dw2_symtab_iter_init (&iter, dwarf2_per_objfile, 1, block_index, domain, name);
+ dw2_symtab_iter_init (&iter, dwarf2_per_objfile, block_index, domain, name);
while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
{
struct symbol *sym, *with_opaque = NULL;
- struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu);
+ struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu, false);
const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
- struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+ const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
sym = block_find_symbol (block, name, domain,
block_find_non_opaque_type_preferred,
{
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->all_type_units.size ());
int count = 0;
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;
}
static void
-dw2_relocate (struct objfile *objfile,
- const struct section_offsets *new_offsets,
- const struct section_offsets *delta)
-{
- /* There's nothing to relocate here. */
-}
-
-static void
-dw2_expand_symtabs_for_function (struct objfile *objfile,
- const char *func_name)
+dw2_expand_symtabs_for_function (struct objfile *objfile,
+ const char *func_name)
{
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
struct dw2_symtab_iterator iter;
struct dwarf2_per_cu_data *per_cu;
- /* Note: It doesn't matter what we pass for block_index here. */
- dw2_symtab_iter_init (&iter, dwarf2_per_objfile, 0, GLOBAL_BLOCK, VAR_DOMAIN,
- func_name);
+ dw2_symtab_iter_init (&iter, dwarf2_per_objfile, {}, VAR_DOMAIN, func_name);
while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
- dw2_instantiate_symtab (per_cu);
+ dw2_instantiate_symtab (per_cu, false);
}
{
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- int total_units = (dwarf2_per_objfile->n_comp_units
- + dwarf2_per_objfile->n_type_units);
+ int total_units = (dwarf2_per_objfile->all_comp_units.size ()
+ + dwarf2_per_objfile->all_type_units.size ());
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);
+ /* We don't want to directly expand a partial CU, because if we
+ read it with the wrong language, then assertion failures can
+ be triggered later on. See PR symtab/23010. So, tell
+ dw2_instantiate_symtab to skip partial CUs -- any important
+ partial CU will be read via DW_TAG_imported_unit anyway. */
+ dw2_instantiate_symtab (per_cu, true);
}
}
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;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, 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];
if (filename_cmp (this_fullname, fullname) == 0)
{
- dw2_instantiate_symtab (per_cu);
+ dw2_instantiate_symtab (per_cu, false);
break;
}
}
}
static void
-dw2_map_matching_symbols (struct objfile *objfile,
- const char * name, domain_enum domain,
- int global,
- int (*callback) (struct block *,
- struct symbol *, void *),
- void *data, symbol_name_match_type match,
- symbol_compare_ftype *ordered_compare)
+dw2_map_matching_symbols
+ (struct objfile *objfile,
+ const lookup_name_info &name, domain_enum domain,
+ int global,
+ gdb::function_view<symbol_found_callback_ftype> callback,
+ symbol_compare_ftype *ordered_compare)
{
/* Currently unimplemented; used for Ada. The function can be called if the
current language is Ada for a non-Ada objfile using GNU index. As Ada
does not look for non-Ada symbols this function should just return. */
}
-/* Symbol name matcher for .gdb_index names.
-
- Symbol names in .gdb_index have a few particularities:
-
- - There's no indication of which is the language of each symbol.
-
- Since each language has its own symbol name matching algorithm,
- and we don't know which language is the right one, we must match
- each symbol against all languages. This would be a potential
- performance problem if it were not mitigated by the
- mapped_index::name_components lookup table, which significantly
- reduces the number of times we need to call into this matcher,
- making it a non-issue.
-
- - Symbol names in the index have no overload (parameter)
- information. I.e., in C++, "foo(int)" and "foo(long)" both
- appear as "foo" in the index, for example.
-
- This means that the lookup names passed to the symbol name
- matcher functions must have no parameter information either
- because (e.g.) symbol search name "foo" does not match
- lookup-name "foo(int)" [while swapping search name for lookup
- name would match].
-*/
-class gdb_index_symbol_name_matcher
-{
-public:
- /* Prepares the vector of comparison functions for LOOKUP_NAME. */
- gdb_index_symbol_name_matcher (const lookup_name_info &lookup_name);
-
- /* Walk all the matcher routines and match SYMBOL_NAME against them.
- Returns true if any matcher matches. */
- bool matches (const char *symbol_name);
-
-private:
- /* A reference to the lookup name we're matching against. */
- const lookup_name_info &m_lookup_name;
-
- /* A vector holding all the different symbol name matchers, for all
- languages. */
- std::vector<symbol_name_matcher_ftype *> m_symbol_name_matcher_funcs;
-};
-
-gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
- (const lookup_name_info &lookup_name)
- : m_lookup_name (lookup_name)
-{
- /* Prepare the vector of comparison functions upfront, to avoid
- doing the same work for each symbol. Care is taken to avoid
- matching with the same matcher more than once if/when multiple
- languages use the same matcher function. */
- auto &matchers = m_symbol_name_matcher_funcs;
- matchers.reserve (nr_languages);
-
- matchers.push_back (default_symbol_name_matcher);
-
- for (int i = 0; i < nr_languages; i++)
- {
- const language_defn *lang = language_def ((enum language) i);
- symbol_name_matcher_ftype *name_matcher
- = get_symbol_name_matcher (lang, m_lookup_name);
-
- /* Don't insert the same comparison routine more than once.
- Note that we do this linear walk instead of a seemingly
- cheaper sorted insert, or use a std::set or something like
- that, because relative order of function addresses is not
- stable. This is not a problem in practice because the number
- of supported languages is low, and the cost here is tiny
- compared to the number of searches we'll do afterwards using
- this object. */
- if (name_matcher != default_symbol_name_matcher
- && (std::find (matchers.begin (), matchers.end (), name_matcher)
- == matchers.end ()))
- matchers.push_back (name_matcher);
- }
-}
-
-bool
-gdb_index_symbol_name_matcher::matches (const char *symbol_name)
-{
- for (auto matches_name : m_symbol_name_matcher_funcs)
- if (matches_name (symbol_name, m_lookup_name, NULL))
- return true;
-
- return false;
-}
-
/* Starting from a search name, return the string that finds the upper
bound of all strings that start with SEARCH_NAME in a sorted name
list. Returns the empty string to indicate that the upper bound is
std::pair<std::vector<name_component>::const_iterator,
std::vector<name_component>::const_iterator>
mapped_index_base::find_name_components_bounds
- (const lookup_name_info &lookup_name_without_params) const
+ (const lookup_name_info &lookup_name_without_params, language lang) const
{
auto *name_cmp
= this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
- const char *cplus
- = lookup_name_without_params.cplus ().lookup_name ().c_str ();
+ const char *lang_name
+ = lookup_name_without_params.language_lookup_name (lang).c_str ();
/* Comparison function object for lower_bound that matches against a
given symbol name. */
/* Find the lower bound. */
auto lower = [&] ()
{
- if (lookup_name_without_params.completion_mode () && cplus[0] == '\0')
+ if (lookup_name_without_params.completion_mode () && lang_name[0] == '\0')
return begin;
else
- return std::lower_bound (begin, end, cplus, lookup_compare_lower);
+ return std::lower_bound (begin, end, lang_name, lookup_compare_lower);
} ();
/* Find the upper bound. */
We find the upper bound by looking for the insertion
point of "func"-with-last-character-incremented,
i.e. "fund". */
- std::string after = make_sort_after_prefix_name (cplus);
+ std::string after = make_sort_after_prefix_name (lang_name);
if (after.empty ())
return end;
return std::lower_bound (lower, end, after.c_str (),
lookup_compare_lower);
}
else
- return std::upper_bound (lower, end, cplus, lookup_compare_upper);
+ return std::upper_bound (lower, end, lang_name, lookup_compare_upper);
} ();
return {lower, upper};
/* The code below only knows how to break apart components of C++
symbol names (and other languages that use '::' as
- namespace/module separator). If we add support for wild matching
- to some language that uses some other operator (E.g., Ada, Go and
- D use '.'), then we'll need to try splitting the symbol name
- according to that language too. Note that Ada does support wild
- matching, but doesn't currently support .gdb_index. */
+ namespace/module separator) and Ada symbol names. */
auto count = this->symbol_name_count ();
for (offset_type idx = 0; idx < count; idx++)
{
/* Add each name component to the name component table. */
unsigned int previous_len = 0;
- for (unsigned int current_len = cp_find_first_component (name);
- name[current_len] != '\0';
- current_len += cp_find_first_component (name + current_len))
+
+ if (strstr (name, "::") != nullptr)
+ {
+ for (unsigned int current_len = cp_find_first_component (name);
+ name[current_len] != '\0';
+ current_len += cp_find_first_component (name + current_len))
+ {
+ gdb_assert (name[current_len] == ':');
+ this->name_components.push_back ({previous_len, idx});
+ /* Skip the '::'. */
+ current_len += 2;
+ previous_len = current_len;
+ }
+ }
+ else
{
- gdb_assert (name[current_len] == ':');
- this->name_components.push_back ({previous_len, idx});
- /* Skip the '::'. */
- current_len += 2;
- previous_len = current_len;
+ /* Handle the Ada encoded (aka mangled) form here. */
+ for (const char *iter = strstr (name, "__");
+ iter != nullptr;
+ iter = strstr (iter, "__"))
+ {
+ this->name_components.push_back ({previous_len, idx});
+ iter += 2;
+ previous_len = iter - name;
+ }
}
+
this->name_components.push_back ({previous_len, idx});
}
const lookup_name_info &lookup_name_in,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
enum search_domain kind,
- gdb::function_view<void (offset_type)> match_callback)
+ gdb::function_view<bool (offset_type)> match_callback)
{
lookup_name_info lookup_name_without_params
= lookup_name_in.make_ignore_params ();
- gdb_index_symbol_name_matcher lookup_name_matcher
- (lookup_name_without_params);
/* Build the symbol name component sorted vector, if we haven't
yet. */
index.build_name_components ();
- auto bounds = index.find_name_components_bounds (lookup_name_without_params);
-
- /* Now for each symbol name in range, check to see if we have a name
- match, and if so, call the MATCH_CALLBACK callback. */
-
/* The same symbol may appear more than once in the range though.
E.g., if we're looking for symbols that complete "w", and we have
a symbol named "w1::w2", we'll find the two name components for
indexes that matched in a temporary vector and ignore
duplicates. */
std::vector<offset_type> matches;
- matches.reserve (std::distance (bounds.first, bounds.second));
- for (; bounds.first != bounds.second; ++bounds.first)
+ struct name_and_matcher
+ {
+ symbol_name_matcher_ftype *matcher;
+ const std::string &name;
+
+ bool operator== (const name_and_matcher &other) const
+ {
+ return matcher == other.matcher && name == other.name;
+ }
+ };
+
+ /* A vector holding all the different symbol name matchers, for all
+ languages. */
+ std::vector<name_and_matcher> matchers;
+
+ for (int i = 0; i < nr_languages; i++)
{
- const char *qualified = index.symbol_name_at (bounds.first->idx);
+ enum language lang_e = (enum language) i;
+
+ const language_defn *lang = language_def (lang_e);
+ symbol_name_matcher_ftype *name_matcher
+ = get_symbol_name_matcher (lang, lookup_name_without_params);
+
+ name_and_matcher key {
+ name_matcher,
+ lookup_name_without_params.language_lookup_name (lang_e)
+ };
- if (!lookup_name_matcher.matches (qualified)
- || (symbol_matcher != NULL && !symbol_matcher (qualified)))
+ /* Don't insert the same comparison routine more than once.
+ Note that we do this linear walk. This is not a problem in
+ practice because the number of supported languages is
+ low. */
+ if (std::find (matchers.begin (), matchers.end (), key)
+ != matchers.end ())
continue;
+ matchers.push_back (std::move (key));
+
+ auto bounds
+ = index.find_name_components_bounds (lookup_name_without_params,
+ lang_e);
+
+ /* Now for each symbol name in range, check to see if we have a name
+ match, and if so, call the MATCH_CALLBACK callback. */
+
+ for (; bounds.first != bounds.second; ++bounds.first)
+ {
+ const char *qualified = index.symbol_name_at (bounds.first->idx);
+
+ if (!name_matcher (qualified, lookup_name_without_params, NULL)
+ || (symbol_matcher != NULL && !symbol_matcher (qualified)))
+ continue;
- matches.push_back (bounds.first->idx);
+ matches.push_back (bounds.first->idx);
+ }
}
std::sort (matches.begin (), matches.end ());
{
if (prev != idx)
{
- match_callback (idx);
+ if (!match_callback (idx))
+ break;
prev = idx;
}
}
DISABLE_COPY_AND_ASSIGN (mock_mapped_index);
/* Return the number of names in the symbol table. */
- virtual size_t symbol_name_count () const
+ size_t symbol_name_count () const override
{
return m_symbol_table.size ();
}
/* Get the name of the symbol at IDX in the symbol table. */
- virtual const char *symbol_name_at (offset_type idx) const
+ const char *symbol_name_at (offset_type idx) const override
{
return m_symbol_table[idx];
}
if (expected_str == NULL || strcmp (expected_str, matched_name) != 0)
mismatch (expected_str, matched_name);
+ return true;
});
const char *expected_str
lookup_name_info lookup_name (search_name,
symbol_name_match_type::FULL, true);
- auto bounds = index.find_name_components_bounds (lookup_name);
+ auto bounds = index.find_name_components_bounds (lookup_name,
+ language_cplus);
size_t distance = std::distance (bounds.first, bounds.second);
if (distance != expected_syms.size ())
bool symtab_was_null
= (per_cu->v.quick->compunit_symtab == NULL);
- dw2_instantiate_symtab (per_cu);
+ dw2_instantiate_symtab (per_cu, false);
if (expansion_notify != NULL
&& symtab_was_null
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);
if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
continue;
break;
+ case MODULES_DOMAIN:
+ if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
+ continue;
+ break;
default:
break;
}
}
/* Don't crash on bad data. */
- if (cu_index >= (dwarf2_per_objfile->n_comp_units
- + dwarf2_per_objfile->n_type_units))
+ if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
+ + dwarf2_per_objfile->all_type_units.size ()))
{
- complaint (&symfile_complaints,
- _(".gdb_index entry has bad CU index"
+ complaint (_(".gdb_index entry has bad CU index"
" [in module %s]"),
objfile_name (dwarf2_per_objfile->objfile));
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);
}
/* 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;
- struct dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, i);
- struct quick_file_names *file_data;
- void **slot;
-
QUIT;
per_cu->v.quick->mark = 0;
if (per_cu->v.quick->compunit_symtab)
continue;
- file_data = dw2_get_file_names (per_cu);
+ quick_file_names *file_data = dw2_get_file_names (per_cu);
if (file_data == NULL)
continue;
continue;
}
- for (j = 0; j < file_data->num_file_names; ++j)
+ for (int j = 0; j < file_data->num_file_names; ++j)
{
const char *this_real_name;
}
}
- slot = htab_find_slot (per_cu->v.quick->mark
- ? visited_found.get ()
- : visited_not_found.get (),
- file_data, INSERT);
+ void **slot = htab_find_slot (per_cu->v.quick->mark
+ ? visited_found.get ()
+ : visited_not_found.get (),
+ file_data, INSERT);
*slot = file_data;
}
}
{
dw2_expand_marked_cus (dwarf2_per_objfile, idx, file_matcher,
expansion_notify, kind);
+ return true;
});
}
struct dwarf2_per_cu_data *data;
struct compunit_symtab *result;
- if (!objfile->psymtabs_addrmap)
+ if (!objfile->partial_symtabs->psymtabs_addrmap)
return NULL;
- data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->psymtabs_addrmap,
- pc);
+ CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+ data = (struct dwarf2_per_cu_data *) addrmap_find
+ (objfile->partial_symtabs->psymtabs_addrmap, pc - baseaddr);
if (!data)
return NULL;
paddress (get_objfile_arch (objfile), pc));
result
- = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data),
+ = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data,
+ false),
pc);
gdb_assert (result != NULL);
return result;
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 = dw2_get_cutu (dwarf2_per_objfile, i);
-
if (per_cu->v.quick->compunit_symtab)
{
void **slot = htab_find_slot (visited.get (),
}
}
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_per_cu_data *per_cu = dw2_get_cu (dwarf2_per_objfile, 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. */
dw2_lookup_symbol,
dw2_print_stats,
dw2_dump,
- dw2_relocate,
dw2_expand_symtabs_for_function,
dw2_expand_all_symtabs,
dw2_expand_symtabs_with_fullname,
const gdb_byte *abbrev_table_start = addr;
for (;;)
{
- unsigned int bytes_read;
const ULONGEST index_num = read_unsigned_leb128 (abfd, addr, &bytes_read);
addr += bytes_read;
if (index_num == 0)
if (addr != abbrev_table_start + abbrev_table_size)
{
warning (_("Section .debug_names in %s has abbreviation_table "
- "of size %zu vs. written as %u, ignoring .debug_names."),
- filename, addr - abbrev_table_start, abbrev_table_size);
+ "of size %s vs. written as %u, ignoring .debug_names."),
+ filename, plongest (addr - abbrev_table_start),
+ abbrev_table_size);
return false;
}
map.entry_pool = addr;
create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
const mapped_debug_names &map,
dwarf2_section_info §ion,
- bool is_dwz, int base_offset)
+ bool is_dwz)
{
sect_offset sect_off_prev;
for (uint32_t i = 0; i <= map.cu_count; ++i)
if (i >= 1)
{
const ULONGEST length = sect_off_next - sect_off_prev;
- dwarf2_per_objfile->all_comp_units[base_offset + (i - 1)]
+ dwarf2_per_cu_data *per_cu
= create_cu_from_index_list (dwarf2_per_objfile, §ion, is_dwz,
sect_off_prev, length);
+ dwarf2_per_objfile->all_comp_units.push_back (per_cu);
}
sect_off_prev = sect_off_next;
}
const mapped_debug_names &map,
const mapped_debug_names &dwz_map)
{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- dwarf2_per_objfile->n_comp_units = map.cu_count + dwz_map.cu_count;
- dwarf2_per_objfile->all_comp_units
- = XOBNEWVEC (&objfile->objfile_obstack, struct dwarf2_per_cu_data *,
- dwarf2_per_objfile->n_comp_units);
+ gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
+ dwarf2_per_objfile->all_comp_units.reserve (map.cu_count + dwz_map.cu_count);
create_cus_from_debug_names_list (dwarf2_per_objfile, map,
dwarf2_per_objfile->info,
- false /* is_dwz */,
- 0 /* base_offset */);
+ false /* is_dwz */);
if (dwz_map.cu_count == 0)
return;
dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
- true /* is_dwz */,
- map.cu_count /* base_offset */);
+ true /* is_dwz */);
}
/* Read .debug_names. If everything went ok, initialize the "quick"
static bool
dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- mapped_debug_names local_map (dwarf2_per_objfile);
+ std::unique_ptr<mapped_debug_names> map
+ (new mapped_debug_names (dwarf2_per_objfile));
mapped_debug_names dwz_map (dwarf2_per_objfile);
struct objfile *objfile = dwarf2_per_objfile->objfile;
if (!read_debug_names_from_section (objfile, objfile_name (objfile),
&dwarf2_per_objfile->debug_names,
- local_map))
+ *map))
return false;
/* Don't use the index if it's empty. */
- if (local_map.name_count == 0)
+ if (map->name_count == 0)
return false;
/* If there is a .dwz file, read it so we can get its CU list as
if (dwz != NULL)
{
if (!read_debug_names_from_section (objfile,
- bfd_get_filename (dwz->dwz_bfd),
+ bfd_get_filename (dwz->dwz_bfd.get ()),
&dwz->debug_names, dwz_map))
{
warning (_("could not read '.debug_names' section from %s; skipping"),
- bfd_get_filename (dwz->dwz_bfd));
+ bfd_get_filename (dwz->dwz_bfd.get ()));
return false;
}
}
- create_cus_from_debug_names (dwarf2_per_objfile, local_map, dwz_map);
+ create_cus_from_debug_names (dwarf2_per_objfile, *map, dwz_map);
- if (local_map.tu_count != 0)
+ if (map->tu_count != 0)
{
/* We can only handle a single .debug_types when we have an
index. */
- if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
+ if (dwarf2_per_objfile->types.size () != 1)
return false;
- dwarf2_section_info *section = VEC_index (dwarf2_section_info_def,
- dwarf2_per_objfile->types, 0);
+ dwarf2_section_info *section = &dwarf2_per_objfile->types[0];
create_signatured_type_table_from_debug_names
- (dwarf2_per_objfile, local_map, section, &dwarf2_per_objfile->abbrev);
+ (dwarf2_per_objfile, *map, section, &dwarf2_per_objfile->abbrev);
}
create_addrmap_from_aranges (dwarf2_per_objfile,
&dwarf2_per_objfile->debug_aranges);
- dwarf2_per_objfile->debug_names_table.reset
- (new mapped_debug_names (dwarf2_per_objfile));
- *dwarf2_per_objfile->debug_names_table = std::move (local_map);
+ dwarf2_per_objfile->debug_names_table = std::move (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;
}
-/* Symbol name hashing function as specified by DWARF-5. */
-
-static uint32_t
-dwarf5_djb_hash (const char *str_)
-{
- const unsigned char *str = (const unsigned char *) str_;
-
- /* Note: tolower here ignores UTF-8, which isn't fully compliant.
- See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
-
- uint32_t hash = 5381;
- while (int c = *str++)
- hash = hash * 33 + tolower (c);
- return hash;
-}
-
/* Type used to manage iterating over all CUs looking for a symbol for
.debug_names. */
class dw2_debug_names_iterator
{
public:
- /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
- BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
dw2_debug_names_iterator (const mapped_debug_names &map,
- bool want_specific_block,
- block_enum block_index, domain_enum domain,
+ gdb::optional<block_enum> block_index,
+ domain_enum domain,
const char *name)
- : m_map (map), m_want_specific_block (want_specific_block),
- m_block_index (block_index), m_domain (domain),
+ : m_map (map), m_block_index (block_index), m_domain (domain),
m_addr (find_vec_in_debug_names (map, name))
{}
m_addr (find_vec_in_debug_names (map, namei))
{}
+ dw2_debug_names_iterator (const mapped_debug_names &map,
+ block_enum block_index, domain_enum domain,
+ uint32_t namei)
+ : m_map (map), m_block_index (block_index), m_domain (domain),
+ m_addr (find_vec_in_debug_names (map, namei))
+ {}
+
/* Return the next matching CU or NULL if there are no more. */
dwarf2_per_cu_data *next ();
/* The internalized form of .debug_names. */
const mapped_debug_names &m_map;
- /* If true, only look for symbols that match BLOCK_INDEX. */
- const bool m_want_specific_block = false;
-
- /* One of GLOBAL_BLOCK or STATIC_BLOCK.
- Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
- value. */
- const block_enum m_block_index = FIRST_LOCAL_BLOCK;
+ /* If set, only look for symbols that match that block. Valid values are
+ GLOBAL_BLOCK and STATIC_BLOCK. */
+ const gdb::optional<block_enum> m_block_index;
/* The kind of symbol we're looking for. */
const domain_enum m_domain = UNDEF_DOMAIN;
{
int (*cmp) (const char *, const char *);
+ gdb::unique_xmalloc_ptr<char> without_params;
if (current_language->la_language == language_cplus
|| current_language->la_language == language_fortran
|| current_language->la_language == language_d)
if (strchr (name, '(') != NULL)
{
- gdb::unique_xmalloc_ptr<char> without_params
- = cp_remove_params (name);
-
+ without_params = cp_remove_params (name);
if (without_params != NULL)
- {
- name = without_params.get();
- }
+ name = without_params.get ();
}
}
--namei;
if (namei >= map.name_count)
{
- complaint (&symfile_complaints,
- _("Wrong .debug_names with name index %u but name_count=%u "
+ complaint (_("Wrong .debug_names with name index %u but name_count=%u "
"[in module %s]"),
namei, map.name_count,
objfile_name (map.dwarf2_per_objfile->objfile));
#if 0 /* An expensive sanity check. */
if (namei_full_hash != dwarf5_djb_hash (namei_string))
{
- complaint (&symfile_complaints,
- _("Wrong .debug_names hash for string at index %u "
+ complaint (_("Wrong .debug_names hash for string at index %u "
"[in module %s]"),
namei, objfile_name (dwarf2_per_objfile->objfile));
return NULL;
{
if (namei >= map.name_count)
{
- complaint (&symfile_complaints,
- _("Wrong .debug_names with name index %u but name_count=%u "
+ complaint (_("Wrong .debug_names with name index %u but name_count=%u "
"[in module %s]"),
namei, map.name_count,
objfile_name (map.dwarf2_per_objfile->objfile));
const auto indexval_it = m_map.abbrev_map.find (abbrev);
if (indexval_it == m_map.abbrev_map.cend ())
{
- complaint (&symfile_complaints,
- _("Wrong .debug_names undefined abbrev code %s "
+ complaint (_("Wrong .debug_names undefined abbrev code %s "
"[in module %s]"),
pulongest (abbrev), objfile_name (objfile));
return NULL;
}
const mapped_debug_names::index_val &indexval = indexval_it->second;
- bool have_is_static = false;
- bool is_static;
+ enum class symbol_linkage {
+ unknown,
+ static_,
+ extern_,
+ } symbol_linkage_ = symbol_linkage::unknown;
dwarf2_per_cu_data *per_cu = NULL;
for (const mapped_debug_names::index_val::attr &attr : indexval.attr_vec)
{
m_addr += bytes_read;
break;
default:
- complaint (&symfile_complaints,
- _("Unsupported .debug_names form %s [in module %s]"),
+ complaint (_("Unsupported .debug_names form %s [in module %s]"),
dwarf_form_name (attr.form),
objfile_name (objfile));
return NULL;
{
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"
+ complaint (_(".debug_names entry has bad CU index %s"
" [in module %s]"),
pulongest (ull),
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. */
- 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"
+ complaint (_(".debug_names entry has bad TU index %s"
" [in module %s]"),
pulongest (ull),
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)
break;
- have_is_static = true;
- is_static = true;
+ symbol_linkage_ = symbol_linkage::static_;
break;
case DW_IDX_GNU_external:
if (!m_map.augmentation_is_gdb)
break;
- have_is_static = true;
- is_static = false;
+ symbol_linkage_ = symbol_linkage::extern_;
break;
}
}
goto again;
/* Check static vs global. */
- if (have_is_static)
+ if (symbol_linkage_ != symbol_linkage::unknown && m_block_index.has_value ())
{
- const bool want_static = m_block_index != GLOBAL_BLOCK;
- if (m_want_specific_block && want_static != is_static)
- goto again;
+ const bool want_static = *m_block_index == STATIC_BLOCK;
+ const bool symbol_is_static =
+ symbol_linkage_ == symbol_linkage::static_;
+ if (want_static != symbol_is_static)
+ goto again;
}
/* Match dw2_symtab_iter_next, symbol_kind
goto again;
}
break;
+ case MODULE_DOMAIN:
+ switch (indexval.dwarf_tag)
+ {
+ case DW_TAG_module:
+ break;
+ default:
+ goto again;
+ }
+ break;
default:
break;
}
goto again;
}
break;
+ case MODULES_DOMAIN:
+ switch (indexval.dwarf_tag)
+ {
+ case DW_TAG_module:
+ break;
+ default:
+ goto again;
+ }
default:
break;
}
}
static struct compunit_symtab *
-dw2_debug_names_lookup_symbol (struct objfile *objfile, int block_index_int,
+dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
const char *name, domain_enum domain)
{
- const block_enum block_index = static_cast<block_enum> (block_index_int);
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
}
const auto &map = *mapp;
- dw2_debug_names_iterator iter (map, true /* want_specific_block */,
- block_index, domain, name);
+ dw2_debug_names_iterator iter (map, block_index, domain, name);
struct compunit_symtab *stab_best = NULL;
struct dwarf2_per_cu_data *per_cu;
while ((per_cu = iter.next ()) != NULL)
{
struct symbol *sym, *with_opaque = NULL;
- struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu);
+ struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu, false);
const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
- struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+ const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
sym = block_find_symbol (block, name, domain,
block_find_non_opaque_type_preferred,
information (but NAME might contain it). */
if (sym != NULL
- && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
+ && strcmp_iw (sym->search_name (), name) == 0)
return stab;
if (with_opaque != NULL
- && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque), name) == 0)
+ && strcmp_iw (with_opaque->search_name (), name) == 0)
stab_best = stab;
/* Keep looking through other CUs. */
{
const mapped_debug_names &map = *dwarf2_per_objfile->debug_names_table;
- /* Note: It doesn't matter what we pass for block_index here. */
- dw2_debug_names_iterator iter (map, false /* want_specific_block */,
- GLOBAL_BLOCK, VAR_DOMAIN, func_name);
+ dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name);
+
+ struct dwarf2_per_cu_data *per_cu;
+ while ((per_cu = iter.next ()) != NULL)
+ dw2_instantiate_symtab (per_cu, false);
+ }
+}
+
+static void
+dw2_debug_names_map_matching_symbols
+ (struct objfile *objfile,
+ const lookup_name_info &name, domain_enum domain,
+ int global,
+ gdb::function_view<symbol_found_callback_ftype> callback,
+ symbol_compare_ftype *ordered_compare)
+{
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);
+
+ /* debug_names_table is NULL if OBJF_READNOW. */
+ if (!dwarf2_per_objfile->debug_names_table)
+ return;
+
+ mapped_debug_names &map = *dwarf2_per_objfile->debug_names_table;
+ const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+
+ const char *match_name = name.ada ().lookup_name ().c_str ();
+ auto matcher = [&] (const char *symname)
+ {
+ if (ordered_compare == nullptr)
+ return true;
+ return ordered_compare (symname, match_name) == 0;
+ };
+
+ dw2_expand_symtabs_matching_symbol (map, name, matcher, ALL_DOMAIN,
+ [&] (offset_type namei)
+ {
+ /* The name was matched, now expand corresponding CUs that were
+ marked. */
+ dw2_debug_names_iterator iter (map, block_kind, domain, namei);
struct dwarf2_per_cu_data *per_cu;
while ((per_cu = iter.next ()) != NULL)
- dw2_instantiate_symtab (per_cu);
+ dw2_expand_symtabs_matching_one (per_cu, nullptr, nullptr);
+ return true;
+ });
+
+ /* It's a shame we couldn't do this inside the
+ dw2_expand_symtabs_matching_symbol callback, but that skips CUs
+ that have already been expanded. Instead, this loop matches what
+ the psymtab code does. */
+ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
+ {
+ struct compunit_symtab *cust = per_cu->v.quick->compunit_symtab;
+ if (cust != nullptr)
+ {
+ const struct block *block
+ = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
+ if (!iterate_over_symbols_terminated (block, name,
+ domain, callback))
+ break;
+ }
}
}
while ((per_cu = iter.next ()) != NULL)
dw2_expand_symtabs_matching_one (per_cu, file_matcher,
expansion_notify);
+ return true;
});
}
dw2_debug_names_lookup_symbol,
dw2_print_stats,
dw2_debug_names_dump,
- dw2_relocate,
dw2_debug_names_expand_symtabs_for_function,
dw2_expand_all_symtabs,
dw2_expand_symtabs_with_fullname,
- dw2_map_matching_symbols,
+ dw2_debug_names_map_matching_symbols,
dw2_debug_names_expand_symtabs_matching,
dw2_find_pc_sect_compunit_symtab,
NULL,
dw2_map_symbol_filenames
};
+/* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
+ to either a dwarf2_per_objfile or dwz_file object. */
+
+template <typename T>
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_section (objfile *obj, T *section_owner)
+{
+ dwarf2_section_info *section = §ion_owner->gdb_index;
+
+ if (dwarf2_section_empty_p (section))
+ return {};
+
+ /* Older elfutils strip versions could keep the section in the main
+ executable while splitting it for the separate debug info file. */
+ if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
+ return {};
+
+ dwarf2_read_section (obj, section);
+
+ /* dwarf2_section_info::size is a bfd_size_type, while
+ gdb::array_view works with size_t. On 32-bit hosts, with
+ --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
+ is 32-bit. So we need an explicit narrowing conversion here.
+ This is fine, because it's impossible to allocate or mmap an
+ array/buffer larger than what size_t can represent. */
+ return gdb::make_array_view (section->buffer, section->size);
+}
+
+/* Lookup the index cache for the contents of the index associated to
+ DWARF2_OBJ. */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache (objfile *obj, dwarf2_per_objfile *dwarf2_obj)
+{
+ const bfd_build_id *build_id = build_id_bfd_get (obj->obfd);
+ if (build_id == nullptr)
+ return {};
+
+ return global_index_cache.lookup_gdb_index (build_id,
+ &dwarf2_obj->index_cache_res);
+}
+
+/* Same as the above, but for DWZ. */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz)
+{
+ const bfd_build_id *build_id = build_id_bfd_get (dwz->dwz_bfd.get ());
+ if (build_id == nullptr)
+ return {};
+
+ return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
+}
+
/* See symfile.h. */
bool
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->all_type_units.size ()); ++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);
return true;
}
- if (dwarf2_read_index (objfile))
+ if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+ get_gdb_index_contents_from_section<struct dwarf2_per_objfile>,
+ get_gdb_index_contents_from_section<dwz_file>))
+ {
+ *index_kind = dw_index_kind::GDB_INDEX;
+ return true;
+ }
+
+ /* ... otherwise, try to find the index in the index cache. */
+ if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+ get_gdb_index_contents_from_cache,
+ get_gdb_index_contents_from_cache_dwz))
{
+ global_index_cache.hit ();
*index_kind = dw_index_kind::GDB_INDEX;
return true;
}
+ global_index_cache.miss ();
return false;
}
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
- if (objfile->global_psymbols.capacity () == 0
- && objfile->static_psymbols.capacity () == 0)
- init_psymbol_list (objfile, 1024);
+ init_psymbol_list (objfile, 1024);
- TRY
+ try
{
/* This isn't really ideal: all the data we allocate on the
objfile's obstack is still uselessly kept around. However,
psymtab_discarder psymtabs (objfile);
dwarf2_build_psymtabs_hard (dwarf2_per_objfile);
psymtabs.keep ();
+
+ /* (maybe) store an index in the cache. */
+ global_index_cache.store (dwarf2_per_objfile);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
exception_print (gdb_stderr, except);
}
- END_CATCH
}
/* Return the total length of the CU described by HEADER. */
cu->base_address = 0;
attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
- if (attr)
+ if (attr != nullptr)
{
cu->base_address = attr_value_as_address (attr);
cu->base_known = 1;
else
{
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
- if (attr)
+ if (attr != nullptr)
{
cu->base_address = attr_value_as_address (attr);
cu->base_known = 1;
cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
info_ptr += bytes_read;
cu_header->version = read_2_bytes (abfd, info_ptr);
+ if (cu_header->version < 2 || cu_header->version > 5)
+ error (_("Dwarf Error: wrong version in compilation unit header "
+ "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
+ cu_header->version, filename);
info_ptr += 2;
if (cu_header->version < 5)
switch (section_kind)
switch (cu_header->unit_type)
{
case DW_UT_compile:
+ case DW_UT_partial:
+ case DW_UT_skeleton:
+ case DW_UT_split_compile:
if (section_kind != rcuh_kind::COMPILE)
error (_("Dwarf Error: wrong unit_type in compilation unit header "
- "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
- filename);
+ "(is %s, should be %s) [in module %s]"),
+ dwarf_unit_type_name (cu_header->unit_type),
+ dwarf_unit_type_name (DW_UT_type), filename);
break;
case DW_UT_type:
+ case DW_UT_split_type:
section_kind = rcuh_kind::TYPE;
break;
default:
error (_("Dwarf Error: wrong unit_type in compilation unit header "
- "(is %d, should be %d or %d) [in module %s]"),
- cu_header->unit_type, DW_UT_compile, DW_UT_type, filename);
+ "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
+ "[in module %s]"), cu_header->unit_type,
+ dwarf_unit_type_name (DW_UT_compile),
+ dwarf_unit_type_name (DW_UT_skeleton),
+ dwarf_unit_type_name (DW_UT_split_compile),
+ dwarf_unit_type_name (DW_UT_type),
+ dwarf_unit_type_name (DW_UT_split_type), filename);
}
cu_header->addr_size = read_1_byte (abfd, info_ptr);
_("read_comp_unit_head: dwarf from non elf file"));
cu_header->signed_addr_p = signed_addr;
- if (section_kind == rcuh_kind::TYPE)
- {
- LONGEST type_offset;
+ bool header_has_signature = section_kind == rcuh_kind::TYPE
+ || cu_header->unit_type == DW_UT_skeleton
+ || cu_header->unit_type == DW_UT_split_compile;
+ if (header_has_signature)
+ {
cu_header->signature = read_8_bytes (abfd, info_ptr);
info_ptr += 8;
+ }
+ if (section_kind == rcuh_kind::TYPE)
+ {
+ LONGEST type_offset;
type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read);
info_ptr += bytes_read;
cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
{
const char *filename = get_section_file_name (section);
- if (header->version < 2 || header->version > 5)
- error (_("Dwarf Error: wrong version in compilation unit header "
- "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header->version,
- filename);
-
if (to_underlying (header->abbrev_sect_off)
>= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
error (_("Dwarf Error: bad offset (%s) in compilation unit header "
subpst->dirname = pst->dirname;
}
- subpst->textlow = 0;
- subpst->texthigh = 0;
-
- subpst->dependencies
- = XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
+ subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1);
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
- subpst->globals_offset = 0;
- subpst->n_global_syms = 0;
- subpst->statics_offset = 0;
- subpst->n_static_syms = 0;
- subpst->compunit_symtab = NULL;
subpst->read_symtab = pst->read_symtab;
- subpst->readin = 0;
/* No private part is necessary for include psymtabs. This property
can be used to differentiate between such include psymtabs and
struct attribute *attr;
attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
- if (attr)
+ if (attr != nullptr)
lh = dwarf_decode_line_header ((sect_offset) DW_UNSND (attr), cu);
if (lh == NULL)
return; /* No linetable, so no includes. */
- /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
- dwarf_decode_lines (lh.get (), pst->dirname, cu, pst, pst->textlow, 1);
+ /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
+ that we pass in the raw text_low here; that is ok because we're
+ only decoding the line table to make include partial symtabs, and
+ so the addresses aren't really used. */
+ dwarf_decode_lines (lh.get (), pst->dirname, cu, pst,
+ pst->raw_text_low (), 1);
}
static hashval_t
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;
}
dup_sect_off = dup_tu->per_cu.sect_off;
}
- complaint (&symfile_complaints,
- _("debug type entry at offset %s is duplicate to"
+ complaint (_("debug type entry at offset %s is duplicate to"
" the entry at offset %s, signature %s"),
sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
hex_string (header.signature));
static void
create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
struct dwo_file *dwo_file,
- VEC (dwarf2_section_info_def) *types,
+ gdb::array_view<dwarf2_section_info> type_sections,
htab_t &types_htab)
{
- int ix;
- struct dwarf2_section_info *section;
-
- if (VEC_empty (dwarf2_section_info_def, types))
- return;
-
- for (ix = 0;
- VEC_iterate (dwarf2_section_info_def, types, ix, section);
- ++ix)
- create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, section,
+ for (dwarf2_section_info §ion : type_sections)
+ create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, §ion,
types_htab, rcuh_kind::TYPE);
}
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,
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;
}
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;
+
+ signatured_type *sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct signatured_type);
- sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
- struct signatured_type);
- dwarf2_per_objfile->all_type_units[n_type_units - 1] = sig_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)
comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
/* There should be a DW_AT_addr_base attribute here (if needed).
- We need the value before we can process DW_FORM_GNU_addr_index. */
+ We need the value before we can process DW_FORM_GNU_addr_index
+ or DW_FORM_addrx. */
cu->addr_base = 0;
attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu);
- if (attr)
+ if (attr != nullptr)
cu->addr_base = DW_UNSND (attr);
/* There should be a DW_AT_ranges_base attribute here (if needed).
We need the value before we can process DW_AT_ranges. */
cu->ranges_base = 0;
attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_ranges_base, cu);
- if (attr)
+ if (attr != nullptr)
cu->ranges_base = DW_UNSND (attr);
}
else if (stub_comp_dir != NULL)
return 1;
}
+/* Return the signature of the compile unit, if found. In DWARF 4 and before,
+ the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
+ signature is part of the header. */
+static gdb::optional<ULONGEST>
+lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
+{
+ if (cu->header.version >= 5)
+ return cu->header.signature;
+ struct attribute *attr;
+ attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
+ if (attr == nullptr)
+ return gdb::optional<ULONGEST> ();
+ return DW_UNSND (attr);
+}
+
/* Subroutine of init_cutu_and_read_dies to simplify it.
Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
Returns NULL if the specified DWO unit cannot be found. */
struct die_info *comp_unit_die)
{
struct dwarf2_cu *cu = this_cu->cu;
- ULONGEST signature;
struct dwo_unit *dwo_unit;
const char *comp_dir, *dwo_name;
gdb_assert (cu != NULL);
/* Yeah, we look dwo_name up again, but it simplifies the code. */
- dwo_name = dwarf2_string_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
+ dwo_name = dwarf2_dwo_name (comp_unit_die, cu);
comp_dir = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
if (this_cu->is_debug_types)
/* Since this_cu is the first member of struct signatured_type,
we can go from a pointer to one to a pointer to the other. */
sig_type = (struct signatured_type *) this_cu;
- signature = sig_type->signature;
dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir);
}
else
{
- struct attribute *attr;
-
- attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
- if (! attr)
+ gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
+ if (!signature.has_value ())
error (_("Dwarf Error: missing dwo_id for dwo_name %s"
" [in module %s]"),
dwo_name, objfile_name (this_cu->dwarf2_per_objfile->objfile));
- signature = DW_UNSND (attr);
dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir,
- signature);
+ *signature);
}
return dwo_unit;
init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
struct abbrev_table *abbrev_table,
int use_existing_cu, int keep,
+ bool skip_partial,
die_reader_func_ftype *die_reader_func,
void *data)
{
struct die_reader_specs reader;
struct die_info *comp_unit_die;
int has_children;
- struct attribute *attr;
struct signatured_type *sig_type = NULL;
struct dwarf2_section_info *abbrev_section;
/* Non-zero if CU currently points to a DWO file and we need to
init_cu_die_reader (&reader, cu, section, NULL, abbrev_table);
info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
+ if (skip_partial && comp_unit_die->tag == DW_TAG_partial_unit)
+ return;
+
/* If we are in a DWO stub, process it and then read in the "real" CU/TU
from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
table from the DWO file and pass the ownership over to us. It will be
Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
DWO CU, that this test will fail (the attribute will not be present). */
- attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
+ const char *dwo_name = dwarf2_dwo_name (comp_unit_die, cu);
abbrev_table_up dwo_abbrev_table;
- if (attr)
+ if (dwo_name != nullptr)
{
struct dwo_unit *dwo_unit;
struct die_info *dwo_comp_unit_die;
if (has_children)
{
- complaint (&symfile_complaints,
- _("compilation unit with DW_AT_GNU_dwo_name"
+ complaint (_("compilation unit with DW_AT_GNU_dwo_name"
" has children (offset %s) [in module %s]"),
sect_offset_str (this_cu->sect_off),
bfd_get_filename (abfd));
{
unsigned int line_offset = to_underlying (line_offset_struct);
struct partial_symtab *pst;
- char *name;
+ std::string name;
/* Give the symtab a useful name for debug purposes. */
if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
- name = xstrprintf ("<type_units_%d>",
- (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
+ name = string_printf ("<type_units_%d>",
+ (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
else
- name = xstrprintf ("<type_units_at_0x%x>", line_offset);
+ name = string_printf ("<type_units_at_0x%x>", line_offset);
- pst = create_partial_symtab (per_cu, name);
+ pst = create_partial_symtab (per_cu, name.c_str ());
pst->anonymous = 1;
-
- xfree (name);
}
tu_group->hash.dwo_unit = cu->dwo_unit;
struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
struct partial_symtab *pst;
- pst = start_psymtab_common (objfile, name, 0,
- objfile->global_psymbols,
- objfile->static_psymbols);
+ pst = start_psymtab_common (objfile, name, 0);
pst->psymtabs_addrmap_supported = 1;
prepare_one_comp_unit (cu, comp_unit_die, info->pretend_language);
- cu->list_in_scope = &file_symbols;
-
/* Allocate a new partial symbol table structure. */
filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu);
if (filename == NULL)
/* This must be done before calling dwarf2_build_include_psymtabs. */
pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
dwarf2_find_base_address (comp_unit_die, cu);
cu_bounds_kind = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
&best_highpc, cu, pst);
if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
- /* Store the contiguous range if it is not empty; it can be empty for
- CUs with no code. */
- addrmap_set_empty (objfile->psymtabs_addrmap,
- gdbarch_adjust_dwarf2_addr (gdbarch,
- best_lowpc + baseaddr),
- gdbarch_adjust_dwarf2_addr (gdbarch,
- best_highpc + baseaddr) - 1,
- pst);
+ {
+ CORE_ADDR low
+ = (gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr)
+ - baseaddr);
+ CORE_ADDR high
+ = (gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr)
+ - baseaddr - 1);
+ /* Store the contiguous range if it is not empty; it can be
+ empty for CUs with no code. */
+ addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+ low, high, pst);
+ }
/* Check if comp unit has_children.
If so, read the rest of the partial symbols from this comp unit.
best_highpc = highpc;
}
}
- pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr);
- pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr);
+ pst->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch,
+ best_lowpc + baseaddr)
+ - baseaddr);
+ pst->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch,
+ best_highpc + baseaddr)
+ - baseaddr);
end_psymtab_common (objfile, pst);
- if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs))
+ if (!cu->per_cu->imported_symtabs_empty ())
{
int i;
- int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
- struct dwarf2_per_cu_data *iter;
+ int len = cu->per_cu->imported_symtabs_size ();
/* Fill in 'dependencies' here; we fill in 'users' in a
post-pass. */
pst->number_of_dependencies = len;
- pst->dependencies =
- XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
- for (i = 0;
- VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
- i, iter);
- ++i)
- pst->dependencies[i] = iter->v.psymtab;
+ pst->dependencies
+ = objfile->partial_symtabs->allocate_dependencies (len);
+ for (i = 0; i < len; ++i)
+ {
+ pst->dependencies[i]
+ = cu->per_cu->imported_symtabs->at (i)->v.psymtab;
+ }
- VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
+ cu->per_cu->imported_symtabs_free ();
}
/* Get the list of files included in the current compilation unit,
dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
if (dwarf_read_debug)
- {
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
-
- fprintf_unfiltered (gdb_stdlog,
- "Psymtab for %s unit @%s: %s - %s"
- ", %d global, %d static syms\n",
- per_cu->is_debug_types ? "type" : "comp",
- sect_offset_str (per_cu->sect_off),
- paddress (gdbarch, pst->textlow),
- paddress (gdbarch, pst->texthigh),
- pst->n_global_syms, pst->n_static_syms);
- }
+ fprintf_unfiltered (gdb_stdlog,
+ "Psymtab for %s unit @%s: %s - %s"
+ ", %d global, %d static syms\n",
+ per_cu->is_debug_types ? "type" : "comp",
+ sect_offset_str (per_cu->sect_off),
+ paddress (gdbarch, pst->text_low (objfile)),
+ paddress (gdbarch, pst->text_high (objfile)),
+ pst->n_global_syms, pst->n_static_syms);
}
/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
free_one_cached_comp_unit (this_cu);
if (this_cu->is_debug_types)
- init_cutu_and_read_dies (this_cu, NULL, 0, 0, build_type_psymtabs_reader,
- NULL);
+ init_cutu_and_read_dies (this_cu, NULL, 0, 0, false,
+ build_type_psymtabs_reader, NULL);
else
{
process_psymtab_comp_unit_data info;
info.want_partial_unit = want_partial_unit;
info.pretend_language = pretend_language;
- init_cutu_and_read_dies (this_cu, NULL, 0, 0,
+ init_cutu_and_read_dies (this_cu, NULL, 0, 0, false,
process_psymtab_comp_unit_reader, &info);
}
attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
- VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
+ if (tu_group->tus == nullptr)
+ tu_group->tus = new std::vector<signatured_type *>;
+ tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
- cu->list_in_scope = &file_symbols;
pst = create_partial_symtab (per_cu, "");
pst->anonymous = 1;
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;
};
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
/* 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,
++tu_stats->nr_uniq_abbrev_tables;
}
- init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table.get (),
- 0, 0, build_type_psymtabs_reader, NULL);
+ init_cutu_and_read_dies (&tu.sig_type->per_cu, abbrev_table.get (),
+ 0, 0, false, build_type_psymtabs_reader, NULL);
}
}
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",
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
struct partial_symtab *pst = per_cu->v.psymtab;
- int len = VEC_length (sig_type_ptr, tu_group->tus);
- struct signatured_type *iter;
+ int len = (tu_group->tus == nullptr) ? 0 : tu_group->tus->size ();
int i;
gdb_assert (len > 0);
gdb_assert (IS_TYPE_UNIT_GROUP (per_cu));
pst->number_of_dependencies = len;
- pst->dependencies =
- XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
- for (i = 0;
- VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
- ++i)
+ pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
+ for (i = 0; i < len; ++i)
{
+ struct signatured_type *iter = tu_group->tus->at (i);
gdb_assert (iter->per_cu.is_debug_types);
pst->dependencies[i] = iter->per_cu.v.psymtab;
iter->type_unit_group = tu_group;
}
- VEC_free (sig_type_ptr, tu_group->tus);
+ delete tu_group->tus;
+ tu_group->tus = nullptr;
return 1;
}
*slot = entry;
/* This does the job that build_type_psymtabs_1 would have done. */
- init_cutu_and_read_dies (&entry->per_cu, NULL, 0, 0,
+ init_cutu_and_read_dies (&entry->per_cu, NULL, 0, 0, false,
build_type_psymtabs_reader, NULL);
return 1;
if (get_dwp_file (dwarf2_per_objfile) == NULL
&& dwarf2_per_objfile->dwo_files != NULL)
{
- htab_traverse_noresize (dwarf2_per_objfile->dwo_files,
+ htab_traverse_noresize (dwarf2_per_objfile->dwo_files.get (),
process_dwo_file_for_skeletonless_type_units,
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)
{
- struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (dwarf2_per_objfile, i);
struct partial_symtab *pst = per_cu->v.psymtab;
- int j;
if (pst == NULL)
continue;
- for (j = 0; j < pst->number_of_dependencies; ++j)
+ for (int j = 0; j < pst->number_of_dependencies; ++j)
{
/* Set the 'user' field only if it is not already set. */
if (pst->dependencies[j]->user == NULL)
static void
dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- struct cleanup *back_to;
- int i;
struct objfile *objfile = dwarf2_per_objfile->objfile;
if (dwarf_read_debug)
/* Any cached compilation units will be linked by the per-objfile
read_in_chain. Make sure to free them when we're done. */
- back_to = make_cleanup (free_cached_comp_units, dwarf2_per_objfile);
+ free_cached_comp_units freer (dwarf2_per_objfile);
build_type_psymtabs (dwarf2_per_objfile);
auto_obstack temp_obstack;
scoped_restore save_psymtabs_addrmap
- = make_scoped_restore (&objfile->psymtabs_addrmap,
+ = make_scoped_restore (&objfile->partial_symtabs->psymtabs_addrmap,
addrmap_create_mutable (&temp_obstack));
- 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);
-
- 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);
set_partial_user (dwarf2_per_objfile);
- objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
- &objfile->objfile_obstack);
+ objfile->partial_symtabs->psymtabs_addrmap
+ = addrmap_create_fixed (objfile->partial_symtabs->psymtabs_addrmap,
+ objfile->partial_symtabs->obstack ());
/* At this point we want to keep the address map. */
save_psymtabs_addrmap.release ();
- do_cleanups (back_to);
-
if (dwarf_read_debug)
fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
objfile_name (objfile));
static void
load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
{
- init_cutu_and_read_dies (this_cu, NULL, 1, 1,
+ init_cutu_and_read_dies (this_cu, NULL, 1, 1, false,
load_partial_comp_unit_reader, NULL);
}
read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
struct dwarf2_section_info *section,
struct dwarf2_section_info *abbrev_section,
- unsigned int is_dwz,
- int *n_allocated,
- int *n_comp_units,
- struct dwarf2_per_cu_data ***all_comp_units)
+ unsigned int is_dwz)
{
const gdb_byte *info_ptr;
struct objfile *objfile = dwarf2_per_objfile->objfile;
this_cu->dwarf2_per_objfile = dwarf2_per_objfile;
this_cu->section = section;
- if (*n_comp_units == *n_allocated)
- {
- *n_allocated *= 2;
- *all_comp_units = XRESIZEVEC (struct dwarf2_per_cu_data *,
- *all_comp_units, *n_allocated);
- }
- (*all_comp_units)[*n_comp_units] = this_cu;
- ++*n_comp_units;
+ dwarf2_per_objfile->all_comp_units.push_back (this_cu);
info_ptr = info_ptr + this_cu->length;
}
static void
create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- int n_allocated;
- int n_comp_units;
- struct dwarf2_per_cu_data **all_comp_units;
- struct dwz_file *dwz;
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- n_comp_units = 0;
- n_allocated = 10;
- all_comp_units = XNEWVEC (struct dwarf2_per_cu_data *, n_allocated);
-
+ gdb_assert (dwarf2_per_objfile->all_comp_units.empty ());
read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->info,
- &dwarf2_per_objfile->abbrev, 0,
- &n_allocated, &n_comp_units, &all_comp_units);
+ &dwarf2_per_objfile->abbrev, 0);
- dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+ dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
if (dwz != NULL)
read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
- 1, &n_allocated, &n_comp_units,
- &all_comp_units);
-
- dwarf2_per_objfile->all_comp_units = XOBNEWVEC (&objfile->objfile_obstack,
- struct dwarf2_per_cu_data *,
- n_comp_units);
- memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
- n_comp_units * sizeof (struct dwarf2_per_cu_data *));
- xfree (all_comp_units);
- dwarf2_per_objfile->n_comp_units = n_comp_units;
+ 1);
}
/* Process all loaded DIEs for compilation unit CU, starting at
add_partial_namespace (pdi, lowpc, highpc, set_addrmap, cu);
break;
case DW_TAG_module:
- add_partial_module (pdi, lowpc, highpc, set_addrmap, cu);
+ if (!pdi->is_declaration)
+ add_partial_module (pdi, lowpc, highpc, set_addrmap, cu);
break;
case DW_TAG_imported_unit:
{
if (per_cu->v.psymtab == NULL)
process_psymtab_comp_unit (per_cu, 1, cu->language);
- VEC_safe_push (dwarf2_per_cu_ptr,
- cu->per_cu->imported_symtabs, per_cu);
+ cu->per_cu->imported_symtabs_push (per_cu);
}
break;
case DW_TAG_imported_declaration:
real_pdi = pdi;
while (real_pdi->has_specification)
- real_pdi = find_partial_die (real_pdi->spec_offset,
- real_pdi->spec_is_dwz, cu);
+ {
+ auto res = find_partial_die (real_pdi->spec_offset,
+ real_pdi->spec_is_dwz, cu);
+ real_pdi = res.pdi;
+ cu = res.cu;
+ }
parent = real_pdi->die_parent;
if (parent == NULL)
return NULL;
}
+ /* Nested subroutines in Fortran get a prefix. */
if (pdi->tag == DW_TAG_enumerator)
/* Enumerators should not get the name of the enumeration as a prefix. */
parent->scope = grandparent_scope;
|| parent->tag == DW_TAG_class_type
|| parent->tag == DW_TAG_interface_type
|| parent->tag == DW_TAG_union_type
- || parent->tag == DW_TAG_enumeration_type)
+ || parent->tag == DW_TAG_enumeration_type
+ || (cu->language == language_fortran
+ && parent->tag == DW_TAG_subprogram
+ && pdi->tag == DW_TAG_subprogram))
{
if (grandparent_scope == NULL)
parent->scope = parent->name;
/* FIXME drow/2004-04-01: What should we be doing with
function-local names? For partial symbols, we should probably be
ignoring them. */
- complaint (&symfile_complaints,
- _("unhandled containing DIE tag %d for DIE at %s"),
- parent->tag, sect_offset_str (pdi->sect_off));
+ complaint (_("unhandled containing DIE tag %s for DIE at %s"),
+ dwarf_tag_name (parent->tag),
+ sect_offset_str (pdi->sect_off));
parent->scope = grandparent_scope;
}
/* Return the fully scoped name associated with PDI, from compilation unit
CU. The result will be allocated with malloc. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
partial_die_full_name (struct partial_die_info *pdi,
struct dwarf2_cu *cu)
{
attr.u.unsnd = to_underlying (pdi->sect_off);
die = follow_die_ref (NULL, &attr, &ref_cu);
- return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
+ return make_unique_xstrdup (dwarf2_full_name (NULL, die, ref_cu));
}
}
if (parent_scope == NULL)
return NULL;
else
- return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
+ return gdb::unique_xmalloc_ptr<char> (typename_concat (NULL, parent_scope,
+ pdi->name, 0, cu));
}
static void
CORE_ADDR addr = 0;
const char *actual_name = NULL;
CORE_ADDR baseaddr;
- char *built_actual_name;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
- built_actual_name = partial_die_full_name (pdi, cu);
+ gdb::unique_xmalloc_ptr<char> built_actual_name
+ = partial_die_full_name (pdi, cu);
if (built_actual_name != NULL)
- actual_name = built_actual_name;
+ actual_name = built_actual_name.get ();
if (actual_name == NULL)
actual_name = pdi->name;
{
case DW_TAG_inlined_subroutine:
case DW_TAG_subprogram:
- addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr);
- if (pdi->is_external || cu->language == language_ada)
- {
- /* brobecker/2007-12-26: Normally, only "external" DIEs are part
- of the global scope. But in Ada, we want to be able to access
- nested procedures globally. So all Ada subprograms are stored
- in the global scope. */
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr)
+ - baseaddr);
+ if (pdi->is_external
+ || cu->language == language_ada
+ || (cu->language == language_fortran
+ && pdi->die_parent != NULL
+ && pdi->die_parent->tag == DW_TAG_subprogram))
+ {
+ /* Normally, only "external" DIEs are part of the global scope.
+ But in Ada and Fortran, we want to be able to access nested
+ procedures globally. So all Ada and Fortran subprograms are
+ stored in the global scope. */
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
- &objfile->global_psymbols,
- addr, cu->language, objfile);
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::GLOBAL,
+ addr,
+ cu->language, objfile);
}
else
{
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
VAR_DOMAIN, LOC_BLOCK,
- &objfile->static_psymbols,
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::STATIC,
addr, cu->language, objfile);
}
set_objfile_main_name (objfile, actual_name, cu->language);
break;
case DW_TAG_constant:
- {
- std::vector<partial_symbol *> *list;
-
- if (pdi->is_external)
- list = &objfile->global_psymbols;
- else
- list = &objfile->static_psymbols;
- add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
- list, 0, cu->language, objfile);
- }
+ add_psymbol_to_list (actual_name,
+ built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
+ -1, (pdi->is_external
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC),
+ 0, cu->language, objfile);
break;
case DW_TAG_variable:
if (pdi->d.locdesc)
table building. */
if (pdi->d.locdesc || pdi->has_type)
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
- &objfile->global_psymbols,
- addr + baseaddr,
- cu->language, objfile);
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::GLOBAL,
+ addr, cu->language, objfile);
}
else
{
/* Static Variable. Skip symbols whose value we cannot know (those
without location descriptors or constant values). */
if (!has_loc && !pdi->has_const_value)
- {
- xfree (built_actual_name);
- return;
- }
+ return;
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
VAR_DOMAIN, LOC_STATIC,
- &objfile->static_psymbols,
- has_loc ? addr + baseaddr : (CORE_ADDR) 0,
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::STATIC,
+ has_loc ? addr : 0,
cu->language, objfile);
}
break;
case DW_TAG_typedef:
case DW_TAG_base_type:
case DW_TAG_subrange_type:
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
- VAR_DOMAIN, LOC_TYPEDEF,
- &objfile->static_psymbols,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::STATIC,
0, cu->language, objfile);
break;
case DW_TAG_imported_declaration:
case DW_TAG_namespace:
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
- VAR_DOMAIN, LOC_TYPEDEF,
- &objfile->global_psymbols,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::GLOBAL,
0, cu->language, objfile);
break;
case DW_TAG_module:
- add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name != NULL,
- MODULE_DOMAIN, LOC_TYPEDEF,
- &objfile->global_psymbols,
- 0, cu->language, objfile);
+ /* With Fortran 77 there might be a "BLOCK DATA" module
+ available without any name. If so, we skip the module as it
+ doesn't bring any value. */
+ if (actual_name != nullptr)
+ add_psymbol_to_list (actual_name,
+ built_actual_name != NULL,
+ MODULE_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::GLOBAL,
+ 0, cu->language, objfile);
break;
case DW_TAG_class_type:
case DW_TAG_interface_type:
union or class entry that does not have a byte size attribute
and that has a DW_AT_declaration attribute." */
if (!pdi->has_byte_size && pdi->is_declaration)
- {
- xfree (built_actual_name);
- return;
- }
+ return;
/* NOTE: carlton/2003-10-07: See comment in new_symbol about
static vs. global. */
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
- STRUCT_DOMAIN, LOC_TYPEDEF,
+ STRUCT_DOMAIN, LOC_TYPEDEF, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
break;
case DW_TAG_enumerator:
- add_psymbol_to_list (actual_name, strlen (actual_name),
+ add_psymbol_to_list (actual_name,
built_actual_name != NULL,
- VAR_DOMAIN, LOC_CONST,
+ VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
break;
default:
break;
}
-
- xfree (built_actual_name);
}
/* Read a partial die corresponding to a namespace; also, add a symbol
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
CORE_ADDR baseaddr;
- CORE_ADDR highpc;
- CORE_ADDR lowpc;
-
- baseaddr = ANOFFSET (objfile->section_offsets,
- SECT_OFF_TEXT (objfile));
- lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- pdi->lowpc + baseaddr);
- highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- pdi->highpc + baseaddr);
- addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
+ CORE_ADDR this_highpc;
+ CORE_ADDR this_lowpc;
+
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+ this_lowpc
+ = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->lowpc + baseaddr)
+ - baseaddr);
+ this_highpc
+ = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ pdi->highpc + baseaddr)
+ - baseaddr);
+ addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+ this_lowpc, this_highpc - 1,
cu->per_cu->v.psymtab);
}
}
if (! pdi->has_children)
return;
- if (cu->language == language_ada)
+ if (cu->language == language_ada || cu->language == language_fortran)
{
pdi = pdi->die_child;
while (pdi != NULL)
while (pdi)
{
if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
- complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
+ complaint (_("malformed enumerator DIE ignored"));
else
add_partial_symbol (pdi, cu);
pdi = pdi->die_sibling;
{
read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
if (attr.form == DW_FORM_ref_addr)
- complaint (&symfile_complaints,
- _("ignoring absolute DW_AT_sibling"));
+ complaint (_("ignoring absolute DW_AT_sibling"));
else
{
sect_offset off = dwarf2_get_ref_die_offset (&attr);
const gdb_byte *sibling_ptr = buffer + to_underlying (off);
if (sibling_ptr < info_ptr)
- complaint (&symfile_complaints,
- _("DW_AT_sibling points backwards"));
+ complaint (_("DW_AT_sibling points backwards"));
else if (sibling_ptr > reader->buffer_end)
dwarf2_section_buffer_overflow_complaint (reader->die_section);
else
case DW_FORM_data1:
case DW_FORM_ref1:
case DW_FORM_flag:
+ case DW_FORM_strx1:
info_ptr += 1;
break;
case DW_FORM_flag_present:
break;
case DW_FORM_data2:
case DW_FORM_ref2:
+ case DW_FORM_strx2:
info_ptr += 2;
break;
+ case DW_FORM_strx3:
+ info_ptr += 3;
+ break;
case DW_FORM_data4:
case DW_FORM_ref4:
+ case DW_FORM_strx4:
info_ptr += 4;
break;
case DW_FORM_data8:
case DW_FORM_block4:
info_ptr += 4 + read_4_bytes (abfd, info_ptr);
break;
+ case DW_FORM_addrx:
+ case DW_FORM_strx:
case DW_FORM_sdata:
case DW_FORM_udata:
case DW_FORM_ref_udata:
return;
}
- dw2_do_instantiate_symtab (per_cu);
+ dw2_do_instantiate_symtab (per_cu, false);
}
/* Trivial hash function for die_info: the hash value of a DIE
static void
load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
+ bool skip_partial,
enum language pretend_language)
{
gdb_assert (! this_cu->is_debug_types);
- init_cutu_and_read_dies (this_cu, NULL, 1, 1,
+ init_cutu_and_read_dies (this_cu, NULL, 1, 1, skip_partial,
load_full_comp_unit_reader, &pretend_language);
}
return;
gdb_assert (cu->language == language_cplus);
- for (struct delayed_method_info &mi : cu->method_list)
+ for (const delayed_method_info &mi : cu->method_list)
{
const char *physname;
struct fn_fieldlist *fn_flp
static void
fixup_go_packaging (struct dwarf2_cu *cu)
{
- char *package_name = NULL;
+ gdb::unique_xmalloc_ptr<char> package_name;
struct pending *list;
int i;
- for (list = global_symbols; list != NULL; list = list->next)
+ for (list = *cu->get_builder ()->get_global_symbols ();
+ list != NULL;
+ list = list->next)
{
for (i = 0; i < list->nsyms; ++i)
{
struct symbol *sym = list->symbol[i];
- if (SYMBOL_LANGUAGE (sym) == language_go
+ if (sym->language () == language_go
&& SYMBOL_CLASS (sym) == LOC_BLOCK)
{
- char *this_package_name = go_symbol_package_name (sym);
+ gdb::unique_xmalloc_ptr<char> this_package_name
+ (go_symbol_package_name (sym));
if (this_package_name == NULL)
continue;
if (package_name == NULL)
- package_name = this_package_name;
+ package_name = std::move (this_package_name);
else
{
struct objfile *objfile
= cu->per_cu->dwarf2_per_objfile->objfile;
- if (strcmp (package_name, this_package_name) != 0)
- complaint (&symfile_complaints,
- _("Symtab %s has objects from two different Go packages: %s and %s"),
+ if (strcmp (package_name.get (), this_package_name.get ()) != 0)
+ complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
(symbol_symtab (sym) != NULL
? symtab_to_filename_for_display
(symbol_symtab (sym))
: objfile_name (objfile)),
- this_package_name, package_name);
- xfree (this_package_name);
+ this_package_name.get (), package_name.get ());
}
}
}
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
const char *saved_package_name
- = (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack,
- package_name,
- strlen (package_name));
+ = obstack_strdup (&objfile->per_bfd->storage_obstack, package_name.get ());
struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
saved_package_name);
struct symbol *sym;
- TYPE_TAG_NAME (type) = TYPE_NAME (type);
-
sym = allocate_symbol (objfile);
- SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack);
- SYMBOL_SET_NAMES (sym, saved_package_name,
- strlen (saved_package_name), 0, objfile);
+ sym->set_language (language_go, &objfile->objfile_obstack);
+ sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
/* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
e.g., "main" finds the "main" module and not C's main(). */
SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
SYMBOL_TYPE (sym) = type;
- add_symbol_to_list (sym, &global_symbols);
-
- xfree (package_name);
+ add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ());
}
}
|| (TYPE_FIELD_LOC_KIND (field_type, index)
!= FIELD_LOC_KIND_BITPOS))
{
- complaint (&symfile_complaints,
- _("Could not parse Rust enum encoding string \"%s\""
+ complaint (_("Could not parse Rust enum encoding string \"%s\""
"[in module %s]"),
TYPE_FIELD_NAME (type, 0),
objfile_name (objfile));
TYPE_FIELDS (union_type)
= (struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field));
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
/* Put the discriminant must at index 0. */
TYPE_FIELD_TYPE (union_type, 0) = field_type;
SET_FIELD_BITPOS (TYPE_FIELD (type, 0), 0);
TYPE_FIELD_NAME (type, 0) = "<<variants>>";
}
- else if (TYPE_NFIELDS (type) == 1)
+ /* A union with a single anonymous field is probably an old-style
+ univariant enum. */
+ else if (TYPE_NFIELDS (type) == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
{
- /* We assume that a union with a single field is a univariant
- enum. */
/* Smash this type to be a structure type. We have to do this
because the type has already been recorded. */
TYPE_CODE (type) = TYPE_CODE_STRUCT;
TYPE_CODE (union_type) = TYPE_CODE_UNION;
TYPE_NFIELDS (union_type) = TYPE_NFIELDS (type);
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
TYPE_FIELDS (union_type) = TYPE_FIELDS (type);
struct type *field_type = TYPE_FIELD_TYPE (union_type, 0);
{
disr_type = TYPE_FIELD_TYPE (type, i);
- if (TYPE_NFIELDS (disr_type) == 0)
+ if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT)
+ {
+ /* All fields of a true enum will be structs. */
+ return;
+ }
+ else if (TYPE_NFIELDS (disr_type) == 0)
{
/* Could be data-less variant, so keep going. */
+ disr_type = nullptr;
}
else if (strcmp (TYPE_FIELD_NAME (disr_type, 0),
"RUST$ENUM$DISR") != 0)
TYPE_CODE (union_type) = TYPE_CODE_UNION;
TYPE_NFIELDS (union_type) = 1 + TYPE_NFIELDS (type);
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
TYPE_FIELDS (union_type)
= (struct field *) TYPE_ZALLOC (union_type,
(TYPE_NFIELDS (union_type)
if (iter != discriminant_map.end ())
disc->discriminants[i] = iter->second;
- /* Remove the discriminant field. */
+ /* Remove the discriminant field, if it exists. */
struct type *sub_type = TYPE_FIELD_TYPE (union_type, i);
- --TYPE_NFIELDS (sub_type);
- ++TYPE_FIELDS (sub_type);
+ if (TYPE_NFIELDS (sub_type) > 0)
+ {
+ --TYPE_NFIELDS (sub_type);
+ ++TYPE_FIELDS (sub_type);
+ }
TYPE_FIELD_NAME (union_type, i) = variant_name;
TYPE_NAME (sub_type)
= rust_fully_qualify (&objfile->objfile_obstack,
rust_union_quirks (struct dwarf2_cu *cu)
{
gdb_assert (cu->language == language_rust);
- for (struct type *type : cu->rust_unions)
- quirk_rust_enum (type, cu->per_cu->dwarf2_per_objfile->objfile);
+ for (type *type_ : cu->rust_unions)
+ quirk_rust_enum (type_, cu->per_cu->dwarf2_per_objfile->objfile);
+ /* We don't need this any more. */
+ cu->rust_unions.clear ();
}
/* Return the symtab for PER_CU. This works properly regardless of
included by PER_CU. */
static void
-recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
+recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
htab_t all_children, htab_t all_type_symtabs,
struct dwarf2_per_cu_data *per_cu,
struct compunit_symtab *immediate_parent)
{
void **slot;
- int ix;
struct compunit_symtab *cust;
- struct dwarf2_per_cu_data *iter;
slot = htab_find_slot (all_children, per_cu, INSERT);
if (*slot != NULL)
if (*slot == NULL)
{
*slot = cust;
- VEC_safe_push (compunit_symtab_ptr, *result, cust);
+ result->push_back (cust);
if (cust->user == NULL)
cust->user = immediate_parent;
}
}
else
{
- VEC_safe_push (compunit_symtab_ptr, *result, cust);
+ result->push_back (cust);
if (cust->user == NULL)
cust->user = immediate_parent;
}
}
- for (ix = 0;
- VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
- ++ix)
- {
- recursively_compute_inclusions (result, all_children,
- all_type_symtabs, iter, cust);
- }
+ if (!per_cu->imported_symtabs_empty ())
+ for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
+ {
+ recursively_compute_inclusions (result, all_children,
+ all_type_symtabs, ptr, cust);
+ }
}
/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
{
gdb_assert (! per_cu->is_debug_types);
- if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
+ if (!per_cu->imported_symtabs_empty ())
{
- int ix, len;
- struct dwarf2_per_cu_data *per_cu_iter;
- struct compunit_symtab *compunit_symtab_iter;
- VEC (compunit_symtab_ptr) *result_symtabs = NULL;
+ int len;
+ std::vector<compunit_symtab *> result_symtabs;
htab_t all_children, all_type_symtabs;
struct compunit_symtab *cust = get_compunit_symtab (per_cu);
all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
NULL, xcalloc, xfree);
- for (ix = 0;
- VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
- ix, per_cu_iter);
- ++ix)
+ for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
{
recursively_compute_inclusions (&result_symtabs, all_children,
- all_type_symtabs, per_cu_iter,
- cust);
+ all_type_symtabs, ptr, cust);
}
/* Now we have a transitive closure of all the included symtabs. */
- len = VEC_length (compunit_symtab_ptr, result_symtabs);
+ len = result_symtabs.size ();
cust->includes
= XOBNEWVEC (&per_cu->dwarf2_per_objfile->objfile->objfile_obstack,
struct compunit_symtab *, len + 1);
- for (ix = 0;
- VEC_iterate (compunit_symtab_ptr, result_symtabs, ix,
- compunit_symtab_iter);
- ++ix)
- cust->includes[ix] = compunit_symtab_iter;
+ memcpy (cust->includes, result_symtabs.data (),
+ len * sizeof (compunit_symtab *));
cust->includes[len] = NULL;
- VEC_free (compunit_symtab_ptr, result_symtabs);
htab_delete (all_children);
htab_delete (all_type_symtabs);
}
static void
process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- int ix;
- struct dwarf2_per_cu_data *iter;
-
- for (ix = 0;
- VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus,
- ix, iter);
- ++ix)
+ for (dwarf2_per_cu_data *iter : dwarf2_per_objfile->just_read_cus)
{
if (! iter->is_debug_types)
compute_compunit_symtab_includes (iter);
}
- VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
+ dwarf2_per_objfile->just_read_cus.clear ();
}
/* Generate full symbol information for PER_CU, whose DIEs have
struct block *static_block;
CORE_ADDR addr;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
-
- buildsym_init ();
- scoped_free_pendings free_pending;
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
/* Clear the list here in case something was left over. */
cu->method_list.clear ();
- cu->list_in_scope = &file_symbols;
-
cu->language = pretend_language;
cu->language_defn = language_def (cu->language);
if (cu->language == language_go)
fixup_go_packaging (cu);
- /* Now that we have processed all the DIEs in the CU, all the types
+ /* Now that we have processed all the DIEs in the CU, all the types
should be complete, and it should now be safe to compute all of the
physnames. */
compute_delayed_physnames (cu);
get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
addr = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
- static_block = end_symtab_get_static_block (addr, 0, 1);
+ static_block = cu->get_builder ()->end_symtab_get_static_block (addr, 0, 1);
/* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
Also, DW_AT_ranges may record ranges not belonging to any child DIEs
this comp unit. */
dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
- cust = end_symtab_from_static_block (static_block,
- SECT_OFF_TEXT (objfile), 0);
+ cust = cu->get_builder ()->end_symtab_from_static_block (static_block,
+ SECT_OFF_TEXT (objfile),
+ 0);
if (cust != NULL)
{
Still one can confuse GDB by using non-standard GCC compilation
options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
- */
+ */
if (cu->has_loclist && gcc_4_minor >= 5)
cust->locations_valid = 1;
}
/* Push it for inclusion processing later. */
- VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu);
+ dwarf2_per_objfile->just_read_cus.push_back (per_cu);
+
+ /* Not needed any more. */
+ cu->reset_builder ();
}
/* Generate full symbol information for type unit PER_CU, whose DIEs have
gdb_assert (per_cu->is_debug_types);
sig_type = (struct signatured_type *) per_cu;
- buildsym_init ();
- scoped_free_pendings free_pending;
-
/* Clear the list here in case something was left over. */
cu->method_list.clear ();
- cu->list_in_scope = &file_symbols;
-
cu->language = pretend_language;
cu->language_defn = language_def (cu->language);
if (cu->language == language_go)
fixup_go_packaging (cu);
- /* Now that we have processed all the DIEs in the CU, all the types
+ /* Now that we have processed all the DIEs in the CU, all the types
should be complete, and it should now be safe to compute all of the
physnames. */
compute_delayed_physnames (cu);
this TU's symbols to the existing symtab. */
if (sig_type->type_unit_group->compunit_symtab == NULL)
{
- cust = end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
+ buildsym_compunit *builder = cu->get_builder ();
+ cust = builder->end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
sig_type->type_unit_group->compunit_symtab = cust;
if (cust != NULL)
}
else
{
- augment_type_symtab ();
+ cu->get_builder ()->augment_type_symtab ();
cust = sig_type->type_unit_group->compunit_symtab;
}
pst->compunit_symtab = cust;
pst->readin = 1;
}
+
+ /* Not needed any more. */
+ cu->reset_builder ();
}
/* Process an imported unit DIE. */
/* If necessary, add it to the queue and load its DIEs. */
if (maybe_queue_comp_unit (cu, per_cu, cu->language))
- load_full_comp_unit (per_cu, cu->language);
+ load_full_comp_unit (per_cu, false, cu->language);
- VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
- per_cu);
+ cu->per_cu->imported_symtabs_push (per_cu);
}
}
read_type_unit_scope (die, cu);
break;
case DW_TAG_subprogram:
+ /* Nested subprograms in Fortran get a prefix. */
+ if (cu->language == language_fortran
+ && die->parent != NULL
+ && die->parent->tag == DW_TAG_subprogram)
+ cu->processing_has_namespace_info = true;
+ /* Fall through. */
case DW_TAG_inlined_subroutine:
read_func_scope (die, cu);
break;
case DW_TAG_common_inclusion:
break;
case DW_TAG_namespace:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
read_namespace (die, cu);
break;
case DW_TAG_module:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
read_module (die, cu);
break;
case DW_TAG_imported_declaration:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
if (read_namespace_alias (die, cu))
break;
- /* The declaration is not a global namespace alias: fall through. */
+ /* The declaration is not a global namespace alias. */
+ /* Fall through. */
case DW_TAG_imported_module:
- cu->processing_has_namespace_info = 1;
+ cu->processing_has_namespace_info = true;
if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
|| cu->language != language_fortran))
- complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
+ complaint (_("Tag '%s' has unexpected children"),
dwarf_tag_name (die->tag));
read_import_statement (die, cu);
break;
/* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
but otherwise compute it by typename_concat inside GDB.
FIXME: Actually this is not really true, or at least not always true.
- It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
+ It's all very confusing. compute_and_set_names doesn't try to demangle
Fortran names because there is no mangling standard. So new_symbol
will set the demangled name to the result of dwarf2_full_name, and it is
the demangled name that GDB uses if it exists. */
prefix = determine_prefix (die, cu);
if (*prefix != '\0')
{
- char *prefixed_name = typename_concat (NULL, prefix, name,
- physname, cu);
+ gdb::unique_xmalloc_ptr<char> prefixed_name
+ (typename_concat (NULL, prefix, name, physname, cu));
- buf.puts (prefixed_name);
- xfree (prefixed_name);
+ buf.puts (prefixed_name.get ());
}
else
buf.puts (name);
attr = dwarf2_attr (child, DW_AT_type, cu);
if (attr == NULL)
{
- complaint (&symfile_complaints,
- _("template parameter missing DW_AT_type"));
+ complaint (_("template parameter missing DW_AT_type"));
buf.puts ("UNKNOWN_TYPE");
continue;
}
if (child->tag == DW_TAG_template_type_param)
{
- c_print_type (type, "", &buf, -1, 0, &type_print_raw_options);
+ c_print_type (type, "", &buf, -1, 0, cu->language,
+ &type_print_raw_options);
continue;
}
attr = dwarf2_attr (child, DW_AT_const_value, cu);
if (attr == NULL)
{
- complaint (&symfile_complaints,
- _("template parameter missing "
+ complaint (_("template parameter missing "
"DW_AT_const_value"));
buf.puts ("UNKNOWN_VALUE");
continue;
opts.raw = 1;
value_print (v, &buf, &opts);
release_value (v);
- value_free (v);
}
}
INTERMEDIATE_NAME is already canonical, then we need to
copy it to the appropriate obstack. */
if (canonical_name == NULL || canonical_name == intermediate_name.c_str ())
- name = ((const char *)
- obstack_copy0 (&objfile->per_bfd->storage_obstack,
- intermediate_name.c_str (),
- intermediate_name.length ()));
+ name = obstack_strdup (&objfile->per_bfd->storage_obstack,
+ intermediate_name);
else
name = canonical_name;
}
if (mangled != NULL)
{
- if (cu->language == language_go)
+ if (language_def (cu->language)->la_store_sym_names_in_linkage_form_p)
+ {
+ /* Do nothing (do not demangle the symbol name). */
+ }
+ else if (cu->language == language_go)
{
/* This is a lie, but we already lie to the caller new_symbol.
new_symbol assumes we return the mangled name.
compute DW_AT_linkage_name incorrectly. But in such case
GDB would need to be bug-to-bug compatible. */
- complaint (&symfile_complaints,
- _("Computed physname <%s> does not match demangled <%s> "
+ complaint (_("Computed physname <%s> does not match demangled <%s> "
"(from linkage <%s>) - DIE at %s [in module %s]"),
physname, canon, mangled, sect_offset_str (die->sect_off),
objfile_name (objfile));
retval = canon;
if (need_copy)
- retval = ((const char *)
- obstack_copy0 (&objfile->per_bfd->storage_obstack,
- retval, strlen (retval)));
+ retval = obstack_strdup (&objfile->per_bfd->storage_obstack, retval);
return retval;
}
if (num == MAX_NESTED_IMPORTED_DECLARATIONS)
{
- complaint (&symfile_complaints,
- _("DIE at %s has too many recursively imported "
+ complaint (_("DIE at %s has too many recursively imported "
"declarations"), sect_offset_str (d->sect_off));
return 0;
}
}
/* Return the using directives repository (global or local?) to use in the
- current context for LANGUAGE.
+ current context for CU.
For Ada, imported declarations can materialize renamings, which *may* be
global. However it is impossible (for now?) in DWARF to distinguish
global only in Ada. */
static struct using_direct **
-using_directives (enum language language)
+using_directives (struct dwarf2_cu *cu)
{
- if (language == language_ada && context_stack_depth == 0)
- return &global_using_directives;
+ if (cu->language == language_ada
+ && cu->get_builder ()->outermost_context_p ())
+ return cu->get_builder ()->get_global_using_directives ();
else
- return &local_using_directives;
+ return cu->get_builder ()->get_local_using_directives ();
}
/* Read the import statement specified by the given die and record it. */
import_attr = dwarf2_attr (die, DW_AT_import, cu);
if (import_attr == NULL)
{
- complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
+ complaint (_("Tag '%s' has no DW_AT_import"),
dwarf_tag_name (die->tag));
return;
}
if (child_die->tag != DW_TAG_imported_declaration)
{
- complaint (&symfile_complaints,
- _("child DW_TAG_imported_declaration expected "
+ complaint (_("child DW_TAG_imported_declaration expected "
"- DIE at %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (objfile));
import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
if (import_attr == NULL)
{
- complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
+ complaint (_("Tag '%s' has no DW_AT_import"),
dwarf_tag_name (child_die->tag));
continue;
}
imported_name = dwarf2_name (imported_die, imported_cu);
if (imported_name == NULL)
{
- complaint (&symfile_complaints,
- _("child DW_TAG_imported_declaration has unknown "
+ complaint (_("child DW_TAG_imported_declaration has unknown "
"imported name - DIE at %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (objfile));
process_die (child_die, cu);
}
- add_using_directive (using_directives (cu->language),
+ add_using_directive (using_directives (cu),
import_prefix,
canonical_name,
import_alias,
types, but gives them a size of zero. Starting with version 14,
ICC is compatible with GCC. */
-static int
+static bool
producer_is_icc_lt_14 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
return cu->producer_is_icc_lt_14;
}
+/* ICC generates a DW_AT_type for C void functions. This was observed on
+ ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
+ which says that void functions should not have a DW_AT_type. */
+
+static bool
+producer_is_icc (struct dwarf2_cu *cu)
+{
+ if (!cu->checked_producer)
+ check_producer (cu);
+
+ return cu->producer_is_icc;
+}
+
/* Check for possibly missing DW_AT_comp_dir with relative .debug_line
directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
this, it was first present in GCC release 4.3.0. */
-static int
+static bool
producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
struct die_info *child_die;
CORE_ADDR baseaddr;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ prepare_one_comp_unit (cu, die, cu->language);
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
get_scope_pc_bounds (die, &lowpc, &highpc, cu);
file_and_directory fnd = find_file_and_directory (die, cu);
- prepare_one_comp_unit (cu, die, cu->language);
-
/* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
standardised yet. As a workaround for the language detection we fall
back to the DW_AT_producer string. */
if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
set_cu_language (DW_LANG_Go, cu);
- dwarf2_start_symtab (cu, fnd.name, fnd.comp_dir, lowpc);
+ cu->start_symtab (fnd.name, fnd.comp_dir, lowpc);
/* Decode line number information if present. We do this before
processing child DIEs, so that the line header table is available
if (attr && cu->line_header)
{
if (dwarf2_attr (die, DW_AT_macro_info, cu))
- complaint (&symfile_complaints,
- _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
+ complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
dwarf_decode_macros (cu, DW_UNSND (attr), 1);
}
}
}
-/* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
- Create the set of symtabs used by this TU, or if this TU is sharing
- symtabs with another TU and the symtabs have already been created
- then restore those symtabs in the line header.
- We don't need the pc/line-number mapping for type units. */
-
-static void
-setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
+void
+dwarf2_cu::setup_type_unit_groups (struct die_info *die)
{
- struct dwarf2_per_cu_data *per_cu = cu->per_cu;
struct type_unit_group *tu_group;
int first_time;
struct attribute *attr;
gdb_assert (per_cu->is_debug_types);
sig_type = (struct signatured_type *) per_cu;
- attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
+ attr = dwarf2_attr (die, DW_AT_stmt_list, this);
/* If we're using .gdb_index (includes -readnow) then
per_cu->type_unit_group may not have been set up yet. */
if (sig_type->type_unit_group == NULL)
- sig_type->type_unit_group = get_type_unit_group (cu, attr);
+ sig_type->type_unit_group = get_type_unit_group (this, attr);
tu_group = sig_type->type_unit_group;
/* If we've already processed this stmt_list there's no real need to
if (attr != NULL)
{
sect_offset line_offset = (sect_offset) DW_UNSND (attr);
- lh = dwarf_decode_line_header (line_offset, cu);
+ lh = dwarf_decode_line_header (line_offset, this);
}
if (lh == NULL)
{
if (first_time)
- dwarf2_start_symtab (cu, "", NULL, 0);
+ start_symtab ("", NULL, 0);
else
{
gdb_assert (tu_group->symtabs == NULL);
- restart_symtab (tu_group->compunit_symtab, "", 0);
+ gdb_assert (m_builder == nullptr);
+ struct compunit_symtab *cust = tu_group->compunit_symtab;
+ m_builder.reset (new struct buildsym_compunit
+ (COMPUNIT_OBJFILE (cust), "",
+ COMPUNIT_DIRNAME (cust),
+ compunit_language (cust),
+ 0, cust));
}
return;
}
- cu->line_header = lh.release ();
- cu->line_header_die_owner = die;
+ line_header = lh.release ();
+ line_header_die_owner = die;
if (first_time)
{
- struct compunit_symtab *cust = dwarf2_start_symtab (cu, "", NULL, 0);
+ struct compunit_symtab *cust = start_symtab ("", NULL, 0);
/* Note: We don't assign tu_group->compunit_symtab yet because we're
still initializing it, and our caller (a few levels up)
process_full_type_unit still needs to know if this is the first
time. */
- tu_group->num_symtabs = cu->line_header->file_names.size ();
+ tu_group->num_symtabs = line_header->file_names_size ();
tu_group->symtabs = XNEWVEC (struct symtab *,
- cu->line_header->file_names.size ());
+ line_header->file_names_size ());
- for (i = 0; i < cu->line_header->file_names.size (); ++i)
+ auto &file_names = line_header->file_names ();
+ for (i = 0; i < file_names.size (); ++i)
{
- file_entry &fe = cu->line_header->file_names[i];
-
- dwarf2_start_subfile (fe.name, fe.include_dir (cu->line_header));
-
- if (current_subfile->symtab == NULL)
+ file_entry &fe = file_names[i];
+ dwarf2_start_subfile (this, fe.name,
+ fe.include_dir (line_header));
+ buildsym_compunit *b = get_builder ();
+ if (b->get_current_subfile ()->symtab == NULL)
{
/* NOTE: start_subfile will recognize when it's been
passed a file it has already seen. So we can't
assume there's a simple mapping from
cu->line_header->file_names to subfiles, plus
cu->line_header->file_names may contain dups. */
- current_subfile->symtab
- = allocate_symtab (cust, current_subfile->name);
+ b->get_current_subfile ()->symtab
+ = allocate_symtab (cust, b->get_current_subfile ()->name);
}
- fe.symtab = current_subfile->symtab;
+ fe.symtab = b->get_current_subfile ()->symtab;
tu_group->symtabs[i] = fe.symtab;
}
}
else
{
- restart_symtab (tu_group->compunit_symtab, "", 0);
+ gdb_assert (m_builder == nullptr);
+ struct compunit_symtab *cust = tu_group->compunit_symtab;
+ m_builder.reset (new struct buildsym_compunit
+ (COMPUNIT_OBJFILE (cust), "",
+ COMPUNIT_DIRNAME (cust),
+ compunit_language (cust),
+ 0, cust));
- for (i = 0; i < cu->line_header->file_names.size (); ++i)
+ auto &file_names = line_header->file_names ();
+ for (i = 0; i < file_names.size (); ++i)
{
- file_entry &fe = cu->line_header->file_names[i];
-
+ file_entry &fe = file_names[i];
fe.symtab = tu_group->symtabs[i];
}
}
/* Initialize (or reinitialize) the machinery for building symtabs.
We do this before processing child DIEs, so that the line header table
is available for DW_AT_decl_file. */
- setup_type_unit_groups (die, cu);
+ cu->setup_type_unit_groups (die);
if (die->child != NULL)
{
/* Allocate a hash table for DWO files. */
-static htab_t
+static htab_up
allocate_dwo_file_hash_table (struct objfile *objfile)
{
- return htab_create_alloc_ex (41,
- hash_dwo_file,
- eq_dwo_file,
- NULL,
- &objfile->objfile_obstack,
- hashtab_obstack_allocate,
- dummy_obstack_deallocate);
+ auto delete_dwo_file = [] (void *item)
+ {
+ struct dwo_file *dwo_file = (struct dwo_file *) item;
+
+ delete dwo_file;
+ };
+
+ return htab_up (htab_create_alloc_ex (41,
+ hash_dwo_file,
+ eq_dwo_file,
+ delete_dwo_file,
+ &objfile->objfile_obstack,
+ hashtab_obstack_allocate,
+ dummy_obstack_deallocate));
}
/* Lookup DWO file DWO_NAME. */
dwarf2_per_objfile->dwo_files
= allocate_dwo_file_hash_table (dwarf2_per_objfile->objfile);
- memset (&find_entry, 0, sizeof (find_entry));
find_entry.dwo_name = dwo_name;
find_entry.comp_dir = comp_dir;
- slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT);
+ slot = htab_find_slot (dwarf2_per_objfile->dwo_files.get (), &find_entry,
+ INSERT);
return slot;
}
struct create_dwo_cu_data *data = (struct create_dwo_cu_data *) datap;
struct dwo_file *dwo_file = data->dwo_file;
struct dwo_unit *dwo_unit = &data->dwo_unit;
- struct attribute *attr;
- attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
- if (attr == NULL)
+ gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
+ if (!signature.has_value ())
{
- complaint (&symfile_complaints,
- _("Dwarf Error: debug entry at offset %s is missing"
+ complaint (_("Dwarf Error: debug entry at offset %s is missing"
" its dwo_id [in module %s]"),
sect_offset_str (sect_off), dwo_file->dwo_name);
return;
}
dwo_unit->dwo_file = dwo_file;
- dwo_unit->signature = DW_UNSND (attr);
+ dwo_unit->signature = *signature;
dwo_unit->section = section;
dwo_unit->sect_off = sect_off;
dwo_unit->length = cu->per_cu->length;
const struct dwo_unit *dup_cu = (const struct dwo_unit *)*slot;
sect_offset dup_sect_off = dup_cu->sect_off;
- complaint (&symfile_complaints,
- _("debug cu entry at offset %s is duplicate to"
+ complaint (_("debug cu entry at offset %s is duplicate to"
" the entry at offset %s, signature %s"),
sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
hex_string (dwo_unit->signature));
struct dwp_file *dwp_file, int is_debug_types)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- bfd *dbfd = dwp_file->dbfd;
+ bfd *dbfd = dwp_file->dbfd.get ();
const gdb_byte *index_ptr, *index_end;
struct dwarf2_section_info *index;
uint32_t version, nr_columns, nr_units, nr_slots;
if (nr_slots != 0 || nr_units != 0
|| (version == 2 && nr_columns != 0))
{
- complaint (&symfile_complaints,
- _("Empty DWP but nr_slots,nr_units,nr_columns not"
+ complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
" all zero [in modules %s]"),
dwp_file->name);
}
{
const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
int *ids = htab->section_pool.v2.section_ids;
+ size_t sizeof_ids = sizeof (htab->section_pool.v2.section_ids);
/* Reverse map for error checking. */
int ids_seen[DW_SECT_MAX + 1];
int i;
" in section table [in module %s]"),
dwp_file->name);
}
- memset (ids, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
- memset (ids_seen, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
+ memset (ids, 255, sizeof_ids);
+ memset (ids_seen, 255, sizeof (ids_seen));
for (i = 0; i < nr_columns; ++i)
{
int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
if (sections->abbrev.s.section != NULL)
return 0;
sections->abbrev.s.section = sectp;
- sections->abbrev.size = bfd_get_section_size (sectp);
+ sections->abbrev.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->info_dwo)
|| section_is_p (sectp->name, &names->types_dwo))
if (sections->info_or_types.s.section != NULL)
return 0;
sections->info_or_types.s.section = sectp;
- sections->info_or_types.size = bfd_get_section_size (sectp);
+ sections->info_or_types.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->line_dwo))
{
if (sections->line.s.section != NULL)
return 0;
sections->line.s.section = sectp;
- sections->line.size = bfd_get_section_size (sectp);
+ sections->line.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->loc_dwo))
{
if (sections->loc.s.section != NULL)
return 0;
sections->loc.s.section = sectp;
- sections->loc.size = bfd_get_section_size (sectp);
+ sections->loc.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macinfo_dwo))
{
if (sections->macinfo.s.section != NULL)
return 0;
sections->macinfo.s.section = sectp;
- sections->macinfo.size = bfd_get_section_size (sectp);
+ sections->macinfo.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macro_dwo))
{
if (sections->macro.s.section != NULL)
return 0;
sections->macro.s.section = sectp;
- sections->macro.size = bfd_get_section_size (sectp);
+ sections->macro.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->str_offsets_dwo))
{
if (sections->str_offsets.s.section != NULL)
return 0;
sections->str_offsets.s.section = sectp;
- sections->str_offsets.size = bfd_get_section_size (sectp);
+ sections->str_offsets.size = bfd_section_size (sectp);
}
else
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
const struct dwp_hash_table *dwp_htab =
is_debug_types ? dwp_file->tus : dwp_file->cus;
- bfd *dbfd = dwp_file->dbfd;
+ bfd *dbfd = dwp_file->dbfd.get ();
const char *kind = is_debug_types ? "TU" : "CU";
struct dwo_file *dwo_file;
struct dwo_unit *dwo_unit;
fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
virtual_dwo_name.c_str ());
}
- dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
- dwo_file->dwo_name
- = (const char *) obstack_copy0 (&objfile->objfile_obstack,
- virtual_dwo_name.c_str (),
- virtual_dwo_name.size ());
+ dwo_file = new struct dwo_file;
+ dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack,
+ virtual_dwo_name);
dwo_file->comp_dir = comp_dir;
dwo_file->sections.abbrev = sections.abbrev;
dwo_file->sections.line = sections.line;
memset (&result, 0, sizeof (result));
result.s.containing_section = section;
- result.is_virtual = 1;
+ result.is_virtual = true;
if (size == 0)
return result;
bounds of the real section. This is a pretty-rare event, so just
flag an error (easier) instead of a warning and trying to cope. */
if (sectp == NULL
- || offset + size > bfd_get_section_size (sectp))
+ || offset + size > bfd_section_size (sectp))
{
error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
" in section %s [in module %s]"),
- sectp ? bfd_section_name (abfd, sectp) : "<unknown>",
+ sectp ? bfd_section_name (sectp) : "<unknown>",
objfile_name (dwarf2_per_objfile->objfile));
}
struct objfile *objfile = dwarf2_per_objfile->objfile;
const struct dwp_hash_table *dwp_htab =
is_debug_types ? dwp_file->tus : dwp_file->cus;
- bfd *dbfd = dwp_file->dbfd;
+ bfd *dbfd = dwp_file->dbfd.get ();
const char *kind = is_debug_types ? "TU" : "CU";
struct dwo_file *dwo_file;
struct dwo_unit *dwo_unit;
fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
virtual_dwo_name.c_str ());
}
- dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
- dwo_file->dwo_name
- = (const char *) obstack_copy0 (&objfile->objfile_obstack,
- virtual_dwo_name.c_str (),
- virtual_dwo_name.size ());
+ dwo_file = new struct dwo_file;
+ dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack,
+ virtual_dwo_name);
dwo_file->comp_dir = comp_dir;
dwo_file->sections.abbrev =
create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.abbrev,
{
const struct dwp_hash_table *dwp_htab =
is_debug_types ? dwp_file->tus : dwp_file->cus;
- bfd *dbfd = dwp_file->dbfd;
+ bfd *dbfd = dwp_file->dbfd.get ();
uint32_t mask = dwp_htab->nr_slots - 1;
uint32_t hash = signature & mask;
uint32_t hash2 = ((signature >> 32) & mask) | 1;
if (comp_dir != NULL)
{
- char *path_to_try = concat (comp_dir, SLASH_STRING,
- file_name, (char *) NULL);
+ gdb::unique_xmalloc_ptr<char> path_to_try
+ (concat (comp_dir, SLASH_STRING, file_name, (char *) NULL));
/* NOTE: If comp_dir is a relative path, this will also try the
search path, which seems useful. */
gdb_bfd_ref_ptr abfd (try_open_dwop_file (dwarf2_per_objfile,
- path_to_try,
+ path_to_try.get (),
0 /*is_dwp*/,
1 /*search_cwd*/));
- xfree (path_to_try);
if (abfd != NULL)
return abfd;
}
if (section_is_p (sectp->name, &names->abbrev_dwo))
{
dwo_sections->abbrev.s.section = sectp;
- dwo_sections->abbrev.size = bfd_get_section_size (sectp);
+ dwo_sections->abbrev.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->info_dwo))
{
dwo_sections->info.s.section = sectp;
- dwo_sections->info.size = bfd_get_section_size (sectp);
+ dwo_sections->info.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->line_dwo))
{
dwo_sections->line.s.section = sectp;
- dwo_sections->line.size = bfd_get_section_size (sectp);
+ dwo_sections->line.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->loc_dwo))
{
dwo_sections->loc.s.section = sectp;
- dwo_sections->loc.size = bfd_get_section_size (sectp);
+ dwo_sections->loc.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macinfo_dwo))
{
dwo_sections->macinfo.s.section = sectp;
- dwo_sections->macinfo.size = bfd_get_section_size (sectp);
+ dwo_sections->macinfo.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macro_dwo))
{
dwo_sections->macro.s.section = sectp;
- dwo_sections->macro.size = bfd_get_section_size (sectp);
+ dwo_sections->macro.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->str_dwo))
{
dwo_sections->str.s.section = sectp;
- dwo_sections->str.size = bfd_get_section_size (sectp);
+ dwo_sections->str.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->str_offsets_dwo))
{
dwo_sections->str_offsets.s.section = sectp;
- dwo_sections->str_offsets.size = bfd_get_section_size (sectp);
+ dwo_sections->str_offsets.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->types_dwo))
{
memset (&type_section, 0, sizeof (type_section));
type_section.s.section = sectp;
- type_section.size = bfd_get_section_size (sectp);
- VEC_safe_push (dwarf2_section_info_def, dwo_sections->types,
- &type_section);
+ type_section.size = bfd_section_size (sectp);
+ dwo_sections->types.push_back (type_section);
}
}
const char *dwo_name, const char *comp_dir)
{
struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
- struct objfile *objfile = dwarf2_per_objfile->objfile;
- struct dwo_file *dwo_file;
- struct cleanup *cleanups;
- gdb_bfd_ref_ptr dbfd (open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir));
+ gdb_bfd_ref_ptr dbfd = open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir);
if (dbfd == NULL)
{
if (dwarf_read_debug)
fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
return NULL;
}
- dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
+
+ dwo_file_up dwo_file (new struct dwo_file);
dwo_file->dwo_name = dwo_name;
dwo_file->comp_dir = comp_dir;
- dwo_file->dbfd = dbfd.release ();
-
- free_dwo_file_cleanup_data *cleanup_data = XNEW (free_dwo_file_cleanup_data);
- cleanup_data->dwo_file = dwo_file;
- cleanup_data->dwarf2_per_objfile = dwarf2_per_objfile;
-
- cleanups = make_cleanup (free_dwo_file_cleanup, cleanup_data);
+ dwo_file->dbfd = std::move (dbfd);
- bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections,
+ bfd_map_over_sections (dwo_file->dbfd.get (), dwarf2_locate_dwo_sections,
&dwo_file->sections);
create_cus_hash_table (dwarf2_per_objfile, *dwo_file, dwo_file->sections.info,
dwo_file->cus);
- create_debug_types_hash_table (dwarf2_per_objfile, dwo_file,
+ create_debug_types_hash_table (dwarf2_per_objfile, dwo_file.get (),
dwo_file->sections.types, dwo_file->tus);
- discard_cleanups (cleanups);
-
if (dwarf_read_debug)
fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
- return dwo_file;
+ return dwo_file.release ();
}
/* This function is mapped across the sections and remembers the offset and
if (section_is_p (sectp->name, &names->str_dwo))
{
dwp_file->sections.str.s.section = sectp;
- dwp_file->sections.str.size = bfd_get_section_size (sectp);
+ dwp_file->sections.str.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->cu_index))
{
dwp_file->sections.cu_index.s.section = sectp;
- dwp_file->sections.cu_index.size = bfd_get_section_size (sectp);
+ dwp_file->sections.cu_index.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->tu_index))
{
dwp_file->sections.tu_index.s.section = sectp;
- dwp_file->sections.tu_index.size = bfd_get_section_size (sectp);
+ dwp_file->sections.tu_index.size = bfd_section_size (sectp);
}
}
if (section_is_p (sectp->name, &names->abbrev_dwo))
{
dwp_file->sections.abbrev.s.section = sectp;
- dwp_file->sections.abbrev.size = bfd_get_section_size (sectp);
+ dwp_file->sections.abbrev.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->info_dwo))
{
dwp_file->sections.info.s.section = sectp;
- dwp_file->sections.info.size = bfd_get_section_size (sectp);
+ dwp_file->sections.info.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->line_dwo))
{
dwp_file->sections.line.s.section = sectp;
- dwp_file->sections.line.size = bfd_get_section_size (sectp);
+ dwp_file->sections.line.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->loc_dwo))
{
dwp_file->sections.loc.s.section = sectp;
- dwp_file->sections.loc.size = bfd_get_section_size (sectp);
+ dwp_file->sections.loc.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macinfo_dwo))
{
dwp_file->sections.macinfo.s.section = sectp;
- dwp_file->sections.macinfo.size = bfd_get_section_size (sectp);
+ dwp_file->sections.macinfo.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->macro_dwo))
{
dwp_file->sections.macro.s.section = sectp;
- dwp_file->sections.macro.size = bfd_get_section_size (sectp);
+ dwp_file->sections.macro.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->str_offsets_dwo))
{
dwp_file->sections.str_offsets.s.section = sectp;
- dwp_file->sections.str_offsets.size = bfd_get_section_size (sectp);
+ dwp_file->sections.str_offsets.size = bfd_section_size (sectp);
}
else if (section_is_p (sectp->name, &names->types_dwo))
{
dwp_file->sections.types.s.section = sectp;
- dwp_file->sections.types.size = bfd_get_section_size (sectp);
+ dwp_file->sections.types.size = bfd_section_size (sectp);
}
}
By convention the name of the DWP file is ${objfile}.dwp.
The result is NULL if it can't be found. */
-static struct dwp_file *
+static std::unique_ptr<struct dwp_file>
open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- struct dwp_file *dwp_file;
/* Try to find first .dwp for the binary file before any symbolic links
resolving. */
{
if (dwarf_read_debug)
fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name.c_str ());
- return NULL;
+ return std::unique_ptr<dwp_file> ();
}
- dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file);
- dwp_file->name = bfd_get_filename (dbfd.get ());
- dwp_file->dbfd = dbfd.release ();
- /* +1: section 0 is unused */
- dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1;
+ const char *name = bfd_get_filename (dbfd.get ());
+ std::unique_ptr<struct dwp_file> dwp_file
+ (new struct dwp_file (name, std::move (dbfd)));
+
+ dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
dwp_file->elf_sections =
OBSTACK_CALLOC (&objfile->objfile_obstack,
dwp_file->num_sections, asection *);
- bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_common_dwp_sections,
- dwp_file);
+ bfd_map_over_sections (dwp_file->dbfd.get (),
+ dwarf2_locate_common_dwp_sections,
+ dwp_file.get ());
- dwp_file->cus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file, 0);
+ dwp_file->cus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (),
+ 0);
- dwp_file->tus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file, 1);
+ dwp_file->tus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (),
+ 1);
/* The DWP file version is stored in the hash table. Oh well. */
if (dwp_file->cus && dwp_file->tus
dwp_file->version = 2;
if (dwp_file->version == 2)
- bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_v2_dwp_sections,
- dwp_file);
+ bfd_map_over_sections (dwp_file->dbfd.get (),
+ dwarf2_locate_v2_dwp_sections,
+ dwp_file.get ());
dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table (objfile);
dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table (objfile);
= open_and_init_dwp_file (dwarf2_per_objfile);
dwarf2_per_objfile->dwp_checked = 1;
}
- return dwarf2_per_objfile->dwp_file;
+ return dwarf2_per_objfile->dwp_file.get ();
}
/* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
while processing PER_CU. */
if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language))
load_full_type_unit (sig_cu);
- VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu);
+ per_cu->imported_symtabs_push (sig_cu);
}
return 1;
htab_traverse_noresize (dwo_file->tus, queue_and_load_dwo_tu, per_cu);
}
-/* Free all resources associated with DWO_FILE.
- Close the DWO file and munmap the sections.
- All memory should be on the objfile obstack. */
-
-static void
-free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
-{
-
- /* Note: dbfd is NULL for virtual DWO files. */
- gdb_bfd_unref (dwo_file->dbfd);
-
- VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
-}
-
-/* Wrapper for free_dwo_file for use in cleanups. */
-
-static void
-free_dwo_file_cleanup (void *arg)
-{
- struct free_dwo_file_cleanup_data *data
- = (struct free_dwo_file_cleanup_data *) arg;
- struct objfile *objfile = data->dwarf2_per_objfile->objfile;
-
- free_dwo_file (data->dwo_file, objfile);
-
- xfree (data);
-}
-
-/* Traversal function for free_dwo_files. */
-
-static int
-free_dwo_file_from_slot (void **slot, void *info)
-{
- struct dwo_file *dwo_file = (struct dwo_file *) *slot;
- struct objfile *objfile = (struct objfile *) info;
-
- free_dwo_file (dwo_file, objfile);
-
- return 1;
-}
-
-/* Free all resources associated with DWO_FILES. */
-
-static void
-free_dwo_files (htab_t dwo_files, struct objfile *objfile)
-{
- htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile);
-}
-\f
/* Read in various DIEs. */
/* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
if (die->tag != origin_die->tag
&& !(die->tag == DW_TAG_inlined_subroutine
&& origin_die->tag == DW_TAG_subprogram))
- complaint (&symfile_complaints,
- _("DIE %s and its abstract origin %s have different tags"),
+ complaint (_("DIE %s and its abstract origin %s have different tags"),
sect_offset_str (die->sect_off),
sect_offset_str (origin_die->sect_off));
if (child_die->tag != child_origin_die->tag
&& !(child_die->tag == DW_TAG_inlined_subroutine
&& child_origin_die->tag == DW_TAG_subprogram))
- complaint (&symfile_complaints,
- _("Child DIE %s and its abstract origin %s have "
+ complaint (_("Child DIE %s and its abstract origin %s have "
"different tags"),
sect_offset_str (child_die->sect_off),
sect_offset_str (child_origin_die->sect_off));
if (child_origin_die->parent != origin_die)
- complaint (&symfile_complaints,
- _("Child DIE %s and its abstract origin %s have "
+ complaint (_("Child DIE %s and its abstract origin %s have "
"different parents"),
sect_offset_str (child_die->sect_off),
sect_offset_str (child_origin_die->sect_off));
sect_offset *offsets_end = offsets.data () + offsets.size ();
for (offsetp = offsets.data () + 1; offsetp < offsets_end; offsetp++)
if (offsetp[-1] == *offsetp)
- complaint (&symfile_complaints,
- _("Multiple children of DIE %s refer "
+ complaint (_("Multiple children of DIE %s refer "
"to DIE %s as their abstract origin"),
sect_offset_str (die->sect_off), sect_offset_str (*offsetp));
origin_child_die = sibling_die (origin_child_die);
}
origin_cu->list_in_scope = origin_previous_list_in_scope;
+
+ if (cu != origin_cu)
+ compute_delayed_physnames (origin_cu);
}
static void
}
}
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
name = dwarf2_name (die, cu);
illegal according to the DWARF standard. */
if (name == NULL)
{
- complaint (&symfile_complaints,
- _("missing name for subprogram DIE at %s"),
+ complaint (_("missing name for subprogram DIE at %s"),
sect_offset_str (die->sect_off));
return;
}
{
attr = dwarf2_attr (die, DW_AT_external, cu);
if (!attr || !DW_UNSND (attr))
- complaint (&symfile_complaints,
- _("cannot get low and high bounds "
+ complaint (_("cannot get low and high bounds "
"for subprogram DIE at %s"),
sect_offset_str (die->sect_off));
return;
}
}
- newobj = push_context (0, lowpc);
+ newobj = cu->get_builder ()->push_context (0, lowpc);
newobj->name = new_symbol (die, read_type_die (die, cu), cu,
(struct symbol *) templ_func);
+ if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
+ set_objfile_main_name (objfile, newobj->name->linkage_name (),
+ cu->language);
+
/* If there is a location expression for DW_AT_frame_base, record
it. */
attr = dwarf2_attr (die, DW_AT_frame_base, cu);
- if (attr)
+ if (attr != nullptr)
dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1);
/* If there is a location for the static link, record it. */
newobj->static_link = NULL;
attr = dwarf2_attr (die, DW_AT_static_link, cu);
- if (attr)
+ if (attr != nullptr)
{
newobj->static_link
= XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
- attr_to_dynamic_prop (attr, die, cu, newobj->static_link);
+ attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
+ dwarf2_per_cu_addr_type (cu->per_cu));
}
- cu->list_in_scope = &local_symbols;
+ cu->list_in_scope = cu->get_builder ()->get_local_symbols ();
if (die->child != NULL)
{
}
}
- newobj = pop_context ();
+ struct context_stack cstk = cu->get_builder ()->pop_context ();
/* Make a block for the local symbols within. */
- block = finish_block (newobj->name, &local_symbols, newobj->old_blocks,
- newobj->static_link, lowpc, highpc);
+ block = cu->get_builder ()->finish_block (cstk.name, cstk.old_blocks,
+ cstk.static_link, lowpc, highpc);
/* For C++, set the block's scope. */
if ((cu->language == language_cplus
/* If we have address ranges, record them. */
dwarf2_record_block_ranges (die, block, baseaddr, cu);
- gdbarch_make_symbol_special (gdbarch, newobj->name, objfile);
+ gdbarch_make_symbol_special (gdbarch, cstk.name, objfile);
/* Attach template arguments to function. */
if (!template_args.empty ())
memcpy (templ_func->template_arguments,
template_args.data (),
(templ_func->n_template_arguments * sizeof (struct symbol *)));
+
+ /* Make sure that the symtab is set on the new symbols. Even
+ though they don't appear in this symtab directly, other parts
+ of gdb assume that symbols do, and this is reasonably
+ true. */
+ for (symbol *sym : template_args)
+ symbol_set_symtab (sym, symbol_symtab (templ_func));
}
/* In C++, we can have functions nested inside functions (e.g., when
a function declares a class that has methods). This means that
when we finish processing a function scope, we may need to go
back to building a containing block's symbol lists. */
- local_symbols = newobj->locals;
- local_using_directives = newobj->local_using_directives;
+ *cu->get_builder ()->get_local_symbols () = cstk.locals;
+ cu->get_builder ()->set_local_using_directives (cstk.local_using_directives);
/* If we've finished processing a top-level function, subsequent
symbols go in the file symbol list. */
- if (outermost_context_p ())
- cu->list_in_scope = &file_symbols;
+ if (cu->get_builder ()->outermost_context_p ())
+ cu->list_in_scope = cu->get_builder ()->get_file_symbols ();
}
/* Process all the DIES contained within a lexical block scope. Start
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- struct context_stack *newobj;
CORE_ADDR lowpc, highpc;
struct die_info *child_die;
CORE_ADDR baseaddr;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
/* Ignore blocks with missing or invalid low and high pc attributes. */
/* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
- push_context (0, lowpc);
+ cu->get_builder ()->push_context (0, lowpc);
if (die->child != NULL)
{
child_die = die->child;
}
}
inherit_abstract_dies (die, cu);
- newobj = pop_context ();
+ struct context_stack cstk = cu->get_builder ()->pop_context ();
- if (local_symbols != NULL || local_using_directives != NULL)
+ if (*cu->get_builder ()->get_local_symbols () != NULL
+ || (*cu->get_builder ()->get_local_using_directives ()) != NULL)
{
struct block *block
- = finish_block (0, &local_symbols, newobj->old_blocks, NULL,
- newobj->start_addr, highpc);
+ = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL,
+ cstk.start_addr, highpc);
/* Note that recording ranges after traversing children, as we
do here, means that recording a parent's ranges entails
to do. */
dwarf2_record_block_ranges (die, block, baseaddr, cu);
}
- local_symbols = newobj->locals;
- local_using_directives = newobj->local_using_directives;
+ *cu->get_builder ()->get_local_symbols () = cstk.locals;
+ cu->get_builder ()->set_local_using_directives (cstk.local_using_directives);
}
/* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
int nparams;
struct die_info *child_die;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
attr = dwarf2_attr (die, DW_AT_call_return_pc, cu);
if (attr == NULL)
}
if (!attr)
{
- complaint (&symfile_complaints,
- _("missing DW_AT_call_return_pc for DW_TAG_call_site "
+ complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
"DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
return;
slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
if (*slot != NULL)
{
- complaint (&symfile_complaints,
- _("Duplicate PC %s for DW_TAG_call_site "
+ complaint (_("Duplicate PC %s for DW_TAG_call_site "
"DIE %s [in module %s]"),
paddress (gdbarch, pc), sect_offset_str (die->sect_off),
objfile_name (objfile));
if (child_die->tag != DW_TAG_call_site_parameter
&& child_die->tag != DW_TAG_GNU_call_site_parameter)
{
- complaint (&symfile_complaints,
- _("Tag %d is not DW_TAG_call_site_parameter in "
+ complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
"DW_TAG_call_site child DIE %s [in module %s]"),
child_die->tag, sect_offset_str (child_die->sect_off),
objfile_name (objfile));
TYPE_TAIL_CALL_LIST (func_type) = call_site;
}
else
- complaint (&symfile_complaints,
- _("Cannot find function owning DW_TAG_call_site "
+ complaint (_("Cannot find function owning DW_TAG_call_site "
"DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
}
if (target_physname == NULL)
target_physname = dwarf2_physname (NULL, target_die, target_cu);
if (target_physname == NULL)
- complaint (&symfile_complaints,
- _("DW_AT_call_target target DIE has invalid "
+ complaint (_("DW_AT_call_target target DIE has invalid "
"physname, for referencing DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
else
/* DW_AT_entry_pc should be preferred. */
if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)
<= PC_BOUNDS_INVALID)
- complaint (&symfile_complaints,
- _("DW_AT_call_target target DIE has invalid "
+ complaint (_("DW_AT_call_target target DIE has invalid "
"low pc, for referencing DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
else
}
}
else
- complaint (&symfile_complaints,
- _("DW_TAG_call_site DW_AT_call_target is neither "
+ complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
"block nor reference, for DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
/* As DW_OP_GNU_parameter_ref uses CU-relative offset this
binding can be done only inside one CU. Such referenced DIE
therefore cannot be even moved to DW_TAG_partial_unit. */
- complaint (&symfile_complaints,
- _("DW_AT_call_parameter offset is not in CU for "
+ complaint (_("DW_AT_call_parameter offset is not in CU for "
"DW_TAG_call_site child DIE %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (objfile));
}
else if (loc == NULL || origin != NULL || !attr_form_is_block (loc))
{
- complaint (&symfile_complaints,
- _("No DW_FORM_block* DW_AT_location for "
+ complaint (_("No DW_FORM_block* DW_AT_location for "
"DW_TAG_call_site child DIE %s [in module %s]"),
sect_offset_str (child_die->sect_off), objfile_name (objfile));
continue;
parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
else
{
- complaint (&symfile_complaints,
- _("Only single DW_OP_reg or DW_OP_fbreg is supported "
+ complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
"for DW_FORM_block* DW_AT_location is supported for "
"DW_TAG_call_site child DIE %s "
"[in module %s]"),
attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
if (!attr_form_is_block (attr))
{
- complaint (&symfile_complaints,
- _("No DW_FORM_block* DW_AT_call_value for "
+ complaint (_("No DW_FORM_block* DW_AT_call_value for "
"DW_TAG_call_site child DIE %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (objfile));
attr = dwarf2_attr (child_die, DW_AT_call_data_value, cu);
if (attr == NULL)
attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
- if (attr)
+ if (attr != nullptr)
{
if (!attr_form_is_block (attr))
- complaint (&symfile_complaints,
- _("No DW_FORM_block* DW_AT_call_data_value for "
+ complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
"DW_TAG_call_site child DIE %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (objfile));
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
- storage = OBSTACK_ZALLOC (&objfile->objfile_obstack,
- struct rust_vtable_symbol);
+ storage = new (&objfile->objfile_obstack) rust_vtable_symbol ();
initialize_objfile_symbol (storage);
storage->concrete_type = containing_type;
storage->subclass = SYMBOL_RUST_VTABLE;
}
}
- new_symbol (die, NULL, cu, storage);
+ struct symbol *res = new_symbol (die, NULL, cu, storage);
+ struct attribute *abstract_origin
+ = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+ struct attribute *loc = dwarf2_attr (die, DW_AT_location, cu);
+ if (res == NULL && loc && abstract_origin)
+ {
+ /* We have a variable without a name, but with a location and an abstract
+ origin. This may be a concrete instance of an abstract variable
+ referenced from an DW_OP_GNU_variable_value, so save it to find it back
+ later. */
+ struct dwarf2_cu *origin_cu = cu;
+ struct die_info *origin_die
+ = follow_die_ref (die, abstract_origin, &origin_cu);
+ dwarf2_per_objfile *dpo = cu->per_cu->dwarf2_per_objfile;
+ dpo->abstract_to_concrete[origin_die->sect_off].push_back (die->sect_off);
+ }
}
/* Call CALLBACK from DW_AT_ranges attribute value OFFSET
dwarf2_read_section (objfile, &dwarf2_per_objfile->rnglists);
if (offset >= dwarf2_per_objfile->rnglists.size)
{
- complaint (&symfile_complaints,
- _("Offset %d out of bounds for DW_AT_ranges attribute"),
+ complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
offset);
return false;
}
buffer = dwarf2_per_objfile->rnglists.buffer + offset;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
while (1)
{
buffer += bytes_read;
break;
default:
- complaint (&symfile_complaints,
- _("Invalid .debug_rnglists data (no base address)"));
+ complaint (_("Invalid .debug_rnglists data (no base address)"));
return false;
}
if (rlet == DW_RLE_end_of_list || overflow)
{
/* We have no valid base address for the ranges
data. */
- complaint (&symfile_complaints,
- _("Invalid .debug_rnglists data (no base address)"));
+ complaint (_("Invalid .debug_rnglists data (no base address)"));
return false;
}
if (range_beginning > range_end)
{
/* Inverted range entries are invalid. */
- complaint (&symfile_complaints,
- _("Invalid .debug_rnglists data (inverted range)"));
+ complaint (_("Invalid .debug_rnglists data (inverted range)"));
return false;
}
if (range_beginning + baseaddr == 0
&& !dwarf2_per_objfile->has_section_at_zero)
{
- complaint (&symfile_complaints,
- _(".debug_rnglists entry has start address of zero"
+ complaint (_(".debug_rnglists entry has start address of zero"
" [in module %s]"), objfile_name (objfile));
continue;
}
if (overflow)
{
- complaint (&symfile_complaints,
- _("Offset %d is not terminated "
+ complaint (_("Offset %d is not terminated "
"for DW_AT_ranges attribute"),
offset);
return false;
dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
if (offset >= dwarf2_per_objfile->ranges.size)
{
- complaint (&symfile_complaints,
- _("Offset %d out of bounds for DW_AT_ranges attribute"),
+ complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
offset);
return 0;
}
buffer = dwarf2_per_objfile->ranges.buffer + offset;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
while (1)
{
{
/* We have no valid base address for the ranges
data. */
- complaint (&symfile_complaints,
- _("Invalid .debug_ranges data (no base address)"));
+ complaint (_("Invalid .debug_ranges data (no base address)"));
return 0;
}
if (range_beginning > range_end)
{
/* Inverted range entries are invalid. */
- complaint (&symfile_complaints,
- _("Invalid .debug_ranges data (inverted range)"));
+ complaint (_("Invalid .debug_ranges data (inverted range)"));
return 0;
}
if (range_beginning + baseaddr == 0
&& !dwarf2_per_objfile->has_section_at_zero)
{
- complaint (&symfile_complaints,
- _(".debug_ranges entry has start address of zero"
+ complaint (_(".debug_ranges entry has start address of zero"
" [in module %s]"), objfile_name (objfile));
continue;
}
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
- SECT_OFF_TEXT (objfile));
+ const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
int low_set = 0;
CORE_ADDR low = 0;
CORE_ADDR high = 0;
CORE_ADDR lowpc;
CORE_ADDR highpc;
- lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- range_beginning + baseaddr);
- highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
- range_end + baseaddr);
- addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
- ranges_pst);
+ lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ range_beginning + baseaddr)
+ - baseaddr);
+ highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+ range_end + baseaddr)
+ - baseaddr);
+ addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+ lowpc, highpc - 1, ranges_pst);
}
/* FIXME: This is recording everything as a low-high
if (attr_high)
{
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
- if (attr)
+ if (attr != nullptr)
{
low = attr_value_as_address (attr);
high = attr_value_as_address (attr_high);
if (attr_high)
{
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
- if (attr)
+ if (attr != nullptr)
{
CORE_ADDR low = attr_value_as_address (attr);
CORE_ADDR high = attr_value_as_address (attr_high);
low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr);
high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr);
- record_block_range (block, low, high - 1);
+ cu->get_builder ()->record_block_range (block, low, high - 1);
}
}
attr = dwarf2_attr (die, DW_AT_ranges, cu);
- if (attr)
+ if (attr != nullptr)
{
/* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
We take advantage of the fact that DW_AT_ranges does not appear
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;
+ std::vector<blockrange> blockvec;
dwarf2_ranges_process (offset, cu,
[&] (CORE_ADDR start, CORE_ADDR end)
{
end += baseaddr;
start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
- record_block_range (block, start, end - 1);
+ cu->get_builder ()->record_block_range (block, start, end - 1);
+ blockvec.emplace_back (start, end);
});
+
+ BLOCK_RANGES(block) = make_blockranges (objfile, blockvec);
}
}
cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
}
else if (producer_is_icc (cu->producer, &major, &minor))
- cu->producer_is_icc_lt_14 = major < 14;
+ {
+ cu->producer_is_icc = true;
+ cu->producer_is_icc_lt_14 = major < 14;
+ }
+ else if (startswith (cu->producer, "CodeWarrior S12/L-ISA"))
+ cu->producer_is_codewarrior = true;
else
{
/* For other non-GCC compilers, expect their behavior is DWARF version
compliant. */
}
- cu->checked_producer = 1;
+ cu->checked_producer = true;
}
/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
during 4.6.0 experimental. */
-static int
+static bool
producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
{
if (!cu->checked_producer)
return cu->producer_is_gxx_lt_4_6;
}
-/* Return the default accessibility type if it is not overriden by
+
+/* Codewarrior (at least as of version 5.0.40) generates dwarf line information
+ with incorrect is_stmt attributes. */
+
+static bool
+producer_is_codewarrior (struct dwarf2_cu *cu)
+{
+ if (!cu->checked_producer)
+ check_producer (cu);
+
+ return cu->producer_is_codewarrior;
+}
+
+/* Return the default accessibility type if it is not overridden by
DW_AT_accessibility. */
static enum dwarf_access_attribute
fip->nfields++;
attr = dwarf2_attr (die, DW_AT_accessibility, cu);
- if (attr)
+ if (attr != nullptr)
new_field->accessibility = DW_UNSND (attr);
else
new_field->accessibility = dwarf2_default_access_attribute (die, cu);
fip->non_public_fields = 1;
attr = dwarf2_attr (die, DW_AT_virtuality, cu);
- if (attr)
+ if (attr != nullptr)
new_field->virtuality = DW_UNSND (attr);
else
new_field->virtuality = DW_VIRTUALITY_none;
/* Get bit size of field (zero if none). */
attr = dwarf2_attr (die, DW_AT_bit_size, cu);
- if (attr)
+ if (attr != nullptr)
{
FIELD_BITSIZE (*fp) = DW_UNSND (attr);
}
if (handle_data_member_location (die, cu, &offset))
SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
- if (attr)
+ if (attr != nullptr)
{
- if (gdbarch_bits_big_endian (gdbarch))
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
{
/* For big endian bits, the DW_AT_bit_offset gives the
additional bit offset from the MSB of the containing
int bit_offset = DW_UNSND (attr);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
{
/* The size of the anonymous object containing
the bit field is explicit, so use the
SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
FIELD_BITSIZE (*fp) = 0;
FIELD_TYPE (*fp) = die_type (die, cu);
- FIELD_NAME (*fp) = type_name_no_tag (fp->type);
+ FIELD_NAME (*fp) = TYPE_NAME (fp->type);
}
else if (die->tag == DW_TAG_variant_part)
{
fp->type = get_die_type (die, cu);
fp->artificial = 1;
fp->name = "<<variant>>";
+
+ /* Normally a DW_TAG_variant_part won't have a size, but our
+ representation requires one, so set it to the maximum of the
+ child sizes, being sure to account for the offset at which
+ each child is seen. */
+ if (TYPE_LENGTH (fp->type) == 0)
+ {
+ unsigned max = 0;
+ for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i)
+ {
+ unsigned len = ((TYPE_FIELD_BITPOS (fp->type, i) + 7) / 8
+ + TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)));
+ if (len > max)
+ max = len;
+ }
+ TYPE_LENGTH (fp->type) = max;
+ }
}
else
gdb_assert_not_reached ("missing case in dwarf2_add_field");
fp.is_protected = 1;
break;
default:
- complaint (&symfile_complaints,
- _("Unhandled DW_AT_accessibility value (%x)"), accessibility);
+ complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility);
}
if (die->tag == DW_TAG_typedef)
default:
/* Unknown accessibility. Complain and treat it as public. */
{
- complaint (&symfile_complaints, _("unsupported accessibility %d"),
+ complaint (_("unsupported accessibility %d"),
field.accessibility);
}
break;
&& (type_name[len] == '\0' || type_name[len] == '<'));
}
+/* Check if the given VALUE is a recognized enum
+ dwarf_defaulted_attribute constant according to DWARF5 spec,
+ Table 7.24. */
+
+static bool
+is_valid_DW_AT_defaulted (ULONGEST value)
+{
+ switch (value)
+ {
+ case DW_DEFAULTED_no:
+ case DW_DEFAULTED_in_class:
+ case DW_DEFAULTED_out_of_class:
+ return true;
+ }
+
+ complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value));
+ return false;
+}
+
/* Add a member function to the proper fieldlist. */
static void
fnp->voffset = VOFFSET_STATIC;
}
else
- complaint (&symfile_complaints, _("member function type missing for '%s'"),
+ complaint (_("member function type missing for '%s'"),
dwarf2_full_name (fieldname, die, cu));
/* Get fcontext from DW_AT_containing_type if present. */
/* Get accessibility. */
attr = dwarf2_attr (die, DW_AT_accessibility, cu);
- if (attr)
+ if (attr != nullptr)
accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
else
accessibility = dwarf2_default_access_attribute (die, cu);
if (attr && DW_UNSND (attr) != 0)
fnp->is_artificial = 1;
+ /* Check for defaulted methods. */
+ attr = dwarf2_attr (die, DW_AT_defaulted, cu);
+ if (attr != nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr)))
+ fnp->defaulted = (enum dwarf_defaulted_attribute) DW_UNSND (attr);
+
+ /* Check for deleted methods. */
+ attr = dwarf2_attr (die, DW_AT_deleted, cu);
+ if (attr != nullptr && DW_UNSND (attr) != 0)
+ fnp->is_deleted = 1;
+
fnp->is_constructor = dwarf2_is_constructor (die, cu);
/* Get index in virtual function table if it is a virtual member
to the object address. */
attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
- if (attr)
+ if (attr != nullptr)
{
if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
{
if (TYPE_NFIELDS (this_type) == 0
|| !TYPE_FIELD_ARTIFICIAL (this_type, 0))
{
- complaint (&symfile_complaints,
- _("cannot determine context for virtual member "
+ complaint (_("cannot determine context for virtual member "
"function \"%s\" (offset %s)"),
fieldname, sect_offset_str (die->sect_off));
}
if (attr && DW_UNSND (attr))
{
/* GCC does this, as of 2008-08-25; PR debug/37237. */
- complaint (&symfile_complaints,
- _("Member function \"%s\" (offset %s) is virtual "
+ complaint (_("Member function \"%s\" (offset %s) is virtual "
"but the vtable offset is not specified"),
fieldname, sect_offset_str (die->sect_off));
ALLOCATE_CPLUS_STRUCT_TYPE (type);
smash_to_methodptr_type (type, new_type);
}
+/* If the DIE has a DW_AT_alignment attribute, return its value, doing
+ appropriate error checking and issuing complaints if there is a
+ problem. */
+
+static ULONGEST
+get_alignment (struct dwarf2_cu *cu, struct die_info *die)
+{
+ struct attribute *attr = dwarf2_attr (die, DW_AT_alignment, cu);
+
+ if (attr == nullptr)
+ return 0;
+
+ if (!attr_form_is_constant (attr))
+ {
+ complaint (_("DW_AT_alignment must have constant form"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ ULONGEST align;
+ if (attr->form == DW_FORM_sdata)
+ {
+ LONGEST val = DW_SND (attr);
+ if (val < 0)
+ {
+ complaint (_("DW_AT_alignment value must not be negative"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ align = val;
+ }
+ else
+ align = DW_UNSND (attr);
+
+ if (align == 0)
+ {
+ complaint (_("DW_AT_alignment value must not be zero"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ if ((align & (align - 1)) != 0)
+ {
+ complaint (_("DW_AT_alignment value must be a power of 2"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ return align;
+}
+
+/* If the DIE has a DW_AT_alignment attribute, use its value to set
+ the alignment for TYPE. */
+
+static void
+maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
+ struct type *type)
+{
+ if (!set_type_align (type, get_alignment (cu, die)))
+ complaint (_("DW_AT_alignment value too large"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+}
+
+/* Check if the given VALUE is a valid enum dwarf_calling_convention
+ constant for a type, according to DWARF5 spec, Table 5.5. */
+
+static bool
+is_valid_DW_AT_calling_convention_for_type (ULONGEST value)
+{
+ switch (value)
+ {
+ case DW_CC_normal:
+ case DW_CC_pass_by_reference:
+ case DW_CC_pass_by_value:
+ return true;
+
+ default:
+ complaint (_("unrecognized DW_AT_calling_convention value "
+ "(%s) for a type"), pulongest (value));
+ return false;
+ }
+}
+
+/* Check if the given VALUE is a valid enum dwarf_calling_convention
+ constant for a subroutine, according to DWARF5 spec, Table 3.3, and
+ also according to GNU-specific values (see include/dwarf2.h). */
+
+static bool
+is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value)
+{
+ switch (value)
+ {
+ case DW_CC_normal:
+ case DW_CC_program:
+ case DW_CC_nocall:
+ return true;
+
+ case DW_CC_GNU_renesas_sh:
+ case DW_CC_GNU_borland_fastcall_i386:
+ case DW_CC_GDB_IBM_OpenCL:
+ return true;
+
+ default:
+ complaint (_("unrecognized DW_AT_calling_convention value "
+ "(%s) for a subroutine"), pulongest (value));
+ return false;
+ }
+}
/* Called when we find the DIE that starts a structure or union scope
(definition) to create a type for the structure or union. Fill in
Don't follow DW_AT_specification though, that will take us back up
the chain and we want to go down. */
attr = dwarf2_attr_no_follow (die, DW_AT_signature);
- if (attr)
+ if (attr != nullptr)
{
type = get_DW_AT_signature_type (die, attr, cu);
if (get_die_type (die, cu) != NULL)
return get_die_type (die, cu);
- TYPE_TAG_NAME (type) = full_name;
- if (die->tag == DW_TAG_structure_type
- || die->tag == DW_TAG_class_type)
- TYPE_NAME (type) = TYPE_TAG_NAME (type);
+ TYPE_NAME (type) = full_name;
}
else
{
/* The name is already allocated along with this objfile, so
we don't need to duplicate it for the type. */
- TYPE_TAG_NAME (type) = name;
- if (die->tag == DW_TAG_class_type)
- TYPE_NAME (type) = TYPE_TAG_NAME (type);
+ TYPE_NAME (type) = name;
}
}
if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
TYPE_DECLARED_CLASS (type) = 1;
+ /* Store the calling convention in the type if it's available in
+ the die. Otherwise the calling convention remains set to
+ the default value DW_CC_normal. */
+ attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
+ if (attr != nullptr
+ && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr)))
+ {
+ ALLOCATE_CPLUS_STRUCT_TYPE (type);
+ TYPE_CPLUS_CALLING_CONVENTION (type)
+ = (enum dwarf_calling_convention) (DW_UNSND (attr));
+ }
+
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
{
if (attr_form_is_constant (attr))
TYPE_LENGTH (type) = DW_UNSND (attr);
TYPE_LENGTH (type) = 0;
}
+ maybe_set_alignment (cu, die, type);
+
if (producer_is_icc_lt_14 (cu) && (TYPE_LENGTH (type) == 0))
{
/* ICC<14 does not output the required DW_AT_declaration on
field for our sole member child. */
struct attribute *discr = dwarf2_attr (child_die, DW_AT_discr_value, cu);
- for (struct die_info *variant_child = child_die->child;
+ for (die_info *variant_child = child_die->child;
variant_child != NULL;
variant_child = sibling_die (variant_child))
{
/* We don't handle this but we might as well report it if we see
it. */
if (dwarf2_attr (child_die, DW_AT_discr_list, cu) != nullptr)
- complaint (&symfile_complaints,
- _("DW_AT_discr_list is not supported yet"
+ complaint (_("DW_AT_discr_list is not supported yet"
" - DIE at %s [in module %s]"),
sect_offset_str (child_die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
read the discriminant member, so we can record it later in the
discriminant_info. */
bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type);
- sect_offset discr_offset;
+ sect_offset discr_offset {};
+ bool has_template_parameters = false;
if (is_variant_part)
{
}
else
{
- complaint (&symfile_complaints,
- _("DW_AT_discr does not have DIE reference form"
+ complaint (_("DW_AT_discr does not have DIE reference form"
" - DIE at %s [in module %s]"),
sect_offset_str (die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
/* Attach template arguments to type. */
if (!template_args.empty ())
{
+ has_template_parameters = true;
ALLOCATE_CPLUS_STRUCT_TYPE (type);
TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
TYPE_TEMPLATE_ARGUMENTS (type)
/* Complain if virtual function table field not found. */
if (i < TYPE_N_BASECLASSES (t))
- complaint (&symfile_complaints,
- _("virtual function table pointer "
+ complaint (_("virtual function table pointer "
"not found when defining class '%s'"),
- TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
- "");
+ TYPE_NAME (type) ? TYPE_NAME (type) : "");
}
else
{
attribute, and a declaration attribute. */
if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
|| !die_is_declaration (die, cu))
- new_symbol (die, type, cu);
-}
-
-/* Assuming DIE is an enumeration type, and TYPE is its associated type,
- update TYPE using some information only available in DIE's children. */
+ {
+ struct symbol *sym = new_symbol (die, type, cu);
-static void
-update_enumeration_type_from_children (struct die_info *die,
- struct type *type,
- struct dwarf2_cu *cu)
-{
+ if (has_template_parameters)
+ {
+ struct symtab *symtab;
+ if (sym != nullptr)
+ symtab = symbol_symtab (sym);
+ else if (cu->line_header != nullptr)
+ {
+ /* Any related symtab will do. */
+ symtab
+ = cu->line_header->file_names ()[0].symtab;
+ }
+ else
+ {
+ symtab = nullptr;
+ complaint (_("could not find suitable "
+ "symtab for template parameter"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (objfile));
+ }
+
+ if (symtab != nullptr)
+ {
+ /* Make sure that the symtab is set on the new symbols.
+ Even though they don't appear in this symtab directly,
+ other parts of gdb assume that symbols do, and this is
+ reasonably true. */
+ for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
+ symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i), symtab);
+ }
+ }
+ }
+}
+
+/* Assuming DIE is an enumeration type, and TYPE is its associated type,
+ update TYPE using some information only available in DIE's children. */
+
+static void
+update_enumeration_type_from_children (struct die_info *die,
+ struct type *type,
+ struct dwarf2_cu *cu)
+{
struct die_info *child_die;
int unsigned_enum = 1;
int flag_enum = 1;
Don't follow DW_AT_specification though, that will take us back up
the chain and we want to go down. */
attr = dwarf2_attr_no_follow (die, DW_AT_signature);
- if (attr)
+ if (attr != nullptr)
{
type = get_DW_AT_signature_type (die, attr, cu);
TYPE_CODE (type) = TYPE_CODE_ENUM;
name = dwarf2_full_name (NULL, die, cu);
if (name != NULL)
- TYPE_TAG_NAME (type) = name;
+ TYPE_NAME (type) = name;
attr = dwarf2_attr (die, DW_AT_type, cu);
if (attr != NULL)
}
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
{
TYPE_LENGTH (type) = DW_UNSND (attr);
}
TYPE_LENGTH (type) = 0;
}
+ maybe_set_alignment (cu, die, type);
+
/* The enumeration DIE can be incomplete. In Ada, any type can be
declared as private in the package spec, and then defined only
inside the package body. Such types are known as Taft Amendment
TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type));
if (TYPE_LENGTH (type) == 0)
TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+ if (TYPE_RAW_ALIGN (type) == 0
+ && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type)) != 0)
+ set_type_align (type, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type)));
}
TYPE_DECLARED_CLASS (type) = dwarf2_flag_true_p (die, DW_AT_enum_class, cu);
{
struct die_info *child_die;
struct symbol *sym;
- struct field *fields = NULL;
- int num_fields = 0;
+ std::vector<struct field> fields;
const char *name;
child_die = die->child;
{
sym = new_symbol (child_die, this_type, cu);
- if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
- {
- fields = (struct field *)
- xrealloc (fields,
- (num_fields + DW_FIELD_ALLOC_CHUNK)
- * sizeof (struct field));
- }
-
- FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
- FIELD_TYPE (fields[num_fields]) = NULL;
- SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
- FIELD_BITSIZE (fields[num_fields]) = 0;
+ fields.emplace_back ();
+ struct field &field = fields.back ();
- num_fields++;
+ FIELD_NAME (field) = sym->linkage_name ();
+ FIELD_TYPE (field) = NULL;
+ SET_FIELD_ENUMVAL (field, SYMBOL_VALUE (sym));
+ FIELD_BITSIZE (field) = 0;
}
}
child_die = sibling_die (child_die);
}
- if (num_fields)
+ if (!fields.empty ())
{
- TYPE_NFIELDS (this_type) = num_fields;
+ TYPE_NFIELDS (this_type) = fields.size ();
TYPE_FIELDS (this_type) = (struct field *)
- TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
- memcpy (TYPE_FIELDS (this_type), fields,
- sizeof (struct field) * num_fields);
- xfree (fields);
+ TYPE_ALLOC (this_type, sizeof (struct field) * fields.size ());
+ memcpy (TYPE_FIELDS (this_type), fields.data (),
+ sizeof (struct field) * fields.size ());
}
}
if (attr != NULL)
{
int stride_ok;
+ struct type *prop_type
+ = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
byte_stride_prop
= (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
- stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop);
+ stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop,
+ prop_type);
if (!stride_ok)
{
- complaint (&symfile_complaints,
- _("unable to read array DW_AT_byte_stride "
+ complaint (_("unable to read array DW_AT_byte_stride "
" - DIE at %s [in module %s]"),
sect_offset_str (die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
array and the vector variant is that vectors are passed by value
to functions. */
attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
- if (attr)
+ if (attr != nullptr)
make_vector_type (type);
/* The DIE may have DW_AT_byte_size set. For example an OpenCL
implementation may choose to implement triple vectors using this
attribute. */
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
{
if (DW_UNSND (attr) >= TYPE_LENGTH (type))
TYPE_LENGTH (type) = DW_UNSND (attr);
else
- complaint (&symfile_complaints,
- _("DW_AT_byte_size for array type smaller "
+ complaint (_("DW_AT_byte_size for array type smaller "
"than the total size of elements"));
}
if (name)
TYPE_NAME (type) = name;
+ maybe_set_alignment (cu, die, type);
+
/* Install the type in the die. */
set_die_type (die, type, cu);
attr = dwarf2_attr (die, DW_AT_ordering, cu);
- if (attr)
+ if (attr != nullptr)
return (enum dwarf_array_dim_ordering) DW_SND (attr);
/* GNU F77 is a special case, as at 08/2004 array type info is the
set_type = create_set_type (NULL, domain_type);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
TYPE_LENGTH (set_type) = DW_UNSND (attr);
+ maybe_set_alignment (cu, die, set_type);
+
return set_die_type (die, set_type, cu);
}
/* Create appropriate locally-scoped variables for all the
DW_TAG_common_block entries. Also create a struct common_block
listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
- is used to sepate the common blocks name namespace from regular
+ is used to separate the common blocks name namespace from regular
variable names. */
static void
struct attribute *attr;
attr = dwarf2_attr (die, DW_AT_location, cu);
- if (attr)
+ if (attr != nullptr)
{
/* Support the .debug_loc offsets. */
if (attr_form_is_block (attr))
not specified by DWARF. It seems to have been
emitted by gfortran at least as recently as:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
- complaint (&symfile_complaints,
- _("Variable in common block has "
+ complaint (_("Variable in common block has "
"DW_AT_data_member_location "
"- DIE at %s [in module %s]"),
sect_offset_str (child_die->sect_off),
else if (attr_form_is_constant (member_loc)
|| attr_form_is_block (member_loc))
{
- if (attr)
+ if (attr != nullptr)
mark_common_block_symbol_computed (sym, die, attr,
member_loc, cu);
}
/* Create the type. */
type = init_type (objfile, TYPE_CODE_NAMESPACE, 0, name);
- TYPE_TAG_NAME (type) = TYPE_NAME (type);
return set_die_type (die, type, cu);
}
const char *previous_prefix = determine_prefix (die, cu);
std::vector<const char *> excludes;
- add_using_directive (using_directives (cu->language),
+ add_using_directive (using_directives (cu),
previous_prefix, TYPE_NAME (type), NULL,
NULL, excludes, 0, &objfile->objfile_obstack);
}
struct type *type;
module_name = dwarf2_name (die, cu);
- if (!module_name)
- complaint (&symfile_complaints,
- _("DW_TAG_module has no name, offset %s"),
- sect_offset_str (die->sect_off));
type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
- /* determine_prefix uses TYPE_TAG_NAME. */
- TYPE_TAG_NAME (type) = TYPE_NAME (type);
-
return set_die_type (die, type, cu);
}
else
addr_class = DW_ADDR_none;
- /* If the pointer size or address class is different than the
- default, create a type variant marked as such and set the
- length accordingly. */
- if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
+ ULONGEST alignment = get_alignment (cu, die);
+
+ /* If the pointer size, alignment, or address class is different
+ than the default, create a type variant marked as such and set
+ the length accordingly. */
+ if (TYPE_LENGTH (type) != byte_size
+ || (alignment != 0 && TYPE_RAW_ALIGN (type) != 0
+ && alignment != TYPE_RAW_ALIGN (type))
+ || addr_class != DW_ADDR_none)
{
if (gdbarch_address_class_type_flags_p (gdbarch))
{
}
else if (TYPE_LENGTH (type) != byte_size)
{
- complaint (&symfile_complaints,
- _("invalid pointer size %d"), byte_size);
+ complaint (_("invalid pointer size %d"), byte_size);
+ }
+ else if (TYPE_RAW_ALIGN (type) != alignment)
+ {
+ complaint (_("Invalid DW_AT_alignment"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
}
else
{
}
TYPE_LENGTH (type) = byte_size;
+ set_type_align (type, alignment);
return set_die_type (die, type, cu);
}
type = lookup_reference_type (target_type, refcode);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
{
TYPE_LENGTH (type) = DW_UNSND (attr);
}
{
TYPE_LENGTH (type) = cu_header->addr_size;
}
+ maybe_set_alignment (cu, die, type);
return set_die_type (die, type, cu);
}
struct gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *type, *range_type, *index_type, *char_type;
struct attribute *attr;
- unsigned int length;
+ struct dynamic_prop prop;
+ bool length_is_constant = true;
+ LONGEST length;
+
+ /* There are a couple of places where bit sizes might be made use of
+ when parsing a DW_TAG_string_type, however, no producer that we know
+ of make use of these. Handling bit sizes that are a multiple of the
+ byte size is easy enough, but what about other bit sizes? Lets deal
+ with that problem when we have to. Warn about these attributes being
+ unsupported, then parse the type and ignore them like we always
+ have. */
+ if (dwarf2_attr (die, DW_AT_bit_size, cu) != nullptr
+ || dwarf2_attr (die, DW_AT_string_length_bit_size, cu) != nullptr)
+ {
+ static bool warning_printed = false;
+ if (!warning_printed)
+ {
+ warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
+ "currently supported on DW_TAG_string_type."));
+ warning_printed = true;
+ }
+ }
attr = dwarf2_attr (die, DW_AT_string_length, cu);
- if (attr)
+ if (attr != nullptr && !attr_form_is_constant (attr))
+ {
+ /* The string length describes the location at which the length of
+ the string can be found. The size of the length field can be
+ specified with one of the attributes below. */
+ struct type *prop_type;
+ struct attribute *len
+ = dwarf2_attr (die, DW_AT_string_length_byte_size, cu);
+ if (len == nullptr)
+ len = dwarf2_attr (die, DW_AT_byte_size, cu);
+ if (len != nullptr && attr_form_is_constant (len))
+ {
+ /* Pass 0 as the default as we know this attribute is constant
+ and the default value will not be returned. */
+ LONGEST sz = dwarf2_get_attr_constant_value (len, 0);
+ prop_type = dwarf2_per_cu_int_type (cu->per_cu, sz, true);
+ }
+ else
+ {
+ /* If the size is not specified then we assume it is the size of
+ an address on this target. */
+ prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, true);
+ }
+
+ /* Convert the attribute into a dynamic property. */
+ if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
+ length = 1;
+ else
+ length_is_constant = false;
+ }
+ else if (attr != nullptr)
+ {
+ /* This DW_AT_string_length just contains the length with no
+ indirection. There's no need to create a dynamic property in this
+ case. Pass 0 for the default value as we know it will not be
+ returned in this case. */
+ length = dwarf2_get_attr_constant_value (attr, 0);
+ }
+ else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
{
- length = DW_UNSND (attr);
+ /* We don't currently support non-constant byte sizes for strings. */
+ length = dwarf2_get_attr_constant_value (attr, 1);
}
else
{
- /* Check for the DW_AT_byte_size attribute. */
- attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
- {
- length = DW_UNSND (attr);
- }
- else
- {
- length = 1;
- }
+ /* Use 1 as a fallback length if we have nothing else. */
+ length = 1;
}
index_type = objfile_type (objfile)->builtin_int;
- range_type = create_static_range_type (NULL, index_type, 1, length);
+ if (length_is_constant)
+ range_type = create_static_range_type (NULL, index_type, 1, length);
+ else
+ {
+ struct dynamic_prop low_bound;
+
+ low_bound.kind = PROP_CONST;
+ low_bound.data.const_val = 1;
+ range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
+ }
char_type = language_string_char_type (cu->language_defn, gdbarch);
type = create_string_type (NULL, char_type, range_type);
return 1;
/* The DWARF standard implies that the DW_AT_prototyped attribute
- is only meaninful for C, but the concept also extends to other
+ is only meaningful for C, but the concept also extends to other
languages that allow unprototyped functions (Eg: Objective C).
For all other languages, assume that functions are always
prototyped. */
the subroutine die. Otherwise set the calling convention to
the default value DW_CC_normal. */
attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
- if (attr)
- TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
+ if (attr != nullptr
+ && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr)))
+ TYPE_CALLING_CONVENTION (ftype)
+ = (enum dwarf_calling_convention) (DW_UNSND (attr));
else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
else
DWARF version 3 added DW_AT_object_pointer, which GCC
4.5 does not yet generate. */
attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
- if (attr)
+ if (attr != nullptr)
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
else
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
const char *name = dwarf2_name (child_die, cu);
attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
- if (attr)
+ if (attr != nullptr)
{
/* If the compiler emits this, use it. */
if (follow_die_ref (die, attr, &arg_cu) == child_die)
{
/* Self-referential typedefs are, it seems, not allowed by the DWARF
spec and cause infinite loops in GDB. */
- complaint (&symfile_complaints,
- _("Self-referential DW_TAG_typedef "
+ complaint (_("Self-referential DW_TAG_typedef "
"- DIE at %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
TYPE_TARGET_TYPE (this_type) = NULL;
static struct type *
dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
- const char *name_hint)
+ const char *name_hint, enum bfd_endian byte_order)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const struct floatformat **format;
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (objfile, bits, name, format, byte_order);
else
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
return type;
}
+/* Allocate an integer type of size BITS and name NAME. */
+
+static struct type *
+dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
+ int bits, int unsigned_p, const char *name)
+{
+ struct type *type;
+
+ /* Versions of Intel's C Compiler generate an integer type called "void"
+ instead of using DW_TAG_unspecified_type. This has been seen on
+ at least versions 14, 17, and 18. */
+ if (bits == 0 && producer_is_icc (cu) && name != nullptr
+ && strcmp (name, "void") == 0)
+ type = objfile_type (objfile)->builtin_void;
+ else
+ type = init_integer_type (objfile, bits, unsigned_p, name);
+
+ return type;
+}
+
+/* Initialise and return a floating point type of size BITS suitable for
+ use as a component of a complex number. The NAME_HINT is passed through
+ when initialising the floating point type and is the name of the complex
+ type.
+
+ As DWARF doesn't currently provide an explicit name for the components
+ of a complex number, but it can be helpful to have these components
+ named, we try to select a suitable name based on the size of the
+ component. */
+static struct type *
+dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
+ struct objfile *objfile,
+ int bits, const char *name_hint,
+ enum bfd_endian byte_order)
+{
+ gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct type *tt = nullptr;
+
+ /* Try to find a suitable floating point builtin type of size BITS.
+ We're going to use the name of this type as the name for the complex
+ target type that we are about to create. */
+ switch (cu->language)
+ {
+ case language_fortran:
+ switch (bits)
+ {
+ case 32:
+ tt = builtin_f_type (gdbarch)->builtin_real;
+ break;
+ case 64:
+ tt = builtin_f_type (gdbarch)->builtin_real_s8;
+ break;
+ case 96: /* The x86-32 ABI specifies 96-bit long double. */
+ case 128:
+ tt = builtin_f_type (gdbarch)->builtin_real_s16;
+ break;
+ }
+ break;
+ default:
+ switch (bits)
+ {
+ case 32:
+ tt = builtin_type (gdbarch)->builtin_float;
+ break;
+ case 64:
+ tt = builtin_type (gdbarch)->builtin_double;
+ break;
+ case 96: /* The x86-32 ABI specifies 96-bit long double. */
+ case 128:
+ tt = builtin_type (gdbarch)->builtin_long_double;
+ break;
+ }
+ break;
+ }
+
+ /* If the type we found doesn't match the size we were looking for, then
+ pretend we didn't find a type at all, the complex target type we
+ create will then be nameless. */
+ if (tt != nullptr && TYPE_LENGTH (tt) * TARGET_CHAR_BIT != bits)
+ tt = nullptr;
+
+ const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
+ return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
+}
+
/* Find a representation of a given base type and install
it in the TYPE field of the die. */
struct attribute *attr;
int encoding = 0, bits = 0;
const char *name;
+ gdbarch *arch;
attr = dwarf2_attr (die, DW_AT_encoding, cu);
- if (attr)
- {
- encoding = DW_UNSND (attr);
- }
+ if (attr != nullptr)
+ encoding = DW_UNSND (attr);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
- {
- bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
- }
+ if (attr != nullptr)
+ bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
name = dwarf2_name (die, cu);
if (!name)
+ complaint (_("DW_AT_name missing from DW_TAG_base_type"));
+
+ arch = get_objfile_arch (objfile);
+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
+ attr = dwarf2_attr (die, DW_AT_endianity, cu);
+ if (attr)
{
- complaint (&symfile_complaints,
- _("DW_AT_name missing from DW_TAG_base_type"));
+ int endianity = DW_UNSND (attr);
+
+ switch (endianity)
+ {
+ case DW_END_big:
+ byte_order = BFD_ENDIAN_BIG;
+ break;
+ case DW_END_little:
+ byte_order = BFD_ENDIAN_LITTLE;
+ break;
+ default:
+ complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+ break;
+ }
}
switch (encoding)
type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- type = dwarf2_init_float_type (objfile, bits / 2, NULL, name);
+ type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+ byte_order);
type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- type = dwarf2_init_float_type (objfile, bits, name, name);
+ type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
break;
case DW_ATE_signed:
- type = init_integer_type (objfile, bits, 0, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
break;
case DW_ATE_unsigned:
if (cu->language == language_fortran
&& startswith (name, "character("))
type = init_character_type (objfile, bits, 1, name);
else
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
break;
case DW_ATE_signed_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_fortran)
type = init_character_type (objfile, bits, 0, name);
else
- type = init_integer_type (objfile, bits, 0, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
break;
case DW_ATE_unsigned_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_rust)
type = init_character_type (objfile, bits, 1, name);
else
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
break;
case DW_ATE_UTF:
{
- gdbarch *arch = get_objfile_arch (objfile);
-
if (bits == 16)
type = builtin_type (arch)->builtin_char16;
else if (bits == 32)
type = builtin_type (arch)->builtin_char32;
else
{
- complaint (&symfile_complaints,
- _("unsupported DW_ATE_UTF bit size: '%d'"),
+ complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
bits);
- type = init_integer_type (objfile, bits, 1, name);
+ type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
}
return set_die_type (die, type, cu);
}
break;
default:
- complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
+ complaint (_("unsupported DW_AT_encoding: '%s'"),
dwarf_type_encoding_name (encoding));
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
break;
if (name && strcmp (name, "char") == 0)
TYPE_NOSIGN (type) = 1;
+ maybe_set_alignment (cu, die, type);
+
+ TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
+
return set_die_type (die, type, cu);
}
static int
attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
- struct dwarf2_cu *cu, struct dynamic_prop *prop)
+ struct dwarf2_cu *cu, struct dynamic_prop *prop,
+ struct type *default_type)
{
struct dwarf2_property_baton *baton;
struct obstack *obstack
= &cu->per_cu->dwarf2_per_objfile->objfile->objfile_obstack;
+ gdb_assert (default_type != NULL);
+
if (attr == NULL || prop == NULL)
return 0;
if (attr_form_is_block (attr))
{
baton = XOBNEW (obstack, struct dwarf2_property_baton);
- baton->referenced_type = NULL;
+ baton->property_type = default_type;
baton->locexpr.per_cu = cu->per_cu;
baton->locexpr.size = DW_BLOCK (attr)->size;
baton->locexpr.data = DW_BLOCK (attr)->data;
+ switch (attr->name)
+ {
+ case DW_AT_string_length:
+ baton->locexpr.is_reference = true;
+ break;
+ default:
+ baton->locexpr.is_reference = false;
+ break;
+ }
prop->data.baton = baton;
prop->kind = PROP_LOCEXPR;
gdb_assert (prop->data.baton != NULL);
if (attr_form_is_section_offset (target_attr))
{
baton = XOBNEW (obstack, struct dwarf2_property_baton);
- baton->referenced_type = die_type (target_die, target_cu);
+ baton->property_type = die_type (target_die, target_cu);
fill_in_loclist_baton (cu, &baton->loclist, target_attr);
prop->data.baton = baton;
prop->kind = PROP_LOCLIST;
else if (attr_form_is_block (target_attr))
{
baton = XOBNEW (obstack, struct dwarf2_property_baton);
- baton->referenced_type = die_type (target_die, target_cu);
+ baton->property_type = die_type (target_die, target_cu);
baton->locexpr.per_cu = cu->per_cu;
baton->locexpr.size = DW_BLOCK (target_attr)->size;
baton->locexpr.data = DW_BLOCK (target_attr)->data;
+ baton->locexpr.is_reference = true;
prop->data.baton = baton;
prop->kind = PROP_LOCEXPR;
gdb_assert (prop->data.baton != NULL);
return 0;
baton = XOBNEW (obstack, struct dwarf2_property_baton);
- baton->referenced_type = read_type_die (target_die->parent,
+ baton->property_type = read_type_die (target_die->parent,
target_cu);
baton->offset_info.offset = offset;
baton->offset_info.type = die_type (target_die, target_cu);
return 1;
}
+/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
+ UNSIGNED_P controls if the integer is unsigned or not. */
+
+static struct type *
+dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
+ int size_in_bytes, bool unsigned_p)
+{
+ struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+ struct type *int_type;
+
+ /* Helper macro to examine the various builtin types. */
+#define TRY_TYPE(F) \
+ int_type = (unsigned_p \
+ ? objfile_type (objfile)->builtin_unsigned_ ## F \
+ : objfile_type (objfile)->builtin_ ## F); \
+ if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
+ return int_type
+
+ TRY_TYPE (char);
+ TRY_TYPE (short);
+ TRY_TYPE (int);
+ TRY_TYPE (long);
+ TRY_TYPE (long_long);
+
+#undef TRY_TYPE
+
+ gdb_assert_not_reached ("unable to find suitable integer type");
+}
+
+/* Find an integer type the same size as the address size given in the
+ compilation unit header for PER_CU. UNSIGNED_P controls if the integer
+ is unsigned or not. */
+
+static struct type *
+dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
+ bool unsigned_p)
+{
+ int addr_size = dwarf2_per_cu_addr_size (per_cu);
+ return dwarf2_per_cu_int_type (per_cu, addr_size, unsigned_p);
+}
+
+/* Read the DW_AT_type attribute for a sub-range. If this attribute is not
+ present (which is valid) then compute the default type based on the
+ compilation units address size. */
+
+static struct type *
+read_subrange_index_type (struct die_info *die, struct dwarf2_cu *cu)
+{
+ struct type *index_type = die_type (die, cu);
+
+ /* Dwarf-2 specifications explicitly allows to create subrange types
+ without specifying a base type.
+ In that case, the base type must be set to the type of
+ the lower bound, upper bound or count, in that order, if any of these
+ three attributes references an object that has a type.
+ If no base type is found, the Dwarf-2 specifications say that
+ a signed integer type of size equal to the size of an address should
+ be used.
+ For the following C code: `extern char gdb_int [];'
+ GCC produces an empty range DIE.
+ FIXME: muller/2010-05-28: Possible references to object for low bound,
+ high bound or count are not yet handled by this code. */
+ if (TYPE_CODE (index_type) == TYPE_CODE_VOID)
+ index_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+
+ return index_type;
+}
+
/* Read the given DW_AT_subrange DIE. */
static struct type *
int low_default_is_valid;
int high_bound_is_count = 0;
const char *name;
- LONGEST negative_mask;
+ ULONGEST negative_mask;
+
+ orig_base_type = read_subrange_index_type (die, cu);
- orig_base_type = die_type (die, cu);
/* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
whereas the real type might be. So, we use ORIG_BASE_TYPE when
creating the range type, but we use the result of check_typedef
}
attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
- if (attr)
- attr_to_dynamic_prop (attr, die, cu, &low);
+ if (attr != nullptr)
+ attr_to_dynamic_prop (attr, die, cu, &low, base_type);
else if (!low_default_is_valid)
- complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
+ complaint (_("Missing DW_AT_lower_bound "
"- DIE at %s [in module %s]"),
sect_offset_str (die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
- attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
- if (!attr_to_dynamic_prop (attr, die, cu, &high))
+ struct attribute *attr_ub, *attr_count;
+ attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
+ if (!attr_to_dynamic_prop (attr, die, cu, &high, base_type))
{
- attr = dwarf2_attr (die, DW_AT_count, cu);
- if (attr_to_dynamic_prop (attr, die, cu, &high))
+ attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
+ if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
{
/* If bounds are constant do the final calculation here. */
if (low.kind == PROP_CONST && high.kind == PROP_CONST)
else
high_bound_is_count = 1;
}
- }
-
- /* Dwarf-2 specifications explicitly allows to create subrange types
- without specifying a base type.
- In that case, the base type must be set to the type of
- the lower bound, upper bound or count, in that order, if any of these
- three attributes references an object that has a type.
- If no base type is found, the Dwarf-2 specifications say that
- a signed integer type of size equal to the size of an address should
- be used.
- For the following C code: `extern char gdb_int [];'
- GCC produces an empty range DIE.
- FIXME: muller/2010-05-28: Possible references to object for low bound,
- high bound or count are not yet handled by this code. */
- if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
- {
- struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- int addr_size = gdbarch_addr_bit (gdbarch) /8;
- struct type *int_type = objfile_type (objfile)->builtin_int;
-
- /* Test "int", "long int", and "long long int" objfile types,
- and select the first one having a size above or equal to the
- architecture address size. */
- if (int_type && TYPE_LENGTH (int_type) >= addr_size)
- base_type = int_type;
else
{
- int_type = objfile_type (objfile)->builtin_long;
- if (int_type && TYPE_LENGTH (int_type) >= addr_size)
- base_type = int_type;
- else
- {
- int_type = objfile_type (objfile)->builtin_long_long;
- if (int_type && TYPE_LENGTH (int_type) >= addr_size)
- base_type = int_type;
- }
+ if (attr_ub != NULL)
+ complaint (_("Unresolved DW_AT_upper_bound "
+ "- DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ if (attr_count != NULL)
+ complaint (_("Unresolved DW_AT_count "
+ "- DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
}
}
+ LONGEST bias = 0;
+ struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
+ if (bias_attr != nullptr && attr_form_is_constant (bias_attr))
+ bias = dwarf2_get_attr_constant_value (bias_attr, 0);
+
/* Normally, the DWARF producers are expected to use a signed
constant form (Eg. DW_FORM_sdata) to express negative bounds.
But this is unfortunately not always the case, as witnessed
the bounds as signed, and thus sign-extend their values, when
the base type is signed. */
negative_mask =
- -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
+ -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
if (low.kind == PROP_CONST
&& !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
low.data.const_val |= negative_mask;
&& !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
high.data.const_val |= negative_mask;
- range_type = create_range_type (NULL, orig_base_type, &low, &high);
+ /* Check for bit and byte strides. */
+ struct dynamic_prop byte_stride_prop;
+ attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
+ if (attr_byte_stride != nullptr)
+ {
+ struct type *prop_type
+ = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+ attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
+ prop_type);
+ }
+
+ struct dynamic_prop bit_stride_prop;
+ attribute *attr_bit_stride = dwarf2_attr (die, DW_AT_bit_stride, cu);
+ if (attr_bit_stride != nullptr)
+ {
+ /* It only makes sense to have either a bit or byte stride. */
+ if (attr_byte_stride != nullptr)
+ {
+ complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
+ "- DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ attr_bit_stride = nullptr;
+ }
+ else
+ {
+ struct type *prop_type
+ = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+ attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
+ prop_type);
+ }
+ }
+
+ if (attr_byte_stride != nullptr
+ || attr_bit_stride != nullptr)
+ {
+ bool byte_stride_p = (attr_byte_stride != nullptr);
+ struct dynamic_prop *stride
+ = byte_stride_p ? &byte_stride_prop : &bit_stride_prop;
+
+ range_type
+ = create_range_type_with_stride (NULL, orig_base_type, &low,
+ &high, bias, stride, byte_stride_p);
+ }
+ else
+ range_type = create_range_type (NULL, orig_base_type, &low, &high, bias);
if (high_bound_is_count)
TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
TYPE_NAME (range_type) = name;
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
- if (attr)
+ if (attr != nullptr)
TYPE_LENGTH (range_type) = DW_UNSND (attr);
+ maybe_set_alignment (cu, die, range_type);
+
set_die_type (die, range_type, cu);
/* set_die_type should be already done. */
TYPE_NAME (type) = dwarf2_name (die, cu);
/* In Ada, an unspecified type is typically used when the description
- of the type is defered to a different unit. When encountering
+ of the type is deferred to a different unit. When encountering
such a type, we treat it as a stub, and try to resolve it later on,
when needed. */
if (cu->language == language_ada)
struct abbrev_info *cur_abbrev;
unsigned int abbrev_number, bytes_read, abbrev_name;
unsigned int abbrev_form;
- struct attr_abbrev *cur_attrs;
- unsigned int allocated_attrs;
+ std::vector<struct attr_abbrev> cur_attrs;
abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
abbrev_ptr += bytes_read;
- allocated_attrs = ATTR_ALLOC_CHUNK;
- cur_attrs = XNEWVEC (struct attr_abbrev, allocated_attrs);
-
/* Loop until we reach an abbrev number of 0. */
while (abbrev_number)
{
+ cur_attrs.clear ();
cur_abbrev = abbrev_table->alloc_abbrev ();
/* read in abbrev header */
if (abbrev_name == 0)
break;
- if (cur_abbrev->num_attrs == allocated_attrs)
- {
- allocated_attrs += ATTR_ALLOC_CHUNK;
- cur_attrs
- = XRESIZEVEC (struct attr_abbrev, cur_attrs, allocated_attrs);
- }
-
- cur_attrs[cur_abbrev->num_attrs].name
- = (enum dwarf_attribute) abbrev_name;
- cur_attrs[cur_abbrev->num_attrs].form
- = (enum dwarf_form) abbrev_form;
- cur_attrs[cur_abbrev->num_attrs].implicit_const = implicit_const;
+ cur_attrs.emplace_back ();
+ struct attr_abbrev &cur_attr = cur_attrs.back ();
+ cur_attr.name = (enum dwarf_attribute) abbrev_name;
+ cur_attr.form = (enum dwarf_form) abbrev_form;
+ cur_attr.implicit_const = implicit_const;
++cur_abbrev->num_attrs;
}
cur_abbrev->attrs =
XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev,
cur_abbrev->num_attrs);
- memcpy (cur_abbrev->attrs, cur_attrs,
+ memcpy (cur_abbrev->attrs, cur_attrs.data (),
cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
break;
}
- xfree (cur_attrs);
return abbrev_table;
}
|| pdi.tag == DW_TAG_subrange_type))
{
if (building_psymtab && pdi.name != NULL)
- add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
- VAR_DOMAIN, LOC_TYPEDEF,
- &objfile->static_psymbols,
+ add_psymbol_to_list (pdi.name, false,
+ VAR_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::STATIC,
0, cu->language, objfile);
info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
continue;
/* The exception for DW_TAG_typedef with has_children above is
a workaround of GCC PR debug/47510. In the case of this complaint
- type_name_no_tag_or_error will error on such types later.
+ type_name_or_error will error on such types later.
GDB skipped children of DW_TAG_typedef by the shortcut above and then
it could not find the child DIEs referenced later, this is checked
above. In correct DWARF DW_TAG_typedef should have no children. */
if (pdi.tag == DW_TAG_typedef && pdi.has_children)
- complaint (&symfile_complaints,
- _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
+ complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
"- DIE at %s [in module %s]"),
sect_offset_str (pdi.sect_off), objfile_name (objfile));
&& parent_die->has_specification == 0)
{
if (pdi.name == NULL)
- complaint (&symfile_complaints,
- _("malformed enumerator DIE ignored"));
+ complaint (_("malformed enumerator DIE ignored"));
else if (building_psymtab)
- add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
- VAR_DOMAIN, LOC_CONST,
+ add_psymbol_to_list (pdi.name, false,
+ VAR_DOMAIN, LOC_CONST, -1,
cu->language == language_cplus
- ? &objfile->global_psymbols
- : &objfile->static_psymbols,
+ ? psymbol_placement::GLOBAL
+ : psymbol_placement::STATIC,
0, cu->language, objfile);
info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
inside functions to find template arguments (if the name of the
function does not already contain the template arguments).
- For Ada, we need to scan the children of subprograms and lexical
- blocks as well because Ada allows the definition of nested
- entities that could be interesting for the debugger, such as
- nested subprograms for instance. */
+ For Ada and Fortran, we need to scan the children of subprograms
+ and lexical blocks as well because these languages allow the
+ definition of nested entities that could be interesting for the
+ debugger, such as nested subprograms for instance. */
if (last_die->has_children
&& (load_all
|| last_die->tag == DW_TAG_namespace
|| last_die->tag == DW_TAG_interface_type
|| last_die->tag == DW_TAG_structure_type
|| last_die->tag == DW_TAG_union_type))
- || (cu->language == language_ada
+ || ((cu->language == language_ada
+ || cu->language == language_fortran)
&& (last_die->tag == DW_TAG_subprogram
|| last_die->tag == DW_TAG_lexical_block))))
{
/* Note that both forms of linkage name might appear. We
assume they will be the same, and we only store the last
one we see. */
- if (cu->language == language_ada)
- name = DW_STRING (&attr);
linkage_name = DW_STRING (&attr);
break;
case DW_AT_low_pc:
/* Ignore absolute siblings, they might point outside of
the current compile unit. */
if (attr.form == DW_FORM_ref_addr)
- complaint (&symfile_complaints,
- _("ignoring absolute DW_AT_sibling"));
+ complaint (_("ignoring absolute DW_AT_sibling"));
else
{
const gdb_byte *buffer = reader->buffer;
const gdb_byte *sibling_ptr = buffer + to_underlying (off);
if (sibling_ptr < info_ptr)
- complaint (&symfile_complaints,
- _("DW_AT_sibling points backwards"));
+ complaint (_("DW_AT_sibling points backwards"));
else if (sibling_ptr > reader->buffer_end)
dwarf2_section_buffer_overflow_complaint (reader->die_section);
else
main_subprogram = DW_UNSND (&attr);
break;
+ case DW_AT_ranges:
+ {
+ /* It would be nice to reuse dwarf2_get_pc_bounds here,
+ but that requires a full DIE, so instead we just
+ reimplement it. */
+ int need_ranges_base = tag != DW_TAG_compile_unit;
+ unsigned int ranges_offset = (DW_UNSND (&attr)
+ + (need_ranges_base
+ ? cu->ranges_base
+ : 0));
+
+ /* Value of the DW_AT_ranges attribute is the offset in the
+ .debug_ranges section. */
+ if (dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, cu,
+ nullptr))
+ has_pc_info = 1;
+ }
+ break;
+
default:
break;
}
}
+ /* For Ada, if both the name and the linkage name appear, we prefer
+ the latter. This lets "catch exception" work better, regardless
+ of the order in which the name and linkage name were emitted.
+ Really, though, this is just a workaround for the fact that gdb
+ doesn't store both the name and the linkage name. */
+ if (cu->language == language_ada && linkage_name != nullptr)
+ name = linkage_name;
+
if (high_pc_relative)
highpc += lowpc;
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- complaint (&symfile_complaints,
- _("DW_AT_low_pc %s is zero "
+ complaint (_("DW_AT_low_pc %s is zero "
"for DIE at %s [in module %s]"),
paddress (gdbarch, lowpc),
sect_offset_str (sect_off),
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- complaint (&symfile_complaints,
- _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
+ complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
"for DIE at %s [in module %s]"),
paddress (gdbarch, lowpc),
paddress (gdbarch, highpc),
outside their CU (they do however referencing other types via
DW_FORM_ref_sig8). */
-static struct partial_die_info *
+static const struct cu_partial_die_info
find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
{
struct dwarf2_per_objfile *dwarf2_per_objfile
{
pd = cu->find_partial_die (sect_off);
if (pd != NULL)
- return pd;
+ return { cu, pd };
/* We missed recording what we needed.
Load all dies and try again. */
per_cu = cu->per_cu;
_("could not find partial DIE %s "
"in cache [from module %s]\n"),
sect_offset_str (sect_off), bfd_get_filename (objfile->obfd));
- return pd;
+ return { per_cu->cu, pd };
}
/* See if we can figure out if the class lives in a namespace. We do
real_pdi = struct_pdi;
while (real_pdi->has_specification)
- real_pdi = find_partial_die (real_pdi->spec_offset,
- real_pdi->spec_is_dwz, cu);
+ {
+ auto res = find_partial_die (real_pdi->spec_offset,
+ real_pdi->spec_is_dwz, cu);
+ real_pdi = res.pdi;
+ cu = res.cu;
+ }
if (real_pdi->die_parent != NULL)
return;
if (child_pdi->tag == DW_TAG_subprogram
&& child_pdi->linkage_name != NULL)
{
- char *actual_class_name
- = language_class_name_from_physname (cu->language_defn,
- child_pdi->linkage_name);
+ gdb::unique_xmalloc_ptr<char> actual_class_name
+ (language_class_name_from_physname (cu->language_defn,
+ child_pdi->linkage_name));
if (actual_class_name != NULL)
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
struct_pdi->name
- = ((const char *)
- obstack_copy0 (&objfile->per_bfd->storage_obstack,
- actual_class_name,
- strlen (actual_class_name)));
- xfree (actual_class_name);
+ = obstack_strdup (&objfile->per_bfd->storage_obstack,
+ actual_class_name.get ());
}
break;
}
{
struct partial_die_info *spec_die;
- spec_die = find_partial_die (spec_offset, spec_is_dwz, cu);
+ auto res = find_partial_die (spec_offset, spec_is_dwz, cu);
+ spec_die = res.pdi;
+ cu = res.cu;
spec_die->fixup (cu);
children, see if we can determine the namespace from their linkage
name. */
if (cu->language == language_cplus
- && !VEC_empty (dwarf2_section_info_def,
- cu->per_cu->dwarf2_per_objfile->types)
+ && !cu->per_cu->dwarf2_per_objfile->types.empty ()
&& die_parent == NULL
&& has_children
&& (tag == DW_TAG_class_type
|| tag == DW_TAG_union_type)
&& linkage_name != NULL)
{
- char *demangled;
-
- demangled = gdb_demangle (linkage_name, DMGL_TYPES);
- if (demangled)
+ gdb::unique_xmalloc_ptr<char> demangled
+ (gdb_demangle (linkage_name, DMGL_TYPES));
+ if (demangled != nullptr)
{
const char *base;
/* Strip any leading namespaces/classes, keep only the base name.
DW_AT_name for named DIEs does not contain the prefixes. */
- base = strrchr (demangled, ':');
- if (base && base > demangled && base[-1] == ':')
+ base = strrchr (demangled.get (), ':');
+ if (base && base > demangled.get () && base[-1] == ':')
base++;
else
- base = demangled;
+ base = demangled.get ();
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
- name
- = ((const char *)
- obstack_copy0 (&objfile->per_bfd->storage_obstack,
- base, strlen (base)));
- xfree (demangled);
+ name = obstack_strdup (&objfile->per_bfd->storage_obstack, base);
}
}
case DW_FORM_implicit_const:
DW_SND (attr) = implicit_const;
break;
+ case DW_FORM_addrx:
case DW_FORM_GNU_addr_index:
if (reader->dwo_file == NULL)
{
DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
info_ptr += bytes_read;
break;
+ case DW_FORM_strx:
+ case DW_FORM_strx1:
+ case DW_FORM_strx2:
+ case DW_FORM_strx3:
+ case DW_FORM_strx4:
case DW_FORM_GNU_str_index:
if (reader->dwo_file == NULL)
{
bfd_get_filename (abfd));
}
{
- ULONGEST str_index =
- read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
-
+ ULONGEST str_index;
+ if (form == DW_FORM_strx1)
+ {
+ str_index = read_1_byte (abfd, info_ptr);
+ info_ptr += 1;
+ }
+ else if (form == DW_FORM_strx2)
+ {
+ str_index = read_2_bytes (abfd, info_ptr);
+ info_ptr += 2;
+ }
+ else if (form == DW_FORM_strx3)
+ {
+ str_index = read_3_bytes (abfd, info_ptr);
+ info_ptr += 3;
+ }
+ else if (form == DW_FORM_strx4)
+ {
+ str_index = read_4_bytes (abfd, info_ptr);
+ info_ptr += 4;
+ }
+ else
+ {
+ str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+ info_ptr += bytes_read;
+ }
DW_STRING (attr) = read_str_index (reader, str_index);
DW_STRING_IS_CANONICAL (attr) = 0;
- info_ptr += bytes_read;
}
break;
default:
&& DW_UNSND (attr) >= 0xffffffff)
{
complaint
- (&symfile_complaints,
- _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
+ (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
hex_string (DW_UNSND (attr)));
DW_UNSND (attr) = 0;
}
return bfd_get_signed_16 (abfd, buf);
}
+static unsigned int
+read_3_bytes (bfd *abfd, const gdb_byte *buf)
+{
+ unsigned int result = 0;
+ for (int i = 0; i < 3; ++i)
+ {
+ unsigned char byte = bfd_get_8 (abfd, buf);
+ buf++;
+ result |= ((unsigned int) byte << (i * 8));
+ }
+ return result;
+}
+
static unsigned int
read_4_bytes (bfd *abfd, const gdb_byte *buf)
{
|| cu_header->initial_length_size == 12);
if (cu_header->initial_length_size != *bytes_read)
- complaint (&symfile_complaints,
- _("intermixed 32-bit and 64-bit DWARF sections"));
+ complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
*offset_size = (*bytes_read == 4) ? 4 : 8;
return length;
if (dwz->str.buffer == NULL)
error (_("DW_FORM_GNU_strp_alt used without .debug_str "
"section [in module %s]"),
- bfd_get_filename (dwz->dwz_bfd));
+ bfd_get_filename (dwz->dwz_bfd.get ()));
if (str_offset >= dwz->str.size)
error (_("DW_FORM_GNU_strp_alt pointing outside of "
".debug_str section [in module %s]"),
- bfd_get_filename (dwz->dwz_bfd));
+ bfd_get_filename (dwz->dwz_bfd.get ()));
gdb_assert (HOST_CHAR_BIT == 8);
if (dwz->str.buffer[str_offset] == '\0')
return NULL;
read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
unsigned int *bytes_read_ptr)
{
- LONGEST result;
+ ULONGEST result;
int shift, num_read;
unsigned char byte;
byte = bfd_get_8 (abfd, buf);
buf++;
num_read++;
- result |= ((LONGEST) (byte & 127) << shift);
+ result |= ((ULONGEST) (byte & 127) << shift);
shift += 7;
if ((byte & 128) == 0)
{
}
}
if ((shift < 8 * sizeof (result)) && (byte & 0x40))
- result |= -(((LONGEST) 1) << shift);
+ result |= -(((ULONGEST) 1) << shift);
*bytes_read_ptr = num_read;
return result;
}
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;
/* Note: We can't use init_cutu_and_read_dies_simple here,
we need addr_base. */
- init_cutu_and_read_dies (per_cu, NULL, 0, 0,
+ init_cutu_and_read_dies (per_cu, NULL, 0, 0, false,
dwarf2_read_addr_index_reader, &aidata);
addr_base = aidata.addr_base;
addr_size = aidata.addr_size;
addr_size);
}
-/* Given a DW_FORM_GNU_str_index, fetch the string.
+/* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
This is only used by the Fission support. */
static const char *
&reader->dwo_file->sections.str_offsets;
const gdb_byte *info_ptr;
ULONGEST str_offset;
- static const char form_name[] = "DW_FORM_GNU_str_index";
+ static const char form_name[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
dwarf2_read_section (objfile, str_section);
dwarf2_read_section (objfile, str_offsets_section);
{
if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
|| attr->form == DW_FORM_string
+ || attr->form == DW_FORM_strx
+ || attr->form == DW_FORM_strx1
+ || attr->form == DW_FORM_strx2
+ || attr->form == DW_FORM_strx3
+ || attr->form == DW_FORM_strx4
|| attr->form == DW_FORM_GNU_str_index
|| attr->form == DW_FORM_GNU_strp_alt)
str = DW_STRING (attr);
else
- complaint (&symfile_complaints,
- _("string type expected for attribute %s for "
+ complaint (_("string type expected for attribute %s for "
"DIE at %s in module %s"),
dwarf_attr_name (name), sect_offset_str (die->sect_off),
objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
return str;
}
+/* Return the dwo name or NULL if not present. If present, it is in either
+ DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
+static const char *
+dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu)
+{
+ const char *dwo_name = dwarf2_string_attr (die, DW_AT_GNU_dwo_name, cu);
+ if (dwo_name == nullptr)
+ dwo_name = dwarf2_string_attr (die, DW_AT_dwo_name, cu);
+ return dwo_name;
+}
+
/* Return non-zero iff the attribute NAME is defined for the given DIE,
and holds a non-zero value. This function should only be used for
DW_FORM_flag or DW_FORM_flag_present attributes. */
line_header::add_include_dir (const char *include_dir)
{
if (dwarf_line_debug >= 2)
- fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
- include_dirs.size () + 1, include_dir);
-
- include_dirs.push_back (include_dir);
+ {
+ size_t new_size;
+ if (version >= 5)
+ new_size = m_include_dirs.size ();
+ else
+ new_size = m_include_dirs.size () + 1;
+ fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
+ new_size, include_dir);
+ }
+ m_include_dirs.push_back (include_dir);
}
void
unsigned int length)
{
if (dwarf_line_debug >= 2)
- fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n",
- (unsigned) file_names.size () + 1, name);
-
- file_names.emplace_back (name, d_index, mod_time, length);
-}
+ {
+ size_t new_size;
+ if (version >= 5)
+ new_size = file_names_size ();
+ else
+ new_size = file_names_size () + 1;
+ fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
+ new_size, name);
+ }
+ m_file_names.emplace_back (name, d_index, mod_time, length);
+}
/* A convenience function to find the proper .debug_line section for a CU. */
buf += 8;
break;
+ case DW_FORM_data16:
+ /* This is used for MD5, but file_entry does not record MD5s. */
+ buf += 16;
+ break;
+
case DW_FORM_udata:
uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read));
buf += bytes_read;
case DW_LNCT_MD5:
break;
default:
- complaint (&symfile_complaints,
- _("Unknown format content type %s"),
+ complaint (_("Unknown format content type %s"),
pulongest (content_type));
}
}
if (section->buffer == NULL)
{
if (cu->dwo_unit && cu->per_cu->is_debug_types)
- complaint (&symfile_complaints, _("missing .debug_line.dwo section"));
+ complaint (_("missing .debug_line.dwo section"));
else
- complaint (&symfile_complaints, _("missing .debug_line section"));
+ complaint (_("missing .debug_line section"));
return 0;
}
read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
&bytes_read, &offset_size);
line_ptr += bytes_read;
+
+ const gdb_byte *start_here = line_ptr;
+
if (line_ptr + lh->total_length > (section->buffer + section->size))
{
dwarf2_statement_list_fits_in_line_number_section_complaint ();
return 0;
}
- lh->statement_program_end = line_ptr + lh->total_length;
+ lh->statement_program_end = start_here + lh->total_length;
lh->version = read_2_bytes (abfd, line_ptr);
line_ptr += 2;
if (lh->version > 5)
{
/* This is a version we don't understand. The format could have
changed in ways we don't handle properly so just punt. */
- complaint (&symfile_complaints,
- _("unsupported version in .debug_line section"));
+ complaint (_("unsupported version in .debug_line section"));
return NULL;
}
if (lh->version >= 5)
line_ptr += 1;
if (segment_selector_size != 0)
{
- complaint (&symfile_complaints,
- _("unsupported segment selector size %u "
+ complaint (_("unsupported segment selector size %u "
"in .debug_line section"),
segment_selector_size);
return NULL;
}
lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
line_ptr += offset_size;
+ lh->statement_program_start = line_ptr + lh->header_length;
lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
line_ptr += 1;
if (lh->version >= 4)
if (lh->maximum_ops_per_instruction == 0)
{
lh->maximum_ops_per_instruction = 1;
- complaint (&symfile_complaints,
- _("invalid maximum_ops_per_instruction "
+ complaint (_("invalid maximum_ops_per_instruction "
"in `.debug_line' section"));
}
/* Read directory table. */
read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
&cu->header,
- [] (struct line_header *lh, const char *name,
+ [] (struct line_header *header, const char *name,
dir_index d_index, unsigned int mod_time,
unsigned int length)
{
- lh->add_include_dir (name);
+ header->add_include_dir (name);
});
/* Read file name table. */
read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
&cu->header,
- [] (struct line_header *lh, const char *name,
+ [] (struct line_header *header, const char *name,
dir_index d_index, unsigned int mod_time,
unsigned int length)
{
- lh->add_file_name (name, d_index, mod_time, length);
+ header->add_file_name (name, d_index, mod_time, length);
});
}
else
}
line_ptr += bytes_read;
}
- lh->statement_program_start = line_ptr;
if (line_ptr > (section->buffer + section->size))
- complaint (&symfile_complaints,
- _("line number info header doesn't "
+ complaint (_("line number info header doesn't "
"fit in `.debug_line' section"));
return lh;
}
/* Subroutine of dwarf_decode_lines to simplify it.
- Return the file name of the psymtab for included file FILE_INDEX
- in line header LH of PST.
+ Return the file name of the psymtab for the given file_entry.
COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
If space for the result is malloc'd, *NAME_HOLDER will be set.
Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
static const char *
-psymtab_include_file_name (const struct line_header *lh, int file_index,
+psymtab_include_file_name (const struct line_header *lh, const file_entry &fe,
const struct partial_symtab *pst,
const char *comp_dir,
gdb::unique_xmalloc_ptr<char> *name_holder)
{
- const file_entry &fe = lh->file_names[file_index];
const char *include_name = fe.name;
const char *include_name_to_compare = include_name;
const char *pst_filename;
public:
/* Initialize a machine state for the start of a line number
program. */
- lnp_state_machine (gdbarch *arch, line_header *lh, bool record_lines_p);
+ lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, line_header *lh,
+ bool record_lines_p);
file_entry *current_file ()
{
we're processing the end of a sequence. */
void record_line (bool end_sequence);
- /* Check address and if invalid nop-out the rest of the lines in this
- sequence. */
+ /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
+ nop-out rest of the lines in this sequence. */
void check_line_address (struct dwarf2_cu *cu,
const gdb_byte *line_ptr,
- CORE_ADDR lowpc, CORE_ADDR address);
+ CORE_ADDR unrelocated_lowpc, CORE_ADDR address);
void handle_set_discriminator (unsigned int discriminator)
{
/* Handle DW_LNE_end_sequence. */
void handle_end_sequence ()
{
- m_record_line_callback = ::record_line;
+ m_currently_recording_lines = true;
}
private:
m_line_has_non_zero_discriminator = m_discriminator != 0;
}
+ struct dwarf2_cu *m_cu;
+
gdbarch *m_gdbarch;
/* True if we're recording lines.
and initialized according to the DWARF spec. */
unsigned char m_op_index = 0;
- /* The line table index (1-based) of the current file. */
- file_name_index m_file = (file_name_index) 1;
+ /* The line table index of the current file. */
+ file_name_index m_file = 1;
unsigned int m_line = 1;
/* These are initialized in the constructor. */
/* The last file a line number was recorded for. */
struct subfile *m_last_subfile = NULL;
- /* The function to call to record a line. */
- record_line_ftype *m_record_line_callback = NULL;
+ /* When true, record the lines we decode. */
+ bool m_currently_recording_lines = false;
/* The last line number that was recorded, used to coalesce
consecutive entries for the same line. This can happen, for
{
const char *dir = fe->include_dir (m_line_header);
- m_last_subfile = current_subfile;
+ m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
m_line_has_non_zero_discriminator = m_discriminator != 0;
- dwarf2_start_subfile (fe->name, dir);
+ dwarf2_start_subfile (m_cu, fe->name, dir);
}
}
% m_line_header->maximum_ops_per_instruction);
}
-/* Ignore this record_line request. */
-
-static void
-noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
-{
- return;
-}
-
/* Return non-zero if we should add LINE to the line number table.
LINE is the line to add, LAST_LINE is the last line that was added,
LAST_SUBFILE is the subfile for LAST_LINE.
within one sequence, thus this coalescing is ok. */
static int
-dwarf_record_line_p (unsigned int line, unsigned int last_line,
+dwarf_record_line_p (struct dwarf2_cu *cu,
+ unsigned int line, unsigned int last_line,
int line_has_non_zero_discriminator,
struct subfile *last_subfile)
{
- if (current_subfile != last_subfile)
+ if (cu->get_builder ()->get_current_subfile () != last_subfile)
return 1;
if (line != last_line)
return 1;
return 0;
}
-/* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
- in the line table of subfile SUBFILE. */
+/* Use the CU's builder to record line number LINE beginning at
+ address ADDRESS in the line table of subfile SUBFILE. */
static void
dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
unsigned int line, CORE_ADDR address,
- record_line_ftype p_record_line)
+ struct dwarf2_cu *cu)
{
CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
paddress (gdbarch, address));
}
- (*p_record_line) (subfile, line, addr);
+ if (cu != nullptr)
+ cu->get_builder ()->record_line (subfile, line, addr);
}
/* Subroutine of dwarf_decode_lines_1 to simplify it.
static void
dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
- CORE_ADDR address, record_line_ftype p_record_line)
+ CORE_ADDR address, struct dwarf2_cu *cu)
{
if (subfile == NULL)
return;
paddress (gdbarch, address));
}
- dwarf_record_line_1 (gdbarch, subfile, 0, address, p_record_line);
+ dwarf_record_line_1 (gdbarch, subfile, 0, address, cu);
}
void
fprintf_unfiltered (gdb_stdlog,
"Processing actual line %u: file %u,"
" address %s, is_stmt %u, discrim %u\n",
- m_line, to_underlying (m_file),
+ m_line, m_file,
paddress (m_gdbarch, m_address),
m_is_stmt, m_discriminator);
}
else if (m_op_index == 0 || end_sequence)
{
fe->included_p = 1;
- if (m_record_lines_p && m_is_stmt)
+ if (m_record_lines_p && (producer_is_codewarrior (m_cu) || m_is_stmt))
{
- if (m_last_subfile != current_subfile || end_sequence)
+ if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
+ || end_sequence)
{
- dwarf_finish_line (m_gdbarch, m_last_subfile,
- m_address, m_record_line_callback);
+ dwarf_finish_line (m_gdbarch, m_last_subfile, m_address,
+ m_currently_recording_lines ? m_cu : nullptr);
}
if (!end_sequence)
{
- if (dwarf_record_line_p (m_line, m_last_line,
+ if (dwarf_record_line_p (m_cu, m_line, m_last_line,
m_line_has_non_zero_discriminator,
m_last_subfile))
{
- dwarf_record_line_1 (m_gdbarch, current_subfile,
+ buildsym_compunit *builder = m_cu->get_builder ();
+ dwarf_record_line_1 (m_gdbarch,
+ builder->get_current_subfile (),
m_line, m_address,
- m_record_line_callback);
+ m_currently_recording_lines ? m_cu : nullptr);
}
- m_last_subfile = current_subfile;
+ m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
m_last_line = m_line;
}
}
}
}
-lnp_state_machine::lnp_state_machine (gdbarch *arch, line_header *lh,
- bool record_lines_p)
+lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
+ line_header *lh, bool record_lines_p)
{
+ m_cu = cu;
m_gdbarch = arch;
m_record_lines_p = record_lines_p;
m_line_header = lh;
- m_record_line_callback = ::record_line;
+ m_currently_recording_lines = true;
/* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
was a line entry for it so that the backend has a chance to adjust it
void
lnp_state_machine::check_line_address (struct dwarf2_cu *cu,
const gdb_byte *line_ptr,
- CORE_ADDR lowpc, CORE_ADDR address)
+ CORE_ADDR unrelocated_lowpc, CORE_ADDR address)
{
- /* If address < lowpc then it's not a usable value, it's outside the
- pc range of the CU. However, we restrict the test to only address
- values of zero to preserve GDB's previous behaviour which is to
- handle the specific case of a function being GC'd by the linker. */
+ /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
+ the pc range of the CU. However, we restrict the test to only ADDRESS
+ values of zero to preserve GDB's previous behaviour which is to handle
+ the specific case of a function being GC'd by the linker. */
- if (address == 0 && address < lowpc)
+ if (address == 0 && address < unrelocated_lowpc)
{
/* This line table is for a function which has been
GCd by the linker. Ignore it. PR gdb/12528 */
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
long line_offset = line_ptr - get_debug_line_section (cu)->buffer;
- complaint (&symfile_complaints,
- _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
+ complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
line_offset, objfile_name (objfile));
- m_record_line_callback = noop_record_line;
- /* Note: record_line_callback is left as noop_record_line until
- we see DW_LNE_end_sequence. */
+ m_currently_recording_lines = false;
+ /* Note: m_currently_recording_lines is left as false until we see
+ DW_LNE_end_sequence. */
}
}
the line number program). */
bool record_lines_p = !decode_for_pst_p;
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
line_ptr = lh->statement_program_start;
line_end = lh->statement_program_end;
{
/* The DWARF line number program state machine. Reset the state
machine at the start of each sequence. */
- lnp_state_machine state_machine (gdbarch, lh, record_lines_p);
+ lnp_state_machine state_machine (cu, gdbarch, lh, record_lines_p);
bool end_sequence = false;
if (record_lines_p)
const file_entry *fe = state_machine.current_file ();
if (fe != NULL)
- dwarf2_start_subfile (fe->name, fe->include_dir (lh));
+ dwarf2_start_subfile (cu, fe->name, fe->include_dir (lh));
}
/* Decode the table. */
line_ptr += bytes_read;
state_machine.check_line_address (cu, line_ptr,
- lowpc, address);
+ lowpc - baseaddr, address);
state_machine.handle_set_address (baseaddr, address);
}
break;
}
break;
default:
- complaint (&symfile_complaints,
- _("mangled .debug_line section"));
+ complaint (_("mangled .debug_line section"));
return;
}
/* Make sure that we parsed the extended op correctly. If e.g.
we may have read the wrong number of bytes. */
if (line_ptr != extended_end)
{
- complaint (&symfile_complaints,
- _("mangled .debug_line section"));
+ complaint (_("mangled .debug_line section"));
return;
}
break;
if (decode_for_pst_p)
{
- int file_index;
-
/* Now that we're done scanning the Line Header Program, we can
create the psymtab of each included file. */
- for (file_index = 0; file_index < lh->file_names.size (); file_index++)
- if (lh->file_names[file_index].included_p == 1)
+ for (auto &file_entry : lh->file_names ())
+ if (file_entry.included_p == 1)
{
gdb::unique_xmalloc_ptr<char> name_holder;
const char *include_name =
- psymtab_include_file_name (lh, file_index, pst, comp_dir,
- &name_holder);
+ psymtab_include_file_name (lh, file_entry, pst,
+ comp_dir, &name_holder);
if (include_name != NULL)
dwarf2_create_include_psymtab (include_name, pst, objfile);
}
/* Make sure a symtab is created for every file, even files
which contain only variables (i.e. no code with associated
line numbers). */
- struct compunit_symtab *cust = buildsym_compunit_symtab ();
- int i;
+ buildsym_compunit *builder = cu->get_builder ();
+ struct compunit_symtab *cust = builder->get_compunit_symtab ();
- for (i = 0; i < lh->file_names.size (); i++)
+ for (auto &fe : lh->file_names ())
{
- file_entry &fe = lh->file_names[i];
-
- dwarf2_start_subfile (fe.name, fe.include_dir (lh));
-
- if (current_subfile->symtab == NULL)
+ dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh));
+ if (builder->get_current_subfile ()->symtab == NULL)
{
- current_subfile->symtab
- = allocate_symtab (cust, current_subfile->name);
+ builder->get_current_subfile ()->symtab
+ = allocate_symtab (cust,
+ builder->get_current_subfile ()->name);
}
- fe.symtab = current_subfile->symtab;
+ fe.symtab = builder->get_current_subfile ()->symtab;
}
}
}
subfile's name. */
static void
-dwarf2_start_subfile (const char *filename, const char *dirname)
+dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename,
+ const char *dirname)
{
- char *copy = NULL;
+ gdb::unique_xmalloc_ptr<char> copy;
/* In order not to lose the line information directory,
we concatenate it to the filename when it makes sense.
if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
{
- copy = concat (dirname, SLASH_STRING, filename, (char *)NULL);
- filename = copy;
+ copy.reset (concat (dirname, SLASH_STRING, filename, (char *) NULL));
+ filename = copy.get ();
}
- start_subfile (filename);
-
- if (copy != NULL)
- xfree (copy);
+ cu->get_builder ()->start_subfile (filename);
}
-/* Start a symtab for DWARF.
- NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
+/* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
+ buildsym_compunit constructor. */
-static struct compunit_symtab *
-dwarf2_start_symtab (struct dwarf2_cu *cu,
- const char *name, const char *comp_dir, CORE_ADDR low_pc)
+struct compunit_symtab *
+dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
+ CORE_ADDR low_pc)
{
- struct compunit_symtab *cust
- = start_symtab (cu->per_cu->dwarf2_per_objfile->objfile, name, comp_dir,
- low_pc, cu->language);
+ gdb_assert (m_builder == nullptr);
+
+ m_builder.reset (new struct buildsym_compunit
+ (per_cu->dwarf2_per_objfile->objfile,
+ name, comp_dir, language, low_pc));
- record_debugformat ("DWARF 2");
- record_producer (cu->producer);
+ list_in_scope = get_builder ()->get_file_symbols ();
- /* We assume that we're processing GCC output. */
- processing_gcc_compilation = 2;
+ get_builder ()->record_debugformat ("DWARF 2");
+ get_builder ()->record_producer (producer);
- cu->processing_has_namespace_info = 0;
+ processing_has_namespace_info = false;
- return cust;
+ return get_builder ()->get_compunit_symtab ();
}
static void
/* Handle one degenerate form of location expression specially, to
preserve GDB's previous behavior when section offsets are
- specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
- then mark this symbol as LOC_STATIC. */
+ specified. If this is just a DW_OP_addr, DW_OP_addrx, or
+ DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
if (attr_form_is_block (attr)
&& ((DW_BLOCK (attr)->data[0] == DW_OP_addr
&& DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
- || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
+ || ((DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
+ || DW_BLOCK (attr)->data[0] == DW_OP_addrx)
&& (DW_BLOCK (attr)->size
== 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
{
unsigned int dummy;
if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
- SYMBOL_VALUE_ADDRESS (sym) =
- read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
+ SET_SYMBOL_VALUE_ADDRESS (sym,
+ read_address (objfile->obfd,
+ DW_BLOCK (attr)->data + 1,
+ cu, &dummy));
else
- SYMBOL_VALUE_ADDRESS (sym) =
- read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy);
+ SET_SYMBOL_VALUE_ADDRESS
+ (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
+ &dummy));
SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
fixup_symbol_section (sym, objfile);
- SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
- SYMBOL_SECTION (sym));
+ SET_SYMBOL_VALUE_ADDRESS
+ (sym,
+ SYMBOL_VALUE_ADDRESS (sym)
+ + objfile->section_offsets[SYMBOL_SECTION (sym)]);
return;
}
dwarf2_symbol_mark_computed (attr, sym, cu, 0);
if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
- cu->has_loclist = 1;
+ cu->has_loclist = true;
}
/* Given a pointer to a DWARF information entry, figure out if we need
int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
name = dwarf2_name (die, cu);
if (name)
OBJSTAT (objfile, n_syms++);
/* Cache this symbol's name and the name's demangled form (if any). */
- SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
+ sym->set_language (cu->language, &objfile->objfile_obstack);
linkagename = dwarf2_physname (name, die, cu);
- SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
+ sym->compute_and_set_names (linkagename, false, objfile->per_bfd);
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
- symbol_set_demangled_name (&(sym->ginfo),
+ && symbol_get_demangled_name (sym) == NULL)
+ symbol_set_demangled_name (sym,
dwarf2_full_name (name, die, cu),
NULL);
attr = dwarf2_attr (die,
inlined_func ? DW_AT_call_line : DW_AT_decl_line,
cu);
- if (attr)
+ if (attr != nullptr)
{
SYMBOL_LINE (sym) = DW_UNSND (attr);
}
attr = dwarf2_attr (die,
inlined_func ? DW_AT_call_file : DW_AT_decl_file,
cu);
- if (attr)
+ if (attr != nullptr)
{
file_name_index file_index = (file_name_index) DW_UNSND (attr);
struct file_entry *fe;
fe = NULL;
if (fe == NULL)
- complaint (&symfile_complaints,
- _("file index out of range"));
+ complaint (_("file index out of range"));
else
symbol_set_symtab (sym, fe->symtab);
}
{
case DW_TAG_label:
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
- if (attr)
+ if (attr != nullptr)
{
CORE_ADDR addr;
addr = attr_value_as_address (attr);
addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
- SYMBOL_VALUE_ADDRESS (sym) = addr;
+ SET_SYMBOL_VALUE_ADDRESS (sym, addr);
}
SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
attr2 = dwarf2_attr (die, DW_AT_external, cu);
if ((attr2 && (DW_UNSND (attr2) != 0))
- || cu->language == language_ada)
+ || cu->language == language_ada
+ || cu->language == language_fortran)
{
/* Subprograms marked external are stored as a global symbol.
- Ada subprograms, whether marked external or not, are always
- stored as a global symbol, because we want to be able to
- access them globally. For instance, we want to be able
- to break on a nested subprogram without having to
- specify the context. */
- list_to_add = &global_symbols;
+ Ada and Fortran subprograms, whether marked external or
+ not, are always stored as a global symbol, because we want
+ to be able to access them globally. For instance, we want
+ to be able to break on a nested subprogram without having
+ to specify the context. */
+ list_to_add = cu->get_builder ()->get_global_symbols ();
}
else
{
gdb_assert (die_is_declaration (die, cu));
gdb_assert (attr);
}
- if (attr)
+ if (attr != nullptr)
{
dwarf2_const_value (attr, sym, cu);
attr2 = dwarf2_attr (die, DW_AT_external, cu);
if (!suppress_add)
{
if (attr2 && (DW_UNSND (attr2) != 0))
- list_to_add = &global_symbols;
+ list_to_add = cu->get_builder ()->get_global_symbols ();
else
list_to_add = cu->list_in_scope;
}
break;
}
attr = dwarf2_attr (die, DW_AT_location, cu);
- if (attr)
+ if (attr != nullptr)
{
var_decode_location (attr, sym, cu);
attr2 = dwarf2_attr (die, DW_AT_external, cu);
}
else if (attr2 && (DW_UNSND (attr2) != 0))
{
- /* Workaround gfortran PR debug/40040 - it uses
- DW_AT_location for variables in -fPIC libraries which may
- get overriden by other libraries/executable and get
- a different address. Resolve it by the minimal symbol
- which may come from inferior's executable using copy
- relocation. Make this workaround only for gfortran as for
- other compilers GDB cannot guess the minimal symbol
- Fortran mangling kind. */
- if (cu->language == language_fortran && die->parent
- && die->parent->tag == DW_TAG_module
- && cu->producer
- && startswith (cu->producer, "GNU Fortran"))
- SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
+ if (SYMBOL_CLASS (sym) == LOC_STATIC
+ && (objfile->flags & OBJF_MAINLINE) == 0
+ && dwarf2_per_objfile->can_copy)
+ {
+ /* A global static variable might be subject to
+ copy relocation. We first check for a local
+ minsym, though, because maybe the symbol was
+ marked hidden, in which case this would not
+ apply. */
+ bound_minimal_symbol found
+ = (lookup_minimal_symbol_linkage
+ (sym->linkage_name (), objfile));
+ if (found.minsym != nullptr)
+ sym->maybe_copied = 1;
+ }
/* A variable with DW_AT_external is never static,
but it may be block-scoped. */
- list_to_add = (cu->list_in_scope == &file_symbols
- ? &global_symbols : cu->list_in_scope);
+ list_to_add
+ = ((cu->list_in_scope
+ == cu->get_builder ()->get_file_symbols ())
+ ? cu->get_builder ()->get_global_symbols ()
+ : cu->list_in_scope);
}
else
list_to_add = cu->list_in_scope;
{
/* A variable with DW_AT_external is never static, but it
may be block-scoped. */
- list_to_add = (cu->list_in_scope == &file_symbols
- ? &global_symbols : cu->list_in_scope);
+ list_to_add
+ = ((cu->list_in_scope
+ == cu->get_builder ()->get_file_symbols ())
+ ? cu->get_builder ()->get_global_symbols ()
+ : cu->list_in_scope);
SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
}
}
break;
case DW_TAG_formal_parameter:
- /* If we are inside a function, mark this as an argument. If
- not, we might be looking at an argument to an inlined function
- when we do not have enough information to show inlined frames;
- pretend it's a local variable in that case so that the user can
- still see it. */
- if (context_stack_depth > 0
- && context_stack[context_stack_depth - 1].name != NULL)
- SYMBOL_IS_ARGUMENT (sym) = 1;
- attr = dwarf2_attr (die, DW_AT_location, cu);
- if (attr)
- {
- var_decode_location (attr, sym, cu);
- }
- attr = dwarf2_attr (die, DW_AT_const_value, cu);
- if (attr)
- {
- dwarf2_const_value (attr, sym, cu);
- }
+ {
+ /* If we are inside a function, mark this as an argument. If
+ not, we might be looking at an argument to an inlined function
+ when we do not have enough information to show inlined frames;
+ pretend it's a local variable in that case so that the user can
+ still see it. */
+ struct context_stack *curr
+ = cu->get_builder ()->get_current_context_stack ();
+ if (curr != nullptr && curr->name != nullptr)
+ SYMBOL_IS_ARGUMENT (sym) = 1;
+ attr = dwarf2_attr (die, DW_AT_location, cu);
+ if (attr != nullptr)
+ {
+ var_decode_location (attr, sym, cu);
+ }
+ attr = dwarf2_attr (die, DW_AT_const_value, cu);
+ if (attr != nullptr)
+ {
+ dwarf2_const_value (attr, sym, cu);
+ }
- list_to_add = cu->list_in_scope;
+ list_to_add = cu->list_in_scope;
+ }
break;
case DW_TAG_unspecified_parameters:
/* From varargs functions; gdb doesn't seem to have any
if (!suppress_add)
{
- list_to_add = (cu->list_in_scope == &file_symbols
- && cu->language == language_cplus
- ? &global_symbols : cu->list_in_scope);
+ buildsym_compunit *builder = cu->get_builder ();
+ list_to_add
+ = (cu->list_in_scope == builder->get_file_symbols ()
+ && cu->language == language_cplus
+ ? builder->get_global_symbols ()
+ : cu->list_in_scope);
/* The semantics of C++ state that "struct foo {
... }" also defines a typedef for "foo". */
with this objfile, so we don't need to
duplicate it for the type. */
if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
- TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
+ TYPE_NAME (SYMBOL_TYPE (sym)) = sym->search_name ();
}
}
}
break;
case DW_TAG_enumerator:
attr = dwarf2_attr (die, DW_AT_const_value, cu);
- if (attr)
+ if (attr != nullptr)
{
dwarf2_const_value (attr, sym, cu);
}
/* NOTE: carlton/2003-11-10: See comment above in the
DW_TAG_class_type, etc. block. */
- list_to_add = (cu->list_in_scope == &file_symbols
- && cu->language == language_cplus
- ? &global_symbols : cu->list_in_scope);
+ list_to_add
+ = (cu->list_in_scope == cu->get_builder ()->get_file_symbols ()
+ && cu->language == language_cplus
+ ? cu->get_builder ()->get_global_symbols ()
+ : cu->list_in_scope);
}
break;
case DW_TAG_imported_declaration:
case DW_TAG_namespace:
SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
- list_to_add = &global_symbols;
+ list_to_add = cu->get_builder ()->get_global_symbols ();
break;
case DW_TAG_module:
SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
- list_to_add = &global_symbols;
+ list_to_add = cu->get_builder ()->get_global_symbols ();
break;
case DW_TAG_common_block:
SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
trash data, but since we must specifically ignore things
we don't recognize, there is nothing else we should do at
this point. */
- complaint (&symfile_complaints, _("unsupported tag: '%s'"),
+ complaint (_("unsupported tag: '%s'"),
dwarf_tag_name (die->tag));
break;
}
namespaces based on the demangled name. */
if (!cu->processing_has_namespace_info
&& cu->language == language_cplus)
- cp_scan_for_anonymous_namespaces (sym, objfile);
+ cp_scan_for_anonymous_namespaces (cu->get_builder (), sym, objfile);
}
return (sym);
}
switch (attr->form)
{
case DW_FORM_addr:
+ case DW_FORM_addrx:
case DW_FORM_GNU_addr_index:
{
gdb_byte *data;
break;
case DW_FORM_string:
case DW_FORM_strp:
+ case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
/* DW_STRING is already allocated on the objfile obstack, point
break;
default:
- complaint (&symfile_complaints,
- _("unsupported const value attribute form: '%s'"),
+ complaint (_("unsupported const value attribute form: '%s'"),
dwarf_form_name (attr->form));
*value = 0;
break;
struct dwarf2_locexpr_baton *baton;
dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
- SYMBOL_PRINT_NAME (sym),
+ sym->print_name (),
&objfile->objfile_obstack, cu,
&value, &bytes, &baton);
struct dwarf2_per_objfile *dwarf2_per_objfile
= cu->per_cu->dwarf2_per_objfile;
struct objfile *objfile = dwarf2_per_objfile->objfile;
- char *message, *saved;
+ char *saved;
- message = xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
- objfile_name (objfile),
- sect_offset_str (cu->header.sect_off),
- sect_offset_str (die->sect_off));
- saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
- message, strlen (message));
- xfree (message);
+ std::string message
+ = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
+ objfile_name (objfile),
+ sect_offset_str (cu->header.sect_off),
+ sect_offset_str (die->sect_off));
+ saved = obstack_strdup (&objfile->objfile_obstack, message);
return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
}
}
else
{
- complaint (&symfile_complaints,
- _("Dwarf Error: Bad type attribute %s in DIE"
+ complaint (_("Dwarf Error: Bad type attribute %s in DIE"
" at %s [in module %s]"),
dwarf_attr_name (attr->name), sect_offset_str (die->sect_off),
objfile_name (objfile));
this_type = read_tag_atomic_type (die, cu);
break;
default:
- complaint (&symfile_complaints,
- _("unexpected tag in read_type_die: '%s'"),
+ complaint (_("unexpected tag in read_type_die: '%s'"),
dwarf_tag_name (die->tag));
break;
}
This is the full-die version of guess_partial_die_structure_name.
In this case we know DIE has no useful parent. */
-static char *
+static const char *
guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
{
struct die_info *spec_die;
if (linkage_name != NULL)
{
- char *actual_name
- = language_class_name_from_physname (cu->language_defn,
- linkage_name);
- char *name = NULL;
+ gdb::unique_xmalloc_ptr<char> actual_name
+ (language_class_name_from_physname (cu->language_defn,
+ linkage_name));
+ const char *name = NULL;
if (actual_name != NULL)
{
const char *die_name = dwarf2_name (die, cu);
if (die_name != NULL
- && strcmp (die_name, actual_name) != 0)
+ && strcmp (die_name, actual_name.get ()) != 0)
{
/* Strip off the class name from the full name.
We want the prefix. */
int die_name_len = strlen (die_name);
- int actual_name_len = strlen (actual_name);
+ int actual_name_len = strlen (actual_name.get ());
+ const char *ptr = actual_name.get ();
/* Test for '::' as a sanity check. */
if (actual_name_len > die_name_len + 2
- && actual_name[actual_name_len
- - die_name_len - 1] == ':')
- name = (char *) obstack_copy0 (
+ && ptr[actual_name_len - die_name_len - 1] == ':')
+ name = obstack_strndup (
&objfile->per_bfd->storage_obstack,
- actual_name, actual_name_len - die_name_len - 2);
+ ptr, actual_name_len - die_name_len - 2);
}
}
- xfree (actual_name);
return name;
}
}
return "";
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
- return (char *) obstack_copy0 (&objfile->per_bfd->storage_obstack,
- DW_STRING (attr),
- &base[-1] - DW_STRING (attr));
+ return obstack_strndup (&objfile->per_bfd->storage_obstack,
+ DW_STRING (attr),
+ &base[-1] - DW_STRING (attr));
}
/* Return the name of the namespace/class that DIE is defined within,
doesn't allow it), and break the loop here. */
name = dwarf2_name (die, cu);
parent_name = dwarf2_name (parent, cu);
- complaint (&symfile_complaints,
- _("template param type '%s' defined within parent '%s'"),
+ complaint (_("template param type '%s' defined within parent '%s'"),
name ? name : "<unknown>",
parent_name ? parent_name : "<unknown>");
return "";
DW_TAG_namespace DIEs with a name of "::" for the global namespace.
Work around this problem here. */
if (cu->language == language_cplus
- && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
+ && strcmp (TYPE_NAME (parent_type), "::") == 0)
return "";
/* We give a name to even anonymous namespaces. */
- return TYPE_TAG_NAME (parent_type);
+ return TYPE_NAME (parent_type);
case DW_TAG_class_type:
case DW_TAG_interface_type:
case DW_TAG_structure_type:
case DW_TAG_union_type:
case DW_TAG_module:
parent_type = read_type_die (parent, cu);
- if (TYPE_TAG_NAME (parent_type) != NULL)
- return TYPE_TAG_NAME (parent_type);
+ if (TYPE_NAME (parent_type) != NULL)
+ return TYPE_NAME (parent_type);
else
/* An anonymous structure is only allowed non-static data
members; no typedefs, no member functions, et cetera.
case DW_TAG_partial_unit:
/* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
if (cu->language == language_cplus
- && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
+ && !dwarf2_per_objfile->types.empty ()
&& die->child != NULL
&& (die->tag == DW_TAG_class_type
|| die->tag == DW_TAG_structure_type
|| die->tag == DW_TAG_union_type))
{
- char *name = guess_full_die_structure_name (die, cu);
+ const char *name = guess_full_die_structure_name (die, cu);
if (name != NULL)
return name;
}
return "";
+ case DW_TAG_subprogram:
+ /* Nested subroutines in Fortran get a prefix with the name
+ of the parent's subroutine. */
+ if (cu->language == language_fortran)
+ {
+ if ((die->tag == DW_TAG_subprogram)
+ && (dwarf2_name (parent, cu) != NULL))
+ return dwarf2_name (parent, cu);
+ }
+ return determine_prefix (parent, cu);
case DW_TAG_enumeration_type:
parent_type = read_type_die (parent, cu);
if (TYPE_DECLARED_CLASS (parent_type))
{
- if (TYPE_TAG_NAME (parent_type) != NULL)
- return TYPE_TAG_NAME (parent_type);
+ if (TYPE_NAME (parent_type) != NULL)
+ return TYPE_NAME (parent_type);
return "";
}
/* Fall through. */
if (!canon_name.empty ())
{
if (canon_name != name)
- name = (const char *) obstack_copy0 (obstack,
- canon_name.c_str (),
- canon_name.length ());
+ name = obstack_strdup (obstack, canon_name);
}
}
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
if (!attr || DW_STRING (attr) == NULL)
{
- char *demangled = NULL;
-
attr = dw2_linkage_name_attr (die, cu);
if (attr == NULL || DW_STRING (attr) == NULL)
return NULL;
/* Avoid demangling DW_STRING (attr) the second time on a second
call for the same DIE. */
if (!DW_STRING_IS_CANONICAL (attr))
- demangled = gdb_demangle (DW_STRING (attr), DMGL_TYPES);
-
- if (demangled)
{
+ gdb::unique_xmalloc_ptr<char> demangled
+ (gdb_demangle (DW_STRING (attr), DMGL_TYPES));
+
const char *base;
/* FIXME: we already did this for the partial symbol... */
DW_STRING (attr)
- = ((const char *)
- obstack_copy0 (&objfile->per_bfd->storage_obstack,
- demangled, strlen (demangled)));
+ = obstack_strdup (&objfile->per_bfd->storage_obstack,
+ demangled.get ());
DW_STRING_IS_CANONICAL (attr) = 1;
- xfree (demangled);
/* Strip any leading namespaces/classes, keep only the base name.
DW_AT_name for named DIEs does not contain the prefixes. */
return follow_die_ref (die, attr, ext_cu);
}
+/* A convenience function that returns an "unknown" DWARF name,
+ including the value of V. STR is the name of the entity being
+ printed, e.g., "TAG". */
+
+static const char *
+dwarf_unknown (const char *str, unsigned v)
+{
+ char *cell = get_print_cell ();
+ xsnprintf (cell, PRINT_CELL_SIZE, "DW_%s_<unknown: %u>", str, v);
+ return cell;
+}
+
/* Convert a DIE tag into its string name. */
static const char *
const char *name = get_DW_TAG_name (tag);
if (name == NULL)
- return "DW_TAG_<unknown>";
+ return dwarf_unknown ("TAG", tag);
return name;
}
name = get_DW_AT_name (attr);
if (name == NULL)
- return "DW_AT_<unknown>";
+ return dwarf_unknown ("AT", attr);
return name;
}
+/* Convert a unit type to corresponding DW_UT name. */
+
+static const char *
+dwarf_unit_type_name (int unit_type) {
+ switch (unit_type)
+ {
+ case 0x01:
+ return "DW_UT_compile (0x01)";
+ case 0x02:
+ return "DW_UT_type (0x02)";
+ case 0x03:
+ return "DW_UT_partial (0x03)";
+ case 0x04:
+ return "DW_UT_skeleton (0x04)";
+ case 0x05:
+ return "DW_UT_split_compile (0x05)";
+ case 0x06:
+ return "DW_UT_split_type (0x06)";
+ case 0x80:
+ return "DW_UT_lo_user (0x80)";
+ case 0xff:
+ return "DW_UT_hi_user (0xff)";
+ default:
+ return nullptr;
+ }
+}
+
/* Convert a DWARF value form code into its string name. */
static const char *
const char *name = get_DW_FORM_name (form);
if (name == NULL)
- return "DW_FORM_<unknown>";
+ return dwarf_unknown ("FORM", form);
return name;
}
const char *name = get_DW_ATE_name (enc);
if (name == NULL)
- return "DW_ATE_<unknown>";
+ return dwarf_unknown ("ATE", enc);
return name;
}
switch (die->attrs[i].form)
{
case DW_FORM_addr:
+ case DW_FORM_addrx:
case DW_FORM_GNU_addr_index:
fprintf_unfiltered (f, "address: ");
fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
case DW_FORM_string:
case DW_FORM_strp:
case DW_FORM_line_strp:
+ case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
case DW_FORM_indirect:
/* The reader will have reduced the indirect form to
the "base form" so this form should not occur. */
- fprintf_unfiltered (f,
+ fprintf_unfiltered (f,
"unexpected attribute form: DW_FORM_indirect");
break;
case DW_FORM_implicit_const:
if (attr_form_is_ref (attr))
return (sect_offset) DW_UNSND (attr);
- complaint (&symfile_complaints,
- _("unsupported die ref attribute form: '%s'"),
+ complaint (_("unsupported die ref attribute form: '%s'"),
dwarf_form_name (attr->form));
return {};
}
else
{
/* For DW_FORM_data16 see attr_form_is_constant. */
- complaint (&symfile_complaints,
- _("Attribute value is not a constant (%s)"),
+ complaint (_("Attribute value is not a constant (%s)"),
dwarf_form_name (attr->form));
return default_value;
}
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);
/* If necessary, add it to the queue and load its DIEs. */
if (maybe_queue_comp_unit (cu, per_cu, cu->language))
- load_full_comp_unit (per_cu, cu->language);
+ load_full_comp_unit (per_cu, false, cu->language);
target_cu = per_cu->cu;
}
{
/* We're loading full DIEs during partial symbol reading. */
gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
- load_full_comp_unit (cu->per_cu, language_minimal);
+ load_full_comp_unit (cu->per_cu, false, language_minimal);
}
*ref_cu = target_cu;
temp_die.sect_off = sect_off;
+
+ if (target_cu != cu)
+ target_cu->ancestor = cu;
+
return (struct die_info *) htab_find_with_hash (target_cu->die_hash,
&temp_die,
to_underlying (sect_off));
dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
struct dwarf2_per_cu_data *per_cu,
CORE_ADDR (*get_frame_pc) (void *baton),
- void *baton)
+ void *baton, bool resolve_abstract_p)
{
struct dwarf2_cu *cu;
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);
+ load_cu (per_cu, false);
cu = per_cu->cu;
if (cu == NULL)
{
sect_offset_str (sect_off), objfile_name (objfile));
attr = dwarf2_attr (die, DW_AT_location, cu);
+ if (!attr && resolve_abstract_p
+ && (dwarf2_per_objfile->abstract_to_concrete.find (die->sect_off)
+ != dwarf2_per_objfile->abstract_to_concrete.end ()))
+ {
+ CORE_ADDR pc = (*get_frame_pc) (baton);
+ CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
+ for (const auto &cand_off
+ : dwarf2_per_objfile->abstract_to_concrete[die->sect_off])
+ {
+ struct dwarf2_cu *cand_cu = cu;
+ struct die_info *cand
+ = follow_die_offset (cand_off, per_cu->is_dwz, &cand_cu);
+ if (!cand
+ || !cand->parent
+ || cand->parent->tag != DW_TAG_subprogram)
+ continue;
+
+ CORE_ADDR pc_low, pc_high;
+ get_scope_pc_bounds (cand->parent, &pc_low, &pc_high, cu);
+ if (pc_low == ((CORE_ADDR) -1))
+ continue;
+ pc_low = gdbarch_adjust_dwarf2_addr (gdbarch, pc_low + baseaddr);
+ pc_high = gdbarch_adjust_dwarf2_addr (gdbarch, pc_high + baseaddr);
+ if (!(pc_low <= pc && pc < pc_high))
+ continue;
+
+ die = cand;
+ attr = dwarf2_attr (die, DW_AT_location, cu);
+ break;
+ }
+ }
+
if (!attr)
{
/* DWARF: "If there is no such attribute, then there is no effect.".
struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
if (per_cu->cu == NULL)
- load_cu (per_cu);
+ load_cu (per_cu, false);
cu = per_cu->cu;
if (cu == NULL)
{
switch (attr->form)
{
case DW_FORM_addr:
+ case DW_FORM_addrx:
case DW_FORM_GNU_addr_index:
{
gdb_byte *tem;
break;
case DW_FORM_string:
case DW_FORM_strp:
+ case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
/* DW_STRING is already allocated on the objfile obstack, point
break;
default:
- complaint (&symfile_complaints,
- _("unsupported const value attribute form: '%s'"),
+ complaint (_("unsupported const value attribute form: '%s'"),
dwarf_form_name (attr->form));
break;
}
struct die_info *die;
if (per_cu->cu == NULL)
- load_cu (per_cu);
+ load_cu (per_cu, false);
cu = per_cu->cu;
if (!cu)
return NULL;
struct dwarf2_cu **ref_cu)
{
struct die_info temp_die;
- struct dwarf2_cu *sig_cu;
+ struct dwarf2_cu *sig_cu, *cu = *ref_cu;
struct die_info *die;
/* While it might be nice to assert sig_type->type == NULL here,
if (dwarf2_per_objfile->index_table != NULL
&& dwarf2_per_objfile->index_table->version <= 7)
{
- VEC_safe_push (dwarf2_per_cu_ptr,
- (*ref_cu)->per_cu->imported_symtabs,
- sig_cu->per_cu);
+ (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu);
}
*ref_cu = sig_cu;
+ if (sig_cu != cu)
+ sig_cu->ancestor = cu;
+
return die;
}
the debug info. */
if (sig_type == NULL)
{
- complaint (&symfile_complaints,
- _("Dwarf Error: Cannot find signatured DIE %s referenced"
+ complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
" from DIE at %s [in module %s]"),
hex_string (signature), sect_offset_str (die->sect_off),
objfile_name (dwarf2_per_objfile->objfile));
type = read_type_die (type_die, type_cu);
if (type == NULL)
{
- complaint (&symfile_complaints,
- _("Dwarf Error: Cannot build signatured type %s"
+ complaint (_("Dwarf Error: Cannot build signatured type %s"
" referenced from DIE at %s [in module %s]"),
hex_string (signature), sect_offset_str (die->sect_off),
objfile_name (dwarf2_per_objfile->objfile));
}
else
{
- complaint (&symfile_complaints,
- _("Dwarf Error: Problem reading signatured DIE %s referenced"
+ complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
" from DIE at %s [in module %s]"),
hex_string (signature), sect_offset_str (die->sect_off),
objfile_name (dwarf2_per_objfile->objfile));
struct dwarf2_per_objfile *dwarf2_per_objfile
= cu->per_cu->dwarf2_per_objfile;
- complaint (&symfile_complaints,
- _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
+ complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
" at %s [in module %s]"),
dwarf_form_name (attr->form), sect_offset_str (die->sect_off),
objfile_name (dwarf2_per_objfile->objfile));
gdb_assert (per_cu->is_debug_types);
gdb_assert (per_cu->cu == NULL);
- init_cutu_and_read_dies (per_cu, NULL, 0, 1,
+ init_cutu_and_read_dies (per_cu, NULL, 0, 1, false,
read_signatured_type_reader, NULL);
sig_type->per_cu.tu_read = 1;
}
case DW_OP_GNU_uninit:
break;
+ case DW_OP_addrx:
case DW_OP_GNU_addr_index:
case DW_OP_GNU_const_index:
stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
const char *name = get_DW_OP_name (op);
if (name)
- complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
+ complaint (_("unsupported stack op: '%s'"),
name);
else
- complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
+ complaint (_("unsupported stack op: '%02x'"),
op);
}
outside of the allocated space. Also enforce minimum>0. */
if (stacki >= ARRAY_SIZE (stack) - 1)
{
- complaint (&symfile_complaints,
- _("location description stack overflow"));
+ complaint (_("location description stack overflow"));
return 0;
}
if (stacki <= 0)
{
- complaint (&symfile_complaints,
- _("location description stack underflow"));
+ complaint (_("location description stack underflow"));
return 0;
}
}
{
/* Is the file number a valid index into the line header's file name
table? Remember that file numbers start with one, not zero. */
- if (1 <= file && file <= lh->file_names.size ())
+ if (lh->is_valid_file_index (file))
{
- const file_entry &fe = lh->file_names[file - 1];
+ const file_entry *fe = lh->file_name_at (file);
- if (!IS_ABSOLUTE_PATH (fe.name))
+ if (!IS_ABSOLUTE_PATH (fe->name))
{
- const char *dir = fe.include_dir (lh);
+ const char *dir = fe->include_dir (lh);
if (dir != NULL)
- return concat (dir, SLASH_STRING, fe.name, (char *) NULL);
+ return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
}
- return xstrdup (fe.name);
+ return xstrdup (fe->name);
}
else
{
xsnprintf (fake_name, sizeof (fake_name),
"<bad macro file number %d>", file);
- complaint (&symfile_complaints,
- _("bad file number in macro information (%d)"),
+ complaint (_("bad file number in macro information (%d)"),
file);
return xstrdup (fake_name);
{
/* Is the file number a valid index into the line header's file name
table? Remember that file numbers start with one, not zero. */
- if (1 <= file && file <= lh->file_names.size ())
+ if (lh->is_valid_file_index (file))
{
char *relative = file_file_name (file, lh);
static struct macro_source_file *
-macro_start_file (int file, int line,
+macro_start_file (struct dwarf2_cu *cu,
+ int file, int line,
struct macro_source_file *current_file,
struct line_header *lh)
{
{
/* Note: We don't create a macro table for this compilation unit
at all until we actually get a filename. */
- struct macro_table *macro_table = get_macro_table ();
+ struct macro_table *macro_table = cu->get_builder ()->get_macro_table ();
/* If we have no current file, then this must be the start_file
directive for the compilation unit's main source file. */
{
if (*p == ' ')
{
- complaint (&symfile_complaints,
- _("macro definition contains spaces "
+ complaint (_("macro definition contains spaces "
"in formal argument list:\n`%s'"),
body);
{
/* It's an object-like macro. */
int name_len = p - body;
- char *name = savestring (body, name_len);
+ std::string name (body, name_len);
const char *replacement;
if (*p == ' ')
replacement = body + name_len;
}
- macro_define_object (file, line, name, replacement);
-
- xfree (name);
+ macro_define_object (file, line, name.c_str (), replacement);
}
else if (*p == '(')
{
/* It's a function-like macro. */
- char *name = savestring (body, p - body);
+ std::string name (body, p - body);
int argc = 0;
int argv_size = 1;
char **argv = XNEWVEC (char *, argv_size);
if (*p == ' ')
/* Perfectly formed definition, no complaints. */
- macro_define_function (file, line, name,
+ macro_define_function (file, line, name.c_str (),
argc, (const char **) argv,
p + 1);
else if (*p == '\0')
{
/* Complain, but do define it. */
dwarf2_macro_malformed_definition_complaint (body);
- macro_define_function (file, line, name,
+ macro_define_function (file, line, name.c_str (),
argc, (const char **) argv,
p);
}
/* Just complain. */
dwarf2_macro_malformed_definition_complaint (body);
- xfree (name);
{
int i;
bytes += 4 + read_4_bytes (abfd, bytes);
break;
+ case DW_FORM_addrx:
case DW_FORM_sdata:
+ case DW_FORM_strx:
case DW_FORM_udata:
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index:
default:
{
- complaint (&symfile_complaints,
- _("invalid form 0x%x in `%s'"),
+ complaint (_("invalid form 0x%x in `%s'"),
form, get_section_name (section));
return NULL;
}
if (opcode_definitions[opcode] == NULL)
{
- complaint (&symfile_complaints,
- _("unrecognized DW_MACFINO opcode 0x%x"),
+ complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
opcode);
return NULL;
}
version = read_2_bytes (abfd, mac_ptr);
if (version != 4 && version != 5)
{
- complaint (&symfile_complaints,
- _("unrecognized version `%d' in .debug_macro section"),
+ complaint (_("unrecognized version `%d' in .debug_macro section"),
version);
return NULL;
}
including DW_MACRO_import. */
static void
-dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
+dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
bfd *abfd,
const gdb_byte *mac_ptr, const gdb_byte *mac_end,
struct macro_source_file *current_file,
unsigned int offset_size,
htab_t include_hash)
{
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = cu->per_cu->dwarf2_per_objfile;
struct objfile *objfile = dwarf2_per_objfile->objfile;
enum dwarf_macro_record_type macinfo_type;
int at_commandline;
if (! current_file)
{
/* DWARF violation as no main source is present. */
- complaint (&symfile_complaints,
- _("debug info with no main source gives macro %s "
+ complaint (_("debug info with no main source gives macro %s "
"on line %d: %s"),
is_define ? _("definition") : _("undefinition"),
line, body);
}
if ((line == 0 && !at_commandline)
|| (line != 0 && at_commandline))
- complaint (&symfile_complaints,
- _("debug info gives %s macro %s with %s line %d: %s"),
+ complaint (_("debug info gives %s macro %s with %s line %d: %s"),
at_commandline ? _("command-line") : _("in-file"),
is_define ? _("definition") : _("undefinition"),
line == 0 ? _("zero") : _("non-zero"), line, body);
- if (is_define)
+ if (body == NULL)
+ {
+ /* Fedora's rpm-build's "debugedit" binary
+ corrupted .debug_macro sections.
+
+ For more info, see
+ https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
+ complaint (_("debug info gives %s invalid macro %s "
+ "without body (corrupted?) at line %d "
+ "on file %s"),
+ at_commandline ? _("command-line") : _("in-file"),
+ is_define ? _("definition") : _("undefinition"),
+ line, current_file->filename);
+ }
+ else if (is_define)
parse_macro_definition (current_file, line, body);
else
{
if ((line == 0 && !at_commandline)
|| (line != 0 && at_commandline))
- complaint (&symfile_complaints,
- _("debug info gives source %d included "
+ complaint (_("debug info gives source %d included "
"from %s at %s line %d"),
file, at_commandline ? _("command-line") : _("file"),
line == 0 ? _("zero") : _("non-zero"), line);
at_commandline = 0;
}
else
- current_file = macro_start_file (file, line, current_file, lh);
+ current_file = macro_start_file (cu, file, line, current_file,
+ lh);
}
break;
case DW_MACRO_end_file:
if (! current_file)
- complaint (&symfile_complaints,
- _("macro debug info has an unmatched "
+ complaint (_("macro debug info has an unmatched "
"`close_file' directive"));
else
{
= (enum dwarf_macro_record_type) read_1_byte (abfd,
mac_ptr);
if (next_type != 0)
- complaint (&symfile_complaints,
- _("no terminating 0-type entry for "
+ complaint (_("no terminating 0-type entry for "
"macros in `.debug_macinfo' section"));
return;
{
/* This has actually happened; see
http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
- complaint (&symfile_complaints,
- _("recursive DW_MACRO_import in "
+ complaint (_("recursive DW_MACRO_import in "
".debug_macro section"));
}
else
{
*slot = (void *) new_mac_ptr;
- dwarf_decode_macro_bytes (dwarf2_per_objfile,
- include_bfd, new_mac_ptr,
+ dwarf_decode_macro_bytes (cu, include_bfd, new_mac_ptr,
include_mac_end, current_file, lh,
section, section_is_gnu, is_dwz,
offset_size, include_hash);
dwarf2_read_section (objfile, section);
if (section->buffer == NULL)
{
- complaint (&symfile_complaints, _("missing %s section"), section_name);
+ complaint (_("missing %s section"), section_name);
return;
}
abfd = get_section_bfd_owner (section);
file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
- current_file = macro_start_file (file, line, current_file, lh);
+ current_file = macro_start_file (cu, file, line, current_file, lh);
}
break;
mac_ptr = section->buffer + offset;
slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
*slot = (void *) mac_ptr;
- dwarf_decode_macro_bytes (dwarf2_per_objfile,
- abfd, mac_ptr, mac_end,
+ dwarf_decode_macro_bytes (cu, abfd, mac_ptr, mac_end,
current_file, lh, section,
section_is_gnu, 0, offset_size,
include_hash.get ());
if (cu->dwo_unit)
{
struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
-
+
return cu->header.version >= 5 ? §ions->loclists : §ions->loc;
}
return (cu->header.version >= 5 ? &dwarf2_per_objfile->loclists
fill_in_loclist_baton (cu, baton, attr);
if (cu->base_known == 0)
- complaint (&symfile_complaints,
- _("Location list used without "
+ complaint (_("Location list used without "
"specifying the CU base address."));
SYMBOL_ACLASS_INDEX (sym) = (is_block
else
{
dwarf2_invalid_attrib_class_complaint ("location description",
- SYMBOL_NATURAL_NAME (sym));
+ sym->natural_name ());
baton->size = 0;
}
{
struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
- return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+ return objfile->section_offsets[SECT_OFF_TEXT (objfile)];
+}
+
+/* Return a type that is a generic pointer type, the size of which matches
+ the address size given in the compilation unit header for PER_CU. */
+static struct type *
+dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu)
+{
+ struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+ struct type *void_type = objfile_type (objfile)->builtin_void;
+ struct type *addr_type = lookup_pointer_type (void_type);
+ int addr_size = dwarf2_per_cu_addr_size (per_cu);
+
+ if (TYPE_LENGTH (addr_type) == addr_size)
+ return addr_type;
+
+ addr_type
+ = dwarf2_per_cu_addr_sized_int_type (per_cu, TYPE_UNSIGNED (addr_type));
+ return addr_type;
}
/* Return DWARF version number of PER_CU. */
{
struct dwarf2_per_cu_data *this_cu;
int low, high;
- 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;
int mid = low + (high - low) / 2;
mid_cu = dwarf2_per_objfile->all_comp_units[mid];
- cu_off = &mid_cu->sect_off;
if (mid_cu->is_dwz > offset_in_dwz
- || (mid_cu->is_dwz == offset_in_dwz && *cu_off >= sect_off))
+ || (mid_cu->is_dwz == offset_in_dwz
+ && mid_cu->sect_off + mid_cu->length >= sect_off))
high = mid;
else
low = mid + 1;
}
gdb_assert (low == high);
this_cu = dwarf2_per_objfile->all_comp_units[low];
- cu_off = &this_cu->sect_off;
- if (this_cu->is_dwz != offset_in_dwz || *cu_off > sect_off)
+ if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
{
if (low == 0 || this_cu->is_dwz != offset_in_dwz)
error (_("Dwarf Error: could not find partial DIE containing "
}
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);
dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data *per_cu_)
: per_cu (per_cu_),
- mark (0),
- has_loclist (0),
- checked_producer (0),
- producer_is_gxx_lt_4_6 (0),
- producer_is_gcc_lt_4_3 (0),
- producer_is_icc_lt_14 (0),
- processing_has_namespace_info (0)
+ mark (false),
+ has_loclist (false),
+ checked_producer (false),
+ producer_is_gxx_lt_4_6 (false),
+ producer_is_gcc_lt_4_3 (false),
+ producer_is_icc (false),
+ producer_is_icc_lt_14 (false),
+ producer_is_codewarrior (false),
+ processing_has_namespace_info (false)
{
per_cu->cu = this;
}
/* Set the language we're debugging. */
attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
- if (attr)
+ if (attr != nullptr)
set_cu_language (DW_UNSND (attr), cu);
else
{
cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu);
}
-/* Free all cached compilation units. */
-
-static void
-free_cached_comp_units (void *data)
-{
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = (struct dwarf2_per_objfile *) data;
-
- dwarf2_per_objfile->free_cached_comp_units ();
-}
-
/* Increase the age counter on each cached compilation unit, and free
any that are too old. */
}
}
-/* Release all extra memory associated with OBJFILE. */
-
-void
-dwarf2_free_objfile (struct objfile *objfile)
-{
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
-
- delete dwarf2_per_objfile;
-}
-
/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
We store these in a hash table separate from the DIEs, and preserve them
when the DIEs are flushed out of cache.
table if necessary. For convenience, return TYPE.
The DIEs reading must have careful ordering to:
- * Not cause infite loops trying to read in DIEs as a prerequisite for
+ * Not cause infinite loops trying to read in DIEs as a prerequisite for
reading current DIE.
* Not trying to dereference contents of still incompletely read in types
while reading in other DIEs.
attr = dwarf2_attr (die, DW_AT_allocated, cu);
if (attr_form_is_block (attr))
{
- if (attr_to_dynamic_prop (attr, die, cu, &prop))
+ struct type *prop_type
+ = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+ if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
add_dyn_prop (DYN_PROP_ALLOCATED, prop, type);
}
else if (attr != NULL)
{
- complaint (&symfile_complaints,
- _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
+ complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
(attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
sect_offset_str (die->sect_off));
}
attr = dwarf2_attr (die, DW_AT_associated, cu);
if (attr_form_is_block (attr))
{
- if (attr_to_dynamic_prop (attr, die, cu, &prop))
+ struct type *prop_type
+ = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+ if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type);
}
else if (attr != NULL)
{
- complaint (&symfile_complaints,
- _("DW_AT_associated has the wrong form (%s) at DIE %s"),
+ complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
(attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
sect_offset_str (die->sect_off));
}
/* Read DW_AT_data_location and set in type. */
attr = dwarf2_attr (die, DW_AT_data_location, cu);
- if (attr_to_dynamic_prop (attr, die, cu, &prop))
+ if (attr_to_dynamic_prop (attr, die, cu, &prop,
+ dwarf2_per_cu_addr_type (cu->per_cu)))
add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
if (dwarf2_per_objfile->die_type_hash == NULL)
slot = (struct dwarf2_per_cu_offset_and_type **)
htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
if (*slot)
- complaint (&symfile_complaints,
- _("A problem internal to GDB: DIE %s has type already set"),
+ complaint (_("A problem internal to GDB: DIE %s has type already set"),
sect_offset_str (die->sect_off));
*slot = XOBNEW (&objfile->objfile_obstack,
struct dwarf2_per_cu_offset_and_type);
if (per_cu->cu->mark)
return 1;
- per_cu->cu->mark = 1;
+ per_cu->cu->mark = true;
if (per_cu->cu->dependencies != NULL)
htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
{
if (cu->mark)
return;
- cu->mark = 1;
+ cu->mark = true;
if (cu->dependencies != NULL)
htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
}
{
while (per_cu)
{
- per_cu->cu->mark = 0;
+ per_cu->cu->mark = false;
per_cu = per_cu->cu->read_in_chain;
}
}
return part_die_lhs->sect_off == part_die_rhs->sect_off;
}
-static struct cmd_list_element *set_dwarf_cmdlist;
-static struct cmd_list_element *show_dwarf_cmdlist;
+struct cmd_list_element *set_dwarf_cmdlist;
+struct cmd_list_element *show_dwarf_cmdlist;
static void
set_dwarf_cmd (const char *args, int from_tty)
cmd_show_list (show_dwarf_cmdlist, from_tty, "");
}
-/* The "save gdb-index" command. */
-
-/* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
- error checking. */
+bool dwarf_always_disassemble;
static void
-file_write (FILE *file, const void *data, size_t size)
+show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
{
- if (fwrite (data, 1, size, file) != size)
- error (_("couldn't data write to file"));
+ fprintf_filtered (file,
+ _("Whether to always disassemble "
+ "DWARF expressions is %s.\n"),
+ value);
}
-/* Write the contents of VEC to FILE, with error checking. */
-
-template<typename Elem, typename Alloc>
static void
-file_write (FILE *file, const std::vector<Elem, Alloc> &vec)
-{
- file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
-}
-
-/* In-memory buffer to prepare data to be written later to a file. */
-class data_buf
-{
-public:
- /* Copy DATA to the end of the buffer. */
- template<typename T>
- void append_data (const T &data)
- {
- std::copy (reinterpret_cast<const gdb_byte *> (&data),
- reinterpret_cast<const gdb_byte *> (&data + 1),
- grow (sizeof (data)));
- }
-
- /* Copy CSTR (a zero-terminated string) to the end of buffer. The
- terminating zero is appended too. */
- void append_cstr0 (const char *cstr)
- {
- const size_t size = strlen (cstr) + 1;
- std::copy (cstr, cstr + size, grow (size));
- }
-
- /* Store INPUT as ULEB128 to the end of buffer. */
- void append_unsigned_leb128 (ULONGEST input)
- {
- for (;;)
- {
- gdb_byte output = input & 0x7f;
- input >>= 7;
- if (input)
- output |= 0x80;
- append_data (output);
- if (input == 0)
- break;
- }
- }
-
- /* Accept a host-format integer in VAL and append it to the buffer
- as a target-format integer which is LEN bytes long. */
- void append_uint (size_t len, bfd_endian byte_order, ULONGEST val)
- {
- ::store_unsigned_integer (grow (len), len, byte_order, val);
- }
-
- /* Return the size of the buffer. */
- size_t size () const
- {
- return m_vec.size ();
- }
-
- /* Return true iff the buffer is empty. */
- bool empty () const
- {
- return m_vec.empty ();
- }
-
- /* Write the buffer to FILE. */
- void file_write (FILE *file) const
- {
- ::file_write (file, m_vec);
- }
-
-private:
- /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
- the start of the new block. */
- gdb_byte *grow (size_t size)
- {
- m_vec.resize (m_vec.size () + size);
- return &*m_vec.end () - size;
- }
-
- gdb::byte_vector m_vec;
-};
-
-/* An entry in the symbol table. */
-struct symtab_index_entry
-{
- /* The name of the symbol. */
- const char *name;
- /* The offset of the name in the constant pool. */
- offset_type index_offset;
- /* A sorted vector of the indices of all the CUs that hold an object
- of this name. */
- std::vector<offset_type> cu_indices;
-};
-
-/* The symbol table. This is a power-of-2-sized hash table. */
-struct mapped_symtab
-{
- mapped_symtab ()
- {
- data.resize (1024);
- }
-
- offset_type n_elements = 0;
- std::vector<symtab_index_entry> data;
-};
-
-/* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
- the slot.
-
- Function is used only during write_hash_table so no index format backward
- compatibility is needed. */
-
-static symtab_index_entry &
-find_slot (struct mapped_symtab *symtab, const char *name)
+show_check_physname (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
{
- offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
-
- index = hash & (symtab->data.size () - 1);
- step = ((hash * 17) & (symtab->data.size () - 1)) | 1;
-
- for (;;)
- {
- if (symtab->data[index].name == NULL
- || strcmp (name, symtab->data[index].name) == 0)
- return symtab->data[index];
- index = (index + step) & (symtab->data.size () - 1);
- }
+ fprintf_filtered (file,
+ _("Whether to check \"physname\" is %s.\n"),
+ value);
}
-/* Expand SYMTAB's hash table. */
-
-static void
-hash_expand (struct mapped_symtab *symtab)
+void
+_initialize_dwarf2_read (void)
{
- auto old_entries = std::move (symtab->data);
-
- symtab->data.clear ();
- symtab->data.resize (old_entries.size () * 2);
-
- for (auto &it : old_entries)
- if (it.name != NULL)
- {
- auto &ref = find_slot (symtab, it.name);
- ref = std::move (it);
- }
-}
+ add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
+Set DWARF specific variables.\n\
+Configure DWARF variables such as the cache size."),
+ &set_dwarf_cmdlist, "maintenance set dwarf ",
+ 0/*allow-unknown*/, &maintenance_set_cmdlist);
-/* Add an entry to SYMTAB. NAME is the name of the symbol.
- CU_INDEX is the index of the CU in which the symbol appears.
- IS_STATIC is one if the symbol is static, otherwise zero (global). */
+ add_prefix_cmd ("dwarf", class_maintenance, show_dwarf_cmd, _("\
+Show DWARF specific variables.\n\
+Show DWARF variables such as the cache size."),
+ &show_dwarf_cmdlist, "maintenance show dwarf ",
+ 0/*allow-unknown*/, &maintenance_show_cmdlist);
-static void
-add_index_entry (struct mapped_symtab *symtab, const char *name,
- int is_static, gdb_index_symbol_kind kind,
- offset_type cu_index)
-{
- offset_type cu_index_and_attrs;
+ add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
+ &dwarf_max_cache_age, _("\
+Set the upper bound on the age of cached DWARF compilation units."), _("\
+Show the upper bound on the age of cached DWARF compilation units."), _("\
+A higher limit means that cached compilation units will be stored\n\
+in memory longer, and more total memory will be used. Zero disables\n\
+caching, which can slow down startup."),
+ NULL,
+ show_dwarf_max_cache_age,
+ &set_dwarf_cmdlist,
+ &show_dwarf_cmdlist);
- ++symtab->n_elements;
- if (4 * symtab->n_elements / 3 >= symtab->data.size ())
- hash_expand (symtab);
+ add_setshow_boolean_cmd ("always-disassemble", class_obscure,
+ &dwarf_always_disassemble, _("\
+Set whether `info address' always disassembles DWARF expressions."), _("\
+Show whether `info address' always disassembles DWARF expressions."), _("\
+When enabled, DWARF expressions are always printed in an assembly-like\n\
+syntax. When disabled, expressions will be printed in a more\n\
+conversational style, when possible."),
+ NULL,
+ show_dwarf_always_disassemble,
+ &set_dwarf_cmdlist,
+ &show_dwarf_cmdlist);
- symtab_index_entry &slot = find_slot (symtab, name);
- if (slot.name == NULL)
- {
- slot.name = name;
- /* index_offset is set later. */
- }
+ add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\
+Set debugging of the DWARF reader."), _("\
+Show debugging of the DWARF reader."), _("\
+When enabled (non-zero), debugging messages are printed during DWARF\n\
+reading and symtab expansion. A value of 1 (one) provides basic\n\
+information. A value greater than 1 provides more verbose information."),
+ NULL,
+ NULL,
+ &setdebuglist, &showdebuglist);
- cu_index_and_attrs = 0;
- DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index);
- DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static);
- DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind);
+ add_setshow_zuinteger_cmd ("dwarf-die", no_class, &dwarf_die_debug, _("\
+Set debugging of the DWARF DIE reader."), _("\
+Show debugging of the DWARF DIE reader."), _("\
+When enabled (non-zero), DIEs are dumped after they are read in.\n\
+The value is the maximum depth to print."),
+ NULL,
+ NULL,
+ &setdebuglist, &showdebuglist);
- /* We don't want to record an index value twice as we want to avoid the
- duplication.
- We process all global symbols and then all static symbols
- (which would allow us to avoid the duplication by only having to check
- the last entry pushed), but a symbol could have multiple kinds in one CU.
- To keep things simple we don't worry about the duplication here and
- sort and uniqufy the list after we've processed all symbols. */
- slot.cu_indices.push_back (cu_index_and_attrs);
-}
+ add_setshow_zuinteger_cmd ("dwarf-line", no_class, &dwarf_line_debug, _("\
+Set debugging of the dwarf line reader."), _("\
+Show debugging of the dwarf line reader."), _("\
+When enabled (non-zero), line number entries are dumped as they are read in.\n\
+A value of 1 (one) provides basic information.\n\
+A value greater than 1 provides more verbose information."),
+ NULL,
+ NULL,
+ &setdebuglist, &showdebuglist);
-/* Sort and remove duplicates of all symbols' cu_indices lists. */
-
-static void
-uniquify_cu_indices (struct mapped_symtab *symtab)
-{
- for (auto &entry : symtab->data)
- {
- if (entry.name != NULL && !entry.cu_indices.empty ())
- {
- auto &cu_indices = entry.cu_indices;
- std::sort (cu_indices.begin (), cu_indices.end ());
- auto from = std::unique (cu_indices.begin (), cu_indices.end ());
- cu_indices.erase (from, cu_indices.end ());
- }
- }
-}
-
-/* A form of 'const char *' suitable for container keys. Only the
- pointer is stored. The strings themselves are compared, not the
- pointers. */
-class c_str_view
-{
-public:
- c_str_view (const char *cstr)
- : m_cstr (cstr)
- {}
-
- bool operator== (const c_str_view &other) const
- {
- return strcmp (m_cstr, other.m_cstr) == 0;
- }
-
- /* Return the underlying C string. Note, the returned string is
- only a reference with lifetime of this object. */
- const char *c_str () const
- {
- return m_cstr;
- }
-
-private:
- friend class c_str_view_hasher;
- const char *const m_cstr;
-};
-
-/* A std::unordered_map::hasher for c_str_view that uses the right
- hash function for strings in a mapped index. */
-class c_str_view_hasher
-{
-public:
- size_t operator () (const c_str_view &x) const
- {
- return mapped_index_string_hash (INT_MAX, x.m_cstr);
- }
-};
-
-/* A std::unordered_map::hasher for std::vector<>. */
-template<typename T>
-class vector_hasher
-{
-public:
- size_t operator () (const std::vector<T> &key) const
- {
- return iterative_hash (key.data (),
- sizeof (key.front ()) * key.size (), 0);
- }
-};
-
-/* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
- constant pool entries going into the data buffer CPOOL. */
-
-static void
-write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool)
-{
- {
- /* Elements are sorted vectors of the indices of all the CUs that
- hold an object of this name. */
- std::unordered_map<std::vector<offset_type>, offset_type,
- vector_hasher<offset_type>>
- symbol_hash_table;
-
- /* We add all the index vectors to the constant pool first, to
- ensure alignment is ok. */
- for (symtab_index_entry &entry : symtab->data)
- {
- if (entry.name == NULL)
- continue;
- gdb_assert (entry.index_offset == 0);
-
- /* Finding before inserting is faster than always trying to
- insert, because inserting always allocates a node, does the
- lookup, and then destroys the new node if another node
- already had the same key. C++17 try_emplace will avoid
- this. */
- const auto found
- = symbol_hash_table.find (entry.cu_indices);
- if (found != symbol_hash_table.end ())
- {
- entry.index_offset = found->second;
- continue;
- }
-
- symbol_hash_table.emplace (entry.cu_indices, cpool.size ());
- entry.index_offset = cpool.size ();
- cpool.append_data (MAYBE_SWAP (entry.cu_indices.size ()));
- for (const auto index : entry.cu_indices)
- cpool.append_data (MAYBE_SWAP (index));
- }
- }
-
- /* Now write out the hash table. */
- std::unordered_map<c_str_view, offset_type, c_str_view_hasher> str_table;
- for (const auto &entry : symtab->data)
- {
- offset_type str_off, vec_off;
-
- if (entry.name != NULL)
- {
- const auto insertpair = str_table.emplace (entry.name, cpool.size ());
- if (insertpair.second)
- cpool.append_cstr0 (entry.name);
- str_off = insertpair.first->second;
- vec_off = entry.index_offset;
- }
- else
- {
- /* While 0 is a valid constant pool index, it is not valid
- to have 0 for both offsets. */
- str_off = 0;
- vec_off = 0;
- }
-
- output.append_data (MAYBE_SWAP (str_off));
- output.append_data (MAYBE_SWAP (vec_off));
- }
-}
-
-typedef std::unordered_map<partial_symtab *, unsigned int> psym_index_map;
-
-/* Helper struct for building the address table. */
-struct addrmap_index_data
-{
- addrmap_index_data (data_buf &addr_vec_, psym_index_map &cu_index_htab_)
- : addr_vec (addr_vec_), cu_index_htab (cu_index_htab_)
- {}
-
- struct objfile *objfile;
- data_buf &addr_vec;
- psym_index_map &cu_index_htab;
-
- /* Non-zero if the previous_* fields are valid.
- We can't write an entry until we see the next entry (since it is only then
- that we know the end of the entry). */
- int previous_valid;
- /* Index of the CU in the table of all CUs in the index file. */
- unsigned int previous_cu_index;
- /* Start address of the CU. */
- CORE_ADDR previous_cu_start;
-};
-
-/* Write an address entry to ADDR_VEC. */
-
-static void
-add_address_entry (struct objfile *objfile, data_buf &addr_vec,
- CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
-{
- CORE_ADDR baseaddr;
-
- baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
-
- addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start - baseaddr);
- addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, end - baseaddr);
- addr_vec.append_data (MAYBE_SWAP (cu_index));
-}
-
-/* Worker function for traversing an addrmap to build the address table. */
-
-static int
-add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
-{
- struct addrmap_index_data *data = (struct addrmap_index_data *) datap;
- struct partial_symtab *pst = (struct partial_symtab *) obj;
-
- if (data->previous_valid)
- add_address_entry (data->objfile, data->addr_vec,
- data->previous_cu_start, start_addr,
- data->previous_cu_index);
-
- data->previous_cu_start = start_addr;
- if (pst != NULL)
- {
- const auto it = data->cu_index_htab.find (pst);
- gdb_assert (it != data->cu_index_htab.cend ());
- data->previous_cu_index = it->second;
- data->previous_valid = 1;
- }
- else
- data->previous_valid = 0;
-
- return 0;
-}
-
-/* Write OBJFILE's address map to ADDR_VEC.
- CU_INDEX_HTAB is used to map addrmap entries to their CU indices
- in the index file. */
-
-static void
-write_address_map (struct objfile *objfile, data_buf &addr_vec,
- psym_index_map &cu_index_htab)
-{
- struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
-
- /* When writing the address table, we have to cope with the fact that
- the addrmap iterator only provides the start of a region; we have to
- wait until the next invocation to get the start of the next region. */
-
- addrmap_index_data.objfile = objfile;
- addrmap_index_data.previous_valid = 0;
-
- addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
- &addrmap_index_data);
-
- /* It's highly unlikely the last entry (end address = 0xff...ff)
- is valid, but we should still handle it.
- The end address is recorded as the start of the next region, but that
- doesn't work here. To cope we pass 0xff...ff, this is a rare situation
- anyway. */
- if (addrmap_index_data.previous_valid)
- add_address_entry (objfile, addr_vec,
- addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
- addrmap_index_data.previous_cu_index);
-}
-
-/* Return the symbol kind of PSYM. */
-
-static gdb_index_symbol_kind
-symbol_kind (struct partial_symbol *psym)
-{
- domain_enum domain = PSYMBOL_DOMAIN (psym);
- enum address_class aclass = PSYMBOL_CLASS (psym);
-
- switch (domain)
- {
- case VAR_DOMAIN:
- switch (aclass)
- {
- case LOC_BLOCK:
- return GDB_INDEX_SYMBOL_KIND_FUNCTION;
- case LOC_TYPEDEF:
- return GDB_INDEX_SYMBOL_KIND_TYPE;
- case LOC_COMPUTED:
- case LOC_CONST_BYTES:
- case LOC_OPTIMIZED_OUT:
- case LOC_STATIC:
- return GDB_INDEX_SYMBOL_KIND_VARIABLE;
- case LOC_CONST:
- /* Note: It's currently impossible to recognize psyms as enum values
- short of reading the type info. For now punt. */
- return GDB_INDEX_SYMBOL_KIND_VARIABLE;
- default:
- /* There are other LOC_FOO values that one might want to classify
- as variables, but dwarf2read.c doesn't currently use them. */
- return GDB_INDEX_SYMBOL_KIND_OTHER;
- }
- case STRUCT_DOMAIN:
- return GDB_INDEX_SYMBOL_KIND_TYPE;
- default:
- return GDB_INDEX_SYMBOL_KIND_OTHER;
- }
-}
-
-/* Add a list of partial symbols to SYMTAB. */
-
-static void
-write_psymbols (struct mapped_symtab *symtab,
- std::unordered_set<partial_symbol *> &psyms_seen,
- struct partial_symbol **psymp,
- int count,
- offset_type cu_index,
- int is_static)
-{
- for (; count-- > 0; ++psymp)
- {
- struct partial_symbol *psym = *psymp;
-
- if (SYMBOL_LANGUAGE (psym) == language_ada)
- error (_("Ada is not currently supported by the index"));
-
- /* Only add a given psymbol once. */
- if (psyms_seen.insert (psym).second)
- {
- gdb_index_symbol_kind kind = symbol_kind (psym);
-
- add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
- is_static, kind, cu_index);
- }
- }
-}
-
-/* A helper struct used when iterating over debug_types. */
-struct signatured_type_index_data
-{
- signatured_type_index_data (data_buf &types_list_,
- std::unordered_set<partial_symbol *> &psyms_seen_)
- : types_list (types_list_), psyms_seen (psyms_seen_)
- {}
-
- struct objfile *objfile;
- struct mapped_symtab *symtab;
- data_buf &types_list;
- std::unordered_set<partial_symbol *> &psyms_seen;
- int cu_index;
-};
-
-/* A helper function that writes a single signatured_type to an
- obstack. */
-
-static int
-write_one_signatured_type (void **slot, void *d)
-{
- struct signatured_type_index_data *info
- = (struct signatured_type_index_data *) d;
- struct signatured_type *entry = (struct signatured_type *) *slot;
- struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
-
- write_psymbols (info->symtab,
- info->psyms_seen,
- &info->objfile->global_psymbols[psymtab->globals_offset],
- psymtab->n_global_syms, info->cu_index,
- 0);
- write_psymbols (info->symtab,
- info->psyms_seen,
- &info->objfile->static_psymbols[psymtab->statics_offset],
- psymtab->n_static_syms, info->cu_index,
- 1);
-
- info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
- to_underlying (entry->per_cu.sect_off));
- info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
- to_underlying (entry->type_offset_in_tu));
- info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, entry->signature);
-
- ++info->cu_index;
-
- return 1;
-}
-
-/* Recurse into all "included" dependencies and count their symbols as
- if they appeared in this psymtab. */
-
-static void
-recursively_count_psymbols (struct partial_symtab *psymtab,
- size_t &psyms_seen)
-{
- for (int i = 0; i < psymtab->number_of_dependencies; ++i)
- if (psymtab->dependencies[i]->user != NULL)
- recursively_count_psymbols (psymtab->dependencies[i],
- psyms_seen);
-
- psyms_seen += psymtab->n_global_syms;
- psyms_seen += psymtab->n_static_syms;
-}
-
-/* Recurse into all "included" dependencies and write their symbols as
- if they appeared in this psymtab. */
-
-static void
-recursively_write_psymbols (struct objfile *objfile,
- struct partial_symtab *psymtab,
- struct mapped_symtab *symtab,
- std::unordered_set<partial_symbol *> &psyms_seen,
- offset_type cu_index)
-{
- int i;
-
- for (i = 0; i < psymtab->number_of_dependencies; ++i)
- if (psymtab->dependencies[i]->user != NULL)
- recursively_write_psymbols (objfile, psymtab->dependencies[i],
- symtab, psyms_seen, cu_index);
-
- write_psymbols (symtab,
- psyms_seen,
- &objfile->global_psymbols[psymtab->globals_offset],
- psymtab->n_global_syms, cu_index,
- 0);
- write_psymbols (symtab,
- psyms_seen,
- &objfile->static_psymbols[psymtab->statics_offset],
- psymtab->n_static_syms, cu_index,
- 1);
-}
-
-/* DWARF-5 .debug_names builder. */
-class debug_names
-{
-public:
- debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile, bool is_dwarf64,
- bfd_endian dwarf5_byte_order)
- : m_dwarf5_byte_order (dwarf5_byte_order),
- m_dwarf32 (dwarf5_byte_order),
- m_dwarf64 (dwarf5_byte_order),
- m_dwarf (is_dwarf64
- ? static_cast<dwarf &> (m_dwarf64)
- : static_cast<dwarf &> (m_dwarf32)),
- m_name_table_string_offs (m_dwarf.name_table_string_offs),
- m_name_table_entry_offs (m_dwarf.name_table_entry_offs),
- m_debugstrlookup (dwarf2_per_objfile)
- {}
-
- int dwarf5_offset_size () const
- {
- const bool dwarf5_is_dwarf64 = &m_dwarf == &m_dwarf64;
- return dwarf5_is_dwarf64 ? 8 : 4;
- }
-
- /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
- enum class unit_kind { cu, tu };
-
- /* Insert one symbol. */
- void insert (const partial_symbol *psym, int cu_index, bool is_static,
- unit_kind kind)
- {
- const int dwarf_tag = psymbol_tag (psym);
- if (dwarf_tag == 0)
- return;
- const char *const name = SYMBOL_SEARCH_NAME (psym);
- const auto insertpair
- = m_name_to_value_set.emplace (c_str_view (name),
- std::set<symbol_value> ());
- std::set<symbol_value> &value_set = insertpair.first->second;
- value_set.emplace (symbol_value (dwarf_tag, cu_index, is_static, kind));
- }
-
- /* Build all the tables. All symbols must be already inserted.
- This function does not call file_write, caller has to do it
- afterwards. */
- void build ()
- {
- /* Verify the build method has not be called twice. */
- gdb_assert (m_abbrev_table.empty ());
- const size_t name_count = m_name_to_value_set.size ();
- m_bucket_table.resize
- (std::pow (2, std::ceil (std::log2 (name_count * 4 / 3))));
- m_hash_table.reserve (name_count);
- m_name_table_string_offs.reserve (name_count);
- m_name_table_entry_offs.reserve (name_count);
-
- /* Map each hash of symbol to its name and value. */
- struct hash_it_pair
- {
- uint32_t hash;
- decltype (m_name_to_value_set)::const_iterator it;
- };
- std::vector<std::forward_list<hash_it_pair>> bucket_hash;
- bucket_hash.resize (m_bucket_table.size ());
- for (decltype (m_name_to_value_set)::const_iterator it
- = m_name_to_value_set.cbegin ();
- it != m_name_to_value_set.cend ();
- ++it)
- {
- const char *const name = it->first.c_str ();
- const uint32_t hash = dwarf5_djb_hash (name);
- hash_it_pair hashitpair;
- hashitpair.hash = hash;
- hashitpair.it = it;
- auto &slot = bucket_hash[hash % bucket_hash.size()];
- slot.push_front (std::move (hashitpair));
- }
- for (size_t bucket_ix = 0; bucket_ix < bucket_hash.size (); ++bucket_ix)
- {
- const std::forward_list<hash_it_pair> &hashitlist
- = bucket_hash[bucket_ix];
- if (hashitlist.empty ())
- continue;
- uint32_t &bucket_slot = m_bucket_table[bucket_ix];
- /* The hashes array is indexed starting at 1. */
- store_unsigned_integer (reinterpret_cast<gdb_byte *> (&bucket_slot),
- sizeof (bucket_slot), m_dwarf5_byte_order,
- m_hash_table.size () + 1);
- for (const hash_it_pair &hashitpair : hashitlist)
- {
- m_hash_table.push_back (0);
- store_unsigned_integer (reinterpret_cast<gdb_byte *>
- (&m_hash_table.back ()),
- sizeof (m_hash_table.back ()),
- m_dwarf5_byte_order, hashitpair.hash);
- const c_str_view &name = hashitpair.it->first;
- const std::set<symbol_value> &value_set = hashitpair.it->second;
- m_name_table_string_offs.push_back_reorder
- (m_debugstrlookup.lookup (name.c_str ()));
- m_name_table_entry_offs.push_back_reorder (m_entry_pool.size ());
- gdb_assert (!value_set.empty ());
- for (const symbol_value &value : value_set)
- {
- int &idx = m_indexkey_to_idx[index_key (value.dwarf_tag,
- value.is_static,
- value.kind)];
- if (idx == 0)
- {
- idx = m_idx_next++;
- m_abbrev_table.append_unsigned_leb128 (idx);
- m_abbrev_table.append_unsigned_leb128 (value.dwarf_tag);
- m_abbrev_table.append_unsigned_leb128
- (value.kind == unit_kind::cu ? DW_IDX_compile_unit
- : DW_IDX_type_unit);
- m_abbrev_table.append_unsigned_leb128 (DW_FORM_udata);
- m_abbrev_table.append_unsigned_leb128 (value.is_static
- ? DW_IDX_GNU_internal
- : DW_IDX_GNU_external);
- m_abbrev_table.append_unsigned_leb128 (DW_FORM_flag_present);
-
- /* Terminate attributes list. */
- m_abbrev_table.append_unsigned_leb128 (0);
- m_abbrev_table.append_unsigned_leb128 (0);
- }
-
- m_entry_pool.append_unsigned_leb128 (idx);
- m_entry_pool.append_unsigned_leb128 (value.cu_index);
- }
-
- /* Terminate the list of CUs. */
- m_entry_pool.append_unsigned_leb128 (0);
- }
- }
- gdb_assert (m_hash_table.size () == name_count);
-
- /* Terminate tags list. */
- m_abbrev_table.append_unsigned_leb128 (0);
- }
-
- /* Return .debug_names bucket count. This must be called only after
- calling the build method. */
- uint32_t bucket_count () const
- {
- /* Verify the build method has been already called. */
- gdb_assert (!m_abbrev_table.empty ());
- const uint32_t retval = m_bucket_table.size ();
-
- /* Check for overflow. */
- gdb_assert (retval == m_bucket_table.size ());
- return retval;
- }
-
- /* Return .debug_names names count. This must be called only after
- calling the build method. */
- uint32_t name_count () const
- {
- /* Verify the build method has been already called. */
- gdb_assert (!m_abbrev_table.empty ());
- const uint32_t retval = m_hash_table.size ();
-
- /* Check for overflow. */
- gdb_assert (retval == m_hash_table.size ());
- return retval;
- }
-
- /* Return number of bytes of .debug_names abbreviation table. This
- must be called only after calling the build method. */
- uint32_t abbrev_table_bytes () const
- {
- gdb_assert (!m_abbrev_table.empty ());
- return m_abbrev_table.size ();
- }
-
- /* Recurse into all "included" dependencies and store their symbols
- as if they appeared in this psymtab. */
- void recursively_write_psymbols
- (struct objfile *objfile,
- struct partial_symtab *psymtab,
- std::unordered_set<partial_symbol *> &psyms_seen,
- int cu_index)
- {
- for (int i = 0; i < psymtab->number_of_dependencies; ++i)
- if (psymtab->dependencies[i]->user != NULL)
- recursively_write_psymbols (objfile, psymtab->dependencies[i],
- psyms_seen, cu_index);
-
- write_psymbols (psyms_seen,
- &objfile->global_psymbols[psymtab->globals_offset],
- psymtab->n_global_syms, cu_index, false, unit_kind::cu);
- write_psymbols (psyms_seen,
- &objfile->static_psymbols[psymtab->statics_offset],
- psymtab->n_static_syms, cu_index, true, unit_kind::cu);
- }
-
- /* Return number of bytes the .debug_names section will have. This
- must be called only after calling the build method. */
- size_t bytes () const
- {
- /* Verify the build method has been already called. */
- gdb_assert (!m_abbrev_table.empty ());
- size_t expected_bytes = 0;
- expected_bytes += m_bucket_table.size () * sizeof (m_bucket_table[0]);
- expected_bytes += m_hash_table.size () * sizeof (m_hash_table[0]);
- expected_bytes += m_name_table_string_offs.bytes ();
- expected_bytes += m_name_table_entry_offs.bytes ();
- expected_bytes += m_abbrev_table.size ();
- expected_bytes += m_entry_pool.size ();
- return expected_bytes;
- }
-
- /* Write .debug_names to FILE_NAMES and .debug_str addition to
- FILE_STR. This must be called only after calling the build
- method. */
- void file_write (FILE *file_names, FILE *file_str) const
- {
- /* Verify the build method has been already called. */
- gdb_assert (!m_abbrev_table.empty ());
- ::file_write (file_names, m_bucket_table);
- ::file_write (file_names, m_hash_table);
- m_name_table_string_offs.file_write (file_names);
- m_name_table_entry_offs.file_write (file_names);
- m_abbrev_table.file_write (file_names);
- m_entry_pool.file_write (file_names);
- m_debugstrlookup.file_write (file_str);
- }
-
- /* A helper user data for write_one_signatured_type. */
- class write_one_signatured_type_data
- {
- public:
- write_one_signatured_type_data (debug_names &nametable_,
- signatured_type_index_data &&info_)
- : nametable (nametable_), info (std::move (info_))
- {}
- debug_names &nametable;
- struct signatured_type_index_data info;
- };
-
- /* A helper function to pass write_one_signatured_type to
- htab_traverse_noresize. */
- static int
- write_one_signatured_type (void **slot, void *d)
- {
- write_one_signatured_type_data *data = (write_one_signatured_type_data *) d;
- struct signatured_type_index_data *info = &data->info;
- struct signatured_type *entry = (struct signatured_type *) *slot;
-
- data->nametable.write_one_signatured_type (entry, info);
-
- return 1;
- }
-
-private:
-
- /* Storage for symbol names mapping them to their .debug_str section
- offsets. */
- class debug_str_lookup
- {
- public:
-
- /* Object costructor to be called for current DWARF2_PER_OBJFILE.
- All .debug_str section strings are automatically stored. */
- debug_str_lookup (struct dwarf2_per_objfile *dwarf2_per_objfile)
- : m_abfd (dwarf2_per_objfile->objfile->obfd),
- m_dwarf2_per_objfile (dwarf2_per_objfile)
- {
- dwarf2_read_section (dwarf2_per_objfile->objfile,
- &dwarf2_per_objfile->str);
- if (dwarf2_per_objfile->str.buffer == NULL)
- return;
- for (const gdb_byte *data = dwarf2_per_objfile->str.buffer;
- data < (dwarf2_per_objfile->str.buffer
- + dwarf2_per_objfile->str.size);)
- {
- const char *const s = reinterpret_cast<const char *> (data);
- const auto insertpair
- = m_str_table.emplace (c_str_view (s),
- data - dwarf2_per_objfile->str.buffer);
- if (!insertpair.second)
- complaint (&symfile_complaints,
- _("Duplicate string \"%s\" in "
- ".debug_str section [in module %s]"),
- s, bfd_get_filename (m_abfd));
- data += strlen (s) + 1;
- }
- }
-
- /* Return offset of symbol name S in the .debug_str section. Add
- such symbol to the section's end if it does not exist there
- yet. */
- size_t lookup (const char *s)
- {
- const auto it = m_str_table.find (c_str_view (s));
- if (it != m_str_table.end ())
- return it->second;
- const size_t offset = (m_dwarf2_per_objfile->str.size
- + m_str_add_buf.size ());
- m_str_table.emplace (c_str_view (s), offset);
- m_str_add_buf.append_cstr0 (s);
- return offset;
- }
-
- /* Append the end of the .debug_str section to FILE. */
- void file_write (FILE *file) const
- {
- m_str_add_buf.file_write (file);
- }
-
- private:
- std::unordered_map<c_str_view, size_t, c_str_view_hasher> m_str_table;
- bfd *const m_abfd;
- struct dwarf2_per_objfile *m_dwarf2_per_objfile;
-
- /* Data to add at the end of .debug_str for new needed symbol names. */
- data_buf m_str_add_buf;
- };
-
- /* Container to map used DWARF tags to their .debug_names abbreviation
- tags. */
- class index_key
- {
- public:
- index_key (int dwarf_tag_, bool is_static_, unit_kind kind_)
- : dwarf_tag (dwarf_tag_), is_static (is_static_), kind (kind_)
- {
- }
-
- bool
- operator== (const index_key &other) const
- {
- return (dwarf_tag == other.dwarf_tag && is_static == other.is_static
- && kind == other.kind);
- }
-
- const int dwarf_tag;
- const bool is_static;
- const unit_kind kind;
- };
-
- /* Provide std::unordered_map::hasher for index_key. */
- class index_key_hasher
- {
- public:
- size_t
- operator () (const index_key &key) const
- {
- return (std::hash<int>() (key.dwarf_tag) << 1) | key.is_static;
- }
- };
-
- /* Parameters of one symbol entry. */
- class symbol_value
- {
- public:
- const int dwarf_tag, cu_index;
- const bool is_static;
- const unit_kind kind;
-
- symbol_value (int dwarf_tag_, int cu_index_, bool is_static_,
- unit_kind kind_)
- : dwarf_tag (dwarf_tag_), cu_index (cu_index_), is_static (is_static_),
- kind (kind_)
- {}
-
- bool
- operator< (const symbol_value &other) const
- {
-#define X(n) \
- do \
- { \
- if (n < other.n) \
- return true; \
- if (n > other.n) \
- return false; \
- } \
- while (0)
- X (dwarf_tag);
- X (is_static);
- X (kind);
- X (cu_index);
-#undef X
- return false;
- }
- };
-
- /* Abstract base class to unify DWARF-32 and DWARF-64 name table
- output. */
- class offset_vec
- {
- protected:
- const bfd_endian dwarf5_byte_order;
- public:
- explicit offset_vec (bfd_endian dwarf5_byte_order_)
- : dwarf5_byte_order (dwarf5_byte_order_)
- {}
-
- /* Call std::vector::reserve for NELEM elements. */
- virtual void reserve (size_t nelem) = 0;
-
- /* Call std::vector::push_back with store_unsigned_integer byte
- reordering for ELEM. */
- virtual void push_back_reorder (size_t elem) = 0;
-
- /* Return expected output size in bytes. */
- virtual size_t bytes () const = 0;
-
- /* Write name table to FILE. */
- virtual void file_write (FILE *file) const = 0;
- };
-
- /* Template to unify DWARF-32 and DWARF-64 output. */
- template<typename OffsetSize>
- class offset_vec_tmpl : public offset_vec
- {
- public:
- explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_)
- : offset_vec (dwarf5_byte_order_)
- {}
-
- /* Implement offset_vec::reserve. */
- void reserve (size_t nelem) override
- {
- m_vec.reserve (nelem);
- }
-
- /* Implement offset_vec::push_back_reorder. */
- void push_back_reorder (size_t elem) override
- {
- m_vec.push_back (elem);
- /* Check for overflow. */
- gdb_assert (m_vec.back () == elem);
- store_unsigned_integer (reinterpret_cast<gdb_byte *> (&m_vec.back ()),
- sizeof (m_vec.back ()), dwarf5_byte_order, elem);
- }
-
- /* Implement offset_vec::bytes. */
- size_t bytes () const override
- {
- return m_vec.size () * sizeof (m_vec[0]);
- }
-
- /* Implement offset_vec::file_write. */
- void file_write (FILE *file) const override
- {
- ::file_write (file, m_vec);
- }
-
- private:
- std::vector<OffsetSize> m_vec;
- };
-
- /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
- respecting name table width. */
- class dwarf
- {
- public:
- offset_vec &name_table_string_offs, &name_table_entry_offs;
-
- dwarf (offset_vec &name_table_string_offs_,
- offset_vec &name_table_entry_offs_)
- : name_table_string_offs (name_table_string_offs_),
- name_table_entry_offs (name_table_entry_offs_)
- {
- }
- };
-
- /* Template to unify DWARF-32 and DWARF-64 .debug_names output
- respecting name table width. */
- template<typename OffsetSize>
- class dwarf_tmpl : public dwarf
- {
- public:
- explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_)
- : dwarf (m_name_table_string_offs, m_name_table_entry_offs),
- m_name_table_string_offs (dwarf5_byte_order_),
- m_name_table_entry_offs (dwarf5_byte_order_)
- {}
-
- private:
- offset_vec_tmpl<OffsetSize> m_name_table_string_offs;
- offset_vec_tmpl<OffsetSize> m_name_table_entry_offs;
- };
-
- /* Try to reconstruct original DWARF tag for given partial_symbol.
- This function is not DWARF-5 compliant but it is sufficient for
- GDB as a DWARF-5 index consumer. */
- static int psymbol_tag (const struct partial_symbol *psym)
- {
- domain_enum domain = PSYMBOL_DOMAIN (psym);
- enum address_class aclass = PSYMBOL_CLASS (psym);
-
- switch (domain)
- {
- case VAR_DOMAIN:
- switch (aclass)
- {
- case LOC_BLOCK:
- return DW_TAG_subprogram;
- case LOC_TYPEDEF:
- return DW_TAG_typedef;
- case LOC_COMPUTED:
- case LOC_CONST_BYTES:
- case LOC_OPTIMIZED_OUT:
- case LOC_STATIC:
- return DW_TAG_variable;
- case LOC_CONST:
- /* Note: It's currently impossible to recognize psyms as enum values
- short of reading the type info. For now punt. */
- return DW_TAG_variable;
- default:
- /* There are other LOC_FOO values that one might want to classify
- as variables, but dwarf2read.c doesn't currently use them. */
- return DW_TAG_variable;
- }
- case STRUCT_DOMAIN:
- return DW_TAG_structure_type;
- default:
- return 0;
- }
- }
-
- /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
- void write_psymbols (std::unordered_set<partial_symbol *> &psyms_seen,
- struct partial_symbol **psymp, int count, int cu_index,
- bool is_static, unit_kind kind)
- {
- for (; count-- > 0; ++psymp)
- {
- struct partial_symbol *psym = *psymp;
-
- if (SYMBOL_LANGUAGE (psym) == language_ada)
- error (_("Ada is not currently supported by the index"));
-
- /* Only add a given psymbol once. */
- if (psyms_seen.insert (psym).second)
- insert (psym, cu_index, is_static, kind);
- }
- }
-
- /* A helper function that writes a single signatured_type
- to a debug_names. */
- void
- write_one_signatured_type (struct signatured_type *entry,
- struct signatured_type_index_data *info)
- {
- struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
-
- write_psymbols (info->psyms_seen,
- &info->objfile->global_psymbols[psymtab->globals_offset],
- psymtab->n_global_syms, info->cu_index, false,
- unit_kind::tu);
- write_psymbols (info->psyms_seen,
- &info->objfile->static_psymbols[psymtab->statics_offset],
- psymtab->n_static_syms, info->cu_index, true,
- unit_kind::tu);
-
- info->types_list.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order,
- to_underlying (entry->per_cu.sect_off));
-
- ++info->cu_index;
- }
-
- /* Store value of each symbol. */
- std::unordered_map<c_str_view, std::set<symbol_value>, c_str_view_hasher>
- m_name_to_value_set;
-
- /* Tables of DWARF-5 .debug_names. They are in object file byte
- order. */
- std::vector<uint32_t> m_bucket_table;
- std::vector<uint32_t> m_hash_table;
-
- const bfd_endian m_dwarf5_byte_order;
- dwarf_tmpl<uint32_t> m_dwarf32;
- dwarf_tmpl<uint64_t> m_dwarf64;
- dwarf &m_dwarf;
- offset_vec &m_name_table_string_offs, &m_name_table_entry_offs;
- debug_str_lookup m_debugstrlookup;
-
- /* Map each used .debug_names abbreviation tag parameter to its
- index value. */
- std::unordered_map<index_key, int, index_key_hasher> m_indexkey_to_idx;
-
- /* Next unused .debug_names abbreviation tag for
- m_indexkey_to_idx. */
- int m_idx_next = 1;
-
- /* .debug_names abbreviation table. */
- data_buf m_abbrev_table;
-
- /* .debug_names entry pool. */
- data_buf m_entry_pool;
-};
-
-/* Return iff any of the needed offsets does not fit into 32-bit
- .debug_names section. */
-
-static bool
-check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile)
-{
- for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
- {
- 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))
- return true;
- }
- for (int i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
- {
- const signatured_type &sigtype = *dwarf2_per_objfile->all_type_units[i];
- 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;
- }
- return false;
-}
-
-/* The psyms_seen set is potentially going to be largish (~40k
- elements when indexing a -g3 build of GDB itself). Estimate the
- number of elements in order to avoid too many rehashes, which
- require rebuilding buckets and thus many trips to
- malloc/free. */
-
-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)
- {
- 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)
- recursively_count_psymbols (psymtab, psyms_count);
- }
- /* Generating an index for gdb itself shows a ratio of
- TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
- return psyms_count / 4;
-}
-
-/* Write new .gdb_index section for OBJFILE into OUT_FILE.
- Return how many bytes were expected to be written into OUT_FILE. */
-
-static size_t
-write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file)
-{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
- mapped_symtab symtab;
- data_buf cu_list;
-
- /* While we're scanning CU's create a table that maps a psymtab pointer
- (which is what addrmap records) to its index (which is what is recorded
- 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);
-
- /* 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
- all_comp_units, but only in their own hash table. */
-
- 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)
- {
- struct dwarf2_per_cu_data *per_cu
- = dwarf2_per_objfile->all_comp_units[i];
- struct partial_symtab *psymtab = per_cu->v.psymtab;
-
- /* CU of a shared file from 'dwz -m' may be unused by this main file.
- It may be referenced from a local scope but in such case it does not
- need to be present in .gdb_index. */
- if (psymtab == NULL)
- continue;
-
- if (psymtab->user == NULL)
- recursively_write_psymbols (objfile, psymtab, &symtab,
- psyms_seen, i);
-
- const auto insertpair = cu_index_htab.emplace (psymtab, i);
- gdb_assert (insertpair.second);
-
- cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
- to_underlying (per_cu->sect_off));
- cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length);
- }
-
- /* Dump the address map. */
- data_buf addr_vec;
- write_address_map (objfile, addr_vec, cu_index_htab);
-
- /* Write out the .debug_type entries, if any. */
- data_buf types_cu_list;
- if (dwarf2_per_objfile->signatured_types)
- {
- signatured_type_index_data sig_data (types_cu_list,
- psyms_seen);
-
- sig_data.objfile = objfile;
- sig_data.symtab = &symtab;
- sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
- htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
- write_one_signatured_type, &sig_data);
- }
-
- /* Now that we've processed all symbols we can shrink their cu_indices
- lists. */
- uniquify_cu_indices (&symtab);
-
- data_buf symtab_vec, constant_pool;
- write_hash_table (&symtab, symtab_vec, constant_pool);
-
- data_buf contents;
- const offset_type size_of_contents = 6 * sizeof (offset_type);
- offset_type total_len = size_of_contents;
-
- /* The version number. */
- contents.append_data (MAYBE_SWAP (8));
-
- /* The offset of the CU list from the start of the file. */
- contents.append_data (MAYBE_SWAP (total_len));
- total_len += cu_list.size ();
-
- /* The offset of the types CU list from the start of the file. */
- contents.append_data (MAYBE_SWAP (total_len));
- total_len += types_cu_list.size ();
-
- /* The offset of the address table from the start of the file. */
- contents.append_data (MAYBE_SWAP (total_len));
- total_len += addr_vec.size ();
-
- /* The offset of the symbol table from the start of the file. */
- contents.append_data (MAYBE_SWAP (total_len));
- total_len += symtab_vec.size ();
-
- /* The offset of the constant pool from the start of the file. */
- contents.append_data (MAYBE_SWAP (total_len));
- total_len += constant_pool.size ();
-
- gdb_assert (contents.size () == size_of_contents);
-
- contents.file_write (out_file);
- cu_list.file_write (out_file);
- types_cu_list.file_write (out_file);
- addr_vec.file_write (out_file);
- symtab_vec.file_write (out_file);
- constant_pool.file_write (out_file);
-
- return total_len;
-}
-
-/* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
-static const gdb_byte dwarf5_gdb_augmentation[] = { 'G', 'D', 'B', 0 };
-
-/* Write a new .debug_names section for OBJFILE into OUT_FILE, write
- needed addition to .debug_str section to OUT_FILE_STR. Return how
- many bytes were expected to be written into OUT_FILE. */
-
-static size_t
-write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
- FILE *out_file, FILE *out_file_str)
-{
- const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (dwarf2_per_objfile);
- struct objfile *objfile = dwarf2_per_objfile->objfile;
- const enum bfd_endian dwarf5_byte_order
- = gdbarch_byte_order (get_objfile_arch (objfile));
-
- /* 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
- all_comp_units, but only in their own hash table. */
- data_buf cu_list;
- debug_names nametable (dwarf2_per_objfile, dwarf5_is_dwarf64,
- 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)
- {
- const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
- partial_symtab *psymtab = per_cu->v.psymtab;
-
- /* CU of a shared file from 'dwz -m' may be unused by this main
- file. It may be referenced from a local scope but in such
- case it does not need to be present in .debug_names. */
- if (psymtab == NULL)
- continue;
-
- if (psymtab->user == NULL)
- nametable.recursively_write_psymbols (objfile, psymtab, psyms_seen, i);
-
- cu_list.append_uint (nametable.dwarf5_offset_size (), dwarf5_byte_order,
- to_underlying (per_cu->sect_off));
- }
-
- /* Write out the .debug_type entries, if any. */
- data_buf types_cu_list;
- if (dwarf2_per_objfile->signatured_types)
- {
- debug_names::write_one_signatured_type_data sig_data (nametable,
- signatured_type_index_data (types_cu_list, psyms_seen));
-
- sig_data.info.objfile = objfile;
- /* It is used only for gdb_index. */
- sig_data.info.symtab = nullptr;
- sig_data.info.cu_index = 0;
- htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
- debug_names::write_one_signatured_type,
- &sig_data);
- }
-
- nametable.build ();
-
- /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
-
- const offset_type bytes_of_header
- = ((dwarf5_is_dwarf64 ? 12 : 4)
- + 2 + 2 + 7 * 4
- + sizeof (dwarf5_gdb_augmentation));
- size_t expected_bytes = 0;
- expected_bytes += bytes_of_header;
- expected_bytes += cu_list.size ();
- expected_bytes += types_cu_list.size ();
- expected_bytes += nametable.bytes ();
- data_buf header;
-
- if (!dwarf5_is_dwarf64)
- {
- const uint64_t size64 = expected_bytes - 4;
- gdb_assert (size64 < 0xfffffff0);
- header.append_uint (4, dwarf5_byte_order, size64);
- }
- else
- {
- header.append_uint (4, dwarf5_byte_order, 0xffffffff);
- header.append_uint (8, dwarf5_byte_order, expected_bytes - 12);
- }
-
- /* The version number. */
- header.append_uint (2, dwarf5_byte_order, 5);
-
- /* Padding. */
- 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);
-
- /* 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);
-
- /* foreign_type_unit_count - The number of TUs in the foreign TU
- list. */
- header.append_uint (4, dwarf5_byte_order, 0);
-
- /* bucket_count - The number of hash buckets in the hash lookup
- table. */
- header.append_uint (4, dwarf5_byte_order, nametable.bucket_count ());
-
- /* name_count - The number of unique names in the index. */
- header.append_uint (4, dwarf5_byte_order, nametable.name_count ());
-
- /* abbrev_table_size - The size in bytes of the abbreviations
- table. */
- header.append_uint (4, dwarf5_byte_order, nametable.abbrev_table_bytes ());
-
- /* augmentation_string_size - The size in bytes of the augmentation
- string. This value is rounded up to a multiple of 4. */
- static_assert (sizeof (dwarf5_gdb_augmentation) % 4 == 0, "");
- header.append_uint (4, dwarf5_byte_order, sizeof (dwarf5_gdb_augmentation));
- header.append_data (dwarf5_gdb_augmentation);
-
- gdb_assert (header.size () == bytes_of_header);
-
- header.file_write (out_file);
- cu_list.file_write (out_file);
- types_cu_list.file_write (out_file);
- nametable.file_write (out_file, out_file_str);
-
- return expected_bytes;
-}
-
-/* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
- position is at the end of the file. */
-
-static void
-assert_file_size (FILE *file, const char *filename, size_t expected_size)
-{
- const auto file_size = ftell (file);
- if (file_size == -1)
- error (_("Can't get `%s' size"), filename);
- gdb_assert (file_size == expected_size);
-}
-
-/* Create an index file for OBJFILE in the directory DIR. */
-
-static void
-write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
- const char *dir,
- dw_index_kind index_kind)
-{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
-
- if (dwarf2_per_objfile->using_index)
- error (_("Cannot use an index to create the index"));
-
- if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
- error (_("Cannot make an index when the file has multiple .debug_types sections"));
-
- if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
- return;
-
- struct stat st;
- if (stat (objfile_name (objfile), &st) < 0)
- perror_with_name (objfile_name (objfile));
-
- std::string filename (std::string (dir) + SLASH_STRING
- + lbasename (objfile_name (objfile))
- + (index_kind == dw_index_kind::DEBUG_NAMES
- ? INDEX5_SUFFIX : INDEX4_SUFFIX));
-
- FILE *out_file = gdb_fopen_cloexec (filename.c_str (), "wb").release ();
- if (!out_file)
- error (_("Can't open `%s' for writing"), filename.c_str ());
-
- /* Order matters here; we want FILE to be closed before FILENAME is
- unlinked, because on MS-Windows one cannot delete a file that is
- still open. (Don't call anything here that might throw until
- file_closer is created.) */
- gdb::unlinker unlink_file (filename.c_str ());
- gdb_file_up close_out_file (out_file);
-
- if (index_kind == dw_index_kind::DEBUG_NAMES)
- {
- std::string filename_str (std::string (dir) + SLASH_STRING
- + lbasename (objfile_name (objfile))
- + DEBUG_STR_SUFFIX);
- FILE *out_file_str
- = gdb_fopen_cloexec (filename_str.c_str (), "wb").release ();
- if (!out_file_str)
- error (_("Can't open `%s' for writing"), filename_str.c_str ());
- gdb::unlinker unlink_file_str (filename_str.c_str ());
- gdb_file_up close_out_file_str (out_file_str);
-
- const size_t total_len
- = write_debug_names (dwarf2_per_objfile, out_file, out_file_str);
- assert_file_size (out_file, filename.c_str (), total_len);
-
- /* We want to keep the file .debug_str file too. */
- unlink_file_str.keep ();
- }
- else
- {
- const size_t total_len
- = write_gdbindex (dwarf2_per_objfile, out_file);
- assert_file_size (out_file, filename.c_str (), total_len);
- }
-
- /* We want to keep the file. */
- unlink_file.keep ();
-}
-
-/* Implementation of the `save gdb-index' command.
-
- Note that the .gdb_index file format used by this command is
- documented in the GDB manual. Any changes here must be documented
- there. */
-
-static void
-save_gdb_index_command (const char *arg, int from_tty)
-{
- struct objfile *objfile;
- const char dwarf5space[] = "-dwarf-5 ";
- dw_index_kind index_kind = dw_index_kind::GDB_INDEX;
-
- if (!arg)
- arg = "";
-
- arg = skip_spaces (arg);
- if (strncmp (arg, dwarf5space, strlen (dwarf5space)) == 0)
- {
- index_kind = dw_index_kind::DEBUG_NAMES;
- arg += strlen (dwarf5space);
- arg = skip_spaces (arg);
- }
-
- if (!*arg)
- error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
-
- ALL_OBJFILES (objfile)
- {
- struct stat st;
-
- /* If the objfile does not correspond to an actual file, skip it. */
- if (stat (objfile_name (objfile), &st) < 0)
- continue;
-
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
-
- if (dwarf2_per_objfile != NULL)
- {
- TRY
- {
- write_psymtabs_to_index (dwarf2_per_objfile, arg, index_kind);
- }
- CATCH (except, RETURN_MASK_ERROR)
- {
- exception_fprintf (gdb_stderr, except,
- _("Error while writing index for `%s': "),
- objfile_name (objfile));
- }
- END_CATCH
- }
-
- }
-}
-
-\f
-
-int dwarf_always_disassemble;
-
-static void
-show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
-{
- fprintf_filtered (file,
- _("Whether to always disassemble "
- "DWARF expressions is %s.\n"),
- value);
-}
-
-static void
-show_check_physname (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
-{
- fprintf_filtered (file,
- _("Whether to check \"physname\" is %s.\n"),
- value);
-}
-
-void
-_initialize_dwarf2_read (void)
-{
- struct cmd_list_element *c;
-
- dwarf2_objfile_data_key = register_objfile_data ();
-
- add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
-Set DWARF specific variables.\n\
-Configure DWARF variables such as the cache size"),
- &set_dwarf_cmdlist, "maintenance set dwarf ",
- 0/*allow-unknown*/, &maintenance_set_cmdlist);
-
- add_prefix_cmd ("dwarf", class_maintenance, show_dwarf_cmd, _("\
-Show DWARF specific variables\n\
-Show DWARF variables such as the cache size"),
- &show_dwarf_cmdlist, "maintenance show dwarf ",
- 0/*allow-unknown*/, &maintenance_show_cmdlist);
-
- add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
- &dwarf_max_cache_age, _("\
-Set the upper bound on the age of cached DWARF compilation units."), _("\
-Show the upper bound on the age of cached DWARF compilation units."), _("\
-A higher limit means that cached compilation units will be stored\n\
-in memory longer, and more total memory will be used. Zero disables\n\
-caching, which can slow down startup."),
- NULL,
- show_dwarf_max_cache_age,
- &set_dwarf_cmdlist,
- &show_dwarf_cmdlist);
-
- add_setshow_boolean_cmd ("always-disassemble", class_obscure,
- &dwarf_always_disassemble, _("\
-Set whether `info address' always disassembles DWARF expressions."), _("\
-Show whether `info address' always disassembles DWARF expressions."), _("\
-When enabled, DWARF expressions are always printed in an assembly-like\n\
-syntax. When disabled, expressions will be printed in a more\n\
-conversational style, when possible."),
- NULL,
- show_dwarf_always_disassemble,
- &set_dwarf_cmdlist,
- &show_dwarf_cmdlist);
-
- add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\
-Set debugging of the DWARF reader."), _("\
-Show debugging of the DWARF reader."), _("\
-When enabled (non-zero), debugging messages are printed during DWARF\n\
-reading and symtab expansion. A value of 1 (one) provides basic\n\
-information. A value greater than 1 provides more verbose information."),
- NULL,
- NULL,
- &setdebuglist, &showdebuglist);
-
- add_setshow_zuinteger_cmd ("dwarf-die", no_class, &dwarf_die_debug, _("\
-Set debugging of the DWARF DIE reader."), _("\
-Show debugging of the DWARF DIE reader."), _("\
-When enabled (non-zero), DIEs are dumped after they are read in.\n\
-The value is the maximum depth to print."),
- NULL,
- NULL,
- &setdebuglist, &showdebuglist);
-
- add_setshow_zuinteger_cmd ("dwarf-line", no_class, &dwarf_line_debug, _("\
-Set debugging of the dwarf line reader."), _("\
-Show debugging of the dwarf line reader."), _("\
-When enabled (non-zero), line number entries are dumped as they are read in.\n\
-A value of 1 (one) provides basic information.\n\
-A value greater than 1 provides more verbose information."),
- NULL,
- NULL,
- &setdebuglist, &showdebuglist);
-
- add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
-Set cross-checking of \"physname\" code against demangler."), _("\
-Show cross-checking of \"physname\" code against demangler."), _("\
-When enabled, GDB's internal \"physname\" code is checked against\n\
-the demangler."),
- NULL, show_check_physname,
- &setdebuglist, &showdebuglist);
+ add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
+Set cross-checking of \"physname\" code against demangler."), _("\
+Show cross-checking of \"physname\" code against demangler."), _("\
+When enabled, GDB's internal \"physname\" code is checked against\n\
+the demangler."),
+ NULL, show_check_physname,
+ &setdebuglist, &showdebuglist);
add_setshow_boolean_cmd ("use-deprecated-index-sections",
no_class, &use_deprecated_index_sections, _("\
NULL,
&setlist, &showlist);
- c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
- _("\
-Save a gdb-index file.\n\
-Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
-\n\
-No options create one file with .gdb-index extension for pre-DWARF-5\n\
-compatible .gdb_index section. With -dwarf-5 creates two files with\n\
-extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
- &save_cmdlist);
- set_cmd_completer (c, filename_completer);
-
dwarf2_locexpr_index = register_symbol_computed_impl (LOC_COMPUTED,
&dwarf2_locexpr_funcs);
dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED,