133965Sjdp/* debug.c -- Handle generic debugging information.
2218822Sdim   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2007
3218822Sdim   Free Software Foundation, Inc.
433965Sjdp   Written by Ian Lance Taylor <ian@cygnus.com>.
533965Sjdp
633965Sjdp   This file is part of GNU Binutils.
733965Sjdp
833965Sjdp   This program is free software; you can redistribute it and/or modify
933965Sjdp   it under the terms of the GNU General Public License as published by
1033965Sjdp   the Free Software Foundation; either version 2 of the License, or
1133965Sjdp   (at your option) any later version.
1233965Sjdp
1333965Sjdp   This program is distributed in the hope that it will be useful,
1433965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1533965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1633965Sjdp   GNU General Public License for more details.
1733965Sjdp
1833965Sjdp   You should have received a copy of the GNU General Public License
1933965Sjdp   along with this program; if not, write to the Free Software
20218822Sdim   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21218822Sdim   02110-1301, USA.  */
2233965Sjdp
2333965Sjdp/* This file implements a generic debugging format.  We may eventually
2433965Sjdp   have readers which convert different formats into this generic
2533965Sjdp   format, and writers which write it out.  The initial impetus for
26130561Sobrien   this was writing a converter from stabs to HP IEEE-695 debugging
2733965Sjdp   format.  */
2833965Sjdp
29218822Sdim#include "sysdep.h"
3033965Sjdp#include <assert.h>
3133965Sjdp#include "bfd.h"
3233965Sjdp#include "libiberty.h"
3333965Sjdp#include "debug.h"
3433965Sjdp
3533965Sjdp/* Global information we keep for debugging.  A pointer to this
3633965Sjdp   structure is the debugging handle passed to all the routines.  */
3733965Sjdp
3833965Sjdpstruct debug_handle
3933965Sjdp{
4033965Sjdp  /* A linked list of compilation units.  */
4133965Sjdp  struct debug_unit *units;
4233965Sjdp  /* The current compilation unit.  */
4333965Sjdp  struct debug_unit *current_unit;
4433965Sjdp  /* The current source file.  */
4533965Sjdp  struct debug_file *current_file;
4633965Sjdp  /* The current function.  */
4733965Sjdp  struct debug_function *current_function;
4833965Sjdp  /* The current block.  */
4933965Sjdp  struct debug_block *current_block;
5033965Sjdp  /* The current line number information for the current unit.  */
5133965Sjdp  struct debug_lineno *current_lineno;
5233965Sjdp  /* Mark.  This is used by debug_write.  */
5333965Sjdp  unsigned int mark;
5433965Sjdp  /* A struct/class ID used by debug_write.  */
5533965Sjdp  unsigned int class_id;
5633965Sjdp  /* The base for class_id for this call to debug_write.  */
5733965Sjdp  unsigned int base_id;
5833965Sjdp  /* The current line number in debug_write.  */
5933965Sjdp  struct debug_lineno *current_write_lineno;
6033965Sjdp  unsigned int current_write_lineno_index;
6133965Sjdp  /* A list of classes which have assigned ID's during debug_write.
6233965Sjdp     This is linked through the next_id field of debug_class_type.  */
6333965Sjdp  struct debug_class_id *id_list;
6433965Sjdp  /* A list used to avoid recursion during debug_type_samep.  */
6533965Sjdp  struct debug_type_compare_list *compare_list;
6633965Sjdp};
6733965Sjdp
6833965Sjdp/* Information we keep for a single compilation unit.  */
6933965Sjdp
7033965Sjdpstruct debug_unit
7133965Sjdp{
7233965Sjdp  /* The next compilation unit.  */
7333965Sjdp  struct debug_unit *next;
7433965Sjdp  /* A list of files included in this compilation unit.  The first
7533965Sjdp     file is always the main one, and that is where the main file name
7633965Sjdp     is stored.  */
7733965Sjdp  struct debug_file *files;
7833965Sjdp  /* Line number information for this compilation unit.  This is not
7933965Sjdp     stored by function, because assembler code may have line number
8033965Sjdp     information without function information.  */
8133965Sjdp  struct debug_lineno *linenos;
8233965Sjdp};
8333965Sjdp
8433965Sjdp/* Information kept for a single source file.  */
8533965Sjdp
8633965Sjdpstruct debug_file
8733965Sjdp{
8833965Sjdp  /* The next source file in this compilation unit.  */
8933965Sjdp  struct debug_file *next;
9033965Sjdp  /* The name of the source file.  */
9133965Sjdp  const char *filename;
9233965Sjdp  /* Global functions, variables, types, etc.  */
9333965Sjdp  struct debug_namespace *globals;
9433965Sjdp};
9533965Sjdp
9633965Sjdp/* A type.  */
9733965Sjdp
9833965Sjdpstruct debug_type
9933965Sjdp{
10033965Sjdp  /* Kind of type.  */
10133965Sjdp  enum debug_type_kind kind;
10233965Sjdp  /* Size of type (0 if not known).  */
10333965Sjdp  unsigned int size;
10433965Sjdp  /* Type which is a pointer to this type.  */
10533965Sjdp  debug_type pointer;
10633965Sjdp  /* Tagged union with additional information about the type.  */
10733965Sjdp  union
10833965Sjdp    {
10933965Sjdp      /* DEBUG_KIND_INDIRECT.  */
11033965Sjdp      struct debug_indirect_type *kindirect;
11133965Sjdp      /* DEBUG_KIND_INT.  */
11233965Sjdp      /* Whether the integer is unsigned.  */
113130561Sobrien      bfd_boolean kint;
11433965Sjdp      /* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
11533965Sjdp         DEBUG_KIND_UNION_CLASS.  */
11633965Sjdp      struct debug_class_type *kclass;
11733965Sjdp      /* DEBUG_KIND_ENUM.  */
11833965Sjdp      struct debug_enum_type *kenum;
11933965Sjdp      /* DEBUG_KIND_POINTER.  */
12033965Sjdp      struct debug_type *kpointer;
12133965Sjdp      /* DEBUG_KIND_FUNCTION.  */
12233965Sjdp      struct debug_function_type *kfunction;
12333965Sjdp      /* DEBUG_KIND_REFERENCE.  */
12433965Sjdp      struct debug_type *kreference;
12533965Sjdp      /* DEBUG_KIND_RANGE.  */
12633965Sjdp      struct debug_range_type *krange;
12733965Sjdp      /* DEBUG_KIND_ARRAY.  */
12833965Sjdp      struct debug_array_type *karray;
12933965Sjdp      /* DEBUG_KIND_SET.  */
13033965Sjdp      struct debug_set_type *kset;
13133965Sjdp      /* DEBUG_KIND_OFFSET.  */
13233965Sjdp      struct debug_offset_type *koffset;
13333965Sjdp      /* DEBUG_KIND_METHOD.  */
13433965Sjdp      struct debug_method_type *kmethod;
13533965Sjdp      /* DEBUG_KIND_CONST.  */
13633965Sjdp      struct debug_type *kconst;
13733965Sjdp      /* DEBUG_KIND_VOLATILE.  */
13833965Sjdp      struct debug_type *kvolatile;
13933965Sjdp      /* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED.  */
14033965Sjdp      struct debug_named_type *knamed;
14133965Sjdp    } u;
14233965Sjdp};
14333965Sjdp
14433965Sjdp/* Information kept for an indirect type.  */
14533965Sjdp
14633965Sjdpstruct debug_indirect_type
14733965Sjdp{
14833965Sjdp  /* Slot where the final type will appear.  */
14933965Sjdp  debug_type *slot;
15033965Sjdp  /* Tag.  */
15133965Sjdp  const char *tag;
15233965Sjdp};
15333965Sjdp
15433965Sjdp/* Information kept for a struct, union, or class.  */
15533965Sjdp
15633965Sjdpstruct debug_class_type
15733965Sjdp{
15833965Sjdp  /* NULL terminated array of fields.  */
15933965Sjdp  debug_field *fields;
16033965Sjdp  /* A mark field which indicates whether the struct has already been
16133965Sjdp     printed.  */
16233965Sjdp  unsigned int mark;
16333965Sjdp  /* This is used to uniquely identify unnamed structs when printing.  */
16433965Sjdp  unsigned int id;
16533965Sjdp  /* The remaining fields are only used for DEBUG_KIND_CLASS and
16633965Sjdp     DEBUG_KIND_UNION_CLASS.  */
16733965Sjdp  /* NULL terminated array of base classes.  */
16833965Sjdp  debug_baseclass *baseclasses;
16933965Sjdp  /* NULL terminated array of methods.  */
17033965Sjdp  debug_method *methods;
17133965Sjdp  /* The type of the class providing the virtual function table for
17233965Sjdp     this class.  This may point to the type itself.  */
17333965Sjdp  debug_type vptrbase;
17433965Sjdp};
17533965Sjdp
17633965Sjdp/* Information kept for an enum.  */
17733965Sjdp
17833965Sjdpstruct debug_enum_type
17933965Sjdp{
18033965Sjdp  /* NULL terminated array of names.  */
18133965Sjdp  const char **names;
18233965Sjdp  /* Array of corresponding values.  */
18333965Sjdp  bfd_signed_vma *values;
18433965Sjdp};
18533965Sjdp
18633965Sjdp/* Information kept for a function.  FIXME: We should be able to
18733965Sjdp   record the parameter types.  */
18833965Sjdp
18933965Sjdpstruct debug_function_type
19033965Sjdp{
19133965Sjdp  /* Return type.  */
19233965Sjdp  debug_type return_type;
19333965Sjdp  /* NULL terminated array of argument types.  */
19433965Sjdp  debug_type *arg_types;
19533965Sjdp  /* Whether the function takes a variable number of arguments.  */
196130561Sobrien  bfd_boolean varargs;
19733965Sjdp};
19833965Sjdp
19933965Sjdp/* Information kept for a range.  */
20033965Sjdp
20133965Sjdpstruct debug_range_type
20233965Sjdp{
20333965Sjdp  /* Range base type.  */
20433965Sjdp  debug_type type;
20533965Sjdp  /* Lower bound.  */
20633965Sjdp  bfd_signed_vma lower;
20733965Sjdp  /* Upper bound.  */
20833965Sjdp  bfd_signed_vma upper;
20933965Sjdp};
21033965Sjdp
21133965Sjdp/* Information kept for an array.  */
21233965Sjdp
21333965Sjdpstruct debug_array_type
21433965Sjdp{
21533965Sjdp  /* Element type.  */
21633965Sjdp  debug_type element_type;
21733965Sjdp  /* Range type.  */
21833965Sjdp  debug_type range_type;
21933965Sjdp  /* Lower bound.  */
22033965Sjdp  bfd_signed_vma lower;
22133965Sjdp  /* Upper bound.  */
22233965Sjdp  bfd_signed_vma upper;
22333965Sjdp  /* Whether this array is really a string.  */
224130561Sobrien  bfd_boolean stringp;
22533965Sjdp};
22633965Sjdp
22733965Sjdp/* Information kept for a set.  */
22833965Sjdp
22933965Sjdpstruct debug_set_type
23033965Sjdp{
23133965Sjdp  /* Base type.  */
23233965Sjdp  debug_type type;
23333965Sjdp  /* Whether this set is really a bitstring.  */
234130561Sobrien  bfd_boolean bitstringp;
23533965Sjdp};
23633965Sjdp
23733965Sjdp/* Information kept for an offset type (a based pointer).  */
23833965Sjdp
23933965Sjdpstruct debug_offset_type
24033965Sjdp{
24133965Sjdp  /* The type the pointer is an offset from.  */
24233965Sjdp  debug_type base_type;
24333965Sjdp  /* The type the pointer points to.  */
24433965Sjdp  debug_type target_type;
24533965Sjdp};
24633965Sjdp
24733965Sjdp/* Information kept for a method type.  */
24833965Sjdp
24933965Sjdpstruct debug_method_type
25033965Sjdp{
25133965Sjdp  /* The return type.  */
25233965Sjdp  debug_type return_type;
25333965Sjdp  /* The object type which this method is for.  */
25433965Sjdp  debug_type domain_type;
25533965Sjdp  /* A NULL terminated array of argument types.  */
25633965Sjdp  debug_type *arg_types;
25733965Sjdp  /* Whether the method takes a variable number of arguments.  */
258130561Sobrien  bfd_boolean varargs;
25933965Sjdp};
26033965Sjdp
26133965Sjdp/* Information kept for a named type.  */
26233965Sjdp
26333965Sjdpstruct debug_named_type
26433965Sjdp{
26533965Sjdp  /* Name.  */
26633965Sjdp  struct debug_name *name;
26733965Sjdp  /* Real type.  */
26833965Sjdp  debug_type type;
26933965Sjdp};
27033965Sjdp
27133965Sjdp/* A field in a struct or union.  */
27233965Sjdp
27333965Sjdpstruct debug_field
27433965Sjdp{
27533965Sjdp  /* Name of the field.  */
27633965Sjdp  const char *name;
27733965Sjdp  /* Type of the field.  */
27833965Sjdp  struct debug_type *type;
27933965Sjdp  /* Visibility of the field.  */
28033965Sjdp  enum debug_visibility visibility;
28133965Sjdp  /* Whether this is a static member.  */
282130561Sobrien  bfd_boolean static_member;
28333965Sjdp  union
28433965Sjdp    {
28533965Sjdp      /* If static_member is false.  */
28633965Sjdp      struct
28733965Sjdp	{
28833965Sjdp	  /* Bit position of the field in the struct.  */
28933965Sjdp	  unsigned int bitpos;
29033965Sjdp	  /* Size of the field in bits.  */
29133965Sjdp	  unsigned int bitsize;
29233965Sjdp	} f;
29333965Sjdp      /* If static_member is true.  */
29433965Sjdp      struct
29533965Sjdp	{
29633965Sjdp	  const char *physname;
29733965Sjdp	} s;
29833965Sjdp    } u;
29933965Sjdp};
30033965Sjdp
30133965Sjdp/* A base class for an object.  */
30233965Sjdp
30333965Sjdpstruct debug_baseclass
30433965Sjdp{
30533965Sjdp  /* Type of the base class.  */
30633965Sjdp  struct debug_type *type;
30733965Sjdp  /* Bit position of the base class in the object.  */
30833965Sjdp  unsigned int bitpos;
30933965Sjdp  /* Whether the base class is virtual.  */
310130561Sobrien  bfd_boolean virtual;
31133965Sjdp  /* Visibility of the base class.  */
31233965Sjdp  enum debug_visibility visibility;
31333965Sjdp};
31433965Sjdp
31533965Sjdp/* A method of an object.  */
31633965Sjdp
31733965Sjdpstruct debug_method
31833965Sjdp{
31933965Sjdp  /* The name of the method.  */
32033965Sjdp  const char *name;
32133965Sjdp  /* A NULL terminated array of different types of variants.  */
32233965Sjdp  struct debug_method_variant **variants;
32333965Sjdp};
32433965Sjdp
32533965Sjdp/* The variants of a method function of an object.  These indicate
32633965Sjdp   which method to run.  */
32733965Sjdp
32833965Sjdpstruct debug_method_variant
32933965Sjdp{
33033965Sjdp  /* The physical name of the function.  */
33133965Sjdp  const char *physname;
33233965Sjdp  /* The type of the function.  */
33333965Sjdp  struct debug_type *type;
33433965Sjdp  /* The visibility of the function.  */
33533965Sjdp  enum debug_visibility visibility;
33633965Sjdp  /* Whether the function is const.  */
337130561Sobrien  bfd_boolean constp;
33833965Sjdp  /* Whether the function is volatile.  */
339130561Sobrien  bfd_boolean volatilep;
34033965Sjdp  /* The offset to the function in the virtual function table.  */
34133965Sjdp  bfd_vma voffset;
34233965Sjdp  /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */
34333965Sjdp#define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
34433965Sjdp  /* Context of a virtual method function.  */
34533965Sjdp  struct debug_type *context;
34633965Sjdp};
34733965Sjdp
34833965Sjdp/* A variable.  This is the information we keep for a variable object.
34933965Sjdp   This has no name; a name is associated with a variable in a
35033965Sjdp   debug_name structure.  */
35133965Sjdp
35233965Sjdpstruct debug_variable
35333965Sjdp{
35433965Sjdp  /* Kind of variable.  */
35533965Sjdp  enum debug_var_kind kind;
35633965Sjdp  /* Type.  */
35733965Sjdp  debug_type type;
35833965Sjdp  /* Value.  The interpretation of the value depends upon kind.  */
35933965Sjdp  bfd_vma val;
36033965Sjdp};
36133965Sjdp
36233965Sjdp/* A function.  This has no name; a name is associated with a function
36333965Sjdp   in a debug_name structure.  */
36433965Sjdp
36533965Sjdpstruct debug_function
36633965Sjdp{
36733965Sjdp  /* Return type.  */
36833965Sjdp  debug_type return_type;
36933965Sjdp  /* Parameter information.  */
37033965Sjdp  struct debug_parameter *parameters;
37133965Sjdp  /* Block information.  The first structure on the list is the main
37233965Sjdp     block of the function, and describes function local variables.  */
37333965Sjdp  struct debug_block *blocks;
37433965Sjdp};
37533965Sjdp
37633965Sjdp/* A function parameter.  */
37733965Sjdp
37833965Sjdpstruct debug_parameter
37933965Sjdp{
38033965Sjdp  /* Next parameter.  */
38133965Sjdp  struct debug_parameter *next;
38233965Sjdp  /* Name.  */
38333965Sjdp  const char *name;
38433965Sjdp  /* Type.  */
38533965Sjdp  debug_type type;
38633965Sjdp  /* Kind.  */
38733965Sjdp  enum debug_parm_kind kind;
38833965Sjdp  /* Value (meaning depends upon kind).  */
38933965Sjdp  bfd_vma val;
39033965Sjdp};
39133965Sjdp
39233965Sjdp/* A typed constant.  */
39333965Sjdp
39433965Sjdpstruct debug_typed_constant
39533965Sjdp{
39633965Sjdp  /* Type.  */
39733965Sjdp  debug_type type;
39833965Sjdp  /* Value.  FIXME: We may eventually need to support non-integral
39933965Sjdp     values.  */
40033965Sjdp  bfd_vma val;
40133965Sjdp};
40233965Sjdp
40333965Sjdp/* Information about a block within a function.  */
40433965Sjdp
40533965Sjdpstruct debug_block
40633965Sjdp{
40733965Sjdp  /* Next block with the same parent.  */
40833965Sjdp  struct debug_block *next;
40933965Sjdp  /* Parent block.  */
41033965Sjdp  struct debug_block *parent;
41133965Sjdp  /* List of child blocks.  */
41233965Sjdp  struct debug_block *children;
41333965Sjdp  /* Start address of the block.  */
41433965Sjdp  bfd_vma start;
41533965Sjdp  /* End address of the block.  */
41633965Sjdp  bfd_vma end;
41733965Sjdp  /* Local variables.  */
41833965Sjdp  struct debug_namespace *locals;
41933965Sjdp};
42033965Sjdp
42133965Sjdp/* Line number information we keep for a compilation unit.  FIXME:
42233965Sjdp   This structure is easy to create, but can be very space
42333965Sjdp   inefficient.  */
42433965Sjdp
42533965Sjdpstruct debug_lineno
42633965Sjdp{
42733965Sjdp  /* More line number information for this block.  */
42833965Sjdp  struct debug_lineno *next;
42933965Sjdp  /* Source file.  */
43033965Sjdp  struct debug_file *file;
43133965Sjdp  /* Line numbers, terminated by a -1 or the end of the array.  */
43233965Sjdp#define DEBUG_LINENO_COUNT 10
43333965Sjdp  unsigned long linenos[DEBUG_LINENO_COUNT];
43433965Sjdp  /* Addresses for the line numbers.  */
43533965Sjdp  bfd_vma addrs[DEBUG_LINENO_COUNT];
43633965Sjdp};
43733965Sjdp
43833965Sjdp/* A namespace.  This is a mapping from names to objects.  FIXME: This
43933965Sjdp   should be implemented as a hash table.  */
44033965Sjdp
44133965Sjdpstruct debug_namespace
44233965Sjdp{
44333965Sjdp  /* List of items in this namespace.  */
44433965Sjdp  struct debug_name *list;
44533965Sjdp  /* Pointer to where the next item in this namespace should go.  */
44633965Sjdp  struct debug_name **tail;
44733965Sjdp};
44833965Sjdp
44933965Sjdp/* Kinds of objects that appear in a namespace.  */
45033965Sjdp
45133965Sjdpenum debug_object_kind
45233965Sjdp{
45333965Sjdp  /* A type.  */
45433965Sjdp  DEBUG_OBJECT_TYPE,
45533965Sjdp  /* A tagged type (really a different sort of namespace).  */
45633965Sjdp  DEBUG_OBJECT_TAG,
45733965Sjdp  /* A variable.  */
45833965Sjdp  DEBUG_OBJECT_VARIABLE,
45933965Sjdp  /* A function.  */
46033965Sjdp  DEBUG_OBJECT_FUNCTION,
46133965Sjdp  /* An integer constant.  */
46233965Sjdp  DEBUG_OBJECT_INT_CONSTANT,
46333965Sjdp  /* A floating point constant.  */
46433965Sjdp  DEBUG_OBJECT_FLOAT_CONSTANT,
46533965Sjdp  /* A typed constant.  */
46633965Sjdp  DEBUG_OBJECT_TYPED_CONSTANT
46733965Sjdp};
46833965Sjdp
46933965Sjdp/* Linkage of an object that appears in a namespace.  */
47033965Sjdp
47133965Sjdpenum debug_object_linkage
47233965Sjdp{
47333965Sjdp  /* Local variable.  */
47433965Sjdp  DEBUG_LINKAGE_AUTOMATIC,
47533965Sjdp  /* Static--either file static or function static, depending upon the
47633965Sjdp     namespace is.  */
47733965Sjdp  DEBUG_LINKAGE_STATIC,
47833965Sjdp  /* Global.  */
47933965Sjdp  DEBUG_LINKAGE_GLOBAL,
48033965Sjdp  /* No linkage.  */
48133965Sjdp  DEBUG_LINKAGE_NONE
48233965Sjdp};
48333965Sjdp
48433965Sjdp/* A name in a namespace.  */
48533965Sjdp
48633965Sjdpstruct debug_name
48733965Sjdp{
48833965Sjdp  /* Next name in this namespace.  */
48933965Sjdp  struct debug_name *next;
49033965Sjdp  /* Name.  */
49133965Sjdp  const char *name;
49233965Sjdp  /* Mark.  This is used by debug_write.  */
49333965Sjdp  unsigned int mark;
49433965Sjdp  /* Kind of object.  */
49533965Sjdp  enum debug_object_kind kind;
49633965Sjdp  /* Linkage of object.  */
49733965Sjdp  enum debug_object_linkage linkage;
49833965Sjdp  /* Tagged union with additional information about the object.  */
49933965Sjdp  union
50033965Sjdp    {
50133965Sjdp      /* DEBUG_OBJECT_TYPE.  */
50233965Sjdp      struct debug_type *type;
50333965Sjdp      /* DEBUG_OBJECT_TAG.  */
50433965Sjdp      struct debug_type *tag;
50533965Sjdp      /* DEBUG_OBJECT_VARIABLE.  */
50633965Sjdp      struct debug_variable *variable;
50733965Sjdp      /* DEBUG_OBJECT_FUNCTION.  */
50833965Sjdp      struct debug_function *function;
50933965Sjdp      /* DEBUG_OBJECT_INT_CONSTANT.  */
51033965Sjdp      bfd_vma int_constant;
51133965Sjdp      /* DEBUG_OBJECT_FLOAT_CONSTANT.  */
51233965Sjdp      double float_constant;
51333965Sjdp      /* DEBUG_OBJECT_TYPED_CONSTANT.  */
51433965Sjdp      struct debug_typed_constant *typed_constant;
51533965Sjdp    } u;
51633965Sjdp};
51733965Sjdp
51833965Sjdp/* During debug_write, a linked list of these structures is used to
51933965Sjdp   keep track of ID numbers that have been assigned to classes.  */
52033965Sjdp
52133965Sjdpstruct debug_class_id
52233965Sjdp{
52333965Sjdp  /* Next ID number.  */
52433965Sjdp  struct debug_class_id *next;
52533965Sjdp  /* The type with the ID.  */
52633965Sjdp  struct debug_type *type;
52733965Sjdp  /* The tag; NULL if no tag.  */
52833965Sjdp  const char *tag;
52933965Sjdp};
53033965Sjdp
53133965Sjdp/* During debug_type_samep, a linked list of these structures is kept
53233965Sjdp   on the stack to avoid infinite recursion.  */
53333965Sjdp
53433965Sjdpstruct debug_type_compare_list
53533965Sjdp{
53633965Sjdp  /* Next type on list.  */
53733965Sjdp  struct debug_type_compare_list *next;
53833965Sjdp  /* The types we are comparing.  */
53933965Sjdp  struct debug_type *t1;
54033965Sjdp  struct debug_type *t2;
54133965Sjdp};
54233965Sjdp
54360484Sobrien/* During debug_get_real_type, a linked list of these structures is
54460484Sobrien   kept on the stack to avoid infinite recursion.  */
54560484Sobrien
54660484Sobrienstruct debug_type_real_list
54760484Sobrien{
54860484Sobrien  /* Next type on list.  */
54960484Sobrien  struct debug_type_real_list *next;
55060484Sobrien  /* The type we are checking.  */
55160484Sobrien  struct debug_type *t;
55260484Sobrien};
55360484Sobrien
55433965Sjdp/* Local functions.  */
55533965Sjdp
556130561Sobrienstatic void debug_error (const char *);
55733965Sjdpstatic struct debug_name *debug_add_to_namespace
558130561Sobrien  (struct debug_handle *, struct debug_namespace **, const char *,
559130561Sobrien   enum debug_object_kind, enum debug_object_linkage);
56033965Sjdpstatic struct debug_name *debug_add_to_current_namespace
561130561Sobrien  (struct debug_handle *, const char *, enum debug_object_kind,
562130561Sobrien   enum debug_object_linkage);
56333965Sjdpstatic struct debug_type *debug_make_type
564130561Sobrien  (struct debug_handle *, enum debug_type_kind, unsigned int);
56560484Sobrienstatic struct debug_type *debug_get_real_type
566130561Sobrien  (void *, debug_type, struct debug_type_real_list *);
567130561Sobrienstatic bfd_boolean debug_write_name
568130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *,
569130561Sobrien   struct debug_name *);
570130561Sobrienstatic bfd_boolean debug_write_type
571130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *,
572130561Sobrien   struct debug_type *, struct debug_name *);
573130561Sobrienstatic bfd_boolean debug_write_class_type
574130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *,
575130561Sobrien   struct debug_type *, const char *);
576130561Sobrienstatic bfd_boolean debug_write_function
577130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *,
578130561Sobrien   const char *, enum debug_object_linkage, struct debug_function *);
579130561Sobrienstatic bfd_boolean debug_write_block
580130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *,
581130561Sobrien   struct debug_block *);
582130561Sobrienstatic bfd_boolean debug_write_linenos
583130561Sobrien  (struct debug_handle *, const struct debug_write_fns *, void *, bfd_vma);
584130561Sobrienstatic bfd_boolean debug_set_class_id
585130561Sobrien  (struct debug_handle *, const char *, struct debug_type *);
586130561Sobrienstatic bfd_boolean debug_type_samep
587130561Sobrien  (struct debug_handle *, struct debug_type *, struct debug_type *);
588130561Sobrienstatic bfd_boolean debug_class_type_samep
589130561Sobrien  (struct debug_handle *, struct debug_type *, struct debug_type *);
59033965Sjdp
59133965Sjdp/* Issue an error message.  */
59233965Sjdp
59333965Sjdpstatic void
594130561Sobriendebug_error (const char *message)
59533965Sjdp{
59633965Sjdp  fprintf (stderr, "%s\n", message);
59733965Sjdp}
59833965Sjdp
59933965Sjdp/* Add an object to a namespace.  */
60033965Sjdp
60133965Sjdpstatic struct debug_name *
602130561Sobriendebug_add_to_namespace (struct debug_handle *info ATTRIBUTE_UNUSED,
603130561Sobrien			struct debug_namespace **nsp, const char *name,
604130561Sobrien			enum debug_object_kind kind,
605130561Sobrien			enum debug_object_linkage linkage)
60633965Sjdp{
60733965Sjdp  struct debug_name *n;
60833965Sjdp  struct debug_namespace *ns;
60933965Sjdp
61033965Sjdp  n = (struct debug_name *) xmalloc (sizeof *n);
61133965Sjdp  memset (n, 0, sizeof *n);
61233965Sjdp
61333965Sjdp  n->name = name;
61433965Sjdp  n->kind = kind;
61533965Sjdp  n->linkage = linkage;
61633965Sjdp
61733965Sjdp  ns = *nsp;
61833965Sjdp  if (ns == NULL)
61933965Sjdp    {
62033965Sjdp      ns = (struct debug_namespace *) xmalloc (sizeof *ns);
62133965Sjdp      memset (ns, 0, sizeof *ns);
62233965Sjdp
62333965Sjdp      ns->tail = &ns->list;
62433965Sjdp
62533965Sjdp      *nsp = ns;
62633965Sjdp    }
62733965Sjdp
62833965Sjdp  *ns->tail = n;
62933965Sjdp  ns->tail = &n->next;
63033965Sjdp
63133965Sjdp  return n;
63233965Sjdp}
63333965Sjdp
63433965Sjdp/* Add an object to the current namespace.  */
63533965Sjdp
63633965Sjdpstatic struct debug_name *
637130561Sobriendebug_add_to_current_namespace (struct debug_handle *info, const char *name,
638130561Sobrien				enum debug_object_kind kind,
639130561Sobrien				enum debug_object_linkage linkage)
64033965Sjdp{
64133965Sjdp  struct debug_namespace **nsp;
64233965Sjdp
64333965Sjdp  if (info->current_unit == NULL
64433965Sjdp      || info->current_file == NULL)
64533965Sjdp    {
64660484Sobrien      debug_error (_("debug_add_to_current_namespace: no current file"));
64733965Sjdp      return NULL;
64833965Sjdp    }
64933965Sjdp
65033965Sjdp  if (info->current_block != NULL)
65133965Sjdp    nsp = &info->current_block->locals;
65233965Sjdp  else
65333965Sjdp    nsp = &info->current_file->globals;
65433965Sjdp
65533965Sjdp  return debug_add_to_namespace (info, nsp, name, kind, linkage);
65633965Sjdp}
65733965Sjdp
65833965Sjdp/* Return a handle for debugging information.  */
65933965Sjdp
660130561Sobrienvoid *
661130561Sobriendebug_init (void)
66233965Sjdp{
66333965Sjdp  struct debug_handle *ret;
66433965Sjdp
66533965Sjdp  ret = (struct debug_handle *) xmalloc (sizeof *ret);
66633965Sjdp  memset (ret, 0, sizeof *ret);
667130561Sobrien  return (void *) ret;
66833965Sjdp}
66933965Sjdp
67033965Sjdp/* Set the source filename.  This implicitly starts a new compilation
67133965Sjdp   unit.  */
67233965Sjdp
673130561Sobrienbfd_boolean
674130561Sobriendebug_set_filename (void *handle, const char *name)
67533965Sjdp{
67633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
67733965Sjdp  struct debug_file *nfile;
67833965Sjdp  struct debug_unit *nunit;
67933965Sjdp
68033965Sjdp  if (name == NULL)
68133965Sjdp    name = "";
68233965Sjdp
68333965Sjdp  nfile = (struct debug_file *) xmalloc (sizeof *nfile);
68433965Sjdp  memset (nfile, 0, sizeof *nfile);
68533965Sjdp
68633965Sjdp  nfile->filename = name;
68733965Sjdp
68833965Sjdp  nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
68933965Sjdp  memset (nunit, 0, sizeof *nunit);
69033965Sjdp
69133965Sjdp  nunit->files = nfile;
69233965Sjdp  info->current_file = nfile;
69333965Sjdp
69433965Sjdp  if (info->current_unit != NULL)
69533965Sjdp    info->current_unit->next = nunit;
69633965Sjdp  else
69733965Sjdp    {
69833965Sjdp      assert (info->units == NULL);
69933965Sjdp      info->units = nunit;
70033965Sjdp    }
70133965Sjdp
70233965Sjdp  info->current_unit = nunit;
70333965Sjdp
70433965Sjdp  info->current_function = NULL;
70533965Sjdp  info->current_block = NULL;
70633965Sjdp  info->current_lineno = NULL;
70733965Sjdp
708130561Sobrien  return TRUE;
70933965Sjdp}
71033965Sjdp
71133965Sjdp/* Change source files to the given file name.  This is used for
71233965Sjdp   include files in a single compilation unit.  */
71333965Sjdp
714130561Sobrienbfd_boolean
715130561Sobriendebug_start_source (void *handle, const char *name)
71633965Sjdp{
71733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
71833965Sjdp  struct debug_file *f, **pf;
71933965Sjdp
72033965Sjdp  if (name == NULL)
72133965Sjdp    name = "";
72233965Sjdp
72333965Sjdp  if (info->current_unit == NULL)
72433965Sjdp    {
72560484Sobrien      debug_error (_("debug_start_source: no debug_set_filename call"));
726130561Sobrien      return FALSE;
72733965Sjdp    }
72833965Sjdp
72933965Sjdp  for (f = info->current_unit->files; f != NULL; f = f->next)
73033965Sjdp    {
73133965Sjdp      if (f->filename[0] == name[0]
73233965Sjdp	  && f->filename[1] == name[1]
73333965Sjdp	  && strcmp (f->filename, name) == 0)
73433965Sjdp	{
73533965Sjdp	  info->current_file = f;
736130561Sobrien	  return TRUE;
73733965Sjdp	}
73833965Sjdp    }
73933965Sjdp
74033965Sjdp  f = (struct debug_file *) xmalloc (sizeof *f);
74133965Sjdp  memset (f, 0, sizeof *f);
74233965Sjdp
74333965Sjdp  f->filename = name;
74433965Sjdp
74533965Sjdp  for (pf = &info->current_file->next;
74633965Sjdp       *pf != NULL;
74733965Sjdp       pf = &(*pf)->next)
74833965Sjdp    ;
74933965Sjdp  *pf = f;
75033965Sjdp
75133965Sjdp  info->current_file = f;
75233965Sjdp
753130561Sobrien  return TRUE;
75433965Sjdp}
75533965Sjdp
75633965Sjdp/* Record a function definition.  This implicitly starts a function
75733965Sjdp   block.  The debug_type argument is the type of the return value.
75833965Sjdp   The boolean indicates whether the function is globally visible.
75933965Sjdp   The bfd_vma is the address of the start of the function.  Currently
76033965Sjdp   the parameter types are specified by calls to
76133965Sjdp   debug_record_parameter.  FIXME: There is no way to specify nested
76233965Sjdp   functions.  */
76333965Sjdp
764130561Sobrienbfd_boolean
765130561Sobriendebug_record_function (void *handle, const char *name,
766130561Sobrien		       debug_type return_type, bfd_boolean global,
767130561Sobrien		       bfd_vma addr)
76833965Sjdp{
76933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
77033965Sjdp  struct debug_function *f;
77133965Sjdp  struct debug_block *b;
77233965Sjdp  struct debug_name *n;
77333965Sjdp
77433965Sjdp  if (name == NULL)
77533965Sjdp    name = "";
77633965Sjdp  if (return_type == NULL)
777130561Sobrien    return FALSE;
77833965Sjdp
77933965Sjdp  if (info->current_unit == NULL)
78033965Sjdp    {
78160484Sobrien      debug_error (_("debug_record_function: no debug_set_filename call"));
782130561Sobrien      return FALSE;
78333965Sjdp    }
78433965Sjdp
78533965Sjdp  f = (struct debug_function *) xmalloc (sizeof *f);
78633965Sjdp  memset (f, 0, sizeof *f);
78733965Sjdp
78833965Sjdp  f->return_type = return_type;
78933965Sjdp
79033965Sjdp  b = (struct debug_block *) xmalloc (sizeof *b);
79133965Sjdp  memset (b, 0, sizeof *b);
79233965Sjdp
79333965Sjdp  b->start = addr;
79433965Sjdp  b->end = (bfd_vma) -1;
79533965Sjdp
79633965Sjdp  f->blocks = b;
79733965Sjdp
79833965Sjdp  info->current_function = f;
79933965Sjdp  info->current_block = b;
80033965Sjdp
80133965Sjdp  /* FIXME: If we could handle nested functions, this would be the
80233965Sjdp     place: we would want to use a different namespace.  */
80333965Sjdp  n = debug_add_to_namespace (info,
80433965Sjdp			      &info->current_file->globals,
80533965Sjdp			      name,
80633965Sjdp			      DEBUG_OBJECT_FUNCTION,
80733965Sjdp			      (global
80833965Sjdp			       ? DEBUG_LINKAGE_GLOBAL
80933965Sjdp			       : DEBUG_LINKAGE_STATIC));
81033965Sjdp  if (n == NULL)
811130561Sobrien    return FALSE;
81233965Sjdp
81333965Sjdp  n->u.function = f;
81433965Sjdp
815130561Sobrien  return TRUE;
81633965Sjdp}
81733965Sjdp
81833965Sjdp/* Record a parameter for the current function.  */
81933965Sjdp
820130561Sobrienbfd_boolean
821130561Sobriendebug_record_parameter (void *handle, const char *name, debug_type type,
822130561Sobrien			enum debug_parm_kind kind, bfd_vma val)
82333965Sjdp{
82433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
82533965Sjdp  struct debug_parameter *p, **pp;
82633965Sjdp
82733965Sjdp  if (name == NULL || type == NULL)
828130561Sobrien    return FALSE;
82933965Sjdp
83033965Sjdp  if (info->current_unit == NULL
83133965Sjdp      || info->current_function == NULL)
83233965Sjdp    {
83360484Sobrien      debug_error (_("debug_record_parameter: no current function"));
834130561Sobrien      return FALSE;
83533965Sjdp    }
83633965Sjdp
83733965Sjdp  p = (struct debug_parameter *) xmalloc (sizeof *p);
83833965Sjdp  memset (p, 0, sizeof *p);
83933965Sjdp
84033965Sjdp  p->name = name;
84133965Sjdp  p->type = type;
84233965Sjdp  p->kind = kind;
84333965Sjdp  p->val = val;
84433965Sjdp
84533965Sjdp  for (pp = &info->current_function->parameters;
84633965Sjdp       *pp != NULL;
84733965Sjdp       pp = &(*pp)->next)
84833965Sjdp    ;
84933965Sjdp  *pp = p;
85033965Sjdp
851130561Sobrien  return TRUE;
85233965Sjdp}
85333965Sjdp
85433965Sjdp/* End a function.  FIXME: This should handle function nesting.  */
85533965Sjdp
856130561Sobrienbfd_boolean
857130561Sobriendebug_end_function (void *handle, bfd_vma addr)
85833965Sjdp{
85933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
86033965Sjdp
86133965Sjdp  if (info->current_unit == NULL
86233965Sjdp      || info->current_block == NULL
86333965Sjdp      || info->current_function == NULL)
86433965Sjdp    {
86560484Sobrien      debug_error (_("debug_end_function: no current function"));
866130561Sobrien      return FALSE;
86733965Sjdp    }
86833965Sjdp
86933965Sjdp  if (info->current_block->parent != NULL)
87033965Sjdp    {
87160484Sobrien      debug_error (_("debug_end_function: some blocks were not closed"));
872130561Sobrien      return FALSE;
87333965Sjdp    }
87433965Sjdp
87533965Sjdp  info->current_block->end = addr;
87633965Sjdp
87733965Sjdp  info->current_function = NULL;
87833965Sjdp  info->current_block = NULL;
87933965Sjdp
880130561Sobrien  return TRUE;
88133965Sjdp}
88233965Sjdp
88333965Sjdp/* Start a block in a function.  All local information will be
88433965Sjdp   recorded in this block, until the matching call to debug_end_block.
88533965Sjdp   debug_start_block and debug_end_block may be nested.  The bfd_vma
88633965Sjdp   argument is the address at which this block starts.  */
88733965Sjdp
888130561Sobrienbfd_boolean
889130561Sobriendebug_start_block (void *handle, bfd_vma addr)
89033965Sjdp{
89133965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
89233965Sjdp  struct debug_block *b, **pb;
89333965Sjdp
89433965Sjdp  /* We must always have a current block: debug_record_function sets
89533965Sjdp     one up.  */
89633965Sjdp  if (info->current_unit == NULL
89733965Sjdp      || info->current_block == NULL)
89833965Sjdp    {
89960484Sobrien      debug_error (_("debug_start_block: no current block"));
900130561Sobrien      return FALSE;
90133965Sjdp    }
90233965Sjdp
90333965Sjdp  b = (struct debug_block *) xmalloc (sizeof *b);
90433965Sjdp  memset (b, 0, sizeof *b);
90533965Sjdp
90633965Sjdp  b->parent = info->current_block;
90733965Sjdp  b->start = addr;
90833965Sjdp  b->end = (bfd_vma) -1;
90933965Sjdp
91033965Sjdp  /* This new block is a child of the current block.  */
91133965Sjdp  for (pb = &info->current_block->children;
91233965Sjdp       *pb != NULL;
91333965Sjdp       pb = &(*pb)->next)
91433965Sjdp    ;
91533965Sjdp  *pb = b;
91633965Sjdp
91733965Sjdp  info->current_block = b;
91833965Sjdp
919130561Sobrien  return TRUE;
92033965Sjdp}
92133965Sjdp
92233965Sjdp/* Finish a block in a function.  This matches the call to
92333965Sjdp   debug_start_block.  The argument is the address at which this block
92433965Sjdp   ends.  */
92533965Sjdp
926130561Sobrienbfd_boolean
927130561Sobriendebug_end_block (void *handle, bfd_vma addr)
92833965Sjdp{
92933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
93033965Sjdp  struct debug_block *parent;
93133965Sjdp
93233965Sjdp  if (info->current_unit == NULL
93333965Sjdp      || info->current_block == NULL)
93433965Sjdp    {
93560484Sobrien      debug_error (_("debug_end_block: no current block"));
936130561Sobrien      return FALSE;
93733965Sjdp    }
93833965Sjdp
93933965Sjdp  parent = info->current_block->parent;
94033965Sjdp  if (parent == NULL)
94133965Sjdp    {
94260484Sobrien      debug_error (_("debug_end_block: attempt to close top level block"));
943130561Sobrien      return FALSE;
94433965Sjdp    }
94533965Sjdp
94633965Sjdp  info->current_block->end = addr;
94733965Sjdp
94833965Sjdp  info->current_block = parent;
94933965Sjdp
950130561Sobrien  return TRUE;
95133965Sjdp}
95233965Sjdp
95333965Sjdp/* Associate a line number in the current source file and function
95433965Sjdp   with a given address.  */
95533965Sjdp
956130561Sobrienbfd_boolean
957130561Sobriendebug_record_line (void *handle, unsigned long lineno, bfd_vma addr)
95833965Sjdp{
95933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
96033965Sjdp  struct debug_lineno *l;
96133965Sjdp  unsigned int i;
96233965Sjdp
96333965Sjdp  if (info->current_unit == NULL)
96433965Sjdp    {
96560484Sobrien      debug_error (_("debug_record_line: no current unit"));
966130561Sobrien      return FALSE;
96733965Sjdp    }
96833965Sjdp
96933965Sjdp  l = info->current_lineno;
97033965Sjdp  if (l != NULL && l->file == info->current_file)
97133965Sjdp    {
97233965Sjdp      for (i = 0; i < DEBUG_LINENO_COUNT; i++)
97333965Sjdp	{
97433965Sjdp	  if (l->linenos[i] == (unsigned long) -1)
97533965Sjdp	    {
97633965Sjdp	      l->linenos[i] = lineno;
97733965Sjdp	      l->addrs[i] = addr;
978130561Sobrien	      return TRUE;
97933965Sjdp	    }
98033965Sjdp	}
98133965Sjdp    }
98233965Sjdp
98333965Sjdp  /* If we get here, then either 1) there is no current_lineno
98433965Sjdp     structure, which means this is the first line number in this
98533965Sjdp     compilation unit, 2) the current_lineno structure is for a
98633965Sjdp     different file, or 3) the current_lineno structure is full.
98733965Sjdp     Regardless, we want to allocate a new debug_lineno structure, put
98833965Sjdp     it in the right place, and make it the new current_lineno
98933965Sjdp     structure.  */
99033965Sjdp
99133965Sjdp  l = (struct debug_lineno *) xmalloc (sizeof *l);
99233965Sjdp  memset (l, 0, sizeof *l);
99333965Sjdp
99433965Sjdp  l->file = info->current_file;
99533965Sjdp  l->linenos[0] = lineno;
99633965Sjdp  l->addrs[0] = addr;
99733965Sjdp  for (i = 1; i < DEBUG_LINENO_COUNT; i++)
99833965Sjdp    l->linenos[i] = (unsigned long) -1;
99933965Sjdp
100033965Sjdp  if (info->current_lineno != NULL)
100133965Sjdp    info->current_lineno->next = l;
100233965Sjdp  else
100333965Sjdp    info->current_unit->linenos = l;
100433965Sjdp
100533965Sjdp  info->current_lineno = l;
100633965Sjdp
1007130561Sobrien  return TRUE;
100833965Sjdp}
100933965Sjdp
101033965Sjdp/* Start a named common block.  This is a block of variables that may
101133965Sjdp   move in memory.  */
101233965Sjdp
1013130561Sobrienbfd_boolean
1014130561Sobriendebug_start_common_block (void *handle ATTRIBUTE_UNUSED,
1015130561Sobrien			  const char *name ATTRIBUTE_UNUSED)
101633965Sjdp{
101733965Sjdp  /* FIXME */
101860484Sobrien  debug_error (_("debug_start_common_block: not implemented"));
1019130561Sobrien  return FALSE;
102033965Sjdp}
102133965Sjdp
102233965Sjdp/* End a named common block.  */
102333965Sjdp
1024130561Sobrienbfd_boolean
1025130561Sobriendebug_end_common_block (void *handle ATTRIBUTE_UNUSED,
1026130561Sobrien			const char *name ATTRIBUTE_UNUSED)
102733965Sjdp{
102833965Sjdp  /* FIXME */
102960484Sobrien  debug_error (_("debug_end_common_block: not implemented"));
1030130561Sobrien  return FALSE;
103133965Sjdp}
103233965Sjdp
103333965Sjdp/* Record a named integer constant.  */
103433965Sjdp
1035130561Sobrienbfd_boolean
1036130561Sobriendebug_record_int_const (void *handle, const char *name, bfd_vma val)
103733965Sjdp{
103833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
103933965Sjdp  struct debug_name *n;
104033965Sjdp
104133965Sjdp  if (name == NULL)
1042130561Sobrien    return FALSE;
104333965Sjdp
104433965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
104533965Sjdp				      DEBUG_LINKAGE_NONE);
104633965Sjdp  if (n == NULL)
1047130561Sobrien    return FALSE;
104833965Sjdp
104933965Sjdp  n->u.int_constant = val;
105033965Sjdp
1051130561Sobrien  return TRUE;
105233965Sjdp}
105333965Sjdp
105433965Sjdp/* Record a named floating point constant.  */
105533965Sjdp
1056130561Sobrienbfd_boolean
1057130561Sobriendebug_record_float_const (void *handle, const char *name, double val)
105833965Sjdp{
105933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
106033965Sjdp  struct debug_name *n;
106133965Sjdp
106233965Sjdp  if (name == NULL)
1063130561Sobrien    return FALSE;
106433965Sjdp
106533965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
106633965Sjdp				      DEBUG_LINKAGE_NONE);
106733965Sjdp  if (n == NULL)
1068130561Sobrien    return FALSE;
106933965Sjdp
107033965Sjdp  n->u.float_constant = val;
107133965Sjdp
1072130561Sobrien  return TRUE;
107333965Sjdp}
107433965Sjdp
107533965Sjdp/* Record a typed constant with an integral value.  */
107633965Sjdp
1077130561Sobrienbfd_boolean
1078130561Sobriendebug_record_typed_const (void *handle, const char *name, debug_type type,
1079130561Sobrien			  bfd_vma val)
108033965Sjdp{
108133965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
108233965Sjdp  struct debug_name *n;
108333965Sjdp  struct debug_typed_constant *tc;
108433965Sjdp
108533965Sjdp  if (name == NULL || type == NULL)
1086130561Sobrien    return FALSE;
108733965Sjdp
108833965Sjdp  n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
108933965Sjdp				      DEBUG_LINKAGE_NONE);
109033965Sjdp  if (n == NULL)
1091130561Sobrien    return FALSE;
109233965Sjdp
109333965Sjdp  tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
109433965Sjdp  memset (tc, 0, sizeof *tc);
109533965Sjdp
109633965Sjdp  tc->type = type;
109733965Sjdp  tc->val = val;
109833965Sjdp
109933965Sjdp  n->u.typed_constant = tc;
110033965Sjdp
1101130561Sobrien  return TRUE;
110233965Sjdp}
110333965Sjdp
110433965Sjdp/* Record a label.  */
110533965Sjdp
1106130561Sobrienbfd_boolean
1107130561Sobriendebug_record_label (void *handle ATTRIBUTE_UNUSED,
1108130561Sobrien		    const char *name ATTRIBUTE_UNUSED,
1109130561Sobrien		    debug_type type ATTRIBUTE_UNUSED,
1110130561Sobrien		    bfd_vma addr ATTRIBUTE_UNUSED)
111133965Sjdp{
111233965Sjdp  /* FIXME.  */
1113104834Sobrien  debug_error (_("debug_record_label: not implemented"));
1114130561Sobrien  return FALSE;
111533965Sjdp}
111633965Sjdp
111733965Sjdp/* Record a variable.  */
111833965Sjdp
1119130561Sobrienbfd_boolean
1120130561Sobriendebug_record_variable (void *handle, const char *name, debug_type type,
1121130561Sobrien		       enum debug_var_kind kind, bfd_vma val)
112233965Sjdp{
112333965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
112433965Sjdp  struct debug_namespace **nsp;
112533965Sjdp  enum debug_object_linkage linkage;
112633965Sjdp  struct debug_name *n;
112733965Sjdp  struct debug_variable *v;
112833965Sjdp
112933965Sjdp  if (name == NULL || type == NULL)
1130130561Sobrien    return FALSE;
113133965Sjdp
113233965Sjdp  if (info->current_unit == NULL
113333965Sjdp      || info->current_file == NULL)
113433965Sjdp    {
113560484Sobrien      debug_error (_("debug_record_variable: no current file"));
1136130561Sobrien      return FALSE;
113733965Sjdp    }
113833965Sjdp
113933965Sjdp  if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
114033965Sjdp    {
114133965Sjdp      nsp = &info->current_file->globals;
114233965Sjdp      if (kind == DEBUG_GLOBAL)
114333965Sjdp	linkage = DEBUG_LINKAGE_GLOBAL;
114433965Sjdp      else
114533965Sjdp	linkage = DEBUG_LINKAGE_STATIC;
114633965Sjdp    }
114733965Sjdp  else
114833965Sjdp    {
114933965Sjdp      if (info->current_block == NULL)
1150130561Sobrien	nsp = &info->current_file->globals;
1151130561Sobrien      else
1152130561Sobrien	nsp = &info->current_block->locals;
115333965Sjdp      linkage = DEBUG_LINKAGE_AUTOMATIC;
115433965Sjdp    }
115533965Sjdp
115633965Sjdp  n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
115733965Sjdp  if (n == NULL)
1158130561Sobrien    return FALSE;
115933965Sjdp
116033965Sjdp  v = (struct debug_variable *) xmalloc (sizeof *v);
116133965Sjdp  memset (v, 0, sizeof *v);
116233965Sjdp
116333965Sjdp  v->kind = kind;
116433965Sjdp  v->type = type;
116533965Sjdp  v->val = val;
116633965Sjdp
116733965Sjdp  n->u.variable = v;
116833965Sjdp
1169130561Sobrien  return TRUE;
117033965Sjdp}
117133965Sjdp
117233965Sjdp/* Make a type with a given kind and size.  */
117333965Sjdp
117433965Sjdpstatic struct debug_type *
1175130561Sobriendebug_make_type (struct debug_handle *info ATTRIBUTE_UNUSED,
1176130561Sobrien		 enum debug_type_kind kind, unsigned int size)
117733965Sjdp{
117833965Sjdp  struct debug_type *t;
117933965Sjdp
118033965Sjdp  t = (struct debug_type *) xmalloc (sizeof *t);
118133965Sjdp  memset (t, 0, sizeof *t);
118233965Sjdp
118333965Sjdp  t->kind = kind;
118433965Sjdp  t->size = size;
118533965Sjdp
118633965Sjdp  return t;
118733965Sjdp}
118833965Sjdp
118933965Sjdp/* Make an indirect type which may be used as a placeholder for a type
119033965Sjdp   which is referenced before it is defined.  */
119133965Sjdp
119233965Sjdpdebug_type
1193130561Sobriendebug_make_indirect_type (void *handle, debug_type *slot, const char *tag)
119433965Sjdp{
119533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
119633965Sjdp  struct debug_type *t;
119733965Sjdp  struct debug_indirect_type *i;
119833965Sjdp
119933965Sjdp  t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
120033965Sjdp  if (t == NULL)
120133965Sjdp    return DEBUG_TYPE_NULL;
120233965Sjdp
120333965Sjdp  i = (struct debug_indirect_type *) xmalloc (sizeof *i);
120433965Sjdp  memset (i, 0, sizeof *i);
120533965Sjdp
120633965Sjdp  i->slot = slot;
120733965Sjdp  i->tag = tag;
120833965Sjdp
120933965Sjdp  t->u.kindirect = i;
121033965Sjdp
121133965Sjdp  return t;
121233965Sjdp}
121333965Sjdp
121433965Sjdp/* Make a void type.  There is only one of these.  */
121533965Sjdp
121633965Sjdpdebug_type
1217130561Sobriendebug_make_void_type (void *handle)
121833965Sjdp{
121933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
122033965Sjdp
122133965Sjdp  return debug_make_type (info, DEBUG_KIND_VOID, 0);
122233965Sjdp}
122333965Sjdp
122433965Sjdp/* Make an integer type of a given size.  The boolean argument is true
122533965Sjdp   if the integer is unsigned.  */
122633965Sjdp
122733965Sjdpdebug_type
1228130561Sobriendebug_make_int_type (void *handle, unsigned int size, bfd_boolean unsignedp)
122933965Sjdp{
123033965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
123133965Sjdp  struct debug_type *t;
123233965Sjdp
123333965Sjdp  t = debug_make_type (info, DEBUG_KIND_INT, size);
123433965Sjdp  if (t == NULL)
123533965Sjdp    return DEBUG_TYPE_NULL;
123633965Sjdp
123733965Sjdp  t->u.kint = unsignedp;
123833965Sjdp
123933965Sjdp  return t;
124033965Sjdp}
124133965Sjdp
124233965Sjdp/* Make a floating point type of a given size.  FIXME: On some
124333965Sjdp   platforms, like an Alpha, you probably need to be able to specify
124433965Sjdp   the format.  */
124533965Sjdp
124633965Sjdpdebug_type
1247130561Sobriendebug_make_float_type (void *handle, unsigned int size)
124833965Sjdp{
124933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
125033965Sjdp
125133965Sjdp  return debug_make_type (info, DEBUG_KIND_FLOAT, size);
125233965Sjdp}
125333965Sjdp
125433965Sjdp/* Make a boolean type of a given size.  */
125533965Sjdp
125633965Sjdpdebug_type
1257130561Sobriendebug_make_bool_type (void *handle, unsigned int size)
125833965Sjdp{
125933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
126033965Sjdp
126133965Sjdp  return debug_make_type (info, DEBUG_KIND_BOOL, size);
126233965Sjdp}
126333965Sjdp
126433965Sjdp/* Make a complex type of a given size.  */
126533965Sjdp
126633965Sjdpdebug_type
1267130561Sobriendebug_make_complex_type (void *handle, unsigned int size)
126833965Sjdp{
126933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
127033965Sjdp
127133965Sjdp  return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
127233965Sjdp}
127333965Sjdp
127433965Sjdp/* Make a structure type.  The second argument is true for a struct,
127533965Sjdp   false for a union.  The third argument is the size of the struct.
127633965Sjdp   The fourth argument is a NULL terminated array of fields.  */
127733965Sjdp
127833965Sjdpdebug_type
1279130561Sobriendebug_make_struct_type (void *handle, bfd_boolean structp, bfd_vma size,
1280130561Sobrien			debug_field *fields)
128133965Sjdp{
128233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
128333965Sjdp  struct debug_type *t;
128433965Sjdp  struct debug_class_type *c;
128533965Sjdp
128633965Sjdp  t = debug_make_type (info,
128733965Sjdp		       structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
128833965Sjdp		       size);
128933965Sjdp  if (t == NULL)
129033965Sjdp    return DEBUG_TYPE_NULL;
129133965Sjdp
129233965Sjdp  c = (struct debug_class_type *) xmalloc (sizeof *c);
129333965Sjdp  memset (c, 0, sizeof *c);
129433965Sjdp
129533965Sjdp  c->fields = fields;
129633965Sjdp
129733965Sjdp  t->u.kclass = c;
129833965Sjdp
129933965Sjdp  return t;
130033965Sjdp}
130133965Sjdp
130233965Sjdp/* Make an object type.  The first three arguments after the handle
130333965Sjdp   are the same as for debug_make_struct_type.  The next arguments are
130433965Sjdp   a NULL terminated array of base classes, a NULL terminated array of
130533965Sjdp   methods, the type of the object holding the virtual function table
130633965Sjdp   if it is not this object, and a boolean which is true if this
130733965Sjdp   object has its own virtual function table.  */
130833965Sjdp
130933965Sjdpdebug_type
1310130561Sobriendebug_make_object_type (void *handle, bfd_boolean structp, bfd_vma size,
1311130561Sobrien			debug_field *fields, debug_baseclass *baseclasses,
1312130561Sobrien			debug_method *methods, debug_type vptrbase,
1313130561Sobrien			bfd_boolean ownvptr)
131433965Sjdp{
131533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
131633965Sjdp  struct debug_type *t;
131733965Sjdp  struct debug_class_type *c;
131833965Sjdp
131933965Sjdp  t = debug_make_type (info,
132033965Sjdp		       structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
132133965Sjdp		       size);
132233965Sjdp  if (t == NULL)
132333965Sjdp    return DEBUG_TYPE_NULL;
132433965Sjdp
132533965Sjdp  c = (struct debug_class_type *) xmalloc (sizeof *c);
132633965Sjdp  memset (c, 0, sizeof *c);
132733965Sjdp
132833965Sjdp  c->fields = fields;
132933965Sjdp  c->baseclasses = baseclasses;
133033965Sjdp  c->methods = methods;
133133965Sjdp  if (ownvptr)
133233965Sjdp    c->vptrbase = t;
133333965Sjdp  else
133433965Sjdp    c->vptrbase = vptrbase;
133533965Sjdp
133633965Sjdp  t->u.kclass = c;
133733965Sjdp
133833965Sjdp  return t;
133933965Sjdp}
134033965Sjdp
134133965Sjdp/* Make an enumeration type.  The arguments are a null terminated
134233965Sjdp   array of strings, and an array of corresponding values.  */
134333965Sjdp
134433965Sjdpdebug_type
1345130561Sobriendebug_make_enum_type (void *handle, const char **names,
1346130561Sobrien		      bfd_signed_vma *values)
134733965Sjdp{
134833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
134933965Sjdp  struct debug_type *t;
135033965Sjdp  struct debug_enum_type *e;
135133965Sjdp
135233965Sjdp  t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
135333965Sjdp  if (t == NULL)
135433965Sjdp    return DEBUG_TYPE_NULL;
135533965Sjdp
135633965Sjdp  e = (struct debug_enum_type *) xmalloc (sizeof *e);
135733965Sjdp  memset (e, 0, sizeof *e);
135833965Sjdp
135933965Sjdp  e->names = names;
136033965Sjdp  e->values = values;
136133965Sjdp
136233965Sjdp  t->u.kenum = e;
136333965Sjdp
136433965Sjdp  return t;
136533965Sjdp}
136633965Sjdp
136733965Sjdp/* Make a pointer to a given type.  */
136833965Sjdp
136933965Sjdpdebug_type
1370130561Sobriendebug_make_pointer_type (void *handle, debug_type type)
137133965Sjdp{
137233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
137333965Sjdp  struct debug_type *t;
137433965Sjdp
137533965Sjdp  if (type == NULL)
137633965Sjdp    return DEBUG_TYPE_NULL;
137733965Sjdp
137833965Sjdp  if (type->pointer != DEBUG_TYPE_NULL)
137933965Sjdp    return type->pointer;
138033965Sjdp
138133965Sjdp  t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
138233965Sjdp  if (t == NULL)
138333965Sjdp    return DEBUG_TYPE_NULL;
138433965Sjdp
138533965Sjdp  t->u.kpointer = type;
138633965Sjdp
138733965Sjdp  type->pointer = t;
138833965Sjdp
138933965Sjdp  return t;
139033965Sjdp}
139133965Sjdp
139233965Sjdp/* Make a function returning a given type.  FIXME: We should be able
139333965Sjdp   to record the parameter types.  */
139433965Sjdp
139533965Sjdpdebug_type
1396130561Sobriendebug_make_function_type (void *handle, debug_type type,
1397130561Sobrien			  debug_type *arg_types, bfd_boolean varargs)
139833965Sjdp{
139933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
140033965Sjdp  struct debug_type *t;
140133965Sjdp  struct debug_function_type *f;
140233965Sjdp
140333965Sjdp  if (type == NULL)
140433965Sjdp    return DEBUG_TYPE_NULL;
140533965Sjdp
140633965Sjdp  t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
140733965Sjdp  if (t == NULL)
140833965Sjdp    return DEBUG_TYPE_NULL;
140933965Sjdp
141033965Sjdp  f = (struct debug_function_type *) xmalloc (sizeof *f);
141133965Sjdp  memset (f, 0, sizeof *f);
141233965Sjdp
141333965Sjdp  f->return_type = type;
141433965Sjdp  f->arg_types = arg_types;
141533965Sjdp  f->varargs = varargs;
141633965Sjdp
141733965Sjdp  t->u.kfunction = f;
141833965Sjdp
141933965Sjdp  return t;
142033965Sjdp}
142133965Sjdp
142233965Sjdp/* Make a reference to a given type.  */
142333965Sjdp
142433965Sjdpdebug_type
1425130561Sobriendebug_make_reference_type (void *handle, debug_type type)
142633965Sjdp{
142733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
142833965Sjdp  struct debug_type *t;
142933965Sjdp
143033965Sjdp  if (type == NULL)
143133965Sjdp    return DEBUG_TYPE_NULL;
143233965Sjdp
143333965Sjdp  t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
143433965Sjdp  if (t == NULL)
143533965Sjdp    return DEBUG_TYPE_NULL;
143633965Sjdp
143733965Sjdp  t->u.kreference = type;
143833965Sjdp
143933965Sjdp  return t;
144033965Sjdp}
144133965Sjdp
144233965Sjdp/* Make a range of a given type from a lower to an upper bound.  */
144333965Sjdp
144433965Sjdpdebug_type
1445130561Sobriendebug_make_range_type (void *handle, debug_type type, bfd_signed_vma lower,
1446130561Sobrien		       bfd_signed_vma upper)
144733965Sjdp{
144833965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
144933965Sjdp  struct debug_type *t;
145033965Sjdp  struct debug_range_type *r;
145133965Sjdp
145233965Sjdp  if (type == NULL)
145333965Sjdp    return DEBUG_TYPE_NULL;
145433965Sjdp
145533965Sjdp  t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
145633965Sjdp  if (t == NULL)
145733965Sjdp    return DEBUG_TYPE_NULL;
145833965Sjdp
145933965Sjdp  r = (struct debug_range_type *) xmalloc (sizeof *r);
146033965Sjdp  memset (r, 0, sizeof *r);
146133965Sjdp
146233965Sjdp  r->type = type;
146333965Sjdp  r->lower = lower;
146433965Sjdp  r->upper = upper;
146533965Sjdp
146633965Sjdp  t->u.krange = r;
146733965Sjdp
146833965Sjdp  return t;
146933965Sjdp}
147033965Sjdp
147133965Sjdp/* Make an array type.  The second argument is the type of an element
147233965Sjdp   of the array.  The third argument is the type of a range of the
147333965Sjdp   array.  The fourth and fifth argument are the lower and upper
147433965Sjdp   bounds, respectively.  The sixth argument is true if this array is
147533965Sjdp   actually a string, as in C.  */
147633965Sjdp
147733965Sjdpdebug_type
1478130561Sobriendebug_make_array_type (void *handle, debug_type element_type,
1479130561Sobrien		       debug_type range_type, bfd_signed_vma lower,
1480130561Sobrien		       bfd_signed_vma upper, bfd_boolean stringp)
148133965Sjdp{
148233965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
148333965Sjdp  struct debug_type *t;
148433965Sjdp  struct debug_array_type *a;
148533965Sjdp
148633965Sjdp  if (element_type == NULL || range_type == NULL)
148733965Sjdp    return DEBUG_TYPE_NULL;
148833965Sjdp
148933965Sjdp  t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
149033965Sjdp  if (t == NULL)
149133965Sjdp    return DEBUG_TYPE_NULL;
149233965Sjdp
149333965Sjdp  a = (struct debug_array_type *) xmalloc (sizeof *a);
149433965Sjdp  memset (a, 0, sizeof *a);
149533965Sjdp
149633965Sjdp  a->element_type = element_type;
149733965Sjdp  a->range_type = range_type;
149833965Sjdp  a->lower = lower;
149933965Sjdp  a->upper = upper;
150033965Sjdp  a->stringp = stringp;
150133965Sjdp
150233965Sjdp  t->u.karray = a;
150333965Sjdp
150433965Sjdp  return t;
150533965Sjdp}
150633965Sjdp
150733965Sjdp/* Make a set of a given type.  For example, a Pascal set type.  The
150833965Sjdp   boolean argument is true if this set is actually a bitstring, as in
150933965Sjdp   CHILL.  */
151033965Sjdp
151133965Sjdpdebug_type
1512130561Sobriendebug_make_set_type (void *handle, debug_type type, bfd_boolean bitstringp)
151333965Sjdp{
151433965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
151533965Sjdp  struct debug_type *t;
151633965Sjdp  struct debug_set_type *s;
151733965Sjdp
151833965Sjdp  if (type == NULL)
151933965Sjdp    return DEBUG_TYPE_NULL;
152033965Sjdp
152133965Sjdp  t = debug_make_type (info, DEBUG_KIND_SET, 0);
152233965Sjdp  if (t == NULL)
152333965Sjdp    return DEBUG_TYPE_NULL;
152433965Sjdp
152533965Sjdp  s = (struct debug_set_type *) xmalloc (sizeof *s);
152633965Sjdp  memset (s, 0, sizeof *s);
152733965Sjdp
152833965Sjdp  s->type = type;
152933965Sjdp  s->bitstringp = bitstringp;
153033965Sjdp
153133965Sjdp  t->u.kset = s;
153233965Sjdp
153333965Sjdp  return t;
153433965Sjdp}
153533965Sjdp
153633965Sjdp/* Make a type for a pointer which is relative to an object.  The
153733965Sjdp   second argument is the type of the object to which the pointer is
153833965Sjdp   relative.  The third argument is the type that the pointer points
153933965Sjdp   to.  */
154033965Sjdp
154133965Sjdpdebug_type
1542130561Sobriendebug_make_offset_type (void *handle, debug_type base_type,
1543130561Sobrien			debug_type target_type)
154433965Sjdp{
154533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
154633965Sjdp  struct debug_type *t;
154733965Sjdp  struct debug_offset_type *o;
154833965Sjdp
154933965Sjdp  if (base_type == NULL || target_type == NULL)
155033965Sjdp    return DEBUG_TYPE_NULL;
155133965Sjdp
155233965Sjdp  t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
155333965Sjdp  if (t == NULL)
155433965Sjdp    return DEBUG_TYPE_NULL;
155533965Sjdp
155633965Sjdp  o = (struct debug_offset_type *) xmalloc (sizeof *o);
155733965Sjdp  memset (o, 0, sizeof *o);
155833965Sjdp
155933965Sjdp  o->base_type = base_type;
156033965Sjdp  o->target_type = target_type;
156133965Sjdp
156233965Sjdp  t->u.koffset = o;
156333965Sjdp
156433965Sjdp  return t;
156533965Sjdp}
156633965Sjdp
156733965Sjdp/* Make a type for a method function.  The second argument is the
156833965Sjdp   return type, the third argument is the domain, and the fourth
156933965Sjdp   argument is a NULL terminated array of argument types.  */
157033965Sjdp
157133965Sjdpdebug_type
1572130561Sobriendebug_make_method_type (void *handle, debug_type return_type,
1573130561Sobrien			debug_type domain_type, debug_type *arg_types,
1574130561Sobrien			bfd_boolean varargs)
157533965Sjdp{
157633965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
157733965Sjdp  struct debug_type *t;
157833965Sjdp  struct debug_method_type *m;
157933965Sjdp
158033965Sjdp  if (return_type == NULL)
158133965Sjdp    return DEBUG_TYPE_NULL;
158233965Sjdp
158333965Sjdp  t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
158433965Sjdp  if (t == NULL)
158533965Sjdp    return DEBUG_TYPE_NULL;
158633965Sjdp
158733965Sjdp  m = (struct debug_method_type *) xmalloc (sizeof *m);
158833965Sjdp  memset (m, 0, sizeof *m);
158933965Sjdp
159033965Sjdp  m->return_type = return_type;
159133965Sjdp  m->domain_type = domain_type;
159233965Sjdp  m->arg_types = arg_types;
159333965Sjdp  m->varargs = varargs;
159433965Sjdp
159533965Sjdp  t->u.kmethod = m;
159633965Sjdp
159733965Sjdp  return t;
159833965Sjdp}
159933965Sjdp
160033965Sjdp/* Make a const qualified version of a given type.  */
160133965Sjdp
160233965Sjdpdebug_type
1603130561Sobriendebug_make_const_type (void *handle, debug_type type)
160433965Sjdp{
160533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
160633965Sjdp  struct debug_type *t;
160733965Sjdp
160833965Sjdp  if (type == NULL)
160933965Sjdp    return DEBUG_TYPE_NULL;
161033965Sjdp
161133965Sjdp  t = debug_make_type (info, DEBUG_KIND_CONST, 0);
161233965Sjdp  if (t == NULL)
161333965Sjdp    return DEBUG_TYPE_NULL;
161433965Sjdp
161533965Sjdp  t->u.kconst = type;
161633965Sjdp
161733965Sjdp  return t;
161833965Sjdp}
161933965Sjdp
162033965Sjdp/* Make a volatile qualified version of a given type.  */
162133965Sjdp
162233965Sjdpdebug_type
1623130561Sobriendebug_make_volatile_type (void *handle, debug_type type)
162433965Sjdp{
162533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
162633965Sjdp  struct debug_type *t;
162733965Sjdp
162833965Sjdp  if (type == NULL)
162933965Sjdp    return DEBUG_TYPE_NULL;
163033965Sjdp
163133965Sjdp  t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
163233965Sjdp  if (t == NULL)
163333965Sjdp    return DEBUG_TYPE_NULL;
163433965Sjdp
163533965Sjdp  t->u.kvolatile = type;
163633965Sjdp
163733965Sjdp  return t;
163833965Sjdp}
163933965Sjdp
164033965Sjdp/* Make an undefined tagged type.  For example, a struct which has
164133965Sjdp   been mentioned, but not defined.  */
164233965Sjdp
164333965Sjdpdebug_type
1644130561Sobriendebug_make_undefined_tagged_type (void *handle, const char *name,
1645130561Sobrien				  enum debug_type_kind kind)
164633965Sjdp{
164733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
164833965Sjdp  struct debug_type *t;
164933965Sjdp
165033965Sjdp  if (name == NULL)
165133965Sjdp    return DEBUG_TYPE_NULL;
165233965Sjdp
165333965Sjdp  switch (kind)
165433965Sjdp    {
165533965Sjdp    case DEBUG_KIND_STRUCT:
165633965Sjdp    case DEBUG_KIND_UNION:
165733965Sjdp    case DEBUG_KIND_CLASS:
165833965Sjdp    case DEBUG_KIND_UNION_CLASS:
165933965Sjdp    case DEBUG_KIND_ENUM:
166033965Sjdp      break;
166133965Sjdp
166233965Sjdp    default:
166360484Sobrien      debug_error (_("debug_make_undefined_type: unsupported kind"));
166433965Sjdp      return DEBUG_TYPE_NULL;
166533965Sjdp    }
166633965Sjdp
166733965Sjdp  t = debug_make_type (info, kind, 0);
166833965Sjdp  if (t == NULL)
166933965Sjdp    return DEBUG_TYPE_NULL;
167033965Sjdp
167133965Sjdp  return debug_tag_type (handle, name, t);
167233965Sjdp}
167333965Sjdp
167433965Sjdp/* Make a base class for an object.  The second argument is the base
167533965Sjdp   class type.  The third argument is the bit position of this base
167633965Sjdp   class in the object (always 0 unless doing multiple inheritance).
167733965Sjdp   The fourth argument is whether this is a virtual class.  The fifth
167833965Sjdp   argument is the visibility of the base class.  */
167933965Sjdp
168033965Sjdpdebug_baseclass
1681130561Sobriendebug_make_baseclass (void *handle ATTRIBUTE_UNUSED, debug_type type,
1682130561Sobrien		      bfd_vma bitpos, bfd_boolean virtual,
1683130561Sobrien		      enum debug_visibility visibility)
1684104834Sobrien{
168533965Sjdp  struct debug_baseclass *b;
168633965Sjdp
168733965Sjdp  b = (struct debug_baseclass *) xmalloc (sizeof *b);
168833965Sjdp  memset (b, 0, sizeof *b);
168933965Sjdp
169033965Sjdp  b->type = type;
169133965Sjdp  b->bitpos = bitpos;
169233965Sjdp  b->virtual = virtual;
169333965Sjdp  b->visibility = visibility;
169433965Sjdp
169533965Sjdp  return b;
169633965Sjdp}
169733965Sjdp
169833965Sjdp/* Make a field for a struct.  The second argument is the name.  The
169933965Sjdp   third argument is the type of the field.  The fourth argument is
170033965Sjdp   the bit position of the field.  The fifth argument is the size of
170133965Sjdp   the field (it may be zero).  The sixth argument is the visibility
170233965Sjdp   of the field.  */
170333965Sjdp
170433965Sjdpdebug_field
1705130561Sobriendebug_make_field (void *handle ATTRIBUTE_UNUSED, const char *name,
1706130561Sobrien		  debug_type type, bfd_vma bitpos, bfd_vma bitsize,
1707130561Sobrien		  enum debug_visibility visibility)
170833965Sjdp{
170933965Sjdp  struct debug_field *f;
171033965Sjdp
171133965Sjdp  f = (struct debug_field *) xmalloc (sizeof *f);
171233965Sjdp  memset (f, 0, sizeof *f);
171333965Sjdp
171433965Sjdp  f->name = name;
171533965Sjdp  f->type = type;
1716130561Sobrien  f->static_member = FALSE;
171733965Sjdp  f->u.f.bitpos = bitpos;
171833965Sjdp  f->u.f.bitsize = bitsize;
171933965Sjdp  f->visibility = visibility;
172033965Sjdp
172133965Sjdp  return f;
172233965Sjdp}
172333965Sjdp
172433965Sjdp/* Make a static member of an object.  The second argument is the
172533965Sjdp   name.  The third argument is the type of the member.  The fourth
172633965Sjdp   argument is the physical name of the member (i.e., the name as a
172733965Sjdp   global variable).  The fifth argument is the visibility of the
172833965Sjdp   member.  */
172933965Sjdp
173033965Sjdpdebug_field
1731130561Sobriendebug_make_static_member (void *handle ATTRIBUTE_UNUSED, const char *name,
1732130561Sobrien			  debug_type type, const char *physname,
1733130561Sobrien			  enum debug_visibility visibility)
173433965Sjdp{
173533965Sjdp  struct debug_field *f;
173633965Sjdp
173733965Sjdp  f = (struct debug_field *) xmalloc (sizeof *f);
173833965Sjdp  memset (f, 0, sizeof *f);
173933965Sjdp
174033965Sjdp  f->name = name;
174133965Sjdp  f->type = type;
1742130561Sobrien  f->static_member = TRUE;
174333965Sjdp  f->u.s.physname = physname;
174433965Sjdp  f->visibility = visibility;
174533965Sjdp
174633965Sjdp  return f;
174733965Sjdp}
174833965Sjdp
174933965Sjdp/* Make a method.  The second argument is the name, and the third
175033965Sjdp   argument is a NULL terminated array of method variants.  */
175133965Sjdp
175233965Sjdpdebug_method
1753130561Sobriendebug_make_method (void *handle ATTRIBUTE_UNUSED, const char *name,
1754130561Sobrien		   debug_method_variant *variants)
175533965Sjdp{
175633965Sjdp  struct debug_method *m;
175733965Sjdp
175833965Sjdp  m = (struct debug_method *) xmalloc (sizeof *m);
175933965Sjdp  memset (m, 0, sizeof *m);
176033965Sjdp
176133965Sjdp  m->name = name;
176233965Sjdp  m->variants = variants;
176333965Sjdp
176433965Sjdp  return m;
176533965Sjdp}
176633965Sjdp
176733965Sjdp/* Make a method argument.  The second argument is the real name of
176833965Sjdp   the function.  The third argument is the type of the function.  The
176933965Sjdp   fourth argument is the visibility.  The fifth argument is whether
177033965Sjdp   this is a const function.  The sixth argument is whether this is a
177133965Sjdp   volatile function.  The seventh argument is the offset in the
177233965Sjdp   virtual function table, if any.  The eighth argument is the virtual
177333965Sjdp   function context.  FIXME: Are the const and volatile arguments
177433965Sjdp   necessary?  Could we just use debug_make_const_type?  */
177533965Sjdp
177633965Sjdpdebug_method_variant
1777130561Sobriendebug_make_method_variant (void *handle ATTRIBUTE_UNUSED,
1778130561Sobrien			   const char *physname, debug_type type,
1779130561Sobrien			   enum debug_visibility visibility,
1780130561Sobrien			   bfd_boolean constp, bfd_boolean volatilep,
1781130561Sobrien			   bfd_vma voffset, debug_type context)
178233965Sjdp{
178333965Sjdp  struct debug_method_variant *m;
178433965Sjdp
178533965Sjdp  m = (struct debug_method_variant *) xmalloc (sizeof *m);
178633965Sjdp  memset (m, 0, sizeof *m);
178733965Sjdp
178833965Sjdp  m->physname = physname;
178933965Sjdp  m->type = type;
179033965Sjdp  m->visibility = visibility;
179133965Sjdp  m->constp = constp;
179233965Sjdp  m->volatilep = volatilep;
179333965Sjdp  m->voffset = voffset;
179433965Sjdp  m->context = context;
179533965Sjdp
179633965Sjdp  return m;
179733965Sjdp}
179833965Sjdp
179933965Sjdp/* Make a static method argument.  The arguments are the same as for
180033965Sjdp   debug_make_method_variant, except that the last two are omitted
180133965Sjdp   since a static method can not also be virtual.  */
180233965Sjdp
180333965Sjdpdebug_method_variant
1804130561Sobriendebug_make_static_method_variant (void *handle ATTRIBUTE_UNUSED,
1805130561Sobrien				  const char *physname, debug_type type,
1806130561Sobrien				  enum debug_visibility visibility,
1807130561Sobrien				  bfd_boolean constp, bfd_boolean volatilep)
180833965Sjdp{
180933965Sjdp  struct debug_method_variant *m;
181033965Sjdp
181133965Sjdp  m = (struct debug_method_variant *) xmalloc (sizeof *m);
181233965Sjdp  memset (m, 0, sizeof *m);
181333965Sjdp
181433965Sjdp  m->physname = physname;
181533965Sjdp  m->type = type;
181633965Sjdp  m->visibility = visibility;
181733965Sjdp  m->constp = constp;
181833965Sjdp  m->volatilep = volatilep;
181933965Sjdp  m->voffset = VOFFSET_STATIC_METHOD;
182033965Sjdp
182133965Sjdp  return m;
182233965Sjdp}
182333965Sjdp
182433965Sjdp/* Name a type.  */
182533965Sjdp
182633965Sjdpdebug_type
1827130561Sobriendebug_name_type (void *handle, const char *name, debug_type type)
182833965Sjdp{
182933965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
183033965Sjdp  struct debug_type *t;
183133965Sjdp  struct debug_named_type *n;
183233965Sjdp  struct debug_name *nm;
183333965Sjdp
183433965Sjdp  if (name == NULL || type == NULL)
183533965Sjdp    return DEBUG_TYPE_NULL;
183633965Sjdp
183733965Sjdp  if (info->current_unit == NULL
183833965Sjdp      || info->current_file == NULL)
183933965Sjdp    {
184060484Sobrien      debug_error (_("debug_name_type: no current file"));
184160484Sobrien      return DEBUG_TYPE_NULL;
184233965Sjdp    }
184333965Sjdp
184433965Sjdp  t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
184533965Sjdp  if (t == NULL)
184633965Sjdp    return DEBUG_TYPE_NULL;
184733965Sjdp
184833965Sjdp  n = (struct debug_named_type *) xmalloc (sizeof *n);
184933965Sjdp  memset (n, 0, sizeof *n);
185033965Sjdp
185133965Sjdp  n->type = type;
185233965Sjdp
185333965Sjdp  t->u.knamed = n;
185433965Sjdp
185533965Sjdp  /* We always add the name to the global namespace.  This is probably
185633965Sjdp     wrong in some cases, but it seems to be right for stabs.  FIXME.  */
185733965Sjdp
185833965Sjdp  nm = debug_add_to_namespace (info, &info->current_file->globals, name,
185933965Sjdp			       DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
186033965Sjdp  if (nm == NULL)
186160484Sobrien    return DEBUG_TYPE_NULL;
186233965Sjdp
186333965Sjdp  nm->u.type = t;
186433965Sjdp
186533965Sjdp  n->name = nm;
186633965Sjdp
186733965Sjdp  return t;
186833965Sjdp}
186933965Sjdp
187033965Sjdp/* Tag a type.  */
187133965Sjdp
187233965Sjdpdebug_type
1873130561Sobriendebug_tag_type (void *handle, const char *name, debug_type type)
187433965Sjdp{
187533965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
187633965Sjdp  struct debug_type *t;
187733965Sjdp  struct debug_named_type *n;
187833965Sjdp  struct debug_name *nm;
187933965Sjdp
188033965Sjdp  if (name == NULL || type == NULL)
188133965Sjdp    return DEBUG_TYPE_NULL;
188233965Sjdp
188333965Sjdp  if (info->current_file == NULL)
188433965Sjdp    {
188560484Sobrien      debug_error (_("debug_tag_type: no current file"));
188633965Sjdp      return DEBUG_TYPE_NULL;
188733965Sjdp    }
188833965Sjdp
188933965Sjdp  if (type->kind == DEBUG_KIND_TAGGED)
189033965Sjdp    {
189133965Sjdp      if (strcmp (type->u.knamed->name->name, name) == 0)
189233965Sjdp	return type;
189360484Sobrien      debug_error (_("debug_tag_type: extra tag attempted"));
189433965Sjdp      return DEBUG_TYPE_NULL;
189533965Sjdp    }
189633965Sjdp
189733965Sjdp  t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
189833965Sjdp  if (t == NULL)
189933965Sjdp    return DEBUG_TYPE_NULL;
190033965Sjdp
190133965Sjdp  n = (struct debug_named_type *) xmalloc (sizeof *n);
190233965Sjdp  memset (n, 0, sizeof *n);
190333965Sjdp
190433965Sjdp  n->type = type;
190533965Sjdp
190633965Sjdp  t->u.knamed = n;
190733965Sjdp
190833965Sjdp  /* We keep a global namespace of tags for each compilation unit.  I
190933965Sjdp     don't know if that is the right thing to do.  */
191033965Sjdp
191133965Sjdp  nm = debug_add_to_namespace (info, &info->current_file->globals, name,
191233965Sjdp			       DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
191333965Sjdp  if (nm == NULL)
191460484Sobrien    return DEBUG_TYPE_NULL;
191533965Sjdp
191633965Sjdp  nm->u.tag = t;
191733965Sjdp
191833965Sjdp  n->name = nm;
191933965Sjdp
192033965Sjdp  return t;
192133965Sjdp}
192233965Sjdp
192333965Sjdp/* Record the size of a given type.  */
192433965Sjdp
1925130561Sobrienbfd_boolean
1926130561Sobriendebug_record_type_size (void *handle ATTRIBUTE_UNUSED, debug_type type,
1927130561Sobrien			unsigned int size)
192833965Sjdp{
192933965Sjdp  if (type->size != 0 && type->size != size)
193060484Sobrien    fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
193133965Sjdp	     type->size, size);
193233965Sjdp
193333965Sjdp  type->size = size;
193433965Sjdp
1935130561Sobrien  return TRUE;
193633965Sjdp}
193733965Sjdp
193833965Sjdp/* Find a named type.  */
193933965Sjdp
194033965Sjdpdebug_type
1941130561Sobriendebug_find_named_type (void *handle, const char *name)
194233965Sjdp{
194333965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
194433965Sjdp  struct debug_block *b;
194533965Sjdp  struct debug_file *f;
194633965Sjdp
194733965Sjdp  /* We only search the current compilation unit.  I don't know if
194833965Sjdp     this is right or not.  */
194933965Sjdp
195033965Sjdp  if (info->current_unit == NULL)
195133965Sjdp    {
195260484Sobrien      debug_error (_("debug_find_named_type: no current compilation unit"));
195333965Sjdp      return DEBUG_TYPE_NULL;
195433965Sjdp    }
195533965Sjdp
195633965Sjdp  for (b = info->current_block; b != NULL; b = b->parent)
195733965Sjdp    {
195833965Sjdp      if (b->locals != NULL)
195933965Sjdp	{
196033965Sjdp	  struct debug_name *n;
196133965Sjdp
196233965Sjdp	  for (n = b->locals->list; n != NULL; n = n->next)
196333965Sjdp	    {
196433965Sjdp	      if (n->kind == DEBUG_OBJECT_TYPE
196533965Sjdp		  && n->name[0] == name[0]
196633965Sjdp		  && strcmp (n->name, name) == 0)
196733965Sjdp		return n->u.type;
196833965Sjdp	    }
196933965Sjdp	}
197033965Sjdp    }
197133965Sjdp
197233965Sjdp  for (f = info->current_unit->files; f != NULL; f = f->next)
197333965Sjdp    {
197433965Sjdp      if (f->globals != NULL)
197533965Sjdp	{
197633965Sjdp	  struct debug_name *n;
197733965Sjdp
197833965Sjdp	  for (n = f->globals->list; n != NULL; n = n->next)
197933965Sjdp	    {
198033965Sjdp	      if (n->kind == DEBUG_OBJECT_TYPE
198133965Sjdp		  && n->name[0] == name[0]
198233965Sjdp		  && strcmp (n->name, name) == 0)
198333965Sjdp		return n->u.type;
198433965Sjdp	    }
198533965Sjdp	}
198633965Sjdp    }
198733965Sjdp
1988104834Sobrien  return DEBUG_TYPE_NULL;
198933965Sjdp}
199033965Sjdp
199133965Sjdp/* Find a tagged type.  */
199233965Sjdp
199333965Sjdpdebug_type
1994130561Sobriendebug_find_tagged_type (void *handle, const char *name,
1995130561Sobrien			enum debug_type_kind kind)
199633965Sjdp{
199733965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
199833965Sjdp  struct debug_unit *u;
199933965Sjdp
200033965Sjdp  /* We search the globals of all the compilation units.  I don't know
200133965Sjdp     if this is correct or not.  It would be easy to change.  */
200233965Sjdp
200333965Sjdp  for (u = info->units; u != NULL; u = u->next)
200433965Sjdp    {
200533965Sjdp      struct debug_file *f;
200633965Sjdp
200733965Sjdp      for (f = u->files; f != NULL; f = f->next)
200833965Sjdp	{
200933965Sjdp	  struct debug_name *n;
201033965Sjdp
201133965Sjdp	  if (f->globals != NULL)
201233965Sjdp	    {
201333965Sjdp	      for (n = f->globals->list; n != NULL; n = n->next)
201433965Sjdp		{
201533965Sjdp		  if (n->kind == DEBUG_OBJECT_TAG
201633965Sjdp		      && (kind == DEBUG_KIND_ILLEGAL
201733965Sjdp			  || n->u.tag->kind == kind)
201833965Sjdp		      && n->name[0] == name[0]
201933965Sjdp		      && strcmp (n->name, name) == 0)
202033965Sjdp		    return n->u.tag;
202133965Sjdp		}
202233965Sjdp	    }
202333965Sjdp	}
202433965Sjdp    }
202533965Sjdp
202633965Sjdp  return DEBUG_TYPE_NULL;
202733965Sjdp}
202833965Sjdp
202960484Sobrien/* Get a base type.  We build a linked list on the stack to avoid
203060484Sobrien   crashing if the type is defined circularly.  */
203133965Sjdp
203233965Sjdpstatic struct debug_type *
2033130561Sobriendebug_get_real_type (void *handle, debug_type type,
2034130561Sobrien		     struct debug_type_real_list *list)
203533965Sjdp{
203660484Sobrien  struct debug_type_real_list *l;
203760484Sobrien  struct debug_type_real_list rl;
203860484Sobrien
203933965Sjdp  switch (type->kind)
204033965Sjdp    {
204133965Sjdp    default:
204233965Sjdp      return type;
204360484Sobrien
204433965Sjdp    case DEBUG_KIND_INDIRECT:
204560484Sobrien    case DEBUG_KIND_NAMED:
204660484Sobrien    case DEBUG_KIND_TAGGED:
204760484Sobrien      break;
204860484Sobrien    }
204960484Sobrien
205060484Sobrien  for (l = list; l != NULL; l = l->next)
205160484Sobrien    {
2052130561Sobrien      if (l->t == type || l == l->next)
205360484Sobrien	{
205460484Sobrien	  fprintf (stderr,
205560484Sobrien		   _("debug_get_real_type: circular debug information for %s\n"),
205660484Sobrien		   debug_get_type_name (handle, type));
205760484Sobrien	  return NULL;
205860484Sobrien	}
205960484Sobrien    }
206060484Sobrien
206160484Sobrien  rl.next = list;
206260484Sobrien  rl.t = type;
206360484Sobrien
206460484Sobrien  switch (type->kind)
206560484Sobrien    {
206660484Sobrien      /* The default case is just here to avoid warnings.  */
206760484Sobrien    default:
206860484Sobrien    case DEBUG_KIND_INDIRECT:
206933965Sjdp      if (*type->u.kindirect->slot != NULL)
207060484Sobrien	return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
207133965Sjdp      return type;
207233965Sjdp    case DEBUG_KIND_NAMED:
207333965Sjdp    case DEBUG_KIND_TAGGED:
207460484Sobrien      return debug_get_real_type (handle, type->u.knamed->type, &rl);
207533965Sjdp    }
207633965Sjdp  /*NOTREACHED*/
207733965Sjdp}
207833965Sjdp
207933965Sjdp/* Get the kind of a type.  */
208033965Sjdp
208133965Sjdpenum debug_type_kind
2082130561Sobriendebug_get_type_kind (void *handle, debug_type type)
208333965Sjdp{
208433965Sjdp  if (type == NULL)
208533965Sjdp    return DEBUG_KIND_ILLEGAL;
208660484Sobrien  type = debug_get_real_type (handle, type, NULL);
208760484Sobrien  if (type == NULL)
208860484Sobrien    return DEBUG_KIND_ILLEGAL;
208933965Sjdp  return type->kind;
209033965Sjdp}
209133965Sjdp
209233965Sjdp/* Get the name of a type.  */
209333965Sjdp
209433965Sjdpconst char *
2095130561Sobriendebug_get_type_name (void *handle, debug_type type)
209633965Sjdp{
209733965Sjdp  if (type->kind == DEBUG_KIND_INDIRECT)
209833965Sjdp    {
209933965Sjdp      if (*type->u.kindirect->slot != NULL)
210033965Sjdp	return debug_get_type_name (handle, *type->u.kindirect->slot);
210133965Sjdp      return type->u.kindirect->tag;
210233965Sjdp    }
210333965Sjdp  if (type->kind == DEBUG_KIND_NAMED
210433965Sjdp      || type->kind == DEBUG_KIND_TAGGED)
210533965Sjdp    return type->u.knamed->name->name;
210633965Sjdp  return NULL;
210733965Sjdp}
210833965Sjdp
210933965Sjdp/* Get the size of a type.  */
211033965Sjdp
211133965Sjdpbfd_vma
2112130561Sobriendebug_get_type_size (void *handle, debug_type type)
211333965Sjdp{
211433965Sjdp  if (type == NULL)
211533965Sjdp    return 0;
211633965Sjdp
211733965Sjdp  /* We don't call debug_get_real_type, because somebody might have
211833965Sjdp     called debug_record_type_size on a named or indirect type.  */
211933965Sjdp
212033965Sjdp  if (type->size != 0)
212133965Sjdp    return type->size;
212233965Sjdp
212333965Sjdp  switch (type->kind)
212433965Sjdp    {
212533965Sjdp    default:
212633965Sjdp      return 0;
212733965Sjdp    case DEBUG_KIND_INDIRECT:
212833965Sjdp      if (*type->u.kindirect->slot != NULL)
212933965Sjdp	return debug_get_type_size (handle, *type->u.kindirect->slot);
213033965Sjdp      return 0;
213133965Sjdp    case DEBUG_KIND_NAMED:
213233965Sjdp    case DEBUG_KIND_TAGGED:
213333965Sjdp      return debug_get_type_size (handle, type->u.knamed->type);
213433965Sjdp    }
213533965Sjdp  /*NOTREACHED*/
213633965Sjdp}
213733965Sjdp
213833965Sjdp/* Get the return type of a function or method type.  */
213933965Sjdp
214033965Sjdpdebug_type
2141130561Sobriendebug_get_return_type (void *handle, debug_type type)
214233965Sjdp{
214333965Sjdp  if (type == NULL)
214433965Sjdp    return DEBUG_TYPE_NULL;
2145130561Sobrien
214660484Sobrien  type = debug_get_real_type (handle, type, NULL);
214760484Sobrien  if (type == NULL)
214860484Sobrien    return DEBUG_TYPE_NULL;
2149130561Sobrien
215033965Sjdp  switch (type->kind)
215133965Sjdp    {
215233965Sjdp    default:
215333965Sjdp      return DEBUG_TYPE_NULL;
215433965Sjdp    case DEBUG_KIND_FUNCTION:
215533965Sjdp      return type->u.kfunction->return_type;
215633965Sjdp    case DEBUG_KIND_METHOD:
215733965Sjdp      return type->u.kmethod->return_type;
215833965Sjdp    }
2159104834Sobrien  /*NOTREACHED*/
216033965Sjdp}
216133965Sjdp
216233965Sjdp/* Get the parameter types of a function or method type (except that
216333965Sjdp   we don't currently store the parameter types of a function).  */
216433965Sjdp
216533965Sjdpconst debug_type *
2166130561Sobriendebug_get_parameter_types (void *handle, debug_type type,
2167130561Sobrien			   bfd_boolean *pvarargs)
216833965Sjdp{
216933965Sjdp  if (type == NULL)
217033965Sjdp    return NULL;
2171130561Sobrien
217260484Sobrien  type = debug_get_real_type (handle, type, NULL);
217360484Sobrien  if (type == NULL)
217460484Sobrien    return NULL;
2175130561Sobrien
217633965Sjdp  switch (type->kind)
217733965Sjdp    {
217833965Sjdp    default:
217933965Sjdp      return NULL;
218033965Sjdp    case DEBUG_KIND_FUNCTION:
218133965Sjdp      *pvarargs = type->u.kfunction->varargs;
218233965Sjdp      return type->u.kfunction->arg_types;
218333965Sjdp    case DEBUG_KIND_METHOD:
218433965Sjdp      *pvarargs = type->u.kmethod->varargs;
218533965Sjdp      return type->u.kmethod->arg_types;
218633965Sjdp    }
218733965Sjdp  /*NOTREACHED*/
218833965Sjdp}
218933965Sjdp
219033965Sjdp/* Get the target type of a type.  */
219133965Sjdp
219233965Sjdpdebug_type
2193130561Sobriendebug_get_target_type (void *handle, debug_type type)
219433965Sjdp{
219533965Sjdp  if (type == NULL)
219633965Sjdp    return NULL;
2197130561Sobrien
219860484Sobrien  type = debug_get_real_type (handle, type, NULL);
219960484Sobrien  if (type == NULL)
220060484Sobrien    return NULL;
2201130561Sobrien
220233965Sjdp  switch (type->kind)
220333965Sjdp    {
220433965Sjdp    default:
220533965Sjdp      return NULL;
220633965Sjdp    case DEBUG_KIND_POINTER:
220733965Sjdp      return type->u.kpointer;
220833965Sjdp    case DEBUG_KIND_REFERENCE:
220933965Sjdp      return type->u.kreference;
221033965Sjdp    case DEBUG_KIND_CONST:
221133965Sjdp      return type->u.kconst;
221233965Sjdp    case DEBUG_KIND_VOLATILE:
221333965Sjdp      return type->u.kvolatile;
221433965Sjdp    }
221533965Sjdp  /*NOTREACHED*/
221633965Sjdp}
221733965Sjdp
221833965Sjdp/* Get the NULL terminated array of fields for a struct, union, or
221933965Sjdp   class.  */
222033965Sjdp
222133965Sjdpconst debug_field *
2222130561Sobriendebug_get_fields (void *handle, debug_type type)
222333965Sjdp{
222433965Sjdp  if (type == NULL)
222533965Sjdp    return NULL;
2226130561Sobrien
222760484Sobrien  type = debug_get_real_type (handle, type, NULL);
222860484Sobrien  if (type == NULL)
222960484Sobrien    return NULL;
2230130561Sobrien
223133965Sjdp  switch (type->kind)
223233965Sjdp    {
223333965Sjdp    default:
223433965Sjdp      return NULL;
223533965Sjdp    case DEBUG_KIND_STRUCT:
223633965Sjdp    case DEBUG_KIND_UNION:
223733965Sjdp    case DEBUG_KIND_CLASS:
223833965Sjdp    case DEBUG_KIND_UNION_CLASS:
223933965Sjdp      return type->u.kclass->fields;
224033965Sjdp    }
224133965Sjdp  /*NOTREACHED*/
224233965Sjdp}
224333965Sjdp
224433965Sjdp/* Get the type of a field.  */
224533965Sjdp
224633965Sjdpdebug_type
2247130561Sobriendebug_get_field_type (void *handle ATTRIBUTE_UNUSED, debug_field field)
224833965Sjdp{
224933965Sjdp  if (field == NULL)
225033965Sjdp    return NULL;
225133965Sjdp  return field->type;
225233965Sjdp}
225333965Sjdp
225433965Sjdp/* Get the name of a field.  */
225533965Sjdp
225633965Sjdpconst char *
2257130561Sobriendebug_get_field_name (void *handle ATTRIBUTE_UNUSED, debug_field field)
225833965Sjdp{
225933965Sjdp  if (field == NULL)
226033965Sjdp    return NULL;
226133965Sjdp  return field->name;
226233965Sjdp}
226333965Sjdp
226433965Sjdp/* Get the bit position of a field.  */
226533965Sjdp
226633965Sjdpbfd_vma
2267130561Sobriendebug_get_field_bitpos (void *handle ATTRIBUTE_UNUSED, debug_field field)
226833965Sjdp{
226933965Sjdp  if (field == NULL || field->static_member)
227033965Sjdp    return (bfd_vma) -1;
227133965Sjdp  return field->u.f.bitpos;
227233965Sjdp}
227333965Sjdp
227433965Sjdp/* Get the bit size of a field.  */
227533965Sjdp
227633965Sjdpbfd_vma
2277130561Sobriendebug_get_field_bitsize (void *handle ATTRIBUTE_UNUSED, debug_field field)
227833965Sjdp{
227933965Sjdp  if (field == NULL || field->static_member)
228033965Sjdp    return (bfd_vma) -1;
228133965Sjdp  return field->u.f.bitsize;
228233965Sjdp}
228333965Sjdp
228433965Sjdp/* Get the visibility of a field.  */
228533965Sjdp
228633965Sjdpenum debug_visibility
2287130561Sobriendebug_get_field_visibility (void *handle ATTRIBUTE_UNUSED, debug_field field)
228833965Sjdp{
228933965Sjdp  if (field == NULL)
229033965Sjdp    return DEBUG_VISIBILITY_IGNORE;
229133965Sjdp  return field->visibility;
229233965Sjdp}
229333965Sjdp
229433965Sjdp/* Get the physical name of a field.  */
229533965Sjdp
229633965Sjdpconst char *
2297130561Sobriendebug_get_field_physname (void *handle ATTRIBUTE_UNUSED, debug_field field)
229833965Sjdp{
229933965Sjdp  if (field == NULL || ! field->static_member)
230033965Sjdp    return NULL;
230133965Sjdp  return field->u.s.physname;
230233965Sjdp}
230333965Sjdp
230433965Sjdp/* Write out the debugging information.  This is given a handle to
230533965Sjdp   debugging information, and a set of function pointers to call.  */
230633965Sjdp
2307130561Sobrienbfd_boolean
2308130561Sobriendebug_write (void *handle, const struct debug_write_fns *fns, void *fhandle)
230933965Sjdp{
231033965Sjdp  struct debug_handle *info = (struct debug_handle *) handle;
231133965Sjdp  struct debug_unit *u;
231233965Sjdp
231333965Sjdp  /* We use a mark to tell whether we have already written out a
231433965Sjdp     particular name.  We use an integer, so that we don't have to
231533965Sjdp     clear the mark fields if we happen to write out the same
231633965Sjdp     information more than once.  */
231733965Sjdp  ++info->mark;
231833965Sjdp
231933965Sjdp  /* The base_id field holds an ID value which will never be used, so
232033965Sjdp     that we can tell whether we have assigned an ID during this call
232133965Sjdp     to debug_write.  */
232233965Sjdp  info->base_id = info->class_id;
232333965Sjdp
232433965Sjdp  /* We keep a linked list of classes for which was have assigned ID's
232533965Sjdp     during this call to debug_write.  */
232633965Sjdp  info->id_list = NULL;
232733965Sjdp
232833965Sjdp  for (u = info->units; u != NULL; u = u->next)
232933965Sjdp    {
233033965Sjdp      struct debug_file *f;
2331130561Sobrien      bfd_boolean first_file;
233233965Sjdp
233333965Sjdp      info->current_write_lineno = u->linenos;
233433965Sjdp      info->current_write_lineno_index = 0;
233533965Sjdp
233633965Sjdp      if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
2337130561Sobrien	return FALSE;
233833965Sjdp
2339130561Sobrien      first_file = TRUE;
234033965Sjdp      for (f = u->files; f != NULL; f = f->next)
234133965Sjdp	{
234233965Sjdp	  struct debug_name *n;
234333965Sjdp
234433965Sjdp	  if (first_file)
2345130561Sobrien	    first_file = FALSE;
2346130561Sobrien	  else if (! (*fns->start_source) (fhandle, f->filename))
2347130561Sobrien	    return FALSE;
234833965Sjdp
234933965Sjdp	  if (f->globals != NULL)
2350130561Sobrien	    for (n = f->globals->list; n != NULL; n = n->next)
2351130561Sobrien	      if (! debug_write_name (info, fns, fhandle, n))
2352130561Sobrien		return FALSE;
235333965Sjdp	}
235433965Sjdp
235533965Sjdp      /* Output any line number information which hasn't already been
235633965Sjdp         handled.  */
235733965Sjdp      if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
2358130561Sobrien	return FALSE;
235933965Sjdp    }
236033965Sjdp
2361130561Sobrien  return TRUE;
236233965Sjdp}
236333965Sjdp
236433965Sjdp/* Write out an element in a namespace.  */
236533965Sjdp
2366130561Sobrienstatic bfd_boolean
2367130561Sobriendebug_write_name (struct debug_handle *info,
2368130561Sobrien		  const struct debug_write_fns *fns, void *fhandle,
2369130561Sobrien		  struct debug_name *n)
237033965Sjdp{
237133965Sjdp  switch (n->kind)
237233965Sjdp    {
237333965Sjdp    case DEBUG_OBJECT_TYPE:
237433965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.type, n)
237533965Sjdp	  || ! (*fns->typdef) (fhandle, n->name))
2376130561Sobrien	return FALSE;
2377130561Sobrien      return TRUE;
237833965Sjdp    case DEBUG_OBJECT_TAG:
237933965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
2380130561Sobrien	return FALSE;
238133965Sjdp      return (*fns->tag) (fhandle, n->name);
238233965Sjdp    case DEBUG_OBJECT_VARIABLE:
238333965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
238433965Sjdp			      (struct debug_name *) NULL))
2385130561Sobrien	return FALSE;
238633965Sjdp      return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
238733965Sjdp			       n->u.variable->val);
238833965Sjdp    case DEBUG_OBJECT_FUNCTION:
238933965Sjdp      return debug_write_function (info, fns, fhandle, n->name,
239033965Sjdp				   n->linkage, n->u.function);
239133965Sjdp    case DEBUG_OBJECT_INT_CONSTANT:
239233965Sjdp      return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
239333965Sjdp    case DEBUG_OBJECT_FLOAT_CONSTANT:
239433965Sjdp      return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
239533965Sjdp    case DEBUG_OBJECT_TYPED_CONSTANT:
239633965Sjdp      if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
239733965Sjdp			      (struct debug_name *) NULL))
2398130561Sobrien	return FALSE;
239933965Sjdp      return (*fns->typed_constant) (fhandle, n->name,
240033965Sjdp				     n->u.typed_constant->val);
240133965Sjdp    default:
240233965Sjdp      abort ();
2403130561Sobrien      return FALSE;
240433965Sjdp    }
240533965Sjdp  /*NOTREACHED*/
240633965Sjdp}
240733965Sjdp
240833965Sjdp/* Write out a type.  If the type is DEBUG_KIND_NAMED or
240933965Sjdp   DEBUG_KIND_TAGGED, then the name argument is the name for which we
241033965Sjdp   are about to call typedef or tag.  If the type is anything else,
241133965Sjdp   then the name argument is a tag from a DEBUG_KIND_TAGGED type which
241233965Sjdp   points to this one.  */
241333965Sjdp
2414130561Sobrienstatic bfd_boolean
2415130561Sobriendebug_write_type (struct debug_handle *info,
2416130561Sobrien		  const struct debug_write_fns *fns, void *fhandle,
2417130561Sobrien		  struct debug_type *type, struct debug_name *name)
241833965Sjdp{
241933965Sjdp  unsigned int i;
242033965Sjdp  int is;
242160484Sobrien  const char *tag = NULL;
242233965Sjdp
242333965Sjdp  /* If we have a name for this type, just output it.  We only output
242433965Sjdp     typedef names after they have been defined.  We output type tags
242533965Sjdp     whenever we are not actually defining them.  */
242633965Sjdp  if ((type->kind == DEBUG_KIND_NAMED
242733965Sjdp       || type->kind == DEBUG_KIND_TAGGED)
242833965Sjdp      && (type->u.knamed->name->mark == info->mark
242933965Sjdp	  || (type->kind == DEBUG_KIND_TAGGED
243033965Sjdp	      && type->u.knamed->name != name)))
243133965Sjdp    {
243233965Sjdp      if (type->kind == DEBUG_KIND_NAMED)
243333965Sjdp	return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
243433965Sjdp      else
243533965Sjdp	{
243633965Sjdp	  struct debug_type *real;
243733965Sjdp	  unsigned int id;
243833965Sjdp
2439130561Sobrien	  real = debug_get_real_type ((void *) info, type, NULL);
244060484Sobrien	  if (real == NULL)
244160484Sobrien	    return (*fns->empty_type) (fhandle);
244233965Sjdp	  id = 0;
244333965Sjdp	  if ((real->kind == DEBUG_KIND_STRUCT
244433965Sjdp	       || real->kind == DEBUG_KIND_UNION
244533965Sjdp	       || real->kind == DEBUG_KIND_CLASS
244633965Sjdp	       || real->kind == DEBUG_KIND_UNION_CLASS)
244733965Sjdp	      && real->u.kclass != NULL)
244833965Sjdp	    {
244933965Sjdp	      if (real->u.kclass->id <= info->base_id)
245033965Sjdp		{
245133965Sjdp		  if (! debug_set_class_id (info,
245233965Sjdp					    type->u.knamed->name->name,
245333965Sjdp					    real))
2454130561Sobrien		    return FALSE;
245533965Sjdp		}
245633965Sjdp	      id = real->u.kclass->id;
245733965Sjdp	    }
245833965Sjdp
245933965Sjdp	  return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
246033965Sjdp				   real->kind);
246133965Sjdp	}
246233965Sjdp    }
246333965Sjdp
246433965Sjdp  /* Mark the name after we have already looked for a known name, so
246533965Sjdp     that we don't just define a type in terms of itself.  We need to
246633965Sjdp     mark the name here so that a struct containing a pointer to
246733965Sjdp     itself will work.  */
246833965Sjdp  if (name != NULL)
246933965Sjdp    name->mark = info->mark;
247033965Sjdp
247133965Sjdp  if (name != NULL
247233965Sjdp      && type->kind != DEBUG_KIND_NAMED
247333965Sjdp      && type->kind != DEBUG_KIND_TAGGED)
247433965Sjdp    {
247533965Sjdp      assert (name->kind == DEBUG_OBJECT_TAG);
247633965Sjdp      tag = name->name;
247733965Sjdp    }
247833965Sjdp
247933965Sjdp  switch (type->kind)
248033965Sjdp    {
248133965Sjdp    case DEBUG_KIND_ILLEGAL:
248260484Sobrien      debug_error (_("debug_write_type: illegal type encountered"));
2483130561Sobrien      return FALSE;
248433965Sjdp    case DEBUG_KIND_INDIRECT:
248533965Sjdp      if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
248633965Sjdp	return (*fns->empty_type) (fhandle);
248733965Sjdp      return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
248833965Sjdp			       name);
248933965Sjdp    case DEBUG_KIND_VOID:
249033965Sjdp      return (*fns->void_type) (fhandle);
249133965Sjdp    case DEBUG_KIND_INT:
249233965Sjdp      return (*fns->int_type) (fhandle, type->size, type->u.kint);
249333965Sjdp    case DEBUG_KIND_FLOAT:
249433965Sjdp      return (*fns->float_type) (fhandle, type->size);
249533965Sjdp    case DEBUG_KIND_COMPLEX:
249633965Sjdp      return (*fns->complex_type) (fhandle, type->size);
249733965Sjdp    case DEBUG_KIND_BOOL:
249833965Sjdp      return (*fns->bool_type) (fhandle, type->size);
249933965Sjdp    case DEBUG_KIND_STRUCT:
250033965Sjdp    case DEBUG_KIND_UNION:
250133965Sjdp      if (type->u.kclass != NULL)
250233965Sjdp	{
250333965Sjdp	  if (type->u.kclass->id <= info->base_id)
250433965Sjdp	    {
250533965Sjdp	      if (! debug_set_class_id (info, tag, type))
2506130561Sobrien		return FALSE;
250733965Sjdp	    }
250833965Sjdp
250933965Sjdp	  if (info->mark == type->u.kclass->mark)
251033965Sjdp	    {
251133965Sjdp	      /* We are currently outputting this struct, or we have
251233965Sjdp		 already output it.  I don't know if this can happen,
251333965Sjdp		 but it can happen for a class.  */
251433965Sjdp	      assert (type->u.kclass->id > info->base_id);
251533965Sjdp	      return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
251633965Sjdp				       type->kind);
251733965Sjdp	    }
251833965Sjdp	  type->u.kclass->mark = info->mark;
251933965Sjdp	}
252033965Sjdp
252133965Sjdp      if (! (*fns->start_struct_type) (fhandle, tag,
252233965Sjdp				       (type->u.kclass != NULL
252333965Sjdp					? type->u.kclass->id
252433965Sjdp					: 0),
252533965Sjdp				       type->kind == DEBUG_KIND_STRUCT,
252633965Sjdp				       type->size))
2527130561Sobrien	return FALSE;
252833965Sjdp      if (type->u.kclass != NULL
252933965Sjdp	  && type->u.kclass->fields != NULL)
253033965Sjdp	{
253133965Sjdp	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
253233965Sjdp	    {
253333965Sjdp	      struct debug_field *f;
253433965Sjdp
253533965Sjdp	      f = type->u.kclass->fields[i];
253633965Sjdp	      if (! debug_write_type (info, fns, fhandle, f->type,
253733965Sjdp				      (struct debug_name *) NULL)
253833965Sjdp		  || ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
253933965Sjdp					     f->u.f.bitsize, f->visibility))
2540130561Sobrien		return FALSE;
254133965Sjdp	    }
254233965Sjdp	}
254333965Sjdp      return (*fns->end_struct_type) (fhandle);
254433965Sjdp    case DEBUG_KIND_CLASS:
254533965Sjdp    case DEBUG_KIND_UNION_CLASS:
254633965Sjdp      return debug_write_class_type (info, fns, fhandle, type, tag);
254733965Sjdp    case DEBUG_KIND_ENUM:
254833965Sjdp      if (type->u.kenum == NULL)
254933965Sjdp	return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
255033965Sjdp				  (bfd_signed_vma *) NULL);
255133965Sjdp      return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
255233965Sjdp				type->u.kenum->values);
255333965Sjdp    case DEBUG_KIND_POINTER:
255433965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
255533965Sjdp			      (struct debug_name *) NULL))
2556130561Sobrien	return FALSE;
255733965Sjdp      return (*fns->pointer_type) (fhandle);
255833965Sjdp    case DEBUG_KIND_FUNCTION:
255933965Sjdp      if (! debug_write_type (info, fns, fhandle,
256033965Sjdp			      type->u.kfunction->return_type,
256133965Sjdp			      (struct debug_name *) NULL))
2562130561Sobrien	return FALSE;
256333965Sjdp      if (type->u.kfunction->arg_types == NULL)
256433965Sjdp	is = -1;
256533965Sjdp      else
256633965Sjdp	{
256733965Sjdp	  for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
256833965Sjdp	    if (! debug_write_type (info, fns, fhandle,
256933965Sjdp				    type->u.kfunction->arg_types[is],
257033965Sjdp				    (struct debug_name *) NULL))
2571130561Sobrien	      return FALSE;
257233965Sjdp	}
257333965Sjdp      return (*fns->function_type) (fhandle, is,
257433965Sjdp				    type->u.kfunction->varargs);
257533965Sjdp    case DEBUG_KIND_REFERENCE:
257633965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kreference,
257733965Sjdp			      (struct debug_name *) NULL))
2578130561Sobrien	return FALSE;
257933965Sjdp      return (*fns->reference_type) (fhandle);
258033965Sjdp    case DEBUG_KIND_RANGE:
258133965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
258233965Sjdp			      (struct debug_name *) NULL))
2583130561Sobrien	return FALSE;
258433965Sjdp      return (*fns->range_type) (fhandle, type->u.krange->lower,
258533965Sjdp				 type->u.krange->upper);
258633965Sjdp    case DEBUG_KIND_ARRAY:
258733965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
258833965Sjdp			      (struct debug_name *) NULL)
258933965Sjdp	  || ! debug_write_type (info, fns, fhandle,
259033965Sjdp				 type->u.karray->range_type,
259133965Sjdp				 (struct debug_name *) NULL))
2592130561Sobrien	return FALSE;
259333965Sjdp      return (*fns->array_type) (fhandle, type->u.karray->lower,
259433965Sjdp				 type->u.karray->upper,
259533965Sjdp				 type->u.karray->stringp);
259633965Sjdp    case DEBUG_KIND_SET:
259733965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
259833965Sjdp			      (struct debug_name *) NULL))
2599130561Sobrien	return FALSE;
260033965Sjdp      return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
260133965Sjdp    case DEBUG_KIND_OFFSET:
260233965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
260333965Sjdp			      (struct debug_name *) NULL)
260433965Sjdp	  || ! debug_write_type (info, fns, fhandle,
260533965Sjdp				 type->u.koffset->target_type,
260633965Sjdp				 (struct debug_name *) NULL))
2607130561Sobrien	return FALSE;
260833965Sjdp      return (*fns->offset_type) (fhandle);
260933965Sjdp    case DEBUG_KIND_METHOD:
261033965Sjdp      if (! debug_write_type (info, fns, fhandle,
261133965Sjdp			      type->u.kmethod->return_type,
261233965Sjdp			      (struct debug_name *) NULL))
2613130561Sobrien	return FALSE;
261433965Sjdp      if (type->u.kmethod->arg_types == NULL)
261533965Sjdp	is = -1;
261633965Sjdp      else
261733965Sjdp	{
261833965Sjdp	  for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
261933965Sjdp	    if (! debug_write_type (info, fns, fhandle,
262033965Sjdp				    type->u.kmethod->arg_types[is],
262133965Sjdp				    (struct debug_name *) NULL))
2622130561Sobrien	      return FALSE;
262333965Sjdp	}
262433965Sjdp      if (type->u.kmethod->domain_type != NULL)
262533965Sjdp	{
262633965Sjdp	  if (! debug_write_type (info, fns, fhandle,
262733965Sjdp				  type->u.kmethod->domain_type,
262833965Sjdp				  (struct debug_name *) NULL))
2629130561Sobrien	    return FALSE;
263033965Sjdp	}
263133965Sjdp      return (*fns->method_type) (fhandle,
263233965Sjdp				  type->u.kmethod->domain_type != NULL,
263333965Sjdp				  is,
263433965Sjdp				  type->u.kmethod->varargs);
263533965Sjdp    case DEBUG_KIND_CONST:
263633965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kconst,
263733965Sjdp			      (struct debug_name *) NULL))
2638130561Sobrien	return FALSE;
263933965Sjdp      return (*fns->const_type) (fhandle);
264033965Sjdp    case DEBUG_KIND_VOLATILE:
264133965Sjdp      if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
264233965Sjdp			      (struct debug_name *) NULL))
2643130561Sobrien	return FALSE;
264433965Sjdp      return (*fns->volatile_type) (fhandle);
264533965Sjdp    case DEBUG_KIND_NAMED:
264633965Sjdp      return debug_write_type (info, fns, fhandle, type->u.knamed->type,
264733965Sjdp			       (struct debug_name *) NULL);
264833965Sjdp    case DEBUG_KIND_TAGGED:
264933965Sjdp      return debug_write_type (info, fns, fhandle, type->u.knamed->type,
265033965Sjdp			       type->u.knamed->name);
265133965Sjdp    default:
265233965Sjdp      abort ();
2653130561Sobrien      return FALSE;
265433965Sjdp    }
265533965Sjdp}
265633965Sjdp
265733965Sjdp/* Write out a class type.  */
265833965Sjdp
2659130561Sobrienstatic bfd_boolean
2660130561Sobriendebug_write_class_type (struct debug_handle *info,
2661130561Sobrien			const struct debug_write_fns *fns, void *fhandle,
2662130561Sobrien			struct debug_type *type, const char *tag)
266333965Sjdp{
266433965Sjdp  unsigned int i;
266533965Sjdp  unsigned int id;
266633965Sjdp  struct debug_type *vptrbase;
266733965Sjdp
266833965Sjdp  if (type->u.kclass == NULL)
266933965Sjdp    {
267033965Sjdp      id = 0;
267133965Sjdp      vptrbase = NULL;
267233965Sjdp    }
267333965Sjdp  else
267433965Sjdp    {
267533965Sjdp      if (type->u.kclass->id <= info->base_id)
267633965Sjdp	{
267733965Sjdp	  if (! debug_set_class_id (info, tag, type))
2678130561Sobrien	    return FALSE;
267933965Sjdp	}
268033965Sjdp
268133965Sjdp      if (info->mark == type->u.kclass->mark)
268233965Sjdp	{
268333965Sjdp	  /* We are currently outputting this class, or we have
268433965Sjdp	     already output it.  This can happen when there are
268533965Sjdp	     methods for an anonymous class.  */
268633965Sjdp	  assert (type->u.kclass->id > info->base_id);
268733965Sjdp	  return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
268833965Sjdp				   type->kind);
268933965Sjdp	}
269033965Sjdp      type->u.kclass->mark = info->mark;
269133965Sjdp      id = type->u.kclass->id;
269233965Sjdp
269333965Sjdp      vptrbase = type->u.kclass->vptrbase;
269433965Sjdp      if (vptrbase != NULL && vptrbase != type)
269533965Sjdp	{
269633965Sjdp	  if (! debug_write_type (info, fns, fhandle, vptrbase,
269733965Sjdp				  (struct debug_name *) NULL))
2698130561Sobrien	    return FALSE;
269933965Sjdp	}
270033965Sjdp    }
270133965Sjdp
270233965Sjdp  if (! (*fns->start_class_type) (fhandle, tag, id,
270333965Sjdp				  type->kind == DEBUG_KIND_CLASS,
270433965Sjdp				  type->size,
270533965Sjdp				  vptrbase != NULL,
270633965Sjdp				  vptrbase == type))
2707130561Sobrien    return FALSE;
270833965Sjdp
270933965Sjdp  if (type->u.kclass != NULL)
271033965Sjdp    {
271133965Sjdp      if (type->u.kclass->fields != NULL)
271233965Sjdp	{
271333965Sjdp	  for (i = 0; type->u.kclass->fields[i] != NULL; i++)
271433965Sjdp	    {
271533965Sjdp	      struct debug_field *f;
271633965Sjdp
271733965Sjdp	      f = type->u.kclass->fields[i];
271833965Sjdp	      if (! debug_write_type (info, fns, fhandle, f->type,
271933965Sjdp				      (struct debug_name *) NULL))
2720130561Sobrien		return FALSE;
272133965Sjdp	      if (f->static_member)
272233965Sjdp		{
272333965Sjdp		  if (! (*fns->class_static_member) (fhandle, f->name,
272433965Sjdp						     f->u.s.physname,
272533965Sjdp						     f->visibility))
2726130561Sobrien		    return FALSE;
272733965Sjdp		}
272833965Sjdp	      else
272933965Sjdp		{
273033965Sjdp		  if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
273133965Sjdp					      f->u.f.bitsize, f->visibility))
2732130561Sobrien		    return FALSE;
273333965Sjdp		}
273433965Sjdp	    }
273533965Sjdp	}
273633965Sjdp
273733965Sjdp      if (type->u.kclass->baseclasses != NULL)
273833965Sjdp	{
273933965Sjdp	  for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
274033965Sjdp	    {
274133965Sjdp	      struct debug_baseclass *b;
274233965Sjdp
274333965Sjdp	      b = type->u.kclass->baseclasses[i];
274433965Sjdp	      if (! debug_write_type (info, fns, fhandle, b->type,
274533965Sjdp				      (struct debug_name *) NULL))
2746130561Sobrien		return FALSE;
274733965Sjdp	      if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
274833965Sjdp					     b->visibility))
2749130561Sobrien		return FALSE;
275033965Sjdp	    }
275133965Sjdp	}
275233965Sjdp
275333965Sjdp      if (type->u.kclass->methods != NULL)
275433965Sjdp	{
275533965Sjdp	  for (i = 0; type->u.kclass->methods[i] != NULL; i++)
275633965Sjdp	    {
275733965Sjdp	      struct debug_method *m;
275833965Sjdp	      unsigned int j;
275933965Sjdp
276033965Sjdp	      m = type->u.kclass->methods[i];
276133965Sjdp	      if (! (*fns->class_start_method) (fhandle, m->name))
2762130561Sobrien		return FALSE;
276333965Sjdp	      for (j = 0; m->variants[j] != NULL; j++)
276433965Sjdp		{
276533965Sjdp		  struct debug_method_variant *v;
276633965Sjdp
276733965Sjdp		  v = m->variants[j];
276833965Sjdp		  if (v->context != NULL)
276933965Sjdp		    {
277033965Sjdp		      if (! debug_write_type (info, fns, fhandle, v->context,
277133965Sjdp					      (struct debug_name *) NULL))
2772130561Sobrien			return FALSE;
277333965Sjdp		    }
277433965Sjdp		  if (! debug_write_type (info, fns, fhandle, v->type,
277533965Sjdp					  (struct debug_name *) NULL))
2776130561Sobrien		    return FALSE;
277733965Sjdp		  if (v->voffset != VOFFSET_STATIC_METHOD)
277833965Sjdp		    {
277933965Sjdp		      if (! (*fns->class_method_variant) (fhandle, v->physname,
278033965Sjdp							  v->visibility,
278133965Sjdp							  v->constp,
278233965Sjdp							  v->volatilep,
278333965Sjdp							  v->voffset,
278433965Sjdp							  v->context != NULL))
2785130561Sobrien			return FALSE;
278633965Sjdp		    }
278733965Sjdp		  else
278833965Sjdp		    {
278933965Sjdp		      if (! (*fns->class_static_method_variant) (fhandle,
279033965Sjdp								 v->physname,
279133965Sjdp								 v->visibility,
279233965Sjdp								 v->constp,
279333965Sjdp								 v->volatilep))
2794130561Sobrien			return FALSE;
279533965Sjdp		    }
279633965Sjdp		}
279733965Sjdp	      if (! (*fns->class_end_method) (fhandle))
2798130561Sobrien		return FALSE;
279933965Sjdp	    }
280033965Sjdp	}
280133965Sjdp    }
280233965Sjdp
280333965Sjdp  return (*fns->end_class_type) (fhandle);
280433965Sjdp}
280533965Sjdp
280633965Sjdp/* Write out information for a function.  */
280733965Sjdp
2808130561Sobrienstatic bfd_boolean
2809130561Sobriendebug_write_function (struct debug_handle *info,
2810130561Sobrien		      const struct debug_write_fns *fns, void *fhandle,
2811130561Sobrien		      const char *name, enum debug_object_linkage linkage,
2812130561Sobrien		      struct debug_function *function)
281333965Sjdp{
281433965Sjdp  struct debug_parameter *p;
281533965Sjdp  struct debug_block *b;
281633965Sjdp
281733965Sjdp  if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
2818130561Sobrien    return FALSE;
281933965Sjdp
282033965Sjdp  if (! debug_write_type (info, fns, fhandle, function->return_type,
282133965Sjdp			  (struct debug_name *) NULL))
2822130561Sobrien    return FALSE;
282333965Sjdp
282433965Sjdp  if (! (*fns->start_function) (fhandle, name,
282533965Sjdp				linkage == DEBUG_LINKAGE_GLOBAL))
2826130561Sobrien    return FALSE;
282733965Sjdp
282833965Sjdp  for (p = function->parameters; p != NULL; p = p->next)
282933965Sjdp    {
283033965Sjdp      if (! debug_write_type (info, fns, fhandle, p->type,
283133965Sjdp			      (struct debug_name *) NULL)
283233965Sjdp	  || ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
2833130561Sobrien	return FALSE;
283433965Sjdp    }
283533965Sjdp
283633965Sjdp  for (b = function->blocks; b != NULL; b = b->next)
283733965Sjdp    {
283833965Sjdp      if (! debug_write_block (info, fns, fhandle, b))
2839130561Sobrien	return FALSE;
284033965Sjdp    }
284133965Sjdp
284233965Sjdp  return (*fns->end_function) (fhandle);
284333965Sjdp}
284433965Sjdp
284533965Sjdp/* Write out information for a block.  */
284633965Sjdp
2847130561Sobrienstatic bfd_boolean
2848130561Sobriendebug_write_block (struct debug_handle *info,
2849130561Sobrien		   const struct debug_write_fns *fns, void *fhandle,
2850130561Sobrien		   struct debug_block *block)
285133965Sjdp{
285233965Sjdp  struct debug_name *n;
285333965Sjdp  struct debug_block *b;
285433965Sjdp
285533965Sjdp  if (! debug_write_linenos (info, fns, fhandle, block->start))
2856130561Sobrien    return FALSE;
285733965Sjdp
285833965Sjdp  /* I can't see any point to writing out a block with no local
285933965Sjdp     variables, so we don't bother, except for the top level block.  */
286033965Sjdp  if (block->locals != NULL || block->parent == NULL)
286133965Sjdp    {
286233965Sjdp      if (! (*fns->start_block) (fhandle, block->start))
2863130561Sobrien	return FALSE;
286433965Sjdp    }
286533965Sjdp
286633965Sjdp  if (block->locals != NULL)
286733965Sjdp    {
286833965Sjdp      for (n = block->locals->list; n != NULL; n = n->next)
286933965Sjdp	{
287033965Sjdp	  if (! debug_write_name (info, fns, fhandle, n))
2871130561Sobrien	    return FALSE;
287233965Sjdp	}
287333965Sjdp    }
287433965Sjdp
287533965Sjdp  for (b = block->children; b != NULL; b = b->next)
287633965Sjdp    {
287733965Sjdp      if (! debug_write_block (info, fns, fhandle, b))
2878130561Sobrien	return FALSE;
287933965Sjdp    }
288033965Sjdp
288133965Sjdp  if (! debug_write_linenos (info, fns, fhandle, block->end))
2882130561Sobrien    return FALSE;
288333965Sjdp
288433965Sjdp  if (block->locals != NULL || block->parent == NULL)
288533965Sjdp    {
288633965Sjdp      if (! (*fns->end_block) (fhandle, block->end))
2887130561Sobrien	return FALSE;
288833965Sjdp    }
288933965Sjdp
2890130561Sobrien  return TRUE;
289133965Sjdp}
289233965Sjdp
289333965Sjdp/* Write out line number information up to ADDRESS.  */
289433965Sjdp
2895130561Sobrienstatic bfd_boolean
2896130561Sobriendebug_write_linenos (struct debug_handle *info,
2897130561Sobrien		     const struct debug_write_fns *fns, void *fhandle,
2898130561Sobrien		     bfd_vma address)
289933965Sjdp{
290033965Sjdp  while (info->current_write_lineno != NULL)
290133965Sjdp    {
290233965Sjdp      struct debug_lineno *l;
290333965Sjdp
290433965Sjdp      l = info->current_write_lineno;
290533965Sjdp
290633965Sjdp      while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
290733965Sjdp	{
290833965Sjdp	  if (l->linenos[info->current_write_lineno_index]
290933965Sjdp	      == (unsigned long) -1)
291033965Sjdp	    break;
291133965Sjdp
291233965Sjdp	  if (l->addrs[info->current_write_lineno_index] >= address)
2913130561Sobrien	    return TRUE;
291433965Sjdp
291533965Sjdp	  if (! (*fns->lineno) (fhandle, l->file->filename,
291633965Sjdp				l->linenos[info->current_write_lineno_index],
291733965Sjdp				l->addrs[info->current_write_lineno_index]))
2918130561Sobrien	    return FALSE;
291933965Sjdp
292033965Sjdp	  ++info->current_write_lineno_index;
292133965Sjdp	}
292233965Sjdp
292333965Sjdp      info->current_write_lineno = l->next;
292433965Sjdp      info->current_write_lineno_index = 0;
292533965Sjdp    }
292633965Sjdp
2927130561Sobrien  return TRUE;
292833965Sjdp}
292933965Sjdp
293033965Sjdp/* Get the ID number for a class.  If during the same call to
293133965Sjdp   debug_write we find a struct with the same definition with the same
293233965Sjdp   name, we use the same ID.  This type of things happens because the
293333965Sjdp   same struct will be defined by multiple compilation units.  */
293433965Sjdp
2935130561Sobrienstatic bfd_boolean
2936130561Sobriendebug_set_class_id (struct debug_handle *info, const char *tag,
2937130561Sobrien		    struct debug_type *type)
293833965Sjdp{
293933965Sjdp  struct debug_class_type *c;
294033965Sjdp  struct debug_class_id *l;
294133965Sjdp
294233965Sjdp  assert (type->kind == DEBUG_KIND_STRUCT
294333965Sjdp	  || type->kind == DEBUG_KIND_UNION
294433965Sjdp	  || type->kind == DEBUG_KIND_CLASS
294533965Sjdp	  || type->kind == DEBUG_KIND_UNION_CLASS);
294633965Sjdp
294733965Sjdp  c = type->u.kclass;
294833965Sjdp
294933965Sjdp  if (c->id > info->base_id)
2950130561Sobrien    return TRUE;
295133965Sjdp
295233965Sjdp  for (l = info->id_list; l != NULL; l = l->next)
295333965Sjdp    {
295433965Sjdp      if (l->type->kind != type->kind)
295533965Sjdp	continue;
295633965Sjdp
295733965Sjdp      if (tag == NULL)
295833965Sjdp	{
295933965Sjdp	  if (l->tag != NULL)
296033965Sjdp	    continue;
296133965Sjdp	}
296233965Sjdp      else
296333965Sjdp	{
296433965Sjdp	  if (l->tag == NULL
296533965Sjdp	      || l->tag[0] != tag[0]
296633965Sjdp	      || strcmp (l->tag, tag) != 0)
296733965Sjdp	    continue;
296833965Sjdp	}
296933965Sjdp
297033965Sjdp      if (debug_type_samep (info, l->type, type))
297133965Sjdp	{
297233965Sjdp	  c->id = l->type->u.kclass->id;
2973130561Sobrien	  return TRUE;
297433965Sjdp	}
297533965Sjdp    }
297633965Sjdp
297733965Sjdp  /* There are no identical types.  Use a new ID, and add it to the
297833965Sjdp     list.  */
297933965Sjdp  ++info->class_id;
298033965Sjdp  c->id = info->class_id;
298133965Sjdp
298233965Sjdp  l = (struct debug_class_id *) xmalloc (sizeof *l);
298333965Sjdp  memset (l, 0, sizeof *l);
298433965Sjdp
298533965Sjdp  l->type = type;
298633965Sjdp  l->tag = tag;
298733965Sjdp
298833965Sjdp  l->next = info->id_list;
298933965Sjdp  info->id_list = l;
299033965Sjdp
2991130561Sobrien  return TRUE;
299233965Sjdp}
299333965Sjdp
299433965Sjdp/* See if two types are the same.  At this point, we don't care about
299533965Sjdp   tags and the like.  */
299633965Sjdp
2997130561Sobrienstatic bfd_boolean
2998130561Sobriendebug_type_samep (struct debug_handle *info, struct debug_type *t1,
2999130561Sobrien		  struct debug_type *t2)
300033965Sjdp{
300133965Sjdp  struct debug_type_compare_list *l;
300233965Sjdp  struct debug_type_compare_list top;
3003130561Sobrien  bfd_boolean ret;
300433965Sjdp
300533965Sjdp  if (t1 == NULL)
300633965Sjdp    return t2 == NULL;
300733965Sjdp  if (t2 == NULL)
3008130561Sobrien    return FALSE;
300933965Sjdp
301033965Sjdp  while (t1->kind == DEBUG_KIND_INDIRECT)
301133965Sjdp    {
301233965Sjdp      t1 = *t1->u.kindirect->slot;
301333965Sjdp      if (t1 == NULL)
3014130561Sobrien	return FALSE;
301533965Sjdp    }
301633965Sjdp  while (t2->kind == DEBUG_KIND_INDIRECT)
301733965Sjdp    {
301833965Sjdp      t2 = *t2->u.kindirect->slot;
301933965Sjdp      if (t2 == NULL)
3020130561Sobrien	return FALSE;
302133965Sjdp    }
302233965Sjdp
302333965Sjdp  if (t1 == t2)
3024130561Sobrien    return TRUE;
302533965Sjdp
302633965Sjdp  /* As a special case, permit a typedef to match a tag, since C++
302733965Sjdp     debugging output will sometimes add a typedef where C debugging
302833965Sjdp     output will not.  */
302933965Sjdp  if (t1->kind == DEBUG_KIND_NAMED
303033965Sjdp      && t2->kind == DEBUG_KIND_TAGGED)
303133965Sjdp    return debug_type_samep (info, t1->u.knamed->type, t2);
303233965Sjdp  else if (t1->kind == DEBUG_KIND_TAGGED
303333965Sjdp	   && t2->kind == DEBUG_KIND_NAMED)
303433965Sjdp    return debug_type_samep (info, t1, t2->u.knamed->type);
303533965Sjdp
303633965Sjdp  if (t1->kind != t2->kind
303733965Sjdp      || t1->size != t2->size)
3038130561Sobrien    return FALSE;
303933965Sjdp
304033965Sjdp  /* Get rid of the trivial cases first.  */
304133965Sjdp  switch (t1->kind)
304233965Sjdp    {
304333965Sjdp    default:
304433965Sjdp      break;
304533965Sjdp    case DEBUG_KIND_VOID:
304633965Sjdp    case DEBUG_KIND_FLOAT:
304733965Sjdp    case DEBUG_KIND_COMPLEX:
304833965Sjdp    case DEBUG_KIND_BOOL:
3049130561Sobrien      return TRUE;
305033965Sjdp    case DEBUG_KIND_INT:
305133965Sjdp      return t1->u.kint == t2->u.kint;
305233965Sjdp    }
305333965Sjdp
305433965Sjdp  /* We have to avoid an infinite recursion.  We do this by keeping a
305533965Sjdp     list of types which we are comparing.  We just keep the list on
305633965Sjdp     the stack.  If we encounter a pair of types we are currently
305733965Sjdp     comparing, we just assume that they are equal.  */
305833965Sjdp  for (l = info->compare_list; l != NULL; l = l->next)
305933965Sjdp    {
306033965Sjdp      if (l->t1 == t1 && l->t2 == t2)
3061130561Sobrien	return TRUE;
306233965Sjdp    }
306333965Sjdp
306433965Sjdp  top.t1 = t1;
306533965Sjdp  top.t2 = t2;
306633965Sjdp  top.next = info->compare_list;
306733965Sjdp  info->compare_list = &top;
306833965Sjdp
306933965Sjdp  switch (t1->kind)
307033965Sjdp    {
307133965Sjdp    default:
307233965Sjdp      abort ();
3073130561Sobrien      ret = FALSE;
307433965Sjdp      break;
307533965Sjdp
307633965Sjdp    case DEBUG_KIND_STRUCT:
307733965Sjdp    case DEBUG_KIND_UNION:
307833965Sjdp    case DEBUG_KIND_CLASS:
307933965Sjdp    case DEBUG_KIND_UNION_CLASS:
308033965Sjdp      if (t1->u.kclass == NULL)
308133965Sjdp	ret = t2->u.kclass == NULL;
308233965Sjdp      else if (t2->u.kclass == NULL)
3083130561Sobrien	ret = FALSE;
308433965Sjdp      else if (t1->u.kclass->id > info->base_id
308533965Sjdp	       && t1->u.kclass->id == t2->u.kclass->id)
3086130561Sobrien	ret = TRUE;
308733965Sjdp      else
308833965Sjdp	ret = debug_class_type_samep (info, t1, t2);
308933965Sjdp      break;
309033965Sjdp
309133965Sjdp    case DEBUG_KIND_ENUM:
309233965Sjdp      if (t1->u.kenum == NULL)
309333965Sjdp	ret = t2->u.kenum == NULL;
309433965Sjdp      else if (t2->u.kenum == NULL)
3095130561Sobrien	ret = FALSE;
309633965Sjdp      else
309733965Sjdp	{
309833965Sjdp	  const char **pn1, **pn2;
309933965Sjdp	  bfd_signed_vma *pv1, *pv2;
310033965Sjdp
310133965Sjdp	  pn1 = t1->u.kenum->names;
310233965Sjdp	  pn2 = t2->u.kenum->names;
310333965Sjdp	  pv1 = t1->u.kenum->values;
310433965Sjdp	  pv2 = t2->u.kenum->values;
310533965Sjdp	  while (*pn1 != NULL && *pn2 != NULL)
310633965Sjdp	    {
310733965Sjdp	      if (**pn1 != **pn2
310833965Sjdp		  || *pv1 != *pv2
310933965Sjdp		  || strcmp (*pn1, *pn2) != 0)
311033965Sjdp		break;
311133965Sjdp	      ++pn1;
311233965Sjdp	      ++pn2;
311333965Sjdp	      ++pv1;
311433965Sjdp	      ++pv2;
311533965Sjdp	    }
311633965Sjdp	  ret = *pn1 == NULL && *pn2 == NULL;
311733965Sjdp	}
311833965Sjdp      break;
311933965Sjdp
312033965Sjdp    case DEBUG_KIND_POINTER:
312133965Sjdp      ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
312233965Sjdp      break;
3123104834Sobrien
312433965Sjdp    case DEBUG_KIND_FUNCTION:
312533965Sjdp      if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
312633965Sjdp	  || ! debug_type_samep (info, t1->u.kfunction->return_type,
312733965Sjdp				 t2->u.kfunction->return_type)
312833965Sjdp	  || ((t1->u.kfunction->arg_types == NULL)
312933965Sjdp	      != (t2->u.kfunction->arg_types == NULL)))
3130130561Sobrien	ret = FALSE;
313133965Sjdp      else if (t1->u.kfunction->arg_types == NULL)
3132130561Sobrien	ret = TRUE;
313333965Sjdp      else
313433965Sjdp	{
313533965Sjdp	  struct debug_type **a1, **a2;
313633965Sjdp
313733965Sjdp	  a1 = t1->u.kfunction->arg_types;
313833965Sjdp	  a2 = t2->u.kfunction->arg_types;
313933965Sjdp	  while (*a1 != NULL && *a2 != NULL)
314060484Sobrien	    {
314160484Sobrien	      if (! debug_type_samep (info, *a1, *a2))
314260484Sobrien		break;
314360484Sobrien	      ++a1;
314460484Sobrien	      ++a2;
314560484Sobrien	    }
314633965Sjdp	  ret = *a1 == NULL && *a2 == NULL;
314733965Sjdp	}
314833965Sjdp      break;
314933965Sjdp
315033965Sjdp    case DEBUG_KIND_REFERENCE:
315133965Sjdp      ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
315233965Sjdp      break;
315333965Sjdp
315433965Sjdp    case DEBUG_KIND_RANGE:
315533965Sjdp      ret = (t1->u.krange->lower == t2->u.krange->lower
315633965Sjdp	     && t1->u.krange->upper == t2->u.krange->upper
315733965Sjdp	     && debug_type_samep (info, t1->u.krange->type,
315833965Sjdp				  t2->u.krange->type));
315933965Sjdp
316033965Sjdp    case DEBUG_KIND_ARRAY:
316133965Sjdp      ret = (t1->u.karray->lower == t2->u.karray->lower
316233965Sjdp	     && t1->u.karray->upper == t2->u.karray->upper
316333965Sjdp	     && t1->u.karray->stringp == t2->u.karray->stringp
316433965Sjdp	     && debug_type_samep (info, t1->u.karray->element_type,
316533965Sjdp				  t2->u.karray->element_type));
316633965Sjdp      break;
316733965Sjdp
316833965Sjdp    case DEBUG_KIND_SET:
316933965Sjdp      ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
317033965Sjdp	     && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
317133965Sjdp      break;
317233965Sjdp
317333965Sjdp    case DEBUG_KIND_OFFSET:
317433965Sjdp      ret = (debug_type_samep (info, t1->u.koffset->base_type,
317533965Sjdp			       t2->u.koffset->base_type)
317633965Sjdp	     && debug_type_samep (info, t1->u.koffset->target_type,
317733965Sjdp				  t2->u.koffset->target_type));
317833965Sjdp      break;
317933965Sjdp
318033965Sjdp    case DEBUG_KIND_METHOD:
318133965Sjdp      if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
318233965Sjdp	  || ! debug_type_samep (info, t1->u.kmethod->return_type,
318333965Sjdp				 t2->u.kmethod->return_type)
318433965Sjdp	  || ! debug_type_samep (info, t1->u.kmethod->domain_type,
318533965Sjdp				 t2->u.kmethod->domain_type)
318633965Sjdp	  || ((t1->u.kmethod->arg_types == NULL)
318733965Sjdp	      != (t2->u.kmethod->arg_types == NULL)))
3188130561Sobrien	ret = FALSE;
318933965Sjdp      else if (t1->u.kmethod->arg_types == NULL)
3190130561Sobrien	ret = TRUE;
319133965Sjdp      else
319233965Sjdp	{
319333965Sjdp	  struct debug_type **a1, **a2;
319433965Sjdp
319533965Sjdp	  a1 = t1->u.kmethod->arg_types;
319633965Sjdp	  a2 = t2->u.kmethod->arg_types;
319733965Sjdp	  while (*a1 != NULL && *a2 != NULL)
319860484Sobrien	    {
319960484Sobrien	      if (! debug_type_samep (info, *a1, *a2))
320060484Sobrien		break;
320160484Sobrien	      ++a1;
320260484Sobrien	      ++a2;
320360484Sobrien	    }
320433965Sjdp	  ret = *a1 == NULL && *a2 == NULL;
320533965Sjdp	}
320633965Sjdp      break;
320733965Sjdp
320833965Sjdp    case DEBUG_KIND_CONST:
320933965Sjdp      ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
321033965Sjdp      break;
321133965Sjdp
321233965Sjdp    case DEBUG_KIND_VOLATILE:
321333965Sjdp      ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
321433965Sjdp      break;
321533965Sjdp
321633965Sjdp    case DEBUG_KIND_NAMED:
321733965Sjdp    case DEBUG_KIND_TAGGED:
321833965Sjdp      ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
321933965Sjdp	     && debug_type_samep (info, t1->u.knamed->type,
322033965Sjdp				  t2->u.knamed->type));
322133965Sjdp      break;
322233965Sjdp    }
322333965Sjdp
322433965Sjdp  info->compare_list = top.next;
322533965Sjdp
322633965Sjdp  return ret;
322733965Sjdp}
322833965Sjdp
322933965Sjdp/* See if two classes are the same.  This is a subroutine of
323033965Sjdp   debug_type_samep.  */
323133965Sjdp
3232130561Sobrienstatic bfd_boolean
3233130561Sobriendebug_class_type_samep (struct debug_handle *info, struct debug_type *t1,
3234130561Sobrien			struct debug_type *t2)
323533965Sjdp{
323633965Sjdp  struct debug_class_type *c1, *c2;
323733965Sjdp
323833965Sjdp  c1 = t1->u.kclass;
323933965Sjdp  c2 = t2->u.kclass;
324033965Sjdp
324133965Sjdp  if ((c1->fields == NULL) != (c2->fields == NULL)
324233965Sjdp      || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
324333965Sjdp      || (c1->methods == NULL) != (c2->methods == NULL)
324433965Sjdp      || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
3245130561Sobrien    return FALSE;
324633965Sjdp
324733965Sjdp  if (c1->fields != NULL)
324833965Sjdp    {
324933965Sjdp      struct debug_field **pf1, **pf2;
325033965Sjdp
325133965Sjdp      for (pf1 = c1->fields, pf2 = c2->fields;
325233965Sjdp	   *pf1 != NULL && *pf2 != NULL;
325333965Sjdp	   pf1++, pf2++)
325433965Sjdp	{
325533965Sjdp	  struct debug_field *f1, *f2;
325633965Sjdp
325733965Sjdp	  f1 = *pf1;
325833965Sjdp	  f2 = *pf2;
325933965Sjdp	  if (f1->name[0] != f2->name[0]
326033965Sjdp	      || f1->visibility != f2->visibility
326133965Sjdp	      || f1->static_member != f2->static_member)
3262130561Sobrien	    return FALSE;
326333965Sjdp	  if (f1->static_member)
326433965Sjdp	    {
326533965Sjdp	      if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
3266130561Sobrien		return FALSE;
326733965Sjdp	    }
326833965Sjdp	  else
326933965Sjdp	    {
327033965Sjdp	      if (f1->u.f.bitpos != f2->u.f.bitpos
327133965Sjdp		  || f1->u.f.bitsize != f2->u.f.bitsize)
3272130561Sobrien		return FALSE;
327333965Sjdp	    }
327433965Sjdp	  /* We do the checks which require function calls last.  We
327533965Sjdp             don't require that the types of fields have the same
327633965Sjdp             names, since that sometimes fails in the presence of
327733965Sjdp             typedefs and we really don't care.  */
327833965Sjdp	  if (strcmp (f1->name, f2->name) != 0
327933965Sjdp	      || ! debug_type_samep (info,
3280130561Sobrien				     debug_get_real_type ((void *) info,
328160484Sobrien							  f1->type, NULL),
3282130561Sobrien				     debug_get_real_type ((void *) info,
328360484Sobrien							  f2->type, NULL)))
3284130561Sobrien	    return FALSE;
328533965Sjdp	}
328633965Sjdp      if (*pf1 != NULL || *pf2 != NULL)
3287130561Sobrien	return FALSE;
328833965Sjdp    }
328933965Sjdp
329033965Sjdp  if (c1->vptrbase != NULL)
329133965Sjdp    {
329233965Sjdp      if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
3293130561Sobrien	return FALSE;
329433965Sjdp    }
329533965Sjdp
329633965Sjdp  if (c1->baseclasses != NULL)
329733965Sjdp    {
329833965Sjdp      struct debug_baseclass **pb1, **pb2;
329933965Sjdp
330033965Sjdp      for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
330133965Sjdp	   *pb1 != NULL && *pb2 != NULL;
330233965Sjdp	   ++pb1, ++pb2)
330333965Sjdp	{
330433965Sjdp	  struct debug_baseclass *b1, *b2;
330533965Sjdp
330633965Sjdp	  b1 = *pb1;
330733965Sjdp	  b2 = *pb2;
330833965Sjdp	  if (b1->bitpos != b2->bitpos
330933965Sjdp	      || b1->virtual != b2->virtual
331033965Sjdp	      || b1->visibility != b2->visibility
331133965Sjdp	      || ! debug_type_samep (info, b1->type, b2->type))
3312130561Sobrien	    return FALSE;
331333965Sjdp	}
331433965Sjdp      if (*pb1 != NULL || *pb2 != NULL)
3315130561Sobrien	return FALSE;
331633965Sjdp    }
331733965Sjdp
331833965Sjdp  if (c1->methods != NULL)
331933965Sjdp    {
332033965Sjdp      struct debug_method **pm1, **pm2;
332133965Sjdp
332233965Sjdp      for (pm1 = c1->methods, pm2 = c2->methods;
332333965Sjdp	   *pm1 != NULL && *pm2 != NULL;
332433965Sjdp	   ++pm1, ++pm2)
332533965Sjdp	{
332633965Sjdp	  struct debug_method *m1, *m2;
332733965Sjdp
332833965Sjdp	  m1 = *pm1;
332933965Sjdp	  m2 = *pm2;
333033965Sjdp	  if (m1->name[0] != m2->name[0]
333133965Sjdp	      || strcmp (m1->name, m2->name) != 0
333233965Sjdp	      || (m1->variants == NULL) != (m2->variants == NULL))
3333130561Sobrien	    return FALSE;
333433965Sjdp	  if (m1->variants == NULL)
333533965Sjdp	    {
333633965Sjdp	      struct debug_method_variant **pv1, **pv2;
333733965Sjdp
333833965Sjdp	      for (pv1 = m1->variants, pv2 = m2->variants;
333933965Sjdp		   *pv1 != NULL && *pv2 != NULL;
334033965Sjdp		   ++pv1, ++pv2)
334133965Sjdp		{
334233965Sjdp		  struct debug_method_variant *v1, *v2;
334333965Sjdp
334433965Sjdp		  v1 = *pv1;
334533965Sjdp		  v2 = *pv2;
334633965Sjdp		  if (v1->physname[0] != v2->physname[0]
334733965Sjdp		      || v1->visibility != v2->visibility
334833965Sjdp		      || v1->constp != v2->constp
334933965Sjdp		      || v1->volatilep != v2->volatilep
335033965Sjdp		      || v1->voffset != v2->voffset
335133965Sjdp		      || (v1->context == NULL) != (v2->context == NULL)
335233965Sjdp		      || strcmp (v1->physname, v2->physname) != 0
335333965Sjdp		      || ! debug_type_samep (info, v1->type, v2->type))
3354130561Sobrien		    return FALSE;
335533965Sjdp		  if (v1->context != NULL)
335633965Sjdp		    {
335733965Sjdp		      if (! debug_type_samep (info, v1->context,
335833965Sjdp					      v2->context))
3359130561Sobrien			return FALSE;
336033965Sjdp		    }
336133965Sjdp		}
336233965Sjdp	      if (*pv1 != NULL || *pv2 != NULL)
3363130561Sobrien		return FALSE;
336433965Sjdp	    }
336533965Sjdp	}
336633965Sjdp      if (*pm1 != NULL || *pm2 != NULL)
3367130561Sobrien	return FALSE;
336833965Sjdp    }
336933965Sjdp
3370130561Sobrien  return TRUE;
337133965Sjdp}
3372