X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=binutils%2Fdebug.c;h=bb26d9143d0f8031f4d9425dcdf3d02a4e71b6b7;hb=27b1f19f8f5cc46faba4bb2142547df074a82a29;hp=ffdc7667a4a447a28924d82965324dcf6fca4c48;hpb=8c2bc6877d75f8cd9073f206fab29920f73d325c;p=binutils-gdb.git diff --git a/binutils/debug.c b/binutils/debug.c index ffdc7667a4a..bb26d9143d0 100644 --- a/binutils/debug.c +++ b/binutils/debug.c @@ -1,12 +1,12 @@ /* debug.c -- Handle generic debugging information. - Copyright 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. + Copyright (C) 1995-2023 Free Software Foundation, Inc. Written by Ian Lance Taylor . This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,21 +16,22 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + /* This file implements a generic debugging format. We may eventually have readers which convert different formats into this generic format, and writers which write it out. The initial impetus for - this was writing a convertor from stabs to HP IEEE-695 debugging + this was writing a converter from stabs to HP IEEE-695 debugging format. */ -#include +#include "sysdep.h" #include - #include "bfd.h" -#include "bucomm.h" #include "libiberty.h" +#include "filenames.h" +#include "bucomm.h" #include "debug.h" /* Global information we keep for debugging. A pointer to this @@ -38,6 +39,8 @@ 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. */ @@ -96,12 +99,14 @@ struct debug_file /* A type. */ -struct debug_type +struct debug_type_s { /* Kind of type. */ enum debug_type_kind kind; /* Size of type (0 if not known). */ unsigned int size; + /* Used by debug_write to stop DEBUG_KIND_INDIRECT infinite recursion. */ + unsigned int mark; /* Type which is a pointer to this type. */ debug_type pointer; /* Tagged union with additional information about the type. */ @@ -111,18 +116,18 @@ struct debug_type struct debug_indirect_type *kindirect; /* DEBUG_KIND_INT. */ /* Whether the integer is unsigned. */ - boolean kint; + bool kint; /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS, DEBUG_KIND_UNION_CLASS. */ struct debug_class_type *kclass; /* DEBUG_KIND_ENUM. */ struct debug_enum_type *kenum; /* DEBUG_KIND_POINTER. */ - struct debug_type *kpointer; + struct debug_type_s *kpointer; /* DEBUG_KIND_FUNCTION. */ struct debug_function_type *kfunction; /* DEBUG_KIND_REFERENCE. */ - struct debug_type *kreference; + struct debug_type_s *kreference; /* DEBUG_KIND_RANGE. */ struct debug_range_type *krange; /* DEBUG_KIND_ARRAY. */ @@ -134,9 +139,9 @@ struct debug_type /* DEBUG_KIND_METHOD. */ struct debug_method_type *kmethod; /* DEBUG_KIND_CONST. */ - struct debug_type *kconst; + struct debug_type_s *kconst; /* DEBUG_KIND_VOLATILE. */ - struct debug_type *kvolatile; + struct debug_type_s *kvolatile; /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */ struct debug_named_type *knamed; } u; @@ -194,7 +199,7 @@ struct debug_function_type /* NULL terminated array of argument types. */ debug_type *arg_types; /* Whether the function takes a variable number of arguments. */ - boolean varargs; + bool varargs; }; /* Information kept for a range. */ @@ -222,7 +227,7 @@ struct debug_array_type /* Upper bound. */ bfd_signed_vma upper; /* Whether this array is really a string. */ - boolean stringp; + bool stringp; }; /* Information kept for a set. */ @@ -232,7 +237,7 @@ struct debug_set_type /* Base type. */ debug_type type; /* Whether this set is really a bitstring. */ - boolean bitstringp; + bool bitstringp; }; /* Information kept for an offset type (a based pointer). */ @@ -256,7 +261,7 @@ struct debug_method_type /* A NULL terminated array of argument types. */ debug_type *arg_types; /* Whether the method takes a variable number of arguments. */ - boolean varargs; + bool varargs; }; /* Information kept for a named type. */ @@ -271,16 +276,16 @@ struct debug_named_type /* A field in a struct or union. */ -struct debug_field +struct debug_field_s { /* Name of the field. */ const char *name; /* Type of the field. */ - struct debug_type *type; + struct debug_type_s *type; /* Visibility of the field. */ enum debug_visibility visibility; /* Whether this is a static member. */ - boolean static_member; + bool static_member; union { /* If static_member is false. */ @@ -301,49 +306,49 @@ struct debug_field /* A base class for an object. */ -struct debug_baseclass +struct debug_baseclass_s { /* Type of the base class. */ - struct debug_type *type; + struct debug_type_s *type; /* Bit position of the base class in the object. */ unsigned int bitpos; /* Whether the base class is virtual. */ - boolean virtual; + bool is_virtual; /* Visibility of the base class. */ enum debug_visibility visibility; }; /* A method of an object. */ -struct debug_method +struct debug_method_s { /* The name of the method. */ const char *name; /* A NULL terminated array of different types of variants. */ - struct debug_method_variant **variants; + struct debug_method_variant_s **variants; }; /* The variants of a method function of an object. These indicate which method to run. */ -struct debug_method_variant +struct debug_method_variant_s { /* The physical name of the function. */ const char *physname; /* The type of the function. */ - struct debug_type *type; + struct debug_type_s *type; /* The visibility of the function. */ enum debug_visibility visibility; /* Whether the function is const. */ - boolean constp; + bool constp; /* Whether the function is volatile. */ - boolean volatilep; + bool volatilep; /* The offset to the function in the virtual function table. */ bfd_vma voffset; /* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */ #define VOFFSET_STATIC_METHOD ((bfd_vma) -1) /* Context of a virtual method function. */ - struct debug_type *context; + struct debug_type_s *context; }; /* A variable. This is the information we keep for a variable object. @@ -500,9 +505,9 @@ struct debug_name union { /* DEBUG_OBJECT_TYPE. */ - struct debug_type *type; + struct debug_type_s *type; /* DEBUG_OBJECT_TAG. */ - struct debug_type *tag; + struct debug_type_s *tag; /* DEBUG_OBJECT_VARIABLE. */ struct debug_variable *variable; /* DEBUG_OBJECT_FUNCTION. */ @@ -524,7 +529,7 @@ struct debug_class_id /* Next ID number. */ struct debug_class_id *next; /* The type with the ID. */ - struct debug_type *type; + struct debug_type_s *type; /* The tag; NULL if no tag. */ const char *tag; }; @@ -537,8 +542,8 @@ struct debug_type_compare_list /* Next type on list. */ struct debug_type_compare_list *next; /* The types we are comparing. */ - struct debug_type *t1; - struct debug_type *t2; + struct debug_type_s *t1; + struct debug_type_s *t2; }; /* During debug_get_real_type, a linked list of these structures is @@ -549,52 +554,50 @@ struct debug_type_real_list /* Next type on list. */ struct debug_type_real_list *next; /* The type we are checking. */ - struct debug_type *t; + struct debug_type_s *t; }; /* Local functions. */ -static void debug_error PARAMS ((const char *)); +static void debug_error (const char *); static struct debug_name *debug_add_to_namespace - PARAMS ((struct debug_handle *, struct debug_namespace **, const char *, - enum debug_object_kind, enum debug_object_linkage)); + (struct debug_handle *, struct debug_namespace **, const char *, + enum debug_object_kind, enum debug_object_linkage); static struct debug_name *debug_add_to_current_namespace - PARAMS ((struct debug_handle *, const char *, enum debug_object_kind, - enum debug_object_linkage)); -static struct debug_type *debug_make_type - PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int)); -static struct debug_type *debug_get_real_type - PARAMS ((PTR, debug_type, struct debug_type_real_list *)); -static boolean debug_write_name - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - struct debug_name *)); -static boolean debug_write_type - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - struct debug_type *, struct debug_name *)); -static boolean debug_write_class_type - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - struct debug_type *, const char *)); -static boolean debug_write_function - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - const char *, enum debug_object_linkage, struct debug_function *)); -static boolean debug_write_block - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - struct debug_block *)); -static boolean debug_write_linenos - PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR, - bfd_vma)); -static boolean debug_set_class_id - PARAMS ((struct debug_handle *, const char *, struct debug_type *)); -static boolean debug_type_samep - PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); -static boolean debug_class_type_samep - PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *)); + (struct debug_handle *, const char *, enum debug_object_kind, + enum debug_object_linkage); +static struct debug_type_s *debug_make_type + (struct debug_handle *, enum debug_type_kind, unsigned int); +static struct debug_type_s *debug_get_real_type + (void *, debug_type, struct debug_type_real_list *); +static bool debug_write_name + (struct debug_handle *, const struct debug_write_fns *, void *, + struct debug_name *); +static bool debug_write_type + (struct debug_handle *, const struct debug_write_fns *, void *, + struct debug_type_s *, struct debug_name *); +static bool debug_write_class_type + (struct debug_handle *, const struct debug_write_fns *, void *, + struct debug_type_s *, const char *); +static bool debug_write_function + (struct debug_handle *, const struct debug_write_fns *, void *, + const char *, enum debug_object_linkage, struct debug_function *); +static bool debug_write_block + (struct debug_handle *, const struct debug_write_fns *, void *, + struct debug_block *); +static bool debug_write_linenos + (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma); +static bool debug_set_class_id + (struct debug_handle *, const char *, struct debug_type_s *); +static bool debug_type_samep + (struct debug_handle *, struct debug_type_s *, struct debug_type_s *); +static bool debug_class_type_samep + (struct debug_handle *, struct debug_type_s *, struct debug_type_s *); /* Issue an error message. */ static void -debug_error (message) - const char *message; +debug_error (const char *message) { fprintf (stderr, "%s\n", message); } @@ -602,18 +605,15 @@ debug_error (message) /* Add an object to a namespace. */ static struct debug_name * -debug_add_to_namespace (info, nsp, name, kind, linkage) - struct debug_handle *info ATTRIBUTE_UNUSED; - struct debug_namespace **nsp; - const char *name; - enum debug_object_kind kind; - enum debug_object_linkage linkage; +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; @@ -622,8 +622,7 @@ debug_add_to_namespace (info, nsp, name, kind, linkage) 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; @@ -639,11 +638,9 @@ debug_add_to_namespace (info, nsp, name, kind, linkage) /* Add an object to the current namespace. */ static struct debug_name * -debug_add_to_current_namespace (info, name, kind, linkage) - struct debug_handle *info; - const char *name; - enum debug_object_kind kind; - enum debug_object_linkage linkage; +debug_add_to_current_namespace (struct debug_handle *info, const char *name, + enum debug_object_kind kind, + enum debug_object_linkage linkage) { struct debug_namespace **nsp; @@ -664,23 +661,38 @@ debug_add_to_current_namespace (info, name, kind, linkage) /* Return a handle for debugging information. */ -PTR -debug_init () +void * +debug_init (bfd *abfd) { struct debug_handle *ret; - ret = (struct debug_handle *) xmalloc (sizeof *ret); - memset (ret, 0, sizeof *ret); - return (PTR) 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 unit. */ -boolean -debug_set_filename (handle, name) - PTR handle; - const char *name; +bool +debug_set_filename (void *handle, const char *name) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_file *nfile; @@ -689,13 +701,11 @@ debug_set_filename (handle, name) 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; @@ -720,10 +730,8 @@ debug_set_filename (handle, name) /* Change source files to the given file name. This is used for include files in a single compilation unit. */ -boolean -debug_start_source (handle, name) - PTR handle; - const char *name; +bool +debug_start_source (void *handle, const char *name) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_file *f, **pf; @@ -739,18 +747,14 @@ debug_start_source (handle, name) for (f = info->current_unit->files; f != NULL; f = f->next) { - if (f->filename[0] == name[0] - && f->filename[1] == name[1] - && strcmp (f->filename, name) == 0) + if (filename_cmp (f->filename, name) == 0) { info->current_file = f; return true; } } - f = (struct debug_file *) xmalloc (sizeof *f); - memset (f, 0, sizeof *f); - + f = debug_xzalloc (info, sizeof (*f)); f->filename = name; for (pf = &info->current_file->next; @@ -772,13 +776,10 @@ debug_start_source (handle, name) debug_record_parameter. FIXME: There is no way to specify nested functions. */ -boolean -debug_record_function (handle, name, return_type, global, addr) - PTR handle; - const char *name; - debug_type return_type; - boolean global; - bfd_vma addr; +bool +debug_record_function (void *handle, const char *name, + debug_type return_type, bool global, + bfd_vma addr) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_function *f; @@ -796,13 +797,11 @@ debug_record_function (handle, name, return_type, global, addr) 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; @@ -831,13 +830,9 @@ debug_record_function (handle, name, return_type, global, addr) /* Record a parameter for the current function. */ -boolean -debug_record_parameter (handle, name, type, kind, val) - PTR handle; - const char *name; - debug_type type; - enum debug_parm_kind kind; - bfd_vma val; +bool +debug_record_parameter (void *handle, const char *name, debug_type type, + enum debug_parm_kind kind, bfd_vma val) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_parameter *p, **pp; @@ -852,8 +847,7 @@ debug_record_parameter (handle, name, type, kind, val) 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; @@ -871,10 +865,8 @@ debug_record_parameter (handle, name, type, kind, val) /* End a function. FIXME: This should handle function nesting. */ -boolean -debug_end_function (handle, addr) - PTR handle; - bfd_vma addr; +bool +debug_end_function (void *handle, bfd_vma addr) { struct debug_handle *info = (struct debug_handle *) handle; @@ -905,10 +897,8 @@ debug_end_function (handle, addr) debug_start_block and debug_end_block may be nested. The bfd_vma argument is the address at which this block starts. */ -boolean -debug_start_block (handle, addr) - PTR handle; - bfd_vma addr; +bool +debug_start_block (void *handle, bfd_vma addr) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_block *b, **pb; @@ -922,8 +912,7 @@ debug_start_block (handle, addr) 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; @@ -945,10 +934,8 @@ debug_start_block (handle, addr) debug_start_block. The argument is the address at which this block ends. */ -boolean -debug_end_block (handle, addr) - PTR handle; - bfd_vma addr; +bool +debug_end_block (void *handle, bfd_vma addr) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_block *parent; @@ -977,11 +964,8 @@ debug_end_block (handle, addr) /* Associate a line number in the current source file and function with a given address. */ -boolean -debug_record_line (handle, lineno, addr) - PTR handle; - unsigned long lineno; - bfd_vma addr; +bool +debug_record_line (void *handle, unsigned long lineno, bfd_vma addr) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_lineno *l; @@ -1015,8 +999,7 @@ debug_record_line (handle, lineno, 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; @@ -1037,10 +1020,9 @@ debug_record_line (handle, lineno, addr) /* Start a named common block. This is a block of variables that may move in memory. */ -boolean -debug_start_common_block (handle, name) - PTR handle ATTRIBUTE_UNUSED; - const char *name ATTRIBUTE_UNUSED; +bool +debug_start_common_block (void *handle ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED) { /* FIXME */ debug_error (_("debug_start_common_block: not implemented")); @@ -1049,10 +1031,9 @@ debug_start_common_block (handle, name) /* End a named common block. */ -boolean -debug_end_common_block (handle, name) - PTR handle ATTRIBUTE_UNUSED; - const char *name ATTRIBUTE_UNUSED; +bool +debug_end_common_block (void *handle ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED) { /* FIXME */ debug_error (_("debug_end_common_block: not implemented")); @@ -1061,11 +1042,8 @@ debug_end_common_block (handle, name) /* Record a named integer constant. */ -boolean -debug_record_int_const (handle, name, val) - PTR handle; - const char *name; - bfd_vma val; +bool +debug_record_int_const (void *handle, const char *name, bfd_vma val) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_name *n; @@ -1085,11 +1063,8 @@ debug_record_int_const (handle, name, val) /* Record a named floating point constant. */ -boolean -debug_record_float_const (handle, name, val) - PTR handle; - const char *name; - double val; +bool +debug_record_float_const (void *handle, const char *name, double val) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_name *n; @@ -1109,12 +1084,9 @@ debug_record_float_const (handle, name, val) /* Record a typed constant with an integral value. */ -boolean -debug_record_typed_const (handle, name, type, val) - PTR handle; - const char *name; - debug_type type; - bfd_vma val; +bool +debug_record_typed_const (void *handle, const char *name, debug_type type, + bfd_vma val) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_name *n; @@ -1128,8 +1100,7 @@ debug_record_typed_const (handle, name, type, val) 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; @@ -1141,27 +1112,22 @@ debug_record_typed_const (handle, name, type, val) /* Record a label. */ -boolean -debug_record_label (handle, name, type, addr) - PTR handle ATTRIBUTE_UNUSED; - const char *name ATTRIBUTE_UNUSED; - debug_type type ATTRIBUTE_UNUSED; - bfd_vma addr ATTRIBUTE_UNUSED; +bool +debug_record_label (void *handle ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + debug_type type ATTRIBUTE_UNUSED, + bfd_vma addr ATTRIBUTE_UNUSED) { /* FIXME. */ - debug_error (_("debug_record_label not implemented")); + debug_error (_("debug_record_label: not implemented")); return false; } /* Record a variable. */ -boolean -debug_record_variable (handle, name, type, kind, val) - PTR handle; - const char *name; - debug_type type; - enum debug_var_kind kind; - bfd_vma val; +bool +debug_record_variable (void *handle, const char *name, debug_type type, + enum debug_var_kind kind, bfd_vma val) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_namespace **nsp; @@ -1190,11 +1156,9 @@ debug_record_variable (handle, name, type, kind, val) else { if (info->current_block == NULL) - { - debug_error (_("debug_record_variable: no current block")); - return false; - } - nsp = &info->current_block->locals; + nsp = &info->current_file->globals; + else + nsp = &info->current_block->locals; linkage = DEBUG_LINKAGE_AUTOMATIC; } @@ -1202,8 +1166,7 @@ debug_record_variable (handle, name, type, kind, 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; @@ -1211,22 +1174,18 @@ debug_record_variable (handle, name, type, kind, val) n->u.variable = v; - return true; + return true; } /* Make a type with a given kind and size. */ -/*ARGSUSED*/ -static struct debug_type * -debug_make_type (info, kind, size) - struct debug_handle *info ATTRIBUTE_UNUSED; - enum debug_type_kind kind; - unsigned int size; +static struct debug_type_s * +debug_make_type (struct debug_handle *info, + enum debug_type_kind kind, unsigned int size) { - struct debug_type *t; + struct debug_type_s *t; - t = (struct debug_type *) xmalloc (sizeof *t); - memset (t, 0, sizeof *t); + t = debug_xzalloc (info, sizeof (*t)); t->kind = kind; t->size = size; @@ -1238,21 +1197,17 @@ debug_make_type (info, kind, size) which is referenced before it is defined. */ debug_type -debug_make_indirect_type (handle, slot, tag) - PTR handle; - debug_type *slot; - const char *tag; +debug_make_indirect_type (void *handle, debug_type *slot, const char *tag) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_indirect_type *i; t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0); 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; @@ -1265,8 +1220,7 @@ debug_make_indirect_type (handle, slot, tag) /* Make a void type. There is only one of these. */ debug_type -debug_make_void_type (handle) - PTR handle; +debug_make_void_type (void *handle) { struct debug_handle *info = (struct debug_handle *) handle; @@ -1277,13 +1231,10 @@ debug_make_void_type (handle) if the integer is unsigned. */ debug_type -debug_make_int_type (handle, size, unsignedp) - PTR handle; - unsigned int size; - boolean unsignedp; +debug_make_int_type (void *handle, unsigned int size, bool unsignedp) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; t = debug_make_type (info, DEBUG_KIND_INT, size); if (t == NULL) @@ -1299,9 +1250,7 @@ debug_make_int_type (handle, size, unsignedp) the format. */ debug_type -debug_make_float_type (handle, size) - PTR handle; - unsigned int size; +debug_make_float_type (void *handle, unsigned int size) { struct debug_handle *info = (struct debug_handle *) handle; @@ -1311,9 +1260,7 @@ debug_make_float_type (handle, size) /* Make a boolean type of a given size. */ debug_type -debug_make_bool_type (handle, size) - PTR handle; - unsigned int size; +debug_make_bool_type (void *handle, unsigned int size) { struct debug_handle *info = (struct debug_handle *) handle; @@ -1323,9 +1270,7 @@ debug_make_bool_type (handle, size) /* Make a complex type of a given size. */ debug_type -debug_make_complex_type (handle, size) - PTR handle; - unsigned int size; +debug_make_complex_type (void *handle, unsigned int size) { struct debug_handle *info = (struct debug_handle *) handle; @@ -1337,14 +1282,11 @@ debug_make_complex_type (handle, size) The fourth argument is a NULL terminated array of fields. */ debug_type -debug_make_struct_type (handle, structp, size, fields) - PTR handle; - boolean structp; - bfd_vma size; - debug_field *fields; +debug_make_struct_type (void *handle, bool structp, bfd_vma size, + debug_field *fields) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_class_type *c; t = debug_make_type (info, @@ -1353,8 +1295,7 @@ debug_make_struct_type (handle, structp, size, 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; @@ -1371,19 +1312,13 @@ debug_make_struct_type (handle, structp, size, fields) object has its own virtual function table. */ debug_type -debug_make_object_type (handle, structp, size, fields, baseclasses, - methods, vptrbase, ownvptr) - PTR handle; - boolean structp; - bfd_vma size; - debug_field *fields; - debug_baseclass *baseclasses; - debug_method *methods; - debug_type vptrbase; - boolean ownvptr; +debug_make_object_type (void *handle, bool structp, bfd_vma size, + debug_field *fields, debug_baseclass *baseclasses, + debug_method *methods, debug_type vptrbase, + bool ownvptr) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_class_type *c; t = debug_make_type (info, @@ -1392,8 +1327,7 @@ debug_make_object_type (handle, structp, size, fields, baseclasses, 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; @@ -1412,21 +1346,18 @@ debug_make_object_type (handle, structp, size, fields, baseclasses, array of strings, and an array of corresponding values. */ debug_type -debug_make_enum_type (handle, names, values) - PTR handle; - const char **names; - bfd_signed_vma *values; +debug_make_enum_type (void *handle, const char **names, + bfd_signed_vma *values) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_enum_type *e; t = debug_make_type (info, DEBUG_KIND_ENUM, 0); 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; @@ -1439,12 +1370,10 @@ debug_make_enum_type (handle, names, values) /* Make a pointer to a given type. */ debug_type -debug_make_pointer_type (handle, type) - PTR handle; - debug_type type; +debug_make_pointer_type (void *handle, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; if (type == NULL) return DEBUG_TYPE_NULL; @@ -1467,14 +1396,11 @@ debug_make_pointer_type (handle, type) to record the parameter types. */ debug_type -debug_make_function_type (handle, type, arg_types, varargs) - PTR handle; - debug_type type; - debug_type *arg_types; - boolean varargs; +debug_make_function_type (void *handle, debug_type type, + debug_type *arg_types, bool varargs) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_function_type *f; if (type == NULL) @@ -1484,8 +1410,7 @@ debug_make_function_type (handle, type, arg_types, varargs) 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; @@ -1499,12 +1424,10 @@ debug_make_function_type (handle, type, arg_types, varargs) /* Make a reference to a given type. */ debug_type -debug_make_reference_type (handle, type) - PTR handle; - debug_type type; +debug_make_reference_type (void *handle, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; if (type == NULL) return DEBUG_TYPE_NULL; @@ -1521,14 +1444,11 @@ debug_make_reference_type (handle, type) /* Make a range of a given type from a lower to an upper bound. */ debug_type -debug_make_range_type (handle, type, lower, upper) - PTR handle; - debug_type type; - bfd_signed_vma lower; - bfd_signed_vma upper; +debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower, + bfd_signed_vma upper) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_range_type *r; if (type == NULL) @@ -1538,8 +1458,7 @@ debug_make_range_type (handle, type, lower, upper) 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; @@ -1557,17 +1476,12 @@ debug_make_range_type (handle, type, lower, upper) actually a string, as in C. */ debug_type -debug_make_array_type (handle, element_type, range_type, lower, upper, - stringp) - PTR handle; - debug_type element_type; - debug_type range_type; - bfd_signed_vma lower; - bfd_signed_vma upper; - boolean stringp; +debug_make_array_type (void *handle, debug_type element_type, + debug_type range_type, bfd_signed_vma lower, + bfd_signed_vma upper, bool stringp) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_array_type *a; if (element_type == NULL || range_type == NULL) @@ -1577,8 +1491,7 @@ debug_make_array_type (handle, element_type, range_type, lower, upper, 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; @@ -1596,13 +1509,10 @@ debug_make_array_type (handle, element_type, range_type, lower, upper, CHILL. */ debug_type -debug_make_set_type (handle, type, bitstringp) - PTR handle; - debug_type type; - boolean bitstringp; +debug_make_set_type (void *handle, debug_type type, bool bitstringp) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_set_type *s; if (type == NULL) @@ -1612,8 +1522,7 @@ debug_make_set_type (handle, type, bitstringp) 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; @@ -1629,13 +1538,11 @@ debug_make_set_type (handle, type, bitstringp) to. */ debug_type -debug_make_offset_type (handle, base_type, target_type) - PTR handle; - debug_type base_type; - debug_type target_type; +debug_make_offset_type (void *handle, debug_type base_type, + debug_type target_type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_offset_type *o; if (base_type == NULL || target_type == NULL) @@ -1645,8 +1552,7 @@ debug_make_offset_type (handle, base_type, target_type) 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; @@ -1661,15 +1567,12 @@ debug_make_offset_type (handle, base_type, target_type) argument is a NULL terminated array of argument types. */ debug_type -debug_make_method_type (handle, return_type, domain_type, arg_types, varargs) - PTR handle; - debug_type return_type; - debug_type domain_type; - debug_type *arg_types; - boolean varargs; +debug_make_method_type (void *handle, debug_type return_type, + debug_type domain_type, debug_type *arg_types, + bool varargs) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_method_type *m; if (return_type == NULL) @@ -1679,8 +1582,7 @@ debug_make_method_type (handle, return_type, domain_type, arg_types, varargs) 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; @@ -1695,12 +1597,10 @@ debug_make_method_type (handle, return_type, domain_type, arg_types, varargs) /* Make a const qualified version of a given type. */ debug_type -debug_make_const_type (handle, type) - PTR handle; - debug_type type; +debug_make_const_type (void *handle, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; if (type == NULL) return DEBUG_TYPE_NULL; @@ -1717,12 +1617,10 @@ debug_make_const_type (handle, type) /* Make a volatile qualified version of a given type. */ debug_type -debug_make_volatile_type (handle, type) - PTR handle; - debug_type type; +debug_make_volatile_type (void *handle, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; if (type == NULL) return DEBUG_TYPE_NULL; @@ -1740,13 +1638,11 @@ debug_make_volatile_type (handle, type) been mentioned, but not defined. */ debug_type -debug_make_undefined_tagged_type (handle, name, kind) - PTR handle; - const char *name; - enum debug_type_kind kind; +debug_make_undefined_tagged_type (void *handle, const char *name, + enum debug_type_kind kind) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; if (name == NULL) return DEBUG_TYPE_NULL; @@ -1778,23 +1674,19 @@ debug_make_undefined_tagged_type (handle, name, kind) The fourth argument is whether this is a virtual class. The fifth argument is the visibility of the base class. */ -/*ARGSUSED*/ debug_baseclass -debug_make_baseclass (handle, type, bitpos, virtual, visibility) - PTR handle ATTRIBUTE_UNUSED; - debug_type type; - bfd_vma bitpos; - boolean virtual; - enum debug_visibility visibility; -{ - struct debug_baseclass *b; - - b = (struct debug_baseclass *) xmalloc (sizeof *b); - memset (b, 0, sizeof *b); +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 = debug_xzalloc (info, sizeof (*b)); b->type = type; b->bitpos = bitpos; - b->virtual = virtual; + b->is_virtual = is_virtual; b->visibility = visibility; return b; @@ -1806,20 +1698,15 @@ debug_make_baseclass (handle, type, bitpos, virtual, visibility) the field (it may be zero). The sixth argument is the visibility of the field. */ -/*ARGSUSED*/ debug_field -debug_make_field (handle, name, type, bitpos, bitsize, visibility) - PTR handle ATTRIBUTE_UNUSED; - const char *name; - debug_type type; - bfd_vma bitpos; - bfd_vma bitsize; - enum debug_visibility visibility; +debug_make_field (void *handle, const char *name, + debug_type type, bfd_vma bitpos, bfd_vma bitsize, + enum debug_visibility visibility) { - struct debug_field *f; + struct debug_handle *info = (struct debug_handle *) handle; + struct debug_field_s *f; - f = (struct debug_field *) xmalloc (sizeof *f); - memset (f, 0, sizeof *f); + f = debug_xzalloc (info, sizeof (*f)); f->name = name; f->type = type; @@ -1837,19 +1724,15 @@ debug_make_field (handle, name, type, bitpos, bitsize, visibility) global variable). The fifth argument is the visibility of the member. */ -/*ARGSUSED*/ debug_field -debug_make_static_member (handle, name, type, physname, visibility) - PTR handle ATTRIBUTE_UNUSED; - const char *name; - debug_type type; - const char *physname; - enum debug_visibility visibility; +debug_make_static_member (void *handle, const char *name, + debug_type type, const char *physname, + enum debug_visibility visibility) { - struct debug_field *f; + struct debug_handle *info = (struct debug_handle *) handle; + struct debug_field_s *f; - f = (struct debug_field *) xmalloc (sizeof *f); - memset (f, 0, sizeof *f); + f = debug_xzalloc (info, sizeof (*f)); f->name = name; f->type = type; @@ -1863,17 +1746,14 @@ debug_make_static_member (handle, name, type, physname, visibility) /* Make a method. The second argument is the name, and the third argument is a NULL terminated array of method variants. */ -/*ARGSUSED*/ debug_method -debug_make_method (handle, name, variants) - PTR handle ATTRIBUTE_UNUSED; - const char *name; - debug_method_variant *variants; +debug_make_method (void *handle, const char *name, + debug_method_variant *variants) { - struct debug_method *m; + struct debug_handle *info = (struct debug_handle *) handle; + struct debug_method_s *m; - m = (struct debug_method *) xmalloc (sizeof *m); - memset (m, 0, sizeof *m); + m = debug_xzalloc (info, sizeof (*m)); m->name = name; m->variants = variants; @@ -1890,23 +1770,17 @@ debug_make_method (handle, name, variants) function context. FIXME: Are the const and volatile arguments necessary? Could we just use debug_make_const_type? */ -/*ARGSUSED*/ debug_method_variant -debug_make_method_variant (handle, physname, type, visibility, constp, - volatilep, voffset, context) - PTR handle ATTRIBUTE_UNUSED; - const char *physname; - debug_type type; - enum debug_visibility visibility; - boolean constp; - boolean volatilep; - bfd_vma voffset; - debug_type context; -{ - struct debug_method_variant *m; - - m = (struct debug_method_variant *) xmalloc (sizeof *m); - memset (m, 0, sizeof *m); +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 = debug_xzalloc (info, sizeof (*m)); m->physname = physname; m->type = type; @@ -1924,19 +1798,15 @@ debug_make_method_variant (handle, physname, type, visibility, constp, since a static method can not also be virtual. */ debug_method_variant -debug_make_static_method_variant (handle, physname, type, visibility, - constp, volatilep) - PTR handle ATTRIBUTE_UNUSED; - const char *physname; - debug_type type; - enum debug_visibility visibility; - boolean constp; - boolean volatilep; +debug_make_static_method_variant (void *handle, + const char *physname, debug_type type, + enum debug_visibility visibility, + bool constp, bool volatilep) { - struct debug_method_variant *m; + struct debug_handle *info = (struct debug_handle *) handle; + struct debug_method_variant_s *m; - m = (struct debug_method_variant *) xmalloc (sizeof *m); - memset (m, 0, sizeof *m); + m = debug_xzalloc (info, sizeof (*m)); m->physname = physname; m->type = type; @@ -1951,13 +1821,10 @@ debug_make_static_method_variant (handle, physname, type, visibility, /* Name a type. */ debug_type -debug_name_type (handle, name, type) - PTR handle; - const char *name; - debug_type type; +debug_name_type (void *handle, const char *name, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_named_type *n; struct debug_name *nm; @@ -1975,8 +1842,7 @@ debug_name_type (handle, name, 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; @@ -2000,13 +1866,10 @@ debug_name_type (handle, name, type) /* Tag a type. */ debug_type -debug_tag_type (handle, name, type) - PTR handle; - const char *name; - debug_type type; +debug_tag_type (void *handle, const char *name, debug_type type) { struct debug_handle *info = (struct debug_handle *) handle; - struct debug_type *t; + struct debug_type_s *t; struct debug_named_type *n; struct debug_name *nm; @@ -2031,8 +1894,7 @@ debug_tag_type (handle, name, 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; @@ -2055,12 +1917,9 @@ debug_tag_type (handle, name, type) /* Record the size of a given type. */ -/*ARGSUSED*/ -boolean -debug_record_type_size (handle, type, size) - PTR handle ATTRIBUTE_UNUSED; - debug_type type; - unsigned int size; +bool +debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type, + unsigned int size) { if (type->size != 0 && type->size != size) fprintf (stderr, _("Warning: changing type size from %d to %d\n"), @@ -2074,9 +1933,7 @@ debug_record_type_size (handle, type, size) /* Find a named type. */ debug_type -debug_find_named_type (handle, name) - PTR handle; - const char *name; +debug_find_named_type (void *handle, const char *name) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_block *b; @@ -2123,16 +1980,14 @@ debug_find_named_type (handle, name) } } - return DEBUG_TYPE_NULL; + return DEBUG_TYPE_NULL; } /* Find a tagged type. */ debug_type -debug_find_tagged_type (handle, name, kind) - PTR handle; - const char *name; - enum debug_type_kind kind; +debug_find_tagged_type (void *handle, const char *name, + enum debug_type_kind kind) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_unit *u; @@ -2169,11 +2024,9 @@ debug_find_tagged_type (handle, name, kind) /* Get a base type. We build a linked list on the stack to avoid crashing if the type is defined circularly. */ -static struct debug_type * -debug_get_real_type (handle, type, list) - PTR handle; - debug_type type; - struct debug_type_real_list *list; +static struct debug_type_s * +debug_get_real_type (void *handle, debug_type type, + struct debug_type_real_list *list) { struct debug_type_real_list *l; struct debug_type_real_list rl; @@ -2191,7 +2044,7 @@ debug_get_real_type (handle, type, list) for (l = list; l != NULL; l = l->next) { - if (l->t == type) + if (l->t == type || l == l->next) { fprintf (stderr, _("debug_get_real_type: circular debug information for %s\n"), @@ -2208,7 +2061,9 @@ debug_get_real_type (handle, type, list) /* The default case is just here to avoid warnings. */ default: case DEBUG_KIND_INDIRECT: - if (*type->u.kindirect->slot != NULL) + /* A valid non-self-referencing indirect type. */ + if (*type->u.kindirect->slot != NULL + && *type->u.kindirect->slot != type) return debug_get_real_type (handle, *type->u.kindirect->slot, &rl); return type; case DEBUG_KIND_NAMED: @@ -2221,9 +2076,7 @@ debug_get_real_type (handle, type, list) /* Get the kind of a type. */ enum debug_type_kind -debug_get_type_kind (handle, type) - PTR handle; - debug_type type; +debug_get_type_kind (void *handle, debug_type type) { if (type == NULL) return DEBUG_KIND_ILLEGAL; @@ -2236,13 +2089,13 @@ debug_get_type_kind (handle, type) /* Get the name of a type. */ const char * -debug_get_type_name (handle, type) - PTR handle; - debug_type type; +debug_get_type_name (void *handle, debug_type type) { if (type->kind == DEBUG_KIND_INDIRECT) { - if (*type->u.kindirect->slot != NULL) + /* A valid non-self-referencing indirect type. */ + if (*type->u.kindirect->slot != NULL + && *type->u.kindirect->slot != type) return debug_get_type_name (handle, *type->u.kindirect->slot); return type->u.kindirect->tag; } @@ -2255,9 +2108,7 @@ debug_get_type_name (handle, type) /* Get the size of a type. */ bfd_vma -debug_get_type_size (handle, type) - PTR handle; - debug_type type; +debug_get_type_size (void *handle, debug_type type) { if (type == NULL) return 0; @@ -2273,7 +2124,9 @@ debug_get_type_size (handle, type) default: return 0; case DEBUG_KIND_INDIRECT: - if (*type->u.kindirect->slot != NULL) + /* A valid non-self-referencing indirect type. */ + if (*type->u.kindirect->slot != NULL + && *type->u.kindirect->slot != type) return debug_get_type_size (handle, *type->u.kindirect->slot); return 0; case DEBUG_KIND_NAMED: @@ -2286,15 +2139,15 @@ debug_get_type_size (handle, type) /* Get the return type of a function or method type. */ debug_type -debug_get_return_type (handle, type) - PTR handle; - debug_type type; +debug_get_return_type (void *handle, debug_type type) { if (type == NULL) return DEBUG_TYPE_NULL; + type = debug_get_real_type (handle, type, NULL); if (type == NULL) return DEBUG_TYPE_NULL; + switch (type->kind) { default: @@ -2304,23 +2157,23 @@ debug_get_return_type (handle, type) case DEBUG_KIND_METHOD: return type->u.kmethod->return_type; } - /*NOTREACHED*/ + /*NOTREACHED*/ } /* Get the parameter types of a function or method type (except that we don't currently store the parameter types of a function). */ const debug_type * -debug_get_parameter_types (handle, type, pvarargs) - PTR handle; - debug_type type; - boolean *pvarargs; +debug_get_parameter_types (void *handle, debug_type type, + bool *pvarargs) { if (type == NULL) return NULL; + type = debug_get_real_type (handle, type, NULL); if (type == NULL) return NULL; + switch (type->kind) { default: @@ -2338,15 +2191,15 @@ debug_get_parameter_types (handle, type, pvarargs) /* Get the target type of a type. */ debug_type -debug_get_target_type (handle, type) - PTR handle; - debug_type type; +debug_get_target_type (void *handle, debug_type type) { if (type == NULL) return NULL; + type = debug_get_real_type (handle, type, NULL); if (type == NULL) return NULL; + switch (type->kind) { default: @@ -2367,15 +2220,15 @@ debug_get_target_type (handle, type) class. */ const debug_field * -debug_get_fields (handle, type) - PTR handle; - debug_type type; +debug_get_fields (void *handle, debug_type type) { if (type == NULL) return NULL; + type = debug_get_real_type (handle, type, NULL); if (type == NULL) return NULL; + switch (type->kind) { default: @@ -2391,11 +2244,8 @@ debug_get_fields (handle, type) /* Get the type of a field. */ -/*ARGSUSED*/ debug_type -debug_get_field_type (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL) return NULL; @@ -2404,11 +2254,8 @@ debug_get_field_type (handle, field) /* Get the name of a field. */ -/*ARGSUSED*/ const char * -debug_get_field_name (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL) return NULL; @@ -2417,11 +2264,8 @@ debug_get_field_name (handle, field) /* Get the bit position of a field. */ -/*ARGSUSED*/ bfd_vma -debug_get_field_bitpos (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL || field->static_member) return (bfd_vma) -1; @@ -2430,11 +2274,8 @@ debug_get_field_bitpos (handle, field) /* Get the bit size of a field. */ -/*ARGSUSED*/ bfd_vma -debug_get_field_bitsize (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL || field->static_member) return (bfd_vma) -1; @@ -2443,11 +2284,8 @@ debug_get_field_bitsize (handle, field) /* Get the visibility of a field. */ -/*ARGSUSED*/ enum debug_visibility -debug_get_field_visibility (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL) return DEBUG_VISIBILITY_IGNORE; @@ -2457,9 +2295,7 @@ debug_get_field_visibility (handle, field) /* Get the physical name of a field. */ const char * -debug_get_field_physname (handle, field) - PTR handle ATTRIBUTE_UNUSED; - debug_field field; +debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field) { if (field == NULL || ! field->static_member) return NULL; @@ -2469,11 +2305,8 @@ debug_get_field_physname (handle, field) /* Write out the debugging information. This is given a handle to debugging information, and a set of function pointers to call. */ -boolean -debug_write (handle, fns, fhandle) - PTR handle; - const struct debug_write_fns *fns; - PTR fhandle; +bool +debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle) { struct debug_handle *info = (struct debug_handle *) handle; struct debug_unit *u; @@ -2496,7 +2329,7 @@ debug_write (handle, fns, fhandle) for (u = info->units; u != NULL; u = u->next) { struct debug_file *f; - boolean first_file; + bool first_file; info->current_write_lineno = u->linenos; info->current_write_lineno_index = 0; @@ -2511,20 +2344,13 @@ debug_write (handle, fns, fhandle) if (first_file) first_file = false; - else - { - if (! (*fns->start_source) (fhandle, f->filename)) - return false; - } + else if (! (*fns->start_source) (fhandle, f->filename)) + return false; if (f->globals != NULL) - { - for (n = f->globals->list; n != NULL; n = n->next) - { - if (! debug_write_name (info, fns, fhandle, n)) - return false; - } - } + for (n = f->globals->list; n != NULL; n = n->next) + if (! debug_write_name (info, fns, fhandle, n)) + return false; } /* Output any line number information which hasn't already been @@ -2538,12 +2364,10 @@ debug_write (handle, fns, fhandle) /* Write out an element in a namespace. */ -static boolean -debug_write_name (info, fns, fhandle, n) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - struct debug_name *n; +static bool +debug_write_name (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + struct debug_name *n) { switch (n->kind) { @@ -2588,18 +2412,21 @@ debug_write_name (info, fns, fhandle, n) then the name argument is a tag from a DEBUG_KIND_TAGGED type which points to this one. */ -static boolean -debug_write_type (info, fns, fhandle, type, name) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - struct debug_type *type; - struct debug_name *name; +static bool +debug_write_type (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + struct debug_type_s *type, struct debug_name *name) { unsigned int i; int is; const char *tag = NULL; + if (type == DEBUG_TYPE_NULL) + return (*fns->empty_type) (fhandle); + + /* Mark the type so that we don't define a type in terms of itself. */ + type->mark = info->mark; + /* If we have a name for this type, just output it. We only output typedef names after they have been defined. We output type tags whenever we are not actually defining them. */ @@ -2613,10 +2440,10 @@ debug_write_type (info, fns, fhandle, type, name) return (*fns->typedef_type) (fhandle, type->u.knamed->name->name); else { - struct debug_type *real; + struct debug_type_s *real; unsigned int id; - real = debug_get_real_type ((PTR) info, type, NULL); + real = debug_get_real_type ((void *) info, type, NULL); if (real == NULL) return (*fns->empty_type) (fhandle); id = 0; @@ -2662,7 +2489,9 @@ debug_write_type (info, fns, fhandle, type, name) debug_error (_("debug_write_type: illegal type encountered")); return false; case DEBUG_KIND_INDIRECT: - if (*type->u.kindirect->slot == DEBUG_TYPE_NULL) + /* Prevent infinite recursion. */ + if (*type->u.kindirect->slot != DEBUG_TYPE_NULL + && (*type->u.kindirect->slot)->mark == info->mark) return (*fns->empty_type) (fhandle); return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot, name); @@ -2710,7 +2539,7 @@ debug_write_type (info, fns, fhandle, type, name) { for (i = 0; type->u.kclass->fields[i] != NULL; i++) { - struct debug_field *f; + struct debug_field_s *f; f = type->u.kclass->fields[i]; if (! debug_write_type (info, fns, fhandle, f->type, @@ -2836,17 +2665,14 @@ debug_write_type (info, fns, fhandle, type, name) /* Write out a class type. */ -static boolean -debug_write_class_type (info, fns, fhandle, type, tag) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - struct debug_type *type; - const char *tag; +static bool +debug_write_class_type (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + struct debug_type_s *type, const char *tag) { unsigned int i; unsigned int id; - struct debug_type *vptrbase; + struct debug_type_s *vptrbase; if (type->u.kclass == NULL) { @@ -2895,7 +2721,7 @@ debug_write_class_type (info, fns, fhandle, type, tag) { for (i = 0; type->u.kclass->fields[i] != NULL; i++) { - struct debug_field *f; + struct debug_field_s *f; f = type->u.kclass->fields[i]; if (! debug_write_type (info, fns, fhandle, f->type, @@ -2921,13 +2747,13 @@ debug_write_class_type (info, fns, fhandle, type, tag) { for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++) { - struct debug_baseclass *b; + struct debug_baseclass_s *b; b = type->u.kclass->baseclasses[i]; if (! debug_write_type (info, fns, fhandle, b->type, (struct debug_name *) NULL)) return false; - if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual, + if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->is_virtual, b->visibility)) return false; } @@ -2937,7 +2763,7 @@ debug_write_class_type (info, fns, fhandle, type, tag) { for (i = 0; type->u.kclass->methods[i] != NULL; i++) { - struct debug_method *m; + struct debug_method_s *m; unsigned int j; m = type->u.kclass->methods[i]; @@ -2945,7 +2771,7 @@ debug_write_class_type (info, fns, fhandle, type, tag) return false; for (j = 0; m->variants[j] != NULL; j++) { - struct debug_method_variant *v; + struct debug_method_variant_s *v; v = m->variants[j]; if (v->context != NULL) @@ -2988,14 +2814,11 @@ debug_write_class_type (info, fns, fhandle, type, tag) /* Write out information for a function. */ -static boolean -debug_write_function (info, fns, fhandle, name, linkage, function) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - const char *name; - enum debug_object_linkage linkage; - struct debug_function *function; +static bool +debug_write_function (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + const char *name, enum debug_object_linkage linkage, + struct debug_function *function) { struct debug_parameter *p; struct debug_block *b; @@ -3030,12 +2853,10 @@ debug_write_function (info, fns, fhandle, name, linkage, function) /* Write out information for a block. */ -static boolean -debug_write_block (info, fns, fhandle, block) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - struct debug_block *block; +static bool +debug_write_block (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + struct debug_block *block) { struct debug_name *n; struct debug_block *b; @@ -3080,12 +2901,10 @@ debug_write_block (info, fns, fhandle, block) /* Write out line number information up to ADDRESS. */ -static boolean -debug_write_linenos (info, fns, fhandle, address) - struct debug_handle *info; - const struct debug_write_fns *fns; - PTR fhandle; - bfd_vma address; +static bool +debug_write_linenos (struct debug_handle *info, + const struct debug_write_fns *fns, void *fhandle, + bfd_vma address) { while (info->current_write_lineno != NULL) { @@ -3122,11 +2941,9 @@ debug_write_linenos (info, fns, fhandle, address) name, we use the same ID. This type of things happens because the same struct will be defined by multiple compilation units. */ -static boolean -debug_set_class_id (info, tag, type) - struct debug_handle *info; - const char *tag; - struct debug_type *type; +static bool +debug_set_class_id (struct debug_handle *info, const char *tag, + struct debug_type_s *type) { struct debug_class_type *c; struct debug_class_id *l; @@ -3171,8 +2988,7 @@ debug_set_class_id (info, tag, 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; @@ -3186,15 +3002,13 @@ debug_set_class_id (info, tag, type) /* See if two types are the same. At this point, we don't care about tags and the like. */ -static boolean -debug_type_samep (info, t1, t2) - struct debug_handle *info; - struct debug_type *t1; - struct debug_type *t2; +static bool +debug_type_samep (struct debug_handle *info, struct debug_type_s *t1, + struct debug_type_s *t2) { struct debug_type_compare_list *l; struct debug_type_compare_list top; - boolean ret; + bool ret; if (t1 == NULL) return t2 == NULL; @@ -3314,7 +3128,7 @@ debug_type_samep (info, t1, t2) case DEBUG_KIND_POINTER: ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer); break; - + case DEBUG_KIND_FUNCTION: if (t1->u.kfunction->varargs != t2->u.kfunction->varargs || ! debug_type_samep (info, t1->u.kfunction->return_type, @@ -3326,7 +3140,7 @@ debug_type_samep (info, t1, t2) ret = true; else { - struct debug_type **a1, **a2; + struct debug_type_s **a1, **a2; a1 = t1->u.kfunction->arg_types; a2 = t2->u.kfunction->arg_types; @@ -3350,6 +3164,7 @@ debug_type_samep (info, t1, t2) && t1->u.krange->upper == t2->u.krange->upper && debug_type_samep (info, t1->u.krange->type, t2->u.krange->type)); + break; case DEBUG_KIND_ARRAY: ret = (t1->u.karray->lower == t2->u.karray->lower @@ -3384,7 +3199,7 @@ debug_type_samep (info, t1, t2) ret = true; else { - struct debug_type **a1, **a2; + struct debug_type_s **a1, **a2; a1 = t1->u.kmethod->arg_types; a2 = t2->u.kmethod->arg_types; @@ -3423,11 +3238,9 @@ debug_type_samep (info, t1, t2) /* See if two classes are the same. This is a subroutine of debug_type_samep. */ -static boolean -debug_class_type_samep (info, t1, t2) - struct debug_handle *info; - struct debug_type *t1; - struct debug_type *t2; +static bool +debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1, + struct debug_type_s *t2) { struct debug_class_type *c1, *c2; @@ -3442,13 +3255,13 @@ debug_class_type_samep (info, t1, t2) if (c1->fields != NULL) { - struct debug_field **pf1, **pf2; + struct debug_field_s **pf1, **pf2; for (pf1 = c1->fields, pf2 = c2->fields; *pf1 != NULL && *pf2 != NULL; pf1++, pf2++) { - struct debug_field *f1, *f2; + struct debug_field_s *f1, *f2; f1 = *pf1; f2 = *pf2; @@ -3472,10 +3285,12 @@ debug_class_type_samep (info, t1, t2) names, since that sometimes fails in the presence of typedefs and we really don't care. */ if (strcmp (f1->name, f2->name) != 0 + || f1->type == NULL + || f2->type == NULL || ! debug_type_samep (info, - debug_get_real_type ((PTR) info, + debug_get_real_type ((void *) info, f1->type, NULL), - debug_get_real_type ((PTR) info, + debug_get_real_type ((void *) info, f2->type, NULL))) return false; } @@ -3491,18 +3306,18 @@ debug_class_type_samep (info, t1, t2) if (c1->baseclasses != NULL) { - struct debug_baseclass **pb1, **pb2; + struct debug_baseclass_s **pb1, **pb2; for (pb1 = c1->baseclasses, pb2 = c2->baseclasses; *pb1 != NULL && *pb2 != NULL; ++pb1, ++pb2) { - struct debug_baseclass *b1, *b2; + struct debug_baseclass_s *b1, *b2; b1 = *pb1; b2 = *pb2; if (b1->bitpos != b2->bitpos - || b1->virtual != b2->virtual + || b1->is_virtual != b2->is_virtual || b1->visibility != b2->visibility || ! debug_type_samep (info, b1->type, b2->type)) return false; @@ -3513,13 +3328,13 @@ debug_class_type_samep (info, t1, t2) if (c1->methods != NULL) { - struct debug_method **pm1, **pm2; + struct debug_method_s **pm1, **pm2; for (pm1 = c1->methods, pm2 = c2->methods; *pm1 != NULL && *pm2 != NULL; ++pm1, ++pm2) { - struct debug_method *m1, *m2; + struct debug_method_s *m1, *m2; m1 = *pm1; m2 = *pm2; @@ -3527,15 +3342,15 @@ debug_class_type_samep (info, t1, t2) || strcmp (m1->name, m2->name) != 0 || (m1->variants == NULL) != (m2->variants == NULL)) return false; - if (m1->variants == NULL) + if (m1->variants != NULL) { - struct debug_method_variant **pv1, **pv2; + struct debug_method_variant_s **pv1, **pv2; for (pv1 = m1->variants, pv2 = m2->variants; *pv1 != NULL && *pv2 != NULL; ++pv1, ++pv2) { - struct debug_method_variant *v1, *v2; + struct debug_method_variant_s *v1, *v2; v1 = *pv1; v2 = *pv2;