X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fdwarf2read.c;h=b2d6136e554eb0f54d61574534530c1f17d53705;hb=421d1616230a78449dc2f5abb60f03d38b96c3cf;hp=6a09d5568b3bf6963b0afa7de63819d672c63660;hpb=c1b5c1ebc938b6dc0277363b8c47d75b0b5a621f;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6a09d5568b..b2d6136e55 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1,6 +1,6 @@ /* DWARF 2 debugging format support for GDB. - Copyright (C) 1994-2019 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 @@ -1343,11 +1343,6 @@ struct dwarf_block #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. */ @@ -8907,7 +8902,7 @@ partial_die_parent_scope (struct partial_die_info *pdi, /* 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 partial_die_full_name (struct partial_die_info *pdi, struct dwarf2_cu *cu) { @@ -8933,7 +8928,7 @@ partial_die_full_name (struct partial_die_info *pdi, 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)); } } @@ -8941,7 +8936,8 @@ partial_die_full_name (struct partial_die_info *pdi, if (parent_scope == NULL) return NULL; else - return typename_concat (NULL, parent_scope, pdi->name, 0, cu); + return gdb::unique_xmalloc_ptr (typename_concat (NULL, parent_scope, + pdi->name, 0, cu)); } static void @@ -8954,13 +8950,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) 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)); - built_actual_name = partial_die_full_name (pdi, cu); + gdb::unique_xmalloc_ptr 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; @@ -9053,10 +9049,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) /* 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, built_actual_name != NULL, @@ -9106,10 +9099,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) 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. */ @@ -9134,8 +9124,6 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) default: break; } - - xfree (built_actual_name); } /* Read a partial die corresponding to a namespace; also, add a symbol @@ -9904,7 +9892,7 @@ compute_delayed_physnames (struct dwarf2_cu *cu) static void fixup_go_packaging (struct dwarf2_cu *cu) { - char *package_name = NULL; + gdb::unique_xmalloc_ptr package_name; struct pending *list; int i; @@ -9919,24 +9907,24 @@ fixup_go_packaging (struct dwarf2_cu *cu) if (sym->language () == language_go && SYMBOL_CLASS (sym) == LOC_BLOCK) { - char *this_package_name = go_symbol_package_name (sym); + gdb::unique_xmalloc_ptr 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) + 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 ()); } } } @@ -9946,14 +9934,14 @@ fixup_go_packaging (struct dwarf2_cu *cu) { struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; const char *saved_package_name - = obstack_strdup (&objfile->per_bfd->storage_obstack, 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; sym = allocate_symbol (objfile); - SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack); - SYMBOL_SET_NAMES (sym, saved_package_name, false, 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; @@ -9961,8 +9949,6 @@ fixup_go_packaging (struct dwarf2_cu *cu) SYMBOL_TYPE (sym) = type; add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ()); - - xfree (package_name); } } @@ -10878,7 +10864,7 @@ dwarf2_compute_name (const char *name, /* 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. */ @@ -10912,11 +10898,10 @@ dwarf2_compute_name (const char *name, prefix = determine_prefix (die, cu); if (*prefix != '\0') { - char *prefixed_name = typename_concat (NULL, prefix, name, - physname, cu); + gdb::unique_xmalloc_ptr 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); @@ -12958,16 +12943,15 @@ open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile, if (comp_dir != NULL) { - char *path_to_try = concat (comp_dir, SLASH_STRING, - file_name, (char *) NULL); + gdb::unique_xmalloc_ptr 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; } @@ -15472,6 +15456,25 @@ dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu) && (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 @@ -15584,6 +15587,16 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, 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 @@ -15823,6 +15836,52 @@ maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die, 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 the type's name and general properties; the members will not be @@ -15904,6 +15963,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu) 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 != nullptr) { @@ -16461,8 +16532,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) { struct die_info *child_die; struct symbol *sym; - struct field *fields = NULL; - int num_fields = 0; + std::vector fields; const char *name; child_die = die->child; @@ -16479,34 +16549,26 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) { 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)); - } + fields.emplace_back (); + struct field &field = fields.back (); - FIELD_NAME (fields[num_fields]) = sym->linkage_name (); - FIELD_TYPE (fields[num_fields]) = NULL; - SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); - FIELD_BITSIZE (fields[num_fields]) = 0; - - 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 ()); } } @@ -17479,8 +17541,10 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) 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 != nullptr) - 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 @@ -19256,16 +19320,15 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi, 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 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 = obstack_strdup (&objfile->per_bfd->storage_obstack, - actual_class_name); - xfree (actual_class_name); + actual_class_name.get ()); } break; } @@ -19330,24 +19393,22 @@ partial_die_info::fixup (struct dwarf2_cu *cu) || tag == DW_TAG_union_type) && linkage_name != NULL) { - char *demangled; - - demangled = gdb_demangle (linkage_name, DMGL_TYPES); - if (demangled) + gdb::unique_xmalloc_ptr 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 = obstack_strdup (&objfile->per_bfd->storage_obstack, base); - xfree (demangled); } } @@ -21627,7 +21688,7 @@ static void dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename, const char *dirname) { - char *copy = NULL; + gdb::unique_xmalloc_ptr copy; /* In order not to lose the line information directory, we concatenate it to the filename when it makes sense. @@ -21638,14 +21699,11 @@ dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename, 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 (); } cu->get_builder ()->start_subfile (filename); - - if (copy != NULL) - xfree (copy); } /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the @@ -21782,9 +21840,9 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, 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, false, 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. */ @@ -22613,7 +22671,7 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) 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; @@ -22639,33 +22697,32 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) if (linkage_name != NULL) { - char *actual_name - = language_class_name_from_physname (cu->language_defn, - linkage_name); - char *name = NULL; + gdb::unique_xmalloc_ptr 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] == ':') + && 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; } } @@ -22852,7 +22909,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu) || 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; } @@ -23026,8 +23083,6 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) 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; @@ -23035,18 +23090,17 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) /* 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 demangled + (gdb_demangle (DW_STRING (attr), DMGL_TYPES)); + const char *base; /* FIXME: we already did this for the partial symbol... */ DW_STRING (attr) = obstack_strdup (&objfile->per_bfd->storage_obstack, - demangled); + 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. */