#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. */
/* 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));
- 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;
/* 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,
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. */
default:
break;
}
-
- xfree (built_actual_name);
}
/* Read a partial die corresponding to a namespace; also, add a symbol
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);
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;
}
{
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]) = sym->linkage_name ();
- 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 (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
= obstack_strdup (&objfile->per_bfd->storage_obstack,
- actual_class_name);
- xfree (actual_class_name);
+ actual_class_name.get ());
}
break;
}
|| 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 = obstack_strdup (&objfile->per_bfd->storage_obstack, base);
- xfree (demangled);
}
}
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 ();
}
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
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] == ':')
+ && 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;
}
}
|| 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;
}
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)
= 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. */