Fix an attempt to allocate an overlarge amount of memory when decoding a corrupt...
[binutils-gdb.git] / binutils / debug.c
index b49aef5c1a71cd83a504eaee74463902acc43416..53b45879e008baf1efb12631cb7748582156bc33 100644 (file)
@@ -1,5 +1,5 @@
 /* debug.c -- Handle generic debugging information.
-   Copyright (C) 1995-2021 Free Software Foundation, Inc.
+   Copyright (C) 1995-2023 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
@@ -31,6 +31,7 @@
 #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
@@ -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.  */
@@ -111,7 +114,7 @@ struct debug_type_s
       struct debug_indirect_type *kindirect;
       /* DEBUG_KIND_INT.  */
       /* Whether the integer is unsigned.  */
-      bfd_boolean kint;
+      bool kint;
       /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
          DEBUG_KIND_UNION_CLASS.  */
       struct debug_class_type *kclass;
@@ -194,7 +197,7 @@ struct debug_function_type
   /* NULL terminated array of argument types.  */
   debug_type *arg_types;
   /* Whether the function takes a variable number of arguments.  */
-  bfd_boolean varargs;
+  bool varargs;
 };
 
 /* Information kept for a range.  */
@@ -222,7 +225,7 @@ struct debug_array_type
   /* Upper bound.  */
   bfd_signed_vma upper;
   /* Whether this array is really a string.  */
-  bfd_boolean stringp;
+  bool stringp;
 };
 
 /* Information kept for a set.  */
@@ -232,7 +235,7 @@ struct debug_set_type
   /* Base type.  */
   debug_type type;
   /* Whether this set is really a bitstring.  */
-  bfd_boolean bitstringp;
+  bool bitstringp;
 };
 
 /* Information kept for an offset type (a based pointer).  */
@@ -256,7 +259,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.  */
-  bfd_boolean varargs;
+  bool varargs;
 };
 
 /* Information kept for a named type.  */
@@ -280,7 +283,7 @@ struct debug_field_s
   /* Visibility of the field.  */
   enum debug_visibility visibility;
   /* Whether this is a static member.  */
-  bfd_boolean static_member;
+  bool static_member;
   union
     {
       /* If static_member is false.  */
@@ -308,7 +311,7 @@ struct debug_baseclass_s
   /* Bit position of the base class in the object.  */
   unsigned int bitpos;
   /* Whether the base class is virtual.  */
-  bfd_boolean is_virtual;
+  bool is_virtual;
   /* Visibility of the base class.  */
   enum debug_visibility visibility;
 };
@@ -335,9 +338,9 @@ struct debug_method_variant_s
   /* The visibility of the function.  */
   enum debug_visibility visibility;
   /* Whether the function is const.  */
-  bfd_boolean constp;
+  bool constp;
   /* Whether the function is volatile.  */
-  bfd_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.  */
@@ -565,28 +568,28 @@ 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 bfd_boolean debug_write_name
+static bool debug_write_name
   (struct debug_handle *, const struct debug_write_fns *, void *,
    struct debug_name *);
-static bfd_boolean debug_write_type
+static bool debug_write_type
   (struct debug_handle *, const struct debug_write_fns *, void *,
    struct debug_type_s *, struct debug_name *);
-static bfd_boolean debug_write_class_type
+static bool debug_write_class_type
   (struct debug_handle *, const struct debug_write_fns *, void *,
    struct debug_type_s *, const char *);
-static bfd_boolean debug_write_function
+static bool debug_write_function
   (struct debug_handle *, const struct debug_write_fns *, void *,
    const char *, enum debug_object_linkage, struct debug_function *);
-static bfd_boolean debug_write_block
+static bool debug_write_block
   (struct debug_handle *, const struct debug_write_fns *, void *,
    struct debug_block *);
