const char *lineno_filename;
};
-static struct bfd_hash_entry *string_hash_newfunc
- (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
-static bool stab_write_symbol
- (struct stab_write_handle *, int, int, bfd_vma, const char *);
-static bool stab_push_string
- (struct stab_write_handle *, const char *, long, bool, unsigned int);
-static bool stab_push_defined_type
- (struct stab_write_handle *, long, unsigned int);
-static char *stab_pop_type (struct stab_write_handle *);
-static bool stab_modify_type
- (struct stab_write_handle *, int, unsigned int, long **, size_t *);
-static long stab_get_struct_index
- (struct stab_write_handle *, const char *, unsigned int,
- enum debug_type_kind, unsigned int *);
-static bool stab_class_method_var
- (struct stab_write_handle *, const char *, enum debug_visibility,
- bool, bool, bool, bfd_vma, bool);
static bool stab_start_compilation_unit (void *, const char *);
static bool stab_start_source (void *, const char *);
static bool stab_empty_type (void *);
if (info->symbols_size + STAB_SYMBOL_SIZE > info->symbols_alloc)
{
info->symbols_alloc *= 2;
- info->symbols = (bfd_byte *) xrealloc (info->symbols,
- info->symbols_alloc);
+ info->symbols = xrealloc (info->symbols, info->symbols_alloc);
}
memcpy (info->symbols + info->symbols_size, sym, STAB_SYMBOL_SIZE);
return true;
}
+static bool
+stab_write_symbol_and_free (struct stab_write_handle *info, int type, int desc,
+ bfd_vma value, char *string)
+{
+ bool ret = stab_write_symbol (info, type, desc, value, string);
+ free (string);
+ return ret;
+}
+
/* Push a string on to the type stack. */
static bool
-stab_push_string (struct stab_write_handle *info, const char *string,
+stab_push_string (struct stab_write_handle *info, char *string,
long tindex, bool definition, unsigned int size)
{
struct stab_type_stack *s;
- s = (struct stab_type_stack *) xmalloc (sizeof *s);
- s->string = xstrdup (string);
+ s = xmalloc (sizeof *s);
+ s->string = string;
s->index = tindex;
s->definition = definition;
s->size = size;
return true;
}
+static bool
+stab_push_string_dup (struct stab_write_handle *info, const char *string,
+ long tindex, bool definition, unsigned int size)
+{
+ return stab_push_string (info, xstrdup (string), tindex, definition, size);
+}
+
/* Push a type index which has already been defined. */
static bool
char buf[20];
sprintf (buf, "%ld", tindex);
- return stab_push_string (info, buf, tindex, false, size);
+ return stab_push_string_dup (info, buf, tindex, false, size);
}
/* Pop a type off the type stack. The caller is responsible for
bfd_size_type *pstringsize)
{
struct stab_write_handle info;
- struct string_hash_entry *h;
+ struct string_hash_entry *h, *hnext;
bfd_byte *p;
+ bool ret;
memset (&info, 0, sizeof info);
info.abfd = abfd;
info.symbols_alloc = 500;
- info.symbols = (bfd_byte *) xmalloc (info.symbols_alloc);
+ info.symbols = xmalloc (info.symbols_alloc);
/* Reserve 1 byte for a null byte. */
info.strings_size = 1;
*psymsize = info.symbols_size;
*pstringsize = info.strings_size;
- *pstrings = (bfd_byte *) xmalloc (info.strings_size);
+ *pstrings = xmalloc (info.strings_size);
p = *pstrings;
*p++ = '\0';
p += strlen ((char *) p) + 1;
}
- bfd_hash_table_free (&info.typedef_hash.table);
- bfd_hash_table_free (&info.strhash.table);
- return true;
+ ret = true;
+ goto out;
fail:
+ free (info.symbols);
+ ret = false;
+ out:
+ for (h = info.strings; h != NULL; h = hnext)
+ {
+ hnext = h->next;
+ free (h);
+ }
+ while (info.type_stack != NULL)
+ {
+ struct stab_type_stack *s = info.type_stack;
+ info.type_stack = s->next;
+ free (s->string);
+ free (s->fields);
+ if (s->baseclasses != NULL)
+ {
+ for (int i = 0; s->baseclasses[i] != NULL; i++)
+ free (s->baseclasses[i]);
+ free (s->baseclasses);
+ }
+ free (s->methods);
+ free (s->vtable);
+ free (s);
+ }
+ free (info.type_cache.pointer_types);
+ free (info.type_cache.function_types);
+ free (info.type_cache.reference_types);
+ free (info.type_cache.struct_types);
if (info.typedef_hash.table.memory)
bfd_hash_table_free (&info.typedef_hash.table);
if (info.strhash.table.memory)
bfd_hash_table_free (&info.strhash.table);
- free (info.symbols);
- return false;
+ return ret;
}
/* Start writing out information for a compilation unit. */
sprintf (buf, "%ld=%ld", tindex, tindex);
- return stab_push_string (info, buf, tindex, false, 0);
+ return stab_push_string_dup (info, buf, tindex, false, 0);
}
}
sprintf (buf, "%ld=%ld", tindex, tindex);
- return stab_push_string (info, buf, tindex, true, 0);
+ return stab_push_string_dup (info, buf, tindex, true, 0);
}
}
abort ();
}
- return stab_push_string (info, buf, tindex, true, size);
+ return stab_push_string_dup (info, buf, tindex, true, size);
}
}
free (int_type);
- return stab_push_string (info, buf, tindex, true, size);
+ return stab_push_string_dup (info, buf, tindex, true, size);
}
}
sprintf (buf, "%ld=r%ld;%u;0;", tindex, tindex, size);
- return stab_push_string (info, buf, tindex, true, size * 2);
+ return stab_push_string_dup (info, buf, tindex, true, size * 2);
}
/* Push a bool type. We use an XCOFF predefined type, since gdb
if (tag == NULL)
return false;
- buf = (char *) xmalloc (10 + strlen (tag));
+ buf = xmalloc (4 + strlen (tag));
sprintf (buf, "xe%s:", tag);
/* FIXME: The size is just a guess. */
- if (! stab_push_string (info, buf, 0, false, 4))
- return false;
- free (buf);
- return true;
+ return stab_push_string (info, buf, 0, false, 4);
}
- len = 10;
+ len = 25;
if (tag != NULL)
len += strlen (tag);
for (pn = names; *pn != NULL; pn++)
- len += strlen (*pn) + 20;
+ len += strlen (*pn) + 22;
- buf = (char *) xmalloc (len);
+ buf = xmalloc (len);
if (tag == NULL)
strcpy (buf, "e");
if (tag == NULL)
{
/* FIXME: The size is just a guess. */
- if (! stab_push_string (info, buf, 0, false, 4))
- return false;
+ return stab_push_string (info, buf, 0, false, 4);
}
else
{
/* FIXME: The size is just a guess. */
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf)
- || ! stab_push_defined_type (info, tindex, 4))
- return false;
+ return (stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf)
+ && stab_push_defined_type (info, tindex, 4));
}
-
- free (buf);
-
- return true;
}
/* Push a modification of the top type on the stack. Cache the
new type, so we don't bother to define one. */
definition = info->type_stack->definition;
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (s) + 2);
+ buf = xmalloc (strlen (s) + 2);
sprintf (buf, "%c%s", mod, s);
free (s);
- if (! stab_push_string (info, buf, 0, definition, size))
- return false;
- free (buf);
+ return stab_push_string (info, buf, 0, definition, size);
}
else
{
alloc = 10;
while ((size_t) targindex >= alloc)
alloc *= 2;
- *cache = (long *) xrealloc (*cache, alloc * sizeof (long));
+ *cache = xrealloc (*cache, alloc * sizeof (**cache));
memset (*cache + *cache_alloc, 0,
- (alloc - *cache_alloc) * sizeof (long));
+ (alloc - *cache_alloc) * sizeof (**cache));
*cache_alloc = alloc;
}
is a struct which we did not define at the time it was
referenced). */
free (stab_pop_type (info));
- if (! stab_push_defined_type (info, tindex, size))
- return false;
+ return stab_push_defined_type (info, tindex, size);
}
else
{
++info->type_index;
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (s) + 20);
+ buf = xmalloc (strlen (s) + 23);
sprintf (buf, "%ld=%c%s", tindex, mod, s);
free (s);
(*cache)[targindex] = tindex;
- if (! stab_push_string (info, buf, tindex, true, size))
- return false;
-
- free (buf);
+ return stab_push_string (info, buf, tindex, true, size);
}
}
-
- return true;
}
/* Push a pointer type. */
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (s) + 3);
+ buf = xmalloc (strlen (s) + 3);
sprintf (buf, ":t%s", s);
free (s);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
- return false;
-
- free (buf);
+ return stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf);
}
}
size = info->type_stack->size;
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (s) + 100);
+ buf = xmalloc (strlen (s) + 45);
sprintf (buf, "r%s;%ld;%ld;", s, (long) low, (long) high);
free (s);
- if (! stab_push_string (info, buf, 0, definition, size))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, 0, definition, size);
}
/* Push an array type. */
element_size = info->type_stack->size;
element = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (range) + strlen (element) + 100);
+ buf = xmalloc (strlen (range) + strlen (element) + 70);
if (! stringp)
{
size = 0;
else
size = element_size * ((high - low) + 1);
- if (! stab_push_string (info, buf, tindex, definition, size))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, tindex, definition, size);
}
/* Push a set type. */
definition = info->type_stack->definition;
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (s) + 30);
+ buf = xmalloc (strlen (s) + 26);
if (! bitstringp)
{
sprintf (buf + strlen (buf), "S%s", s);
free (s);
- if (! stab_push_string (info, buf, tindex, definition, 0))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, tindex, definition, 0);
}
/* Push an offset type. */
definition = definition || info->type_stack->definition;
base = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (target) + strlen (base) + 3);
+ buf = xmalloc (strlen (target) + strlen (base) + 3);
sprintf (buf, "@%s,%s", base, target);
free (base);
free (target);
- if (! stab_push_string (info, buf, 0, definition, 0))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, 0, definition, 0);
}
/* Push a method type. */
args = NULL;
else
{
- args = (char **) xmalloc (1 * sizeof (*args));
+ args = xmalloc (1 * sizeof (*args));
if (! stab_empty_type (p))
- return false;
+ {
+ free (args);
+ return false;
+ }
definition = definition || info->type_stack->definition;
args[0] = stab_pop_type (info);
argcount = 1;
}
else
{
- args = (char **) xmalloc ((argcount + 1) * sizeof (*args));
+ args = xmalloc ((argcount + 1) * sizeof (*args));
for (i = argcount - 1; i >= 0; i--)
{
definition = definition || info->type_stack->definition;
if (! varargs)
{
if (! stab_empty_type (p))
- return false;
+ {
+ for (i = 0; i < argcount; i++)
+ free (args[i]);
+ free (args);
+ return false;
+ }
definition = definition || info->type_stack->definition;
args[argcount] = stab_pop_type (info);
++argcount;
definition = definition || info->type_stack->definition;
return_type = stab_pop_type (info);
- len = strlen (domain) + strlen (return_type) + 10;
+ len = strlen (domain) + strlen (return_type) + 4 + argcount;
for (i = 0; i < argcount; i++)
len += strlen (args[i]);
- buf = (char *) xmalloc (len);
+ buf = xmalloc (len);
sprintf (buf, "#%s,%s", domain, return_type);
free (domain);
free (args);
- if (! stab_push_string (info, buf, 0, definition, 0))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, 0, definition, 0);
}
/* Push a const version of a type. */
while (id >= alloc)
alloc *= 2;
info->type_cache.struct_types =
- (struct stab_tag *) xrealloc (info->type_cache.struct_types,
- alloc * sizeof (struct stab_tag));
+ xrealloc (info->type_cache.struct_types,
+ alloc * sizeof (*info->type_cache.struct_types));
memset ((info->type_cache.struct_types
+ info->type_cache.struct_types_alloc),
0,
((alloc - info->type_cache.struct_types_alloc)
- * sizeof (struct stab_tag)));
+ * sizeof (*info->type_cache.struct_types)));
info->type_cache.struct_types_alloc = alloc;
}
structp ? 's' : 'u',
size);
- if (! stab_push_string (info, buf, tindex, definition, size))
+ if (!stab_push_string_dup (info, buf, tindex, definition, size))
return false;
- info->type_stack->fields = (char *) xmalloc (1);
+ info->type_stack->fields = xmalloc (1);
info->type_stack->fields[0] = '\0';
return true;
/* Add this field to the end of the current struct fields, which is
currently on the top of the stack. */
if (info->type_stack->fields == NULL)
- return false;
+ {
+ free (s);
+ return false;
+ }
- n = (char *) xmalloc (strlen (info->type_stack->fields)
- + strlen (name)
- + strlen (s)
- + 50);
+ n = xmalloc (strlen (info->type_stack->fields)
+ + strlen (name) + strlen (s) + 50);
switch (visibility)
{
(long) bitpos, (long) bitsize);
free (info->type_stack->fields);
+ free (s);
info->type_stack->fields = n;
if (definition)
fields = info->type_stack->fields;
first = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (first) + strlen (fields) + 2);
+ buf = xmalloc (strlen (first) + strlen (fields) + 2);
sprintf (buf, "%s%s;", first, fields);
free (first);
free (fields);
- if (! stab_push_string (info, buf, tindex, definition, size))
- return false;
-
- free (buf);
-
- return true;
+ return stab_push_string (info, buf, tindex, definition, size);
}
/* Start outputting a class. */
}
if (! stab_start_struct_type (p, tag, id, structp, size))
- return false;
+ {
+ free (vstring);
+ return false;
+ }
if (vptr)
{
{
if (info->type_stack->index < 1)
return false;
- vtable = (char *) xmalloc (20);
+ vtable = xmalloc (23);
sprintf (vtable, "~%%%ld", info->type_stack->index);
}
else
{
if (vstring == NULL)
return false;
- vtable = (char *) xmalloc (strlen (vstring) + 3);
+ vtable = xmalloc (strlen (vstring) + 3);
sprintf (vtable, "~%%%s", vstring);
free (vstring);
if (definition)
if (info->type_stack->fields == NULL)
return false;
- n = (char *) xmalloc (strlen (info->type_stack->fields)
- + strlen (name)
- + strlen (s)
- + strlen (physname)
- + 10);
+ n = xmalloc (strlen (info->type_stack->fields) + strlen (name)
+ + strlen (s) + strlen (physname) + 10);
switch (visibility)
{
sprintf (n, "%s%s:%s%s:%s;", info->type_stack->fields, name, vis, s,
physname);
+ free (s);
free (info->type_stack->fields);
info->type_stack->fields = n;
/* Build the base class specifier. */
- buf = (char *) xmalloc (strlen (s) + 25);
+ buf = xmalloc (strlen (s) + 25);
buf[0] = is_virtual ? '1' : '0';
switch (visibility)
{
/* Add the new baseclass to the existing ones. */
if (info->type_stack == NULL || info->type_stack->fields == NULL)
- return false;
+ {
+ free (buf);
+ return false;
+ }
if (info->type_stack->baseclasses == NULL)
c = 0;
++c;
}
- baseclasses = (char **) xrealloc (info->type_stack->baseclasses,
- (c + 2) * sizeof (*baseclasses));
+ baseclasses = xrealloc (info->type_stack->baseclasses,
+ (c + 2) * sizeof (*baseclasses));
baseclasses[c] = buf;
baseclasses[c + 1] = NULL;
if (info->type_stack->methods == NULL)
{
- m = (char *) xmalloc (strlen (name) + 3);
+ m = xmalloc (strlen (name) + 3);
*m = '\0';
}
else
- {
- m = (char *) xrealloc (info->type_stack->methods,
- (strlen (info->type_stack->methods)
- + strlen (name)
- + 4));
- }
+ m = xrealloc (info->type_stack->methods,
+ strlen (info->type_stack->methods) + strlen (name) + 3);
sprintf (m + strlen (m), "%s::", name);
}
if (info->type_stack == NULL || info->type_stack->methods == NULL)
- return false;
+ {
+ free (type);
+ free (context);
+ return false;
+ }
switch (visibility)
{
typec = '*';
info->type_stack->methods =
- (char *) xrealloc (info->type_stack->methods,
- (strlen (info->type_stack->methods)
- + strlen (type)
- + strlen (physname)
- + (contextp ? strlen (context) : 0)
- + 40));
+ xrealloc (info->type_stack->methods,
+ (strlen (info->type_stack->methods) + strlen (type)
+ + strlen (physname) + (contextp ? strlen (context) : 0) + 40));
sprintf (info->type_stack->methods + strlen (info->type_stack->methods),
"%s:%s;%c%c%c", type, physname, visc, qualc, typec);
/* Build the class definition. */
- buf = (char *) xmalloc (len);
+ buf = xmalloc (len);
strcpy (buf, info->type_stack->string);
size = info->type_stack->size;
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (name) + strlen (s) + 20);
+ buf = xmalloc (strlen (name) + strlen (s) + 20);
if (tindex > 0)
sprintf (buf, "%s:t%s", name, s);
free (s);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
+ if (!stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf))
return false;
- free (buf);
-
h = string_hash_lookup (&info->typedef_hash, name, true, false);
if (h == NULL)
{
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (tag) + strlen (s) + 3);
+ buf = xmalloc (strlen (tag) + strlen (s) + 3);
sprintf (buf, "%s:T%s", tag, s);
free (s);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf);
}
/* Define an integer constant. */
struct stab_write_handle *info = (struct stab_write_handle *) p;
char *buf;
- buf = (char *) xmalloc (strlen (name) + 20);
+ buf = xmalloc (strlen (name) + 20);
sprintf (buf, "%s:c=i%ld", name, (long) val);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf);
}
/* Define a floating point constant. */
struct stab_write_handle *info = (struct stab_write_handle *) p;
char *buf;
- buf = (char *) xmalloc (strlen (name) + 20);
+ buf = xmalloc (strlen (name) + 20);
sprintf (buf, "%s:c=f%g", name, val);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf);
}
/* Define a typed constant. */
s = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (name) + strlen (s) + 20);
+ buf = xmalloc (strlen (name) + strlen (s) + 20);
sprintf (buf, "%s:c=e%s,%ld", name, s, (long) val);
free (s);
- if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, N_LSYM, 0, 0, buf);
}
/* Record a variable. */
tindex = info->type_index;
++info->type_index;
- n = (char *) xmalloc (strlen (s) + 20);
+ n = xmalloc (strlen (s) + 20);
sprintf (n, "%ld=%s", tindex, s);
free (s);
s = n;
break;
}
- buf = (char *) xmalloc (strlen (name) + strlen (s) + 3);
+ buf = xmalloc (strlen (name) + strlen (s) + 3);
sprintf (buf, "%s:%s%s", name, kindstr, s);
free (s);
- if (! stab_write_symbol (info, stab_type, 0, val, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, stab_type, 0, val, buf);
}
/* Start outputting a function. */
rettype = stab_pop_type (info);
- buf = (char *) xmalloc (strlen (name) + strlen (rettype) + 3);
+ buf = xmalloc (strlen (name) + strlen (rettype) + 3);
sprintf (buf, "%s:%c%s", name,
globalp ? 'F' : 'f',
rettype);
+ free (rettype);
/* We don't know the value now, so we set it in start_block. */
info->fun_offset = info->symbols_size;
- if (! stab_write_symbol (info, N_FUN, 0, 0, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, N_FUN, 0, 0, buf);
}
/* Output a function parameter. */
break;
}
- buf = (char *) xmalloc (strlen (name) + strlen (s) + 3);
+ buf = xmalloc (strlen (name) + strlen (s) + 3);
sprintf (buf, "%s:%c%s", name, kindc, s);
free (s);
- if (! stab_write_symbol (info, stab_type, 0, val, buf))
- return false;
-
- free (buf);
-
- return true;
+ return stab_write_symbol_and_free (info, stab_type, 0, val, buf);
}
/* Start a block. */