debug.c revision 33965
133965Sjdp/* debug.c -- Handle generic debugging information.
233965Sjdp   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
333965Sjdp   Written by Ian Lance Taylor <ian@cygnus.com>.
433965Sjdp
533965Sjdp   This file is part of GNU Binutils.
633965Sjdp
733965Sjdp   This program is free software; you can redistribute it and/or modify
833965Sjdp   it under the terms of the GNU General Public License as published by
933965Sjdp   the Free Software Foundation; either version 2 of the License, or
1033965Sjdp   (at your option) any later version.
1133965Sjdp
1233965Sjdp   This program is distributed in the hope that it will be useful,
1333965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1433965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965Sjdp   GNU General Public License for more details.
1633965Sjdp
1733965Sjdp   You should have received a copy of the GNU General Public License
1833965Sjdp   along with this program; if not, write to the Free Software
1933965Sjdp   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2033965Sjdp   02111-1307, USA.  */
2133965Sjdp
2233965Sjdp/* This file implements a generic debugging format.  We may eventually
2333965Sjdp   have readers which convert different formats into this generic
2433965Sjdp   format, and writers which write it out.  The initial impetus for
2533965Sjdp   this was writing a convertor from stabs to HP IEEE-695 debugging
2633965Sjdp   format.  */
2733965Sjdp
2833965Sjdp#include <stdio.h>
2933965Sjdp#include <assert.h>
3033965Sjdp
3133965Sjdp#include "bfd.h"
3233965Sjdp#include "bucomm.h"
3333965Sjdp#include "libiberty.h"
3433965Sjdp#include "debug.h"
3533965Sjdp
3633965Sjdp/* Global information we keep for debugging.  A pointer to this
3733965Sjdp   structure is the debugging handle passed to all the routines.  */
3833965Sjdp
3933965Sjdpstruct debug_handle
4033965Sjdp{
4133965Sjdp  /* A linked list of compilation units.  */
4233965Sjdp  struct debug_unit *units;
4333965Sjdp  /* The current compilation unit.  */
4433965Sjdp  struct debug_unit *current_unit;
4533965Sjdp  /* The current source file.  */
4633965Sjdp  struct debug_file *current_file;
4733965Sjdp  /* The current function.  */
4833965Sjdp  struct debug_function *current_function;
4933965Sjdp  /* The current block.  */
5033965Sjdp  struct debug_block *current_block;
5133965Sjdp  /* The current line number information for the current unit.  */
5233965Sjdp  struct debug_lineno *current_lineno;
5333965Sjdp  /* Mark.  This is used by debug_write.  */
5433965Sjdp  unsigned int mark;
5533965Sjdp  /* A struct/class ID used by debug_write.  */
5633965Sjdp  unsigned int class_id;
5733965Sjdp  /* The base for class_id for this call to debug_write.  */
5833965Sjdp  unsigned int base_id;
5933965Sjdp  /* The current line number in debug_write.  */
6033965Sjdp  struct debug_lineno *current_write_lineno;
6133965Sjdp  unsigned int current_write_lineno_index;
6233965Sjdp  /* A list of classes which have assigned ID's during debug_write.
6333965Sjdp     This is linked through the next_id field of debug_class_type.  */
6433965Sjdp  struct debug_class_id *id_list;
6533965Sjdp  /* A list used to avoid recursion during debug_type_samep.  */
6633965Sjdp  struct debug_type_compare_list *compare_list;
6733965Sjdp};
6833965Sjdp
6933965Sjdp/* Information we keep for a single compilation unit.  */
7033965Sjdp
7133965Sjdpstruct debug_unit
7233965Sjdp{
7333965Sjdp  /* The next compilation unit.  */
7433965Sjdp  struct debug_unit *next;
7533965Sjdp  /* A list of files included in this compilation unit.  The first
7633965Sjdp     file is always the main one, and that is where the main file name
7733965Sjdp     is stored.  */
7833965Sjdp  struct debug_file *files;
7933965Sjdp  /* Line number information for this compilation unit.  This is not
8033965Sjdp     stored by function, because assembler code may have line number
8133965Sjdp     information without function information.  */
8233965Sjdp  struct debug_lineno *linenos;
8333965Sjdp};
8433965Sjdp
8533965Sjdp/* Information kept for a single source file.  */
8633965Sjdp
8733965Sjdpstruct debug_file
8833965Sjdp{
8933965Sjdp  /* The next source file in this compilation unit.  */
9033965Sjdp  struct debug_file *next;
9133965Sjdp  /* The name of the source file.  */
9233965Sjdp  const char *filename;
9333965Sjdp  /* Global functions, variables, types, etc.  */
9433965Sjdp  struct debug_namespace *globals;
9533965Sjdp};
9633965Sjdp
9733965Sjdp/* A type.  */
9833965Sjdp
9933965Sjdpstruct debug_type
10033965Sjdp{
10133965Sjdp  /* Kind of type.  */
10233965Sjdp  enum debug_type_kind kind;
10333965Sjdp  /* Size of type (0 if not known).  */
10433965Sjdp  unsigned int size;
10533965Sjdp  /* Type which is a pointer to this type.  */
10633965Sjdp  debug_type pointer;
10733965Sjdp  /* Tagged union with additional information about the type.  */
10833965Sjdp  union
10933965Sjdp    {
11033965Sjdp      /* DEBUG_KIND_INDIRECT.  */
11133965Sjdp      struct debug_indirect_type *kindirect;
11233965Sjdp      /* DEBUG_KIND_INT.  */
11333965Sjdp      /* Whether the integer is unsigned.  */
11433965Sjdp      boolean kint;
11533965Sjdp      /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
11633965Sjdp         DEBUG_KIND_UNION_CLASS.  */
11733965Sjdp      struct debug_class_type *kclass;
11833965Sjdp      /* DEBUG_KIND_ENUM.  */
11933965Sjdp      struct debug_enum_type *kenum;
12033965Sjdp      /* DEBUG_KIND_POINTER.  */
12133965Sjdp      struct debug_type *kpointer;
12233965Sjdp      /* DEBUG_KIND_FUNCTION.  */
12333965Sjdp      struct debug_function_type *kfunction;
12433965Sjdp      /* DEBUG_KIND_REFERENCE.  */
12533965Sjdp      struct debug_type *kreference;
12633965Sjdp      /* DEBUG_KIND_RANGE.  */
12733965Sjdp      struct debug_range_type *krange;
12833965Sjdp      /* DEBUG_KIND_ARRAY.  */
12933965Sjdp      struct debug_array_type *karray;
13033965Sjdp      /* DEBUG_KIND_SET.  */
13133965Sjdp      struct debug_set_type *kset;
13233965Sjdp      /* DEBUG_KIND_OFFSET.  */
13333965Sjdp      struct debug_offset_type *koffset;
13433965Sjdp      /* DEBUG_KIND_METHOD.  */
13533965Sjdp      struct debug_method_type *kmethod;
13633965Sjdp      /* DEBUG_KIND_CONST.  */
13733965Sjdp      struct debug_type *kconst;
13833965Sjdp      /* DEBUG_KIND_VOLATILE.  */
13933965Sjdp      struct debug_type *kvolatile;
14033965Sjdp      /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED.  */
14133965Sjdp      struct debug_named_type *knamed;
14233965Sjdp    } u;
14333965Sjdp};
14433965Sjdp
14533965Sjdp/* Information kept for an indirect type.  */
14633965Sjdp
14733965Sjdpstruct debug_indirect_type
14833965Sjdp{
14933965Sjdp  /* Slot where the final type will appear.  */
15033965Sjdp  debug_type *slot;
15133965Sjdp  /* Tag.  */
15233965Sjdp  const char *tag;
15333965Sjdp};
15433965Sjdp
15533965Sjdp/* Information kept for a struct, union, or class.  */
15633965Sjdp
15733965Sjdpstruct debug_class_type
15833965Sjdp{
15933965Sjdp  /* NULL terminated array of fields.  */
16033965Sjdp  debug_field *fields;
16133965Sjdp  /* A mark field which indicates whether the struct has already been
16233965Sjdp     printed.  */
16333965Sjdp  unsigned int mark;
16433965Sjdp  /* This is used to uniquely identify unnamed structs when printing.  */
16533965Sjdp  unsigned int id;
16633965Sjdp  /* The remaining fields are only used for DEBUG_KIND_CLASS and
16733965Sjdp     DEBUG_KIND_UNION_CLASS.  */
16833965Sjdp  /* NULL terminated array of base classes.  */
16933965Sjdp  debug_baseclass *baseclasses;
17033965Sjdp  /* NULL terminated array of methods.  */
17133965Sjdp  debug_method *methods;
17233965Sjdp  /* The type of the class providing the virtual function table for
17333965Sjdp     this class.  This may point to the type itself.  */
17433965Sjdp  debug_type vptrbase;
17533965Sjdp};
17633965Sjdp
17733965Sjdp/* Information kept for an enum.  */
17833965Sjdp
17933965Sjdpstruct debug_enum_type
18033965Sjdp{
18133965Sjdp  /* NULL terminated array of names.  */
18233965Sjdp  const char **names;
18333965Sjdp  /* Array of corresponding values.  */
18433965Sjdp  bfd_signed_vma *values;
18533965Sjdp};
18633965Sjdp
18733965Sjdp/* Information kept for a function.  FIXME: We should be able to
18833965Sjdp   record the parameter types.  */
18933965Sjdp
19033965Sjdpstruct debug_function_type
19133965Sjdp{
19233965Sjdp  /* Return type.  */
19333965Sjdp  debug_type return_type;
19433965Sjdp  /* NULL terminated array of argument types.  */
19533965Sjdp  debug_type *arg_types;
19633965Sjdp  /* Whether the function takes a variable number of arguments.  */
19733965Sjdp  boolean varargs;
19833965Sjdp};
19933965Sjdp
20033965Sjdp/* Information kept for a range.  */
20133965Sjdp
20233965Sjdpstruct debug_range_type
20333965Sjdp{
20433965Sjdp  /* Range base type.  */
20533965Sjdp  debug_type type;
20633965Sjdp  /* Lower bound.  */
20733965Sjdp  bfd_signed_vma lower;
20833965Sjdp  /* Upper bound.  */
20933965Sjdp  bfd_signed_vma upper;
21033965Sjdp};
21133965Sjdp
21233965Sjdp/* Information kept for an array.  */
21333965Sjdp
21433965Sjdpstruct debug_array_type
21533965Sjdp{
21633965Sjdp  /* Element type.  */
21733965Sjdp  debug_type element_type;
21833965Sjdp  /* Range type.  */
21933965Sjdp  debug_type range_type;
22033965Sjdp  /* Lower bound.  */
22133965Sjdp  bfd_signed_vma lower;
22233965Sjdp  /* Upper bound.  */
22333965Sjdp  bfd_signed_vma upper;
22433965Sjdp  /* Whether this array is really a string.  */
22533965Sjdp  boolean stringp;
22633965Sjdp};
22733965Sjdp
22833965Sjdp/* Information kept for a set.  */
22933965Sjdp
23033965Sjdpstruct debug_set_type
23133965Sjdp{
23233965Sjdp  /* Base type.  */
23333965Sjdp  debug_type type;
23433965Sjdp  /* Whether this set is really a bitstring.  */
23533965Sjdp  boolean bitstringp;
23633965Sjdp};
23733965Sjdp
23833965Sjdp/* Information kept for an offset type (a based pointer).  */
23933965Sjdp
24033965Sjdpstruct debug_offset_type
24133965Sjdp{
24233965Sjdp  /* The type the pointer is an offset from.  */
24333965Sjdp  debug_type base_type;
24433965Sjdp  /* The type the pointer points to.  */
24533965Sjdp  debug_type target_type;
24633965Sjdp};
24733965Sjdp
24833965Sjdp/* Information kept for a method type.  */
24933965Sjdp
25033965Sjdpstruct debug_method_type
25133965Sjdp{
25233965Sjdp  /* The return type.  */
25333965Sjdp  debug_type return_type;
25433965Sjdp  /* The object type which this method is for.  */
25533965Sjdp  debug_type domain_type;
25633965Sjdp  /* A NULL terminated array of argument types.  */
25733965Sjdp  debug_type *arg_types;
25833965Sjdp  /* Whether the method takes a variable number of arguments.  */
25933965Sjdp  boolean varargs;
26033965Sjdp};
26133965Sjdp
26233965Sjdp/* Information kept for a named type.  */
26333965Sjdp
26433965Sjdpstruct debug_named_type
26533965Sjdp{
26633965Sjdp  /* Name.  */
26733965Sjdp  struct debug_name *name;
26833965Sjdp  /* Real type.  */
26933965Sjdp  debug_type type;
27033965Sjdp};
27133965Sjdp
27233965Sjdp/* A field in a struct or union.  */
27333965Sjdp
27433965Sjdpstruct debug_field
27533965Sjdp{
27633965Sjdp  /* Name of the field.  */
27733965Sjdp  const char *name;
27833965Sjdp  /* Type of the field.  */
27933965Sjdp  struct debug_type *type;
28033965Sjdp  /* Visibility of the field.  */
28133965Sjdp  enum debug_visibility visibility;
28233965Sjdp  /* Whether this is a static member.  */
28333965Sjdp  boolean static_member;
28433965Sjdp  union
28533965Sjdp    {
28633965Sjdp      /* If static_member is false.  */
28733965Sjdp      struct
28833965Sjdp	{
28933965Sjdp	  /* Bit position of the field in the struct.  */
29033965Sjdp	  unsigned int bitpos;
29133965Sjdp	  /* Size of the field in bits.  */
29233965Sjdp	  unsigned int bitsize;
29333965Sjdp	} f;
29433965Sjdp      /* If static_member is true.  */
29533965Sjdp      struct
29633965Sjdp	{
29733965Sjdp	  const char *physname;
29833965Sjdp	} s;
29933965Sjdp    } u;
30033965Sjdp};
30133965Sjdp
30233965Sjdp/* A base class for an object.  */
30333965Sjdp
30433965Sjdpstruct debug_baseclass
30533965Sjdp{
30633965Sjdp  /* Type of the base class.  */
30733965Sjdp  struct debug_type *type;
30833965Sjdp  /* Bit position of the base class in the object.  */
30933965Sjdp  unsigned int bitpos;
31033965Sjdp  /* Whether the base class is virtual.  */
31133965Sjdp  boolean virtual;
31233965Sjdp  /* Visibility of the base class.  */
31333965Sjdp  enum debug_visibility visibility;
31433965Sjdp};
31533965Sjdp
31633965Sjdp/* A method of an object.  */
31733965Sjdp
31833965Sjdpstruct debug_method
31933965Sjdp{
32033965Sjdp  /* The name of the method.  */
32133965Sjdp  const char *name;
32233965Sjdp  /* A NULL terminated array of different types of variants.  */
32333965Sjdp  struct debug_method_variant **variants;
32433965Sjdp};
32533965Sjdp
32633965Sjdp/* The variants of a method function of an object.  These indicate
32733965Sjdp   which method to run.  */
32833965Sjdp
32933965Sjdpstruct debug_method_variant
33033965Sjdp{
33133965Sjdp  /* The physical name of the function.  */
33233965Sjdp  const char *physname;
33333965Sjdp  /* The type of the function.  */
33433965Sjdp  struct debug_type *type;
33533965Sjdp  /* The visibility of the function.  */
33633965Sjdp  enum debug_visibility visibility;
33733965Sjdp  /* Whether the function is const.  */
33833965Sjdp  boolean constp;
33933965Sjdp  /* Whether the function is volatile.  */
34033965Sjdp  boolean volatilep;
34133965Sjdp  /* The offset to the function in the virtual function table.  */
34233965Sjdp  bfd_vma voffset;
34333965Sjdp  /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */
34433965Sjdp#define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
34533965Sjdp  /* Context of a virtual method function.  */
34633965Sjdp  struct debug_type *context;
34733965Sjdp};
34833965Sjdp
34933965Sjdp/* A variable.  This is the information we keep for a variable object.
35033965Sjdp   This has no name; a name is associated with a variable in a
35133965Sjdp   debug_name structure.  */
35233965Sjdp
35333965Sjdpstruct debug_variable
35433965Sjdp{
35533965Sjdp  /* Kind of variable.  */
35633965Sjdp  enum debug_var_kind kind;
35733965Sjdp  /* Type.  */
35833965Sjdp  debug_type type;
35933965Sjdp  /* Value.  The interpretation of the value depends upon kind.  */
36033965Sjdp  bfd_vma val;
36133965Sjdp};
36233965Sjdp
36333965Sjdp/* A function.  This has no name; a name is associated with a function
36433965Sjdp   in a debug_name structure.  */
36533965Sjdp
36633965Sjdpstruct debug_function
36733965Sjdp{
36833965Sjdp  /* Return type.  */
36933965Sjdp  debug_type return_type;
37033965Sjdp  /* Parameter information.  */
37133965Sjdp  struct debug_parameter *parameters;
37233965Sjdp  /* Block information.  The first structure on the list is the main
37333965Sjdp     block of the function, and describes function local variables.  */
37433965Sjdp  struct debug_block *blocks;
37533965Sjdp};
37633965Sjdp
37733965Sjdp/* A function parameter.  */
37833965Sjdp
37933965Sjdpstruct debug_parameter
38033965Sjdp{
38133965Sjdp  /* Next parameter.  */
38233965Sjdp  struct debug_parameter *next;
38333965Sjdp  /* Name.  */
38433965Sjdp  const char *name;
38533965Sjdp  /* Type.  */
38633965Sjdp  debug_type type;
38733965Sjdp  /* Kind.  */
38833965Sjdp  enum debug_parm_kind kind;
38933965Sjdp  /* Value (meaning depends upon kind).  */
39033965Sjdp  bfd_vma val;
39133965Sjdp};
39233965Sjdp
39333965Sjdp/* A typed constant.  */
39433965Sjdp
39533965Sjdpstruct debug_typed_constant
39633965Sjdp{
39733965Sjdp  /* Type.  */
39833965Sjdp  debug_type type;
39933965Sjdp  /* Value.  FIXME: We may eventually need to support non-integral
40033965Sjdp     values.  */
40133965Sjdp  bfd_vma val;
40233965Sjdp};
40333965Sjdp
40433965Sjdp/* Information about a block within a function.  */
40533965Sjdp
40633965Sjdpstruct debug_block
40733965Sjdp{
40833965Sjdp  /* Next block with the same parent.  */
40933965Sjdp  struct debug_block *next;
41033965Sjdp  /* Parent block.  */
41133965Sjdp  struct debug_block *parent;
41233965Sjdp  /* List of child blocks.  */
41333965Sjdp  struct debug_block *children;
41433965Sjdp  /* Start address of the block.  */
41533965Sjdp  bfd_vma start;
41633965Sjdp  /* End address of the block.  */
41733965Sjdp  bfd_vma end;
41833965Sjdp  /* Local variables.  */
41933965Sjdp  struct debug_namespace *locals;
42033965Sjdp};
42133965Sjdp
42233965Sjdp/* Line number information we keep for a compilation unit.  FIXME:
42333965Sjdp   This structure is easy to create, but can be very space
42433965Sjdp   inefficient.  */
42533965Sjdp
42633965Sjdpstruct debug_lineno
42733965Sjdp{
42833965Sjdp  /* More line number information for this block.  */
42933965Sjdp  struct debug_lineno *next;
43033965Sjdp  /* Source file.  */
43133965Sjdp  struct debug_file *file;
43233965Sjdp  /* Line numbers, terminated by a -1 or the end of the array.  */
43333965Sjdp#define DEBUG_LINENO_COUNT 10
43433965Sjdp  unsigned long linenos[DEBUG_LINENO_COUNT];
43533965Sjdp  /* Addresses for the line numbers.  */
43633965Sjdp  bfd_vma addrs[DEBUG_LINENO_COUNT];
43733965Sjdp};
43833965Sjdp
43933965Sjdp/* A namespace.  This is a mapping from names to objects.  FIXME: This
44033965Sjdp   should be implemented as a hash table.  */
44133965Sjdp
44233965Sjdpstruct debug_namespace
44333965Sjdp{
44433965Sjdp  /* List of items in this namespace.  */
44533965Sjdp  struct debug_name *list;
44633965Sjdp  /* Pointer to where the next item in this namespace should go.  */
44733965Sjdp  struct debug_name **tail;
44833965Sjdp};
44933965Sjdp
45033965Sjdp/* Kinds of objects that appear in a namespace.  */
45133965Sjdp
45233965Sjdpenum debug_object_kind
45333965Sjdp{
45433965Sjdp  /* A type.  */
45533965Sjdp  DEBUG_OBJECT_TYPE,
45633965Sjdp  /* A tagged type (really a different sort of namespace).  */
45733965Sjdp  DEBUG_OBJECT_TAG,
45833965Sjdp  /* A variable.  */
45933965Sjdp  DEBUG_OBJECT_VARIABLE,
46033965Sjdp  /* A function.  */
46133965Sjdp  DEBUG_OBJECT_FUNCTION,
46233965Sjdp  /* An integer constant.  */
46333965Sjdp  DEBUG_OBJECT_INT_CONSTANT,
46433965Sjdp  /* A floating point constant.  */
46533965Sjdp  DEBUG_OBJECT_FLOAT_CONSTANT,
46633965Sjdp  /* A typed constant.  */
46733965Sjdp  DEBUG_OBJECT_TYPED_CONSTANT
46833965Sjdp};
46933965Sjdp
47033965Sjdp/* Linkage of an object that appears in a namespace.  */
47133965Sjdp
47233965Sjdpenum debug_object_linkage
47333965Sjdp{
47433965Sjdp  /* Local variable.  */
47533965Sjdp  DEBUG_LINKAGE_AUTOMATIC,
47633965Sjdp  /* Static--either file static or function static, depending upon the
47733965Sjdp     namespace is.  */
47833965Sjdp  DEBUG_LINKAGE_STATIC,
47933965Sjdp  /* Global.  */
48033965Sjdp  DEBUG_LINKAGE_GLOBAL,
48133965Sjdp  /* No linkage.  */
48233965Sjdp  DEBUG_LINKAGE_NONE
48333965Sjdp};
48433965Sjdp
48533965Sjdp/* A name in a namespace.  */
48633965Sjdp
48733965Sjdpstruct debug_name
48833965Sjdp{
48933965Sjdp  /* Next name in this namespace.  */
49033965Sjdp  struct debug_name *next;
49133965Sjdp  /* Name.  */
49233965Sjdp  const char *name;
49333965Sjdp  /* Mark.  This is used by debug_write.  */
49433965Sjdp  unsigned int mark;
49533965Sjdp  /* Kind of object.  */
49633965Sjdp  enum debug_object_kind kind;
49733965Sjdp  /* Linkage of object.  */
49833965Sjdp  enum debug_object_linkage linkage;
49933965Sjdp  /* Tagged union with additional information about the object.  */
50033965Sjdp  union
50133965Sjdp    {
50233965Sjdp      /* DEBUG_OBJECT_TYPE.  */
50333965Sjdp      struct debug_type *type;
50433965Sjdp      /* DEBUG_OBJECT_TAG.  */
50533965Sjdp      struct debug_type *tag;
50633965Sjdp      /* DEBUG_OBJECT_VARIABLE.  */
50733965Sjdp      struct debug_variable *variable;
50833965Sjdp      /* DEBUG_OBJECT_FUNCTION.  */
50933965Sjdp      struct debug_function *function;
51033965Sjdp      /* DEBUG_OBJECT_INT_CONSTANT.  */
51133965Sjdp      bfd_vma int_constant;
51233965Sjdp      /* DEBUG_OBJECT_FLOAT_CONSTANT.  */
51333965Sjdp      double float_constant;
51433965Sjdp      /* DEBUG_OBJECT_TYPED_CONSTANT.  */
51533965Sjdp      struct debug_typed_constant *typed_constant;
51633965Sjdp    } u;
51733965Sjdp};
51833965Sjdp
51933965Sjdp/* During debug_write, a linked list of these structures is used to
52033965Sjdp   keep track of ID numbers that have been assigned to classes.  */
52133965Sjdp
52233965Sjdpstruct debug_class_id
52333965Sjdp{
52433965Sjdp  /* Next ID number.  */
52533965Sjdp  struct debug_class_id *next;
52633965Sjdp  /* The type with the ID.  */
52733965Sjdp  struct debug_type *type;
52833965Sjdp  /* The tag; NULL if no tag.  */
52933965Sjdp  const char *tag;
53033965Sjdp};
53133965Sjdp
53233965Sjdp/* During debug_type_samep, a linked list of these structures is kept
53333965Sjdp   on the stack to avoid infinite recursion.  */
53433965Sjdp
53533965Sjdpstruct debug_type_compare_list
53633965Sjdp{
53733965Sjdp  /* Next type on list.  */
53833965Sjdp  struct debug_type_compare_list *next;
53933965Sjdp  /* The types we are comparing.  */
54033965Sjdp  struct debug_type *t1;
54133965Sjdp  struct debug_type *t2;
54233965Sjdp};
54333965Sjdp
54433965Sjdp/* Local functions.  */
54533965Sjdp
54633965Sjdpstatic void debug_error PARAMS ((const char *));
54733965Sjdpstatic struct debug_name *debug_add_to_namespace
54833965Sjdp  PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
54933965Sjdp	   enum debug_object_kind, enum debug_object_linkage));
55033965Sjdpstatic struct debug_name *debug_add_to_current_namespace
55133965Sjdp  PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
55233965Sjdp	   enum debug_object_linkage));
55333965Sjdpstatic struct debug_type *debug_make_type
55433965Sjdp  PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
55533965Sjdpstatic struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
55633965Sjdpstatic boolean debug_write_name
55733965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
55833965Sjdp	   struct debug_name *));
55933965Sjdpstatic boolean debug_write_type
56033965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
56133965Sjdp	   struct debug_type *, struct debug_name *));
56233965Sjdpstatic boolean debug_write_class_type
56333965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
56433965Sjdp	   struct debug_type *, const char *));
56533965Sjdpstatic boolean debug_write_function
56633965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
56733965Sjdp	   const char *, enum debug_object_linkage, struct debug_function *));
56833965Sjdpstatic boolean debug_write_block
56933965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
57033965Sjdp	   struct debug_block *));
57133965Sjdpstatic boolean debug_write_linenos
57233965Sjdp  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
57333965Sjdp	   bfd_vma));
57433965Sjdpstatic boolean debug_set_class_id
57533965Sjdp  PARAMS ((struct debug_handle *, const char *, struct debug_type *));
57633965Sjdpstatic boolean debug_type_samep
57733965Sjdp  PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
57833965Sjdpstatic boolean debug_class_type_samep
57933965Sjdp  PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
58033965Sjdp
58133965Sjdp/* Issue an error message.  */
58233965Sjdp
58333965Sjdpstatic void
58433965Sjdpdebug_error (message)
58533965Sjdp     const char *message;
58633965Sjdp{
58733965Sjdp  fprintf (stderr, "%s\n", message);
58833965Sjdp}
58933965Sjdp
59033965Sjdp/* Add an object to a namespace.  */
59133965Sjdp
59233965Sjdpstatic struct debug_name *
59333965Sjdpdebug_add_to_namespace (info, nsp, name, kind, linkage)
59433965Sjdp     struct debug_handle *info;
59533965Sjdp     struct debug_namespace **nsp;
59633965Sjdp     const char *name;
59733965Sjdp     enum debug_object_kind kind;
59833965Sjdp     enum debug_object_linkage linkage;
59933965Sjdp{
60033965Sjdp  struct debug_name *n;
60133965Sjdp  struct debug_namespace *ns;
60233965Sjdp
60333965Sjdp  n = (struct debug_name *) xmalloc (sizeof *n);
60433965Sjdp  memset (n, 0, sizeof *n);
60533965Sjdp
60633965Sjdp  n->name = name;
60733965Sjdp  n->kind = kind;
60833965Sjdp  n->linkage = linkage;
60933965Sjdp
61033965Sjdp  ns = *nsp;
61133965Sjdp  if (ns == NULL)
61233965Sjdp    {
61333965Sjdp      ns = (struct debug_namespace *) xmalloc (sizeof *ns);
61433965Sjdp      memset (ns, 0, sizeof *ns);
61533965Sjdp
61633965Sjdp      ns->tail = &ns->list;
61733965Sjdp
61833965Sjdp      *nsp = ns;
61933965Sjdp    }
62033965Sjdp
62133965Sjdp  *ns->tail = n;
62233965Sjdp  ns->tail = &n->next;
62333965Sjdp
62433965Sjdp  return n;
62533965Sjdp}
62633965Sjdp
62733965Sjdp/* Add an object to the current namespace.  */
62833965Sjdp
62933965Sjdpstatic struct debug_name *
63033965Sjdpdebug_add_to_current_namespace (info, name, kind, linkage)
63133965Sjdp     struct debug_handle *info;
63233965Sjdp     const char *name;
63333965Sjdp     enum debug_object_kind kind;
63433965Sjdp     enum debug_object_linkage linkage;
63533965Sjdp{
63633965Sjdp  struct debug_namespace **nsp;
63733965Sjdp
63833965Sjdp  if (info->current_unit == NULL
63933965Sjdp      || info->current_file == NULL)
64033965Sjdp    {
64133965Sjdp      debug_error ("debug_add_to_current_namespace: no current file");
64233965Sjdp      return NULL;
64333965Sjdp    }
64433965Sjdp
64533965Sjdp  if (info->current_block != NULL)
64633965Sjdp    nsp = &info->current_block->locals;
64733965Sjdp  else
64833965Sjdp    nsp = &info->current_file->globals;
64933965Sjdp
65033965Sjdp  return debug_add_to_namespace (info, nsp, name, kind, linkage);
65133965Sjdp}
65233965Sjdp
65333965Sjdp/* Return a handle for debugging information.  */
65433965Sjdp
65533965SjdpPTR
65633965Sjdpdebug_init ()
65733965Sjdp{
65833965Sjdp  struct debug_handle *ret;
65933965Sjdp
66033965Sjdp  ret = (struct debug_handle *) xmalloc (sizeof *ret);
66133965Sjdp  memset (ret, 0, sizeof *ret);
66233965Sjdp  return (PTR) ret;
66333965Sjdp}
66433965Sjdp
66533965Sjdp/* Set the source filename.  This implicitly starts a new compilation
66633965Sjdp   unit.  */
66733965Sjdp
66833965Sjdpboolean
66933965Sjdpdebug_set_filename (handle, name)
67033965Sjdp     PTR handle;
67133965Sjdp     const char *name;
67233965Sjdp{
67333965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
67433965Sjdp  struct debug_file *nfile;
67533965Sjdp  struct debug_unit *nunit;
67633965Sjdp
67733965Sjdp  if (name == NULL)
67833965Sjdp    name = "";
67933965Sjdp
68033965Sjdp  nfile = (struct debug_file *) xmalloc (sizeof *nfile);
68133965Sjdp  memset (nfile, 0, sizeof *nfile);
68233965Sjdp
68333965Sjdp  nfile->filename = name;
68433965Sjdp
68533965Sjdp  nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
68633965Sjdp  memset (nunit, 0, sizeof *nunit);
68733965Sjdp
68833965Sjdp  nunit->files = nfile;
68933965Sjdp  info->current_file = nfile;
69033965Sjdp
69133965Sjdp  if (info->current_unit != NULL)
69233965Sjdp    info->current_unit->next = nunit;
69333965Sjdp  else
69433965Sjdp    {
69533965Sjdp      assert (info->units == NULL);
69633965Sjdp      info->units = nunit;
69733965Sjdp    }
69833965Sjdp
69933965Sjdp  info->current_unit = nunit;
70033965Sjdp
70133965Sjdp  info->current_function = NULL;
70233965Sjdp  info->current_block = NULL;
70333965Sjdp  info->current_lineno = NULL;
70433965Sjdp
70533965Sjdp  return true;
70633965Sjdp}
70733965Sjdp
70833965Sjdp/* Change source files to the given file name.  This is used for
70933965Sjdp   include files in a single compilation unit.  */
71033965Sjdp
71133965Sjdpboolean
71233965Sjdpdebug_start_source (handle, name)
71333965Sjdp     PTR handle;
71433965Sjdp     const char *name;
71533965Sjdp{
71633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
71733965Sjdp  struct debug_file *f, **pf;
71833965Sjdp
71933965Sjdp  if (name == NULL)
72033965Sjdp    name = "";
72133965Sjdp
72233965Sjdp  if (info->current_unit == NULL)
72333965Sjdp    {
72433965Sjdp      debug_error ("debug_start_source: no debug_set_filename call");
72533965Sjdp      return false;
72633965Sjdp    }
72733965Sjdp
72833965Sjdp  for (f = info->current_unit->files; f != NULL; f = f->next)
72933965Sjdp    {
73033965Sjdp      if (f->filename[0] == name[0]
73133965Sjdp	  && f->filename[1] == name[1]
73233965Sjdp	  && strcmp (f->filename, name) == 0)
73333965Sjdp	{
73433965Sjdp	  info->current_file = f;
73533965Sjdp	  return true;
73633965Sjdp	}
73733965Sjdp    }
73833965Sjdp
73933965Sjdp  f = (struct debug_file *) xmalloc (sizeof *f);
74033965Sjdp  memset (f, 0, sizeof *f);
74133965Sjdp
74233965Sjdp  f->filename = name;
74333965Sjdp
74433965Sjdp  for (pf = &info->current_file->next;
74533965Sjdp       *pf != NULL;
74633965Sjdp       pf = &(*pf)->next)
74733965Sjdp    ;
74833965Sjdp  *pf = f;
74933965Sjdp
75033965Sjdp  info->current_file = f;
75133965Sjdp
75233965Sjdp  return true;
75333965Sjdp}
75433965Sjdp
75533965Sjdp/* Record a function definition.  This implicitly starts a function
75633965Sjdp   block.  The debug_type argument is the type of the return value.
75733965Sjdp   The boolean indicates whether the function is globally visible.
75833965Sjdp   The bfd_vma is the address of the start of the function.  Currently
75933965Sjdp   the parameter types are specified by calls to
76033965Sjdp   debug_record_parameter.  FIXME: There is no way to specify nested
76133965Sjdp   functions.  */
76233965Sjdp
76333965Sjdpboolean
76433965Sjdpdebug_record_function (handle, name, return_type, global, addr)
76533965Sjdp     PTR handle;
76633965Sjdp     const char *name;
76733965Sjdp     debug_type return_type;
76833965Sjdp     boolean global;
76933965Sjdp     bfd_vma addr;
77033965Sjdp{
77133965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
77233965Sjdp  struct debug_function *f;
77333965Sjdp  struct debug_block *b;
77433965Sjdp  struct debug_name *n;
77533965Sjdp
77633965Sjdp  if (name == NULL)
77733965Sjdp    name = "";
77833965Sjdp  if (return_type == NULL)
77933965Sjdp    return false;
78033965Sjdp
78133965Sjdp  if (info->current_unit == NULL)
78233965Sjdp    {
78333965Sjdp      debug_error ("debug_record_function: no debug_set_filename call");
78433965Sjdp      return false;
78533965Sjdp    }
78633965Sjdp
78733965Sjdp  f = (struct debug_function *) xmalloc (sizeof *f);
78833965Sjdp  memset (f, 0, sizeof *f);
78933965Sjdp
79033965Sjdp  f->return_type = return_type;
79133965Sjdp
79233965Sjdp  b = (struct debug_block *) xmalloc (sizeof *b);
79333965Sjdp  memset (b, 0, sizeof *b);
79433965Sjdp
79533965Sjdp  b->start = addr;
79633965Sjdp  b->end = (bfd_vma) -1;
79733965Sjdp
79833965Sjdp  f->blocks = b;
79933965Sjdp
80033965Sjdp  info->current_function = f;
80133965Sjdp  info->current_block = b;
80233965Sjdp
80333965Sjdp  /* FIXME: If we could handle nested functions, this would be the
80433965Sjdp     place: we would want to use a different namespace.  */
80533965Sjdp  n = debug_add_to_namespace (info,
80633965Sjdp			      &info->current_file->globals,
80733965Sjdp			      name,
80833965Sjdp			      DEBUG_OBJECT_FUNCTION,
80933965Sjdp			      (global
81033965Sjdp			       ? DEBUG_LINKAGE_GLOBAL
81133965Sjdp			       : DEBUG_LINKAGE_STATIC));
81233965Sjdp  if (n == NULL)
81333965Sjdp    return false;
81433965Sjdp
81533965Sjdp  n->u.function = f;
81633965Sjdp
81733965Sjdp  return true;
81833965Sjdp}
81933965Sjdp
82033965Sjdp/* Record a parameter for the current function.  */
82133965Sjdp
82233965Sjdpboolean
82333965Sjdpdebug_record_parameter (handle, name, type, kind, val)
82433965Sjdp     PTR handle;
82533965Sjdp     const char *name;
82633965Sjdp     debug_type type;
82733965Sjdp     enum debug_parm_kind kind;
82833965Sjdp     bfd_vma val;
82933965Sjdp{
83033965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
83133965Sjdp  struct debug_parameter *p, **pp;
83233965Sjdp
83333965Sjdp  if (name == NULL || type == NULL)
83433965Sjdp    return false;
83533965Sjdp
83633965Sjdp  if (info->current_unit == NULL
83733965Sjdp      || info->current_function == NULL)
83833965Sjdp    {
83933965Sjdp      debug_error ("debug_record_parameter: no current function");
84033965Sjdp      return false;
84133965Sjdp    }
84233965Sjdp
84333965Sjdp  p = (struct debug_parameter *) xmalloc (sizeof *p);
84433965Sjdp  memset (p, 0, sizeof *p);
84533965Sjdp
84633965Sjdp  p->name = name;
84733965Sjdp  p->type = type;
84833965Sjdp  p->kind = kind;
84933965Sjdp  p->val = val;
85033965Sjdp
85133965Sjdp  for (pp = &info->current_function->parameters;
85233965Sjdp       *pp != NULL;
85333965Sjdp       pp = &(*pp)->next)
85433965Sjdp    ;
85533965Sjdp  *pp = p;
85633965Sjdp
85733965Sjdp  return true;
85833965Sjdp}
85933965Sjdp
86033965Sjdp/* End a function.  FIXME: This should handle function nesting.  */
86133965Sjdp
86233965Sjdpboolean
86333965Sjdpdebug_end_function (handle, addr)
86433965Sjdp     PTR handle;
86533965Sjdp     bfd_vma addr;
86633965Sjdp{
86733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
86833965Sjdp
86933965Sjdp  if (info->current_unit == NULL
87033965Sjdp      || info->current_block == NULL
87133965Sjdp      || info->current_function == NULL)
87233965Sjdp    {
87333965Sjdp      debug_error ("debug_end_function: no current function");
87433965Sjdp      return false;
87533965Sjdp    }
87633965Sjdp
87733965Sjdp  if (info->current_block->parent != NULL)
87833965Sjdp    {
87933965Sjdp      debug_error ("debug_end_function: some blocks were not closed");
88033965Sjdp      return false;
88133965Sjdp    }
88233965Sjdp
88333965Sjdp  info->current_block->end = addr;
88433965Sjdp
88533965Sjdp  info->current_function = NULL;
88633965Sjdp  info->current_block = NULL;
88733965Sjdp
88833965Sjdp  return true;
88933965Sjdp}
89033965Sjdp
89133965Sjdp/* Start a block in a function.  All local information will be
89233965Sjdp   recorded in this block, until the matching call to debug_end_block.
89333965Sjdp   debug_start_block and debug_end_block may be nested.  The bfd_vma
89433965Sjdp   argument is the address at which this block starts.  */
89533965Sjdp
89633965Sjdpboolean
89733965Sjdpdebug_start_block (handle, addr)
89833965Sjdp     PTR handle;
89933965Sjdp     bfd_vma addr;
90033965Sjdp{
90133965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
90233965Sjdp  struct debug_block *b, **pb;
90333965Sjdp
90433965Sjdp  /* We must always have a current block: debug_record_function sets
90533965Sjdp     one up.  */
90633965Sjdp  if (info->current_unit == NULL
90733965Sjdp      || info->current_block == NULL)
90833965Sjdp    {
90933965Sjdp      debug_error ("debug_start_block: no current block");
91033965Sjdp      return false;
91133965Sjdp    }
91233965Sjdp
91333965Sjdp  b = (struct debug_block *) xmalloc (sizeof *b);
91433965Sjdp  memset (b, 0, sizeof *b);
91533965Sjdp
91633965Sjdp  b->parent = info->current_block;
91733965Sjdp  b->start = addr;
91833965Sjdp  b->end = (bfd_vma) -1;
91933965Sjdp
92033965Sjdp  /* This new block is a child of the current block.  */
92133965Sjdp  for (pb = &info->current_block->children;
92233965Sjdp       *pb != NULL;
92333965Sjdp       pb = &(*pb)->next)
92433965Sjdp    ;
92533965Sjdp  *pb = b;
92633965Sjdp
92733965Sjdp  info->current_block = b;
92833965Sjdp
92933965Sjdp  return true;
93033965Sjdp}
93133965Sjdp
93233965Sjdp/* Finish a block in a function.  This matches the call to
93333965Sjdp   debug_start_block.  The argument is the address at which this block
93433965Sjdp   ends.  */
93533965Sjdp
93633965Sjdpboolean
93733965Sjdpdebug_end_block (handle, addr)
93833965Sjdp     PTR handle;
93933965Sjdp     bfd_vma addr;
94033965Sjdp{
94133965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
94233965Sjdp  struct debug_block *parent;
94333965Sjdp
94433965Sjdp  if (info->current_unit == NULL
94533965Sjdp      || info->current_block == NULL)
94633965Sjdp    {
94733965Sjdp      debug_error ("debug_end_block: no current block");
94833965Sjdp      return false;
94933965Sjdp    }
95033965Sjdp
95133965Sjdp  parent = info->current_block->parent;
95233965Sjdp  if (parent == NULL)
95333965Sjdp    {
95433965Sjdp      debug_error ("debug_end_block: attempt to close top level block");
95533965Sjdp      return false;
95633965Sjdp    }
95733965Sjdp
95833965Sjdp  info->current_block->end = addr;
95933965Sjdp
96033965Sjdp  info->current_block = parent;
96133965Sjdp
96233965Sjdp  return true;
96333965Sjdp}
96433965Sjdp
96533965Sjdp/* Associate a line number in the current source file and function
96633965Sjdp   with a given address.  */
96733965Sjdp
96833965Sjdpboolean
96933965Sjdpdebug_record_line (handle, lineno, addr)
97033965Sjdp     PTR handle;
97133965Sjdp     unsigned long lineno;
97233965Sjdp     bfd_vma addr;
97333965Sjdp{
97433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
97533965Sjdp  struct debug_lineno *l;
97633965Sjdp  unsigned int i;
97733965Sjdp
97833965Sjdp  if (info->current_unit == NULL)
97933965Sjdp    {
98033965Sjdp      debug_error ("debug_record_line: no current unit");
98133965Sjdp      return false;
98233965Sjdp    }
98333965Sjdp
98433965Sjdp  l = info->current_lineno;
98533965Sjdp  if (l != NULL && l->file == info->current_file)
98633965Sjdp    {
98733965Sjdp      for (i = 0; i < DEBUG_LINENO_COUNT; i++)
98833965Sjdp	{
98933965Sjdp	  if (l->linenos[i] == (unsigned long) -1)
99033965Sjdp	    {
99133965Sjdp	      l->linenos[i] = lineno;
99233965Sjdp	      l->addrs[i] = addr;
99333965Sjdp	      return true;
99433965Sjdp	    }
99533965Sjdp	}
99633965Sjdp    }
99733965Sjdp
99833965Sjdp  /* If we get here, then either 1) there is no current_lineno
99933965Sjdp     structure, which means this is the first line number in this
100033965Sjdp     compilation unit, 2) the current_lineno structure is for a
100133965Sjdp     different file, or 3) the current_lineno structure is full.
100233965Sjdp     Regardless, we want to allocate a new debug_lineno structure, put
100333965Sjdp     it in the right place, and make it the new current_lineno
100433965Sjdp     structure.  */
100533965Sjdp
100633965Sjdp  l = (struct debug_lineno *) xmalloc (sizeof *l);
100733965Sjdp  memset (l, 0, sizeof *l);
100833965Sjdp
100933965Sjdp  l->file = info->current_file;
101033965Sjdp  l->linenos[0] = lineno;
101133965Sjdp  l->addrs[0] = addr;
101233965Sjdp  for (i = 1; i < DEBUG_LINENO_COUNT; i++)
101333965Sjdp    l->linenos[i] = (unsigned long) -1;
101433965Sjdp
101533965Sjdp  if (info->current_lineno != NULL)
101633965Sjdp    info->current_lineno->next = l;
101733965Sjdp  else
101833965Sjdp    info->current_unit->linenos = l;
101933965Sjdp
102033965Sjdp  info->current_lineno = l;
102133965Sjdp
102233965Sjdp  return true;
102333965Sjdp}
102433965Sjdp
102533965Sjdp/* Start a named common block.  This is a block of variables that may
102633965Sjdp   move in memory.  */
102733965Sjdp
102833965Sjdpboolean
102933965Sjdpdebug_start_common_block (handle, name)
103033965Sjdp     PTR handle;
103133965Sjdp     const char *name;
103233965Sjdp{
103333965Sjdp  /* FIXME */
103433965Sjdp  debug_error ("debug_start_common_block: not implemented");
103533965Sjdp  return false;
103633965Sjdp}
103733965Sjdp
103833965Sjdp/* End a named common block.  */
103933965Sjdp
104033965Sjdpboolean
104133965Sjdpdebug_end_common_block (handle, name)
104233965Sjdp     PTR handle;
104333965Sjdp     const char *name;
104433965Sjdp{
104533965Sjdp  /* FIXME */
104633965Sjdp  debug_error ("debug_end_common_block: not implemented");
104733965Sjdp  return false;
104833965Sjdp}
104933965Sjdp
105033965Sjdp/* Record a named integer constant.  */
105133965Sjdp
105233965Sjdpboolean
105333965Sjdpdebug_record_int_const (handle, name, val)
105433965Sjdp     PTR handle;
105533965Sjdp     const char *name;
105633965Sjdp     bfd_vma val;
105733965Sjdp{
105833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
105933965Sjdp  struct debug_name *n;
106033965Sjdp
106133965Sjdp  if (name == NULL)
106233965Sjdp    return false;
106333965Sjdp
106433965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
106533965Sjdp				      DEBUG_LINKAGE_NONE);
106633965Sjdp  if (n == NULL)
106733965Sjdp    return false;
106833965Sjdp
106933965Sjdp  n->u.int_constant = val;
107033965Sjdp
107133965Sjdp  return true;
107233965Sjdp}
107333965Sjdp
107433965Sjdp/* Record a named floating point constant.  */
107533965Sjdp
107633965Sjdpboolean
107733965Sjdpdebug_record_float_const (handle, name, val)
107833965Sjdp     PTR handle;
107933965Sjdp     const char *name;
108033965Sjdp     double val;
108133965Sjdp{
108233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
108333965Sjdp  struct debug_name *n;
108433965Sjdp
108533965Sjdp  if (name == NULL)
108633965Sjdp    return false;
108733965Sjdp
108833965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
108933965Sjdp				      DEBUG_LINKAGE_NONE);
109033965Sjdp  if (n == NULL)
109133965Sjdp    return false;
109233965Sjdp
109333965Sjdp  n->u.float_constant = val;
109433965Sjdp
109533965Sjdp  return true;
109633965Sjdp}
109733965Sjdp
109833965Sjdp/* Record a typed constant with an integral value.  */
109933965Sjdp
110033965Sjdpboolean
110133965Sjdpdebug_record_typed_const (handle, name, type, val)
110233965Sjdp     PTR handle;
110333965Sjdp     const char *name;
110433965Sjdp     debug_type type;
110533965Sjdp     bfd_vma val;
110633965Sjdp{
110733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
110833965Sjdp  struct debug_name *n;
110933965Sjdp  struct debug_typed_constant *tc;
111033965Sjdp
111133965Sjdp  if (name == NULL || type == NULL)
111233965Sjdp    return false;
111333965Sjdp
111433965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
111533965Sjdp				      DEBUG_LINKAGE_NONE);
111633965Sjdp  if (n == NULL)
111733965Sjdp    return false;
111833965Sjdp
111933965Sjdp  tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
112033965Sjdp  memset (tc, 0, sizeof *tc);
112133965Sjdp
112233965Sjdp  tc->type = type;
112333965Sjdp  tc->val = val;
112433965Sjdp
112533965Sjdp  n->u.typed_constant = tc;
112633965Sjdp
112733965Sjdp  return true;
112833965Sjdp}
112933965Sjdp
113033965Sjdp/* Record a label.  */
113133965Sjdp
113233965Sjdpboolean
113333965Sjdpdebug_record_label (handle, name, type, addr)
113433965Sjdp     PTR handle;
113533965Sjdp     const char *name;
113633965Sjdp     debug_type type;
113733965Sjdp     bfd_vma addr;
113833965Sjdp{
113933965Sjdp  /* FIXME.  */
114033965Sjdp  debug_error ("debug_record_label not implemented");
114133965Sjdp  return false;
114233965Sjdp}
114333965Sjdp
114433965Sjdp/* Record a variable.  */
114533965Sjdp
114633965Sjdpboolean
114733965Sjdpdebug_record_variable (handle, name, type, kind, val)
114833965Sjdp     PTR handle;
114933965Sjdp     const char *name;
115033965Sjdp     debug_type type;
115133965Sjdp     enum debug_var_kind kind;
115233965Sjdp     bfd_vma val;
115333965Sjdp{
115433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
115533965Sjdp  struct debug_namespace **nsp;
115633965Sjdp  enum debug_object_linkage linkage;
115733965Sjdp  struct debug_name *n;
115833965Sjdp  struct debug_variable *v;
115933965Sjdp
116033965Sjdp  if (name == NULL || type == NULL)
116133965Sjdp    return false;
116233965Sjdp
116333965Sjdp  if (info->current_unit == NULL
116433965Sjdp      || info->current_file == NULL)
116533965Sjdp    {
116633965Sjdp      debug_error ("debug_record_variable: no current file");
116733965Sjdp      return false;
116833965Sjdp    }
116933965Sjdp
117033965Sjdp  if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
117133965Sjdp    {
117233965Sjdp      nsp = &info->current_file->globals;
117333965Sjdp      if (kind == DEBUG_GLOBAL)
117433965Sjdp	linkage = DEBUG_LINKAGE_GLOBAL;
117533965Sjdp      else
117633965Sjdp	linkage = DEBUG_LINKAGE_STATIC;
117733965Sjdp    }
117833965Sjdp  else
117933965Sjdp    {
118033965Sjdp      if (info->current_block == NULL)
118133965Sjdp	{
118233965Sjdp	  debug_error ("debug_record_variable: no current block");
118333965Sjdp	  return false;
118433965Sjdp	}
118533965Sjdp      nsp = &info->current_block->locals;
118633965Sjdp      linkage = DEBUG_LINKAGE_AUTOMATIC;
118733965Sjdp    }
118833965Sjdp
118933965Sjdp  n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
119033965Sjdp  if (n == NULL)
119133965Sjdp    return false;
119233965Sjdp
119333965Sjdp  v = (struct debug_variable *) xmalloc (sizeof *v);
119433965Sjdp  memset (v, 0, sizeof *v);
119533965Sjdp
119633965Sjdp  v->kind = kind;
119733965Sjdp  v->type = type;
119833965Sjdp  v->val = val;
119933965Sjdp
120033965Sjdp  n->u.variable = v;
120133965Sjdp
120233965Sjdp  return true;
120333965Sjdp}
120433965Sjdp
120533965Sjdp/* Make a type with a given kind and size.  */
120633965Sjdp
120733965Sjdp/*ARGSUSED*/
120833965Sjdpstatic struct debug_type *
120933965Sjdpdebug_make_type (info, kind, size)
121033965Sjdp     struct debug_handle *info;
121133965Sjdp     enum debug_type_kind kind;
121233965Sjdp     unsigned int size;
121333965Sjdp{
121433965Sjdp  struct debug_type *t;
121533965Sjdp
121633965Sjdp  t = (struct debug_type *) xmalloc (sizeof *t);
121733965Sjdp  memset (t, 0, sizeof *t);
121833965Sjdp
121933965Sjdp  t->kind = kind;
122033965Sjdp  t->size = size;
122133965Sjdp
122233965Sjdp  return t;
122333965Sjdp}
122433965Sjdp
122533965Sjdp/* Make an indirect type which may be used as a placeholder for a type
122633965Sjdp   which is referenced before it is defined.  */
122733965Sjdp
122833965Sjdpdebug_type
122933965Sjdpdebug_make_indirect_type (handle, slot, tag)
123033965Sjdp     PTR handle;
123133965Sjdp     debug_type *slot;
123233965Sjdp     const char *tag;
123333965Sjdp{
123433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
123533965Sjdp  struct debug_type *t;
123633965Sjdp  struct debug_indirect_type *i;
123733965Sjdp
123833965Sjdp  t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
123933965Sjdp  if (t == NULL)
124033965Sjdp    return DEBUG_TYPE_NULL;
124133965Sjdp
124233965Sjdp  i = (struct debug_indirect_type *) xmalloc (sizeof *i);
124333965Sjdp  memset (i, 0, sizeof *i);
124433965Sjdp
124533965Sjdp  i->slot = slot;
124633965Sjdp  i->tag = tag;
124733965Sjdp
124833965Sjdp  t->u.kindirect = i;
124933965Sjdp
125033965Sjdp  return t;
125133965Sjdp}
125233965Sjdp
125333965Sjdp/* Make a void type.  There is only one of these.  */
125433965Sjdp
125533965Sjdpdebug_type
125633965Sjdpdebug_make_void_type (handle)
125733965Sjdp     PTR handle;
125833965Sjdp{
125933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
126033965Sjdp
126133965Sjdp  return debug_make_type (info, DEBUG_KIND_VOID, 0);
126233965Sjdp}
126333965Sjdp
126433965Sjdp/* Make an integer type of a given size.  The boolean argument is true
126533965Sjdp   if the integer is unsigned.  */
126633965Sjdp
126733965Sjdpdebug_type
126833965Sjdpdebug_make_int_type (handle, size, unsignedp)
126933965Sjdp     PTR handle;
127033965Sjdp     unsigned int size;
127133965Sjdp     boolean unsignedp;
127233965Sjdp{
127333965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
127433965Sjdp  struct debug_type *t;
127533965Sjdp
127633965Sjdp  t = debug_make_type (info, DEBUG_KIND_INT, size);
127733965Sjdp  if (t == NULL)
127833965Sjdp    return DEBUG_TYPE_NULL;
127933965Sjdp
128033965Sjdp  t->u.kint = unsignedp;
128133965Sjdp
128233965Sjdp  return t;
128333965Sjdp}
128433965Sjdp
128533965Sjdp/* Make a floating point type of a given size.  FIXME: On some
128633965Sjdp   platforms, like an Alpha, you probably need to be able to specify
128733965Sjdp   the format.  */
128833965Sjdp
128933965Sjdpdebug_type
129033965Sjdpdebug_make_float_type (handle, size)
129133965Sjdp     PTR handle;
129233965Sjdp     unsigned int size;
129333965Sjdp{
129433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
129533965Sjdp
129633965Sjdp  return debug_make_type (info, DEBUG_KIND_FLOAT, size);
129733965Sjdp}
129833965Sjdp
129933965Sjdp/* Make a boolean type of a given size.  */
130033965Sjdp
130133965Sjdpdebug_type
130233965Sjdpdebug_make_bool_type (handle, size)
130333965Sjdp     PTR handle;
130433965Sjdp     unsigned int size;
130533965Sjdp{
130633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
130733965Sjdp
130833965Sjdp  return debug_make_type (info, DEBUG_KIND_BOOL, size);
130933965Sjdp}
131033965Sjdp
131133965Sjdp/* Make a complex type of a given size.  */
131233965Sjdp
131333965Sjdpdebug_type
131433965Sjdpdebug_make_complex_type (handle, size)
131533965Sjdp     PTR handle;
131633965Sjdp     unsigned int size;
131733965Sjdp{
131833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
131933965Sjdp
132033965Sjdp  return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
132133965Sjdp}
132233965Sjdp
132333965Sjdp/* Make a structure type.  The second argument is true for a struct,
132433965Sjdp   false for a union.  The third argument is the size of the struct.
132533965Sjdp   The fourth argument is a NULL terminated array of fields.  */
132633965Sjdp
132733965Sjdpdebug_type
132833965Sjdpdebug_make_struct_type (handle, structp, size, fields)
132933965Sjdp     PTR handle;
133033965Sjdp     boolean structp;
133133965Sjdp     bfd_vma size;
133233965Sjdp     debug_field *fields;
133333965Sjdp{
133433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
133533965Sjdp  struct debug_type *t;
133633965Sjdp  struct debug_class_type *c;
133733965Sjdp
133833965Sjdp  t = debug_make_type (info,
133933965Sjdp		       structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
134033965Sjdp		       size);
134133965Sjdp  if (t == NULL)
134233965Sjdp    return DEBUG_TYPE_NULL;
134333965Sjdp
134433965Sjdp  c = (struct debug_class_type *) xmalloc (sizeof *c);
134533965Sjdp  memset (c, 0, sizeof *c);
134633965Sjdp
134733965Sjdp  c->fields = fields;
134833965Sjdp
134933965Sjdp  t->u.kclass = c;
135033965Sjdp
135133965Sjdp  return t;
135233965Sjdp}
135333965Sjdp
135433965Sjdp/* Make an object type.  The first three arguments after the handle
135533965Sjdp   are the same as for debug_make_struct_type.  The next arguments are
135633965Sjdp   a NULL terminated array of base classes, a NULL terminated array of
135733965Sjdp   methods, the type of the object holding the virtual function table
135833965Sjdp   if it is not this object, and a boolean which is true if this
135933965Sjdp   object has its own virtual function table.  */
136033965Sjdp
136133965Sjdpdebug_type
136233965Sjdpdebug_make_object_type (handle, structp, size, fields, baseclasses,
136333965Sjdp			methods, vptrbase, ownvptr)
136433965Sjdp     PTR handle;
136533965Sjdp     boolean structp;
136633965Sjdp     bfd_vma size;
136733965Sjdp     debug_field *fields;
136833965Sjdp     debug_baseclass *baseclasses;
136933965Sjdp     debug_method *methods;
137033965Sjdp     debug_type vptrbase;
137133965Sjdp     boolean ownvptr;
137233965Sjdp{
137333965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
137433965Sjdp  struct debug_type *t;
137533965Sjdp  struct debug_class_type *c;
137633965Sjdp
137733965Sjdp  t = debug_make_type (info,
137833965Sjdp		       structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
137933965Sjdp		       size);
138033965Sjdp  if (t == NULL)
138133965Sjdp    return DEBUG_TYPE_NULL;
138233965Sjdp
138333965Sjdp  c = (struct debug_class_type *) xmalloc (sizeof *c);
138433965Sjdp  memset (c, 0, sizeof *c);
138533965Sjdp
138633965Sjdp  c->fields = fields;
138733965Sjdp  c->baseclasses = baseclasses;
138833965Sjdp  c->methods = methods;
138933965Sjdp  if (ownvptr)
139033965Sjdp    c->vptrbase = t;
139133965Sjdp  else
139233965Sjdp    c->vptrbase = vptrbase;
139333965Sjdp
139433965Sjdp  t->u.kclass = c;
139533965Sjdp
139633965Sjdp  return t;
139733965Sjdp}
139833965Sjdp
139933965Sjdp/* Make an enumeration type.  The arguments are a null terminated
140033965Sjdp   array of strings, and an array of corresponding values.  */
140133965Sjdp
140233965Sjdpdebug_type
140333965Sjdpdebug_make_enum_type (handle, names, values)
140433965Sjdp     PTR handle;
140533965Sjdp     const char **names;
140633965Sjdp     bfd_signed_vma *values;
140733965Sjdp{
140833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
140933965Sjdp  struct debug_type *t;
141033965Sjdp  struct debug_enum_type *e;
141133965Sjdp
141233965Sjdp  t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
141333965Sjdp  if (t == NULL)
141433965Sjdp    return DEBUG_TYPE_NULL;
141533965Sjdp
141633965Sjdp  e = (struct debug_enum_type *) xmalloc (sizeof *e);
141733965Sjdp  memset (e, 0, sizeof *e);
141833965Sjdp
141933965Sjdp  e->names = names;
142033965Sjdp  e->values = values;
142133965Sjdp
142233965Sjdp  t->u.kenum = e;
142333965Sjdp
142433965Sjdp  return t;
142533965Sjdp}
142633965Sjdp
142733965Sjdp/* Make a pointer to a given type.  */
142833965Sjdp
142933965Sjdpdebug_type
143033965Sjdpdebug_make_pointer_type (handle, type)
143133965Sjdp     PTR handle;
143233965Sjdp     debug_type type;
143333965Sjdp{
143433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
143533965Sjdp  struct debug_type *t;
143633965Sjdp
143733965Sjdp  if (type == NULL)
143833965Sjdp    return DEBUG_TYPE_NULL;
143933965Sjdp
144033965Sjdp  if (type->pointer != DEBUG_TYPE_NULL)
144133965Sjdp    return type->pointer;
144233965Sjdp
144333965Sjdp  t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
144433965Sjdp  if (t == NULL)
144533965Sjdp    return DEBUG_TYPE_NULL;
144633965Sjdp
144733965Sjdp  t->u.kpointer = type;
144833965Sjdp
144933965Sjdp  type->pointer = t;
145033965Sjdp
145133965Sjdp  return t;
145233965Sjdp}
145333965Sjdp
145433965Sjdp/* Make a function returning a given type.  FIXME: We should be able
145533965Sjdp   to record the parameter types.  */
145633965Sjdp
145733965Sjdpdebug_type
145833965Sjdpdebug_make_function_type (handle, type, arg_types, varargs)
145933965Sjdp     PTR handle;
146033965Sjdp     debug_type type;
146133965Sjdp     debug_type *arg_types;
146233965Sjdp     boolean varargs;
146333965Sjdp{
146433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
146533965Sjdp  struct debug_type *t;
146633965Sjdp  struct debug_function_type *f;
146733965Sjdp
146833965Sjdp  if (type == NULL)
146933965Sjdp    return DEBUG_TYPE_NULL;
147033965Sjdp
147133965Sjdp  t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
147233965Sjdp  if (t == NULL)
147333965Sjdp    return DEBUG_TYPE_NULL;
147433965Sjdp
147533965Sjdp  f = (struct debug_function_type *) xmalloc (sizeof *f);
147633965Sjdp  memset (f, 0, sizeof *f);
147733965Sjdp
147833965Sjdp  f->return_type = type;
147933965Sjdp  f->arg_types = arg_types;
148033965Sjdp  f->varargs = varargs;
148133965Sjdp
148233965Sjdp  t->u.kfunction = f;
148333965Sjdp
148433965Sjdp  return t;
148533965Sjdp}
148633965Sjdp
148733965Sjdp/* Make a reference to a given type.  */
148833965Sjdp
148933965Sjdpdebug_type
149033965Sjdpdebug_make_reference_type (handle, type)
149133965Sjdp     PTR handle;
149233965Sjdp     debug_type type;
149333965Sjdp{
149433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
149533965Sjdp  struct debug_type *t;
149633965Sjdp
149733965Sjdp  if (type == NULL)
149833965Sjdp    return DEBUG_TYPE_NULL;
149933965Sjdp
150033965Sjdp  t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
150133965Sjdp  if (t == NULL)
150233965Sjdp    return DEBUG_TYPE_NULL;
150333965Sjdp
150433965Sjdp  t->u.kreference = type;
150533965Sjdp
150633965Sjdp  return t;
150733965Sjdp}
150833965Sjdp
150933965Sjdp/* Make a range of a given type from a lower to an upper bound.  */
151033965Sjdp
151133965Sjdpdebug_type
151233965Sjdpdebug_make_range_type (handle, type, lower, upper)
151333965Sjdp     PTR handle;
151433965Sjdp     debug_type type;
151533965Sjdp     bfd_signed_vma lower;
151633965Sjdp     bfd_signed_vma upper;
151733965Sjdp{
151833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
151933965Sjdp  struct debug_type *t;
152033965Sjdp  struct debug_range_type *r;
152133965Sjdp
152233965Sjdp  if (type == NULL)
152333965Sjdp    return DEBUG_TYPE_NULL;
152433965Sjdp
152533965Sjdp  t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
152633965Sjdp  if (t == NULL)
152733965Sjdp    return DEBUG_TYPE_NULL;
152833965Sjdp
152933965Sjdp  r = (struct debug_range_type *) xmalloc (sizeof *r);
153033965Sjdp  memset (r, 0, sizeof *r);
153133965Sjdp
153233965Sjdp  r->type = type;
153333965Sjdp  r->lower = lower;
153433965Sjdp  r->upper = upper;
153533965Sjdp
153633965Sjdp  t->u.krange = r;
153733965Sjdp
153833965Sjdp  return t;
153933965Sjdp}
154033965Sjdp
154133965Sjdp/* Make an array type.  The second argument is the type of an element
154233965Sjdp   of the array.  The third argument is the type of a range of the
154333965Sjdp   array.  The fourth and fifth argument are the lower and upper
154433965Sjdp   bounds, respectively.  The sixth argument is true if this array is
154533965Sjdp   actually a string, as in C.  */
154633965Sjdp
154733965Sjdpdebug_type
154833965Sjdpdebug_make_array_type (handle, element_type, range_type, lower, upper,
154933965Sjdp		       stringp)
155033965Sjdp     PTR handle;
155133965Sjdp     debug_type element_type;
155233965Sjdp     debug_type range_type;
155333965Sjdp     bfd_signed_vma lower;
155433965Sjdp     bfd_signed_vma upper;
155533965Sjdp     boolean stringp;
155633965Sjdp{
155733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
155833965Sjdp  struct debug_type *t;
155933965Sjdp  struct debug_array_type *a;
156033965Sjdp
156133965Sjdp  if (element_type == NULL || range_type == NULL)
156233965Sjdp    return DEBUG_TYPE_NULL;
156333965Sjdp
156433965Sjdp  t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
156533965Sjdp  if (t == NULL)
156633965Sjdp    return DEBUG_TYPE_NULL;
156733965Sjdp
156833965Sjdp  a = (struct debug_array_type *) xmalloc (sizeof *a);
156933965Sjdp  memset (a, 0, sizeof *a);
157033965Sjdp
157133965Sjdp  a->element_type = element_type;
157233965Sjdp  a->range_type = range_type;
157333965Sjdp  a->lower = lower;
157433965Sjdp  a->upper = upper;
157533965Sjdp  a->stringp = stringp;
157633965Sjdp
157733965Sjdp  t->u.karray = a;
157833965Sjdp
157933965Sjdp  return t;
158033965Sjdp}
158133965Sjdp
158233965Sjdp/* Make a set of a given type.  For example, a Pascal set type.  The
158333965Sjdp   boolean argument is true if this set is actually a bitstring, as in
158433965Sjdp   CHILL.  */
158533965Sjdp
158633965Sjdpdebug_type
158733965Sjdpdebug_make_set_type (handle, type, bitstringp)
158833965Sjdp     PTR handle;
158933965Sjdp     debug_type type;
159033965Sjdp     boolean bitstringp;
159133965Sjdp{
159233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
159333965Sjdp  struct debug_type *t;
159433965Sjdp  struct debug_set_type *s;
159533965Sjdp
159633965Sjdp  if (type == NULL)
159733965Sjdp    return DEBUG_TYPE_NULL;
159833965Sjdp
159933965Sjdp  t = debug_make_type (info, DEBUG_KIND_SET, 0);
160033965Sjdp  if (t == NULL)
160133965Sjdp    return DEBUG_TYPE_NULL;
160233965Sjdp
160333965Sjdp  s = (struct debug_set_type *) xmalloc (sizeof *s);
160433965Sjdp  memset (s, 0, sizeof *s);
160533965Sjdp
160633965Sjdp  s->type = type;
160733965Sjdp  s->bitstringp = bitstringp;
160833965Sjdp
160933965Sjdp  t->u.kset = s;
161033965Sjdp
161133965Sjdp  return t;
161233965Sjdp}
161333965Sjdp
161433965Sjdp/* Make a type for a pointer which is relative to an object.  The
161533965Sjdp   second argument is the type of the object to which the pointer is
161633965Sjdp   relative.  The third argument is the type that the pointer points
161733965Sjdp   to.  */
161833965Sjdp
161933965Sjdpdebug_type
162033965Sjdpdebug_make_offset_type (handle, base_type, target_type)
162133965Sjdp     PTR handle;
162233965Sjdp     debug_type base_type;
162333965Sjdp     debug_type target_type;
162433965Sjdp{
162533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
162633965Sjdp  struct debug_type *t;
162733965Sjdp  struct debug_offset_type *o;
162833965Sjdp
162933965Sjdp  if (base_type == NULL || target_type == NULL)
163033965Sjdp    return DEBUG_TYPE_NULL;
163133965Sjdp
163233965Sjdp  t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
163333965Sjdp  if (t == NULL)
163433965Sjdp    return DEBUG_TYPE_NULL;
163533965Sjdp
163633965Sjdp  o = (struct debug_offset_type *) xmalloc (sizeof *o);
163733965Sjdp  memset (o, 0, sizeof *o);
163833965Sjdp
163933965Sjdp  o->base_type = base_type;
164033965Sjdp  o->target_type = target_type;
164133965Sjdp
164233965Sjdp  t->u.koffset = o;
164333965Sjdp
164433965Sjdp  return t;
164533965Sjdp}
164633965Sjdp
164733965Sjdp/* Make a type for a method function.  The second argument is the
164833965Sjdp   return type, the third argument is the domain, and the fourth
164933965Sjdp   argument is a NULL terminated array of argument types.  */
165033965Sjdp
165133965Sjdpdebug_type
165233965Sjdpdebug_make_method_type (handle, return_type, domain_type, arg_types, varargs)
165333965Sjdp     PTR handle;
165433965Sjdp     debug_type return_type;
165533965Sjdp     debug_type domain_type;
165633965Sjdp     debug_type *arg_types;
165733965Sjdp     boolean varargs;
165833965Sjdp{
165933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
166033965Sjdp  struct debug_type *t;
166133965Sjdp  struct debug_method_type *m;
166233965Sjdp
166333965Sjdp  if (return_type == NULL)
166433965Sjdp    return DEBUG_TYPE_NULL;
166533965Sjdp
166633965Sjdp  t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
166733965Sjdp  if (t == NULL)
166833965Sjdp    return DEBUG_TYPE_NULL;
166933965Sjdp
167033965Sjdp  m = (struct debug_method_type *) xmalloc (sizeof *m);
167133965Sjdp  memset (m, 0, sizeof *m);
167233965Sjdp
167333965Sjdp  m->return_type = return_type;
167433965Sjdp  m->domain_type = domain_type;
167533965Sjdp  m->arg_types = arg_types;
167633965Sjdp  m->varargs = varargs;
167733965Sjdp
167833965Sjdp  t->u.kmethod = m;
167933965Sjdp
168033965Sjdp  return t;
168133965Sjdp}
168233965Sjdp
168333965Sjdp/* Make a const qualified version of a given type.  */
168433965Sjdp
168533965Sjdpdebug_type
168633965Sjdpdebug_make_const_type (handle, type)
168733965Sjdp     PTR handle;
168833965Sjdp     debug_type type;
168933965Sjdp{
169033965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
169133965Sjdp  struct debug_type *t;
169233965Sjdp
169333965Sjdp  if (type == NULL)
169433965Sjdp    return DEBUG_TYPE_NULL;
169533965Sjdp
169633965Sjdp  t = debug_make_type (info, DEBUG_KIND_CONST, 0);
169733965Sjdp  if (t == NULL)
169833965Sjdp    return DEBUG_TYPE_NULL;
169933965Sjdp
170033965Sjdp  t->u.kconst = type;
170133965Sjdp
170233965Sjdp  return t;
170333965Sjdp}
170433965Sjdp
170533965Sjdp/* Make a volatile qualified version of a given type.  */
170633965Sjdp
170733965Sjdpdebug_type
170833965Sjdpdebug_make_volatile_type (handle, type)
170933965Sjdp     PTR handle;
171033965Sjdp     debug_type type;
171133965Sjdp{
171233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
171333965Sjdp  struct debug_type *t;
171433965Sjdp
171533965Sjdp  if (type == NULL)
171633965Sjdp    return DEBUG_TYPE_NULL;
171733965Sjdp
171833965Sjdp  t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
171933965Sjdp  if (t == NULL)
172033965Sjdp    return DEBUG_TYPE_NULL;
172133965Sjdp
172233965Sjdp  t->u.kvolatile = type;
172333965Sjdp
172433965Sjdp  return t;
172533965Sjdp}
172633965Sjdp
172733965Sjdp/* Make an undefined tagged type.  For example, a struct which has
172833965Sjdp   been mentioned, but not defined.  */
172933965Sjdp
173033965Sjdpdebug_type
173133965Sjdpdebug_make_undefined_tagged_type (handle, name, kind)
173233965Sjdp     PTR handle;
173333965Sjdp     const char *name;
173433965Sjdp     enum debug_type_kind kind;
173533965Sjdp{
173633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
173733965Sjdp  struct debug_type *t;
173833965Sjdp
173933965Sjdp  if (name == NULL)
174033965Sjdp    return DEBUG_TYPE_NULL;
174133965Sjdp
174233965Sjdp  switch (kind)
174333965Sjdp    {
174433965Sjdp    case DEBUG_KIND_STRUCT:
174533965Sjdp    case DEBUG_KIND_UNION:
174633965Sjdp    case DEBUG_KIND_CLASS:
174733965Sjdp    case DEBUG_KIND_UNION_CLASS:
174833965Sjdp    case DEBUG_KIND_ENUM:
174933965Sjdp      break;
175033965Sjdp
175133965Sjdp    default:
175233965Sjdp      debug_error ("debug_make_undefined_type: unsupported kind");
175333965Sjdp      return DEBUG_TYPE_NULL;
175433965Sjdp    }
175533965Sjdp
175633965Sjdp  t = debug_make_type (info, kind, 0);
175733965Sjdp  if (t == NULL)
175833965Sjdp    return DEBUG_TYPE_NULL;
175933965Sjdp
176033965Sjdp  return debug_tag_type (handle, name, t);
176133965Sjdp}
176233965Sjdp
176333965Sjdp/* Make a base class for an object.  The second argument is the base
176433965Sjdp   class type.  The third argument is the bit position of this base
176533965Sjdp   class in the object (always 0 unless doing multiple inheritance).
176633965Sjdp   The fourth argument is whether this is a virtual class.  The fifth
176733965Sjdp   argument is the visibility of the base class.  */
176833965Sjdp
176933965Sjdp/*ARGSUSED*/
177033965Sjdpdebug_baseclass
177133965Sjdpdebug_make_baseclass (handle, type, bitpos, virtual, visibility)
177233965Sjdp     PTR handle;
177333965Sjdp     debug_type type;
177433965Sjdp     bfd_vma bitpos;
177533965Sjdp     boolean virtual;
177633965Sjdp     enum debug_visibility visibility;
177733965Sjdp{
177833965Sjdp  struct debug_baseclass *b;
177933965Sjdp
178033965Sjdp  b = (struct debug_baseclass *) xmalloc (sizeof *b);
178133965Sjdp  memset (b, 0, sizeof *b);
178233965Sjdp
178333965Sjdp  b->type = type;
178433965Sjdp  b->bitpos = bitpos;
178533965Sjdp  b->virtual = virtual;
178633965Sjdp  b->visibility = visibility;
178733965Sjdp
178833965Sjdp  return b;
178933965Sjdp}
179033965Sjdp
179133965Sjdp/* Make a field for a struct.  The second argument is the name.  The
179233965Sjdp   third argument is the type of the field.  The fourth argument is
179333965Sjdp   the bit position of the field.  The fifth argument is the size of
179433965Sjdp   the field (it may be zero).  The sixth argument is the visibility
179533965Sjdp   of the field.  */
179633965Sjdp
179733965Sjdp/*ARGSUSED*/
179833965Sjdpdebug_field
179933965Sjdpdebug_make_field (handle, name, type, bitpos, bitsize, visibility)
180033965Sjdp     PTR handle;
180133965Sjdp     const char *name;
180233965Sjdp     debug_type type;
180333965Sjdp     bfd_vma bitpos;
180433965Sjdp     bfd_vma bitsize;
180533965Sjdp     enum debug_visibility visibility;
180633965Sjdp{
180733965Sjdp  struct debug_field *f;
180833965Sjdp
180933965Sjdp  f = (struct debug_field *) xmalloc (sizeof *f);
181033965Sjdp  memset (f, 0, sizeof *f);
181133965Sjdp
181233965Sjdp  f->name = name;
181333965Sjdp  f->type = type;
181433965Sjdp  f->static_member = false;
181533965Sjdp  f->u.f.bitpos = bitpos;
181633965Sjdp  f->u.f.bitsize = bitsize;
181733965Sjdp  f->visibility = visibility;
181833965Sjdp
181933965Sjdp  return f;
182033965Sjdp}
182133965Sjdp
182233965Sjdp/* Make a static member of an object.  The second argument is the
182333965Sjdp   name.  The third argument is the type of the member.  The fourth
182433965Sjdp   argument is the physical name of the member (i.e., the name as a
182533965Sjdp   global variable).  The fifth argument is the visibility of the
182633965Sjdp   member.  */
182733965Sjdp
182833965Sjdp/*ARGSUSED*/
182933965Sjdpdebug_field
183033965Sjdpdebug_make_static_member (handle, name, type, physname, visibility)
183133965Sjdp     PTR handle;
183233965Sjdp     const char *name;
183333965Sjdp     debug_type type;
183433965Sjdp     const char *physname;
183533965Sjdp     enum debug_visibility visibility;
183633965Sjdp{
183733965Sjdp  struct debug_field *f;
183833965Sjdp
183933965Sjdp  f = (struct debug_field *) xmalloc (sizeof *f);
184033965Sjdp  memset (f, 0, sizeof *f);
184133965Sjdp
184233965Sjdp  f->name = name;
184333965Sjdp  f->type = type;
184433965Sjdp  f->static_member = true;
184533965Sjdp  f->u.s.physname = physname;
184633965Sjdp  f->visibility = visibility;
184733965Sjdp
184833965Sjdp  return f;
184933965Sjdp}
185033965Sjdp
185133965Sjdp/* Make a method.  The second argument is the name, and the third
185233965Sjdp   argument is a NULL terminated array of method variants.  */
185333965Sjdp
185433965Sjdp/*ARGSUSED*/
185533965Sjdpdebug_method
185633965Sjdpdebug_make_method (handle, name, variants)
185733965Sjdp     PTR handle;
185833965Sjdp     const char *name;
185933965Sjdp     debug_method_variant *variants;
186033965Sjdp{
186133965Sjdp  struct debug_method *m;
186233965Sjdp
186333965Sjdp  m = (struct debug_method *) xmalloc (sizeof *m);
186433965Sjdp  memset (m, 0, sizeof *m);
186533965Sjdp
186633965Sjdp  m->name = name;
186733965Sjdp  m->variants = variants;
186833965Sjdp
186933965Sjdp  return m;
187033965Sjdp}
187133965Sjdp
187233965Sjdp/* Make a method argument.  The second argument is the real name of
187333965Sjdp   the function.  The third argument is the type of the function.  The
187433965Sjdp   fourth argument is the visibility.  The fifth argument is whether
187533965Sjdp   this is a const function.  The sixth argument is whether this is a
187633965Sjdp   volatile function.  The seventh argument is the offset in the
187733965Sjdp   virtual function table, if any.  The eighth argument is the virtual
187833965Sjdp   function context.  FIXME: Are the const and volatile arguments
187933965Sjdp   necessary?  Could we just use debug_make_const_type?  */
188033965Sjdp
188133965Sjdp/*ARGSUSED*/
188233965Sjdpdebug_method_variant
188333965Sjdpdebug_make_method_variant (handle, physname, type, visibility, constp,
188433965Sjdp			   volatilep, voffset, context)
188533965Sjdp     PTR handle;
188633965Sjdp     const char *physname;
188733965Sjdp     debug_type type;
188833965Sjdp     enum debug_visibility visibility;
188933965Sjdp     boolean constp;
189033965Sjdp     boolean volatilep;
189133965Sjdp     bfd_vma voffset;
189233965Sjdp     debug_type context;
189333965Sjdp{
189433965Sjdp  struct debug_method_variant *m;
189533965Sjdp
189633965Sjdp  m = (struct debug_method_variant *) xmalloc (sizeof *m);
189733965Sjdp  memset (m, 0, sizeof *m);
189833965Sjdp
189933965Sjdp  m->physname = physname;
190033965Sjdp  m->type = type;
190133965Sjdp  m->visibility = visibility;
190233965Sjdp  m->constp = constp;
190333965Sjdp  m->volatilep = volatilep;
190433965Sjdp  m->voffset = voffset;
190533965Sjdp  m->context = context;
190633965Sjdp
190733965Sjdp  return m;
190833965Sjdp}
190933965Sjdp
191033965Sjdp/* Make a static method argument.  The arguments are the same as for
191133965Sjdp   debug_make_method_variant, except that the last two are omitted
191233965Sjdp   since a static method can not also be virtual.  */
191333965Sjdp
191433965Sjdpdebug_method_variant
191533965Sjdpdebug_make_static_method_variant (handle, physname, type, visibility,
191633965Sjdp				  constp, volatilep)
191733965Sjdp     PTR handle;
191833965Sjdp     const char *physname;
191933965Sjdp     debug_type type;
192033965Sjdp     enum debug_visibility visibility;
192133965Sjdp     boolean constp;
192233965Sjdp     boolean volatilep;
192333965Sjdp{
192433965Sjdp  struct debug_method_variant *m;
192533965Sjdp
192633965Sjdp  m = (struct debug_method_variant *) xmalloc (sizeof *m);
192733965Sjdp  memset (m, 0, sizeof *m);
192833965Sjdp
192933965Sjdp  m->physname = physname;
193033965Sjdp  m->type = type;
193133965Sjdp  m->visibility = visibility;
193233965Sjdp  m->constp = constp;
193333965Sjdp  m->volatilep = volatilep;
193433965Sjdp  m->voffset = VOFFSET_STATIC_METHOD;
193533965Sjdp
193633965Sjdp  return m;
193733965Sjdp}
193833965Sjdp
193933965Sjdp/* Name a type.  */
194033965Sjdp
194133965Sjdpdebug_type
194233965Sjdpdebug_name_type (handle, name, type)
194333965Sjdp     PTR handle;
194433965Sjdp     const char *name;
194533965Sjdp     debug_type type;
194633965Sjdp{
194733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
194833965Sjdp  struct debug_type *t;
194933965Sjdp  struct debug_named_type *n;
195033965Sjdp  struct debug_name *nm;
195133965Sjdp
195233965Sjdp  if (name == NULL || type == NULL)
195333965Sjdp    return DEBUG_TYPE_NULL;
195433965Sjdp
195533965Sjdp  if (info->current_unit == NULL
195633965Sjdp      || info->current_file == NULL)
195733965Sjdp    {
195833965Sjdp      debug_error ("debug_name_type: no current file");
195933965Sjdp      return false;
196033965Sjdp    }
196133965Sjdp
196233965Sjdp  t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
196333965Sjdp  if (t == NULL)
196433965Sjdp    return DEBUG_TYPE_NULL;
196533965Sjdp
196633965Sjdp  n = (struct debug_named_type *) xmalloc (sizeof *n);
196733965Sjdp  memset (n, 0, sizeof *n);
196833965Sjdp
196933965Sjdp  n->type = type;
197033965Sjdp
197133965Sjdp  t->u.knamed = n;
197233965Sjdp
197333965Sjdp  /* We always add the name to the global namespace.  This is probably
197433965Sjdp     wrong in some cases, but it seems to be right for stabs.  FIXME.  */
197533965Sjdp
197633965Sjdp  nm = debug_add_to_namespace (info, &info->current_file->globals, name,
197733965Sjdp			       DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
197833965Sjdp  if (nm == NULL)
197933965Sjdp    return false;
198033965Sjdp
198133965Sjdp  nm->u.type = t;
198233965Sjdp
198333965Sjdp  n->name = nm;
198433965Sjdp
198533965Sjdp  return t;
198633965Sjdp}
198733965Sjdp
198833965Sjdp/* Tag a type.  */
198933965Sjdp
199033965Sjdpdebug_type
199133965Sjdpdebug_tag_type (handle, name, type)
199233965Sjdp     PTR handle;
199333965Sjdp     const char *name;
199433965Sjdp     debug_type type;
199533965Sjdp{
199633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
199733965Sjdp  struct debug_type *t;
199833965Sjdp  struct debug_named_type *n;
199933965Sjdp  struct debug_name *nm;
200033965Sjdp
200133965Sjdp  if (name == NULL || type == NULL)
200233965Sjdp    return DEBUG_TYPE_NULL;
200333965Sjdp
200433965Sjdp  if (info->current_file == NULL)
200533965Sjdp    {
200633965Sjdp      debug_error ("debug_tag_type: no current file");
200733965Sjdp      return DEBUG_TYPE_NULL;
200833965Sjdp    }
200933965Sjdp
201033965Sjdp  if (type->kind == DEBUG_KIND_TAGGED)
201133965Sjdp    {
201233965Sjdp      if (strcmp (type->u.knamed->name->name, name) == 0)
201333965Sjdp	return type;
201433965Sjdp      debug_error ("debug_tag_type: extra tag attempted");
201533965Sjdp      return DEBUG_TYPE_NULL;
201633965Sjdp    }
201733965Sjdp
201833965Sjdp  t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
201933965Sjdp  if (t == NULL)
202033965Sjdp    return DEBUG_TYPE_NULL;
202133965Sjdp
202233965Sjdp  n = (struct debug_named_type *) xmalloc (sizeof *n);
202333965Sjdp  memset (n, 0, sizeof *n);
202433965Sjdp
202533965Sjdp  n->type = type;
202633965Sjdp
202733965Sjdp  t->u.knamed = n;
202833965Sjdp
202933965Sjdp  /* We keep a global namespace of tags for each compilation unit.  I
203033965Sjdp     don't know if that is the right thing to do.  */
203133965Sjdp
203233965Sjdp  nm = debug_add_to_namespace (info, &info->current_file->globals, name,
203333965Sjdp			       DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
203433965Sjdp  if (nm == NULL)
203533965Sjdp    return false;
203633965Sjdp
203733965Sjdp  nm->u.tag = t;
203833965Sjdp
203933965Sjdp  n->name = nm;
204033965Sjdp
204133965Sjdp  return t;
204233965Sjdp}
204333965Sjdp
204433965Sjdp/* Record the size of a given type.  */
204533965Sjdp
204633965Sjdp/*ARGSUSED*/
204733965Sjdpboolean
204833965Sjdpdebug_record_type_size (handle, type, size)
204933965Sjdp     PTR handle;
205033965Sjdp     debug_type type;
205133965Sjdp     unsigned int size;
205233965Sjdp{
205333965Sjdp  if (type->size != 0 && type->size != size)
205433965Sjdp    fprintf (stderr, "Warning: changing type size from %d to %d\n",
205533965Sjdp	     type->size, size);
205633965Sjdp
205733965Sjdp  type->size = size;
205833965Sjdp
205933965Sjdp  return true;
206033965Sjdp}
206133965Sjdp
206233965Sjdp/* Find a named type.  */
206333965Sjdp
206433965Sjdpdebug_type
206533965Sjdpdebug_find_named_type (handle, name)
206633965Sjdp     PTR handle;
206733965Sjdp     const char *name;
206833965Sjdp{
206933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
207033965Sjdp  struct debug_block *b;
207133965Sjdp  struct debug_file *f;
207233965Sjdp
207333965Sjdp  /* We only search the current compilation unit.  I don't know if
207433965Sjdp     this is right or not.  */
207533965Sjdp
207633965Sjdp  if (info->current_unit == NULL)
207733965Sjdp    {
207833965Sjdp      debug_error ("debug_find_named_type: no current compilation unit");
207933965Sjdp      return DEBUG_TYPE_NULL;
208033965Sjdp    }
208133965Sjdp
208233965Sjdp  for (b = info->current_block; b != NULL; b = b->parent)
208333965Sjdp    {
208433965Sjdp      if (b->locals != NULL)
208533965Sjdp	{
208633965Sjdp	  struct debug_name *n;
208733965Sjdp
208833965Sjdp	  for (n = b->locals->list; n != NULL; n = n->next)
208933965Sjdp	    {
209033965Sjdp	      if (n->kind == DEBUG_OBJECT_TYPE
209133965Sjdp		  && n->name[0] == name[0]
209233965Sjdp		  && strcmp (n->name, name) == 0)
209333965Sjdp		return n->u.type;
209433965Sjdp	    }
209533965Sjdp	}
209633965Sjdp    }
209733965Sjdp
209833965Sjdp  for (f = info->current_unit->files; f != NULL; f = f->next)
209933965Sjdp    {
210033965Sjdp      if (f->globals != NULL)
210133965Sjdp	{
210233965Sjdp	  struct debug_name *n;
210333965Sjdp
210433965Sjdp	  for (n = f->globals->list; n != NULL; n = n->next)
210533965Sjdp	    {
210633965Sjdp	      if (n->kind == DEBUG_OBJECT_TYPE
210733965Sjdp		  && n->name[0] == name[0]
210833965Sjdp		  && strcmp (n->name, name) == 0)
210933965Sjdp		return n->u.type;
211033965Sjdp	    }
211133965Sjdp	}
211233965Sjdp    }
211333965Sjdp
211433965Sjdp  return DEBUG_TYPE_NULL;
211533965Sjdp}
211633965Sjdp
211733965Sjdp/* Find a tagged type.  */
211833965Sjdp
211933965Sjdpdebug_type
212033965Sjdpdebug_find_tagged_type (handle, name, kind)
212133965Sjdp     PTR handle;
212233965Sjdp     const char *name;
212333965Sjdp     enum debug_type_kind kind;
212433965Sjdp{
212533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
212633965Sjdp  struct debug_unit *u;
212733965Sjdp
212833965Sjdp  /* We search the globals of all the compilation units.  I don't know
212933965Sjdp     if this is correct or not.  It would be easy to change.  */
213033965Sjdp
213133965Sjdp  for (u = info->units; u != NULL; u = u->next)
213233965Sjdp    {
213333965Sjdp      struct debug_file *f;
213433965Sjdp
213533965Sjdp      for (f = u->files; f != NULL; f = f->next)
213633965Sjdp	{
213733965Sjdp	  struct debug_name *n;
213833965Sjdp
213933965Sjdp	  if (f->globals != NULL)
214033965Sjdp	    {
214133965Sjdp	      for (n = f->globals->list; n != NULL; n = n->next)
214233965Sjdp		{
214333965Sjdp		  if (n->kind == DEBUG_OBJECT_TAG
214433965Sjdp		      && (kind == DEBUG_KIND_ILLEGAL
214533965Sjdp			  || n->u.tag->kind == kind)
214633965Sjdp		      && n->name[0] == name[0]
214733965Sjdp		      && strcmp (n->name, name) == 0)
214833965Sjdp		    return n->u.tag;
214933965Sjdp		}
215033965Sjdp	    }
215133965Sjdp	}
215233965Sjdp    }
215333965Sjdp
215433965Sjdp  return DEBUG_TYPE_NULL;
215533965Sjdp}
215633965Sjdp
215733965Sjdp/* Get a base type.  */
215833965Sjdp
215933965Sjdpstatic struct debug_type *
216033965Sjdpdebug_get_real_type (handle, type)
216133965Sjdp     PTR handle;
216233965Sjdp     debug_type type;
216333965Sjdp{
216433965Sjdp  switch (type->kind)
216533965Sjdp    {
216633965Sjdp    default:
216733965Sjdp      return type;
216833965Sjdp    case DEBUG_KIND_INDIRECT:
216933965Sjdp      if (*type->u.kindirect->slot != NULL)
217033965Sjdp	return debug_get_real_type (handle, *type->u.kindirect->slot);
217133965Sjdp      return type;
217233965Sjdp    case DEBUG_KIND_NAMED:
217333965Sjdp    case DEBUG_KIND_TAGGED:
217433965Sjdp      return debug_get_real_type (handle, type->u.knamed->type);
217533965Sjdp    }
217633965Sjdp  /*NOTREACHED*/
217733965Sjdp}
217833965Sjdp
217933965Sjdp/* Get the kind of a type.  */
218033965Sjdp
218133965Sjdpenum debug_type_kind
218233965Sjdpdebug_get_type_kind (handle, type)
218333965Sjdp     PTR handle;
218433965Sjdp     debug_type type;
218533965Sjdp{
218633965Sjdp  if (type == NULL)
218733965Sjdp    return DEBUG_KIND_ILLEGAL;
218833965Sjdp  type = debug_get_real_type (handle, type);
218933965Sjdp  return type->kind;
219033965Sjdp}
219133965Sjdp
219233965Sjdp/* Get the name of a type.  */
219333965Sjdp
219433965Sjdpconst char *
219533965Sjdpdebug_get_type_name (handle, type)
219633965Sjdp     PTR handle;
219733965Sjdp     debug_type type;
219833965Sjdp{
219933965Sjdp  if (type->kind == DEBUG_KIND_INDIRECT)
220033965Sjdp    {
220133965Sjdp      if (*type->u.kindirect->slot != NULL)
220233965Sjdp	return debug_get_type_name (handle, *type->u.kindirect->slot);
220333965Sjdp      return type->u.kindirect->tag;
220433965Sjdp    }
220533965Sjdp  if (type->kind == DEBUG_KIND_NAMED
220633965Sjdp      || type->kind == DEBUG_KIND_TAGGED)
220733965Sjdp    return type->u.knamed->name->name;
220833965Sjdp  return NULL;
220933965Sjdp}
221033965Sjdp
221133965Sjdp/* Get the size of a type.  */
221233965Sjdp
221333965Sjdpbfd_vma
221433965Sjdpdebug_get_type_size (handle, type)
221533965Sjdp     PTR handle;
221633965Sjdp     debug_type type;
221733965Sjdp{
221833965Sjdp  if (type == NULL)
221933965Sjdp    return 0;
222033965Sjdp
222133965Sjdp  /* We don't call debug_get_real_type, because somebody might have
222233965Sjdp     called debug_record_type_size on a named or indirect type.  */
222333965Sjdp
222433965Sjdp  if (type->size != 0)
222533965Sjdp    return type->size;
222633965Sjdp
222733965Sjdp  switch (type->kind)
222833965Sjdp    {
222933965Sjdp    default:
223033965Sjdp      return 0;
223133965Sjdp    case DEBUG_KIND_INDIRECT:
223233965Sjdp      if (*type->u.kindirect->slot != NULL)
223333965Sjdp	return debug_get_type_size (handle, *type->u.kindirect->slot);
223433965Sjdp      return 0;
223533965Sjdp    case DEBUG_KIND_NAMED:
223633965Sjdp    case DEBUG_KIND_TAGGED:
223733965Sjdp      return debug_get_type_size (handle, type->u.knamed->type);
223833965Sjdp    }
223933965Sjdp  /*NOTREACHED*/
224033965Sjdp}
224133965Sjdp
224233965Sjdp/* Get the return type of a function or method type.  */
224333965Sjdp
224433965Sjdpdebug_type
224533965Sjdpdebug_get_return_type (handle, type)
224633965Sjdp     PTR handle;
224733965Sjdp     debug_type type;
224833965Sjdp{
224933965Sjdp  if (type == NULL)
225033965Sjdp    return DEBUG_TYPE_NULL;
225133965Sjdp  type = debug_get_real_type (handle, type);
225233965Sjdp  switch (type->kind)
225333965Sjdp    {
225433965Sjdp    default:
225533965Sjdp      return DEBUG_TYPE_NULL;
225633965Sjdp    case DEBUG_KIND_FUNCTION:
225733965Sjdp      return type->u.kfunction->return_type;
225833965Sjdp    case DEBUG_KIND_METHOD:
225933965Sjdp      return type->u.kmethod->return_type;
226033965Sjdp    }
226133965Sjdp  /*NOTREACHED*/
226233965Sjdp}
226333965Sjdp
226433965Sjdp/* Get the parameter types of a function or method type (except that
226533965Sjdp   we don't currently store the parameter types of a function).  */
226633965Sjdp
226733965Sjdpconst debug_type *
226833965Sjdpdebug_get_parameter_types (handle, type, pvarargs)
226933965Sjdp     PTR handle;
227033965Sjdp     debug_type type;
227133965Sjdp     boolean *pvarargs;
227233965Sjdp{
227333965Sjdp  if (type == NULL)
227433965Sjdp    return NULL;
227533965Sjdp  type = debug_get_real_type (handle, type);
227633965Sjdp  switch (type->kind)
227733965Sjdp    {
227833965Sjdp    default:
227933965Sjdp      return NULL;
228033965Sjdp    case DEBUG_KIND_FUNCTION:
228133965Sjdp      *pvarargs = type->u.kfunction->varargs;
228233965Sjdp      return type->u.kfunction->arg_types;
228333965Sjdp    case DEBUG_KIND_METHOD:
228433965Sjdp      *pvarargs = type->u.kmethod->varargs;
228533965Sjdp      return type->u.kmethod->arg_types;
228633965Sjdp    }
228733965Sjdp  /*NOTREACHED*/
228833965Sjdp}
228933965Sjdp
229033965Sjdp/* Get the target type of a type.  */
229133965Sjdp
229233965Sjdpdebug_type
229333965Sjdpdebug_get_target_type (handle, type)
229433965Sjdp     PTR handle;
229533965Sjdp     debug_type type;
229633965Sjdp{
229733965Sjdp  if (type == NULL)
229833965Sjdp    return NULL;
229933965Sjdp  type = debug_get_real_type (handle, type);
230033965Sjdp  switch (type->kind)
230133965Sjdp    {
230233965Sjdp    default:
230333965Sjdp      return NULL;
230433965Sjdp    case DEBUG_KIND_POINTER:
230533965Sjdp      return type->u.kpointer;
230633965Sjdp    case DEBUG_KIND_REFERENCE:
230733965Sjdp      return type->u.kreference;
230833965Sjdp    case DEBUG_KIND_CONST:
230933965Sjdp      return type->u.kconst;
231033965Sjdp    case DEBUG_KIND_VOLATILE:
231133965Sjdp      return type->u.kvolatile;
231233965Sjdp    }
231333965Sjdp  /*NOTREACHED*/
231433965Sjdp}
231533965Sjdp
231633965Sjdp/* Get the NULL terminated array of fields for a struct, union, or
231733965Sjdp   class.  */
231833965Sjdp
231933965Sjdpconst debug_field *
232033965Sjdpdebug_get_fields (handle, type)
232133965Sjdp     PTR handle;
232233965Sjdp     debug_type type;
232333965Sjdp{
232433965Sjdp  if (type == NULL)
232533965Sjdp    return NULL;
232633965Sjdp  type = debug_get_real_type (handle, type);
232733965Sjdp  switch (type->kind)
232833965Sjdp    {
232933965Sjdp    default:
233033965Sjdp      return NULL;
233133965Sjdp    case DEBUG_KIND_STRUCT:
233233965Sjdp    case DEBUG_KIND_UNION:
233333965Sjdp    case DEBUG_KIND_CLASS:
233433965Sjdp    case DEBUG_KIND_UNION_CLASS:
233533965Sjdp      return type->u.kclass->fields;
233633965Sjdp    }
233733965Sjdp  /*NOTREACHED*/
233833965Sjdp}
233933965Sjdp
234033965Sjdp/* Get the type of a field.  */
234133965Sjdp
234233965Sjdp/*ARGSUSED*/
234333965Sjdpdebug_type
234433965Sjdpdebug_get_field_type (handle, field)
234533965Sjdp     PTR handle;
234633965Sjdp     debug_field field;
234733965Sjdp{
234833965Sjdp  if (field == NULL)
234933965Sjdp    return NULL;
235033965Sjdp  return field->type;
235133965Sjdp}
235233965Sjdp
235333965Sjdp/* Get the name of a field.  */
235433965Sjdp
235533965Sjdp/*ARGSUSED*/
235633965Sjdpconst char *
235733965Sjdpdebug_get_field_name (handle, field)
235833965Sjdp     PTR handle;
235933965Sjdp     debug_field field;
236033965Sjdp{
236133965Sjdp  if (field == NULL)
236233965Sjdp    return NULL;
236333965Sjdp  return field->name;
236433965Sjdp}
236533965Sjdp
236633965Sjdp/* Get the bit position of a field.  */
236733965Sjdp
236833965Sjdp/*ARGSUSED*/
236933965Sjdpbfd_vma
237033965Sjdpdebug_get_field_bitpos (handle, field)
237133965Sjdp     PTR handle;
237233965Sjdp     debug_field field;
237333965Sjdp{
237433965Sjdp  if (field == NULL || field->static_member)
237533965Sjdp    return (bfd_vma) -1;
237633965Sjdp  return field->u.f.bitpos;
237733965Sjdp}
237833965Sjdp
237933965Sjdp/* Get the bit size of a field.  */
238033965Sjdp
238133965Sjdp/*ARGSUSED*/
238233965Sjdpbfd_vma
238333965Sjdpdebug_get_field_bitsize (handle, field)
238433965Sjdp     PTR handle;
238533965Sjdp     debug_field field;
238633965Sjdp{
238733965Sjdp  if (field == NULL || field->static_member)
238833965Sjdp    return (bfd_vma) -1;
238933965Sjdp  return field->u.f.bitsize;
239033965Sjdp}
239133965Sjdp
239233965Sjdp/* Get the visibility of a field.  */
239333965Sjdp
239433965Sjdp/*ARGSUSED*/
239533965Sjdpenum debug_visibility
239633965Sjdpdebug_get_field_visibility (handle, field)
239733965Sjdp     PTR handle;
239833965Sjdp     debug_field field;
239933965Sjdp{
240033965Sjdp  if (field == NULL)
240133965Sjdp    return DEBUG_VISIBILITY_IGNORE;
240233965Sjdp  return field->visibility;
240333965Sjdp}
240433965Sjdp
240533965Sjdp/* Get the physical name of a field.  */
240633965Sjdp
240733965Sjdpconst char *
240833965Sjdpdebug_get_field_physname (handle, field)
240933965Sjdp     PTR handle;
241033965Sjdp     debug_field field;
241133965Sjdp{
241233965Sjdp  if (field == NULL || ! field->static_member)
241333965Sjdp    return NULL;
241433965Sjdp  return field->u.s.physname;
241533965Sjdp}
241633965Sjdp
241733965Sjdp/* Write out the debugging information.  This is given a handle to
241833965Sjdp   debugging information, and a set of function pointers to call.  */
241933965Sjdp
242033965Sjdpboolean
242133965Sjdpdebug_write (handle, fns, fhandle)
242233965Sjdp     PTR handle;
242333965Sjdp     const struct debug_write_fns *fns;
242433965Sjdp     PTR fhandle;
242533965Sjdp{
242633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
242733965Sjdp  struct debug_unit *u;
242833965Sjdp
242933965Sjdp  /* We use a mark to tell whether we have already written out a
243033965Sjdp     particular name.  We use an integer, so that we don't have to
243133965Sjdp     clear the mark fields if we happen to write out the same
243233965Sjdp     information more than once.  */
243333965Sjdp  ++info->mark;
243433965Sjdp
243533965Sjdp  /* The base_id field holds an ID value which will never be used, so
243633965Sjdp     that we can tell whether we have assigned an ID during this call
243733965Sjdp     to debug_write.  */
243833965Sjdp  info->base_id = info->class_id;
243933965Sjdp
244033965Sjdp  /* We keep a linked list of classes for which was have assigned ID's
244133965Sjdp     during this call to debug_write.  */
244233965Sjdp  info->id_list = NULL;
244333965Sjdp
244433965Sjdp  for (u = info->units; u != NULL; u = u->next)
244533965Sjdp    {
244633965Sjdp      struct debug_file *f;
244733965Sjdp      boolean first_file;
244833965Sjdp
244933965Sjdp      info->current_write_lineno = u->linenos;
245033965Sjdp      info->current_write_lineno_index = 0;
245133965Sjdp
245233965Sjdp      if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
245333965Sjdp	return false;
245433965Sjdp
245533965Sjdp      first_file = true;
245633965Sjdp      for (f = u->files; f != NULL; f = f->next)
245733965Sjdp	{
245833965Sjdp	  struct debug_name *n;
245933965Sjdp
246033965Sjdp	  if (first_file)
246133965Sjdp	    first_file = false;
246233965Sjdp	  else
246333965Sjdp	    {
246433965Sjdp	      if (! (*fns->start_source) (fhandle, f->filename))
246533965Sjdp		return false;
246633965Sjdp	    }
246733965Sjdp
246833965Sjdp	  if (f->globals != NULL)
246933965Sjdp	    {
247033965Sjdp	      for (n = f->globals->list; n != NULL; n = n->next)
247133965Sjdp		{
247233965Sjdp		  if (! debug_write_name (info, fns, fhandle, n))
247333965Sjdp		    return false;
247433965Sjdp		}
247533965Sjdp	    }
247633965Sjdp	}
247733965Sjdp
247833965Sjdp      /* Output any line number information which hasn't already been
247933965Sjdp         handled.  */
248033965Sjdp      if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
248133965Sjdp	return false;
248233965Sjdp    }
248333965Sjdp
248433965Sjdp  return true;
248533965Sjdp}
248633965Sjdp
248733965Sjdp/* Write out an element in a namespace.  */
248833965Sjdp
248933965Sjdpstatic boolean
249033965Sjdpdebug_write_name (info, fns, fhandle, n)
249133965Sjdp     struct debug_handle *info;
249233965Sjdp     const struct debug_write_fns *fns;
249333965Sjdp     PTR fhandle;
249433965Sjdp     struct debug_name *n;
249533965Sjdp{
249633965Sjdp  switch (n->kind)
249733965Sjdp    {
249833965Sjdp    case DEBUG_OBJECT_TYPE:
249933965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.type, n)
250033965Sjdp	  || ! (*fns->typdef) (fhandle, n->name))
250133965Sjdp	return false;
250233965Sjdp      return true;
250333965Sjdp    case DEBUG_OBJECT_TAG:
250433965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
250533965Sjdp	return false;
250633965Sjdp      return (*fns->tag) (fhandle, n->name);
250733965Sjdp    case DEBUG_OBJECT_VARIABLE:
250833965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
250933965Sjdp			      (struct debug_name *) NULL))
251033965Sjdp	return false;
251133965Sjdp      return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
251233965Sjdp			       n->u.variable->val);
251333965Sjdp    case DEBUG_OBJECT_FUNCTION:
251433965Sjdp      return debug_write_function (info, fns, fhandle, n->name,
251533965Sjdp				   n->linkage, n->u.function);
251633965Sjdp    case DEBUG_OBJECT_INT_CONSTANT:
251733965Sjdp      return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
251833965Sjdp    case DEBUG_OBJECT_FLOAT_CONSTANT:
251933965Sjdp      return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
252033965Sjdp    case DEBUG_OBJECT_TYPED_CONSTANT:
252133965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
252233965Sjdp			      (struct debug_name *) NULL))
252333965Sjdp	return false;
252433965Sjdp      return (*fns->typed_constant) (fhandle, n->name,
252533965Sjdp				     n->u.typed_constant->val);
252633965Sjdp    default:
252733965Sjdp      abort ();
252833965Sjdp      return false;
252933965Sjdp    }
253033965Sjdp  /*NOTREACHED*/
253133965Sjdp}
253233965Sjdp
253333965Sjdp/* Write out a type.  If the type is DEBUG_KIND_NAMED or
253433965Sjdp   DEBUG_KIND_TAGGED, then the name argument is the name for which we
253533965Sjdp   are about to call typedef or tag.  If the type is anything else,
253633965Sjdp   then the name argument is a tag from a DEBUG_KIND_TAGGED type which
253733965Sjdp   points to this one.  */
253833965Sjdp
253933965Sjdpstatic boolean
254033965Sjdpdebug_write_type (info, fns, fhandle, type, name)
254133965Sjdp     struct debug_handle *info;
254233965Sjdp     const struct debug_write_fns *fns;
254333965Sjdp     PTR fhandle;
254433965Sjdp     struct debug_type *type;
254533965Sjdp     struct debug_name *name;
254633965Sjdp{
254733965Sjdp  unsigned int i;
254833965Sjdp  int is;
254933965Sjdp  const char *tag;
255033965Sjdp
255133965Sjdp  /* If we have a name for this type, just output it.  We only output
255233965Sjdp     typedef names after they have been defined.  We output type tags
255333965Sjdp     whenever we are not actually defining them.  */
255433965Sjdp  if ((type->kind == DEBUG_KIND_NAMED
255533965Sjdp       || type->kind == DEBUG_KIND_TAGGED)
255633965Sjdp      && (type->u.knamed->name->mark == info->mark
255733965Sjdp	  || (type->kind == DEBUG_KIND_TAGGED
255833965Sjdp	      && type->u.knamed->name != name)))
255933965Sjdp    {
256033965Sjdp      if (type->kind == DEBUG_KIND_NAMED)
256133965Sjdp	return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
256233965Sjdp      else
256333965Sjdp	{
256433965Sjdp	  struct debug_type *real;
256533965Sjdp	  unsigned int id;
256633965Sjdp
256733965Sjdp	  real = debug_get_real_type ((PTR) info, type);
256833965Sjdp	  id = 0;
256933965Sjdp	  if ((real->kind == DEBUG_KIND_STRUCT
257033965Sjdp	       || real->kind == DEBUG_KIND_UNION
257133965Sjdp	       || real->kind == DEBUG_KIND_CLASS
257233965Sjdp	       || real->kind == DEBUG_KIND_UNION_CLASS)
257333965Sjdp	      && real->u.kclass != NULL)
257433965Sjdp	    {
257533965Sjdp	      if (real->u.kclass->id <= info->base_id)
257633965Sjdp		{
257733965Sjdp		  if (! debug_set_class_id (info,
257833965Sjdp					    type->u.knamed->name->name,
257933965Sjdp					    real))
258033965Sjdp		    return false;
258133965Sjdp		}
258233965Sjdp	      id = real->u.kclass->id;
258333965Sjdp	    }
258433965Sjdp
258533965Sjdp	  return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
258633965Sjdp				   real->kind);
258733965Sjdp	}
258833965Sjdp    }
258933965Sjdp
259033965Sjdp  /* Mark the name after we have already looked for a known name, so
259133965Sjdp     that we don't just define a type in terms of itself.  We need to
259233965Sjdp     mark the name here so that a struct containing a pointer to
259333965Sjdp     itself will work.  */
259433965Sjdp  if (name != NULL)
259533965Sjdp    name->mark = info->mark;
259633965Sjdp
259733965Sjdp  tag = NULL;
259833965Sjdp  if (name != NULL
259933965Sjdp      && type->kind != DEBUG_KIND_NAMED
260033965Sjdp      && type->kind != DEBUG_KIND_TAGGED)
260133965Sjdp    {
260233965Sjdp      assert (name->kind == DEBUG_OBJECT_TAG);
260333965Sjdp      tag = name->name;
260433965Sjdp    }
260533965Sjdp
260633965Sjdp  switch (type->kind)
260733965Sjdp    {
260833965Sjdp    case DEBUG_KIND_ILLEGAL:
260933965Sjdp      debug_error ("debug_write_type: illegal type encountered");
261033965Sjdp      return false;
261133965Sjdp    case DEBUG_KIND_INDIRECT:
261233965Sjdp      if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
261333965Sjdp	return (*fns->empty_type) (fhandle);
261433965Sjdp      return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
261533965Sjdp			       name);
261633965Sjdp    case DEBUG_KIND_VOID:
261733965Sjdp      return (*fns->void_type) (fhandle);
261833965Sjdp    case DEBUG_KIND_INT:
261933965Sjdp      return (*fns->int_type) (fhandle, type->size, type->u.kint);
262033965Sjdp    case DEBUG_KIND_FLOAT:
262133965Sjdp      return (*fns->float_type) (fhandle, type->size);
262233965Sjdp    case DEBUG_KIND_COMPLEX:
262333965Sjdp      return (*fns->complex_type) (fhandle, type->size);
262433965Sjdp    case DEBUG_KIND_BOOL:
262533965Sjdp      return (*fns->bool_type) (fhandle, type->size);
262633965Sjdp    case DEBUG_KIND_STRUCT:
262733965Sjdp    case DEBUG_KIND_UNION:
262833965Sjdp      if (type->u.kclass != NULL)
262933965Sjdp	{
263033965Sjdp	  if (type->u.kclass->id <= info->base_id)
263133965Sjdp	    {
263233965Sjdp	      if (! debug_set_class_id (info, tag, type))
263333965Sjdp		return false;
263433965Sjdp	    }
263533965Sjdp
263633965Sjdp	  if (info->mark == type->u.kclass->mark)
263733965Sjdp	    {
263833965Sjdp	      /* We are currently outputting this struct, or we have
263933965Sjdp		 already output it.  I don't know if this can happen,
264033965Sjdp		 but it can happen for a class.  */
264133965Sjdp	      assert (type->u.kclass->id > info->base_id);
264233965Sjdp	      return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
264333965Sjdp				       type->kind);
264433965Sjdp	    }
264533965Sjdp	  type->u.kclass->mark = info->mark;
264633965Sjdp	}
264733965Sjdp
264833965Sjdp      if (! (*fns->start_struct_type) (fhandle, tag,
264933965Sjdp				       (type->u.kclass != NULL
265033965Sjdp					? type->u.kclass->id
265133965Sjdp					: 0),
265233965Sjdp				       type->kind == DEBUG_KIND_STRUCT,
265333965Sjdp				       type->size))
265433965Sjdp	return false;
265533965Sjdp      if (type->u.kclass != NULL
265633965Sjdp	  && type->u.kclass->fields != NULL)
265733965Sjdp	{
265833965Sjdp	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
265933965Sjdp	    {
266033965Sjdp	      struct debug_field *f;
266133965Sjdp
266233965Sjdp	      f = type->u.kclass->fields[i];
266333965Sjdp	      if (! debug_write_type (info, fns, fhandle, f->type,
266433965Sjdp				      (struct debug_name *) NULL)
266533965Sjdp		  || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
266633965Sjdp					     f->u.f.bitsize, f->visibility))
266733965Sjdp		return false;
266833965Sjdp	    }
266933965Sjdp	}
267033965Sjdp      return (*fns->end_struct_type) (fhandle);
267133965Sjdp    case DEBUG_KIND_CLASS:
267233965Sjdp    case DEBUG_KIND_UNION_CLASS:
267333965Sjdp      return debug_write_class_type (info, fns, fhandle, type, tag);
267433965Sjdp    case DEBUG_KIND_ENUM:
267533965Sjdp      if (type->u.kenum == NULL)
267633965Sjdp	return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
267733965Sjdp				  (bfd_signed_vma *) NULL);
267833965Sjdp      return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
267933965Sjdp				type->u.kenum->values);
268033965Sjdp    case DEBUG_KIND_POINTER:
268133965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
268233965Sjdp			      (struct debug_name *) NULL))
268333965Sjdp	return false;
268433965Sjdp      return (*fns->pointer_type) (fhandle);
268533965Sjdp    case DEBUG_KIND_FUNCTION:
268633965Sjdp      if (! debug_write_type (info, fns, fhandle,
268733965Sjdp			      type->u.kfunction->return_type,
268833965Sjdp			      (struct debug_name *) NULL))
268933965Sjdp	return false;
269033965Sjdp      if (type->u.kfunction->arg_types == NULL)
269133965Sjdp	is = -1;
269233965Sjdp      else
269333965Sjdp	{
269433965Sjdp	  for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
269533965Sjdp	    if (! debug_write_type (info, fns, fhandle,
269633965Sjdp				    type->u.kfunction->arg_types[is],
269733965Sjdp				    (struct debug_name *) NULL))
269833965Sjdp	      return false;
269933965Sjdp	}
270033965Sjdp      return (*fns->function_type) (fhandle, is,
270133965Sjdp				    type->u.kfunction->varargs);
270233965Sjdp    case DEBUG_KIND_REFERENCE:
270333965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kreference,
270433965Sjdp			      (struct debug_name *) NULL))
270533965Sjdp	return false;
270633965Sjdp      return (*fns->reference_type) (fhandle);
270733965Sjdp    case DEBUG_KIND_RANGE:
270833965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
270933965Sjdp			      (struct debug_name *) NULL))
271033965Sjdp	return false;
271133965Sjdp      return (*fns->range_type) (fhandle, type->u.krange->lower,
271233965Sjdp				 type->u.krange->upper);
271333965Sjdp    case DEBUG_KIND_ARRAY:
271433965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
271533965Sjdp			      (struct debug_name *) NULL)
271633965Sjdp	  || ! debug_write_type (info, fns, fhandle,
271733965Sjdp				 type->u.karray->range_type,
271833965Sjdp				 (struct debug_name *) NULL))
271933965Sjdp	return false;
272033965Sjdp      return (*fns->array_type) (fhandle, type->u.karray->lower,
272133965Sjdp				 type->u.karray->upper,
272233965Sjdp				 type->u.karray->stringp);
272333965Sjdp    case DEBUG_KIND_SET:
272433965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
272533965Sjdp			      (struct debug_name *) NULL))
272633965Sjdp	return false;
272733965Sjdp      return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
272833965Sjdp    case DEBUG_KIND_OFFSET:
272933965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
273033965Sjdp			      (struct debug_name *) NULL)
273133965Sjdp	  || ! debug_write_type (info, fns, fhandle,
273233965Sjdp				 type->u.koffset->target_type,
273333965Sjdp				 (struct debug_name *) NULL))
273433965Sjdp	return false;
273533965Sjdp      return (*fns->offset_type) (fhandle);
273633965Sjdp    case DEBUG_KIND_METHOD:
273733965Sjdp      if (! debug_write_type (info, fns, fhandle,
273833965Sjdp			      type->u.kmethod->return_type,
273933965Sjdp			      (struct debug_name *) NULL))
274033965Sjdp	return false;
274133965Sjdp      if (type->u.kmethod->arg_types == NULL)
274233965Sjdp	is = -1;
274333965Sjdp      else
274433965Sjdp	{
274533965Sjdp	  for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
274633965Sjdp	    if (! debug_write_type (info, fns, fhandle,
274733965Sjdp				    type->u.kmethod->arg_types[is],
274833965Sjdp				    (struct debug_name *) NULL))
274933965Sjdp	      return false;
275033965Sjdp	}
275133965Sjdp      if (type->u.kmethod->domain_type != NULL)
275233965Sjdp	{
275333965Sjdp	  if (! debug_write_type (info, fns, fhandle,
275433965Sjdp				  type->u.kmethod->domain_type,
275533965Sjdp				  (struct debug_name *) NULL))
275633965Sjdp	    return false;
275733965Sjdp	}
275833965Sjdp      return (*fns->method_type) (fhandle,
275933965Sjdp				  type->u.kmethod->domain_type != NULL,
276033965Sjdp				  is,
276133965Sjdp				  type->u.kmethod->varargs);
276233965Sjdp    case DEBUG_KIND_CONST:
276333965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kconst,
276433965Sjdp			      (struct debug_name *) NULL))
276533965Sjdp	return false;
276633965Sjdp      return (*fns->const_type) (fhandle);
276733965Sjdp    case DEBUG_KIND_VOLATILE:
276833965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
276933965Sjdp			      (struct debug_name *) NULL))
277033965Sjdp	return false;
277133965Sjdp      return (*fns->volatile_type) (fhandle);
277233965Sjdp    case DEBUG_KIND_NAMED:
277333965Sjdp      return debug_write_type (info, fns, fhandle, type->u.knamed->type,
277433965Sjdp			       (struct debug_name *) NULL);
277533965Sjdp    case DEBUG_KIND_TAGGED:
277633965Sjdp      return debug_write_type (info, fns, fhandle, type->u.knamed->type,
277733965Sjdp			       type->u.knamed->name);
277833965Sjdp    default:
277933965Sjdp      abort ();
278033965Sjdp      return false;
278133965Sjdp    }
278233965Sjdp}
278333965Sjdp
278433965Sjdp/* Write out a class type.  */
278533965Sjdp
278633965Sjdpstatic boolean
278733965Sjdpdebug_write_class_type (info, fns, fhandle, type, tag)
278833965Sjdp     struct debug_handle *info;
278933965Sjdp     const struct debug_write_fns *fns;
279033965Sjdp     PTR fhandle;
279133965Sjdp     struct debug_type *type;
279233965Sjdp     const char *tag;
279333965Sjdp{
279433965Sjdp  unsigned int i;
279533965Sjdp  unsigned int id;
279633965Sjdp  struct debug_type *vptrbase;
279733965Sjdp
279833965Sjdp  if (type->u.kclass == NULL)
279933965Sjdp    {
280033965Sjdp      id = 0;
280133965Sjdp      vptrbase = NULL;
280233965Sjdp    }
280333965Sjdp  else
280433965Sjdp    {
280533965Sjdp      if (type->u.kclass->id <= info->base_id)
280633965Sjdp	{
280733965Sjdp	  if (! debug_set_class_id (info, tag, type))
280833965Sjdp	    return false;
280933965Sjdp	}
281033965Sjdp
281133965Sjdp      if (info->mark == type->u.kclass->mark)
281233965Sjdp	{
281333965Sjdp	  /* We are currently outputting this class, or we have
281433965Sjdp	     already output it.  This can happen when there are
281533965Sjdp	     methods for an anonymous class.  */
281633965Sjdp	  assert (type->u.kclass->id > info->base_id);
281733965Sjdp	  return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
281833965Sjdp				   type->kind);
281933965Sjdp	}
282033965Sjdp      type->u.kclass->mark = info->mark;
282133965Sjdp      id = type->u.kclass->id;
282233965Sjdp
282333965Sjdp      vptrbase = type->u.kclass->vptrbase;
282433965Sjdp      if (vptrbase != NULL && vptrbase != type)
282533965Sjdp	{
282633965Sjdp	  if (! debug_write_type (info, fns, fhandle, vptrbase,
282733965Sjdp				  (struct debug_name *) NULL))
282833965Sjdp	    return false;
282933965Sjdp	}
283033965Sjdp    }
283133965Sjdp
283233965Sjdp  if (! (*fns->start_class_type) (fhandle, tag, id,
283333965Sjdp				  type->kind == DEBUG_KIND_CLASS,
283433965Sjdp				  type->size,
283533965Sjdp				  vptrbase != NULL,
283633965Sjdp				  vptrbase == type))
283733965Sjdp    return false;
283833965Sjdp
283933965Sjdp  if (type->u.kclass != NULL)
284033965Sjdp    {
284133965Sjdp      if (type->u.kclass->fields != NULL)
284233965Sjdp	{
284333965Sjdp	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
284433965Sjdp	    {
284533965Sjdp	      struct debug_field *f;
284633965Sjdp
284733965Sjdp	      f = type->u.kclass->fields[i];
284833965Sjdp	      if (! debug_write_type (info, fns, fhandle, f->type,
284933965Sjdp				      (struct debug_name *) NULL))
285033965Sjdp		return false;
285133965Sjdp	      if (f->static_member)
285233965Sjdp		{
285333965Sjdp		  if (! (*fns->class_static_member) (fhandle, f->name,
285433965Sjdp						     f->u.s.physname,
285533965Sjdp						     f->visibility))
285633965Sjdp		    return false;
285733965Sjdp		}
285833965Sjdp	      else
285933965Sjdp		{
286033965Sjdp		  if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
286133965Sjdp					      f->u.f.bitsize, f->visibility))
286233965Sjdp		    return false;
286333965Sjdp		}
286433965Sjdp	    }
286533965Sjdp	}
286633965Sjdp
286733965Sjdp      if (type->u.kclass->baseclasses != NULL)
286833965Sjdp	{
286933965Sjdp	  for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
287033965Sjdp	    {
287133965Sjdp	      struct debug_baseclass *b;
287233965Sjdp
287333965Sjdp	      b = type->u.kclass->baseclasses[i];
287433965Sjdp	      if (! debug_write_type (info, fns, fhandle, b->type,
287533965Sjdp				      (struct debug_name *) NULL))
287633965Sjdp		return false;
287733965Sjdp	      if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
287833965Sjdp					     b->visibility))
287933965Sjdp		return false;
288033965Sjdp	    }
288133965Sjdp	}
288233965Sjdp
288333965Sjdp      if (type->u.kclass->methods != NULL)
288433965Sjdp	{
288533965Sjdp	  for (i = 0; type->u.kclass->methods[i] != NULL; i++)
288633965Sjdp	    {
288733965Sjdp	      struct debug_method *m;
288833965Sjdp	      unsigned int j;
288933965Sjdp
289033965Sjdp	      m = type->u.kclass->methods[i];
289133965Sjdp	      if (! (*fns->class_start_method) (fhandle, m->name))
289233965Sjdp		return false;
289333965Sjdp	      for (j = 0; m->variants[j] != NULL; j++)
289433965Sjdp		{
289533965Sjdp		  struct debug_method_variant *v;
289633965Sjdp
289733965Sjdp		  v = m->variants[j];
289833965Sjdp		  if (v->context != NULL)
289933965Sjdp		    {
290033965Sjdp		      if (! debug_write_type (info, fns, fhandle, v->context,
290133965Sjdp					      (struct debug_name *) NULL))
290233965Sjdp			return false;
290333965Sjdp		    }
290433965Sjdp		  if (! debug_write_type (info, fns, fhandle, v->type,
290533965Sjdp					  (struct debug_name *) NULL))
290633965Sjdp		    return false;
290733965Sjdp		  if (v->voffset != VOFFSET_STATIC_METHOD)
290833965Sjdp		    {
290933965Sjdp		      if (! (*fns->class_method_variant) (fhandle, v->physname,
291033965Sjdp							  v->visibility,
291133965Sjdp							  v->constp,
291233965Sjdp							  v->volatilep,
291333965Sjdp							  v->voffset,
291433965Sjdp							  v->context != NULL))
291533965Sjdp			return false;
291633965Sjdp		    }
291733965Sjdp		  else
291833965Sjdp		    {
291933965Sjdp		      if (! (*fns->class_static_method_variant) (fhandle,
292033965Sjdp								 v->physname,
292133965Sjdp								 v->visibility,
292233965Sjdp								 v->constp,
292333965Sjdp								 v->volatilep))
292433965Sjdp			return false;
292533965Sjdp		    }
292633965Sjdp		}
292733965Sjdp	      if (! (*fns->class_end_method) (fhandle))
292833965Sjdp		return false;
292933965Sjdp	    }
293033965Sjdp	}
293133965Sjdp    }
293233965Sjdp
293333965Sjdp  return (*fns->end_class_type) (fhandle);
293433965Sjdp}
293533965Sjdp
293633965Sjdp/* Write out information for a function.  */
293733965Sjdp
293833965Sjdpstatic boolean
293933965Sjdpdebug_write_function (info, fns, fhandle, name, linkage, function)
294033965Sjdp     struct debug_handle *info;
294133965Sjdp     const struct debug_write_fns *fns;
294233965Sjdp     PTR fhandle;
294333965Sjdp     const char *name;
294433965Sjdp     enum debug_object_linkage linkage;
294533965Sjdp     struct debug_function *function;
294633965Sjdp{
294733965Sjdp  struct debug_parameter *p;
294833965Sjdp  struct debug_block *b;
294933965Sjdp
295033965Sjdp  if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
295133965Sjdp    return false;
295233965Sjdp
295333965Sjdp  if (! debug_write_type (info, fns, fhandle, function->return_type,
295433965Sjdp			  (struct debug_name *) NULL))
295533965Sjdp    return false;
295633965Sjdp
295733965Sjdp  if (! (*fns->start_function) (fhandle, name,
295833965Sjdp				linkage == DEBUG_LINKAGE_GLOBAL))
295933965Sjdp    return false;
296033965Sjdp
296133965Sjdp  for (p = function->parameters; p != NULL; p = p->next)
296233965Sjdp    {
296333965Sjdp      if (! debug_write_type (info, fns, fhandle, p->type,
296433965Sjdp			      (struct debug_name *) NULL)
296533965Sjdp	  || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
296633965Sjdp	return false;
296733965Sjdp    }
296833965Sjdp
296933965Sjdp  for (b = function->blocks; b != NULL; b = b->next)
297033965Sjdp    {
297133965Sjdp      if (! debug_write_block (info, fns, fhandle, b))
297233965Sjdp	return false;
297333965Sjdp    }
297433965Sjdp
297533965Sjdp  return (*fns->end_function) (fhandle);
297633965Sjdp}
297733965Sjdp
297833965Sjdp/* Write out information for a block.  */
297933965Sjdp
298033965Sjdpstatic boolean
298133965Sjdpdebug_write_block (info, fns, fhandle, block)
298233965Sjdp     struct debug_handle *info;
298333965Sjdp     const struct debug_write_fns *fns;
298433965Sjdp     PTR fhandle;
298533965Sjdp     struct debug_block *block;
298633965Sjdp{
298733965Sjdp  struct debug_name *n;
298833965Sjdp  struct debug_block *b;
298933965Sjdp
299033965Sjdp  if (! debug_write_linenos (info, fns, fhandle, block->start))
299133965Sjdp    return false;
299233965Sjdp
299333965Sjdp  /* I can't see any point to writing out a block with no local
299433965Sjdp     variables, so we don't bother, except for the top level block.  */
299533965Sjdp  if (block->locals != NULL || block->parent == NULL)
299633965Sjdp    {
299733965Sjdp      if (! (*fns->start_block) (fhandle, block->start))
299833965Sjdp	return false;
299933965Sjdp    }
300033965Sjdp
300133965Sjdp  if (block->locals != NULL)
300233965Sjdp    {
300333965Sjdp      for (n = block->locals->list; n != NULL; n = n->next)
300433965Sjdp	{
300533965Sjdp	  if (! debug_write_name (info, fns, fhandle, n))
300633965Sjdp	    return false;
300733965Sjdp	}
300833965Sjdp    }
300933965Sjdp
301033965Sjdp  for (b = block->children; b != NULL; b = b->next)
301133965Sjdp    {
301233965Sjdp      if (! debug_write_block (info, fns, fhandle, b))
301333965Sjdp	return false;
301433965Sjdp    }
301533965Sjdp
301633965Sjdp  if (! debug_write_linenos (info, fns, fhandle, block->end))
301733965Sjdp    return false;
301833965Sjdp
301933965Sjdp  if (block->locals != NULL || block->parent == NULL)
302033965Sjdp    {
302133965Sjdp      if (! (*fns->end_block) (fhandle, block->end))
302233965Sjdp	return false;
302333965Sjdp    }
302433965Sjdp
302533965Sjdp  return true;
302633965Sjdp}
302733965Sjdp
302833965Sjdp/* Write out line number information up to ADDRESS.  */
302933965Sjdp
303033965Sjdpstatic boolean
303133965Sjdpdebug_write_linenos (info, fns, fhandle, address)
303233965Sjdp     struct debug_handle *info;
303333965Sjdp     const struct debug_write_fns *fns;
303433965Sjdp     PTR fhandle;
303533965Sjdp     bfd_vma address;
303633965Sjdp{
303733965Sjdp  while (info->current_write_lineno != NULL)
303833965Sjdp    {
303933965Sjdp      struct debug_lineno *l;
304033965Sjdp
304133965Sjdp      l = info->current_write_lineno;
304233965Sjdp
304333965Sjdp      while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
304433965Sjdp	{
304533965Sjdp	  if (l->linenos[info->current_write_lineno_index]
304633965Sjdp	      == (unsigned long) -1)
304733965Sjdp	    break;
304833965Sjdp
304933965Sjdp	  if (l->addrs[info->current_write_lineno_index] >= address)
305033965Sjdp	    return true;
305133965Sjdp
305233965Sjdp	  if (! (*fns->lineno) (fhandle, l->file->filename,
305333965Sjdp				l->linenos[info->current_write_lineno_index],
305433965Sjdp				l->addrs[info->current_write_lineno_index]))
305533965Sjdp	    return false;
305633965Sjdp
305733965Sjdp	  ++info->current_write_lineno_index;
305833965Sjdp	}
305933965Sjdp
306033965Sjdp      info->current_write_lineno = l->next;
306133965Sjdp      info->current_write_lineno_index = 0;
306233965Sjdp    }
306333965Sjdp
306433965Sjdp  return true;
306533965Sjdp}
306633965Sjdp
306733965Sjdp/* Get the ID number for a class.  If during the same call to
306833965Sjdp   debug_write we find a struct with the same definition with the same
306933965Sjdp   name, we use the same ID.  This type of things happens because the
307033965Sjdp   same struct will be defined by multiple compilation units.  */
307133965Sjdp
307233965Sjdpstatic boolean
307333965Sjdpdebug_set_class_id (info, tag, type)
307433965Sjdp     struct debug_handle *info;
307533965Sjdp     const char *tag;
307633965Sjdp     struct debug_type *type;
307733965Sjdp{
307833965Sjdp  struct debug_class_type *c;
307933965Sjdp  struct debug_class_id *l;
308033965Sjdp
308133965Sjdp  assert (type->kind == DEBUG_KIND_STRUCT
308233965Sjdp	  || type->kind == DEBUG_KIND_UNION
308333965Sjdp	  || type->kind == DEBUG_KIND_CLASS
308433965Sjdp	  || type->kind == DEBUG_KIND_UNION_CLASS);
308533965Sjdp
308633965Sjdp  c = type->u.kclass;
308733965Sjdp
308833965Sjdp  if (c->id > info->base_id)
308933965Sjdp    return true;
309033965Sjdp
309133965Sjdp  for (l = info->id_list; l != NULL; l = l->next)
309233965Sjdp    {
309333965Sjdp      if (l->type->kind != type->kind)
309433965Sjdp	continue;
309533965Sjdp
309633965Sjdp      if (tag == NULL)
309733965Sjdp	{
309833965Sjdp	  if (l->tag != NULL)
309933965Sjdp	    continue;
310033965Sjdp	}
310133965Sjdp      else
310233965Sjdp	{
310333965Sjdp	  if (l->tag == NULL
310433965Sjdp	      || l->tag[0] != tag[0]
310533965Sjdp	      || strcmp (l->tag, tag) != 0)
310633965Sjdp	    continue;
310733965Sjdp	}
310833965Sjdp
310933965Sjdp      if (debug_type_samep (info, l->type, type))
311033965Sjdp	{
311133965Sjdp	  c->id = l->type->u.kclass->id;
311233965Sjdp	  return true;
311333965Sjdp	}
311433965Sjdp    }
311533965Sjdp
311633965Sjdp  /* There are no identical types.  Use a new ID, and add it to the
311733965Sjdp     list.  */
311833965Sjdp  ++info->class_id;
311933965Sjdp  c->id = info->class_id;
312033965Sjdp
312133965Sjdp  l = (struct debug_class_id *) xmalloc (sizeof *l);
312233965Sjdp  memset (l, 0, sizeof *l);
312333965Sjdp
312433965Sjdp  l->type = type;
312533965Sjdp  l->tag = tag;
312633965Sjdp
312733965Sjdp  l->next = info->id_list;
312833965Sjdp  info->id_list = l;
312933965Sjdp
313033965Sjdp  return true;
313133965Sjdp}
313233965Sjdp
313333965Sjdp/* See if two types are the same.  At this point, we don't care about
313433965Sjdp   tags and the like.  */
313533965Sjdp
313633965Sjdpstatic boolean
313733965Sjdpdebug_type_samep (info, t1, t2)
313833965Sjdp     struct debug_handle *info;
313933965Sjdp     struct debug_type *t1;
314033965Sjdp     struct debug_type *t2;
314133965Sjdp{
314233965Sjdp  struct debug_type_compare_list *l;
314333965Sjdp  struct debug_type_compare_list top;
314433965Sjdp  boolean ret;
314533965Sjdp
314633965Sjdp  if (t1 == NULL)
314733965Sjdp    return t2 == NULL;
314833965Sjdp  if (t2 == NULL)
314933965Sjdp    return false;
315033965Sjdp
315133965Sjdp  while (t1->kind == DEBUG_KIND_INDIRECT)
315233965Sjdp    {
315333965Sjdp      t1 = *t1->u.kindirect->slot;
315433965Sjdp      if (t1 == NULL)
315533965Sjdp	return false;
315633965Sjdp    }
315733965Sjdp  while (t2->kind == DEBUG_KIND_INDIRECT)
315833965Sjdp    {
315933965Sjdp      t2 = *t2->u.kindirect->slot;
316033965Sjdp      if (t2 == NULL)
316133965Sjdp	return false;
316233965Sjdp    }
316333965Sjdp
316433965Sjdp  if (t1 == t2)
316533965Sjdp    return true;
316633965Sjdp
316733965Sjdp  /* As a special case, permit a typedef to match a tag, since C++
316833965Sjdp     debugging output will sometimes add a typedef where C debugging
316933965Sjdp     output will not.  */
317033965Sjdp  if (t1->kind == DEBUG_KIND_NAMED
317133965Sjdp      && t2->kind == DEBUG_KIND_TAGGED)
317233965Sjdp    return debug_type_samep (info, t1->u.knamed->type, t2);
317333965Sjdp  else if (t1->kind == DEBUG_KIND_TAGGED
317433965Sjdp	   && t2->kind == DEBUG_KIND_NAMED)
317533965Sjdp    return debug_type_samep (info, t1, t2->u.knamed->type);
317633965Sjdp
317733965Sjdp  if (t1->kind != t2->kind
317833965Sjdp      || t1->size != t2->size)
317933965Sjdp    return false;
318033965Sjdp
318133965Sjdp  /* Get rid of the trivial cases first.  */
318233965Sjdp  switch (t1->kind)
318333965Sjdp    {
318433965Sjdp    default:
318533965Sjdp      break;
318633965Sjdp    case DEBUG_KIND_VOID:
318733965Sjdp    case DEBUG_KIND_FLOAT:
318833965Sjdp    case DEBUG_KIND_COMPLEX:
318933965Sjdp    case DEBUG_KIND_BOOL:
319033965Sjdp      return true;
319133965Sjdp    case DEBUG_KIND_INT:
319233965Sjdp      return t1->u.kint == t2->u.kint;
319333965Sjdp    }
319433965Sjdp
319533965Sjdp  /* We have to avoid an infinite recursion.  We do this by keeping a
319633965Sjdp     list of types which we are comparing.  We just keep the list on
319733965Sjdp     the stack.  If we encounter a pair of types we are currently
319833965Sjdp     comparing, we just assume that they are equal.  */
319933965Sjdp  for (l = info->compare_list; l != NULL; l = l->next)
320033965Sjdp    {
320133965Sjdp      if (l->t1 == t1 && l->t2 == t2)
320233965Sjdp	return true;
320333965Sjdp    }
320433965Sjdp
320533965Sjdp  top.t1 = t1;
320633965Sjdp  top.t2 = t2;
320733965Sjdp  top.next = info->compare_list;
320833965Sjdp  info->compare_list = &top;
320933965Sjdp
321033965Sjdp  switch (t1->kind)
321133965Sjdp    {
321233965Sjdp    default:
321333965Sjdp      abort ();
321433965Sjdp      ret = false;
321533965Sjdp      break;
321633965Sjdp
321733965Sjdp    case DEBUG_KIND_STRUCT:
321833965Sjdp    case DEBUG_KIND_UNION:
321933965Sjdp    case DEBUG_KIND_CLASS:
322033965Sjdp    case DEBUG_KIND_UNION_CLASS:
322133965Sjdp      if (t1->u.kclass == NULL)
322233965Sjdp	ret = t2->u.kclass == NULL;
322333965Sjdp      else if (t2->u.kclass == NULL)
322433965Sjdp	ret = false;
322533965Sjdp      else if (t1->u.kclass->id > info->base_id
322633965Sjdp	       && t1->u.kclass->id == t2->u.kclass->id)
322733965Sjdp	ret = true;
322833965Sjdp      else
322933965Sjdp	ret = debug_class_type_samep (info, t1, t2);
323033965Sjdp      break;
323133965Sjdp
323233965Sjdp    case DEBUG_KIND_ENUM:
323333965Sjdp      if (t1->u.kenum == NULL)
323433965Sjdp	ret = t2->u.kenum == NULL;
323533965Sjdp      else if (t2->u.kenum == NULL)
323633965Sjdp	ret = false;
323733965Sjdp      else
323833965Sjdp	{
323933965Sjdp	  const char **pn1, **pn2;
324033965Sjdp	  bfd_signed_vma *pv1, *pv2;
324133965Sjdp
324233965Sjdp	  pn1 = t1->u.kenum->names;
324333965Sjdp	  pn2 = t2->u.kenum->names;
324433965Sjdp	  pv1 = t1->u.kenum->values;
324533965Sjdp	  pv2 = t2->u.kenum->values;
324633965Sjdp	  while (*pn1 != NULL && *pn2 != NULL)
324733965Sjdp	    {
324833965Sjdp	      if (**pn1 != **pn2
324933965Sjdp		  || *pv1 != *pv2
325033965Sjdp		  || strcmp (*pn1, *pn2) != 0)
325133965Sjdp		break;
325233965Sjdp	      ++pn1;
325333965Sjdp	      ++pn2;
325433965Sjdp	      ++pv1;
325533965Sjdp	      ++pv2;
325633965Sjdp	    }
325733965Sjdp	  ret = *pn1 == NULL && *pn2 == NULL;
325833965Sjdp	}
325933965Sjdp      break;
326033965Sjdp
326133965Sjdp    case DEBUG_KIND_POINTER:
326233965Sjdp      ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
326333965Sjdp      break;
326433965Sjdp
326533965Sjdp    case DEBUG_KIND_FUNCTION:
326633965Sjdp      if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
326733965Sjdp	  || ! debug_type_samep (info, t1->u.kfunction->return_type,
326833965Sjdp				 t2->u.kfunction->return_type)
326933965Sjdp	  || ((t1->u.kfunction->arg_types == NULL)
327033965Sjdp	      != (t2->u.kfunction->arg_types == NULL)))
327133965Sjdp	ret = false;
327233965Sjdp      else if (t1->u.kfunction->arg_types == NULL)
327333965Sjdp	ret = true;
327433965Sjdp      else
327533965Sjdp	{
327633965Sjdp	  struct debug_type **a1, **a2;
327733965Sjdp
327833965Sjdp	  a1 = t1->u.kfunction->arg_types;
327933965Sjdp	  a2 = t2->u.kfunction->arg_types;
328033965Sjdp	  while (*a1 != NULL && *a2 != NULL)
328133965Sjdp	    if (! debug_type_samep (info, *a1, *a2))
328233965Sjdp	      break;
328333965Sjdp	  ret = *a1 == NULL && *a2 == NULL;
328433965Sjdp	}
328533965Sjdp      break;
328633965Sjdp
328733965Sjdp    case DEBUG_KIND_REFERENCE:
328833965Sjdp      ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
328933965Sjdp      break;
329033965Sjdp
329133965Sjdp    case DEBUG_KIND_RANGE:
329233965Sjdp      ret = (t1->u.krange->lower == t2->u.krange->lower
329333965Sjdp	     && t1->u.krange->upper == t2->u.krange->upper
329433965Sjdp	     && debug_type_samep (info, t1->u.krange->type,
329533965Sjdp				  t2->u.krange->type));
329633965Sjdp
329733965Sjdp    case DEBUG_KIND_ARRAY:
329833965Sjdp      ret = (t1->u.karray->lower == t2->u.karray->lower
329933965Sjdp	     && t1->u.karray->upper == t2->u.karray->upper
330033965Sjdp	     && t1->u.karray->stringp == t2->u.karray->stringp
330133965Sjdp	     && debug_type_samep (info, t1->u.karray->element_type,
330233965Sjdp				  t2->u.karray->element_type));
330333965Sjdp      break;
330433965Sjdp
330533965Sjdp    case DEBUG_KIND_SET:
330633965Sjdp      ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
330733965Sjdp	     && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
330833965Sjdp      break;
330933965Sjdp
331033965Sjdp    case DEBUG_KIND_OFFSET:
331133965Sjdp      ret = (debug_type_samep (info, t1->u.koffset->base_type,
331233965Sjdp			       t2->u.koffset->base_type)
331333965Sjdp	     && debug_type_samep (info, t1->u.koffset->target_type,
331433965Sjdp				  t2->u.koffset->target_type));
331533965Sjdp      break;
331633965Sjdp
331733965Sjdp    case DEBUG_KIND_METHOD:
331833965Sjdp      if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
331933965Sjdp	  || ! debug_type_samep (info, t1->u.kmethod->return_type,
332033965Sjdp				 t2->u.kmethod->return_type)
332133965Sjdp	  || ! debug_type_samep (info, t1->u.kmethod->domain_type,
332233965Sjdp				 t2->u.kmethod->domain_type)
332333965Sjdp	  || ((t1->u.kmethod->arg_types == NULL)
332433965Sjdp	      != (t2->u.kmethod->arg_types == NULL)))
332533965Sjdp	ret = false;
332633965Sjdp      else if (t1->u.kmethod->arg_types == NULL)
332733965Sjdp	ret = true;
332833965Sjdp      else
332933965Sjdp	{
333033965Sjdp	  struct debug_type **a1, **a2;
333133965Sjdp
333233965Sjdp	  a1 = t1->u.kmethod->arg_types;
333333965Sjdp	  a2 = t2->u.kmethod->arg_types;
333433965Sjdp	  while (*a1 != NULL && *a2 != NULL)
333533965Sjdp	    if (! debug_type_samep (info, *a1, *a2))
333633965Sjdp	      break;
333733965Sjdp	  ret = *a1 == NULL && *a2 == NULL;
333833965Sjdp	}
333933965Sjdp      break;
334033965Sjdp
334133965Sjdp    case DEBUG_KIND_CONST:
334233965Sjdp      ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
334333965Sjdp      break;
334433965Sjdp
334533965Sjdp    case DEBUG_KIND_VOLATILE:
334633965Sjdp      ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
334733965Sjdp      break;
334833965Sjdp
334933965Sjdp    case DEBUG_KIND_NAMED:
335033965Sjdp    case DEBUG_KIND_TAGGED:
335133965Sjdp      ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
335233965Sjdp	     && debug_type_samep (info, t1->u.knamed->type,
335333965Sjdp				  t2->u.knamed->type));
335433965Sjdp      break;
335533965Sjdp    }
335633965Sjdp
335733965Sjdp  info->compare_list = top.next;
335833965Sjdp
335933965Sjdp  return ret;
336033965Sjdp}
336133965Sjdp
336233965Sjdp/* See if two classes are the same.  This is a subroutine of
336333965Sjdp   debug_type_samep.  */
336433965Sjdp
336533965Sjdpstatic boolean
336633965Sjdpdebug_class_type_samep (info, t1, t2)
336733965Sjdp     struct debug_handle *info;
336833965Sjdp     struct debug_type *t1;
336933965Sjdp     struct debug_type *t2;
337033965Sjdp{
337133965Sjdp  struct debug_class_type *c1, *c2;
337233965Sjdp
337333965Sjdp  c1 = t1->u.kclass;
337433965Sjdp  c2 = t2->u.kclass;
337533965Sjdp
337633965Sjdp  if ((c1->fields == NULL) != (c2->fields == NULL)
337733965Sjdp      || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
337833965Sjdp      || (c1->methods == NULL) != (c2->methods == NULL)
337933965Sjdp      || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
338033965Sjdp    return false;
338133965Sjdp
338233965Sjdp  if (c1->fields != NULL)
338333965Sjdp    {
338433965Sjdp      struct debug_field **pf1, **pf2;
338533965Sjdp
338633965Sjdp      for (pf1 = c1->fields, pf2 = c2->fields;
338733965Sjdp	   *pf1 != NULL && *pf2 != NULL;
338833965Sjdp	   pf1++, pf2++)
338933965Sjdp	{
339033965Sjdp	  struct debug_field *f1, *f2;
339133965Sjdp
339233965Sjdp	  f1 = *pf1;
339333965Sjdp	  f2 = *pf2;
339433965Sjdp	  if (f1->name[0] != f2->name[0]
339533965Sjdp	      || f1->visibility != f2->visibility
339633965Sjdp	      || f1->static_member != f2->static_member)
339733965Sjdp	    return false;
339833965Sjdp	  if (f1->static_member)
339933965Sjdp	    {
340033965Sjdp	      if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
340133965Sjdp		return false;
340233965Sjdp	    }
340333965Sjdp	  else
340433965Sjdp	    {
340533965Sjdp	      if (f1->u.f.bitpos != f2->u.f.bitpos
340633965Sjdp		  || f1->u.f.bitsize != f2->u.f.bitsize)
340733965Sjdp		return false;
340833965Sjdp	    }
340933965Sjdp	  /* We do the checks which require function calls last.  We
341033965Sjdp             don't require that the types of fields have the same
341133965Sjdp             names, since that sometimes fails in the presence of
341233965Sjdp             typedefs and we really don't care.  */
341333965Sjdp	  if (strcmp (f1->name, f2->name) != 0
341433965Sjdp	      || ! debug_type_samep (info,
341533965Sjdp				     debug_get_real_type ((PTR) info,
341633965Sjdp							  f1->type),
341733965Sjdp				     debug_get_real_type ((PTR) info,
341833965Sjdp							  f2->type)))
341933965Sjdp	    return false;
342033965Sjdp	}
342133965Sjdp      if (*pf1 != NULL || *pf2 != NULL)
342233965Sjdp	return false;
342333965Sjdp    }
342433965Sjdp
342533965Sjdp  if (c1->vptrbase != NULL)
342633965Sjdp    {
342733965Sjdp      if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
342833965Sjdp	return false;
342933965Sjdp    }
343033965Sjdp
343133965Sjdp  if (c1->baseclasses != NULL)
343233965Sjdp    {
343333965Sjdp      struct debug_baseclass **pb1, **pb2;
343433965Sjdp
343533965Sjdp      for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
343633965Sjdp	   *pb1 != NULL && *pb2 != NULL;
343733965Sjdp	   ++pb1, ++pb2)
343833965Sjdp	{
343933965Sjdp	  struct debug_baseclass *b1, *b2;
344033965Sjdp
344133965Sjdp	  b1 = *pb1;
344233965Sjdp	  b2 = *pb2;
344333965Sjdp	  if (b1->bitpos != b2->bitpos
344433965Sjdp	      || b1->virtual != b2->virtual
344533965Sjdp	      || b1->visibility != b2->visibility
344633965Sjdp	      || ! debug_type_samep (info, b1->type, b2->type))
344733965Sjdp	    return false;
344833965Sjdp	}
344933965Sjdp      if (*pb1 != NULL || *pb2 != NULL)
345033965Sjdp	return false;
345133965Sjdp    }
345233965Sjdp
345333965Sjdp  if (c1->methods != NULL)
345433965Sjdp    {
345533965Sjdp      struct debug_method **pm1, **pm2;
345633965Sjdp
345733965Sjdp      for (pm1 = c1->methods, pm2 = c2->methods;
345833965Sjdp	   *pm1 != NULL && *pm2 != NULL;
345933965Sjdp	   ++pm1, ++pm2)
346033965Sjdp	{
346133965Sjdp	  struct debug_method *m1, *m2;
346233965Sjdp
346333965Sjdp	  m1 = *pm1;
346433965Sjdp	  m2 = *pm2;
346533965Sjdp	  if (m1->name[0] != m2->name[0]
346633965Sjdp	      || strcmp (m1->name, m2->name) != 0
346733965Sjdp	      || (m1->variants == NULL) != (m2->variants == NULL))
346833965Sjdp	    return false;
346933965Sjdp	  if (m1->variants == NULL)
347033965Sjdp	    {
347133965Sjdp	      struct debug_method_variant **pv1, **pv2;
347233965Sjdp
347333965Sjdp	      for (pv1 = m1->variants, pv2 = m2->variants;
347433965Sjdp		   *pv1 != NULL && *pv2 != NULL;
347533965Sjdp		   ++pv1, ++pv2)
347633965Sjdp		{
347733965Sjdp		  struct debug_method_variant *v1, *v2;
347833965Sjdp
347933965Sjdp		  v1 = *pv1;
348033965Sjdp		  v2 = *pv2;
348133965Sjdp		  if (v1->physname[0] != v2->physname[0]
348233965Sjdp		      || v1->visibility != v2->visibility
348333965Sjdp		      || v1->constp != v2->constp
348433965Sjdp		      || v1->volatilep != v2->volatilep
348533965Sjdp		      || v1->voffset != v2->voffset
348633965Sjdp		      || (v1->context == NULL) != (v2->context == NULL)
348733965Sjdp		      || strcmp (v1->physname, v2->physname) != 0
348833965Sjdp		      || ! debug_type_samep (info, v1->type, v2->type))
348933965Sjdp		    return false;
349033965Sjdp		  if (v1->context != NULL)
349133965Sjdp		    {
349233965Sjdp		      if (! debug_type_samep (info, v1->context,
349333965Sjdp					      v2->context))
349433965Sjdp			return false;
349533965Sjdp		    }
349633965Sjdp		}
349733965Sjdp	      if (*pv1 != NULL || *pv2 != NULL)
349833965Sjdp		return false;
349933965Sjdp	    }
350033965Sjdp	}
350133965Sjdp      if (*pm1 != NULL || *pm2 != NULL)
350233965Sjdp	return false;
350333965Sjdp    }
350433965Sjdp
350533965Sjdp  return true;
350633965Sjdp}
3507