-static bfd_boolean debug_write_linenos
+static bool debug_write_linenos
   (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
-static bfd_boolean debug_set_class_id
+static bool debug_set_class_id
   (struct debug_handle *, const char *, struct debug_type_s *);
-static bfd_boolean debug_type_samep
+static bool debug_type_samep
   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
-static bfd_boolean debug_class_type_samep
+static bool debug_class_type_samep
   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
 \f
 /* Issue an error message.  */
@@ -600,7 +603,7 @@ debug_error (const char *message)
 /* 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)
@@ -608,8 +611,7 @@ debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
   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;
@@ -618,8 +620,7 @@ debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
   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;
 
@@ -659,19 +660,36 @@ debug_add_to_current_namespace (struct debug_handle *info, const char *name,
 /* 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
    unit.  */
 
-bfd_boolean
+bool
 debug_set_filename (void *handle, const char *name)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -681,13 +699,11 @@ debug_set_filename (void *handle, const char *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;
@@ -706,13 +722,13 @@ debug_set_filename (void *handle, const char *name)
   info->current_block = NULL;
   info->current_lineno = NULL;
 
-  return TRUE;
+  return true;
 }
 
 /* Change source files to the given file name.  This is used for
    include files in a single compilation unit.  */
 
-bfd_boolean
+bool
 debug_start_source (void *handle, const char *name)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -724,7 +740,7 @@ debug_start_source (void *handle, const char *name)
   if (info->current_unit == NULL)
     {
       debug_error (_("debug_start_source: no debug_set_filename call"));
-      return FALSE;
+      return false;
     }
 
   for (f = info->current_unit->files; f != NULL; f = f->next)
@@ -732,13 +748,11 @@ debug_start_source (void *handle, const char *name)
       if (filename_cmp (f->filename, name) == 0)
        {
          info->current_file = f;
-         return TRUE;
+         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;
@@ -749,7 +763,7 @@ debug_start_source (void *handle, const char *name)
 
   info->current_file = f;
 
-  return TRUE;
+  return true;
 }
 
 /* Record a function definition.  This implicitly starts a function
@@ -760,9 +774,9 @@ debug_start_source (void *handle, const char *name)
    debug_record_parameter.  FIXME: There is no way to specify nested
    functions.  */
 
-bfd_boolean
+bool
 debug_record_function (void *handle, const char *name,
-                      debug_type return_type, bfd_boolean global,
+                      debug_type return_type, bool global,
                       bfd_vma addr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -773,21 +787,19 @@ debug_record_function (void *handle, const char *name,
   if (name == NULL)
     name = "";
   if (return_type == NULL)
-    return FALSE;
+    return false;
 
   if (info->current_unit == NULL)
     {
       debug_error (_("debug_record_function: no debug_set_filename call"));
-      return FALSE;
+      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;
@@ -807,16 +819,16 @@ debug_record_function (void *handle, const char *name,
                               ? DEBUG_LINKAGE_GLOBAL
                               : DEBUG_LINKAGE_STATIC));
   if (n == NULL)
-    return FALSE;
+    return false;
 
   n->u.function = f;
 
-  return TRUE;
+  return true;
 }
 
 /* Record a parameter for the current function.  */
 
-bfd_boolean
+bool
 debug_record_parameter (void *handle, const char *name, debug_type type,
                        enum debug_parm_kind kind, bfd_vma val)
 {
@@ -824,17 +836,16 @@ debug_record_parameter (void *handle, const char *name, debug_type type,
   struct debug_parameter *p, **pp;
 
   if (name == NULL || type == NULL)
-    return FALSE;
+    return false;
 
   if (info->current_unit == NULL
       || info->current_function == NULL)
     {
       debug_error (_("debug_record_parameter: no current function"));
-      return FALSE;
+      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;
@@ -847,12 +858,12 @@ debug_record_parameter (void *handle, const char *name, debug_type type,
     ;
   *pp = p;
 
-  return TRUE;
+  return true;
 }
 
 /* End a function.  FIXME: This should handle function nesting.  */
 
-bfd_boolean
+bool
 debug_end_function (void *handle, bfd_vma addr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -862,13 +873,13 @@ debug_end_function (void *handle, bfd_vma addr)
       || info->current_function == NULL)
     {
       debug_error (_("debug_end_function: no current function"));
-      return FALSE;
+      return false;
     }
 
   if (info->current_block->parent != NULL)
     {
       debug_error (_("debug_end_function: some blocks were not closed"));
-      return FALSE;
+      return false;
     }
 
   info->current_block->end = addr;
@@ -876,7 +887,7 @@ debug_end_function (void *handle, bfd_vma addr)
   info->current_function = NULL;
   info->current_block = NULL;
 
-  return TRUE;
+  return true;
 }
 
 /* Start a block in a function.  All local information will be
@@ -884,7 +895,7 @@ debug_end_function (void *handle, bfd_vma addr)
    debug_start_block and debug_end_block may be nested.  The bfd_vma
    argument is the address at which this block starts.  */
 
-bfd_boolean
+bool
 debug_start_block (void *handle, bfd_vma addr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -896,11 +907,10 @@ debug_start_block (void *handle, bfd_vma addr)
       || info->current_block == NULL)
     {
       debug_error (_("debug_start_block: no current block"));
-      return FALSE;
+      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;
@@ -915,14 +925,14 @@ debug_start_block (void *handle, bfd_vma addr)
 
   info->current_block = b;
 
-  return TRUE;
+  return true;
 }
 
 /* Finish a block in a function.  This matches the call to
    debug_start_block.  The argument is the address at which this block
    ends.  */
 
-bfd_boolean
+bool
 debug_end_block (void *handle, bfd_vma addr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -932,27 +942,27 @@ debug_end_block (void *handle, bfd_vma addr)
       || info->current_block == NULL)
     {
       debug_error (_("debug_end_block: no current block"));
-      return FALSE;
+      return false;
     }
 
   parent = info->current_block->parent;
   if (parent == NULL)
     {
       debug_error (_("debug_end_block: attempt to close top level block"));
-      return FALSE;
+      return false;
     }
 
   info->current_block->end = addr;
 
   info->current_block = parent;
 
-  return TRUE;
+  return true;
 }
 
 /* Associate a line number in the current source file and function
    with a given address.  */
 
-bfd_boolean
+bool
 debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -962,7 +972,7 @@ debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
   if (info->current_unit == NULL)
     {
       debug_error (_("debug_record_line: no current unit"));
-      return FALSE;
+      return false;
     }
 
   l = info->current_lineno;
@@ -974,7 +984,7 @@ debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
            {
              l->linenos[i] = lineno;
              l->addrs[i] = addr;
-             return TRUE;
+             return true;
            }
        }
     }
@@ -987,8 +997,7 @@ debug_record_line (void *handle, unsigned long lineno, bfd_vma 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;
@@ -1003,77 +1012,77 @@ debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
 
   info->current_lineno = l;
 
-  return TRUE;
+  return true;
 }
 
 /* Start a named common block.  This is a block of variables that may
    move in memory.  */
 
-bfd_boolean
+bool
 debug_start_common_block (void *handle ATTRIBUTE_UNUSED,
                          const char *name ATTRIBUTE_UNUSED)
 {
   /* FIXME */
   debug_error (_("debug_start_common_block: not implemented"));
-  return FALSE;
+  return false;
 }
 
 /* End a named common block.  */
 
-bfd_boolean
+bool
 debug_end_common_block (void *handle ATTRIBUTE_UNUSED,
                        const char *name ATTRIBUTE_UNUSED)
 {
   /* FIXME */
   debug_error (_("debug_end_common_block: not implemented"));
-  return FALSE;
+  return false;
 }
 
 /* Record a named integer constant.  */
 
-bfd_boolean
+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;
 
   if (name == NULL)
-    return FALSE;
+    return false;
 
   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
                                      DEBUG_LINKAGE_NONE);
   if (n == NULL)
