/* DWARF 2 debugging format support for GDB.
- Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ Copyright (C) 1994-2017 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
#include "block.h"
#include "addrmap.h"
#include "typeprint.h"
-#include "jv-lang.h"
#include "psympriv.h"
#include <sys/stat.h>
#include "completer.h"
#include <fcntl.h>
#include <sys/types.h>
+#include <algorithm>
typedef struct symbol *symbolp;
DEF_VEC_P (symbolp);
unsigned int has_pc_info : 1;
unsigned int may_be_inlined : 1;
+ /* This DIE has been marked DW_AT_main_subprogram. */
+ unsigned int main_subprogram : 1;
+
/* Flag set if the SCOPE field of this structure has been
computed. */
unsigned int scope_set : 1;
static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
struct dwarf2_cu *, struct partial_symtab *);
-static int dwarf2_get_pc_bounds (struct die_info *,
- CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
- struct partial_symtab *);
+/* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
+ values. Keep the items ordered with increasing constraints compliance. */
+enum pc_bounds_kind
+{
+ /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
+ PC_BOUNDS_NOT_PRESENT,
+
+ /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
+ were present but they do not form a valid range of PC addresses. */
+ PC_BOUNDS_INVALID,
+
+ /* Discontiguous range was found - that is DW_AT_ranges was found. */
+ PC_BOUNDS_RANGES,
+
+ /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
+ PC_BOUNDS_HIGH_LOW,
+};
+
+static enum pc_bounds_kind dwarf2_get_pc_bounds (struct die_info *,
+ CORE_ADDR *, CORE_ADDR *,
+ struct dwarf2_cu *,
+ struct partial_symtab *);
static void get_scope_pc_bounds (struct die_info *,
CORE_ADDR *, CORE_ADDR *,
static struct dwz_file *
dwarf2_get_dwz_file (void)
{
- bfd *dwz_bfd;
char *data;
struct cleanup *cleanup;
const char *filename;
/* First try the file name given in the section. If that doesn't
work, try to use the build-id instead. */
- dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
+ gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename, gnutarget, -1));
if (dwz_bfd != NULL)
{
- if (!build_id_verify (dwz_bfd, buildid_len, buildid))
- {
- gdb_bfd_unref (dwz_bfd);
- dwz_bfd = NULL;
- }
+ if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+ dwz_bfd.release ();
}
if (dwz_bfd == NULL)
result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
struct dwz_file);
- result->dwz_bfd = dwz_bfd;
+ result->dwz_bfd = dwz_bfd.release ();
- bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
+ bfd_map_over_sections (result->dwz_bfd, locate_dwz_sections, result);
do_cleanups (cleanup);
- gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, dwz_bfd);
+ gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, result->dwz_bfd);
dwarf2_per_objfile->dwz_file = result;
return result;
}
int (*cmp) (const char *, const char *);
if (current_language->la_language == language_cplus
- || current_language->la_language == language_java
|| current_language->la_language == language_fortran
|| current_language->la_language == language_d)
{
if (file_matcher != NULL)
{
- struct cleanup *cleanup;
- htab_t visited_found, visited_not_found;
-
- visited_found = htab_create_alloc (10,
- htab_hash_pointer, htab_eq_pointer,
- NULL, xcalloc, xfree);
- cleanup = make_cleanup_htab_delete (visited_found);
- visited_not_found = htab_create_alloc (10,
- htab_hash_pointer, htab_eq_pointer,
- NULL, xcalloc, xfree);
- make_cleanup_htab_delete (visited_not_found);
+ htab_up visited_found (htab_create_alloc (10, htab_hash_pointer,
+ htab_eq_pointer,
+ NULL, xcalloc, xfree));
+ htab_up visited_not_found (htab_create_alloc (10, htab_hash_pointer,
+ htab_eq_pointer,
+ NULL, xcalloc, xfree));
/* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */
if (file_data == NULL)
continue;
- if (htab_find (visited_not_found, file_data) != NULL)
+ if (htab_find (visited_not_found.get (), file_data) != NULL)
continue;
- else if (htab_find (visited_found, file_data) != NULL)
+ else if (htab_find (visited_found.get (), file_data) != NULL)
{
per_cu->v.quick->mark = 1;
continue;
}
slot = htab_find_slot (per_cu->v.quick->mark
- ? visited_found
- : visited_not_found,
+ ? visited_found.get ()
+ : visited_not_found.get (),
file_data, INSERT);
*slot = file_data;
}
-
- do_cleanups (cleanup);
}
for (iter = 0; iter < index->symbol_table_slots; ++iter)
void *data, int need_fullname)
{
int i;
- struct cleanup *cleanup;
- htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
- NULL, xcalloc, xfree);
+ htab_up visited (htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
+ NULL, xcalloc, xfree));
- cleanup = make_cleanup_htab_delete (visited);
dw2_setup (objfile);
/* The rule is CUs specify all the files, including those used by
if (per_cu->v.quick->compunit_symtab)
{
- void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
+ void **slot = htab_find_slot (visited.get (),
+ per_cu->v.quick->file_names,
INSERT);
*slot = per_cu->v.quick->file_names;
if (file_data == NULL)
continue;
- slot = htab_find_slot (visited, file_data, INSERT);
+ slot = htab_find_slot (visited.get (), file_data, INSERT);
if (*slot)
{
/* Already visited. */
(*fun) (file_data->file_names[j], this_real_name, data);
}
}
-
- do_cleanups (cleanup);
}
static int
{
bfd *abfd = get_section_bfd_owner (section);
const gdb_byte *info_ptr;
- unsigned int length, initial_length_size, offset_size;
+ unsigned int initial_length_size, offset_size;
sect_offset abbrev_offset;
dwarf2_read_section (dwarf2_per_objfile->objfile, section);
info_ptr = section->buffer + offset.sect_off;
- length = read_initial_length (abfd, info_ptr, &initial_length_size);
+ read_initial_length (abfd, info_ptr, &initial_length_size);
offset_size = initial_length_size == 4 ? 4 : 8;
info_ptr += initial_length_size + 2 /*version*/;
abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size);
CORE_ADDR baseaddr;
CORE_ADDR best_lowpc = 0, best_highpc = 0;
struct partial_symtab *pst;
- int has_pc_info;
+ enum pc_bounds_kind cu_bounds_kind;
const char *filename;
struct process_psymtab_comp_unit_data *info
= (struct process_psymtab_comp_unit_data *) data;
/* Possibly set the default values of LOWPC and HIGHPC from
`DW_AT_ranges'. */
- has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
- &best_highpc, cu, pst);
- if (has_pc_info == 1 && best_lowpc < best_highpc)
+ 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,
first_die = load_partial_dies (reader, info_ptr, 1);
scan_partial_symbols (first_die, &lowpc, &highpc,
- ! has_pc_info, cu);
+ cu_bounds_kind <= PC_BOUNDS_INVALID, cu);
/* If we didn't find a lowpc, set it to highpc to avoid
complaints from `maint check'. */
/* If the compilation unit didn't have an explicit address range,
then use the information extracted from its child dies. */
- if (! has_pc_info)
+ if (cu_bounds_kind <= PC_BOUNDS_INVALID)
{
best_lowpc = lowpc;
best_highpc = highpc;
{
add_partial_symbol (pdi, cu);
}
+ if (cu->language == language_rust && pdi->has_children)
+ scan_partial_symbols (pdi->die_child, lowpc, highpc,
+ set_addrmap, cu);
break;
case DW_TAG_enumeration_type:
if (!pdi->is_declaration)
/* Functions used to compute the fully scoped name of a partial DIE.
Normally, this is simple. For C++, the parent DIE's fully scoped
- name is concatenated with "::" and the partial DIE's name. For
- Java, the same thing occurs except that "." is used instead of "::".
+ name is concatenated with "::" and the partial DIE's name.
Enumerators are an exception; they use the scope of their parent
enumeration type, i.e. the name of the enumeration type is not
prepended to the enumerator.
&objfile->static_psymbols,
addr, cu->language, objfile);
}
+
+ if (pdi->main_subprogram && actual_name != NULL)
+ set_objfile_main_name (objfile, actual_name, cu->language);
break;
case DW_TAG_constant:
{
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
STRUCT_DOMAIN, LOC_TYPEDEF,
- (cu->language == language_cplus
- || cu->language == language_java)
+ cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
0, cu->language, objfile);
add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name != NULL,
VAR_DOMAIN, LOC_CONST,
- (cu->language == language_cplus
- || cu->language == language_java)
+ cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
0, cu->language, objfile);
= (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack,
package_name,
strlen (package_name));
- struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
- saved_package_name, objfile);
+ struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
+ saved_package_name);
struct symbol *sym;
TYPE_TAG_NAME (type) = TYPE_NAME (type);
/* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
compute the physname for the object, which include a method's:
- - formal parameters (C++/Java),
+ - formal parameters (C++),
- receiver type (Go),
- - return type (Java).
The term "physname" is a bit confusing.
For C++, for example, it is the demangled name.
/* These are the only languages we know how to qualify names in. */
if (name != NULL
- && (cu->language == language_cplus || cu->language == language_java
- || cu->language == language_fortran || cu->language == language_d))
+ && (cu->language == language_cplus
+ || cu->language == language_fortran || cu->language == language_d
+ || cu->language == language_rust))
{
if (die_needs_namespace (die, cu))
{
long length;
const char *prefix;
struct ui_file *buf;
- char *intermediate_name;
const char *canonical_name = NULL;
prefix = determine_prefix (die, cu);
}
}
- /* For Java and C++ methods, append formal parameter type
+ /* For C++ methods, append formal parameter type
information, if PHYSNAME. */
if (physname && die->tag == DW_TAG_subprogram
- && (cu->language == language_cplus
- || cu->language == language_java))
+ && cu->language == language_cplus)
{
struct type *type = read_type_die (die, cu);
c_type_print_args (type, buf, 1, cu->language,
&type_print_raw_options);
- if (cu->language == language_java)
- {
- /* For java, we must append the return type to method
- names. */
- if (die->tag == DW_TAG_subprogram)
- java_print_type (TYPE_TARGET_TYPE (type), "", buf,
- 0, 0, &type_print_raw_options);
- }
- else if (cu->language == language_cplus)
+ if (cu->language == language_cplus)
{
/* Assume that an artificial first parameter is
"this", but do not crash if it is not. RealView
}
}
- intermediate_name = ui_file_xstrdup (buf, &length);
+ std::string intermediate_name = ui_file_as_string (buf);
ui_file_delete (buf);
if (cu->language == language_cplus)
canonical_name
- = dwarf2_canonicalize_name (intermediate_name, cu,
+ = dwarf2_canonicalize_name (intermediate_name.c_str (), cu,
&objfile->per_bfd->storage_obstack);
/* If we only computed INTERMEDIATE_NAME, or if
INTERMEDIATE_NAME is already canonical, then we need to
copy it to the appropriate obstack. */
- if (canonical_name == NULL || canonical_name == intermediate_name)
+ if (canonical_name == NULL || canonical_name == intermediate_name.c_str ())
name = ((const char *)
obstack_copy0 (&objfile->per_bfd->storage_obstack,
- intermediate_name,
- strlen (intermediate_name)));
+ intermediate_name.c_str (),
+ intermediate_name.length ()));
else
name = canonical_name;
-
- xfree (intermediate_name);
}
}
not have a name. NAME may either be from a previous call to
dwarf2_name or NULL.
- The output string will be canonicalized (if C++/Java). */
+ The output string will be canonicalized (if C++). */
static const char *
dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu)
allocated on the objfile_objstack or NULL if the DIE does not have a
name.
- The output string will be canonicalized (if C++/Java). */
+ The output string will be canonicalized (if C++). */
static const char *
dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
if (mangled == NULL)
mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu);
+ /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
+ See https://github.com/rust-lang/rust/issues/32925. */
+ if (cu->language == language_rust && mangled != NULL
+ && strchr (mangled, '{') != NULL)
+ mangled = NULL;
+
/* DW_AT_linkage_name is missing in some cases - depend on what GDB
has computed. */
if (mangled != NULL)
else
{
demangled = gdb_demangle (mangled,
- (DMGL_PARAMS | DMGL_ANSI
- | (cu->language == language_java
- ? DMGL_JAVA | DMGL_RET_POSTFIX
- : DMGL_RET_DROP)));
+ (DMGL_PARAMS | DMGL_ANSI | DMGL_RET_DROP));
}
if (demangled)
{
If unable to find/open the file, return NULL.
NOTE: This function is derived from symfile_bfd_open. */
-static bfd *
+static gdb_bfd_ref_ptr
try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd)
{
- bfd *sym_bfd;
int desc, flags;
char *absolute_name;
/* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
if (desc < 0)
return NULL;
- sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
+ gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name, gnutarget, desc));
xfree (absolute_name);
if (sym_bfd == NULL)
return NULL;
- bfd_set_cacheable (sym_bfd, 1);
+ bfd_set_cacheable (sym_bfd.get (), 1);
- if (!bfd_check_format (sym_bfd, bfd_object))
- {
- gdb_bfd_unref (sym_bfd); /* This also closes desc. */
- return NULL;
- }
+ if (!bfd_check_format (sym_bfd.get (), bfd_object))
+ return NULL;
/* Success. Record the bfd as having been included by the objfile's bfd.
This is important because things like demangled_names_hash lives in the
objfile's per_bfd space and may have references to things like symbol
names that live in the DWO/DWP file's per_bfd space. PR 16426. */
- gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, sym_bfd);
+ gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, sym_bfd.get ());
return sym_bfd;
}
Upon success, the canonicalized path of the file is stored in the bfd,
same as symfile_bfd_open. */
-static bfd *
+static gdb_bfd_ref_ptr
open_dwo_file (const char *file_name, const char *comp_dir)
{
- bfd *abfd;
-
if (IS_ABSOLUTE_PATH (file_name))
return try_open_dwop_file (file_name, 0 /*is_dwp*/, 0 /*search_cwd*/);
/* NOTE: If comp_dir is a relative path, this will also try the
search path, which seems useful. */
- abfd = try_open_dwop_file (path_to_try, 0 /*is_dwp*/, 1 /*search_cwd*/);
+ gdb_bfd_ref_ptr abfd (try_open_dwop_file (path_to_try, 0 /*is_dwp*/,
+ 1 /*search_cwd*/));
xfree (path_to_try);
if (abfd != NULL)
return abfd;
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwo_file *dwo_file;
- bfd *dbfd;
struct cleanup *cleanups;
- dbfd = open_dwo_file (dwo_name, comp_dir);
+ gdb_bfd_ref_ptr dbfd (open_dwo_file (dwo_name, comp_dir));
if (dbfd == NULL)
{
if (dwarf_read_debug)
dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
dwo_file->dwo_name = dwo_name;
dwo_file->comp_dir = comp_dir;
- dwo_file->dbfd = dbfd;
+ dwo_file->dbfd = dbfd.release ();
cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file);
- bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections);
+ bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections,
+ &dwo_file->sections);
dwo_file->cu = create_dwo_cu (dwo_file);
Upon success, the canonicalized path of the file is stored in the bfd,
same as symfile_bfd_open. */
-static bfd *
+static gdb_bfd_ref_ptr
open_dwp_file (const char *file_name)
{
- bfd *abfd;
-
- abfd = try_open_dwop_file (file_name, 1 /*is_dwp*/, 1 /*search_cwd*/);
+ gdb_bfd_ref_ptr abfd (try_open_dwop_file (file_name, 1 /*is_dwp*/,
+ 1 /*search_cwd*/));
if (abfd != NULL)
return abfd;
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwp_file *dwp_file;
char *dwp_name;
- bfd *dbfd;
struct cleanup *cleanups = make_cleanup (null_cleanup, 0);
/* Try to find first .dwp for the binary file before any symbolic links
dwp_name = xstrprintf ("%s.dwp", objfile->original_name);
make_cleanup (xfree, dwp_name);
- dbfd = open_dwp_file (dwp_name);
+ gdb_bfd_ref_ptr dbfd (open_dwp_file (dwp_name));
if (dbfd == NULL
&& strcmp (objfile->original_name, objfile_name (objfile)) != 0)
{
return NULL;
}
dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file);
- dwp_file->name = bfd_get_filename (dbfd);
- dwp_file->dbfd = dbfd;
+ dwp_file->name = bfd_get_filename (dbfd.get ());
+ dwp_file->dbfd = dbfd.release ();
do_cleanups (cleanups);
/* +1: section 0 is unused */
- dwp_file->num_sections = bfd_count_sections (dbfd) + 1;
+ dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1;
dwp_file->elf_sections =
OBSTACK_CALLOC (&objfile->objfile_obstack,
dwp_file->num_sections, asection *);
- bfd_map_over_sections (dbfd, dwarf2_locate_common_dwp_sections, dwp_file);
+ bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_common_dwp_sections,
+ dwp_file);
dwp_file->cus = create_dwp_hash_table (dwp_file, 0);
dwp_file->version = dwp_file->cus->version;
if (dwp_file->version == 2)
- bfd_map_over_sections (dbfd, dwarf2_locate_v2_dwp_sections, dwp_file);
+ bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_v2_dwp_sections,
+ dwp_file);
dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table (objfile);
dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table (objfile);
}
/* Ignore functions with missing or invalid low and high pc attributes. */
- if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
+ if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)
+ <= PC_BOUNDS_INVALID)
{
attr = dwarf2_attr (die, DW_AT_external, cu);
if (!attr || !DW_UNSND (attr))
/* For C++, set the block's scope. */
if ((cu->language == language_cplus
|| cu->language == language_fortran
- || cu->language == language_d)
+ || cu->language == language_d
+ || cu->language == language_rust)
&& cu->processing_has_namespace_info)
block_set_scope (block, determine_prefix (die, cu),
&objfile->objfile_obstack);
as multiple lexical blocks? Handling children in a sane way would
be nasty. Might be easier to properly extend generic blocks to
describe ranges. */
- if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
- return;
+ switch (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
+ {
+ case PC_BOUNDS_NOT_PRESENT:
+ /* DW_TAG_lexical_block has no attributes, process its children as if
+ there was no wrapping by that DW_TAG_lexical_block.
+ GCC does no longer produces such DWARF since GCC r224161. */
+ for (child_die = die->child;
+ child_die != NULL && child_die->tag;
+ child_die = sibling_die (child_die))
+ process_die (child_die, cu);
+ return;
+ case PC_BOUNDS_INVALID:
+ return;
+ }
lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
CORE_ADDR lowpc;
/* DW_AT_entry_pc should be preferred. */
- if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
+ if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)
+ <= PC_BOUNDS_INVALID)
complaint (&symfile_complaints,
_("DW_AT_GNU_call_site_target target DIE has invalid "
"low pc, for referencing DIE 0x%x [in module %s]"),
return 1;
}
-/* Get low and high pc attributes from a die. Return 1 if the attributes
- are present and valid, otherwise, return 0. Return -1 if the range is
- discontinuous, i.e. derived from DW_AT_ranges information. */
+/* Get low and high pc attributes from a die. See enum pc_bounds_kind
+ definition for the return value. *LOWPC and *HIGHPC are set iff
+ neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
-static int
+static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
CORE_ADDR *highpc, struct dwarf2_cu *cu,
struct partial_symtab *pst)
struct attribute *attr_high;
CORE_ADDR low = 0;
CORE_ADDR high = 0;
- int ret = 0;
+ enum pc_bounds_kind ret;
attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
if (attr_high)
}
else
/* Found high w/o low attribute. */
- return 0;
+ return PC_BOUNDS_INVALID;
/* Found consecutive range of addresses. */
- ret = 1;
+ ret = PC_BOUNDS_HIGH_LOW;
}
else
{
/* Value of the DW_AT_ranges attribute is the offset in the
.debug_ranges section. */
if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst))
- return 0;
+ return PC_BOUNDS_INVALID;
/* Found discontinuous range of addresses. */
- ret = -1;
+ ret = PC_BOUNDS_RANGES;
}
+ else
+ return PC_BOUNDS_NOT_PRESENT;
}
/* read_partial_die has also the strict LOW < HIGH requirement. */
if (high <= low)
- return 0;
+ return PC_BOUNDS_INVALID;
/* When using the GNU linker, .gnu.linkonce. sections are used to
eliminate duplicate copies of functions and vtables and such.
If this is a discarded function, mark the pc bounds as invalid,
so that GDB will ignore it. */
if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
- return 0;
+ return PC_BOUNDS_INVALID;
*lowpc = low;
if (highpc)
CORE_ADDR low, high;
struct die_info *child = die->child;
- if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
+ if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL) >= PC_BOUNDS_RANGES)
{
- *lowpc = min (*lowpc, low);
- *highpc = max (*highpc, high);
+ *lowpc = std::min (*lowpc, low);
+ *highpc = std::max (*highpc, high);
}
/* If the language does not allow nested subprograms (either inside
CORE_ADDR best_high = (CORE_ADDR) 0;
CORE_ADDR current_low, current_high;
- if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
+ if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)
+ >= PC_BOUNDS_RANGES)
{
best_low = current_low;
best_high = current_high;
if (current_low != ((CORE_ADDR) -1))
{
- best_low = min (best_low, current_low);
- best_high = max (best_high, current_high);
+ best_low = std::min (best_low, current_low);
+ best_high = std::max (best_high, current_high);
}
break;
default:
- bit_offset - FIELD_BITSIZE (*fp)));
}
}
+ attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
+ if (attr != NULL)
+ SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
+ + dwarf2_get_attr_constant_value (attr, 0)));
/* Get name of field. */
fieldname = dwarf2_name (die, cu);
fnp = &new_fnfield->fnfield;
/* Delay processing of the physname until later. */
- if (cu->language == language_cplus || cu->language == language_java)
+ if (cu->language == language_cplus)
{
add_to_method_list (type, i, flp->length - 1, fieldname,
die, cu);
static const char vptr[] = "_vptr";
static const char vtable[] = "vtable";
- /* Look for the C++ and Java forms of the vtable. */
- if ((cu->language == language_java
- && startswith (name, vtable))
- || (startswith (name, vptr)
- && is_cplus_marker (name[sizeof (vptr) - 1])))
+ /* Look for the C++ form of the vtable. */
+ if (startswith (name, vptr) && is_cplus_marker (name[sizeof (vptr) - 1]))
return 1;
return 0;
if (name != NULL)
{
if (cu->language == language_cplus
- || cu->language == language_java
- || cu->language == language_d)
+ || cu->language == language_d
+ || cu->language == language_rust)
{
const char *full_name = dwarf2_full_name (name, die, cu);
}
else if (child_die->tag == DW_TAG_subprogram)
{
- /* C++ member function. */
- dwarf2_add_member_fn (&fi, child_die, type, cu);
+ /* Rust doesn't have member functions in the C++ sense.
+ However, it does emit ordinary functions as children
+ of a struct DIE. */
+ if (cu->language == language_rust)
+ read_func_scope (child_die, cu);
+ else
+ {
+ /* C++ member function. */
+ dwarf2_add_member_fn (&fi, child_die, type, cu);
+ }
}
else if (child_die->tag == DW_TAG_inheritance)
{
}
do_cleanups (back_to);
-
- if (HAVE_CPLUS_STRUCT (type))
- TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
}
quirk_gcc_member_function_pointer (type, objfile);
previous_prefix, name, 0, cu);
/* Create the type. */
- type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
- objfile);
- TYPE_NAME (type) = name;
+ type = init_type (objfile, TYPE_CODE_NAMESPACE, 0, name);
TYPE_TAG_NAME (type) = TYPE_NAME (type);
return set_die_type (die, type, cu);
complaint (&symfile_complaints,
_("DW_TAG_module has no name, offset 0x%x"),
die->offset.sect_off);
- type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
+ type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
/* determine_prefix uses TYPE_TAG_NAME. */
TYPE_TAG_NAME (type) = TYPE_NAME (type);
if (attr)
TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
else
- {
- TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
-
- /* GCC/43521: In java, the formal parameter
- "this" is sometimes not marked with DW_AT_artificial. */
- if (cu->language == language_java)
- {
- const char *name = dwarf2_name (child_die, cu);
-
- if (name && !strcmp (name, "this"))
- TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
- }
- }
+ TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
arg_type = die_type (child_die, cu);
/* RealView does not mark THIS as const, which the testsuite
struct type *this_type, *target_type;
name = dwarf2_full_name (NULL, die, cu);
- this_type = init_type (TYPE_CODE_TYPEDEF, 0,
- TYPE_FLAG_TARGET_STUB, NULL, objfile);
- TYPE_NAME (this_type) = name;
+ this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, name);
+ TYPE_TARGET_STUB (this_type) = 1;
set_die_type (die, this_type, cu);
target_type = die_type (die, cu);
if (target_type != this_type)
return this_type;
}
+/* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
+ (which may be different from NAME) to the architecture back-end to allow
+ it to guess the correct format if necessary. */
+
+static struct type *
+dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
+ const char *name_hint)
+{
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ const struct floatformat **format;
+ struct type *type;
+
+ format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
+ if (format)
+ type = init_float_type (objfile, bits, name, format);
+ else
+ type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, name);
+
+ return type;
+}
+
/* Find a representation of a given base type and install
it in the TYPE field of the die. */
struct objfile *objfile = cu->objfile;
struct type *type;
struct attribute *attr;
- int encoding = 0, size = 0;
+ int encoding = 0, bits = 0;
const char *name;
- enum type_code code = TYPE_CODE_INT;
- int type_flags = 0;
- struct type *target_type = NULL;
attr = dwarf2_attr (die, DW_AT_encoding, cu);
if (attr)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr)
{
- size = DW_UNSND (attr);
+ bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
}
name = dwarf2_name (die, cu);
if (!name)
{
case DW_ATE_address:
/* Turn DW_ATE_address into a void * pointer. */
- code = TYPE_CODE_PTR;
- type_flags |= TYPE_FLAG_UNSIGNED;
- target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
+ type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+ type = init_pointer_type (objfile, bits, name, type);
break;
case DW_ATE_boolean:
- code = TYPE_CODE_BOOL;
- type_flags |= TYPE_FLAG_UNSIGNED;
+ type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- code = TYPE_CODE_COMPLEX;
- target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
+ type = dwarf2_init_float_type (objfile, bits / 2, NULL, name);
+ type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
- code = TYPE_CODE_DECFLOAT;
+ type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- code = TYPE_CODE_FLT;
+ type = dwarf2_init_float_type (objfile, bits, name, name);
break;
case DW_ATE_signed:
+ type = init_integer_type (objfile, bits, 0, name);
break;
case DW_ATE_unsigned:
- type_flags |= TYPE_FLAG_UNSIGNED;
if (cu->language == language_fortran
&& name
&& startswith (name, "character("))
- code = TYPE_CODE_CHAR;
+ type = init_character_type (objfile, bits, 1, name);
+ else
+ type = init_integer_type (objfile, bits, 1, name);
break;
case DW_ATE_signed_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_pascal
|| cu->language == language_fortran)
- code = TYPE_CODE_CHAR;
+ type = init_character_type (objfile, bits, 0, name);
+ else
+ type = init_integer_type (objfile, bits, 0, name);
break;
case DW_ATE_unsigned_char:
if (cu->language == language_ada || cu->language == language_m2
|| cu->language == language_pascal
- || cu->language == language_fortran)
- code = TYPE_CODE_CHAR;
- type_flags |= TYPE_FLAG_UNSIGNED;
+ || cu->language == language_fortran
+ || cu->language == language_rust)
+ type = init_character_type (objfile, bits, 1, name);
+ else
+ type = init_integer_type (objfile, bits, 1, name);
break;
case DW_ATE_UTF:
/* We just treat this as an integer and then recognize the
type by name elsewhere. */
+ type = init_integer_type (objfile, bits, 0, name);
break;
default:
complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
dwarf_type_encoding_name (encoding));
+ type = init_type (objfile, TYPE_CODE_ERROR,
+ bits / TARGET_CHAR_BIT, name);
break;
}
- type = init_type (code, size, type_flags, NULL, objfile);
- TYPE_NAME (type) = name;
- TYPE_TARGET_TYPE (type) = target_type;
-
if (name && strcmp (name, "char") == 0)
TYPE_NOSIGN (type) = 1;
low_default_is_valid = 1;
break;
case language_d:
- case language_java:
case language_objc:
+ case language_rust:
low.data.const_val = 0;
low_default_is_valid = (cu->header.version >= 4);
break;
/* For now, we only support the C meaning of an unspecified type: void. */
- type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
+ type = init_type (cu->objfile, TYPE_CODE_VOID, 0, NULL);
TYPE_NAME (type) = dwarf2_name (die, cu);
return set_die_type (die, type, cu);
else if (building_psymtab)
add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
VAR_DOMAIN, LOC_CONST,
- (cu->language == language_cplus
- || cu->language == language_java)
+ cu->language == language_cplus
? &objfile->global_psymbols
: &objfile->static_psymbols,
0, cu->language, objfile);
to describe functions' calling conventions.
However, because it's a necessary piece of information in
- Fortran, and because DW_CC_program is the only piece of debugging
- information whose definition refers to a 'main program' at all,
- several compilers have begun marking Fortran main programs with
- DW_CC_program --- even when those functions use the standard
- calling conventions.
-
- So until DWARF specifies a way to provide this information and
- compilers pick up the new representation, we'll support this
- practice. */
+ Fortran, and before DWARF 4 DW_CC_program was the only
+ piece of debugging information whose definition refers to
+ a 'main program' at all, several compilers marked Fortran
+ main programs with DW_CC_program --- even when those
+ functions use the standard calling conventions.
+
+ Although DWARF now specifies a way to provide this
+ information, we support this practice for backward
+ compatibility. */
if (DW_UNSND (&attr) == DW_CC_program
- && cu->language == language_fortran
- && part_die->name != NULL)
- set_objfile_main_name (objfile, part_die->name, language_fortran);
+ && cu->language == language_fortran)
+ part_die->main_subprogram = 1;
break;
case DW_AT_inline:
if (DW_UNSND (&attr) == DW_INL_inlined
}
break;
+ case DW_AT_main_subprogram:
+ part_die->main_subprogram = DW_UNSND (&attr);
+ break;
+
default:
break;
}
case DW_LANG_UPC:
cu->language = language_c;
break;
+ case DW_LANG_Java:
case DW_LANG_C_plus_plus:
case DW_LANG_C_plus_plus_11:
case DW_LANG_C_plus_plus_14:
case DW_LANG_Mips_Assembler:
cu->language = language_asm;
break;
- case DW_LANG_Java:
- cu->language = language_java;
- break;
case DW_LANG_Ada83:
case DW_LANG_Ada95:
cu->language = language_ada;
case DW_LANG_ObjC:
cu->language = language_objc;
break;
+ case DW_LANG_Rust:
+ case DW_LANG_Rust_old:
+ cu->language = language_rust;
+ break;
case DW_LANG_Cobol74:
case DW_LANG_Cobol85:
default:
SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
{
- /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
+ /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
really ever be static objects: otherwise, if you try
to, say, break of a class's method and you're in a file
which doesn't mention that class, it won't work unless
if (!suppress_add)
{
list_to_add = (cu->list_in_scope == &file_symbols
- && (cu->language == language_cplus
- || cu->language == language_java)
+ && cu->language == language_cplus
? &global_symbols : cu->list_in_scope);
/* The semantics of C++ state that "struct foo {
- ... }" also defines a typedef for "foo". A Java
- class declaration also defines a typedef for the
- class. */
+ ... }" also defines a typedef for "foo". */
if (cu->language == language_cplus
- || cu->language == language_java
|| cu->language == language_ada
- || cu->language == language_d)
+ || cu->language == language_d
+ || cu->language == language_rust)
{
/* The symbol's name is already allocated along
with this objfile, so we don't need to
DW_TAG_class_type, etc. block. */
list_to_add = (cu->list_in_scope == &file_symbols
- && (cu->language == language_cplus
- || cu->language == language_java)
+ && cu->language == language_cplus
? &global_symbols : cu->list_in_scope);
}
break;
message, strlen (message));
xfree (message);
- return init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
+ return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
}
/* Look up the type of DIE in CU using its type attribute ATTR.
struct type *parent_type;
char *retval;
- if (cu->language != language_cplus && cu->language != language_java
- && cu->language != language_fortran && cu->language != language_d)
+ if (cu->language != language_cplus
+ && cu->language != language_fortran && cu->language != language_d
+ && cu->language != language_rust)
return "";
retval = anonymous_struct_prefix (die, cu);
if (suffix == NULL || suffix[0] == '\0'
|| prefix == NULL || prefix[0] == '\0')
sep = "";
- else if (cu->language == language_java)
- sep = ".";
else if (cu->language == language_d)
{
/* For D, the 'main' function could be defined in any module, but it
{
if (name && cu->language == language_cplus)
{
- char *canon_name = cp_canonicalize_string (name);
+ std::string canon_name = cp_canonicalize_string (name);
- if (canon_name != NULL)
+ if (!canon_name.empty ())
{
- if (strcmp (canon_name, name) != 0)
- name = (const char *) obstack_copy0 (obstack, canon_name,
- strlen (canon_name));
- xfree (canon_name);
+ if (canon_name != name)
+ name = (const char *) obstack_copy0 (obstack,
+ canon_name.c_str (),
+ canon_name.length ());
}
}
return DW_STRING (attr);
return CP_ANONYMOUS_NAMESPACE_STR;
- case DW_TAG_subprogram:
- /* Java constructors will all be named "<init>", so return
- the class name when we see this special case. */
- if (cu->language == language_java
- && DW_STRING (attr) != NULL
- && strcmp (DW_STRING (attr), "<init>") == 0)
- {
- struct dwarf2_cu *spec_cu = cu;
- struct die_info *spec_die;
-
- /* GCJ will output '<init>' for Java constructor names.
- For this special case, return the name of the parent class. */
-
- /* GCJ may output subprogram DIEs with AT_specification set.
- If so, use the name of the specified DIE. */
- spec_die = die_specification (die, &spec_cu);
- if (spec_die != NULL)
- return dwarf2_name (spec_die, spec_cu);
-
- do
- {
- die = die->parent;
- if (die->tag == DW_TAG_class_type)
- return dwarf2_name (die, cu);
- }
- while (die->tag != DW_TAG_compile_unit
- && die->tag != DW_TAG_partial_unit);
- }
- break;
-
case DW_TAG_class_type:
case DW_TAG_interface_type:
case DW_TAG_structure_type:
break;
case DW_OP_GNU_push_tls_address:
+ case DW_OP_form_tls_address:
/* The top of the stack has the offset from the beginning
of the thread control block at which the variable is located. */
/* Nothing should follow this operator, so the top of stack would
if (!section_is_gnu)
{
unsigned int bytes_read;
- int constant;
- constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ /* This reads the constant, but since we don't recognize
+ any vendor extensions, we ignore it. */
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
read_direct_string (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
unsigned int offset_size = cu->header.offset_size;
const gdb_byte *opcode_definitions[256];
struct cleanup *cleanup;
- htab_t include_hash;
void **slot;
struct dwarf2_section_info *section;
const char *section_name;
command-line macro definitions/undefinitions. This flag is unset when we
reach the first DW_MACINFO_start_file entry. */
- include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
- NULL, xcalloc, xfree);
- cleanup = make_cleanup_htab_delete (include_hash);
+ htab_up include_hash (htab_create_alloc (1, htab_hash_pointer,
+ htab_eq_pointer,
+ NULL, xcalloc, xfree));
mac_ptr = section->buffer + offset;
- slot = htab_find_slot (include_hash, mac_ptr, INSERT);
+ slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
*slot = (void *) mac_ptr;
dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
current_file, lh, section,
- section_is_gnu, 0, offset_size, include_hash);
- do_cleanups (cleanup);
+ section_is_gnu, 0, offset_size,
+ include_hash.get ());
}
/* Check if the attribute's form is a DW_FORM_block*
struct mapped_symtab *symtab;
offset_type val, size_of_contents, total_len;
struct stat st;
- htab_t psyms_seen;
- htab_t cu_index_htab;
struct psymtab_cu_index_map *psymtab_cu_index_map;
if (dwarf2_per_objfile->using_index)
obstack_init (&types_cu_list);
make_cleanup_obstack_free (&types_cu_list);
- psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
- NULL, xcalloc, xfree);
- make_cleanup_htab_delete (psyms_seen);
+ htab_up psyms_seen (htab_create_alloc (100, htab_hash_pointer,
+ htab_eq_pointer,
+ NULL, xcalloc, xfree));
/* 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. */
- cu_index_htab = htab_create_alloc (100,
- hash_psymtab_cu_index,
- eq_psymtab_cu_index,
- NULL, xcalloc, xfree);
- make_cleanup_htab_delete (cu_index_htab);
+ htab_up cu_index_htab (htab_create_alloc (100,
+ hash_psymtab_cu_index,
+ eq_psymtab_cu_index,
+ NULL, xcalloc, xfree));
psymtab_cu_index_map = XNEWVEC (struct psymtab_cu_index_map,
dwarf2_per_objfile->n_comp_units);
make_cleanup (xfree, psymtab_cu_index_map);
continue;
if (psymtab->user == NULL)
- recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);
+ recursively_write_psymbols (objfile, psymtab, symtab,
+ psyms_seen.get (), i);
map = &psymtab_cu_index_map[i];
map->psymtab = psymtab;
map->cu_index = i;
- slot = htab_find_slot (cu_index_htab, map, INSERT);
+ slot = htab_find_slot (cu_index_htab.get (), map, INSERT);
gdb_assert (slot != NULL);
gdb_assert (*slot == NULL);
*slot = map;
}
/* Dump the address map. */
- write_address_map (objfile, &addr_obstack, cu_index_htab);
+ write_address_map (objfile, &addr_obstack, cu_index_htab.get ());
/* Write out the .debug_type entries, if any. */
if (dwarf2_per_objfile->signatured_types)
sig_data.objfile = objfile;
sig_data.symtab = symtab;
sig_data.types_list = &types_cu_list;
- sig_data.psyms_seen = psyms_seen;
+ sig_data.psyms_seen = psyms_seen.get ();
sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
write_one_signatured_type, &sig_data);