#include "bfd.h"
#include "libiberty.h"
#include "filenames.h"
+#include "bucomm.h"
#include "debug.h"
/* Global information we keep for debugging. A pointer to this
struct debug_handle
{
+ /* The bfd where we objalloc memory. */
+ bfd *abfd;
/* A linked list of compilation units. */
struct debug_unit *units;
/* The current compilation unit. */
/* Add an object to a namespace. */
static struct debug_name *
-debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
+debug_add_to_namespace (struct debug_handle *info,
struct debug_namespace **nsp, const char *name,
enum debug_object_kind kind,
enum debug_object_linkage linkage)
struct debug_name *n;
struct debug_namespace *ns;
- n = (struct debug_name *) xmalloc (sizeof *n);
- memset (n, 0, sizeof *n);
+ n = debug_xzalloc (info, sizeof (*n));
n->name = name;
n->kind = kind;
ns = *nsp;
if (ns == NULL)
{
- ns = (struct debug_namespace *) xmalloc (sizeof *ns);
- memset (ns, 0, sizeof *ns);
+ ns = debug_xzalloc (info, sizeof (*ns));
ns->tail = &ns->list;
/* Return a handle for debugging information. */
void *
-debug_init (void)
+debug_init (bfd *abfd)
{
struct debug_handle *ret;
- ret = (struct debug_handle *) xmalloc (sizeof *ret);
- memset (ret, 0, sizeof *ret);
- return (void *) ret;
+ ret = bfd_xalloc (abfd, sizeof (*ret));
+ memset (ret, 0, sizeof (*ret));
+ ret->abfd = abfd;
+ return ret;
+}
+
+void *
+debug_xalloc (void *handle, size_t size)
+{
+ struct debug_handle *info = (struct debug_handle *) handle;
+ return bfd_xalloc (info->abfd, size);
+}
+
+void *
+debug_xzalloc (void *handle, size_t size)
+{
+ struct debug_handle *info = (struct debug_handle *) handle;
+ void *mem = bfd_xalloc (info->abfd, size);
+ memset (mem, 0, size);
+ return mem;
}
/* Set the source filename. This implicitly starts a new compilation
if (name == NULL)
name = "";
- nfile = (struct debug_file *) xmalloc (sizeof *nfile);
- memset (nfile, 0, sizeof *nfile);
+ nfile = debug_xzalloc (info, sizeof (*nfile));
nfile->filename = name;
- nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
- memset (nunit, 0, sizeof *nunit);
+ nunit = debug_xzalloc (info, sizeof (*nunit));
nunit->files = nfile;
info->current_file = nfile;
include files in a single compilation unit. */
bool
-debug_start_source (void *handle, const char *name, bool *name_used)
+debug_start_source (void *handle, const char *name)
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *f, **pf;
}
}
- f = (struct debug_file *) xmalloc (sizeof *f);
- memset (f, 0, sizeof *f);
-
+ f = debug_xzalloc (info, sizeof (*f));
f->filename = name;
- *name_used = true;
for (pf = &info->current_file->next;
*pf != NULL;
return false;
}
- f = (struct debug_function *) xmalloc (sizeof *f);
- memset (f, 0, sizeof *f);
+ f = debug_xzalloc (info, sizeof (*f));
f->return_type = return_type;
- b = (struct debug_block *) xmalloc (sizeof *b);
- memset (b, 0, sizeof *b);
+ b = debug_xzalloc (info, sizeof (*b));
b->start = addr;
b->end = (bfd_vma) -1;
return false;
}
- p = (struct debug_parameter *) xmalloc (sizeof *p);
- memset (p, 0, sizeof *p);
+ p = debug_xzalloc (info, sizeof (*p));
p->name = name;
p->type = type;
return false;
}
- b = (struct debug_block *) xmalloc (sizeof *b);
- memset (b, 0, sizeof *b);
+ b = debug_xzalloc (info, sizeof (*b));
b->parent = info->current_block;
b->start = addr;
it in the right place, and make it the new current_lineno
structure. */
- l = (struct debug_lineno *) xmalloc (sizeof *l);
- memset (l, 0, sizeof *l);
+ l = debug_xzalloc (info, sizeof (*l));
l->file = info->current_file;
l->linenos[0] = lineno;
if (n == NULL)
return false;
- tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
- memset (tc, 0, sizeof *tc);
+ tc = debug_xzalloc (info, sizeof (*tc));
tc->type = type;
tc->val = val;
if (n == NULL)
return false;
- v = (struct debug_variable *) xmalloc (sizeof *v);
- memset (v, 0, sizeof *v);
+ v = debug_xzalloc (info, sizeof (*v));
v->kind = kind;
v->type = type;
/* Make a type with a given kind and size. */
static struct debug_type_s *
-debug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
+debug_make_type (struct debug_handle *info,
enum debug_type_kind kind, unsigned int size)
{
struct debug_type_s *t;
- t = (struct debug_type_s *) xmalloc (sizeof *t);
- memset (t, 0, sizeof *t);
+ t = debug_xzalloc (info, sizeof (*t));
t->kind = kind;
t->size = size;
if (t == NULL)
return DEBUG_TYPE_NULL;
- i = (struct debug_indirect_type *) xmalloc (sizeof *i);
- memset (i, 0, sizeof *i);
+ i = debug_xzalloc (info, sizeof (*i));
i->slot = slot;
i->tag = tag;
if (t == NULL)
return DEBUG_TYPE_NULL;
- c = (struct debug_class_type *) xmalloc (sizeof *c);
- memset (c, 0, sizeof *c);
+ c = debug_xzalloc (info, sizeof (*c));
c->fields = fields;
if (t == NULL)
return DEBUG_TYPE_NULL;
- c = (struct debug_class_type *) xmalloc (sizeof *c);
- memset (c, 0, sizeof *c);
+ c = debug_xzalloc (info, sizeof (*c));
c->fields = fields;
c->baseclasses = baseclasses;
if (t == NULL)
return DEBUG_TYPE_NULL;
- e = (struct debug_enum_type *) xmalloc (sizeof *e);
- memset (e, 0, sizeof *e);
+ e = debug_xzalloc (info, sizeof (*e));
e->names = names;
e->values = values;
if (t == NULL)
return DEBUG_TYPE_NULL;
- f = (struct debug_function_type *) xmalloc (sizeof *f);
- memset (f, 0, sizeof *f);
+ f = debug_xzalloc (info, sizeof (*f));
f->return_type = type;
f->arg_types = arg_types;
if (t == NULL)
return DEBUG_TYPE_NULL;
- r = (struct debug_range_type *) xmalloc (sizeof *r);
- memset (r, 0, sizeof *r);
+ r = debug_xzalloc (info, sizeof (*r));
r->type = type;
r->lower = lower;
if (t == NULL)
return DEBUG_TYPE_NULL;
- a = (struct debug_array_type *) xmalloc (sizeof *a);
- memset (a, 0, sizeof *a);
+ a = debug_xzalloc (info, sizeof (*a));
a->element_type = element_type;
a->range_type = range_type;
if (t == NULL)
return DEBUG_TYPE_NULL;
- s = (struct debug_set_type *) xmalloc (sizeof *s);
- memset (s, 0, sizeof *s);
+ s = debug_xzalloc (info, sizeof (*s));
s->type = type;
s->bitstringp = bitstringp;
if (t == NULL)
return DEBUG_TYPE_NULL;
- o = (struct debug_offset_type *) xmalloc (sizeof *o);
- memset (o, 0, sizeof *o);
+ o = debug_xzalloc (info, sizeof (*o));
o->base_type = base_type;
o->target_type = target_type;
if (t == NULL)
return DEBUG_TYPE_NULL;
- m = (struct debug_method_type *) xmalloc (sizeof *m);
- memset (m, 0, sizeof *m);
+ m = debug_xzalloc (info, sizeof (*m));
m->return_type = return_type;
m->domain_type = domain_type;
argument is the visibility of the base class. */
debug_baseclass
-debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
+debug_make_baseclass (void *handle, debug_type type,
bfd_vma bitpos, bool is_virtual,
enum debug_visibility visibility)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_baseclass_s *b;
- b = (struct debug_baseclass_s *) xmalloc (sizeof *b);
- memset (b, 0, sizeof *b);
+ b = debug_xzalloc (info, sizeof (*b));
b->type = type;
b->bitpos = bitpos;
of the field. */
debug_field
-debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
+debug_make_field (void *handle, const char *name,
debug_type type, bfd_vma bitpos, bfd_vma bitsize,
enum debug_visibility visibility)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_field_s *f;
- f = (struct debug_field_s *) xmalloc (sizeof *f);
- memset (f, 0, sizeof *f);
+ f = debug_xzalloc (info, sizeof (*f));
f->name = name;
f->type = type;
member. */
debug_field
-debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
+debug_make_static_member (void *handle, const char *name,
debug_type type, const char *physname,
enum debug_visibility visibility)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_field_s *f;
- f = (struct debug_field_s *) xmalloc (sizeof *f);
- memset (f, 0, sizeof *f);
+ f = debug_xzalloc (info, sizeof (*f));
f->name = name;
f->type = type;
argument is a NULL terminated array of method variants. */
debug_method
-debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
+debug_make_method (void *handle, const char *name,
debug_method_variant *variants)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_method_s *m;
- m = (struct debug_method_s *) xmalloc (sizeof *m);
- memset (m, 0, sizeof *m);
+ m = debug_xzalloc (info, sizeof (*m));
m->name = name;
m->variants = variants;
necessary? Could we just use debug_make_const_type? */
debug_method_variant
-debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
+debug_make_method_variant (void *handle,
const char *physname, debug_type type,
enum debug_visibility visibility,
bool constp, bool volatilep,
bfd_vma voffset, debug_type context)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_method_variant_s *m;
- m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
- memset (m, 0, sizeof *m);
+ m = debug_xzalloc (info, sizeof (*m));
m->physname = physname;
m->type = type;
since a static method can not also be virtual. */
debug_method_variant
-debug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
+debug_make_static_method_variant (void *handle,
const char *physname, debug_type type,
enum debug_visibility visibility,
bool constp, bool volatilep)
{
+ struct debug_handle *info = (struct debug_handle *) handle;
struct debug_method_variant_s *m;
- m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
- memset (m, 0, sizeof *m);
+ m = debug_xzalloc (info, sizeof (*m));
m->physname = physname;
m->type = type;
if (t == NULL)
return DEBUG_TYPE_NULL;
- n = (struct debug_named_type *) xmalloc (sizeof *n);
- memset (n, 0, sizeof *n);
+ n = debug_xzalloc (info, sizeof (*n));
n->type = type;
if (t == NULL)
return DEBUG_TYPE_NULL;
- n = (struct debug_named_type *) xmalloc (sizeof *n);
- memset (n, 0, sizeof *n);
+ n = debug_xzalloc (info, sizeof (*n));
n->type = type;
++info->class_id;
c->id = info->class_id;
- l = (struct debug_class_id *) xmalloc (sizeof *l);
- memset (l, 0, sizeof *l);
+ l = debug_xzalloc (info, sizeof (*l));
l->type = type;
l->tag = tag;
debug_type type;
};
-static char *savestring (const char *, int);
-
static void bad_stab (const char *);
static void warn_stab (const char *, const char *);
static bool parse_stab_string
bool *, const char *);
static debug_type parse_stab_array_type
(void *, struct stab_handle *, const char **, bool, const char *);
-static void push_bincl (struct stab_handle *, const char *, bfd_vma);
+static void push_bincl (void *, struct stab_handle *, const char *, bfd_vma);
static const char *pop_bincl (struct stab_handle *);
static bool find_excl (struct stab_handle *, const char *, bfd_vma);
static bool stab_record_variable
(void *, struct stab_handle *, const char *, debug_type,
enum debug_var_kind, bfd_vma);
static bool stab_emit_pending_vars (void *, struct stab_handle *);
-static debug_type *stab_find_slot (struct stab_handle *, const int *);
+static debug_type *stab_find_slot (void *, struct stab_handle *, const int *);
static debug_type stab_find_type (void *, struct stab_handle *, const int *);
static bool stab_record_type
(void *, struct stab_handle *, const int *, debug_type);
/* Save a string in memory. */
static char *
-savestring (const char *start, int len)
+savestring (void *dhandle, const char *start, size_t len)
{
char *ret;
- ret = (char *) xmalloc (len + 1);
+ ret = debug_xalloc (dhandle, len + 1);
memcpy (ret, start, len);
ret[len] = '\0';
return ret;
{
struct stab_handle *ret;
- ret = (struct stab_handle *) xmalloc (sizeof *ret);
- memset (ret, 0, sizeof *ret);
+ ret = xmalloc (sizeof (*ret));
+ memset (ret, 0, sizeof (*ret));
ret->abfd = abfd;
ret->sections = sections;
ret->syms = syms;
ret->symcount = symcount;
ret->files = 1;
- ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
+ ret->file_types = xmalloc (sizeof (*ret->file_types));
ret->file_types[0] = NULL;
- ret->function_end = (bfd_vma) -1;
- return (void *) ret;
+ ret->function_end = -1;
+ return ret;
}
/* When we have processed all the stabs information, we need to go
through and fill in all the undefined tags. */
bool
-finish_stab (void *dhandle, void *handle)
+finish_stab (void *dhandle, void *handle, bool emit)
{
struct stab_handle *info = (struct stab_handle *) handle;
struct stab_tag *st;
+ bool ret = true;
- if (info->within_function)
+ if (emit && info->within_function)
{
if (! stab_emit_pending_vars (dhandle, info)
|| ! debug_end_function (dhandle, info->function_end))
- return false;
- info->within_function = false;
- info->function_end = (bfd_vma) -1;
+ ret = false;
}
- for (st = info->tags; st != NULL; st = st->next)
- {
- enum debug_type_kind kind;
+ if (emit && ret)
+ for (st = info->tags; st != NULL; st = st->next)
+ {
+ enum debug_type_kind kind;
- kind = st->kind;
- if (kind == DEBUG_KIND_ILLEGAL)
- kind = DEBUG_KIND_STRUCT;
- st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
- if (st->slot == DEBUG_TYPE_NULL)
- return false;
- }
+ kind = st->kind;
+ if (kind == DEBUG_KIND_ILLEGAL)
+ kind = DEBUG_KIND_STRUCT;
+ st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
+ if (st->slot == DEBUG_TYPE_NULL)
+ {
+ ret = false;
+ break;
+ }
+ }
- return true;
+ free (info->file_types);
+ free (info->so_string);
+ free (info);
+ return ret;
}
/* Handle a single stabs symbol. */
bool
parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
- const char *string, bool *string_used)
+ const char *string)
{
const char * string_end;
struct stab_handle *info = (struct stab_handle *) handle;
+ char *copy;
+ size_t len;
- *string_used = false;
/* gcc will emit two N_SO strings per compilation unit, one for the
directory name and one for the file name. We just collect N_SO
strings as we see them, and start the new compilation unit when
if (info->so_string != NULL
&& (type != N_SO || *string == '\0' || value != info->so_value))
{
- if (! debug_set_filename (dhandle, info->so_string))
+ len = strlen (info->so_string) + 1;
+ copy = debug_xalloc (dhandle, len);
+ memcpy (copy, info->so_string, len);
+ if (! debug_set_filename (dhandle, copy))
return false;
- info->main_filename = info->so_string;
+ info->main_filename = copy;
+
+ free (info->so_string);
+ info->so_string = NULL;
info->gcc_compiled = 0;
info->n_opt_found = false;
can only free the file_types array, not the stab_types
list entries due to the use of debug_make_indirect_type. */
info->files = 1;
- info->file_types = ((struct stab_types **)
- xrealloc (info->file_types, sizeof *info->file_types));
+ info->file_types = xrealloc (info->file_types, sizeof (*info->file_types));
info->file_types[0] = NULL;
- info->so_string = NULL;
/* Now process whatever type we just got. */
}
case N_SOL:
/* Start an include file. */
- if (! debug_start_source (dhandle, string, string_used))
+ len = strlen (string) + 1;
+ copy = debug_xalloc (dhandle, len);
+ memcpy (copy, string, len);
+ if (! debug_start_source (dhandle, copy))
return false;
break;
case N_BINCL:
/* Start an include file which may be replaced. */
- *string_used = true;
- push_bincl (info, string, value);
- if (! debug_start_source (dhandle, string, string_used))
+ len = strlen (string) + 1;
+ copy = debug_xalloc (dhandle, len);
+ memcpy (copy, string, len);
+ push_bincl (dhandle, info, copy, value);
+ if (! debug_start_source (dhandle, copy))
return false;
break;
case N_EINCL:
/* End an N_BINCL include. */
- string = pop_bincl (info);
- if (! debug_start_source (dhandle, string, string_used))
- {
- free ((char *) string);
- return false;
- }
- if (!*string_used)
- free ((char *) string);
- *string_used = false;
+ if (! debug_start_source (dhandle, pop_bincl (info)))
+ return false;
break;
case N_EXCL:
if (p == string || (string[0] == ' ' && p == string + 1))
name = NULL;
else
- name = savestring (string, p - string);
+ name = savestring (dhandle, string, p - string);
}
++p;
the stabs information records both i and j as having the same
type. This could be fixed by patching the compiler. */
if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
- *slotp = stab_find_slot (info, typenums);
+ *slotp = stab_find_slot (dhandle, info, typenums);
/* Type is being defined here. */
/* Skip the '='. */
{
debug_type domain;
debug_type return_type;
- debug_type *args;
+ debug_type *args, *xargs;
unsigned int n;
unsigned int alloc;
bool varargs;
return DEBUG_TYPE_NULL;
alloc = 10;
- args = (debug_type *) xmalloc (alloc * sizeof *args);
+ args = xmalloc (alloc * sizeof (*args));
n = 0;
while (**pp != ';')
{
if (**pp != ',')
{
bad_stab (orig);
+ free (args);
return DEBUG_TYPE_NULL;
}
++*pp;
if (n + 1 >= alloc)
{
alloc += 10;
- args = ((debug_type *)
- xrealloc (args, alloc * sizeof *args));
+ args = xrealloc (args, alloc * sizeof (*args));
}
args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
pp, (debug_type **) NULL, p_end);
if (args[n] == DEBUG_TYPE_NULL)
- return DEBUG_TYPE_NULL;
+ {
+ free (args);
+ return DEBUG_TYPE_NULL;
+ }
++n;
}
++*pp;
}
args[n] = DEBUG_TYPE_NULL;
+ xargs = debug_xalloc (dhandle, (n + 1) * sizeof (*args));
+ memcpy (xargs, args, (n + 1) * sizeof (*args));
+ free (args);
- dtype = debug_make_method_type (dhandle, return_type, domain, args,
+ dtype = debug_make_method_type (dhandle, return_type, domain, xargs,
varargs);
}
break;
parse_stab_enum_type (void *dhandle, const char **pp, const char * p_end)
{
const char *orig;
- const char **names;
- bfd_signed_vma *values;
+ const char **names, **xnames;
+ bfd_signed_vma *values, *xvalues;
unsigned int n;
unsigned int alloc;
The input syntax is NAME:VALUE,NAME:VALUE, and so on.
A semicolon or comma instead of a NAME means the end. */
alloc = 10;
- names = (const char **) xmalloc (alloc * sizeof *names);
- values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
+ names = xmalloc (alloc * sizeof (*names));
+ values = xmalloc (alloc * sizeof (*values));
n = 0;
while (**pp != '\0' && **pp != ';' && **pp != ',')
{
return DEBUG_TYPE_NULL;
}
- name = savestring (*pp, p - *pp);
+ name = savestring (dhandle, *pp, p - *pp);
*pp = p + 1;
val = (bfd_signed_vma) parse_number (pp, (bool *) NULL, p_end);
if (**pp != ',')
{
bad_stab (orig);
- free (name);
free (names);
free (values);
return DEBUG_TYPE_NULL;
if (n + 1 >= alloc)
{
alloc += 10;
- names = ((const char **)
- xrealloc (names, alloc * sizeof *names));
- values = ((bfd_signed_vma *)
- xrealloc (values, alloc * sizeof *values));
+ names = xrealloc (names, alloc * sizeof (*names));
+ values = xrealloc (values, alloc * sizeof (*values));
}
names[n] = name;
names[n] = NULL;
values[n] = 0;
+ xnames = debug_xalloc (dhandle, (n + 1) * sizeof (*names));
+ memcpy (xnames, names, (n + 1) * sizeof (*names));
+ free (names);
+ xvalues = debug_xalloc (dhandle, (n + 1) * sizeof (*names));
+ memcpy (xvalues, values, (n + 1) * sizeof (*names));
+ free (values);
if (**pp == ';')
++*pp;
- return debug_make_enum_type (dhandle, names, values);
+ return debug_make_enum_type (dhandle, xnames, xvalues);
}
/* Read the description of a structure (or union type) and return an object
|| ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods, p_end)
|| ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
&ownvptr, p_end))
- {
- free (fields);
- return DEBUG_TYPE_NULL;
- }
+ return DEBUG_TYPE_NULL;
if (! statics
&& baseclasses == NULL
}
++*pp;
- classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
+ classes = debug_xalloc (dhandle, (c + 1) * sizeof (*classes));
for (i = 0; i < c; i++)
{
{
const char *orig;
const char *p;
- debug_field *fields;
+ debug_field *fields, *xfields;
unsigned int c;
unsigned int alloc;
c = 0;
alloc = 10;
- fields = (debug_field *) xmalloc (alloc * sizeof *fields);
+ fields = xmalloc (alloc * sizeof (*fields));
while (**pp != ';')
{
/* FIXME: gdb checks os9k_stabs here. */
if (c + 1 >= alloc)
{
alloc += 10;
- fields = ((debug_field *)
- xrealloc (fields, alloc * sizeof *fields));
+ fields = xrealloc (fields, alloc * sizeof (*fields));
}
/* If it starts with CPLUS_MARKER it is a special abbreviation,
}
fields[c] = DEBUG_FIELD_NULL;
+ xfields = debug_xalloc (dhandle, (c + 1) * sizeof (*fields));
+ memcpy (xfields, fields, (c + 1) * sizeof (*fields));
+ free (fields);
- *retp = fields;
+ *retp = xfields;
return true;
}
const char *type_name;
debug_type type;
bfd_vma bitpos;
+ size_t len;
*retp = DEBUG_FIELD_NULL;
warn_stab (orig, _("unnamed $vb type"));
type_name = "FOO";
}
- name = concat ("_vb$", type_name, (const char *) NULL);
+ len = strlen (type_name);
+ name = debug_xalloc (dhandle, len + sizeof ("_vb$"));
+ memcpy ((char *) name, "_vb$", sizeof ("_vb$") - 1);
+ memcpy ((char *) name + sizeof ("_vb$") - 1, type_name, len + 1);
break;
default:
warn_stab (orig, _("unrecognized C++ abbreviation"));
/* FIXME: gdb checks ARM_DEMANGLING here. */
- name = savestring (*pp, p - *pp);
+ name = savestring (dhandle, *pp, p - *pp);
*pp = p + 1;
type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
(debug_type **) NULL, p_end);
if (type == DEBUG_TYPE_NULL)
- {
- free (name);
- return false;
- }
+ return false;
if (**pp == ':')
{
if (p == NULL)
{
bad_stab (orig);
- free (name);
return false;
}
- varname = savestring (*pp, p - *pp);
+ varname = savestring (dhandle, *pp, p - *pp);
*pp = p + 1;
if (**pp != ',')
{
bad_stab (orig);
- free (name);
return false;
}
++*pp;
if (**pp != ',')
{
bad_stab (orig);
- free (name);
return false;
}
++*pp;
if (**pp != ';')
{
bad_stab (orig);
- free (name);
return false;
}
++*pp;
const char * p_end)
{
const char *orig;
- debug_method *methods;
+ debug_method *methods, *xmethods;
unsigned int c;
unsigned int alloc;
char *name = NULL;
- debug_method_variant *variants = NULL;
+ debug_method_variant *variants = NULL, *xvariants;
char *argtypes = NULL;
*retp = NULL;
/* FIXME: Some systems use something other than '$' here. */
if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
{
- name = savestring (*pp, p - *pp);
+ name = savestring (dhandle, *pp, p - *pp);
*pp = p + 2;
}
else
bad_stab (orig);
goto fail;
}
- name = savestring (*pp, p - *pp);
+ name = savestring (dhandle, *pp, p - *pp);
*pp = p + 1;
}
allocvars = 10;
- variants = ((debug_method_variant *)
- xmalloc (allocvars * sizeof *variants));
+ variants = xmalloc (allocvars * sizeof (*variants));
cvars = 0;
look_ahead_type = DEBUG_TYPE_NULL;
&& debug_get_parameter_types (dhandle, type, &varargs) == NULL)
stub = true;
- argtypes = savestring (*pp, p - *pp);
+ argtypes = savestring (dhandle, *pp, p - *pp);
*pp = p + 1;
switch (**pp)
if (cvars + 1 >= allocvars)
{
allocvars += 10;
- variants = ((debug_method_variant *)
- xrealloc (variants,
- allocvars * sizeof *variants));
+ variants = xrealloc (variants, allocvars * sizeof (*variants));
}
if (! staticp)
while (**pp != ';' && **pp != '\0');
variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
+ xvariants = debug_xalloc (dhandle, (cvars + 1) * sizeof (*variants));
+ memcpy (xvariants, variants, (cvars + 1) * sizeof (*variants));
+ free (variants);
if (**pp != '\0')
++*pp;
if (c + 1 >= alloc)
{
alloc += 10;
- methods = ((debug_method *)
- xrealloc (methods, alloc * sizeof *methods));
+ methods = xrealloc (methods, alloc * sizeof (*methods));
}
- methods[c] = debug_make_method (dhandle, name, variants);
+ methods[c] = debug_make_method (dhandle, name, xvariants);
++c;
}
+ xmethods = methods;
if (methods != NULL)
- methods[c] = DEBUG_METHOD_NULL;
+ {
+ methods[c] = DEBUG_METHOD_NULL;
+ xmethods = debug_xalloc (dhandle, (c + 1) * sizeof (*methods));
+ memcpy (xmethods, methods, (c + 1) * sizeof (*methods));
+ free (methods);
+ }
- *retp = methods;
+ *retp = xmethods;
return true;
fail:
- free (name);
free (variants);
- free (argtypes);
+ free (methods);
return false;
}
return DEBUG_TYPE_NULL;
}
- physname = (char *) xmalloc (mangled_name_len);
+ physname = debug_xalloc (dhandle, mangled_name_len);
if (is_constructor)
physname[0] = '\0';
else
if (*argtypes == '\0' || is_destructor)
{
- args = (debug_type *) xmalloc (sizeof *args);
+ args = debug_xalloc (dhandle, sizeof (*args));
*args = NULL;
return debug_make_method_type (dhandle, return_type, class_type, args,
false);
/* Start a new N_BINCL file, pushing it onto the stack. */
static void
-push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
+push_bincl (void *dhandle, struct stab_handle *info, const char *name,
+ bfd_vma hash)
{
struct bincl_file *n;
- n = (struct bincl_file *) xmalloc (sizeof *n);
+ n = debug_xalloc (dhandle, sizeof *n);
n->next = info->bincl_list;
n->next_stack = info->bincl_stack;
n->name = name;
info->bincl_stack = n;
++info->files;
- info->file_types = ((struct stab_types **)
- xrealloc (info->file_types,
- (info->files
- * sizeof *info->file_types)));
+ info->file_types = xrealloc (info->file_types,
+ info->files * sizeof (*info->file_types));
info->file_types[n->file] = NULL;
}
struct bincl_file *l;
++info->files;
- info->file_types = ((struct stab_types **)
- xrealloc (info->file_types,
- (info->files
- * sizeof *info->file_types)));
+ info->file_types = xrealloc (info->file_types,
+ info->files * sizeof (*info->file_types));
for (l = info->bincl_list; l != NULL; l = l->next)
if (l->hash == hash && strcmp (l->name, name) == 0)
|| (info->gcc_compiled == 0 && info->n_opt_found))
return debug_record_variable (dhandle, name, type, kind, val);
- v = (struct stab_pending_var *) xmalloc (sizeof *v);
- memset (v, 0, sizeof *v);
+ v = debug_xzalloc (dhandle, sizeof (*v));
v->next = info->pending;
v->name = name;
v = info->pending;
while (v != NULL)
{
- struct stab_pending_var *next;
-
if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
return false;
- next = v->next;
- free (v);
- v = next;
+ v = v->next;
}
info->pending = NULL;
/* Find the slot for a type in the database. */
static debug_type *
-stab_find_slot (struct stab_handle *info, const int *typenums)
+stab_find_slot (void *dhandle, struct stab_handle *info, const int *typenums)
{
unsigned int filenum;
unsigned int tindex;
if (*ps == NULL || (*ps)->base_index != base_index)
{
- struct stab_types *n = xcalloc (1, sizeof (*n));
+ struct stab_types *n = debug_xzalloc (dhandle, sizeof (*n));
n->next = *ps;
n->base_index = base_index;
*ps = n;
return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
}
- slot = stab_find_slot (info, typenums);
+ slot = stab_find_slot (dhandle, info, typenums);
if (slot == NULL)
return DEBUG_TYPE_NULL;
/* Record that a given type number refers to a given type. */
static bool
-stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
+stab_record_type (void *dhandle, struct stab_handle *info,
const int *typenums, debug_type type)
{
debug_type *slot;
- slot = stab_find_slot (info, typenums);
+ slot = stab_find_slot (dhandle, info, typenums);
if (slot == NULL)
return false;
debug_type dtype;
struct stab_tag *st;
- name = savestring (p, len);
+ name = savestring (dhandle, p, len);
/* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
namespace. This is right for C, and I don't know how to handle
other languages. FIXME. */
dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
if (dtype != DEBUG_TYPE_NULL)
- {
- free (name);
- return dtype;
- }
+ return dtype;
/* We need to allocate an entry on the undefined tag list. */
for (st = info->tags; st != NULL; st = st->next)
{
if (st->kind == DEBUG_KIND_ILLEGAL)
st->kind = kind;
- free (name);
break;
}
}
if (st == NULL)
{
- st = (struct stab_tag *) xmalloc (sizeof *st);
- memset (st, 0, sizeof *st);
+ st = debug_xzalloc (dhandle, sizeof (*st));
st->next = info->tags;
st->name = name;
minfo.args = NULL;
minfo.varargs = false;
minfo.typestring_alloc = 10;
- minfo.typestrings = ((struct stab_demangle_typestring *)
- xmalloc (minfo.typestring_alloc
- * sizeof *minfo.typestrings));
+ minfo.typestrings
+ = xmalloc (minfo.typestring_alloc * sizeof (*minfo.typestrings));
minfo.typestring_count = 0;
/* cplus_demangle checks for special GNU mangled forms, but we can't
}
free (minfo.typestrings);
- minfo.typestrings = NULL;
if (minfo.args == NULL)
fprintf (stderr, _("no argument types in mangled string\n"));
context = stab_find_tagged_type (minfo->dhandle, minfo->info,
name, strlen (name),
DEBUG_KIND_CLASS);
- free (name);
if (context == DEBUG_TYPE_NULL)
return false;
}
not give us enough information to figure out the
latter case. */
- name = savestring (*pp, len);
+ name = savestring (minfo->dhandle, *pp, len);
for (; *fields != DEBUG_FIELD_NULL; fields++)
{
ft = debug_get_field_type (minfo->dhandle, *fields);
if (ft == NULL)
- {
- free (name);
- return false;
- }
+ return false;
dn = debug_get_type_name (minfo->dhandle, ft);
if (dn != NULL && strcmp (dn, name) == 0)
{
break;
}
}
-
- free (name);
}
if (context == DEBUG_TYPE_NULL)
{
char *name;
- name = savestring (*pp, len);
+ name = savestring (minfo->dhandle, *pp, len);
context = debug_find_named_type (minfo->dhandle,
name);
- free (name);
}
if (context == DEBUG_TYPE_NULL)
char *s1, *s2, *s3, *s4 = NULL;
char *from, *to;
- s1 = savestring (orig, *pp - orig);
+ s1 = savestring (minfo->dhandle, orig, *pp - orig);
s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
- free (s1);
-
s3 = cplus_demangle (s2, demangle_flags);
free (s2);
|| (from[1] == '>' && from > s3 && from[-1] == '>'))
*to++ = *from;
- *pname = savestring (s3, to - s3);
+ *pname = savestring (minfo->dhandle, s3, to - s3);
free (s3);
}
alloc = 10;
if (pargs != NULL)
- {
- *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
- *pvarargs = false;
- }
+ *pargs = xmalloc (alloc * sizeof (**pargs));
+ if (pvarargs != NULL)
+ *pvarargs = false;
count = 0;
while (**pp != '_' && **pp != '\0' && **pp != 'e')
else
{
if (! stab_demangle_get_count (pp, &r))
- {
- stab_bad_demangle (orig);
- return false;
- }
+ goto bad;
}
- if (! stab_demangle_get_count (pp, &t))
- {
- stab_bad_demangle (orig);
- return false;
- }
+ if (!stab_demangle_get_count (pp, &t)
+ || t >= minfo->typestring_count)
+ goto bad;
- if (t >= minfo->typestring_count)
- {
- stab_bad_demangle (orig);
- return false;
- }
while (r-- > 0)
{
const char *tem;
tem = minfo->typestrings[t].typestring;
if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
- return false;
+ goto fail;
}
}
else
{
if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
- return false;
+ goto fail;
}
}
if (pargs != NULL)
- (*pargs)[count] = DEBUG_TYPE_NULL;
+ {
+ debug_type *xargs;
+ (*pargs)[count] = DEBUG_TYPE_NULL;
+ xargs = debug_xalloc (minfo->dhandle, (count + 1) * sizeof (*xargs));
+ memcpy (xargs, *pargs, (count + 1) * sizeof (*xargs));
+ free (*pargs);
+ *pargs = xargs;
+ }
if (**pp == 'e')
{
- if (pargs != NULL)
+ if (pvarargs != NULL)
*pvarargs = true;
++*pp;
}
-
return true;
+
+ bad:
+ stab_bad_demangle (orig);
+ fail:
+ if (pargs != NULL)
+ {
+ free (*pargs);
+ *pargs = NULL;
+ }
+ return false;
}
/* Demangle a single argument. */
if (*pcount + 1 >= *palloc)
{
*palloc += 10;
- *pargs = ((debug_type *)
- xrealloc (*pargs, *palloc * sizeof **pargs));
+ *pargs = xrealloc (*pargs, *palloc * sizeof (**pargs));
}
(*pargs)[*pcount] = type;
++*pcount;
{
char *name;
- name = savestring (hold, *pp - hold);
+ name = savestring (minfo->dhandle, hold, *pp - hold);
*ptype = debug_find_named_type (minfo->dhandle, name);
- free (name);
if (*ptype == DEBUG_TYPE_NULL)
{
/* FIXME: It is probably incorrect to assume that
*ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
name, strlen (name),
DEBUG_KIND_CLASS);
- free (name);
if (*ptype == DEBUG_TYPE_NULL)
return false;
}
if (minfo->typestring_count >= minfo->typestring_alloc)
{
minfo->typestring_alloc += 10;
- minfo->typestrings = ((struct stab_demangle_typestring *)
- xrealloc (minfo->typestrings,
- (minfo->typestring_alloc
- * sizeof *minfo->typestrings)));
+ minfo->typestrings
+ = xrealloc (minfo->typestrings,
+ minfo->typestring_alloc * sizeof (*minfo->typestrings));
}
minfo->typestrings[minfo->typestring_count].typestring = p;
{
struct demangle_component *dc;
unsigned int alloc, count;
- debug_type *pargs;
+ debug_type *pargs, *xargs;
alloc = 10;
- pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
+ pargs = xmalloc (alloc * sizeof (*pargs));
*pvarargs = false;
count = 0;
if (count + 1 >= alloc)
{
alloc += 10;
- pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
+ pargs = xrealloc (pargs, alloc * sizeof (*pargs));
}
pargs[count] = arg;
}
pargs[count] = DEBUG_TYPE_NULL;
+ xargs = debug_xalloc (dhandle, (count + 1) * sizeof (*pargs));
+ memcpy (xargs, pargs, (count + 1) * sizeof (*pargs));
+ free (pargs);
- return pargs;
+ return xargs;
}
/* Convert a struct demangle_component tree describing an argument
dc->u.s_binary.right,
&varargs);
if (pargs == NULL)
- {
- free (dt);
- return NULL;
- }
+ return NULL;
return debug_make_function_type (dhandle, dt, pargs, varargs);
}