-    return FALSE;
+    return false;
 
   n->u.int_constant = val;
 
-  return TRUE;
+  return true;
 }
 
 /* Record a named floating point constant.  */
 
-bfd_boolean
+bool
 debug_record_float_const (void *handle, const char *name, double val)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_name *n;
 
   if (name == NULL)
-    return FALSE;
+    return false;
 
   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
                                      DEBUG_LINKAGE_NONE);
   if (n == NULL)
-    return FALSE;
+    return false;
 
   n->u.float_constant = val;
 
-  return TRUE;
+  return true;
 }
 
 /* Record a typed constant with an integral value.  */
 
-bfd_boolean
+bool
 debug_record_typed_const (void *handle, const char *name, debug_type type,
                          bfd_vma val)
 {
@@ -1082,27 +1091,26 @@ debug_record_typed_const (void *handle, const char *name, debug_type type,
   struct debug_typed_constant *tc;
 
   if (name == NULL || type == NULL)
-    return FALSE;
+    return false;
 
   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
                                      DEBUG_LINKAGE_NONE);
   if (n == NULL)
-    return FALSE;
+    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;
 
   n->u.typed_constant = tc;
 
-  return TRUE;
+  return true;
 }
 
 /* Record a label.  */
 
-bfd_boolean
+bool
 debug_record_label (void *handle ATTRIBUTE_UNUSED,
                    const char *name ATTRIBUTE_UNUSED,
                    debug_type type ATTRIBUTE_UNUSED,
@@ -1110,12 +1118,12 @@ debug_record_label (void *handle ATTRIBUTE_UNUSED,
 {
   /* FIXME.  */
   debug_error (_("debug_record_label: not implemented"));
-  return FALSE;
+  return false;
 }
 
 /* Record a variable.  */
 
-bfd_boolean
+bool
 debug_record_variable (void *handle, const char *name, debug_type type,
                       enum debug_var_kind kind, bfd_vma val)
 {
@@ -1126,13 +1134,13 @@ debug_record_variable (void *handle, const char *name, debug_type type,
   struct debug_variable *v;
 
   if (name == NULL || type == NULL)
-    return FALSE;
+    return false;
 
   if (info->current_unit == NULL
       || info->current_file == NULL)
     {
       debug_error (_("debug_record_variable: no current file"));
-      return FALSE;
+      return false;
     }
 
   if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
@@ -1154,10 +1162,9 @@ debug_record_variable (void *handle, const char *name, debug_type type,
 
   n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
   if (n == NULL)
-    return FALSE;
+    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;
@@ -1165,19 +1172,18 @@ debug_record_variable (void *handle, const char *name, debug_type type,
 
   n->u.variable = v;
 
-  return TRUE;
+  return true;
 }
 
 /* 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;
@@ -1199,8 +1205,7 @@ debug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
   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;
@@ -1224,7 +1229,7 @@ debug_make_void_type (void *handle)
    if the integer is unsigned.  */
 
 debug_type
-debug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
+debug_make_int_type (void *handle, unsigned int size, bool unsignedp)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1275,7 +1280,7 @@ debug_make_complex_type (void *handle, unsigned int size)
    The fourth argument is a NULL terminated array of fields.  */
 
 debug_type
-debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
+debug_make_struct_type (void *handle, bool structp, bfd_vma size,
                        debug_field *fields)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -1288,8 +1293,7 @@ debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
   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;
 
@@ -1306,10 +1310,10 @@ debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
    object has its own virtual function table.  */
 
 debug_type
-debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
+debug_make_object_type (void *handle, bool structp, bfd_vma size,
                        debug_field *fields, debug_baseclass *baseclasses,
                        debug_method *methods, debug_type vptrbase,
-                       bfd_boolean ownvptr)
+                       bool ownvptr)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1321,8 +1325,7 @@ debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
   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;
@@ -1352,8 +1355,7 @@ debug_make_enum_type (void *handle, const char **names,
   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;
@@ -1393,7 +1395,7 @@ debug_make_pointer_type (void *handle, debug_type type)
 
 debug_type
 debug_make_function_type (void *handle, debug_type type,
-                         debug_type *arg_types, bfd_boolean varargs)
+                         debug_type *arg_types, bool varargs)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1406,8 +1408,7 @@ debug_make_function_type (void *handle, debug_type type,
   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;
@@ -1455,8 +1456,7 @@ debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
   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;
@@ -1476,7 +1476,7 @@ debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
 debug_type
 debug_make_array_type (void *handle, debug_type element_type,
                       debug_type range_type, bfd_signed_vma lower,
-                      bfd_signed_vma upper, bfd_boolean stringp)
+                      bfd_signed_vma upper, bool stringp)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1489,8 +1489,7 @@ debug_make_array_type (void *handle, debug_type element_type,
   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;
@@ -1508,7 +1507,7 @@ debug_make_array_type (void *handle, debug_type element_type,
    CHILL.  */
 
 debug_type
-debug_make_set_type (void *handle, debug_type type, bfd_boolean bitstringp)
+debug_make_set_type (void *handle, debug_type type, bool bitstringp)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1521,8 +1520,7 @@ debug_make_set_type (void *handle, debug_type type, bfd_boolean 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;
@@ -1552,8 +1550,7 @@ debug_make_offset_type (void *handle, debug_type base_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;
@@ -1570,7 +1567,7 @@ debug_make_offset_type (void *handle, debug_type base_type,
 debug_type
 debug_make_method_type (void *handle, debug_type return_type,
                        debug_type domain_type, debug_type *arg_types,
-                       bfd_boolean varargs)
+                       bool varargs)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type_s *t;
@@ -1583,8 +1580,7 @@ debug_make_method_type (void *handle, debug_type return_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;
@@ -1677,14 +1673,14 @@ debug_make_undefined_tagged_type (void *handle, const char *name,
    argument is the visibility of the base class.  */
 
 debug_baseclass
-debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
-                     bfd_vma bitpos, bfd_boolean is_virtual,
+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;
@@ -1701,18 +1697,18 @@ debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
    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;
-  f->static_member = FALSE;
+  f->static_member = false;
   f->u.f.bitpos = bitpos;
   f->u.f.bitsize = bitsize;
   f->visibility = visibility;
@@ -1727,18 +1723,18 @@ debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
    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;
-  f->static_member = TRUE;
+  f->static_member = true;
   f->u.s.physname = physname;
   f->visibility = visibility;
 
@@ -1749,13 +1745,13 @@ debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
    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;
@@ -1773,16 +1769,16 @@ debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
    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,
-                          bfd_boolean constp, bfd_boolean volatilep,
+                          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;
@@ -1800,15 +1796,15 @@ debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
    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,
-                                 bfd_boolean constp, bfd_boolean volatilep)
+                                 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;
@@ -1844,8 +1840,7 @@ debug_name_type (void *handle, const char *name, debug_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;
 
@@ -1897,8 +1892,7 @@ debug_tag_type (void *handle, const char *name, debug_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;
 
@@ -1921,7 +1915,7 @@ debug_tag_type (void *handle, const char *name, debug_type type)
 
 /* Record the size of a given type.  */
 
-bfd_boolean
+bool
 debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
                        unsigned int size)
 {
@@ -1931,7 +1925,7 @@ debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
 
   type->size = size;
 
-  return TRUE;
+  return true;
 }
 
 /* Find a named type.  */
@@ -2065,7 +2059,9 @@ debug_get_real_type (void *handle, debug_type type,
       /* 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:
@@ -2095,7 +2091,9 @@ 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;
     }
@@ -2124,7 +2122,9 @@ debug_get_type_size (void *handle, debug_type 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:
@@ -2163,7 +2163,7 @@ debug_get_return_type (void *handle, debug_type type)
 
 const debug_type *
 debug_get_parameter_types (void *handle, debug_type type,
-                          bfd_boolean *pvarargs)
+                          bool *pvarargs)
 {
   if (type == NULL)
     return NULL;
@@ -2303,7 +2303,7 @@ debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
 /* Write out the debugging information.  This is given a handle to
    debugging information, and a set of function pointers to call.  */
 
-bfd_boolean
+bool
 debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
 {
   struct debug_handle *info = (struct debug_handle *) handle;
@@ -2327,42 +2327,42 @@ debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
   for (u = info->units; u != NULL; u = u->next)
     {
       struct debug_file *f;
-      bfd_boolean first_file;
+      bool first_file;
 
       info->current_write_lineno = u->linenos;
       info->current_write_lineno_index = 0;
 
       if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
-       return FALSE;
+       return false;
 
-      first_file = TRUE;
+      first_file = true;
       for (f = u->files; f != NULL; f = f->next)
        {
          struct debug_name *n;
 
          if (first_file)
-           first_file = FALSE;
+           first_file = false;
          else if (! (*fns->start_source) (fhandle, f->filename))
-           return FALSE;
+           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;
+               return false;
        }
 
       /* Output any line number information which hasn't already been
          handled.  */
       if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Write out an element in a namespace.  */
 
-static bfd_boolean
+static bool
 debug_write_name (struct debug_handle *info,
                  const struct debug_write_fns *fns, void *fhandle,
                  struct debug_name *n)
@@ -2372,16 +2372,16 @@ debug_write_name (struct debug_handle *info,
     case DEBUG_OBJECT_TYPE:
       if (! debug_write_type (info, fns, fhandle, n->u.type, n)
          || ! (*fns->typdef) (fhandle, n->name))
-       return FALSE;
-      return TRUE;
+       return false;
+      return true;
     case DEBUG_OBJECT_TAG:
       if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
-       return FALSE;
+       return false;
       return (*fns->tag) (fhandle, n->name);
     case DEBUG_OBJECT_VARIABLE:
       if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
                               n->u.variable->val);
     case DEBUG_OBJECT_FUNCTION:
@@ -2394,12 +2394,12 @@ debug_write_name (struct debug_handle *info,
     case DEBUG_OBJECT_TYPED_CONSTANT:
       if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->typed_constant) (fhandle, n->name,
                                     n->u.typed_constant->val);
     default:
       abort ();
-      return FALSE;
+      return false;
     }
   /*NOTREACHED*/
 }
@@ -2410,7 +2410,7 @@ debug_write_name (struct debug_handle *info,
    then the name argument is a tag from a DEBUG_KIND_TAGGED type which
    points to this one.  */
 
-static bfd_boolean
+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)
@@ -2453,7 +2453,7 @@ debug_write_type (struct debug_handle *info,
                  if (! debug_set_class_id (info,
                                            type->u.knamed->name->name,
                                            real))
-                   return FALSE;
+                   return false;
                }
              id = real->u.kclass->id;
            }
@@ -2482,8 +2482,11 @@ debug_write_type (struct debug_handle *info,
     {
     case DEBUG_KIND_ILLEGAL:
       debug_error (_("debug_write_type: illegal type encountered"));
-      return FALSE;
+      return false;
     case DEBUG_KIND_INDIRECT:
+      /* Prevent infinite recursion.  */
+      if (*type->u.kindirect->slot == type)
+       return (*fns->empty_type) (fhandle);
       return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
                               name);
     case DEBUG_KIND_VOID:
@@ -2503,7 +2506,7 @@ debug_write_type (struct debug_handle *info,
          if (type->u.kclass->id <= info->base_id)
            {
              if (! debug_set_class_id (info, tag, type))
-               return FALSE;
+               return false;
            }
 
          if (info->mark == type->u.kclass->mark)
@@ -2524,7 +2527,7 @@ debug_write_type (struct debug_handle *info,
                                        : 0),
                                       type->kind == DEBUG_KIND_STRUCT,
                                       type->size))
-       return FALSE;
+       return false;
       if (type->u.kclass != NULL
          && type->u.kclass->fields != NULL)
        {
@@ -2537,7 +2540,7 @@ debug_write_type (struct debug_handle *info,
                                      (struct debug_name *) NULL)
                  || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
                                             f->u.f.bitsize, f->visibility))
-               return FALSE;
+               return false;
            }
        }
       return (*fns->end_struct_type) (fhandle);
@@ -2553,13 +2556,13 @@ debug_write_type (struct debug_handle *info,
     case DEBUG_KIND_POINTER:
       if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->pointer_type) (fhandle);
     case DEBUG_KIND_FUNCTION:
       if (! debug_write_type (info, fns, fhandle,
                              type->u.kfunction->return_type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       if (type->u.kfunction->arg_types == NULL)
        is = -1;
       else
@@ -2568,19 +2571,19 @@ debug_write_type (struct debug_handle *info,
            if (! debug_write_type (info, fns, fhandle,
                                    type->u.kfunction->arg_types[is],
                                    (struct debug_name *) NULL))
-             return FALSE;
+             return false;
        }
       return (*fns->function_type) (fhandle, is,
                                    type->u.kfunction->varargs);
     case DEBUG_KIND_REFERENCE:
       if (! debug_write_type (info, fns, fhandle, type->u.kreference,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->reference_type) (fhandle);
     case DEBUG_KIND_RANGE:
       if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->range_type) (fhandle, type->u.krange->lower,
                                 type->u.krange->upper);
     case DEBUG_KIND_ARRAY:
@@ -2589,14 +2592,14 @@ debug_write_type (struct debug_handle *info,
          || ! debug_write_type (info, fns, fhandle,
                                 type->u.karray->range_type,
                                 (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->array_type) (fhandle, type->u.karray->lower,
                                 type->u.karray->upper,
                                 type->u.karray->stringp);
     case DEBUG_KIND_SET:
       if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
     case DEBUG_KIND_OFFSET:
       if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
@@ -2604,13 +2607,13 @@ debug_write_type (struct debug_handle *info,
          || ! debug_write_type (info, fns, fhandle,
                                 type->u.koffset->target_type,
                                 (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->offset_type) (fhandle);
     case DEBUG_KIND_METHOD:
       if (! debug_write_type (info, fns, fhandle,
                              type->u.kmethod->return_type,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       if (type->u.kmethod->arg_types == NULL)
        is = -1;
       else
@@ -2619,14 +2622,14 @@ debug_write_type (struct debug_handle *info,
            if (! debug_write_type (info, fns, fhandle,
                                    type->u.kmethod->arg_types[is],
                                    (struct debug_name *) NULL))
-             return FALSE;
+             return false;
        }
       if (type->u.kmethod->domain_type != NULL)
        {
          if (! debug_write_type (info, fns, fhandle,
                                  type->u.kmethod->domain_type,
                                  (struct debug_name *) NULL))
-           return FALSE;
+           return false;
        }
       return (*fns->method_type) (fhandle,
                                  type->u.kmethod->domain_type != NULL,
@@ -2635,12 +2638,12 @@ debug_write_type (struct debug_handle *info,
     case DEBUG_KIND_CONST:
       if (! debug_write_type (info, fns, fhandle, type->u.kconst,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->const_type) (fhandle);
     case DEBUG_KIND_VOLATILE:
       if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
                              (struct debug_name *) NULL))
-       return FALSE;
+       return false;
       return (*fns->volatile_type) (fhandle);
     case DEBUG_KIND_NAMED:
       return debug_write_type (info, fns, fhandle, type->u.knamed->type,
@@ -2650,13 +2653,13 @@ debug_write_type (struct debug_handle *info,
                               type->u.knamed->name);
     default:
       abort ();
-      return FALSE;
+      return false;
     }
 }
 
 /* Write out a class type.  */
 
-static bfd_boolean
+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)
@@ -2675,7 +2678,7 @@ debug_write_class_type (struct debug_handle *info,
       if (type->u.kclass->id <= info->base_id)
        {
          if (! debug_set_class_id (info, tag, type))
-           return FALSE;
+           return false;
        }
 
       if (info->mark == type->u.kclass->mark)
@@ -2695,7 +2698,7 @@ debug_write_class_type (struct debug_handle *info,
        {
          if (! debug_write_type (info, fns, fhandle, vptrbase,
                                  (struct debug_name *) NULL))
-           return FALSE;
+           return false;
        }
     }
 
@@ -2704,7 +2707,7 @@ debug_write_class_type (struct debug_handle *info,
                                  type->size,
                                  vptrbase != NULL,
                                  vptrbase == type))
-    return FALSE;
+    return false;
 
   if (type->u.kclass != NULL)
     {
@@ -2717,19 +2720,19 @@ debug_write_class_type (struct debug_handle *info,
              f = type->u.kclass->fields[i];
              if (! debug_write_type (info, fns, fhandle, f->type,
                                      (struct debug_name *) NULL))
-               return FALSE;
+               return false;
              if (f->static_member)
                {
                  if (! (*fns->class_static_member) (fhandle, f->name,
                                                     f->u.s.physname,
                                                     f->visibility))
-                   return FALSE;
+                   return false;
                }
              else
                {
                  if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
                                              f->u.f.bitsize, f->visibility))
-                   return FALSE;
+                   return false;
                }
            }
        }
@@ -2743,10 +2746,10 @@ debug_write_class_type (struct debug_handle *info,
              b = type->u.kclass->baseclasses[i];
              if (! debug_write_type (info, fns, fhandle, b->type,
                                      (struct debug_name *) NULL))
-               return FALSE;
+               return false;
              if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->is_virtual,
                                             b->visibility))
-               return FALSE;
+               return false;
            }
        }
 
@@ -2759,7 +2762,7 @@ debug_write_class_type (struct debug_handle *info,
 
              m = type->u.kclass->methods[i];
              if (! (*fns->class_start_method) (fhandle, m->name))
-               return FALSE;
+               return false;
              for (j = 0; m->variants[j] != NULL; j++)
                {
                  struct debug_method_variant_s *v;
@@ -2769,11 +2772,11 @@ debug_write_class_type (struct debug_handle *info,
                    {
                      if (! debug_write_type (info, fns, fhandle, v->context,
                                              (struct debug_name *) NULL))
-                       return FALSE;
+                       return false;
                    }
                  if (! debug_write_type (info, fns, fhandle, v->type,
                                          (struct debug_name *) NULL))
-                   return FALSE;
+                   return false;
                  if (v->voffset != VOFFSET_STATIC_METHOD)
                    {
                      if (! (*fns->class_method_variant) (fhandle, v->physname,
@@ -2782,7 +2785,7 @@ debug_write_class_type (struct debug_handle *info,
                                                          v->volatilep,
                                                          v->voffset,
                                                          v->context != NULL))
-                       return FALSE;
+                       return false;
                    }
                  else
                    {
@@ -2791,11 +2794,11 @@ debug_write_class_type (struct debug_handle *info,
                                                                 v->visibility,
                                                                 v->constp,
                                                                 v->volatilep))
-                       return FALSE;
+                       return false;
                    }
                }
              if (! (*fns->class_end_method) (fhandle))
-               return FALSE;
+               return false;
            }
        }
     }
@@ -2805,7 +2808,7 @@ debug_write_class_type (struct debug_handle *info,
 
 /* Write out information for a function.  */
 
-static bfd_boolean
+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,
@@ -2815,28 +2818,28 @@ debug_write_function (struct debug_handle *info,
   struct debug_block *b;
 
   if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
-    return FALSE;
+    return false;
 
   if (! debug_write_type (info, fns, fhandle, function->return_type,
                          (struct debug_name *) NULL))
-    return FALSE;
+    return false;
 
   if (! (*fns->start_function) (fhandle, name,
                                linkage == DEBUG_LINKAGE_GLOBAL))
-    return FALSE;
+    return false;
 
   for (p = function->parameters; p != NULL; p = p->next)
     {
       if (! debug_write_type (info, fns, fhandle, p->type,
                              (struct debug_name *) NULL)
          || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
-       return FALSE;
+       return false;
     }
 
   for (b = function->blocks; b != NULL; b = b->next)
     {
       if (! debug_write_block (info, fns, fhandle, b))
-       return FALSE;
+       return false;
     }
 
   return (*fns->end_function) (fhandle);
@@ -2844,7 +2847,7 @@ debug_write_function (struct debug_handle *info,
 
 /* Write out information for a block.  */
 
-static bfd_boolean
+static bool
 debug_write_block (struct debug_handle *info,
                   const struct debug_write_fns *fns, void *fhandle,
                   struct debug_block *block)
@@ -2853,14 +2856,14 @@ debug_write_block (struct debug_handle *info,
   struct debug_block *b;
 
   if (! debug_write_linenos (info, fns, fhandle, block->start))
-    return FALSE;
+    return false;
 
   /* I can't see any point to writing out a block with no local
      variables, so we don't bother, except for the top level block.  */
   if (block->locals != NULL || block->parent == NULL)
     {
       if (! (*fns->start_block) (fhandle, block->start))
-       return FALSE;
+       return false;
     }
 
   if (block->locals != NULL)
@@ -2868,31 +2871,31 @@ debug_write_block (struct debug_handle *info,
       for (n = block->locals->list; n != NULL; n = n->next)
        {
          if (! debug_write_name (info, fns, fhandle, n))
-           return FALSE;
+           return false;
        }
     }
 
   for (b = block->children; b != NULL; b = b->next)
     {
       if (! debug_write_block (info, fns, fhandle, b))
-       return FALSE;
+       return false;
     }
 
   if (! debug_write_linenos (info, fns, fhandle, block->end))
-    return FALSE;
+    return false;
 
   if (block->locals != NULL || block->parent == NULL)
     {
       if (! (*fns->end_block) (fhandle, block->end))
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Write out line number information up to ADDRESS.  */
 
-static bfd_boolean
+static bool
 debug_write_linenos (struct debug_handle *info,
                     const struct debug_write_fns *fns, void *fhandle,
                     bfd_vma address)
@@ -2910,12 +2913,12 @@ debug_write_linenos (struct debug_handle *info,
            break;
 
          if (l->addrs[info->current_write_lineno_index] >= address)
-           return TRUE;
+           return true;
 
          if (! (*fns->lineno) (fhandle, l->file->filename,
                                l->linenos[info->current_write_lineno_index],
                                l->addrs[info->current_write_lineno_index]))
-           return FALSE;
+           return false;
 
          ++info->current_write_lineno_index;
        }
@@ -2924,7 +2927,7 @@ debug_write_linenos (struct debug_handle *info,
       info->current_write_lineno_index = 0;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Get the ID number for a class.  If during the same call to
@@ -2932,7 +2935,7 @@ debug_write_linenos (struct debug_handle *info,
    name, we use the same ID.  This type of things happens because the
    same struct will be defined by multiple compilation units.  */
 
-static bfd_boolean
+static bool
 debug_set_class_id (struct debug_handle *info, const char *tag,
                    struct debug_type_s *type)
 {
@@ -2947,7 +2950,7 @@ debug_set_class_id (struct debug_handle *info, const char *tag,
   c = type->u.kclass;
 
   if (c->id > info->base_id)
-    return TRUE;
+    return true;
 
   for (l = info->id_list; l != NULL; l = l->next)
     {
@@ -2970,7 +2973,7 @@ debug_set_class_id (struct debug_handle *info, const char *tag,
       if (debug_type_samep (info, l->type, type))
        {
          c->id = l->type->u.kclass->id;
-         return TRUE;
+         return true;
        }
     }
 
@@ -2979,8 +2982,7 @@ debug_set_class_id (struct debug_handle *info, const char *tag,
   ++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;
@@ -2988,40 +2990,40 @@ debug_set_class_id (struct debug_handle *info, const char *tag,
   l->next = info->id_list;
   info->id_list = l;
 
-  return TRUE;
+  return true;
 }
 
 /* See if two types are the same.  At this point, we don't care about
    tags and the like.  */
 
-static bfd_boolean
+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;
-  bfd_boolean ret;
+  bool ret;
 
   if (t1 == NULL)
     return t2 == NULL;
   if (t2 == NULL)
-    return FALSE;
+    return false;
 
   while (t1->kind == DEBUG_KIND_INDIRECT)
     {
       t1 = *t1->u.kindirect->slot;
       if (t1 == NULL)
-       return FALSE;
+       return false;
     }
   while (t2->kind == DEBUG_KIND_INDIRECT)
     {
       t2 = *t2->u.kindirect->slot;
       if (t2 == NULL)
-       return FALSE;
+       return false;
     }
 
   if (t1 == t2)
-    return TRUE;
+    return true;
 
   /* As a special case, permit a typedef to match a tag, since C++
      debugging output will sometimes add a typedef where C debugging
@@ -3035,7 +3037,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
 
   if (t1->kind != t2->kind
       || t1->size != t2->size)
-    return FALSE;
+    return false;
 
   /* Get rid of the trivial cases first.  */
   switch (t1->kind)
@@ -3046,7 +3048,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
     case DEBUG_KIND_FLOAT:
     case DEBUG_KIND_COMPLEX:
     case DEBUG_KIND_BOOL:
-      return TRUE;
+      return true;
     case DEBUG_KIND_INT:
       return t1->u.kint == t2->u.kint;
     }
@@ -3058,7 +3060,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
   for (l = info->compare_list; l != NULL; l = l->next)
     {
       if (l->t1 == t1 && l->t2 == t2)
-       return TRUE;
+       return true;
     }
 
   top.t1 = t1;
@@ -3070,7 +3072,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
     {
     default:
       abort ();
-      ret = FALSE;
+      ret = false;
       break;
 
     case DEBUG_KIND_STRUCT:
@@ -3080,10 +3082,10 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
       if (t1->u.kclass == NULL)
        ret = t2->u.kclass == NULL;
       else if (t2->u.kclass == NULL)
-       ret = FALSE;
+       ret = false;
       else if (t1->u.kclass->id > info->base_id
               && t1->u.kclass->id == t2->u.kclass->id)
-       ret = TRUE;
+       ret = true;
       else
        ret = debug_class_type_samep (info, t1, t2);
       break;
@@ -3092,7 +3094,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
       if (t1->u.kenum == NULL)
        ret = t2->u.kenum == NULL;
       else if (t2->u.kenum == NULL)
-       ret = FALSE;
+       ret = false;
       else
        {
          const char **pn1, **pn2;
@@ -3127,9 +3129,9 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
                                 t2->u.kfunction->return_type)
          || ((t1->u.kfunction->arg_types == NULL)
              != (t2->u.kfunction->arg_types == NULL)))
-       ret = FALSE;
+       ret = false;
       else if (t1->u.kfunction->arg_types == NULL)
-       ret = TRUE;
+       ret = true;
       else
        {
          struct debug_type_s **a1, **a2;
@@ -3186,9 +3188,9 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
                                 t2->u.kmethod->domain_type)
          || ((t1->u.kmethod->arg_types == NULL)
              != (t2->u.kmethod->arg_types == NULL)))
-       ret = FALSE;
+       ret = false;
       else if (t1->u.kmethod->arg_types == NULL)
-       ret = TRUE;
+       ret = true;
       else
        {
          struct debug_type_s **a1, **a2;
@@ -3230,7 +3232,7 @@ debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
 /* See if two classes are the same.  This is a subroutine of
    debug_type_samep.  */
 
-static bfd_boolean
+static bool
 debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
                        struct debug_type_s *t2)
 {
@@ -3243,7 +3245,7 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
       || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
       || (c1->methods == NULL) != (c2->methods == NULL)
       || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
-    return FALSE;
+    return false;
 
   if (c1->fields != NULL)
     {
@@ -3260,17 +3262,17 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
          if (f1->name[0] != f2->name[0]
              || f1->visibility != f2->visibility
              || f1->static_member != f2->static_member)
-           return FALSE;
+           return false;
          if (f1->static_member)
            {
              if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
-               return FALSE;
+               return false;
            }
          else
            {
              if (f1->u.f.bitpos != f2->u.f.bitpos
                  || f1->u.f.bitsize != f2->u.f.bitsize)
-               return FALSE;
+               return false;
            }
          /* We do the checks which require function calls last.  We
              don't require that the types of fields have the same
@@ -3284,16 +3286,16 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
                                                          f1->type, NULL),
                                     debug_get_real_type ((void *) info,
                                                          f2->type, NULL)))
-           return FALSE;
+           return false;
        }
       if (*pf1 != NULL || *pf2 != NULL)
-       return FALSE;
+       return false;
     }
 
   if (c1->vptrbase != NULL)
     {
       if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
-       return FALSE;
+       return false;
     }
 
   if (c1->baseclasses != NULL)
@@ -3312,10 +3314,10 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
              || b1->is_virtual != b2->is_virtual
              || b1->visibility != b2->visibility
              || ! debug_type_samep (info, b1->type, b2->type))
-           return FALSE;
+           return false;
        }
       if (*pb1 != NULL || *pb2 != NULL)
-       return FALSE;
+       return false;
     }
 
   if (c1->methods != NULL)
@@ -3333,8 +3335,8 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
          if (m1->name[0] != m2->name[0]
              || strcmp (m1->name, m2->name) != 0
              || (m1->variants == NULL) != (m2->variants == NULL))
-           return FALSE;
-         if (m1->variants == NULL)
+           return false;
+         if (m1->variants != NULL)
            {
              struct debug_method_variant_s **pv1, **pv2;
 
@@ -3354,21 +3356,21 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
                      || (v1->context == NULL) != (v2->context == NULL)
                      || strcmp (v1->physname, v2->physname) != 0
                      || ! debug_type_samep (info, v1->type, v2->type))
-                   return FALSE;
+                   return false;
                  if (v1->context != NULL)
                    {
                      if (! debug_type_samep (info, v1->context,
                                              v2->context))
-                       return FALSE;
+                       return false;
                    }
                }
              if (*pv1 != NULL || *pv2 != NULL)
-               return FALSE;
+               return false;
            }
        }
       if (*pm1 != NULL || *pm2 != NULL)
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }