Subversion Repositories Kolibri OS

Rev

Rev 5217 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* debug.c -- Handle generic debugging information.
  2.    Copyright (C) 1995-2015 Free Software Foundation, Inc.
  3.    Written by Ian Lance Taylor <ian@cygnus.com>.
  4.  
  5.    This file is part of GNU Binutils.
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  20.    02110-1301, USA.  */
  21.  
  22.  
  23. /* This file implements a generic debugging format.  We may eventually
  24.    have readers which convert different formats into this generic
  25.    format, and writers which write it out.  The initial impetus for
  26.    this was writing a converter from stabs to HP IEEE-695 debugging
  27.    format.  */
  28.  
  29. #include "sysdep.h"
  30. #include <assert.h>
  31. #include "bfd.h"
  32. #include "libiberty.h"
  33. #include "filenames.h"
  34. #include "debug.h"
  35.  
  36. /* Global information we keep for debugging.  A pointer to this
  37.    structure is the debugging handle passed to all the routines.  */
  38.  
  39. struct debug_handle
  40. {
  41.   /* A linked list of compilation units.  */
  42.   struct debug_unit *units;
  43.   /* The current compilation unit.  */
  44.   struct debug_unit *current_unit;
  45.   /* The current source file.  */
  46.   struct debug_file *current_file;
  47.   /* The current function.  */
  48.   struct debug_function *current_function;
  49.   /* The current block.  */
  50.   struct debug_block *current_block;
  51.   /* The current line number information for the current unit.  */
  52.   struct debug_lineno *current_lineno;
  53.   /* Mark.  This is used by debug_write.  */
  54.   unsigned int mark;
  55.   /* A struct/class ID used by debug_write.  */
  56.   unsigned int class_id;
  57.   /* The base for class_id for this call to debug_write.  */
  58.   unsigned int base_id;
  59.   /* The current line number in debug_write.  */
  60.   struct debug_lineno *current_write_lineno;
  61.   unsigned int current_write_lineno_index;
  62.   /* A list of classes which have assigned ID's during debug_write.
  63.      This is linked through the next_id field of debug_class_type.  */
  64.   struct debug_class_id *id_list;
  65.   /* A list used to avoid recursion during debug_type_samep.  */
  66.   struct debug_type_compare_list *compare_list;
  67. };
  68.  
  69. /* Information we keep for a single compilation unit.  */
  70.  
  71. struct debug_unit
  72. {
  73.   /* The next compilation unit.  */
  74.   struct debug_unit *next;
  75.   /* A list of files included in this compilation unit.  The first
  76.      file is always the main one, and that is where the main file name
  77.      is stored.  */
  78.   struct debug_file *files;
  79.   /* Line number information for this compilation unit.  This is not
  80.      stored by function, because assembler code may have line number
  81.      information without function information.  */
  82.   struct debug_lineno *linenos;
  83. };
  84.  
  85. /* Information kept for a single source file.  */
  86.  
  87. struct debug_file
  88. {
  89.   /* The next source file in this compilation unit.  */
  90.   struct debug_file *next;
  91.   /* The name of the source file.  */
  92.   const char *filename;
  93.   /* Global functions, variables, types, etc.  */
  94.   struct debug_namespace *globals;
  95. };
  96.  
  97. /* A type.  */
  98.  
  99. struct debug_type_s
  100. {
  101.   /* Kind of type.  */
  102.   enum debug_type_kind kind;
  103.   /* Size of type (0 if not known).  */
  104.   unsigned int size;
  105.   /* Type which is a pointer to this type.  */
  106.   debug_type pointer;
  107.   /* Tagged union with additional information about the type.  */
  108.   union
  109.     {
  110.       /* DEBUG_KIND_INDIRECT.  */
  111.       struct debug_indirect_type *kindirect;
  112.       /* DEBUG_KIND_INT.  */
  113.       /* Whether the integer is unsigned.  */
  114.       bfd_boolean kint;
  115.       /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
  116.          DEBUG_KIND_UNION_CLASS.  */
  117.       struct debug_class_type *kclass;
  118.       /* DEBUG_KIND_ENUM.  */
  119.       struct debug_enum_type *kenum;
  120.       /* DEBUG_KIND_POINTER.  */
  121.       struct debug_type_s *kpointer;
  122.       /* DEBUG_KIND_FUNCTION.  */
  123.       struct debug_function_type *kfunction;
  124.       /* DEBUG_KIND_REFERENCE.  */
  125.       struct debug_type_s *kreference;
  126.       /* DEBUG_KIND_RANGE.  */
  127.       struct debug_range_type *krange;
  128.       /* DEBUG_KIND_ARRAY.  */
  129.       struct debug_array_type *karray;
  130.       /* DEBUG_KIND_SET.  */
  131.       struct debug_set_type *kset;
  132.       /* DEBUG_KIND_OFFSET.  */
  133.       struct debug_offset_type *koffset;
  134.       /* DEBUG_KIND_METHOD.  */
  135.       struct debug_method_type *kmethod;
  136.       /* DEBUG_KIND_CONST.  */
  137.       struct debug_type_s *kconst;
  138.       /* DEBUG_KIND_VOLATILE.  */
  139.       struct debug_type_s *kvolatile;
  140.       /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED.  */
  141.       struct debug_named_type *knamed;
  142.     } u;
  143. };
  144.  
  145. /* Information kept for an indirect type.  */
  146.  
  147. struct debug_indirect_type
  148. {
  149.   /* Slot where the final type will appear.  */
  150.   debug_type *slot;
  151.   /* Tag.  */
  152.   const char *tag;
  153. };
  154.  
  155. /* Information kept for a struct, union, or class.  */
  156.  
  157. struct debug_class_type
  158. {
  159.   /* NULL terminated array of fields.  */
  160.   debug_field *fields;
  161.   /* A mark field which indicates whether the struct has already been
  162.      printed.  */
  163.   unsigned int mark;
  164.   /* This is used to uniquely identify unnamed structs when printing.  */
  165.   unsigned int id;
  166.   /* The remaining fields are only used for DEBUG_KIND_CLASS and
  167.      DEBUG_KIND_UNION_CLASS.  */
  168.   /* NULL terminated array of base classes.  */
  169.   debug_baseclass *baseclasses;
  170.   /* NULL terminated array of methods.  */
  171.   debug_method *methods;
  172.   /* The type of the class providing the virtual function table for
  173.      this class.  This may point to the type itself.  */
  174.   debug_type vptrbase;
  175. };
  176.  
  177. /* Information kept for an enum.  */
  178.  
  179. struct debug_enum_type
  180. {
  181.   /* NULL terminated array of names.  */
  182.   const char **names;
  183.   /* Array of corresponding values.  */
  184.   bfd_signed_vma *values;
  185. };
  186.  
  187. /* Information kept for a function.  FIXME: We should be able to
  188.    record the parameter types.  */
  189.  
  190. struct debug_function_type
  191. {
  192.   /* Return type.  */
  193.   debug_type return_type;
  194.   /* NULL terminated array of argument types.  */
  195.   debug_type *arg_types;
  196.   /* Whether the function takes a variable number of arguments.  */
  197.   bfd_boolean varargs;
  198. };
  199.  
  200. /* Information kept for a range.  */
  201.  
  202. struct debug_range_type
  203. {
  204.   /* Range base type.  */
  205.   debug_type type;
  206.   /* Lower bound.  */
  207.   bfd_signed_vma lower;
  208.   /* Upper bound.  */
  209.   bfd_signed_vma upper;
  210. };
  211.  
  212. /* Information kept for an array.  */
  213.  
  214. struct debug_array_type
  215. {
  216.   /* Element type.  */
  217.   debug_type element_type;
  218.   /* Range type.  */
  219.   debug_type range_type;
  220.   /* Lower bound.  */
  221.   bfd_signed_vma lower;
  222.   /* Upper bound.  */
  223.   bfd_signed_vma upper;
  224.   /* Whether this array is really a string.  */
  225.   bfd_boolean stringp;
  226. };
  227.  
  228. /* Information kept for a set.  */
  229.  
  230. struct debug_set_type
  231. {
  232.   /* Base type.  */
  233.   debug_type type;
  234.   /* Whether this set is really a bitstring.  */
  235.   bfd_boolean bitstringp;
  236. };
  237.  
  238. /* Information kept for an offset type (a based pointer).  */
  239.  
  240. struct debug_offset_type
  241. {
  242.   /* The type the pointer is an offset from.  */
  243.   debug_type base_type;
  244.   /* The type the pointer points to.  */
  245.   debug_type target_type;
  246. };
  247.  
  248. /* Information kept for a method type.  */
  249.  
  250. struct debug_method_type
  251. {
  252.   /* The return type.  */
  253.   debug_type return_type;
  254.   /* The object type which this method is for.  */
  255.   debug_type domain_type;
  256.   /* A NULL terminated array of argument types.  */
  257.   debug_type *arg_types;
  258.   /* Whether the method takes a variable number of arguments.  */
  259.   bfd_boolean varargs;
  260. };
  261.  
  262. /* Information kept for a named type.  */
  263.  
  264. struct debug_named_type
  265. {
  266.   /* Name.  */
  267.   struct debug_name *name;
  268.   /* Real type.  */
  269.   debug_type type;
  270. };
  271.  
  272. /* A field in a struct or union.  */
  273.  
  274. struct debug_field_s
  275. {
  276.   /* Name of the field.  */
  277.   const char *name;
  278.   /* Type of the field.  */
  279.   struct debug_type_s *type;
  280.   /* Visibility of the field.  */
  281.   enum debug_visibility visibility;
  282.   /* Whether this is a static member.  */
  283.   bfd_boolean static_member;
  284.   union
  285.     {
  286.       /* If static_member is false.  */
  287.       struct
  288.         {
  289.           /* Bit position of the field in the struct.  */
  290.           unsigned int bitpos;
  291.           /* Size of the field in bits.  */
  292.           unsigned int bitsize;
  293.         } f;
  294.       /* If static_member is true.  */
  295.       struct
  296.         {
  297.           const char *physname;
  298.         } s;
  299.     } u;
  300. };
  301.  
  302. /* A base class for an object.  */
  303.  
  304. struct debug_baseclass_s
  305. {
  306.   /* Type of the base class.  */
  307.   struct debug_type_s *type;
  308.   /* Bit position of the base class in the object.  */
  309.   unsigned int bitpos;
  310.   /* Whether the base class is virtual.  */
  311.   bfd_boolean is_virtual;
  312.   /* Visibility of the base class.  */
  313.   enum debug_visibility visibility;
  314. };
  315.  
  316. /* A method of an object.  */
  317.  
  318. struct debug_method_s
  319. {
  320.   /* The name of the method.  */
  321.   const char *name;
  322.   /* A NULL terminated array of different types of variants.  */
  323.   struct debug_method_variant_s **variants;
  324. };
  325.  
  326. /* The variants of a method function of an object.  These indicate
  327.    which method to run.  */
  328.  
  329. struct debug_method_variant_s
  330. {
  331.   /* The physical name of the function.  */
  332.   const char *physname;
  333.   /* The type of the function.  */
  334.   struct debug_type_s *type;
  335.   /* The visibility of the function.  */
  336.   enum debug_visibility visibility;
  337.   /* Whether the function is const.  */
  338.   bfd_boolean constp;
  339.   /* Whether the function is volatile.  */
  340.   bfd_boolean volatilep;
  341.   /* The offset to the function in the virtual function table.  */
  342.   bfd_vma voffset;
  343.   /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */
  344. #define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
  345.   /* Context of a virtual method function.  */
  346.   struct debug_type_s *context;
  347. };
  348.  
  349. /* A variable.  This is the information we keep for a variable object.
  350.    This has no name; a name is associated with a variable in a
  351.    debug_name structure.  */
  352.  
  353. struct debug_variable
  354. {
  355.   /* Kind of variable.  */
  356.   enum debug_var_kind kind;
  357.   /* Type.  */
  358.   debug_type type;
  359.   /* Value.  The interpretation of the value depends upon kind.  */
  360.   bfd_vma val;
  361. };
  362.  
  363. /* A function.  This has no name; a name is associated with a function
  364.    in a debug_name structure.  */
  365.  
  366. struct debug_function
  367. {
  368.   /* Return type.  */
  369.   debug_type return_type;
  370.   /* Parameter information.  */
  371.   struct debug_parameter *parameters;
  372.   /* Block information.  The first structure on the list is the main
  373.      block of the function, and describes function local variables.  */
  374.   struct debug_block *blocks;
  375. };
  376.  
  377. /* A function parameter.  */
  378.  
  379. struct debug_parameter
  380. {
  381.   /* Next parameter.  */
  382.   struct debug_parameter *next;
  383.   /* Name.  */
  384.   const char *name;
  385.   /* Type.  */
  386.   debug_type type;
  387.   /* Kind.  */
  388.   enum debug_parm_kind kind;
  389.   /* Value (meaning depends upon kind).  */
  390.   bfd_vma val;
  391. };
  392.  
  393. /* A typed constant.  */
  394.  
  395. struct debug_typed_constant
  396. {
  397.   /* Type.  */
  398.   debug_type type;
  399.   /* Value.  FIXME: We may eventually need to support non-integral
  400.      values.  */
  401.   bfd_vma val;
  402. };
  403.  
  404. /* Information about a block within a function.  */
  405.  
  406. struct debug_block
  407. {
  408.   /* Next block with the same parent.  */
  409.   struct debug_block *next;
  410.   /* Parent block.  */
  411.   struct debug_block *parent;
  412.   /* List of child blocks.  */
  413.   struct debug_block *children;
  414.   /* Start address of the block.  */
  415.   bfd_vma start;
  416.   /* End address of the block.  */
  417.   bfd_vma end;
  418.   /* Local variables.  */
  419.   struct debug_namespace *locals;
  420. };
  421.  
  422. /* Line number information we keep for a compilation unit.  FIXME:
  423.    This structure is easy to create, but can be very space
  424.    inefficient.  */
  425.  
  426. struct debug_lineno
  427. {
  428.   /* More line number information for this block.  */
  429.   struct debug_lineno *next;
  430.   /* Source file.  */
  431.   struct debug_file *file;
  432.   /* Line numbers, terminated by a -1 or the end of the array.  */
  433. #define DEBUG_LINENO_COUNT 10
  434.   unsigned long linenos[DEBUG_LINENO_COUNT];
  435.   /* Addresses for the line numbers.  */
  436.   bfd_vma addrs[DEBUG_LINENO_COUNT];
  437. };
  438.  
  439. /* A namespace.  This is a mapping from names to objects.  FIXME: This
  440.    should be implemented as a hash table.  */
  441.  
  442. struct debug_namespace
  443. {
  444.   /* List of items in this namespace.  */
  445.   struct debug_name *list;
  446.   /* Pointer to where the next item in this namespace should go.  */
  447.   struct debug_name **tail;
  448. };
  449.  
  450. /* Kinds of objects that appear in a namespace.  */
  451.  
  452. enum debug_object_kind
  453. {
  454.   /* A type.  */
  455.   DEBUG_OBJECT_TYPE,
  456.   /* A tagged type (really a different sort of namespace).  */
  457.   DEBUG_OBJECT_TAG,
  458.   /* A variable.  */
  459.   DEBUG_OBJECT_VARIABLE,
  460.   /* A function.  */
  461.   DEBUG_OBJECT_FUNCTION,
  462.   /* An integer constant.  */
  463.   DEBUG_OBJECT_INT_CONSTANT,
  464.   /* A floating point constant.  */
  465.   DEBUG_OBJECT_FLOAT_CONSTANT,
  466.   /* A typed constant.  */
  467.   DEBUG_OBJECT_TYPED_CONSTANT
  468. };
  469.  
  470. /* Linkage of an object that appears in a namespace.  */
  471.  
  472. enum debug_object_linkage
  473. {
  474.   /* Local variable.  */
  475.   DEBUG_LINKAGE_AUTOMATIC,
  476.   /* Static--either file static or function static, depending upon the
  477.      namespace is.  */
  478.   DEBUG_LINKAGE_STATIC,
  479.   /* Global.  */
  480.   DEBUG_LINKAGE_GLOBAL,
  481.   /* No linkage.  */
  482.   DEBUG_LINKAGE_NONE
  483. };
  484.  
  485. /* A name in a namespace.  */
  486.  
  487. struct debug_name
  488. {
  489.   /* Next name in this namespace.  */
  490.   struct debug_name *next;
  491.   /* Name.  */
  492.   const char *name;
  493.   /* Mark.  This is used by debug_write.  */
  494.   unsigned int mark;
  495.   /* Kind of object.  */
  496.   enum debug_object_kind kind;
  497.   /* Linkage of object.  */
  498.   enum debug_object_linkage linkage;
  499.   /* Tagged union with additional information about the object.  */
  500.   union
  501.     {
  502.       /* DEBUG_OBJECT_TYPE.  */
  503.       struct debug_type_s *type;
  504.       /* DEBUG_OBJECT_TAG.  */
  505.       struct debug_type_s *tag;
  506.       /* DEBUG_OBJECT_VARIABLE.  */
  507.       struct debug_variable *variable;
  508.       /* DEBUG_OBJECT_FUNCTION.  */
  509.       struct debug_function *function;
  510.       /* DEBUG_OBJECT_INT_CONSTANT.  */
  511.       bfd_vma int_constant;
  512.       /* DEBUG_OBJECT_FLOAT_CONSTANT.  */
  513.       double float_constant;
  514.       /* DEBUG_OBJECT_TYPED_CONSTANT.  */
  515.       struct debug_typed_constant *typed_constant;
  516.     } u;
  517. };
  518.  
  519. /* During debug_write, a linked list of these structures is used to
  520.    keep track of ID numbers that have been assigned to classes.  */
  521.  
  522. struct debug_class_id
  523. {
  524.   /* Next ID number.  */
  525.   struct debug_class_id *next;
  526.   /* The type with the ID.  */
  527.   struct debug_type_s *type;
  528.   /* The tag; NULL if no tag.  */
  529.   const char *tag;
  530. };
  531.  
  532. /* During debug_type_samep, a linked list of these structures is kept
  533.    on the stack to avoid infinite recursion.  */
  534.  
  535. struct debug_type_compare_list
  536. {
  537.   /* Next type on list.  */
  538.   struct debug_type_compare_list *next;
  539.   /* The types we are comparing.  */
  540.   struct debug_type_s *t1;
  541.   struct debug_type_s *t2;
  542. };
  543.  
  544. /* During debug_get_real_type, a linked list of these structures is
  545.    kept on the stack to avoid infinite recursion.  */
  546.  
  547. struct debug_type_real_list
  548. {
  549.   /* Next type on list.  */
  550.   struct debug_type_real_list *next;
  551.   /* The type we are checking.  */
  552.   struct debug_type_s *t;
  553. };
  554.  
  555. /* Local functions.  */
  556.  
  557. static void debug_error (const char *);
  558. static struct debug_name *debug_add_to_namespace
  559.   (struct debug_handle *, struct debug_namespace **, const char *,
  560.    enum debug_object_kind, enum debug_object_linkage);
  561. static struct debug_name *debug_add_to_current_namespace
  562.   (struct debug_handle *, const char *, enum debug_object_kind,
  563.    enum debug_object_linkage);
  564. static struct debug_type_s *debug_make_type
  565.   (struct debug_handle *, enum debug_type_kind, unsigned int);
  566. static struct debug_type_s *debug_get_real_type
  567.   (void *, debug_type, struct debug_type_real_list *);
  568. static bfd_boolean debug_write_name
  569.   (struct debug_handle *, const struct debug_write_fns *, void *,
  570.    struct debug_name *);
  571. static bfd_boolean debug_write_type
  572.   (struct debug_handle *, const struct debug_write_fns *, void *,
  573.    struct debug_type_s *, struct debug_name *);
  574. static bfd_boolean debug_write_class_type
  575.   (struct debug_handle *, const struct debug_write_fns *, void *,
  576.    struct debug_type_s *, const char *);
  577. static bfd_boolean debug_write_function
  578.   (struct debug_handle *, const struct debug_write_fns *, void *,
  579.    const char *, enum debug_object_linkage, struct debug_function *);
  580. static bfd_boolean debug_write_block
  581.   (struct debug_handle *, const struct debug_write_fns *, void *,
  582.    struct debug_block *);
  583. static bfd_boolean debug_write_linenos
  584.   (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
  585. static bfd_boolean debug_set_class_id
  586.   (struct debug_handle *, const char *, struct debug_type_s *);
  587. static bfd_boolean debug_type_samep
  588.   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
  589. static bfd_boolean debug_class_type_samep
  590.   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
  591. /* Issue an error message.  */
  592.  
  593. static void
  594. debug_error (const char *message)
  595. {
  596.   fprintf (stderr, "%s\n", message);
  597. }
  598.  
  599. /* Add an object to a namespace.  */
  600.  
  601. static struct debug_name *
  602. debug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
  603.                         struct debug_namespace **nsp, const char *name,
  604.                         enum debug_object_kind kind,
  605.                         enum debug_object_linkage linkage)
  606. {
  607.   struct debug_name *n;
  608.   struct debug_namespace *ns;
  609.  
  610.   n = (struct debug_name *) xmalloc (sizeof *n);
  611.   memset (n, 0, sizeof *n);
  612.  
  613.   n->name = name;
  614.   n->kind = kind;
  615.   n->linkage = linkage;
  616.  
  617.   ns = *nsp;
  618.   if (ns == NULL)
  619.     {
  620.       ns = (struct debug_namespace *) xmalloc (sizeof *ns);
  621.       memset (ns, 0, sizeof *ns);
  622.  
  623.       ns->tail = &ns->list;
  624.  
  625.       *nsp = ns;
  626.     }
  627.  
  628.   *ns->tail = n;
  629.   ns->tail = &n->next;
  630.  
  631.   return n;
  632. }
  633.  
  634. /* Add an object to the current namespace.  */
  635.  
  636. static struct debug_name *
  637. debug_add_to_current_namespace (struct debug_handle *info, const char *name,
  638.                                 enum debug_object_kind kind,
  639.                                 enum debug_object_linkage linkage)
  640. {
  641.   struct debug_namespace **nsp;
  642.  
  643.   if (info->current_unit == NULL
  644.       || info->current_file == NULL)
  645.     {
  646.       debug_error (_("debug_add_to_current_namespace: no current file"));
  647.       return NULL;
  648.     }
  649.  
  650.   if (info->current_block != NULL)
  651.     nsp = &info->current_block->locals;
  652.   else
  653.     nsp = &info->current_file->globals;
  654.  
  655.   return debug_add_to_namespace (info, nsp, name, kind, linkage);
  656. }
  657. /* Return a handle for debugging information.  */
  658.  
  659. void *
  660. debug_init (void)
  661. {
  662.   struct debug_handle *ret;
  663.  
  664.   ret = (struct debug_handle *) xmalloc (sizeof *ret);
  665.   memset (ret, 0, sizeof *ret);
  666.   return (void *) ret;
  667. }
  668.  
  669. /* Set the source filename.  This implicitly starts a new compilation
  670.    unit.  */
  671.  
  672. bfd_boolean
  673. debug_set_filename (void *handle, const char *name)
  674. {
  675.   struct debug_handle *info = (struct debug_handle *) handle;
  676.   struct debug_file *nfile;
  677.   struct debug_unit *nunit;
  678.  
  679.   if (name == NULL)
  680.     name = "";
  681.  
  682.   nfile = (struct debug_file *) xmalloc (sizeof *nfile);
  683.   memset (nfile, 0, sizeof *nfile);
  684.  
  685.   nfile->filename = name;
  686.  
  687.   nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
  688.   memset (nunit, 0, sizeof *nunit);
  689.  
  690.   nunit->files = nfile;
  691.   info->current_file = nfile;
  692.  
  693.   if (info->current_unit != NULL)
  694.     info->current_unit->next = nunit;
  695.   else
  696.     {
  697.       assert (info->units == NULL);
  698.       info->units = nunit;
  699.     }
  700.  
  701.   info->current_unit = nunit;
  702.  
  703.   info->current_function = NULL;
  704.   info->current_block = NULL;
  705.   info->current_lineno = NULL;
  706.  
  707.   return TRUE;
  708. }
  709.  
  710. /* Change source files to the given file name.  This is used for
  711.    include files in a single compilation unit.  */
  712.  
  713. bfd_boolean
  714. debug_start_source (void *handle, const char *name)
  715. {
  716.   struct debug_handle *info = (struct debug_handle *) handle;
  717.   struct debug_file *f, **pf;
  718.  
  719.   if (name == NULL)
  720.     name = "";
  721.  
  722.   if (info->current_unit == NULL)
  723.     {
  724.       debug_error (_("debug_start_source: no debug_set_filename call"));
  725.       return FALSE;
  726.     }
  727.  
  728.   for (f = info->current_unit->files; f != NULL; f = f->next)
  729.     {
  730.       if (filename_cmp (f->filename, name) == 0)
  731.         {
  732.           info->current_file = f;
  733.           return TRUE;
  734.         }
  735.     }
  736.  
  737.   f = (struct debug_file *) xmalloc (sizeof *f);
  738.   memset (f, 0, sizeof *f);
  739.  
  740.   f->filename = name;
  741.  
  742.   for (pf = &info->current_file->next;
  743.        *pf != NULL;
  744.        pf = &(*pf)->next)
  745.     ;
  746.   *pf = f;
  747.  
  748.   info->current_file = f;
  749.  
  750.   return TRUE;
  751. }
  752.  
  753. /* Record a function definition.  This implicitly starts a function
  754.    block.  The debug_type argument is the type of the return value.
  755.    The boolean indicates whether the function is globally visible.
  756.    The bfd_vma is the address of the start of the function.  Currently
  757.    the parameter types are specified by calls to
  758.    debug_record_parameter.  FIXME: There is no way to specify nested
  759.    functions.  */
  760.  
  761. bfd_boolean
  762. debug_record_function (void *handle, const char *name,
  763.                        debug_type return_type, bfd_boolean global,
  764.                        bfd_vma addr)
  765. {
  766.   struct debug_handle *info = (struct debug_handle *) handle;
  767.   struct debug_function *f;
  768.   struct debug_block *b;
  769.   struct debug_name *n;
  770.  
  771.   if (name == NULL)
  772.     name = "";
  773.   if (return_type == NULL)
  774.     return FALSE;
  775.  
  776.   if (info->current_unit == NULL)
  777.     {
  778.       debug_error (_("debug_record_function: no debug_set_filename call"));
  779.       return FALSE;
  780.     }
  781.  
  782.   f = (struct debug_function *) xmalloc (sizeof *f);
  783.   memset (f, 0, sizeof *f);
  784.  
  785.   f->return_type = return_type;
  786.  
  787.   b = (struct debug_block *) xmalloc (sizeof *b);
  788.   memset (b, 0, sizeof *b);
  789.  
  790.   b->start = addr;
  791.   b->end = (bfd_vma) -1;
  792.  
  793.   f->blocks = b;
  794.  
  795.   info->current_function = f;
  796.   info->current_block = b;
  797.  
  798.   /* FIXME: If we could handle nested functions, this would be the
  799.      place: we would want to use a different namespace.  */
  800.   n = debug_add_to_namespace (info,
  801.                               &info->current_file->globals,
  802.                               name,
  803.                               DEBUG_OBJECT_FUNCTION,
  804.                               (global
  805.                                ? DEBUG_LINKAGE_GLOBAL
  806.                                : DEBUG_LINKAGE_STATIC));
  807.   if (n == NULL)
  808.     return FALSE;
  809.  
  810.   n->u.function = f;
  811.  
  812.   return TRUE;
  813. }
  814.  
  815. /* Record a parameter for the current function.  */
  816.  
  817. bfd_boolean
  818. debug_record_parameter (void *handle, const char *name, debug_type type,
  819.                         enum debug_parm_kind kind, bfd_vma val)
  820. {
  821.   struct debug_handle *info = (struct debug_handle *) handle;
  822.   struct debug_parameter *p, **pp;
  823.  
  824.   if (name == NULL || type == NULL)
  825.     return FALSE;
  826.  
  827.   if (info->current_unit == NULL
  828.       || info->current_function == NULL)
  829.     {
  830.       debug_error (_("debug_record_parameter: no current function"));
  831.       return FALSE;
  832.     }
  833.  
  834.   p = (struct debug_parameter *) xmalloc (sizeof *p);
  835.   memset (p, 0, sizeof *p);
  836.  
  837.   p->name = name;
  838.   p->type = type;
  839.   p->kind = kind;
  840.   p->val = val;
  841.  
  842.   for (pp = &info->current_function->parameters;
  843.        *pp != NULL;
  844.        pp = &(*pp)->next)
  845.     ;
  846.   *pp = p;
  847.  
  848.   return TRUE;
  849. }
  850.  
  851. /* End a function.  FIXME: This should handle function nesting.  */
  852.  
  853. bfd_boolean
  854. debug_end_function (void *handle, bfd_vma addr)
  855. {
  856.   struct debug_handle *info = (struct debug_handle *) handle;
  857.  
  858.   if (info->current_unit == NULL
  859.       || info->current_block == NULL
  860.       || info->current_function == NULL)
  861.     {
  862.       debug_error (_("debug_end_function: no current function"));
  863.       return FALSE;
  864.     }
  865.  
  866.   if (info->current_block->parent != NULL)
  867.     {
  868.       debug_error (_("debug_end_function: some blocks were not closed"));
  869.       return FALSE;
  870.     }
  871.  
  872.   info->current_block->end = addr;
  873.  
  874.   info->current_function = NULL;
  875.   info->current_block = NULL;
  876.  
  877.   return TRUE;
  878. }
  879.  
  880. /* Start a block in a function.  All local information will be
  881.    recorded in this block, until the matching call to debug_end_block.
  882.    debug_start_block and debug_end_block may be nested.  The bfd_vma
  883.    argument is the address at which this block starts.  */
  884.  
  885. bfd_boolean
  886. debug_start_block (void *handle, bfd_vma addr)
  887. {
  888.   struct debug_handle *info = (struct debug_handle *) handle;
  889.   struct debug_block *b, **pb;
  890.  
  891.   /* We must always have a current block: debug_record_function sets
  892.      one up.  */
  893.   if (info->current_unit == NULL
  894.       || info->current_block == NULL)
  895.     {
  896.       debug_error (_("debug_start_block: no current block"));
  897.       return FALSE;
  898.     }
  899.  
  900.   b = (struct debug_block *) xmalloc (sizeof *b);
  901.   memset (b, 0, sizeof *b);
  902.  
  903.   b->parent = info->current_block;
  904.   b->start = addr;
  905.   b->end = (bfd_vma) -1;
  906.  
  907.   /* This new block is a child of the current block.  */
  908.   for (pb = &info->current_block->children;
  909.        *pb != NULL;
  910.        pb = &(*pb)->next)
  911.     ;
  912.   *pb = b;
  913.  
  914.   info->current_block = b;
  915.  
  916.   return TRUE;
  917. }
  918.  
  919. /* Finish a block in a function.  This matches the call to
  920.    debug_start_block.  The argument is the address at which this block
  921.    ends.  */
  922.  
  923. bfd_boolean
  924. debug_end_block (void *handle, bfd_vma addr)
  925. {
  926.   struct debug_handle *info = (struct debug_handle *) handle;
  927.   struct debug_block *parent;
  928.  
  929.   if (info->current_unit == NULL
  930.       || info->current_block == NULL)
  931.     {
  932.       debug_error (_("debug_end_block: no current block"));
  933.       return FALSE;
  934.     }
  935.  
  936.   parent = info->current_block->parent;
  937.   if (parent == NULL)
  938.     {
  939.       debug_error (_("debug_end_block: attempt to close top level block"));
  940.       return FALSE;
  941.     }
  942.  
  943.   info->current_block->end = addr;
  944.  
  945.   info->current_block = parent;
  946.  
  947.   return TRUE;
  948. }
  949.  
  950. /* Associate a line number in the current source file and function
  951.    with a given address.  */
  952.  
  953. bfd_boolean
  954. debug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
  955. {
  956.   struct debug_handle *info = (struct debug_handle *) handle;
  957.   struct debug_lineno *l;
  958.   unsigned int i;
  959.  
  960.   if (info->current_unit == NULL)
  961.     {
  962.       debug_error (_("debug_record_line: no current unit"));
  963.       return FALSE;
  964.     }
  965.  
  966.   l = info->current_lineno;
  967.   if (l != NULL && l->file == info->current_file)
  968.     {
  969.       for (i = 0; i < DEBUG_LINENO_COUNT; i++)
  970.         {
  971.           if (l->linenos[i] == (unsigned long) -1)
  972.             {
  973.               l->linenos[i] = lineno;
  974.               l->addrs[i] = addr;
  975.               return TRUE;
  976.             }
  977.         }
  978.     }
  979.  
  980.   /* If we get here, then either 1) there is no current_lineno
  981.      structure, which means this is the first line number in this
  982.      compilation unit, 2) the current_lineno structure is for a
  983.      different file, or 3) the current_lineno structure is full.
  984.      Regardless, we want to allocate a new debug_lineno structure, put
  985.      it in the right place, and make it the new current_lineno
  986.      structure.  */
  987.  
  988.   l = (struct debug_lineno *) xmalloc (sizeof *l);
  989.   memset (l, 0, sizeof *l);
  990.  
  991.   l->file = info->current_file;
  992.   l->linenos[0] = lineno;
  993.   l->addrs[0] = addr;
  994.   for (i = 1; i < DEBUG_LINENO_COUNT; i++)
  995.     l->linenos[i] = (unsigned long) -1;
  996.  
  997.   if (info->current_lineno != NULL)
  998.     info->current_lineno->next = l;
  999.   else
  1000.     info->current_unit->linenos = l;
  1001.  
  1002.   info->current_lineno = l;
  1003.  
  1004.   return TRUE;
  1005. }
  1006.  
  1007. /* Start a named common block.  This is a block of variables that may
  1008.    move in memory.  */
  1009.  
  1010. bfd_boolean
  1011. debug_start_common_block (void *handle ATTRIBUTE_UNUSED,
  1012.                           const char *name ATTRIBUTE_UNUSED)
  1013. {
  1014.   /* FIXME */
  1015.   debug_error (_("debug_start_common_block: not implemented"));
  1016.   return FALSE;
  1017. }
  1018.  
  1019. /* End a named common block.  */
  1020.  
  1021. bfd_boolean
  1022. debug_end_common_block (void *handle ATTRIBUTE_UNUSED,
  1023.                         const char *name ATTRIBUTE_UNUSED)
  1024. {
  1025.   /* FIXME */
  1026.   debug_error (_("debug_end_common_block: not implemented"));
  1027.   return FALSE;
  1028. }
  1029.  
  1030. /* Record a named integer constant.  */
  1031.  
  1032. bfd_boolean
  1033. debug_record_int_const (void *handle, const char *name, bfd_vma val)
  1034. {
  1035.   struct debug_handle *info = (struct debug_handle *) handle;
  1036.   struct debug_name *n;
  1037.  
  1038.   if (name == NULL)
  1039.     return FALSE;
  1040.  
  1041.   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
  1042.                                       DEBUG_LINKAGE_NONE);
  1043.   if (n == NULL)
  1044.     return FALSE;
  1045.  
  1046.   n->u.int_constant = val;
  1047.  
  1048.   return TRUE;
  1049. }
  1050.  
  1051. /* Record a named floating point constant.  */
  1052.  
  1053. bfd_boolean
  1054. debug_record_float_const (void *handle, const char *name, double val)
  1055. {
  1056.   struct debug_handle *info = (struct debug_handle *) handle;
  1057.   struct debug_name *n;
  1058.  
  1059.   if (name == NULL)
  1060.     return FALSE;
  1061.  
  1062.   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
  1063.                                       DEBUG_LINKAGE_NONE);
  1064.   if (n == NULL)
  1065.     return FALSE;
  1066.  
  1067.   n->u.float_constant = val;
  1068.  
  1069.   return TRUE;
  1070. }
  1071.  
  1072. /* Record a typed constant with an integral value.  */
  1073.  
  1074. bfd_boolean
  1075. debug_record_typed_const (void *handle, const char *name, debug_type type,
  1076.                           bfd_vma val)
  1077. {
  1078.   struct debug_handle *info = (struct debug_handle *) handle;
  1079.   struct debug_name *n;
  1080.   struct debug_typed_constant *tc;
  1081.  
  1082.   if (name == NULL || type == NULL)
  1083.     return FALSE;
  1084.  
  1085.   n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
  1086.                                       DEBUG_LINKAGE_NONE);
  1087.   if (n == NULL)
  1088.     return FALSE;
  1089.  
  1090.   tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
  1091.   memset (tc, 0, sizeof *tc);
  1092.  
  1093.   tc->type = type;
  1094.   tc->val = val;
  1095.  
  1096.   n->u.typed_constant = tc;
  1097.  
  1098.   return TRUE;
  1099. }
  1100.  
  1101. /* Record a label.  */
  1102.  
  1103. bfd_boolean
  1104. debug_record_label (void *handle ATTRIBUTE_UNUSED,
  1105.                     const char *name ATTRIBUTE_UNUSED,
  1106.                     debug_type type ATTRIBUTE_UNUSED,
  1107.                     bfd_vma addr ATTRIBUTE_UNUSED)
  1108. {
  1109.   /* FIXME.  */
  1110.   debug_error (_("debug_record_label: not implemented"));
  1111.   return FALSE;
  1112. }
  1113.  
  1114. /* Record a variable.  */
  1115.  
  1116. bfd_boolean
  1117. debug_record_variable (void *handle, const char *name, debug_type type,
  1118.                        enum debug_var_kind kind, bfd_vma val)
  1119. {
  1120.   struct debug_handle *info = (struct debug_handle *) handle;
  1121.   struct debug_namespace **nsp;
  1122.   enum debug_object_linkage linkage;
  1123.   struct debug_name *n;
  1124.   struct debug_variable *v;
  1125.  
  1126.   if (name == NULL || type == NULL)
  1127.     return FALSE;
  1128.  
  1129.   if (info->current_unit == NULL
  1130.       || info->current_file == NULL)
  1131.     {
  1132.       debug_error (_("debug_record_variable: no current file"));
  1133.       return FALSE;
  1134.     }
  1135.  
  1136.   if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
  1137.     {
  1138.       nsp = &info->current_file->globals;
  1139.       if (kind == DEBUG_GLOBAL)
  1140.         linkage = DEBUG_LINKAGE_GLOBAL;
  1141.       else
  1142.         linkage = DEBUG_LINKAGE_STATIC;
  1143.     }
  1144.   else
  1145.     {
  1146.       if (info->current_block == NULL)
  1147.         nsp = &info->current_file->globals;
  1148.       else
  1149.         nsp = &info->current_block->locals;
  1150.       linkage = DEBUG_LINKAGE_AUTOMATIC;
  1151.     }
  1152.  
  1153.   n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
  1154.   if (n == NULL)
  1155.     return FALSE;
  1156.  
  1157.   v = (struct debug_variable *) xmalloc (sizeof *v);
  1158.   memset (v, 0, sizeof *v);
  1159.  
  1160.   v->kind = kind;
  1161.   v->type = type;
  1162.   v->val = val;
  1163.  
  1164.   n->u.variable = v;
  1165.  
  1166.   return TRUE;
  1167. }
  1168.  
  1169. /* Make a type with a given kind and size.  */
  1170.  
  1171. static struct debug_type_s *
  1172. debug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
  1173.                  enum debug_type_kind kind, unsigned int size)
  1174. {
  1175.   struct debug_type_s *t;
  1176.  
  1177.   t = (struct debug_type_s *) xmalloc (sizeof *t);
  1178.   memset (t, 0, sizeof *t);
  1179.  
  1180.   t->kind = kind;
  1181.   t->size = size;
  1182.  
  1183.   return t;
  1184. }
  1185.  
  1186. /* Make an indirect type which may be used as a placeholder for a type
  1187.    which is referenced before it is defined.  */
  1188.  
  1189. debug_type
  1190. debug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
  1191. {
  1192.   struct debug_handle *info = (struct debug_handle *) handle;
  1193.   struct debug_type_s *t;
  1194.   struct debug_indirect_type *i;
  1195.  
  1196.   t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
  1197.   if (t == NULL)
  1198.     return DEBUG_TYPE_NULL;
  1199.  
  1200.   i = (struct debug_indirect_type *) xmalloc (sizeof *i);
  1201.   memset (i, 0, sizeof *i);
  1202.  
  1203.   i->slot = slot;
  1204.   i->tag = tag;
  1205.  
  1206.   t->u.kindirect = i;
  1207.  
  1208.   return t;
  1209. }
  1210.  
  1211. /* Make a void type.  There is only one of these.  */
  1212.  
  1213. debug_type
  1214. debug_make_void_type (void *handle)
  1215. {
  1216.   struct debug_handle *info = (struct debug_handle *) handle;
  1217.  
  1218.   return debug_make_type (info, DEBUG_KIND_VOID, 0);
  1219. }
  1220.  
  1221. /* Make an integer type of a given size.  The boolean argument is true
  1222.    if the integer is unsigned.  */
  1223.  
  1224. debug_type
  1225. debug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
  1226. {
  1227.   struct debug_handle *info = (struct debug_handle *) handle;
  1228.   struct debug_type_s *t;
  1229.  
  1230.   t = debug_make_type (info, DEBUG_KIND_INT, size);
  1231.   if (t == NULL)
  1232.     return DEBUG_TYPE_NULL;
  1233.  
  1234.   t->u.kint = unsignedp;
  1235.  
  1236.   return t;
  1237. }
  1238.  
  1239. /* Make a floating point type of a given size.  FIXME: On some
  1240.    platforms, like an Alpha, you probably need to be able to specify
  1241.    the format.  */
  1242.  
  1243. debug_type
  1244. debug_make_float_type (void *handle, unsigned int size)
  1245. {
  1246.   struct debug_handle *info = (struct debug_handle *) handle;
  1247.  
  1248.   return debug_make_type (info, DEBUG_KIND_FLOAT, size);
  1249. }
  1250.  
  1251. /* Make a boolean type of a given size.  */
  1252.  
  1253. debug_type
  1254. debug_make_bool_type (void *handle, unsigned int size)
  1255. {
  1256.   struct debug_handle *info = (struct debug_handle *) handle;
  1257.  
  1258.   return debug_make_type (info, DEBUG_KIND_BOOL, size);
  1259. }
  1260.  
  1261. /* Make a complex type of a given size.  */
  1262.  
  1263. debug_type
  1264. debug_make_complex_type (void *handle, unsigned int size)
  1265. {
  1266.   struct debug_handle *info = (struct debug_handle *) handle;
  1267.  
  1268.   return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
  1269. }
  1270.  
  1271. /* Make a structure type.  The second argument is true for a struct,
  1272.    false for a union.  The third argument is the size of the struct.
  1273.    The fourth argument is a NULL terminated array of fields.  */
  1274.  
  1275. debug_type
  1276. debug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
  1277.                         debug_field *fields)
  1278. {
  1279.   struct debug_handle *info = (struct debug_handle *) handle;
  1280.   struct debug_type_s *t;
  1281.   struct debug_class_type *c;
  1282.  
  1283.   t = debug_make_type (info,
  1284.                        structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
  1285.                        size);
  1286.   if (t == NULL)
  1287.     return DEBUG_TYPE_NULL;
  1288.  
  1289.   c = (struct debug_class_type *) xmalloc (sizeof *c);
  1290.   memset (c, 0, sizeof *c);
  1291.  
  1292.   c->fields = fields;
  1293.  
  1294.   t->u.kclass = c;
  1295.  
  1296.   return t;
  1297. }
  1298.  
  1299. /* Make an object type.  The first three arguments after the handle
  1300.    are the same as for debug_make_struct_type.  The next arguments are
  1301.    a NULL terminated array of base classes, a NULL terminated array of
  1302.    methods, the type of the object holding the virtual function table
  1303.    if it is not this object, and a boolean which is true if this
  1304.    object has its own virtual function table.  */
  1305.  
  1306. debug_type
  1307. debug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
  1308.                         debug_field *fields, debug_baseclass *baseclasses,
  1309.                         debug_method *methods, debug_type vptrbase,
  1310.                         bfd_boolean ownvptr)
  1311. {
  1312.   struct debug_handle *info = (struct debug_handle *) handle;
  1313.   struct debug_type_s *t;
  1314.   struct debug_class_type *c;
  1315.  
  1316.   t = debug_make_type (info,
  1317.                        structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
  1318.                        size);
  1319.   if (t == NULL)
  1320.     return DEBUG_TYPE_NULL;
  1321.  
  1322.   c = (struct debug_class_type *) xmalloc (sizeof *c);
  1323.   memset (c, 0, sizeof *c);
  1324.  
  1325.   c->fields = fields;
  1326.   c->baseclasses = baseclasses;
  1327.   c->methods = methods;
  1328.   if (ownvptr)
  1329.     c->vptrbase = t;
  1330.   else
  1331.     c->vptrbase = vptrbase;
  1332.  
  1333.   t->u.kclass = c;
  1334.  
  1335.   return t;
  1336. }
  1337.  
  1338. /* Make an enumeration type.  The arguments are a null terminated
  1339.    array of strings, and an array of corresponding values.  */
  1340.  
  1341. debug_type
  1342. debug_make_enum_type (void *handle, const char **names,
  1343.                       bfd_signed_vma *values)
  1344. {
  1345.   struct debug_handle *info = (struct debug_handle *) handle;
  1346.   struct debug_type_s *t;
  1347.   struct debug_enum_type *e;
  1348.  
  1349.   t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
  1350.   if (t == NULL)
  1351.     return DEBUG_TYPE_NULL;
  1352.  
  1353.   e = (struct debug_enum_type *) xmalloc (sizeof *e);
  1354.   memset (e, 0, sizeof *e);
  1355.  
  1356.   e->names = names;
  1357.   e->values = values;
  1358.  
  1359.   t->u.kenum = e;
  1360.  
  1361.   return t;
  1362. }
  1363.  
  1364. /* Make a pointer to a given type.  */
  1365.  
  1366. debug_type
  1367. debug_make_pointer_type (void *handle, debug_type type)
  1368. {
  1369.   struct debug_handle *info = (struct debug_handle *) handle;
  1370.   struct debug_type_s *t;
  1371.  
  1372.   if (type == NULL)
  1373.     return DEBUG_TYPE_NULL;
  1374.  
  1375.   if (type->pointer != DEBUG_TYPE_NULL)
  1376.     return type->pointer;
  1377.  
  1378.   t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
  1379.   if (t == NULL)
  1380.     return DEBUG_TYPE_NULL;
  1381.  
  1382.   t->u.kpointer = type;
  1383.  
  1384.   type->pointer = t;
  1385.  
  1386.   return t;
  1387. }
  1388.  
  1389. /* Make a function returning a given type.  FIXME: We should be able
  1390.    to record the parameter types.  */
  1391.  
  1392. debug_type
  1393. debug_make_function_type (void *handle, debug_type type,
  1394.                           debug_type *arg_types, bfd_boolean varargs)
  1395. {
  1396.   struct debug_handle *info = (struct debug_handle *) handle;
  1397.   struct debug_type_s *t;
  1398.   struct debug_function_type *f;
  1399.  
  1400.   if (type == NULL)
  1401.     return DEBUG_TYPE_NULL;
  1402.  
  1403.   t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
  1404.   if (t == NULL)
  1405.     return DEBUG_TYPE_NULL;
  1406.  
  1407.   f = (struct debug_function_type *) xmalloc (sizeof *f);
  1408.   memset (f, 0, sizeof *f);
  1409.  
  1410.   f->return_type = type;
  1411.   f->arg_types = arg_types;
  1412.   f->varargs = varargs;
  1413.  
  1414.   t->u.kfunction = f;
  1415.  
  1416.   return t;
  1417. }
  1418.  
  1419. /* Make a reference to a given type.  */
  1420.  
  1421. debug_type
  1422. debug_make_reference_type (void *handle, debug_type type)
  1423. {
  1424.   struct debug_handle *info = (struct debug_handle *) handle;
  1425.   struct debug_type_s *t;
  1426.  
  1427.   if (type == NULL)
  1428.     return DEBUG_TYPE_NULL;
  1429.  
  1430.   t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
  1431.   if (t == NULL)
  1432.     return DEBUG_TYPE_NULL;
  1433.  
  1434.   t->u.kreference = type;
  1435.  
  1436.   return t;
  1437. }
  1438.  
  1439. /* Make a range of a given type from a lower to an upper bound.  */
  1440.  
  1441. debug_type
  1442. debug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
  1443.                        bfd_signed_vma upper)
  1444. {
  1445.   struct debug_handle *info = (struct debug_handle *) handle;
  1446.   struct debug_type_s *t;
  1447.   struct debug_range_type *r;
  1448.  
  1449.   if (type == NULL)
  1450.     return DEBUG_TYPE_NULL;
  1451.  
  1452.   t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
  1453.   if (t == NULL)
  1454.     return DEBUG_TYPE_NULL;
  1455.  
  1456.   r = (struct debug_range_type *) xmalloc (sizeof *r);
  1457.   memset (r, 0, sizeof *r);
  1458.  
  1459.   r->type = type;
  1460.   r->lower = lower;
  1461.   r->upper = upper;
  1462.  
  1463.   t->u.krange = r;
  1464.  
  1465.   return t;
  1466. }
  1467.  
  1468. /* Make an array type.  The second argument is the type of an element
  1469.    of the array.  The third argument is the type of a range of the
  1470.    array.  The fourth and fifth argument are the lower and upper
  1471.    bounds, respectively.  The sixth argument is true if this array is
  1472.    actually a string, as in C.  */
  1473.  
  1474. debug_type
  1475. debug_make_array_type (void *handle, debug_type element_type,
  1476.                        debug_type range_type, bfd_signed_vma lower,
  1477.                        bfd_signed_vma upper, bfd_boolean stringp)
  1478. {
  1479.   struct debug_handle *info = (struct debug_handle *) handle;
  1480.   struct debug_type_s *t;
  1481.   struct debug_array_type *a;
  1482.  
  1483.   if (element_type == NULL || range_type == NULL)
  1484.     return DEBUG_TYPE_NULL;
  1485.  
  1486.   t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
  1487.   if (t == NULL)
  1488.     return DEBUG_TYPE_NULL;
  1489.  
  1490.   a = (struct debug_array_type *) xmalloc (sizeof *a);
  1491.   memset (a, 0, sizeof *a);
  1492.  
  1493.   a->element_type = element_type;
  1494.   a->range_type = range_type;
  1495.   a->lower = lower;
  1496.   a->upper = upper;
  1497.   a->stringp = stringp;
  1498.  
  1499.   t->u.karray = a;
  1500.  
  1501.   return t;
  1502. }
  1503.  
  1504. /* Make a set of a given type.  For example, a Pascal set type.  The
  1505.    boolean argument is true if this set is actually a bitstring, as in
  1506.    CHILL.  */
  1507.  
  1508. debug_type
  1509. debug_make_set_type (void *handle, debug_type type, bfd_boolean bitstringp)
  1510. {
  1511.   struct debug_handle *info = (struct debug_handle *) handle;
  1512.   struct debug_type_s *t;
  1513.   struct debug_set_type *s;
  1514.  
  1515.   if (type == NULL)
  1516.     return DEBUG_TYPE_NULL;
  1517.  
  1518.   t = debug_make_type (info, DEBUG_KIND_SET, 0);
  1519.   if (t == NULL)
  1520.     return DEBUG_TYPE_NULL;
  1521.  
  1522.   s = (struct debug_set_type *) xmalloc (sizeof *s);
  1523.   memset (s, 0, sizeof *s);
  1524.  
  1525.   s->type = type;
  1526.   s->bitstringp = bitstringp;
  1527.  
  1528.   t->u.kset = s;
  1529.  
  1530.   return t;
  1531. }
  1532.  
  1533. /* Make a type for a pointer which is relative to an object.  The
  1534.    second argument is the type of the object to which the pointer is
  1535.    relative.  The third argument is the type that the pointer points
  1536.    to.  */
  1537.  
  1538. debug_type
  1539. debug_make_offset_type (void *handle, debug_type base_type,
  1540.                         debug_type target_type)
  1541. {
  1542.   struct debug_handle *info = (struct debug_handle *) handle;
  1543.   struct debug_type_s *t;
  1544.   struct debug_offset_type *o;
  1545.  
  1546.   if (base_type == NULL || target_type == NULL)
  1547.     return DEBUG_TYPE_NULL;
  1548.  
  1549.   t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
  1550.   if (t == NULL)
  1551.     return DEBUG_TYPE_NULL;
  1552.  
  1553.   o = (struct debug_offset_type *) xmalloc (sizeof *o);
  1554.   memset (o, 0, sizeof *o);
  1555.  
  1556.   o->base_type = base_type;
  1557.   o->target_type = target_type;
  1558.  
  1559.   t->u.koffset = o;
  1560.  
  1561.   return t;
  1562. }
  1563.  
  1564. /* Make a type for a method function.  The second argument is the
  1565.    return type, the third argument is the domain, and the fourth
  1566.    argument is a NULL terminated array of argument types.  */
  1567.  
  1568. debug_type
  1569. debug_make_method_type (void *handle, debug_type return_type,
  1570.                         debug_type domain_type, debug_type *arg_types,
  1571.                         bfd_boolean varargs)
  1572. {
  1573.   struct debug_handle *info = (struct debug_handle *) handle;
  1574.   struct debug_type_s *t;
  1575.   struct debug_method_type *m;
  1576.  
  1577.   if (return_type == NULL)
  1578.     return DEBUG_TYPE_NULL;
  1579.  
  1580.   t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
  1581.   if (t == NULL)
  1582.     return DEBUG_TYPE_NULL;
  1583.  
  1584.   m = (struct debug_method_type *) xmalloc (sizeof *m);
  1585.   memset (m, 0, sizeof *m);
  1586.  
  1587.   m->return_type = return_type;
  1588.   m->domain_type = domain_type;
  1589.   m->arg_types = arg_types;
  1590.   m->varargs = varargs;
  1591.  
  1592.   t->u.kmethod = m;
  1593.  
  1594.   return t;
  1595. }
  1596.  
  1597. /* Make a const qualified version of a given type.  */
  1598.  
  1599. debug_type
  1600. debug_make_const_type (void *handle, debug_type type)
  1601. {
  1602.   struct debug_handle *info = (struct debug_handle *) handle;
  1603.   struct debug_type_s *t;
  1604.  
  1605.   if (type == NULL)
  1606.     return DEBUG_TYPE_NULL;
  1607.  
  1608.   t = debug_make_type (info, DEBUG_KIND_CONST, 0);
  1609.   if (t == NULL)
  1610.     return DEBUG_TYPE_NULL;
  1611.  
  1612.   t->u.kconst = type;
  1613.  
  1614.   return t;
  1615. }
  1616.  
  1617. /* Make a volatile qualified version of a given type.  */
  1618.  
  1619. debug_type
  1620. debug_make_volatile_type (void *handle, debug_type type)
  1621. {
  1622.   struct debug_handle *info = (struct debug_handle *) handle;
  1623.   struct debug_type_s *t;
  1624.  
  1625.   if (type == NULL)
  1626.     return DEBUG_TYPE_NULL;
  1627.  
  1628.   t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
  1629.   if (t == NULL)
  1630.     return DEBUG_TYPE_NULL;
  1631.  
  1632.   t->u.kvolatile = type;
  1633.  
  1634.   return t;
  1635. }
  1636.  
  1637. /* Make an undefined tagged type.  For example, a struct which has
  1638.    been mentioned, but not defined.  */
  1639.  
  1640. debug_type
  1641. debug_make_undefined_tagged_type (void *handle, const char *name,
  1642.                                   enum debug_type_kind kind)
  1643. {
  1644.   struct debug_handle *info = (struct debug_handle *) handle;
  1645.   struct debug_type_s *t;
  1646.  
  1647.   if (name == NULL)
  1648.     return DEBUG_TYPE_NULL;
  1649.  
  1650.   switch (kind)
  1651.     {
  1652.     case DEBUG_KIND_STRUCT:
  1653.     case DEBUG_KIND_UNION:
  1654.     case DEBUG_KIND_CLASS:
  1655.     case DEBUG_KIND_UNION_CLASS:
  1656.     case DEBUG_KIND_ENUM:
  1657.       break;
  1658.  
  1659.     default:
  1660.       debug_error (_("debug_make_undefined_type: unsupported kind"));
  1661.       return DEBUG_TYPE_NULL;
  1662.     }
  1663.  
  1664.   t = debug_make_type (info, kind, 0);
  1665.   if (t == NULL)
  1666.     return DEBUG_TYPE_NULL;
  1667.  
  1668.   return debug_tag_type (handle, name, t);
  1669. }
  1670.  
  1671. /* Make a base class for an object.  The second argument is the base
  1672.    class type.  The third argument is the bit position of this base
  1673.    class in the object (always 0 unless doing multiple inheritance).
  1674.    The fourth argument is whether this is a virtual class.  The fifth
  1675.    argument is the visibility of the base class.  */
  1676.  
  1677. debug_baseclass
  1678. debug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
  1679.                       bfd_vma bitpos, bfd_boolean is_virtual,
  1680.                       enum debug_visibility visibility)
  1681. {
  1682.   struct debug_baseclass_s *b;
  1683.  
  1684.   b = (struct debug_baseclass_s *) xmalloc (sizeof *b);
  1685.   memset (b, 0, sizeof *b);
  1686.  
  1687.   b->type = type;
  1688.   b->bitpos = bitpos;
  1689.   b->is_virtual = is_virtual;
  1690.   b->visibility = visibility;
  1691.  
  1692.   return b;
  1693. }
  1694.  
  1695. /* Make a field for a struct.  The second argument is the name.  The
  1696.    third argument is the type of the field.  The fourth argument is
  1697.    the bit position of the field.  The fifth argument is the size of
  1698.    the field (it may be zero).  The sixth argument is the visibility
  1699.    of the field.  */
  1700.  
  1701. debug_field
  1702. debug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
  1703.                   debug_type type, bfd_vma bitpos, bfd_vma bitsize,
  1704.                   enum debug_visibility visibility)
  1705. {
  1706.   struct debug_field_s *f;
  1707.  
  1708.   f = (struct debug_field_s *) xmalloc (sizeof *f);
  1709.   memset (f, 0, sizeof *f);
  1710.  
  1711.   f->name = name;
  1712.   f->type = type;
  1713.   f->static_member = FALSE;
  1714.   f->u.f.bitpos = bitpos;
  1715.   f->u.f.bitsize = bitsize;
  1716.   f->visibility = visibility;
  1717.  
  1718.   return f;
  1719. }
  1720.  
  1721. /* Make a static member of an object.  The second argument is the
  1722.    name.  The third argument is the type of the member.  The fourth
  1723.    argument is the physical name of the member (i.e., the name as a
  1724.    global variable).  The fifth argument is the visibility of the
  1725.    member.  */
  1726.  
  1727. debug_field
  1728. debug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
  1729.                           debug_type type, const char *physname,
  1730.                           enum debug_visibility visibility)
  1731. {
  1732.   struct debug_field_s *f;
  1733.  
  1734.   f = (struct debug_field_s *) xmalloc (sizeof *f);
  1735.   memset (f, 0, sizeof *f);
  1736.  
  1737.   f->name = name;
  1738.   f->type = type;
  1739.   f->static_member = TRUE;
  1740.   f->u.s.physname = physname;
  1741.   f->visibility = visibility;
  1742.  
  1743.   return f;
  1744. }
  1745.  
  1746. /* Make a method.  The second argument is the name, and the third
  1747.    argument is a NULL terminated array of method variants.  */
  1748.  
  1749. debug_method
  1750. debug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
  1751.                    debug_method_variant *variants)
  1752. {
  1753.   struct debug_method_s *m;
  1754.  
  1755.   m = (struct debug_method_s *) xmalloc (sizeof *m);
  1756.   memset (m, 0, sizeof *m);
  1757.  
  1758.   m->name = name;
  1759.   m->variants = variants;
  1760.  
  1761.   return m;
  1762. }
  1763.  
  1764. /* Make a method argument.  The second argument is the real name of
  1765.    the function.  The third argument is the type of the function.  The
  1766.    fourth argument is the visibility.  The fifth argument is whether
  1767.    this is a const function.  The sixth argument is whether this is a
  1768.    volatile function.  The seventh argument is the offset in the
  1769.    virtual function table, if any.  The eighth argument is the virtual
  1770.    function context.  FIXME: Are the const and volatile arguments
  1771.    necessary?  Could we just use debug_make_const_type?  */
  1772.  
  1773. debug_method_variant
  1774. debug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
  1775.                            const char *physname, debug_type type,
  1776.                            enum debug_visibility visibility,
  1777.                            bfd_boolean constp, bfd_boolean volatilep,
  1778.                            bfd_vma voffset, debug_type context)
  1779. {
  1780.   struct debug_method_variant_s *m;
  1781.  
  1782.   m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
  1783.   memset (m, 0, sizeof *m);
  1784.  
  1785.   m->physname = physname;
  1786.   m->type = type;
  1787.   m->visibility = visibility;
  1788.   m->constp = constp;
  1789.   m->volatilep = volatilep;
  1790.   m->voffset = voffset;
  1791.   m->context = context;
  1792.  
  1793.   return m;
  1794. }
  1795.  
  1796. /* Make a static method argument.  The arguments are the same as for
  1797.    debug_make_method_variant, except that the last two are omitted
  1798.    since a static method can not also be virtual.  */
  1799.  
  1800. debug_method_variant
  1801. debug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
  1802.                                   const char *physname, debug_type type,
  1803.                                   enum debug_visibility visibility,
  1804.                                   bfd_boolean constp, bfd_boolean volatilep)
  1805. {
  1806.   struct debug_method_variant_s *m;
  1807.  
  1808.   m = (struct debug_method_variant_s *) xmalloc (sizeof *m);
  1809.   memset (m, 0, sizeof *m);
  1810.  
  1811.   m->physname = physname;
  1812.   m->type = type;
  1813.   m->visibility = visibility;
  1814.   m->constp = constp;
  1815.   m->volatilep = volatilep;
  1816.   m->voffset = VOFFSET_STATIC_METHOD;
  1817.  
  1818.   return m;
  1819. }
  1820.  
  1821. /* Name a type.  */
  1822.  
  1823. debug_type
  1824. debug_name_type (void *handle, const char *name, debug_type type)
  1825. {
  1826.   struct debug_handle *info = (struct debug_handle *) handle;
  1827.   struct debug_type_s *t;
  1828.   struct debug_named_type *n;
  1829.   struct debug_name *nm;
  1830.  
  1831.   if (name == NULL || type == NULL)
  1832.     return DEBUG_TYPE_NULL;
  1833.  
  1834.   if (info->current_unit == NULL
  1835.       || info->current_file == NULL)
  1836.     {
  1837.       debug_error (_("debug_name_type: no current file"));
  1838.       return DEBUG_TYPE_NULL;
  1839.     }
  1840.  
  1841.   t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
  1842.   if (t == NULL)
  1843.     return DEBUG_TYPE_NULL;
  1844.  
  1845.   n = (struct debug_named_type *) xmalloc (sizeof *n);
  1846.   memset (n, 0, sizeof *n);
  1847.  
  1848.   n->type = type;
  1849.  
  1850.   t->u.knamed = n;
  1851.  
  1852.   /* We always add the name to the global namespace.  This is probably
  1853.      wrong in some cases, but it seems to be right for stabs.  FIXME.  */
  1854.  
  1855.   nm = debug_add_to_namespace (info, &info->current_file->globals, name,
  1856.                                DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
  1857.   if (nm == NULL)
  1858.     return DEBUG_TYPE_NULL;
  1859.  
  1860.   nm->u.type = t;
  1861.  
  1862.   n->name = nm;
  1863.  
  1864.   return t;
  1865. }
  1866.  
  1867. /* Tag a type.  */
  1868.  
  1869. debug_type
  1870. debug_tag_type (void *handle, const char *name, debug_type type)
  1871. {
  1872.   struct debug_handle *info = (struct debug_handle *) handle;
  1873.   struct debug_type_s *t;
  1874.   struct debug_named_type *n;
  1875.   struct debug_name *nm;
  1876.  
  1877.   if (name == NULL || type == NULL)
  1878.     return DEBUG_TYPE_NULL;
  1879.  
  1880.   if (info->current_file == NULL)
  1881.     {
  1882.       debug_error (_("debug_tag_type: no current file"));
  1883.       return DEBUG_TYPE_NULL;
  1884.     }
  1885.  
  1886.   if (type->kind == DEBUG_KIND_TAGGED)
  1887.     {
  1888.       if (strcmp (type->u.knamed->name->name, name) == 0)
  1889.         return type;
  1890.       debug_error (_("debug_tag_type: extra tag attempted"));
  1891.       return DEBUG_TYPE_NULL;
  1892.     }
  1893.  
  1894.   t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
  1895.   if (t == NULL)
  1896.     return DEBUG_TYPE_NULL;
  1897.  
  1898.   n = (struct debug_named_type *) xmalloc (sizeof *n);
  1899.   memset (n, 0, sizeof *n);
  1900.  
  1901.   n->type = type;
  1902.  
  1903.   t->u.knamed = n;
  1904.  
  1905.   /* We keep a global namespace of tags for each compilation unit.  I
  1906.      don't know if that is the right thing to do.  */
  1907.  
  1908.   nm = debug_add_to_namespace (info, &info->current_file->globals, name,
  1909.                                DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
  1910.   if (nm == NULL)
  1911.     return DEBUG_TYPE_NULL;
  1912.  
  1913.   nm->u.tag = t;
  1914.  
  1915.   n->name = nm;
  1916.  
  1917.   return t;
  1918. }
  1919.  
  1920. /* Record the size of a given type.  */
  1921.  
  1922. bfd_boolean
  1923. debug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
  1924.                         unsigned int size)
  1925. {
  1926.   if (type->size != 0 && type->size != size)
  1927.     fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
  1928.              type->size, size);
  1929.  
  1930.   type->size = size;
  1931.  
  1932.   return TRUE;
  1933. }
  1934.  
  1935. /* Find a named type.  */
  1936.  
  1937. debug_type
  1938. debug_find_named_type (void *handle, const char *name)
  1939. {
  1940.   struct debug_handle *info = (struct debug_handle *) handle;
  1941.   struct debug_block *b;
  1942.   struct debug_file *f;
  1943.  
  1944.   /* We only search the current compilation unit.  I don't know if
  1945.      this is right or not.  */
  1946.  
  1947.   if (info->current_unit == NULL)
  1948.     {
  1949.       debug_error (_("debug_find_named_type: no current compilation unit"));
  1950.       return DEBUG_TYPE_NULL;
  1951.     }
  1952.  
  1953.   for (b = info->current_block; b != NULL; b = b->parent)
  1954.     {
  1955.       if (b->locals != NULL)
  1956.         {
  1957.           struct debug_name *n;
  1958.  
  1959.           for (n = b->locals->list; n != NULL; n = n->next)
  1960.             {
  1961.               if (n->kind == DEBUG_OBJECT_TYPE
  1962.                   && n->name[0] == name[0]
  1963.                   && strcmp (n->name, name) == 0)
  1964.                 return n->u.type;
  1965.             }
  1966.         }
  1967.     }
  1968.  
  1969.   for (f = info->current_unit->files; f != NULL; f = f->next)
  1970.     {
  1971.       if (f->globals != NULL)
  1972.         {
  1973.           struct debug_name *n;
  1974.  
  1975.           for (n = f->globals->list; n != NULL; n = n->next)
  1976.             {
  1977.               if (n->kind == DEBUG_OBJECT_TYPE
  1978.                   && n->name[0] == name[0]
  1979.                   && strcmp (n->name, name) == 0)
  1980.                 return n->u.type;
  1981.             }
  1982.         }
  1983.     }
  1984.  
  1985.   return DEBUG_TYPE_NULL;
  1986. }
  1987.  
  1988. /* Find a tagged type.  */
  1989.  
  1990. debug_type
  1991. debug_find_tagged_type (void *handle, const char *name,
  1992.                         enum debug_type_kind kind)
  1993. {
  1994.   struct debug_handle *info = (struct debug_handle *) handle;
  1995.   struct debug_unit *u;
  1996.  
  1997.   /* We search the globals of all the compilation units.  I don't know
  1998.      if this is correct or not.  It would be easy to change.  */
  1999.  
  2000.   for (u = info->units; u != NULL; u = u->next)
  2001.     {
  2002.       struct debug_file *f;
  2003.  
  2004.       for (f = u->files; f != NULL; f = f->next)
  2005.         {
  2006.           struct debug_name *n;
  2007.  
  2008.           if (f->globals != NULL)
  2009.             {
  2010.               for (n = f->globals->list; n != NULL; n = n->next)
  2011.                 {
  2012.                   if (n->kind == DEBUG_OBJECT_TAG
  2013.                       && (kind == DEBUG_KIND_ILLEGAL
  2014.                           || n->u.tag->kind == kind)
  2015.                       && n->name[0] == name[0]
  2016.                       && strcmp (n->name, name) == 0)
  2017.                     return n->u.tag;
  2018.                 }
  2019.             }
  2020.         }
  2021.     }
  2022.  
  2023.   return DEBUG_TYPE_NULL;
  2024. }
  2025.  
  2026. /* Get a base type.  We build a linked list on the stack to avoid
  2027.    crashing if the type is defined circularly.  */
  2028.  
  2029. static struct debug_type_s *
  2030. debug_get_real_type (void *handle, debug_type type,
  2031.                      struct debug_type_real_list *list)
  2032. {
  2033.   struct debug_type_real_list *l;
  2034.   struct debug_type_real_list rl;
  2035.  
  2036.   switch (type->kind)
  2037.     {
  2038.     default:
  2039.       return type;
  2040.  
  2041.     case DEBUG_KIND_INDIRECT:
  2042.     case DEBUG_KIND_NAMED:
  2043.     case DEBUG_KIND_TAGGED:
  2044.       break;
  2045.     }
  2046.  
  2047.   for (l = list; l != NULL; l = l->next)
  2048.     {
  2049.       if (l->t == type || l == l->next)
  2050.         {
  2051.           fprintf (stderr,
  2052.                    _("debug_get_real_type: circular debug information for %s\n"),
  2053.                    debug_get_type_name (handle, type));
  2054.           return NULL;
  2055.         }
  2056.     }
  2057.  
  2058.   rl.next = list;
  2059.   rl.t = type;
  2060.  
  2061.   switch (type->kind)
  2062.     {
  2063.       /* The default case is just here to avoid warnings.  */
  2064.     default:
  2065.     case DEBUG_KIND_INDIRECT:
  2066.       if (*type->u.kindirect->slot != NULL)
  2067.         return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
  2068.       return type;
  2069.     case DEBUG_KIND_NAMED:
  2070.     case DEBUG_KIND_TAGGED:
  2071.       return debug_get_real_type (handle, type->u.knamed->type, &rl);
  2072.     }
  2073.   /*NOTREACHED*/
  2074. }
  2075.  
  2076. /* Get the kind of a type.  */
  2077.  
  2078. enum debug_type_kind
  2079. debug_get_type_kind (void *handle, debug_type type)
  2080. {
  2081.   if (type == NULL)
  2082.     return DEBUG_KIND_ILLEGAL;
  2083.   type = debug_get_real_type (handle, type, NULL);
  2084.   if (type == NULL)
  2085.     return DEBUG_KIND_ILLEGAL;
  2086.   return type->kind;
  2087. }
  2088.  
  2089. /* Get the name of a type.  */
  2090.  
  2091. const char *
  2092. debug_get_type_name (void *handle, debug_type type)
  2093. {
  2094.   if (type->kind == DEBUG_KIND_INDIRECT)
  2095.     {
  2096.       if (*type->u.kindirect->slot != NULL)
  2097.         return debug_get_type_name (handle, *type->u.kindirect->slot);
  2098.       return type->u.kindirect->tag;
  2099.     }
  2100.   if (type->kind == DEBUG_KIND_NAMED
  2101.       || type->kind == DEBUG_KIND_TAGGED)
  2102.     return type->u.knamed->name->name;
  2103.   return NULL;
  2104. }
  2105.  
  2106. /* Get the size of a type.  */
  2107.  
  2108. bfd_vma
  2109. debug_get_type_size (void *handle, debug_type type)
  2110. {
  2111.   if (type == NULL)
  2112.     return 0;
  2113.  
  2114.   /* We don't call debug_get_real_type, because somebody might have
  2115.      called debug_record_type_size on a named or indirect type.  */
  2116.  
  2117.   if (type->size != 0)
  2118.     return type->size;
  2119.  
  2120.   switch (type->kind)
  2121.     {
  2122.     default:
  2123.       return 0;
  2124.     case DEBUG_KIND_INDIRECT:
  2125.       if (*type->u.kindirect->slot != NULL)
  2126.         return debug_get_type_size (handle, *type->u.kindirect->slot);
  2127.       return 0;
  2128.     case DEBUG_KIND_NAMED:
  2129.     case DEBUG_KIND_TAGGED:
  2130.       return debug_get_type_size (handle, type->u.knamed->type);
  2131.     }
  2132.   /*NOTREACHED*/
  2133. }
  2134.  
  2135. /* Get the return type of a function or method type.  */
  2136.  
  2137. debug_type
  2138. debug_get_return_type (void *handle, debug_type type)
  2139. {
  2140.   if (type == NULL)
  2141.     return DEBUG_TYPE_NULL;
  2142.  
  2143.   type = debug_get_real_type (handle, type, NULL);
  2144.   if (type == NULL)
  2145.     return DEBUG_TYPE_NULL;
  2146.  
  2147.   switch (type->kind)
  2148.     {
  2149.     default:
  2150.       return DEBUG_TYPE_NULL;
  2151.     case DEBUG_KIND_FUNCTION:
  2152.       return type->u.kfunction->return_type;
  2153.     case DEBUG_KIND_METHOD:
  2154.       return type->u.kmethod->return_type;
  2155.     }
  2156.   /*NOTREACHED*/
  2157. }
  2158.  
  2159. /* Get the parameter types of a function or method type (except that
  2160.    we don't currently store the parameter types of a function).  */
  2161.  
  2162. const debug_type *
  2163. debug_get_parameter_types (void *handle, debug_type type,
  2164.                            bfd_boolean *pvarargs)
  2165. {
  2166.   if (type == NULL)
  2167.     return NULL;
  2168.  
  2169.   type = debug_get_real_type (handle, type, NULL);
  2170.   if (type == NULL)
  2171.     return NULL;
  2172.  
  2173.   switch (type->kind)
  2174.     {
  2175.     default:
  2176.       return NULL;
  2177.     case DEBUG_KIND_FUNCTION:
  2178.       *pvarargs = type->u.kfunction->varargs;
  2179.       return type->u.kfunction->arg_types;
  2180.     case DEBUG_KIND_METHOD:
  2181.       *pvarargs = type->u.kmethod->varargs;
  2182.       return type->u.kmethod->arg_types;
  2183.     }
  2184.   /*NOTREACHED*/
  2185. }
  2186.  
  2187. /* Get the target type of a type.  */
  2188.  
  2189. debug_type
  2190. debug_get_target_type (void *handle, debug_type type)
  2191. {
  2192.   if (type == NULL)
  2193.     return NULL;
  2194.  
  2195.   type = debug_get_real_type (handle, type, NULL);
  2196.   if (type == NULL)
  2197.     return NULL;
  2198.  
  2199.   switch (type->kind)
  2200.     {
  2201.     default:
  2202.       return NULL;
  2203.     case DEBUG_KIND_POINTER:
  2204.       return type->u.kpointer;
  2205.     case DEBUG_KIND_REFERENCE:
  2206.       return type->u.kreference;
  2207.     case DEBUG_KIND_CONST:
  2208.       return type->u.kconst;
  2209.     case DEBUG_KIND_VOLATILE:
  2210.       return type->u.kvolatile;
  2211.     }
  2212.   /*NOTREACHED*/
  2213. }
  2214.  
  2215. /* Get the NULL terminated array of fields for a struct, union, or
  2216.    class.  */
  2217.  
  2218. const debug_field *
  2219. debug_get_fields (void *handle, debug_type type)
  2220. {
  2221.   if (type == NULL)
  2222.     return NULL;
  2223.  
  2224.   type = debug_get_real_type (handle, type, NULL);
  2225.   if (type == NULL)
  2226.     return NULL;
  2227.  
  2228.   switch (type->kind)
  2229.     {
  2230.     default:
  2231.       return NULL;
  2232.     case DEBUG_KIND_STRUCT:
  2233.     case DEBUG_KIND_UNION:
  2234.     case DEBUG_KIND_CLASS:
  2235.     case DEBUG_KIND_UNION_CLASS:
  2236.       return type->u.kclass->fields;
  2237.     }
  2238.   /*NOTREACHED*/
  2239. }
  2240.  
  2241. /* Get the type of a field.  */
  2242.  
  2243. debug_type
  2244. debug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2245. {
  2246.   if (field == NULL)
  2247.     return NULL;
  2248.   return field->type;
  2249. }
  2250.  
  2251. /* Get the name of a field.  */
  2252.  
  2253. const char *
  2254. debug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2255. {
  2256.   if (field == NULL)
  2257.     return NULL;
  2258.   return field->name;
  2259. }
  2260.  
  2261. /* Get the bit position of a field.  */
  2262.  
  2263. bfd_vma
  2264. debug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2265. {
  2266.   if (field == NULL || field->static_member)
  2267.     return (bfd_vma) -1;
  2268.   return field->u.f.bitpos;
  2269. }
  2270.  
  2271. /* Get the bit size of a field.  */
  2272.  
  2273. bfd_vma
  2274. debug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2275. {
  2276.   if (field == NULL || field->static_member)
  2277.     return (bfd_vma) -1;
  2278.   return field->u.f.bitsize;
  2279. }
  2280.  
  2281. /* Get the visibility of a field.  */
  2282.  
  2283. enum debug_visibility
  2284. debug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2285. {
  2286.   if (field == NULL)
  2287.     return DEBUG_VISIBILITY_IGNORE;
  2288.   return field->visibility;
  2289. }
  2290.  
  2291. /* Get the physical name of a field.  */
  2292.  
  2293. const char *
  2294. debug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
  2295. {
  2296.   if (field == NULL || ! field->static_member)
  2297.     return NULL;
  2298.   return field->u.s.physname;
  2299. }
  2300. /* Write out the debugging information.  This is given a handle to
  2301.    debugging information, and a set of function pointers to call.  */
  2302.  
  2303. bfd_boolean
  2304. debug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
  2305. {
  2306.   struct debug_handle *info = (struct debug_handle *) handle;
  2307.   struct debug_unit *u;
  2308.  
  2309.   /* We use a mark to tell whether we have already written out a
  2310.      particular name.  We use an integer, so that we don't have to
  2311.      clear the mark fields if we happen to write out the same
  2312.      information more than once.  */
  2313.   ++info->mark;
  2314.  
  2315.   /* The base_id field holds an ID value which will never be used, so
  2316.      that we can tell whether we have assigned an ID during this call
  2317.      to debug_write.  */
  2318.   info->base_id = info->class_id;
  2319.  
  2320.   /* We keep a linked list of classes for which was have assigned ID's
  2321.      during this call to debug_write.  */
  2322.   info->id_list = NULL;
  2323.  
  2324.   for (u = info->units; u != NULL; u = u->next)
  2325.     {
  2326.       struct debug_file *f;
  2327.       bfd_boolean first_file;
  2328.  
  2329.       info->current_write_lineno = u->linenos;
  2330.       info->current_write_lineno_index = 0;
  2331.  
  2332.       if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
  2333.         return FALSE;
  2334.  
  2335.       first_file = TRUE;
  2336.       for (f = u->files; f != NULL; f = f->next)
  2337.         {
  2338.           struct debug_name *n;
  2339.  
  2340.           if (first_file)
  2341.             first_file = FALSE;
  2342.           else if (! (*fns->start_source) (fhandle, f->filename))
  2343.             return FALSE;
  2344.  
  2345.           if (f->globals != NULL)
  2346.             for (n = f->globals->list; n != NULL; n = n->next)
  2347.               if (! debug_write_name (info, fns, fhandle, n))
  2348.                 return FALSE;
  2349.         }
  2350.  
  2351.       /* Output any line number information which hasn't already been
  2352.          handled.  */
  2353.       if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
  2354.         return FALSE;
  2355.     }
  2356.  
  2357.   return TRUE;
  2358. }
  2359.  
  2360. /* Write out an element in a namespace.  */
  2361.  
  2362. static bfd_boolean
  2363. debug_write_name (struct debug_handle *info,
  2364.                   const struct debug_write_fns *fns, void *fhandle,
  2365.                   struct debug_name *n)
  2366. {
  2367.   switch (n->kind)
  2368.     {
  2369.     case DEBUG_OBJECT_TYPE:
  2370.       if (! debug_write_type (info, fns, fhandle, n->u.type, n)
  2371.           || ! (*fns->typdef) (fhandle, n->name))
  2372.         return FALSE;
  2373.       return TRUE;
  2374.     case DEBUG_OBJECT_TAG:
  2375.       if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
  2376.         return FALSE;
  2377.       return (*fns->tag) (fhandle, n->name);
  2378.     case DEBUG_OBJECT_VARIABLE:
  2379.       if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
  2380.                               (struct debug_name *) NULL))
  2381.         return FALSE;
  2382.       return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
  2383.                                n->u.variable->val);
  2384.     case DEBUG_OBJECT_FUNCTION:
  2385.       return debug_write_function (info, fns, fhandle, n->name,
  2386.                                    n->linkage, n->u.function);
  2387.     case DEBUG_OBJECT_INT_CONSTANT:
  2388.       return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
  2389.     case DEBUG_OBJECT_FLOAT_CONSTANT:
  2390.       return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
  2391.     case DEBUG_OBJECT_TYPED_CONSTANT:
  2392.       if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
  2393.                               (struct debug_name *) NULL))
  2394.         return FALSE;
  2395.       return (*fns->typed_constant) (fhandle, n->name,
  2396.                                      n->u.typed_constant->val);
  2397.     default:
  2398.       abort ();
  2399.       return FALSE;
  2400.     }
  2401.   /*NOTREACHED*/
  2402. }
  2403.  
  2404. /* Write out a type.  If the type is DEBUG_KIND_NAMED or
  2405.    DEBUG_KIND_TAGGED, then the name argument is the name for which we
  2406.    are about to call typedef or tag.  If the type is anything else,
  2407.    then the name argument is a tag from a DEBUG_KIND_TAGGED type which
  2408.    points to this one.  */
  2409.  
  2410. static bfd_boolean
  2411. debug_write_type (struct debug_handle *info,
  2412.                   const struct debug_write_fns *fns, void *fhandle,
  2413.                   struct debug_type_s *type, struct debug_name *name)
  2414. {
  2415.   unsigned int i;
  2416.   int is;
  2417.   const char *tag = NULL;
  2418.  
  2419.   /* If we have a name for this type, just output it.  We only output
  2420.      typedef names after they have been defined.  We output type tags
  2421.      whenever we are not actually defining them.  */
  2422.   if ((type->kind == DEBUG_KIND_NAMED
  2423.        || type->kind == DEBUG_KIND_TAGGED)
  2424.       && (type->u.knamed->name->mark == info->mark
  2425.           || (type->kind == DEBUG_KIND_TAGGED
  2426.               && type->u.knamed->name != name)))
  2427.     {
  2428.       if (type->kind == DEBUG_KIND_NAMED)
  2429.         return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
  2430.       else
  2431.         {
  2432.           struct debug_type_s *real;
  2433.           unsigned int id;
  2434.  
  2435.           real = debug_get_real_type ((void *) info, type, NULL);
  2436.           if (real == NULL)
  2437.             return (*fns->empty_type) (fhandle);
  2438.           id = 0;
  2439.           if ((real->kind == DEBUG_KIND_STRUCT
  2440.                || real->kind == DEBUG_KIND_UNION
  2441.                || real->kind == DEBUG_KIND_CLASS
  2442.                || real->kind == DEBUG_KIND_UNION_CLASS)
  2443.               && real->u.kclass != NULL)
  2444.             {
  2445.               if (real->u.kclass->id <= info->base_id)
  2446.                 {
  2447.                   if (! debug_set_class_id (info,
  2448.                                             type->u.knamed->name->name,
  2449.                                             real))
  2450.                     return FALSE;
  2451.                 }
  2452.               id = real->u.kclass->id;
  2453.             }
  2454.  
  2455.           return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
  2456.                                    real->kind);
  2457.         }
  2458.     }
  2459.  
  2460.   /* Mark the name after we have already looked for a known name, so
  2461.      that we don't just define a type in terms of itself.  We need to
  2462.      mark the name here so that a struct containing a pointer to
  2463.      itself will work.  */
  2464.   if (name != NULL)
  2465.     name->mark = info->mark;
  2466.  
  2467.   if (name != NULL
  2468.       && type->kind != DEBUG_KIND_NAMED
  2469.       && type->kind != DEBUG_KIND_TAGGED)
  2470.     {
  2471.       assert (name->kind == DEBUG_OBJECT_TAG);
  2472.       tag = name->name;
  2473.     }
  2474.  
  2475.   switch (type->kind)
  2476.     {
  2477.     case DEBUG_KIND_ILLEGAL:
  2478.       debug_error (_("debug_write_type: illegal type encountered"));
  2479.       return FALSE;
  2480.     case DEBUG_KIND_INDIRECT:
  2481.       if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
  2482.         return (*fns->empty_type) (fhandle);
  2483.       return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
  2484.                                name);
  2485.     case DEBUG_KIND_VOID:
  2486.       return (*fns->void_type) (fhandle);
  2487.     case DEBUG_KIND_INT:
  2488.       return (*fns->int_type) (fhandle, type->size, type->u.kint);
  2489.     case DEBUG_KIND_FLOAT:
  2490.       return (*fns->float_type) (fhandle, type->size);
  2491.     case DEBUG_KIND_COMPLEX:
  2492.       return (*fns->complex_type) (fhandle, type->size);
  2493.     case DEBUG_KIND_BOOL:
  2494.       return (*fns->bool_type) (fhandle, type->size);
  2495.     case DEBUG_KIND_STRUCT:
  2496.     case DEBUG_KIND_UNION:
  2497.       if (type->u.kclass != NULL)
  2498.         {
  2499.           if (type->u.kclass->id <= info->base_id)
  2500.             {
  2501.               if (! debug_set_class_id (info, tag, type))
  2502.                 return FALSE;
  2503.             }
  2504.  
  2505.           if (info->mark == type->u.kclass->mark)
  2506.             {
  2507.               /* We are currently outputting this struct, or we have
  2508.                  already output it.  I don't know if this can happen,
  2509.                  but it can happen for a class.  */
  2510.               assert (type->u.kclass->id > info->base_id);
  2511.               return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
  2512.                                        type->kind);
  2513.             }
  2514.           type->u.kclass->mark = info->mark;
  2515.         }
  2516.  
  2517.       if (! (*fns->start_struct_type) (fhandle, tag,
  2518.                                        (type->u.kclass != NULL
  2519.                                         ? type->u.kclass->id
  2520.                                         : 0),
  2521.                                        type->kind == DEBUG_KIND_STRUCT,
  2522.                                        type->size))
  2523.         return FALSE;
  2524.       if (type->u.kclass != NULL
  2525.           && type->u.kclass->fields != NULL)
  2526.         {
  2527.           for (i = 0; type->u.kclass->fields[i] != NULL; i++)
  2528.             {
  2529.               struct debug_field_s *f;
  2530.  
  2531.               f = type->u.kclass->fields[i];
  2532.               if (! debug_write_type (info, fns, fhandle, f->type,
  2533.                                       (struct debug_name *) NULL)
  2534.                   || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
  2535.                                              f->u.f.bitsize, f->visibility))
  2536.                 return FALSE;
  2537.             }
  2538.         }
  2539.       return (*fns->end_struct_type) (fhandle);
  2540.     case DEBUG_KIND_CLASS:
  2541.     case DEBUG_KIND_UNION_CLASS:
  2542.       return debug_write_class_type (info, fns, fhandle, type, tag);
  2543.     case DEBUG_KIND_ENUM:
  2544.       if (type->u.kenum == NULL)
  2545.         return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
  2546.                                   (bfd_signed_vma *) NULL);
  2547.       return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
  2548.                                 type->u.kenum->values);
  2549.     case DEBUG_KIND_POINTER:
  2550.       if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
  2551.                               (struct debug_name *) NULL))
  2552.         return FALSE;
  2553.       return (*fns->pointer_type) (fhandle);
  2554.     case DEBUG_KIND_FUNCTION:
  2555.       if (! debug_write_type (info, fns, fhandle,
  2556.                               type->u.kfunction->return_type,
  2557.                               (struct debug_name *) NULL))
  2558.         return FALSE;
  2559.       if (type->u.kfunction->arg_types == NULL)
  2560.         is = -1;
  2561.       else
  2562.         {
  2563.           for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
  2564.             if (! debug_write_type (info, fns, fhandle,
  2565.                                     type->u.kfunction->arg_types[is],
  2566.                                     (struct debug_name *) NULL))
  2567.               return FALSE;
  2568.         }
  2569.       return (*fns->function_type) (fhandle, is,
  2570.                                     type->u.kfunction->varargs);
  2571.     case DEBUG_KIND_REFERENCE:
  2572.       if (! debug_write_type (info, fns, fhandle, type->u.kreference,
  2573.                               (struct debug_name *) NULL))
  2574.         return FALSE;
  2575.       return (*fns->reference_type) (fhandle);
  2576.     case DEBUG_KIND_RANGE:
  2577.       if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
  2578.                               (struct debug_name *) NULL))
  2579.         return FALSE;
  2580.       return (*fns->range_type) (fhandle, type->u.krange->lower,
  2581.                                  type->u.krange->upper);
  2582.     case DEBUG_KIND_ARRAY:
  2583.       if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
  2584.                               (struct debug_name *) NULL)
  2585.           || ! debug_write_type (info, fns, fhandle,
  2586.                                  type->u.karray->range_type,
  2587.                                  (struct debug_name *) NULL))
  2588.         return FALSE;
  2589.       return (*fns->array_type) (fhandle, type->u.karray->lower,
  2590.                                  type->u.karray->upper,
  2591.                                  type->u.karray->stringp);
  2592.     case DEBUG_KIND_SET:
  2593.       if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
  2594.                               (struct debug_name *) NULL))
  2595.         return FALSE;
  2596.       return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
  2597.     case DEBUG_KIND_OFFSET:
  2598.       if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
  2599.                               (struct debug_name *) NULL)
  2600.           || ! debug_write_type (info, fns, fhandle,
  2601.                                  type->u.koffset->target_type,
  2602.                                  (struct debug_name *) NULL))
  2603.         return FALSE;
  2604.       return (*fns->offset_type) (fhandle);
  2605.     case DEBUG_KIND_METHOD:
  2606.       if (! debug_write_type (info, fns, fhandle,
  2607.                               type->u.kmethod->return_type,
  2608.                               (struct debug_name *) NULL))
  2609.         return FALSE;
  2610.       if (type->u.kmethod->arg_types == NULL)
  2611.         is = -1;
  2612.       else
  2613.         {
  2614.           for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
  2615.             if (! debug_write_type (info, fns, fhandle,
  2616.                                     type->u.kmethod->arg_types[is],
  2617.                                     (struct debug_name *) NULL))
  2618.               return FALSE;
  2619.         }
  2620.       if (type->u.kmethod->domain_type != NULL)
  2621.         {
  2622.           if (! debug_write_type (info, fns, fhandle,
  2623.                                   type->u.kmethod->domain_type,
  2624.                                   (struct debug_name *) NULL))
  2625.             return FALSE;
  2626.         }
  2627.       return (*fns->method_type) (fhandle,
  2628.                                   type->u.kmethod->domain_type != NULL,
  2629.                                   is,
  2630.                                   type->u.kmethod->varargs);
  2631.     case DEBUG_KIND_CONST:
  2632.       if (! debug_write_type (info, fns, fhandle, type->u.kconst,
  2633.                               (struct debug_name *) NULL))
  2634.         return FALSE;
  2635.       return (*fns->const_type) (fhandle);
  2636.     case DEBUG_KIND_VOLATILE:
  2637.       if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
  2638.                               (struct debug_name *) NULL))
  2639.         return FALSE;
  2640.       return (*fns->volatile_type) (fhandle);
  2641.     case DEBUG_KIND_NAMED:
  2642.       return debug_write_type (info, fns, fhandle, type->u.knamed->type,
  2643.                                (struct debug_name *) NULL);
  2644.     case DEBUG_KIND_TAGGED:
  2645.       return debug_write_type (info, fns, fhandle, type->u.knamed->type,
  2646.                                type->u.knamed->name);
  2647.     default:
  2648.       abort ();
  2649.       return FALSE;
  2650.     }
  2651. }
  2652.  
  2653. /* Write out a class type.  */
  2654.  
  2655. static bfd_boolean
  2656. debug_write_class_type (struct debug_handle *info,
  2657.                         const struct debug_write_fns *fns, void *fhandle,
  2658.                         struct debug_type_s *type, const char *tag)
  2659. {
  2660.   unsigned int i;
  2661.   unsigned int id;
  2662.   struct debug_type_s *vptrbase;
  2663.  
  2664.   if (type->u.kclass == NULL)
  2665.     {
  2666.       id = 0;
  2667.       vptrbase = NULL;
  2668.     }
  2669.   else
  2670.     {
  2671.       if (type->u.kclass->id <= info->base_id)
  2672.         {
  2673.           if (! debug_set_class_id (info, tag, type))
  2674.             return FALSE;
  2675.         }
  2676.  
  2677.       if (info->mark == type->u.kclass->mark)
  2678.         {
  2679.           /* We are currently outputting this class, or we have
  2680.              already output it.  This can happen when there are
  2681.              methods for an anonymous class.  */
  2682.           assert (type->u.kclass->id > info->base_id);
  2683.           return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
  2684.                                    type->kind);
  2685.         }
  2686.       type->u.kclass->mark = info->mark;
  2687.       id = type->u.kclass->id;
  2688.  
  2689.       vptrbase = type->u.kclass->vptrbase;
  2690.       if (vptrbase != NULL && vptrbase != type)
  2691.         {
  2692.           if (! debug_write_type (info, fns, fhandle, vptrbase,
  2693.                                   (struct debug_name *) NULL))
  2694.             return FALSE;
  2695.         }
  2696.     }
  2697.  
  2698.   if (! (*fns->start_class_type) (fhandle, tag, id,
  2699.                                   type->kind == DEBUG_KIND_CLASS,
  2700.                                   type->size,
  2701.                                   vptrbase != NULL,
  2702.                                   vptrbase == type))
  2703.     return FALSE;
  2704.  
  2705.   if (type->u.kclass != NULL)
  2706.     {
  2707.       if (type->u.kclass->fields != NULL)
  2708.         {
  2709.           for (i = 0; type->u.kclass->fields[i] != NULL; i++)
  2710.             {
  2711.               struct debug_field_s *f;
  2712.  
  2713.               f = type->u.kclass->fields[i];
  2714.               if (! debug_write_type (info, fns, fhandle, f->type,
  2715.                                       (struct debug_name *) NULL))
  2716.                 return FALSE;
  2717.               if (f->static_member)
  2718.                 {
  2719.                   if (! (*fns->class_static_member) (fhandle, f->name,
  2720.                                                      f->u.s.physname,
  2721.                                                      f->visibility))
  2722.                     return FALSE;
  2723.                 }
  2724.               else
  2725.                 {
  2726.                   if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
  2727.                                               f->u.f.bitsize, f->visibility))
  2728.                     return FALSE;
  2729.                 }
  2730.             }
  2731.         }
  2732.  
  2733.       if (type->u.kclass->baseclasses != NULL)
  2734.         {
  2735.           for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
  2736.             {
  2737.               struct debug_baseclass_s *b;
  2738.  
  2739.               b = type->u.kclass->baseclasses[i];
  2740.               if (! debug_write_type (info, fns, fhandle, b->type,
  2741.                                       (struct debug_name *) NULL))
  2742.                 return FALSE;
  2743.               if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->is_virtual,
  2744.                                              b->visibility))
  2745.                 return FALSE;
  2746.             }
  2747.         }
  2748.  
  2749.       if (type->u.kclass->methods != NULL)
  2750.         {
  2751.           for (i = 0; type->u.kclass->methods[i] != NULL; i++)
  2752.             {
  2753.               struct debug_method_s *m;
  2754.               unsigned int j;
  2755.  
  2756.               m = type->u.kclass->methods[i];
  2757.               if (! (*fns->class_start_method) (fhandle, m->name))
  2758.                 return FALSE;
  2759.               for (j = 0; m->variants[j] != NULL; j++)
  2760.                 {
  2761.                   struct debug_method_variant_s *v;
  2762.  
  2763.                   v = m->variants[j];
  2764.                   if (v->context != NULL)
  2765.                     {
  2766.                       if (! debug_write_type (info, fns, fhandle, v->context,
  2767.                                               (struct debug_name *) NULL))
  2768.                         return FALSE;
  2769.                     }
  2770.                   if (! debug_write_type (info, fns, fhandle, v->type,
  2771.                                           (struct debug_name *) NULL))
  2772.                     return FALSE;
  2773.                   if (v->voffset != VOFFSET_STATIC_METHOD)
  2774.                     {
  2775.                       if (! (*fns->class_method_variant) (fhandle, v->physname,
  2776.                                                           v->visibility,
  2777.                                                           v->constp,
  2778.                                                           v->volatilep,
  2779.                                                           v->voffset,
  2780.                                                           v->context != NULL))
  2781.                         return FALSE;
  2782.                     }
  2783.                   else
  2784.                     {
  2785.                       if (! (*fns->class_static_method_variant) (fhandle,
  2786.                                                                  v->physname,
  2787.                                                                  v->visibility,
  2788.                                                                  v->constp,
  2789.                                                                  v->volatilep))
  2790.                         return FALSE;
  2791.                     }
  2792.                 }
  2793.               if (! (*fns->class_end_method) (fhandle))
  2794.                 return FALSE;
  2795.             }
  2796.         }
  2797.     }
  2798.  
  2799.   return (*fns->end_class_type) (fhandle);
  2800. }
  2801.  
  2802. /* Write out information for a function.  */
  2803.  
  2804. static bfd_boolean
  2805. debug_write_function (struct debug_handle *info,
  2806.                       const struct debug_write_fns *fns, void *fhandle,
  2807.                       const char *name, enum debug_object_linkage linkage,
  2808.                       struct debug_function *function)
  2809. {
  2810.   struct debug_parameter *p;
  2811.   struct debug_block *b;
  2812.  
  2813.   if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
  2814.     return FALSE;
  2815.  
  2816.   if (! debug_write_type (info, fns, fhandle, function->return_type,
  2817.                           (struct debug_name *) NULL))
  2818.     return FALSE;
  2819.  
  2820.   if (! (*fns->start_function) (fhandle, name,
  2821.                                 linkage == DEBUG_LINKAGE_GLOBAL))
  2822.     return FALSE;
  2823.  
  2824.   for (p = function->parameters; p != NULL; p = p->next)
  2825.     {
  2826.       if (! debug_write_type (info, fns, fhandle, p->type,
  2827.                               (struct debug_name *) NULL)
  2828.           || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
  2829.         return FALSE;
  2830.     }
  2831.  
  2832.   for (b = function->blocks; b != NULL; b = b->next)
  2833.     {
  2834.       if (! debug_write_block (info, fns, fhandle, b))
  2835.         return FALSE;
  2836.     }
  2837.  
  2838.   return (*fns->end_function) (fhandle);
  2839. }
  2840.  
  2841. /* Write out information for a block.  */
  2842.  
  2843. static bfd_boolean
  2844. debug_write_block (struct debug_handle *info,
  2845.                    const struct debug_write_fns *fns, void *fhandle,
  2846.                    struct debug_block *block)
  2847. {
  2848.   struct debug_name *n;
  2849.   struct debug_block *b;
  2850.  
  2851.   if (! debug_write_linenos (info, fns, fhandle, block->start))
  2852.     return FALSE;
  2853.  
  2854.   /* I can't see any point to writing out a block with no local
  2855.      variables, so we don't bother, except for the top level block.  */
  2856.   if (block->locals != NULL || block->parent == NULL)
  2857.     {
  2858.       if (! (*fns->start_block) (fhandle, block->start))
  2859.         return FALSE;
  2860.     }
  2861.  
  2862.   if (block->locals != NULL)
  2863.     {
  2864.       for (n = block->locals->list; n != NULL; n = n->next)
  2865.         {
  2866.           if (! debug_write_name (info, fns, fhandle, n))
  2867.             return FALSE;
  2868.         }
  2869.     }
  2870.  
  2871.   for (b = block->children; b != NULL; b = b->next)
  2872.     {
  2873.       if (! debug_write_block (info, fns, fhandle, b))
  2874.         return FALSE;
  2875.     }
  2876.  
  2877.   if (! debug_write_linenos (info, fns, fhandle, block->end))
  2878.     return FALSE;
  2879.  
  2880.   if (block->locals != NULL || block->parent == NULL)
  2881.     {
  2882.       if (! (*fns->end_block) (fhandle, block->end))
  2883.         return FALSE;
  2884.     }
  2885.  
  2886.   return TRUE;
  2887. }
  2888.  
  2889. /* Write out line number information up to ADDRESS.  */
  2890.  
  2891. static bfd_boolean
  2892. debug_write_linenos (struct debug_handle *info,
  2893.                      const struct debug_write_fns *fns, void *fhandle,
  2894.                      bfd_vma address)
  2895. {
  2896.   while (info->current_write_lineno != NULL)
  2897.     {
  2898.       struct debug_lineno *l;
  2899.  
  2900.       l = info->current_write_lineno;
  2901.  
  2902.       while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
  2903.         {
  2904.           if (l->linenos[info->current_write_lineno_index]
  2905.               == (unsigned long) -1)
  2906.             break;
  2907.  
  2908.           if (l->addrs[info->current_write_lineno_index] >= address)
  2909.             return TRUE;
  2910.  
  2911.           if (! (*fns->lineno) (fhandle, l->file->filename,
  2912.                                 l->linenos[info->current_write_lineno_index],
  2913.                                 l->addrs[info->current_write_lineno_index]))
  2914.             return FALSE;
  2915.  
  2916.           ++info->current_write_lineno_index;
  2917.         }
  2918.  
  2919.       info->current_write_lineno = l->next;
  2920.       info->current_write_lineno_index = 0;
  2921.     }
  2922.  
  2923.   return TRUE;
  2924. }
  2925.  
  2926. /* Get the ID number for a class.  If during the same call to
  2927.    debug_write we find a struct with the same definition with the same
  2928.    name, we use the same ID.  This type of things happens because the
  2929.    same struct will be defined by multiple compilation units.  */
  2930.  
  2931. static bfd_boolean
  2932. debug_set_class_id (struct debug_handle *info, const char *tag,
  2933.                     struct debug_type_s *type)
  2934. {
  2935.   struct debug_class_type *c;
  2936.   struct debug_class_id *l;
  2937.  
  2938.   assert (type->kind == DEBUG_KIND_STRUCT
  2939.           || type->kind == DEBUG_KIND_UNION
  2940.           || type->kind == DEBUG_KIND_CLASS
  2941.           || type->kind == DEBUG_KIND_UNION_CLASS);
  2942.  
  2943.   c = type->u.kclass;
  2944.  
  2945.   if (c->id > info->base_id)
  2946.     return TRUE;
  2947.  
  2948.   for (l = info->id_list; l != NULL; l = l->next)
  2949.     {
  2950.       if (l->type->kind != type->kind)
  2951.         continue;
  2952.  
  2953.       if (tag == NULL)
  2954.         {
  2955.           if (l->tag != NULL)
  2956.             continue;
  2957.         }
  2958.       else
  2959.         {
  2960.           if (l->tag == NULL
  2961.               || l->tag[0] != tag[0]
  2962.               || strcmp (l->tag, tag) != 0)
  2963.             continue;
  2964.         }
  2965.  
  2966.       if (debug_type_samep (info, l->type, type))
  2967.         {
  2968.           c->id = l->type->u.kclass->id;
  2969.           return TRUE;
  2970.         }
  2971.     }
  2972.  
  2973.   /* There are no identical types.  Use a new ID, and add it to the
  2974.      list.  */
  2975.   ++info->class_id;
  2976.   c->id = info->class_id;
  2977.  
  2978.   l = (struct debug_class_id *) xmalloc (sizeof *l);
  2979.   memset (l, 0, sizeof *l);
  2980.  
  2981.   l->type = type;
  2982.   l->tag = tag;
  2983.  
  2984.   l->next = info->id_list;
  2985.   info->id_list = l;
  2986.  
  2987.   return TRUE;
  2988. }
  2989.  
  2990. /* See if two types are the same.  At this point, we don't care about
  2991.    tags and the like.  */
  2992.  
  2993. static bfd_boolean
  2994. debug_type_samep (struct debug_handle *info, struct debug_type_s *t1,
  2995.                   struct debug_type_s *t2)
  2996. {
  2997.   struct debug_type_compare_list *l;
  2998.   struct debug_type_compare_list top;
  2999.   bfd_boolean ret;
  3000.  
  3001.   if (t1 == NULL)
  3002.     return t2 == NULL;
  3003.   if (t2 == NULL)
  3004.     return FALSE;
  3005.  
  3006.   while (t1->kind == DEBUG_KIND_INDIRECT)
  3007.     {
  3008.       t1 = *t1->u.kindirect->slot;
  3009.       if (t1 == NULL)
  3010.         return FALSE;
  3011.     }
  3012.   while (t2->kind == DEBUG_KIND_INDIRECT)
  3013.     {
  3014.       t2 = *t2->u.kindirect->slot;
  3015.       if (t2 == NULL)
  3016.         return FALSE;
  3017.     }
  3018.  
  3019.   if (t1 == t2)
  3020.     return TRUE;
  3021.  
  3022.   /* As a special case, permit a typedef to match a tag, since C++
  3023.      debugging output will sometimes add a typedef where C debugging
  3024.      output will not.  */
  3025.   if (t1->kind == DEBUG_KIND_NAMED
  3026.       && t2->kind == DEBUG_KIND_TAGGED)
  3027.     return debug_type_samep (info, t1->u.knamed->type, t2);
  3028.   else if (t1->kind == DEBUG_KIND_TAGGED
  3029.            && t2->kind == DEBUG_KIND_NAMED)
  3030.     return debug_type_samep (info, t1, t2->u.knamed->type);
  3031.  
  3032.   if (t1->kind != t2->kind
  3033.       || t1->size != t2->size)
  3034.     return FALSE;
  3035.  
  3036.   /* Get rid of the trivial cases first.  */
  3037.   switch (t1->kind)
  3038.     {
  3039.     default:
  3040.       break;
  3041.     case DEBUG_KIND_VOID:
  3042.     case DEBUG_KIND_FLOAT:
  3043.     case DEBUG_KIND_COMPLEX:
  3044.     case DEBUG_KIND_BOOL:
  3045.       return TRUE;
  3046.     case DEBUG_KIND_INT:
  3047.       return t1->u.kint == t2->u.kint;
  3048.     }
  3049.  
  3050.   /* We have to avoid an infinite recursion.  We do this by keeping a
  3051.      list of types which we are comparing.  We just keep the list on
  3052.      the stack.  If we encounter a pair of types we are currently
  3053.      comparing, we just assume that they are equal.  */
  3054.   for (l = info->compare_list; l != NULL; l = l->next)
  3055.     {
  3056.       if (l->t1 == t1 && l->t2 == t2)
  3057.         return TRUE;
  3058.     }
  3059.  
  3060.   top.t1 = t1;
  3061.   top.t2 = t2;
  3062.   top.next = info->compare_list;
  3063.   info->compare_list = &top;
  3064.  
  3065.   switch (t1->kind)
  3066.     {
  3067.     default:
  3068.       abort ();
  3069.       ret = FALSE;
  3070.       break;
  3071.  
  3072.     case DEBUG_KIND_STRUCT:
  3073.     case DEBUG_KIND_UNION:
  3074.     case DEBUG_KIND_CLASS:
  3075.     case DEBUG_KIND_UNION_CLASS:
  3076.       if (t1->u.kclass == NULL)
  3077.         ret = t2->u.kclass == NULL;
  3078.       else if (t2->u.kclass == NULL)
  3079.         ret = FALSE;
  3080.       else if (t1->u.kclass->id > info->base_id
  3081.                && t1->u.kclass->id == t2->u.kclass->id)
  3082.         ret = TRUE;
  3083.       else
  3084.         ret = debug_class_type_samep (info, t1, t2);
  3085.       break;
  3086.  
  3087.     case DEBUG_KIND_ENUM:
  3088.       if (t1->u.kenum == NULL)
  3089.         ret = t2->u.kenum == NULL;
  3090.       else if (t2->u.kenum == NULL)
  3091.         ret = FALSE;
  3092.       else
  3093.         {
  3094.           const char **pn1, **pn2;
  3095.           bfd_signed_vma *pv1, *pv2;
  3096.  
  3097.           pn1 = t1->u.kenum->names;
  3098.           pn2 = t2->u.kenum->names;
  3099.           pv1 = t1->u.kenum->values;
  3100.           pv2 = t2->u.kenum->values;
  3101.           while (*pn1 != NULL && *pn2 != NULL)
  3102.             {
  3103.               if (**pn1 != **pn2
  3104.                   || *pv1 != *pv2
  3105.                   || strcmp (*pn1, *pn2) != 0)
  3106.                 break;
  3107.               ++pn1;
  3108.               ++pn2;
  3109.               ++pv1;
  3110.               ++pv2;
  3111.             }
  3112.           ret = *pn1 == NULL && *pn2 == NULL;
  3113.         }
  3114.       break;
  3115.  
  3116.     case DEBUG_KIND_POINTER:
  3117.       ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
  3118.       break;
  3119.  
  3120.     case DEBUG_KIND_FUNCTION:
  3121.       if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
  3122.           || ! debug_type_samep (info, t1->u.kfunction->return_type,
  3123.                                  t2->u.kfunction->return_type)
  3124.           || ((t1->u.kfunction->arg_types == NULL)
  3125.               != (t2->u.kfunction->arg_types == NULL)))
  3126.         ret = FALSE;
  3127.       else if (t1->u.kfunction->arg_types == NULL)
  3128.         ret = TRUE;
  3129.       else
  3130.         {
  3131.           struct debug_type_s **a1, **a2;
  3132.  
  3133.           a1 = t1->u.kfunction->arg_types;
  3134.           a2 = t2->u.kfunction->arg_types;
  3135.           while (*a1 != NULL && *a2 != NULL)
  3136.             {
  3137.               if (! debug_type_samep (info, *a1, *a2))
  3138.                 break;
  3139.               ++a1;
  3140.               ++a2;
  3141.             }
  3142.           ret = *a1 == NULL && *a2 == NULL;
  3143.         }
  3144.       break;
  3145.  
  3146.     case DEBUG_KIND_REFERENCE:
  3147.       ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
  3148.       break;
  3149.  
  3150.     case DEBUG_KIND_RANGE:
  3151.       ret = (t1->u.krange->lower == t2->u.krange->lower
  3152.              && t1->u.krange->upper == t2->u.krange->upper
  3153.              && debug_type_samep (info, t1->u.krange->type,
  3154.                                   t2->u.krange->type));
  3155.       break;
  3156.  
  3157.     case DEBUG_KIND_ARRAY:
  3158.       ret = (t1->u.karray->lower == t2->u.karray->lower
  3159.              && t1->u.karray->upper == t2->u.karray->upper
  3160.              && t1->u.karray->stringp == t2->u.karray->stringp
  3161.              && debug_type_samep (info, t1->u.karray->element_type,
  3162.                                   t2->u.karray->element_type));
  3163.       break;
  3164.  
  3165.     case DEBUG_KIND_SET:
  3166.       ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
  3167.              && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
  3168.       break;
  3169.  
  3170.     case DEBUG_KIND_OFFSET:
  3171.       ret = (debug_type_samep (info, t1->u.koffset->base_type,
  3172.                                t2->u.koffset->base_type)
  3173.              && debug_type_samep (info, t1->u.koffset->target_type,
  3174.                                   t2->u.koffset->target_type));
  3175.       break;
  3176.  
  3177.     case DEBUG_KIND_METHOD:
  3178.       if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
  3179.           || ! debug_type_samep (info, t1->u.kmethod->return_type,
  3180.                                  t2->u.kmethod->return_type)
  3181.           || ! debug_type_samep (info, t1->u.kmethod->domain_type,
  3182.                                  t2->u.kmethod->domain_type)
  3183.           || ((t1->u.kmethod->arg_types == NULL)
  3184.               != (t2->u.kmethod->arg_types == NULL)))
  3185.         ret = FALSE;
  3186.       else if (t1->u.kmethod->arg_types == NULL)
  3187.         ret = TRUE;
  3188.       else
  3189.         {
  3190.           struct debug_type_s **a1, **a2;
  3191.  
  3192.           a1 = t1->u.kmethod->arg_types;
  3193.           a2 = t2->u.kmethod->arg_types;
  3194.           while (*a1 != NULL && *a2 != NULL)
  3195.             {
  3196.               if (! debug_type_samep (info, *a1, *a2))
  3197.                 break;
  3198.               ++a1;
  3199.               ++a2;
  3200.             }
  3201.           ret = *a1 == NULL && *a2 == NULL;
  3202.         }
  3203.       break;
  3204.  
  3205.     case DEBUG_KIND_CONST:
  3206.       ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
  3207.       break;
  3208.  
  3209.     case DEBUG_KIND_VOLATILE:
  3210.       ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
  3211.       break;
  3212.  
  3213.     case DEBUG_KIND_NAMED:
  3214.     case DEBUG_KIND_TAGGED:
  3215.       ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
  3216.              && debug_type_samep (info, t1->u.knamed->type,
  3217.                                   t2->u.knamed->type));
  3218.       break;
  3219.     }
  3220.  
  3221.   info->compare_list = top.next;
  3222.  
  3223.   return ret;
  3224. }
  3225.  
  3226. /* See if two classes are the same.  This is a subroutine of
  3227.    debug_type_samep.  */
  3228.  
  3229. static bfd_boolean
  3230. debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
  3231.                         struct debug_type_s *t2)
  3232. {
  3233.   struct debug_class_type *c1, *c2;
  3234.  
  3235.   c1 = t1->u.kclass;
  3236.   c2 = t2->u.kclass;
  3237.  
  3238.   if ((c1->fields == NULL) != (c2->fields == NULL)
  3239.       || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
  3240.       || (c1->methods == NULL) != (c2->methods == NULL)
  3241.       || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
  3242.     return FALSE;
  3243.  
  3244.   if (c1->fields != NULL)
  3245.     {
  3246.       struct debug_field_s **pf1, **pf2;
  3247.  
  3248.       for (pf1 = c1->fields, pf2 = c2->fields;
  3249.            *pf1 != NULL && *pf2 != NULL;
  3250.            pf1++, pf2++)
  3251.         {
  3252.           struct debug_field_s *f1, *f2;
  3253.  
  3254.           f1 = *pf1;
  3255.           f2 = *pf2;
  3256.           if (f1->name[0] != f2->name[0]
  3257.               || f1->visibility != f2->visibility
  3258.               || f1->static_member != f2->static_member)
  3259.             return FALSE;
  3260.           if (f1->static_member)
  3261.             {
  3262.               if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
  3263.                 return FALSE;
  3264.             }
  3265.           else
  3266.             {
  3267.               if (f1->u.f.bitpos != f2->u.f.bitpos
  3268.                   || f1->u.f.bitsize != f2->u.f.bitsize)
  3269.                 return FALSE;
  3270.             }
  3271.           /* We do the checks which require function calls last.  We
  3272.              don't require that the types of fields have the same
  3273.              names, since that sometimes fails in the presence of
  3274.              typedefs and we really don't care.  */
  3275.           if (strcmp (f1->name, f2->name) != 0
  3276.               || ! debug_type_samep (info,
  3277.                                      debug_get_real_type ((void *) info,
  3278.                                                           f1->type, NULL),
  3279.                                      debug_get_real_type ((void *) info,
  3280.                                                           f2->type, NULL)))
  3281.             return FALSE;
  3282.         }
  3283.       if (*pf1 != NULL || *pf2 != NULL)
  3284.         return FALSE;
  3285.     }
  3286.  
  3287.   if (c1->vptrbase != NULL)
  3288.     {
  3289.       if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
  3290.         return FALSE;
  3291.     }
  3292.  
  3293.   if (c1->baseclasses != NULL)
  3294.     {
  3295.       struct debug_baseclass_s **pb1, **pb2;
  3296.  
  3297.       for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
  3298.            *pb1 != NULL && *pb2 != NULL;
  3299.            ++pb1, ++pb2)
  3300.         {
  3301.           struct debug_baseclass_s *b1, *b2;
  3302.  
  3303.           b1 = *pb1;
  3304.           b2 = *pb2;
  3305.           if (b1->bitpos != b2->bitpos
  3306.               || b1->is_virtual != b2->is_virtual
  3307.               || b1->visibility != b2->visibility
  3308.               || ! debug_type_samep (info, b1->type, b2->type))
  3309.             return FALSE;
  3310.         }
  3311.       if (*pb1 != NULL || *pb2 != NULL)
  3312.         return FALSE;
  3313.     }
  3314.  
  3315.   if (c1->methods != NULL)
  3316.     {
  3317.       struct debug_method_s **pm1, **pm2;
  3318.  
  3319.       for (pm1 = c1->methods, pm2 = c2->methods;
  3320.            *pm1 != NULL && *pm2 != NULL;
  3321.            ++pm1, ++pm2)
  3322.         {
  3323.           struct debug_method_s *m1, *m2;
  3324.  
  3325.           m1 = *pm1;
  3326.           m2 = *pm2;
  3327.           if (m1->name[0] != m2->name[0]
  3328.               || strcmp (m1->name, m2->name) != 0
  3329.               || (m1->variants == NULL) != (m2->variants == NULL))
  3330.             return FALSE;
  3331.           if (m1->variants == NULL)
  3332.             {
  3333.               struct debug_method_variant_s **pv1, **pv2;
  3334.  
  3335.               for (pv1 = m1->variants, pv2 = m2->variants;
  3336.                    *pv1 != NULL && *pv2 != NULL;
  3337.                    ++pv1, ++pv2)
  3338.                 {
  3339.                   struct debug_method_variant_s *v1, *v2;
  3340.  
  3341.                   v1 = *pv1;
  3342.                   v2 = *pv2;
  3343.                   if (v1->physname[0] != v2->physname[0]
  3344.                       || v1->visibility != v2->visibility
  3345.                       || v1->constp != v2->constp
  3346.                       || v1->volatilep != v2->volatilep
  3347.                       || v1->voffset != v2->voffset
  3348.                       || (v1->context == NULL) != (v2->context == NULL)
  3349.                       || strcmp (v1->physname, v2->physname) != 0
  3350.                       || ! debug_type_samep (info, v1->type, v2->type))
  3351.                     return FALSE;
  3352.                   if (v1->context != NULL)
  3353.                     {
  3354.                       if (! debug_type_samep (info, v1->context,
  3355.                                               v2->context))
  3356.                         return FALSE;
  3357.                     }
  3358.                 }
  3359.               if (*pv1 != NULL || *pv2 != NULL)
  3360.                 return FALSE;
  3361.             }
  3362.         }
  3363.       if (*pm1 != NULL || *pm2 != NULL)
  3364.         return FALSE;
  3365.     }
  3366.  
  3367.   return TRUE;
  3368. }
  3369.