OSDN Git Service

886c218f78d4ca878b58c060f3836b020772e1e6
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2    Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3    Contributed by Gary Funck (gary@intrepid.com).  Derived from the
4    DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
21
22 #include "config.h"
23
24 #if defined(DWARF_DEBUGGING_INFO) && defined(DWARF_VERSION) \
25     && DWARF_VERSION == 2
26 #include <stdio.h>
27 #include "dwarf2.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "rtl.h"
31 #include "hard-reg-set.h"
32 #include "regs.h"
33 #include "insn-config.h"
34 #include "reload.h"
35 #include "output.h"
36 #include "defaults.h"
37
38 /* #define NDEBUG 1 */
39 #include "assert.h"
40 #if defined(DWARF_TIMESTAMPS)
41 #if defined(POSIX)
42 #include <time.h>
43 #else /* !defined(POSIX) */
44 #include <sys/types.h>
45 #if defined(__STDC__)
46 extern time_t time (time_t *);
47 #else /* !defined(__STDC__) */
48 extern time_t time ();
49 #endif /* !defined(__STDC__) */
50 #endif /* !defined(POSIX) */
51 #endif /* defined(DWARF_TIMESTAMPS) */
52
53 extern char *getpwd ();
54 extern char *index ();
55 extern char *rindex ();
56
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58    regarding the GNU implementation of DWARF.  */
59
60 /* NOTE: In the comments in this file, many references are made to
61    "Debugging Information Entries".  This term is abbreviated as `DIE'
62    throughout the remainder of this file.  */
63
64 /* NOTE: The implementation of C++ support is unfinished.  */
65
66 #if defined(__GNUC__) && (NDEBUG == 1)
67 #define inline static inline
68 #else
69 #define inline static
70 #endif
71
72
73 /* An internal representation of the DWARF output is built, and then
74    walked to generate the DWARF debugging info.  The walk of the internal
75    representation is done after the entire program has been compiled.
76    The types below are used to describe the internal representation.  */
77
78 /* Each DIE may have a series of attribute/value pairs.  Values
79    can take on several forms.  The forms that are used in this
80    impelementation are listed below.  */
81 typedef enum
82   {
83     dw_val_class_addr,
84     dw_val_class_loc,
85     dw_val_class_const,
86     dw_val_class_unsigned_const,
87     dw_val_class_double_const,
88     dw_val_class_flag,
89     dw_val_class_die_ref,
90     dw_val_class_fde_ref,
91     dw_val_class_lbl_id,
92     dw_val_class_section_offset,
93     dw_val_class_str
94   }
95 dw_val_class;
96
97 /* Various DIE's use offsets relative to the beginning of the
98    .debug_info section to refer to each other.  */
99 typedef long int dw_offset;
100
101 /* Define typedefs here to avoid circular dependencies.  */
102 typedef struct die_struct *dw_die_ref;
103 typedef struct dw_attr_struct *dw_attr_ref;
104 typedef struct dw_val_struct *dw_val_ref;
105 typedef struct dw_line_info_struct *dw_line_info_ref;
106 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
107 typedef struct dw_cfi_struct *dw_cfi_ref;
108 typedef struct dw_fde_struct *dw_fde_ref;
109 typedef union  dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
110 typedef struct backchain *backchain_ref;
111
112 /* Describe a double word constant value.  */
113 typedef struct dw_double_const_struct
114   {
115     unsigned long dw_dbl_hi;
116     unsigned long dw_dbl_low;
117   }
118 dw_dbl_const;
119
120 /* Each entry in the line_info_table maintains the file and
121    line nuber associated with the label generated for that
122    entry.  The label gives the PC value associated with
123    the line number entry.  */
124 typedef struct dw_line_info_struct
125   {
126     unsigned long dw_file_num;
127     unsigned long dw_line_num;
128   }
129 dw_line_info_entry;
130
131 /* The dw_val_node describes an attibute's value, as it is
132    represnted internally.  */
133 typedef struct dw_val_struct
134   {
135     dw_val_class val_class;
136     union
137       {
138         char *val_addr;
139         dw_loc_descr_ref val_loc;
140         long int val_int;
141         long unsigned val_unsigned;
142         dw_dbl_const val_dbl_const;
143         dw_die_ref val_die_ref;
144         unsigned val_fde_index;
145         char *val_str;
146         char *val_lbl_id;
147         char *val_section;
148         unsigned char val_flag;
149       }
150     v;
151   }
152 dw_val_node;
153
154 /* Locations in memory are described using a sequence of stack machine
155    operations.  */
156 typedef struct dw_loc_descr_struct
157   {
158     dw_loc_descr_ref dw_loc_next;
159     enum dwarf_location_atom dw_loc_opc;
160     dw_val_node dw_loc_oprnd1;
161     dw_val_node dw_loc_oprnd2;
162   }
163 dw_loc_descr_node;
164
165 /* Each DIE attribute has a field specifying the attribute kind,
166    a link to the next attribute in the chain, and an attribute value.
167    Attributes are typically linked below the DIE they modify.  */
168 typedef struct dw_attr_struct
169   {
170     enum dwarf_attribute dw_attr;
171     dw_attr_ref dw_attr_next;
172     dw_val_node dw_attr_val;
173   }
174 dw_attr_node;
175
176 /* Call frames are described using a sequence of Call Frame
177    Information instructions.  The register number, offset
178    and address fields are provided as possible operands;
179    their use is selected by the opcode field.  */
180 typedef union dw_cfi_oprnd_struct
181   {
182     unsigned long dw_cfi_reg_num;
183     long int dw_cfi_offset;
184     char *dw_cfi_addr;
185   }
186 dw_cfi_oprnd;
187
188 typedef struct dw_cfi_struct
189   {
190     dw_cfi_ref dw_cfi_next;
191     enum dwarf_call_frame_info dw_cfi_opc;
192     dw_cfi_oprnd dw_cfi_oprnd1;
193     dw_cfi_oprnd dw_cfi_oprnd2;
194   }
195 dw_cfi_node;
196
197 /* All call frame descriptions (FDE's) in the GCC generated DWARF
198    refer to a signle Common Information Entry (CIE), defined at
199    the beginning of the .debug_frame section.  This used of a single
200    CIE obviates the need to keep track of multiple CIE's
201    in the DWARF generation routines below.  */
202 typedef struct dw_fde_struct
203   {
204     unsigned long dw_fde_offset;
205     char *dw_fde_begin;
206     char *dw_fde_end_prolog;
207     char *dw_fde_begin_epilogue;
208     char *dw_fde_end;
209     dw_cfi_ref dw_fde_cfi;
210   }
211 dw_fde_node;
212
213 /* The Debugging Information Entry (DIE) structure */
214 typedef struct die_struct
215   {
216     enum dwarf_tag die_tag;
217     dw_attr_ref die_attr;
218     dw_attr_ref die_attr_last;
219     dw_die_ref die_parent;
220     dw_die_ref die_child;
221     dw_die_ref die_child_last;
222     dw_die_ref die_sib;
223     dw_offset die_offset;
224     unsigned long die_abbrev;
225   }
226 die_node;
227
228 /* The structure for backchaining support, when structure tags are declared
229    before they are defined.  */
230
231 typedef struct backchain
232   {
233     tree type;
234     dw_die_ref placeholder;
235     backchain_ref next;
236   }
237 backchain_t;
238
239 /* How to start an assembler comment.  */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
242 #endif
243
244 /* Define a macro which returns non-zero for any tagged type which is used
245    (directly or indirectly) in the specification of either some function's
246    return type or some formal parameter of some function. We use this macro
247    when we are operating in "terse" mode to help us know what tagged types
248    have to be represented in Dwarf (even in terse mode) and which ones don't.
249    A flag bit with this meaning really should be a part of the normal GCC
250    ..._TYPE nodes, but at the moment, there is no such bit defined for these
251    nodes.  For now, we have to just fake it.  It it safe for us to simply
252    return zero for all complete tagged types (which will get forced out
253    anyway if they were used in the specification of some formal or return
254    type) and non-zero for all incomplete tagged types.  */
255 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
256
257 /* Information concerning the compilation unit's programming
258    language, and compiler version.  */
259 extern int flag_traditional;
260 extern char *version_string;
261 extern char *language_string;
262
263 /* Maximum size (in bytes) of an artificially generated label.   */
264 #define MAX_ARTIFICIAL_LABEL_BYTES      30
265
266 /* Make sure we know the sizes of the various types dwarf can describe. These
267    are only defaults.  If the sizes are different for your target, you should
268    override these values by defining the appropriate symbols in your tm.h
269    file.  */
270 #ifndef CHAR_TYPE_SIZE
271 #define CHAR_TYPE_SIZE BITS_PER_UNIT
272 #endif
273 #ifndef SHORT_TYPE_SIZE
274 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
275 #endif
276 #ifndef INT_TYPE_SIZE
277 #define INT_TYPE_SIZE BITS_PER_WORD
278 #endif
279 #ifndef LONG_TYPE_SIZE
280 #define LONG_TYPE_SIZE BITS_PER_WORD
281 #endif
282 #ifndef LONG_LONG_TYPE_SIZE
283 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
284 #endif
285 #ifndef WCHAR_TYPE_SIZE
286 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
287 #endif
288 #ifndef WCHAR_UNSIGNED
289 #define WCHAR_UNSIGNED 0
290 #endif
291 #ifndef FLOAT_TYPE_SIZE
292 #define FLOAT_TYPE_SIZE BITS_PER_WORD
293 #endif
294 #ifndef DOUBLE_TYPE_SIZE
295 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
296 #endif
297 #ifndef LONG_DOUBLE_TYPE_SIZE
298 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
299 #endif
300 #ifndef PTR_SIZE
301 #define PTR_SIZE (POINTER_SIZE / 8)
302 #endif
303
304 /* Fixed size portion of the DWARF compilation unit header.  */
305 #define DWARF_COMPILE_UNIT_HEADER_SIZE 11
306
307 /* Fixed size portion of debugging line information prolog.  */
308 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
309
310 /* Fixed size portion of public names info.  */
311 #define DWARF_PUBNAMES_HEADER_SIZE 10
312
313 /* Fixed size portion of the address range info.  */
314 #define DWARF_ARANGES_HEADER_SIZE 12
315
316 /* Fixed size portion of the Common Information Entry (including
317    the length field).  */
318 #define DWARF_CIE_HEADER_SIZE 16
319
320 /* Fixed size of the Common Information Entry in the call frame
321    information (.debug_frame) section rounded up to an 8 byte boundary.  */
322 #define DWARF_CIE_SIZE ((DWARF_CIE_HEADER_SIZE + 7) & ~7)
323
324 /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
325 #define DWARF_CIE_DATA_ALIGNMENT -4
326
327 /* Fixed size portion of the FDE.  */
328 #define DWARF_FDE_HEADER_SIZE (4 + 4 + (2 * PTR_SIZE))
329
330 /* Define the architecture-dependent minimum instruction length (in bytes).
331    In this implementation of DWARF, this field is used for information
332    purposes only.  Since GCC generates assembly language, we have
333    no a priori knowledge of how many instruction bytes are generated
334    for each source line, and therefore can use only the  DW_LNE_set_address
335    and DW_LNS_fixed_advance_pc line information commands.  */
336 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
337 #define DWARF_LINE_MIN_INSTR_LENGTH 4
338 #endif
339
340 /* Minimum line offset in a special line info. opcode.
341    This value was chosen to give a reasonable range of values.  */
342 #define DWARF_LINE_BASE  -10
343
344 /* First special line opcde - leave room for the standard opcodes.  */
345 #define DWARF_LINE_OPCODE_BASE  10
346
347 /* Range of line offsets in a special line info. opcode.  */
348 #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
349
350 /* Flag that indicates the initial value of the is_stmt_start flag.
351    In the present implementation, we do not mark any lines as
352    the beginning of a source statement, because that information
353    is not made available by the GCC front-end.  */
354 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
355
356 /* This location is used by calc_die_sizes() to keep track
357    the offset of each DIE within the .debug_info section.  */
358 static unsigned long next_die_offset;
359
360 /* This location is used by calc_fde_sizes() to keep track
361    the offset of each FDE within the .debug_frame section.  */
362 static unsigned long next_fde_offset;
363
364 /* Record the root of the DIE's built for the current compilation unit.  */
365 dw_die_ref comp_unit_die;
366
367 /* Pointer to an array of filenames referenced by this compilation unit.  */
368 static char **file_table;
369
370 /* Total number of entries in the table (i.e. array) pointed to by
371    `file_table'.  This is the *total* and includes both used and unused
372    slots.  */
373 static unsigned file_table_allocated;
374
375 /* Number of entries in the file_table which are actually in use.  */
376 static unsigned file_table_in_use;
377
378 /* Size (in elements) of increments by which we may expand the filename
379    table.  */
380 #define FILE_TABLE_INCREMENT 64
381
382 /* Local pointer to the name of the main input file.  Initialized in
383    dwarfout_init.  */
384 static char *primary_filename;
385
386 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
387    which their beginnings are encountered. We output Dwarf debugging info
388    that refers to the beginnings and ends of the ranges of code for each
389    lexical block.  The labels themselves are generated in final.c, which
390    assigns numbers to the blocks in the same way.  */
391 static unsigned next_block_number = 2;
392
393 /* Non-zero if we are performing the file-scope finalization pass and if we
394    should force out Dwarf descriptions of any and all file-scope tagged types
395    which are still incomplete types.  */
396 static int finalizing = 0;
397
398 /* A pointer to the base of a list of references to DIE's that describe
399    types.  The table is indexed by TYPE_UID() which is a unique number,
400    indentifying each type.  */
401 static dw_die_ref *type_die_table;
402
403 /* Number of elements currently allocated for type_die_table.  */
404 static unsigned type_die_table_allocated;
405
406 /* Number of elements in type_die_table currently in use.  */
407 static unsigned type_die_table_in_use;
408
409 /* Size (in elements) of increments by which we may expand the
410    type_die_table.  */
411 #define TYPE_DIE_TABLE_INCREMENT 4096
412
413 /* A pointer to the base of a table of references to DIE's that describe
414    declarations.  The table is indexed by DECL_UID() which is a unique
415    number, indentifying each decl.  */
416 static dw_die_ref *decl_die_table;
417
418 /* Number of elements currently allocated for the decl_die_table.  */
419 static unsigned decl_die_table_allocated;
420
421 /* Number of elements in decl_die_table currently in use.  */
422 static unsigned decl_die_table_in_use;
423
424 /* Size (in elements) of increments by which we may expand the
425    decl_die_table.  */
426 #define DECL_DIE_TABLE_INCREMENT 256
427
428 /* A pointer to the base of a table of references to declaration
429    scopes.  This table is a display which tracks the nesting
430    of declaration scopes at the current scope and containing
431    scopes.  This table is used to find the proper place to
432    define type declaration DIE's.  */
433 static tree *decl_scope_table;
434
435 /* Number of elements currently allocated for the decl_scope_table.  */
436 static unsigned decl_scope_table_allocated;
437
438 /* Current level of nesting of declataion scopes.  */
439 static unsigned decl_scope_depth;
440
441 /* Size (in elements) of increments by which we may expand the
442    decl_scope_table.  */
443 #define DECL_SCOPE_TABLE_INCREMENT 64
444
445 /* A pointer to the base of a list of references to DIE's that
446    are uniquely identified by their tag, presence/absence of
447    children DIE's, and list of attribute/value pairs.  */
448 static dw_die_ref *abbrev_die_table;
449
450 /* Number of elements currently allocated for abbrev_die_table.  */
451 static unsigned abbrev_die_table_allocated;
452
453 /* Number of elements in type_die_table currently in use.  */
454 static unsigned abbrev_die_table_in_use;
455
456 /* Size (in elements) of increments by which we may expand the
457    abbrev_die_table.  */
458 #define ABBREV_DIE_TABLE_INCREMENT 256
459
460 /* A pointer to the base of a table that contains line information
461    for each source code line in the compilation unit.  */
462 static dw_line_info_ref line_info_table;
463
464 /* Number of elements currently allocated for line_info_table.  */
465 static unsigned line_info_table_allocated;
466
467 /* Number of elements in line_info_table currently in use.  */
468 static unsigned line_info_table_in_use;
469
470 /* Size (in elements) of increments by which we may expand the
471    line_info_table.  */
472 #define LINE_INFO_TABLE_INCREMENT 1024
473
474 /* Keep track of the last line_info_table entry number, returned
475    by the prior call to lookup_filename().  This serves as a
476    cache used to speed up file name look ups.  */
477 static unsigned prev_file_entry_num = (unsigned) -1;
478
479 /* A pointer to the base of a table that contains frame description
480    information for each routine.  */
481 static dw_fde_ref fde_table;
482
483 /* Number of elements currently allocated for fde_table.  */
484 static unsigned fde_table_allocated;
485
486 /* Number of elements in fde_table currently in use.  */
487 static unsigned fde_table_in_use;
488
489 /* Size (in elements) of increments by which we may expand the
490    fde_table.  */
491 #define FDE_TABLE_INCREMENT 256
492
493 /* The number of the current function definition for which debugging
494    information is being generated.  These numbers range from 1 up to the
495    maximum number of function definitions contained within the current
496    compilation unit.  These numbers are used to create unique label id's
497    unique to each function definition.  */
498 static unsigned current_funcdef_number = 1;
499
500 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
501    attribute that accelerates the lookup of the FDE associated
502    with the subprogram.  This variable holds the table index of the FDE 
503    associated with the current function (body) definition.  */
504 static unsigned current_funcdef_fde;
505
506 /* Record the size of the frame, so that the DW_AT_frame_base
507    attribute can be set properly in gen_subprogram_die.  */
508 static long int current_funcdef_frame_size = 0;
509
510 /* DWARF requires that the compiler's primary datatypes
511    are mapped into a reference to a DIE that defines that
512    primary (base) type.  The base_type_info structure is used
513    to track the correspondence between the name of a
514    base type used by GCC, and its corresponding type
515    characteristics.  Note, that the bt_size field below
516    is the size in bits.  */
517 typedef struct base_type_struct *base_type_ref;
518 typedef struct base_type_struct
519   {
520     char *bt_name;
521     enum dwarf_type bt_type;
522     int bt_is_signed;
523     int bt_size;
524   }
525 base_type_info;
526
527 /* Characteristics of base types used by the compiler.  */
528 static base_type_info base_type_table[] =
529 {
530   {"void", DW_ATE_unsigned, 0, 0},
531   /* TODO: on some architectures, "char" may be signed. */
532   {"char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
533   {"unsigned char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
534   {"signed char", DW_ATE_signed_char, 1, CHAR_TYPE_SIZE},
535   {"int", DW_ATE_signed, 1, /* INT_TYPE_SIZE */ 4*8},
536   {"unsigned int", DW_ATE_unsigned, 0, /* INT_TYPE_SIZE */ 4*8},
537   {"short", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
538   {"short int", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
539   {"short unsigned int", DW_ATE_unsigned, 0, SHORT_TYPE_SIZE},
540   {"long", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
541   {"long int", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
542   {"long unsigned int", DW_ATE_unsigned, 0, /* LONG_TYPE_SIZE */ 4*8},
543   {"long long int", DW_ATE_signed, 1, LONG_LONG_TYPE_SIZE},
544   {"long long unsigned int", DW_ATE_unsigned, 0, LONG_LONG_TYPE_SIZE},
545   {"float", DW_ATE_float, 1, /* FLOAT_TYPE_SIZE */ 4*8},
546   {"double", DW_ATE_float, 1, DOUBLE_TYPE_SIZE},
547   {"long double", DW_ATE_float, 1, LONG_DOUBLE_TYPE_SIZE},
548   {"complex", DW_ATE_complex_float, 1, 2 * /* FLOAT_TYPE_SIZE */ 4*8},
549   {"double complex", DW_ATE_complex_float, 1, 2 * DOUBLE_TYPE_SIZE},
550   {"long double complex", DW_ATE_complex_float, 1, 2 * LONG_DOUBLE_TYPE_SIZE}
551 };
552 #define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info))
553
554 /* Record the DIE associated with a given base type  This table is
555    parallel to the base_type_table, and records the DIE genereated
556    to describe base type that has been previously referenced.  */
557 static dw_die_ref base_type_die_table[NUM_BASE_TYPES];
558
559 /* This predefined base type is used to create certain anonymous types */
560 static dw_die_ref int_base_type_die;
561
562 /* A pointer to the ..._DECL node which we have most recently been working
563    on.  We keep this around just in case something about it looks screwy and
564    we want to tell the user what the source coordinates for the actual
565    declaration are.  */
566 static tree dwarf_last_decl;
567
568 /* A list of DIE reference attributes values that need backchaining
569    support.  */
570 static backchain_ref backchain;
571
572 /* Forward declarations for functions defined in this file.  */
573 static void gen_type_die ();
574 static void add_type_attribute ();
575 static void decls_for_scope ();
576 static void gen_decl_die ();
577 static unsigned lookup_filename ();
578
579
580 /* Definitions of defaults for assembler-dependent names of various
581    pseudo-ops and section names.
582    Theses may be overridden in the tm.h file (if necessary) for a particular
583    assembler.  */
584 #ifndef UNALIGNED_SHORT_ASM_OP
585 #define UNALIGNED_SHORT_ASM_OP  ".2byte"
586 #endif
587 #ifndef UNALIGNED_INT_ASM_OP
588 #define UNALIGNED_INT_ASM_OP    ".4byte"
589 #endif
590 #ifndef ASM_BYTE_OP
591 #define ASM_BYTE_OP             ".byte"
592 #endif
593
594 /* Pseudo-op for defining a new section.  */
595 #ifndef SECTION_ASM_OP
596 #define SECTION_ASM_OP  ".section"
597 #endif
598
599 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
600    print the SECTION_ASM_OP and the section name.  The default here works for
601    almost all svr4 assemblers, except for the sparc, where the section name
602    must be enclosed in double quotes.  (See sparcv4.h).  */
603 #ifndef SECTION_FORMAT
604 #define SECTION_FORMAT  "\t%s\t%s\n"
605 #endif
606
607 /* Section names used to hold DWARF debugging information.  */
608 #ifndef DEBUG_SECTION
609 #define DEBUG_SECTION           ".debug_info"
610 #endif
611 #ifndef ABBREV_SECTION
612 #define ABBREV_SECTION          ".debug_abbrev"
613 #endif
614 #ifndef ARANGES_SECTION
615 #define ARANGES_SECTION         ".debug_aranges"
616 #endif
617 #ifndef DW_MACINFO_SECTION
618 #define DW_MACINFO_SECTION      ".debug_macinfo"
619 #endif
620 #ifndef FRAME_SECTION
621 #define FRAME_SECTION           ".debug_frame"
622 #endif
623 #ifndef LINE_SECTION
624 #define LINE_SECTION            ".debug_line"
625 #endif
626 #ifndef LOC_SECTION
627 #define LOC_SECTION             ".debug_loc"
628 #endif
629 #ifndef PUBNAMES_SECTION
630 #define PUBNAMES_SECTION        ".debug_pubnames"
631 #endif
632 #ifndef STR_SECTION
633 #define STR_SECTION             ".debug_str"
634 #endif
635
636 /* Standerd ELF section names for compiled code and data.  */
637 #ifndef TEXT_SECTION
638 #define TEXT_SECTION            ".text"
639 #endif
640 #ifndef DATA_SECTION
641 #define DATA_SECTION            ".data"
642 #endif
643 #ifndef DATA1_SECTION
644 #define DATA1_SECTION           ".data1"
645 #endif
646 #ifndef RODATA_SECTION
647 #define RODATA_SECTION          ".rodata"
648 #endif
649 #ifndef RODATA1_SECTION
650 #define RODATA1_SECTION         ".rodata1"
651 #endif
652 #ifndef BSS_SECTION
653 #define BSS_SECTION             ".bss"
654 #endif
655
656
657 /* Definitions of defaults for formats and names of various special
658    (artificial) labels which may be generated within this file (when the -g
659    options is used and DWARF_DEBUGGING_INFO is in effect.
660    If necessary, these may be overridden from within the tm.h file, but
661    typically, overriding these defaults is unnecessary.
662    These labels have been hacked so that they all begin with a
663    `.L' sequence to appease the stock sparc/svr4 assembler and the
664    stock m88k/svr4 assembler, both of which need to see .L at the start of a
665    label in order to prevent that label from going into the linker symbol
666    table).  Eventually, the ASM_GENERATE_INTERNAL_LABEL and 
667    ASM_OUTPUT_INTERNAL_LABEL should be used, but that will require
668    a major rework.  */
669 #ifndef TEXT_BEGIN_LABEL
670 #define TEXT_BEGIN_LABEL        ".L_text_b"
671 #endif
672 #ifndef TEXT_END_LABEL
673 #define TEXT_END_LABEL          ".L_text_e"
674 #endif
675 #ifndef DATA_BEGIN_LABEL
676 #define DATA_BEGIN_LABEL        ".L_data_b"
677 #endif
678 #ifndef DATA_END_LABEL
679 #define DATA_END_LABEL          ".L_data_e"
680 #endif
681 #ifndef RODATA_BEGIN_LABEL
682 #define RODATA_BEGIN_LABEL      ".L_rodata_b"
683 #endif
684 #ifndef RODATA_END_LABEL
685 #define RODATA_END_LABEL        ".L_rodata_e"
686 #endif
687 #ifndef BSS_BEGIN_LABEL
688 #define BSS_BEGIN_LABEL         ".L_bss_b"
689 #endif
690 #ifndef BSS_END_LABEL
691 #define BSS_END_LABEL           ".L_bss_e"
692 #endif
693 #ifndef LINE_BEGIN_LABEL
694 #define LINE_BEGIN_LABEL        ".L_line_b"
695 #endif
696 #ifndef LINE_END_LABEL
697 #define LINE_END_LABEL          ".L_line_e"
698 #endif
699 #ifndef INSN_LABEL_FMT
700 #define INSN_LABEL_FMT          ".L_I%u_%u"
701 #endif
702 #ifndef BLOCK_BEGIN_LABEL_FMT
703 #define BLOCK_BEGIN_LABEL_FMT   ".L_B%u"
704 #endif
705 #ifndef BLOCK_END_LABEL_FMT
706 #define BLOCK_END_LABEL_FMT     ".L_B%u_e"
707 #endif
708 #ifndef BODY_BEGIN_LABEL_FMT
709 #define BODY_BEGIN_LABEL_FMT    ".L_b%u"
710 #endif
711 #ifndef BODY_END_LABEL_FMT
712 #define BODY_END_LABEL_FMT      ".L_b%u_e"
713 #endif
714 #ifndef FUNC_END_LABEL_FMT
715 #define FUNC_END_LABEL_FMT      ".L_f%u_e"
716 #endif
717 #ifndef LINE_CODE_LABEL_FMT
718 #define LINE_CODE_LABEL_FMT     ".L_LC%u"
719 #endif
720 #ifndef SFNAMES_ENTRY_LABEL_FMT
721 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
722 #endif
723
724
725 /* Definitions of defaults for various types of primitive assembly language
726    output operations.  These may be overridden from within the tm.h file,
727    but typically, that is unecessary.  */
728 #ifndef ASM_OUTPUT_SECTION
729 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
730   fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
731 #endif
732
733 #ifndef ASM_OUTPUT_DWARF_DELTA2
734 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
735  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);             \
736         assemble_name (FILE, LABEL1);                                   \
737         fprintf (FILE, "-");                                            \
738         assemble_name (FILE, LABEL2);                                   \
739   } while (0)
740 #endif
741
742 #ifndef ASM_OUTPUT_DWARF_DELTA4
743 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
744  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
745         assemble_name (FILE, LABEL1);                                   \
746         fprintf (FILE, "-");                                            \
747         assemble_name (FILE, LABEL2);                                   \
748   } while (0)
749 #endif
750
751 #ifndef ASM_OUTPUT_DWARF_ADDR
752 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
753  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
754         assemble_name (FILE, LABEL);                                    \
755   } while (0)
756 #endif
757
758 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
759 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR)                          \
760     fprintf ((FILE), "\t%s\t%s", UNALIGNED_INT_ASM_OP, (ADDR))
761 #endif
762
763 #ifndef ASM_OUTPUT_DWARF_DATA1
764 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
765   fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
766 #endif
767
768 #ifndef ASM_OUTPUT_DWARF_DATA2
769 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
770   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
771 #endif
772
773 #ifndef ASM_OUTPUT_DWARF_DATA4
774 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
775   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
776 #endif
777
778 #ifndef ASM_OUTPUT_DWARF_DATA8
779 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
780   do {                                                                  \
781     if (WORDS_BIG_ENDIAN)                                               \
782       {                                                                 \
783         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
784         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
785       }                                                                 \
786     else                                                                \
787       {                                                                 \
788         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
789         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
790       }                                                                 \
791   } while (0)
792 #endif
793
794 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
795    newline is produced.  When flag_verbose_asm is asserted, we add commnetary
796    at the end of the line, so we must avoid output of a newline here.  */
797 #ifndef ASM_OUTPUT_DWARF_STRING
798 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
799   do {                                                                        \
800     register int slen = strlen(P);                                            \
801     register char *p = (P);                                                   \
802     register int i;                                                           \
803     fprintf (FILE, "\t.ascii \"");                                            \
804     for (i = 0; i < slen; i++)                                                \
805       {                                                                       \
806           register int c = p[i];                                              \
807           if (c == '\"' || c == '\\')                                         \
808             putc ('\\', FILE);                                                \
809           if (c >= ' ' && c < 0177)                                           \
810             putc (c, FILE);                                                   \
811           else                                                                \
812             {                                                                 \
813               fprintf (FILE, "\\%o", c);                                      \
814             }                                                                 \
815       }                                                                       \
816     fprintf (FILE, "\\0\"");                                                  \
817   }                                                                           \
818   while (0)
819 #endif
820
821 /* Convert a reference to the assembler name of a C-level name.  This
822    macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
823    a string rather than writing to a file.  */
824 #ifndef ASM_NAME_TO_STRING
825 #define ASM_NAME_TO_STRING(STR, NAME) \
826   do {                                                                        \
827       if ((NAME)[0] == '*')                                                   \
828         strcpy (STR, NAME+1);                                                 \
829       else                                                                    \
830         strcpy (STR, NAME);                                                   \
831   }                                                                           \
832   while (0)
833 #endif
834
835 \f
836 /************************ general utility functions **************************/
837
838 /* Return a pointer to a copy of the section string name 's' with all
839    attributes stripped off.  */
840 inline char *
841 stripattributes (s)
842      register char *s;
843 {
844   register char *stripped, *p;
845   stripped = xstrdup (s);
846   p = stripped;
847   while (*p && *p != ',')
848     p++;
849   *p = '\0';
850   return stripped;
851 }
852
853 /* Convert an integer constant expression into assembler syntax.
854    Addition and subtraction are the only arithmetic
855    that may appear in these expressions.   This is an adaptation
856    of output_addr_const() in final.c.   Here, the target of the
857    conversion is a string buffer.  We can't use output_addr_const
858    directly, because it writes to a file.  */
859 static void
860 addr_const_to_string (str, x)
861      char *str;
862      rtx x;
863 {
864   char buf1[256];
865   char buf2[256];
866
867 restart:
868   str[0] = '\0';
869   switch (GET_CODE (x))
870     {
871     case PC:
872       if (flag_pic)
873         strcat (str, ",");
874       else
875         abort ();
876       break;
877
878     case SYMBOL_REF:
879       ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
880       strcat (str, buf1);
881       break;
882
883     case LABEL_REF:
884       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
885       ASM_NAME_TO_STRING (buf2, buf1);
886       strcat (str, buf2);
887       break;
888
889     case CODE_LABEL:
890       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
891       ASM_NAME_TO_STRING (buf2, buf1);
892       strcat (str, buf2);
893       break;
894
895     case CONST_INT:
896       sprintf (buf1,
897 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
898                "%d",
899 #else
900                "%ld",
901 #endif
902                INTVAL (x));
903       strcat (str, buf1);
904       break;
905
906     case CONST:
907       /* This used to output parentheses around the expression, but that does 
908          not work on the 386 (either ATT or BSD assembler).  */
909       addr_const_to_string (buf1, XEXP (x, 0));
910       strcat (str, buf1);
911       break;
912
913     case CONST_DOUBLE:
914       if (GET_MODE (x) == VOIDmode)
915         {
916           /* We can use %d if the number is one word and positive.  */
917           if (CONST_DOUBLE_HIGH (x))
918             sprintf (buf1,
919 #if HOST_BITS_PER_WIDE_INT == 64
920 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
921                      "0x%lx%016lx",
922 #else
923                      "0x%x%016x",
924 #endif
925 #else
926 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
927                      "0x%lx%08lx",
928 #else
929                      "0x%x%08x",
930 #endif
931 #endif
932                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
933           else if (CONST_DOUBLE_LOW (x) < 0)
934             sprintf (buf1,
935 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
936                      "0x%x",
937 #else
938                      "0x%lx",
939 #endif
940                      CONST_DOUBLE_LOW (x));
941           else
942             sprintf (buf1,
943 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
944                      "%d",
945 #else
946                      "%ld",
947 #endif
948                      CONST_DOUBLE_LOW (x));
949           strcat (str, buf1);
950         }
951       else
952         /* We can't handle floating point constants; PRINT_OPERAND must
953            handle them.  */
954         output_operand_lossage ("floating constant misused");
955       break;
956
957     case PLUS:
958       /* Some assemblers need integer constants to appear last (eg masm).  */
959       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
960         {
961           addr_const_to_string (buf1, XEXP (x, 1));
962           strcat (str, buf1);
963           if (INTVAL (XEXP (x, 0)) >= 0)
964             strcat (str, "+");
965           addr_const_to_string (buf1, XEXP (x, 0));
966           strcat (str, buf1);
967         }
968       else
969         {
970           addr_const_to_string (buf1, XEXP (x, 0));
971           strcat (str, buf1);
972           if (INTVAL (XEXP (x, 0)) >= 0)
973             strcat (str, "+");
974           addr_const_to_string (buf1, XEXP (x, 1));
975           strcat (str, buf2);
976         }
977       break;
978
979     case MINUS:
980       /* Avoid outputting things like x-x or x+5-x, since some assemblers
981          can't handle that.  */
982       x = simplify_subtraction (x);
983       if (GET_CODE (x) != MINUS)
984         goto restart;
985
986       addr_const_to_string (buf1, XEXP (x, 0));
987       strcat (str, buf1);
988       strcat (str, "-");
989       if (GET_CODE (XEXP (x, 1)) == CONST_INT
990           && INTVAL (XEXP (x, 1)) < 0)
991         {
992           strcat (str, ASM_OPEN_PAREN);
993           addr_const_to_string (buf1, XEXP (x, 1));
994           strcat (str, buf1);
995           strcat (str, ASM_CLOSE_PAREN);
996         }
997       else
998         {
999           addr_const_to_string (buf1, XEXP (x, 1));
1000           strcat (str, buf1);
1001         }
1002       break;
1003
1004     case ZERO_EXTEND:
1005     case SIGN_EXTEND:
1006       addr_const_to_string (buf1, XEXP (x, 0));
1007       strcat (str, buf1);
1008       break;
1009
1010     default:
1011       output_operand_lossage ("invalid expression as operand");
1012     }
1013 }
1014
1015 /* Convert an address constant to a string, and return a pointer to
1016    a copy of the result, located on the heap.  */
1017 static char *
1018 addr_to_string (x)
1019      rtx x;
1020 {
1021   char buf[1024];
1022   addr_const_to_string (buf, x);
1023   return xstrdup (buf);
1024 }
1025
1026 /* Test if rtl node points to a psuedo register.  */
1027 inline int
1028 is_pseudo_reg (rtl)
1029      register rtx rtl;
1030 {
1031   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1032           || ((GET_CODE (rtl) == SUBREG)
1033               && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1034 }
1035
1036
1037 /* Return a reference to a type, with its const and volatile qualifiers
1038    removed.  */
1039 inline tree
1040 type_main_variant (type)
1041      register tree type;
1042 {
1043   type = TYPE_MAIN_VARIANT (type);
1044
1045   /* There really should be only one main variant among any group of variants 
1046      of a given type (and all of the MAIN_VARIANT values for all members of
1047      the group should point to that one type) but sometimes the C front-end
1048      messes this up for array types, so we work around that bug here.  */
1049   if (TREE_CODE (type) == ARRAY_TYPE)
1050     {
1051       while (type != TYPE_MAIN_VARIANT (type))
1052         type = TYPE_MAIN_VARIANT (type);
1053     }
1054   return type;
1055 }
1056
1057 /* Return non-zero if the given type node represents a tagged type.  */
1058 inline int
1059 is_tagged_type (type)
1060      register tree type;
1061 {
1062   register enum tree_code code = TREE_CODE (type);
1063
1064   return (code == RECORD_TYPE || code == UNION_TYPE
1065           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1066 }
1067
1068 /* Convert a DIE tag into its string name.  */
1069 static char *
1070 dwarf_tag_name (tag)
1071      register unsigned tag;
1072 {
1073   switch (tag)
1074     {
1075     case DW_TAG_padding:
1076       return "DW_TAG_padding";
1077     case DW_TAG_array_type:
1078       return "DW_TAG_array_type";
1079     case DW_TAG_class_type:
1080       return "DW_TAG_class_type";
1081     case DW_TAG_entry_point:
1082       return "DW_TAG_entry_point";
1083     case DW_TAG_enumeration_type:
1084       return "DW_TAG_enumeration_type";
1085     case DW_TAG_formal_parameter:
1086       return "DW_TAG_formal_parameter";
1087     case DW_TAG_imported_declaration:
1088       return "DW_TAG_imported_declaration";
1089     case DW_TAG_label:
1090       return "DW_TAG_label";
1091     case DW_TAG_lexical_block:
1092       return "DW_TAG_lexical_block";
1093     case DW_TAG_member:
1094       return "DW_TAG_member";
1095     case DW_TAG_pointer_type:
1096       return "DW_TAG_pointer_type";
1097     case DW_TAG_reference_type:
1098       return "DW_TAG_reference_type";
1099     case DW_TAG_compile_unit:
1100       return "DW_TAG_compile_unit";
1101     case DW_TAG_string_type:
1102       return "DW_TAG_string_type";
1103     case DW_TAG_structure_type:
1104       return "DW_TAG_structure_type";
1105     case DW_TAG_subroutine_type:
1106       return "DW_TAG_subroutine_type";
1107     case DW_TAG_typedef:
1108       return "DW_TAG_typedef";
1109     case DW_TAG_union_type:
1110       return "DW_TAG_union_type";
1111     case DW_TAG_unspecified_parameters:
1112       return "DW_TAG_unspecified_parameters";
1113     case DW_TAG_variant:
1114       return "DW_TAG_variant";
1115     case DW_TAG_common_block:
1116       return "DW_TAG_common_block";
1117     case DW_TAG_common_inclusion:
1118       return "DW_TAG_common_inclusion";
1119     case DW_TAG_inheritance:
1120       return "DW_TAG_inheritance";
1121     case DW_TAG_inlined_subroutine:
1122       return "DW_TAG_inlined_subroutine";
1123     case DW_TAG_module:
1124       return "DW_TAG_module";
1125     case DW_TAG_ptr_to_member_type:
1126       return "DW_TAG_ptr_to_member_type";
1127     case DW_TAG_set_type:
1128       return "DW_TAG_set_type";
1129     case DW_TAG_subrange_type:
1130       return "DW_TAG_subrange_type";
1131     case DW_TAG_with_stmt:
1132       return "DW_TAG_with_stmt";
1133     case DW_TAG_access_declaration:
1134       return "DW_TAG_access_declaration";
1135     case DW_TAG_base_type:
1136       return "DW_TAG_base_type";
1137     case DW_TAG_catch_block:
1138       return "DW_TAG_catch_block";
1139     case DW_TAG_const_type:
1140       return "DW_TAG_const_type";
1141     case DW_TAG_constant:
1142       return "DW_TAG_constant";
1143     case DW_TAG_enumerator:
1144       return "DW_TAG_enumerator";
1145     case DW_TAG_file_type:
1146       return "DW_TAG_file_type";
1147     case DW_TAG_friend:
1148       return "DW_TAG_friend";
1149     case DW_TAG_namelist:
1150       return "DW_TAG_namelist";
1151     case DW_TAG_namelist_item:
1152       return "DW_TAG_namelist_item";
1153     case DW_TAG_packed_type:
1154       return "DW_TAG_packed_type";
1155     case DW_TAG_subprogram:
1156       return "DW_TAG_subprogram";
1157     case DW_TAG_template_type_param:
1158       return "DW_TAG_template_type_param";
1159     case DW_TAG_template_value_param:
1160       return "DW_TAG_template_value_param";
1161     case DW_TAG_thrown_type:
1162       return "DW_TAG_thrown_type";
1163     case DW_TAG_try_block:
1164       return "DW_TAG_try_block";
1165     case DW_TAG_variant_part:
1166       return "DW_TAG_variant_part";
1167     case DW_TAG_variable:
1168       return "DW_TAG_variable";
1169     case DW_TAG_volatile_type:
1170       return "DW_TAG_volatile_type";
1171     case DW_TAG_MIPS_loop:
1172       return "DW_TAG_MIPS_loop";
1173     case DW_TAG_format_label:
1174       return "DW_TAG_format_label";
1175     case DW_TAG_function_template:
1176       return "DW_TAG_function_template";
1177     case DW_TAG_class_template:
1178       return "DW_TAG_class_template";
1179     default:
1180       return "DW_TAG_<unknown>";
1181     }
1182 }
1183
1184 /* Convert a DWARF attribute code into its string name.  */
1185 static char *
1186 dwarf_attr_name (attr)
1187      register unsigned attr;
1188 {
1189   switch (attr)
1190     {
1191     case DW_AT_sibling:
1192       return "DW_AT_sibling";
1193     case DW_AT_location:
1194       return "DW_AT_location";
1195     case DW_AT_name:
1196       return "DW_AT_name";
1197     case DW_AT_ordering:
1198       return "DW_AT_ordering";
1199     case DW_AT_subscr_data:
1200       return "DW_AT_subscr_data";
1201     case DW_AT_byte_size:
1202       return "DW_AT_byte_size";
1203     case DW_AT_bit_offset:
1204       return "DW_AT_bit_offset";
1205     case DW_AT_bit_size:
1206       return "DW_AT_bit_size";
1207     case DW_AT_element_list:
1208       return "DW_AT_element_list";
1209     case DW_AT_stmt_list:
1210       return "DW_AT_stmt_list";
1211     case DW_AT_low_pc:
1212       return "DW_AT_low_pc";
1213     case DW_AT_high_pc:
1214       return "DW_AT_high_pc";
1215     case DW_AT_language:
1216       return "DW_AT_language";
1217     case DW_AT_member:
1218       return "DW_AT_member";
1219     case DW_AT_discr:
1220       return "DW_AT_discr";
1221     case DW_AT_discr_value:
1222       return "DW_AT_discr_value";
1223     case DW_AT_visibility:
1224       return "DW_AT_visibility";
1225     case DW_AT_import:
1226       return "DW_AT_import";
1227     case DW_AT_string_length:
1228       return "DW_AT_string_length";
1229     case DW_AT_common_reference:
1230       return "DW_AT_common_reference";
1231     case DW_AT_comp_dir:
1232       return "DW_AT_comp_dir";
1233     case DW_AT_const_value:
1234       return "DW_AT_const_value";
1235     case DW_AT_containing_type:
1236       return "DW_AT_containing_type";
1237     case DW_AT_default_value:
1238       return "DW_AT_default_value";
1239     case DW_AT_inline:
1240       return "DW_AT_inline";
1241     case DW_AT_is_optional:
1242       return "DW_AT_is_optional";
1243     case DW_AT_lower_bound:
1244       return "DW_AT_lower_bound";
1245     case DW_AT_producer:
1246       return "DW_AT_producer";
1247     case DW_AT_prototyped:
1248       return "DW_AT_prototyped";
1249     case DW_AT_return_addr:
1250       return "DW_AT_return_addr";
1251     case DW_AT_start_scope:
1252       return "DW_AT_start_scope";
1253     case DW_AT_stride_size:
1254       return "DW_AT_stride_size";
1255     case DW_AT_upper_bound:
1256       return "DW_AT_upper_bound";
1257     case DW_AT_abstract_origin:
1258       return "DW_AT_abstract_origin";
1259     case DW_AT_accessibility:
1260       return "DW_AT_accessibility";
1261     case DW_AT_address_class:
1262       return "DW_AT_address_class";
1263     case DW_AT_artificial:
1264       return "DW_AT_artificial";
1265     case DW_AT_base_types:
1266       return "DW_AT_base_types";
1267     case DW_AT_calling_convention:
1268       return "DW_AT_calling_convention";
1269     case DW_AT_count:
1270       return "DW_AT_count";
1271     case DW_AT_data_member_location:
1272       return "DW_AT_data_member_location";
1273     case DW_AT_decl_column:
1274       return "DW_AT_decl_column";
1275     case DW_AT_decl_file:
1276       return "DW_AT_decl_file";
1277     case DW_AT_decl_line:
1278       return "DW_AT_decl_line";
1279     case DW_AT_declaration:
1280       return "DW_AT_declaration";
1281     case DW_AT_discr_list:
1282       return "DW_AT_discr_list";
1283     case DW_AT_encoding:
1284       return "DW_AT_encoding";
1285     case DW_AT_external:
1286       return "DW_AT_external";
1287     case DW_AT_frame_base:
1288       return "DW_AT_frame_base";
1289     case DW_AT_friend:
1290       return "DW_AT_friend";
1291     case DW_AT_identifier_case:
1292       return "DW_AT_identifier_case";
1293     case DW_AT_macro_info:
1294       return "DW_AT_macro_info";
1295     case DW_AT_namelist_items:
1296       return "DW_AT_namelist_items";
1297     case DW_AT_priority:
1298       return "DW_AT_priority";
1299     case DW_AT_segment:
1300       return "DW_AT_segment";
1301     case DW_AT_specification:
1302       return "DW_AT_specification";
1303     case DW_AT_static_link:
1304       return "DW_AT_static_link";
1305     case DW_AT_type:
1306       return "DW_AT_type";
1307     case DW_AT_use_location:
1308       return "DW_AT_use_location";
1309     case DW_AT_variable_parameter:
1310       return "DW_AT_variable_parameter";
1311     case DW_AT_virtuality:
1312       return "DW_AT_virtuality";
1313     case DW_AT_vtable_elem_location:
1314       return "DW_AT_vtable_elem_location";
1315
1316 #ifdef MIPS_DEBUGGING_INFO
1317     case DW_AT_MIPS_fde:
1318       return "DW_AT_MIPS_fde";
1319     case DW_AT_MIPS_loop_begin:
1320       return "DW_AT_MIPS_loop_begin";
1321     case DW_AT_MIPS_tail_loop_begin:
1322       return "DW_AT_MIPS_tail_loop_begin";
1323     case DW_AT_MIPS_epilog_begin:
1324       return "DW_AT_MIPS_epilog_begin";
1325     case DW_AT_MIPS_loop_unroll_factor:
1326       return "DW_AT_MIPS_loop_unroll_factor";
1327     case DW_AT_MIPS_software_pipeline_depth:
1328       return "DW_AT_MIPS_software_pipeline_depth";
1329     case DW_AT_MIPS_linkage_name:
1330       return "DW_AT_MIPS_linkage_name";
1331 #endif
1332
1333     case DW_AT_sf_names:
1334       return "DW_AT_sf_names";
1335     case DW_AT_src_info:
1336       return "DW_AT_src_info";
1337     case DW_AT_mac_info:
1338       return "DW_AT_mac_info";
1339     case DW_AT_src_coords:
1340       return "DW_AT_src_coords";
1341     case DW_AT_body_begin:
1342       return "DW_AT_body_begin";
1343     case DW_AT_body_end:
1344       return "DW_AT_body_end";
1345     default:
1346       return "DW_AT_<unknown>";
1347     }
1348 }
1349
1350 /* Convert a DWARF value form code into its string name.  */
1351 static char *
1352 dwarf_form_name (form)
1353      register unsigned form;
1354 {
1355   switch (form)
1356     {
1357     case DW_FORM_addr:
1358       return "DW_FORM_addr";
1359     case DW_FORM_block2:
1360       return "DW_FORM_block2";
1361     case DW_FORM_block4:
1362       return "DW_FORM_block4";
1363     case DW_FORM_data2:
1364       return "DW_FORM_data2";
1365     case DW_FORM_data4:
1366       return "DW_FORM_data4";
1367     case DW_FORM_data8:
1368       return "DW_FORM_data8";
1369     case DW_FORM_string:
1370       return "DW_FORM_string";
1371     case DW_FORM_block:
1372       return "DW_FORM_block";
1373     case DW_FORM_block1:
1374       return "DW_FORM_block1";
1375     case DW_FORM_data1:
1376       return "DW_FORM_data1";
1377     case DW_FORM_flag:
1378       return "DW_FORM_flag";
1379     case DW_FORM_sdata:
1380       return "DW_FORM_sdata";
1381     case DW_FORM_strp:
1382       return "DW_FORM_strp";
1383     case DW_FORM_udata:
1384       return "DW_FORM_udata";
1385     case DW_FORM_ref_addr:
1386       return "DW_FORM_ref_addr";
1387     case DW_FORM_ref1:
1388       return "DW_FORM_ref1";
1389     case DW_FORM_ref2:
1390       return "DW_FORM_ref2";
1391     case DW_FORM_ref4:
1392       return "DW_FORM_ref4";
1393     case DW_FORM_ref8:
1394       return "DW_FORM_ref8";
1395     case DW_FORM_ref_udata:
1396       return "DW_FORM_ref_udata";
1397     case DW_FORM_indirect:
1398       return "DW_FORM_indirect";
1399     default:
1400       return "DW_FORM_<unknown>";
1401     }
1402 }
1403
1404 /* Convert a DWARF stack opcode into its string name.  */
1405 static char *
1406 dwarf_stack_op_name (op)
1407      register unsigned op;
1408 {
1409   switch (op)
1410     {
1411     case DW_OP_addr:
1412       return "DW_OP_addr";
1413     case DW_OP_deref:
1414       return "DW_OP_deref";
1415     case DW_OP_const1u:
1416       return "DW_OP_const1u";
1417     case DW_OP_const1s:
1418       return "DW_OP_const1s";
1419     case DW_OP_const2u:
1420       return "DW_OP_const2u";
1421     case DW_OP_const2s:
1422       return "DW_OP_const2s";
1423     case DW_OP_const4u:
1424       return "DW_OP_const4u";
1425     case DW_OP_const4s:
1426       return "DW_OP_const4s";
1427     case DW_OP_const8u:
1428       return "DW_OP_const8u";
1429     case DW_OP_const8s:
1430       return "DW_OP_const8s";
1431     case DW_OP_constu:
1432       return "DW_OP_constu";
1433     case DW_OP_consts:
1434       return "DW_OP_consts";
1435     case DW_OP_dup:
1436       return "DW_OP_dup";
1437     case DW_OP_drop:
1438       return "DW_OP_drop";
1439     case DW_OP_over:
1440       return "DW_OP_over";
1441     case DW_OP_pick:
1442       return "DW_OP_pick";
1443     case DW_OP_swap:
1444       return "DW_OP_swap";
1445     case DW_OP_rot:
1446       return "DW_OP_rot";
1447     case DW_OP_xderef:
1448       return "DW_OP_xderef";
1449     case DW_OP_abs:
1450       return "DW_OP_abs";
1451     case DW_OP_and:
1452       return "DW_OP_and";
1453     case DW_OP_div:
1454       return "DW_OP_div";
1455     case DW_OP_minus:
1456       return "DW_OP_minus";
1457     case DW_OP_mod:
1458       return "DW_OP_mod";
1459     case DW_OP_mul:
1460       return "DW_OP_mul";
1461     case DW_OP_neg:
1462       return "DW_OP_neg";
1463     case DW_OP_not:
1464       return "DW_OP_not";
1465     case DW_OP_or:
1466       return "DW_OP_or";
1467     case DW_OP_plus:
1468       return "DW_OP_plus";
1469     case DW_OP_plus_uconst:
1470       return "DW_OP_plus_uconst";
1471     case DW_OP_shl:
1472       return "DW_OP_shl";
1473     case DW_OP_shr:
1474       return "DW_OP_shr";
1475     case DW_OP_shra:
1476       return "DW_OP_shra";
1477     case DW_OP_xor:
1478       return "DW_OP_xor";
1479     case DW_OP_bra:
1480       return "DW_OP_bra";
1481     case DW_OP_eq:
1482       return "DW_OP_eq";
1483     case DW_OP_ge:
1484       return "DW_OP_ge";
1485     case DW_OP_gt:
1486       return "DW_OP_gt";
1487     case DW_OP_le:
1488       return "DW_OP_le";
1489     case DW_OP_lt:
1490       return "DW_OP_lt";
1491     case DW_OP_ne:
1492       return "DW_OP_ne";
1493     case DW_OP_skip:
1494       return "DW_OP_skip";
1495     case DW_OP_lit0:
1496       return "DW_OP_lit0";
1497     case DW_OP_lit1:
1498       return "DW_OP_lit1";
1499     case DW_OP_lit2:
1500       return "DW_OP_lit2";
1501     case DW_OP_lit3:
1502       return "DW_OP_lit3";
1503     case DW_OP_lit4:
1504       return "DW_OP_lit4";
1505     case DW_OP_lit5:
1506       return "DW_OP_lit5";
1507     case DW_OP_lit6:
1508       return "DW_OP_lit6";
1509     case DW_OP_lit7:
1510       return "DW_OP_lit7";
1511     case DW_OP_lit8:
1512       return "DW_OP_lit8";
1513     case DW_OP_lit9:
1514       return "DW_OP_lit9";
1515     case DW_OP_lit10:
1516       return "DW_OP_lit10";
1517     case DW_OP_lit11:
1518       return "DW_OP_lit11";
1519     case DW_OP_lit12:
1520       return "DW_OP_lit12";
1521     case DW_OP_lit13:
1522       return "DW_OP_lit13";
1523     case DW_OP_lit14:
1524       return "DW_OP_lit14";
1525     case DW_OP_lit15:
1526       return "DW_OP_lit15";
1527     case DW_OP_lit16:
1528       return "DW_OP_lit16";
1529     case DW_OP_lit17:
1530       return "DW_OP_lit17";
1531     case DW_OP_lit18:
1532       return "DW_OP_lit18";
1533     case DW_OP_lit19:
1534       return "DW_OP_lit19";
1535     case DW_OP_lit20:
1536       return "DW_OP_lit20";
1537     case DW_OP_lit21:
1538       return "DW_OP_lit21";
1539     case DW_OP_lit22:
1540       return "DW_OP_lit22";
1541     case DW_OP_lit23:
1542       return "DW_OP_lit23";
1543     case DW_OP_lit24:
1544       return "DW_OP_lit24";
1545     case DW_OP_lit25:
1546       return "DW_OP_lit25";
1547     case DW_OP_lit26:
1548       return "DW_OP_lit26";
1549     case DW_OP_lit27:
1550       return "DW_OP_lit27";
1551     case DW_OP_lit28:
1552       return "DW_OP_lit28";
1553     case DW_OP_lit29:
1554       return "DW_OP_lit29";
1555     case DW_OP_lit30:
1556       return "DW_OP_lit30";
1557     case DW_OP_lit31:
1558       return "DW_OP_lit31";
1559     case DW_OP_reg0:
1560       return "DW_OP_reg0";
1561     case DW_OP_reg1:
1562       return "DW_OP_reg1";
1563     case DW_OP_reg2:
1564       return "DW_OP_reg2";
1565     case DW_OP_reg3:
1566       return "DW_OP_reg3";
1567     case DW_OP_reg4:
1568       return "DW_OP_reg4";
1569     case DW_OP_reg5:
1570       return "DW_OP_reg5";
1571     case DW_OP_reg6:
1572       return "DW_OP_reg6";
1573     case DW_OP_reg7:
1574       return "DW_OP_reg7";
1575     case DW_OP_reg8:
1576       return "DW_OP_reg8";
1577     case DW_OP_reg9:
1578       return "DW_OP_reg9";
1579     case DW_OP_reg10:
1580       return "DW_OP_reg10";
1581     case DW_OP_reg11:
1582       return "DW_OP_reg11";
1583     case DW_OP_reg12:
1584       return "DW_OP_reg12";
1585     case DW_OP_reg13:
1586       return "DW_OP_reg13";
1587     case DW_OP_reg14:
1588       return "DW_OP_reg14";
1589     case DW_OP_reg15:
1590       return "DW_OP_reg15";
1591     case DW_OP_reg16:
1592       return "DW_OP_reg16";
1593     case DW_OP_reg17:
1594       return "DW_OP_reg17";
1595     case DW_OP_reg18:
1596       return "DW_OP_reg18";
1597     case DW_OP_reg19:
1598       return "DW_OP_reg19";
1599     case DW_OP_reg20:
1600       return "DW_OP_reg20";
1601     case DW_OP_reg21:
1602       return "DW_OP_reg21";
1603     case DW_OP_reg22:
1604       return "DW_OP_reg22";
1605     case DW_OP_reg23:
1606       return "DW_OP_reg23";
1607     case DW_OP_reg24:
1608       return "DW_OP_reg24";
1609     case DW_OP_reg25:
1610       return "DW_OP_reg25";
1611     case DW_OP_reg26:
1612       return "DW_OP_reg26";
1613     case DW_OP_reg27:
1614       return "DW_OP_reg27";
1615     case DW_OP_reg28:
1616       return "DW_OP_reg28";
1617     case DW_OP_reg29:
1618       return "DW_OP_reg29";
1619     case DW_OP_reg30:
1620       return "DW_OP_reg30";
1621     case DW_OP_reg31:
1622       return "DW_OP_reg31";
1623     case DW_OP_breg0:
1624       return "DW_OP_breg0";
1625     case DW_OP_breg1:
1626       return "DW_OP_breg1";
1627     case DW_OP_breg2:
1628       return "DW_OP_breg2";
1629     case DW_OP_breg3:
1630       return "DW_OP_breg3";
1631     case DW_OP_breg4:
1632       return "DW_OP_breg4";
1633     case DW_OP_breg5:
1634       return "DW_OP_breg5";
1635     case DW_OP_breg6:
1636       return "DW_OP_breg6";
1637     case DW_OP_breg7:
1638       return "DW_OP_breg7";
1639     case DW_OP_breg8:
1640       return "DW_OP_breg8";
1641     case DW_OP_breg9:
1642       return "DW_OP_breg9";
1643     case DW_OP_breg10:
1644       return "DW_OP_breg10";
1645     case DW_OP_breg11:
1646       return "DW_OP_breg11";
1647     case DW_OP_breg12:
1648       return "DW_OP_breg12";
1649     case DW_OP_breg13:
1650       return "DW_OP_breg13";
1651     case DW_OP_breg14:
1652       return "DW_OP_breg14";
1653     case DW_OP_breg15:
1654       return "DW_OP_breg15";
1655     case DW_OP_breg16:
1656       return "DW_OP_breg16";
1657     case DW_OP_breg17:
1658       return "DW_OP_breg17";
1659     case DW_OP_breg18:
1660       return "DW_OP_breg18";
1661     case DW_OP_breg19:
1662       return "DW_OP_breg19";
1663     case DW_OP_breg20:
1664       return "DW_OP_breg20";
1665     case DW_OP_breg21:
1666       return "DW_OP_breg21";
1667     case DW_OP_breg22:
1668       return "DW_OP_breg22";
1669     case DW_OP_breg23:
1670       return "DW_OP_breg23";
1671     case DW_OP_breg24:
1672       return "DW_OP_breg24";
1673     case DW_OP_breg25:
1674       return "DW_OP_breg25";
1675     case DW_OP_breg26:
1676       return "DW_OP_breg26";
1677     case DW_OP_breg27:
1678       return "DW_OP_breg27";
1679     case DW_OP_breg28:
1680       return "DW_OP_breg28";
1681     case DW_OP_breg29:
1682       return "DW_OP_breg29";
1683     case DW_OP_breg30:
1684       return "DW_OP_breg30";
1685     case DW_OP_breg31:
1686       return "DW_OP_breg31";
1687     case DW_OP_regx:
1688       return "DW_OP_regx";
1689     case DW_OP_fbreg:
1690       return "DW_OP_fbreg";
1691     case DW_OP_bregx:
1692       return "DW_OP_bregx";
1693     case DW_OP_piece:
1694       return "DW_OP_piece";
1695     case DW_OP_deref_size:
1696       return "DW_OP_deref_size";
1697     case DW_OP_xderef_size:
1698       return "DW_OP_xderef_size";
1699     case DW_OP_nop:
1700       return "DW_OP_nop";
1701     default:
1702       return "OP_<unknown>";
1703     }
1704 }
1705
1706 /* Convert a DWARF type code into its string name.  */
1707 static char *
1708 dwarf_type_encoding_name (enc)
1709      register unsigned enc;
1710 {
1711   switch (enc)
1712     {
1713     case DW_ATE_address:
1714       return "DW_ATE_address";
1715     case DW_ATE_boolean:
1716       return "DW_ATE_boolean";
1717     case DW_ATE_complex_float:
1718       return "DW_ATE_complex_float";
1719     case DW_ATE_float:
1720       return "DW_ATE_float";
1721     case DW_ATE_signed:
1722       return "DW_ATE_signed";
1723     case DW_ATE_signed_char:
1724       return "DW_ATE_signed_char";
1725     case DW_ATE_unsigned:
1726       return "DW_ATE_unsigned";
1727     case DW_ATE_unsigned_char:
1728       return "DW_ATE_unsigned_char";
1729     default:
1730       return "DW_ATE_<unknown>";
1731     }
1732 }
1733
1734 /* Convert a DWARF call frame info. operation to its string name */
1735 static char *
1736 dwarf_cfi_name (cfi_opc)
1737      register unsigned cfi_opc;
1738 {
1739   switch (cfi_opc)
1740     {
1741     case DW_CFA_advance_loc:
1742       return "DW_CFA_advance_loc";
1743     case DW_CFA_offset:
1744       return "DW_CFA_offset";
1745     case DW_CFA_restore:
1746       return "DW_CFA_restore";
1747     case DW_CFA_nop:
1748       return "DW_CFA_nop";
1749     case DW_CFA_set_loc:
1750       return "DW_CFA_set_loc";
1751     case DW_CFA_advance_loc1:
1752       return "DW_CFA_advance_loc1";
1753     case DW_CFA_advance_loc2:
1754       return "DW_CFA_advance_loc2";
1755     case DW_CFA_advance_loc4:
1756       return "DW_CFA_advance_loc4";
1757     case DW_CFA_offset_extended:
1758       return "DW_CFA_offset_extended";
1759     case DW_CFA_restore_extended:
1760       return "DW_CFA_restore_extended";
1761     case DW_CFA_undefined:
1762       return "DW_CFA_undefined";
1763     case DW_CFA_same_value:
1764       return "DW_CFA_same_value";
1765     case DW_CFA_register:
1766       return "DW_CFA_register";
1767     case DW_CFA_remember_state:
1768       return "DW_CFA_remember_state";
1769     case DW_CFA_restore_state:
1770       return "DW_CFA_restore_state";
1771     case DW_CFA_def_cfa:
1772       return "DW_CFA_def_cfa";
1773     case DW_CFA_def_cfa_register:
1774       return "DW_CFA_def_cfa_register";
1775     case DW_CFA_def_cfa_offset:
1776       return "DW_CFA_def_cfa_offset";
1777     /* SGI/MIPS specific */
1778     case DW_CFA_MIPS_advance_loc8:
1779       return "DW_CFA_MIPS_advance_loc8";
1780     default:
1781       return "DW_CFA_<unknown>";
1782     }
1783 }
1784 \f
1785 /* Determine the "ultimate origin" of a decl.  The decl may be an inlined
1786    instance of an inlined instance of a decl which is local to an inline
1787    function, so we have to trace all of the way back through the origin chain
1788    to find out what sort of node actually served as the original seed for the
1789    given block.  */
1790 static tree
1791 decl_ultimate_origin (decl)
1792      register tree decl;
1793 {
1794   register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1795
1796   if (immediate_origin == NULL)
1797     return NULL;
1798   else
1799     {
1800       register tree ret_val;
1801       register tree lookahead = immediate_origin;
1802
1803       do
1804         {
1805           ret_val = lookahead;
1806           lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1807         }
1808       while (lookahead != NULL && lookahead != ret_val);
1809       return ret_val;
1810     }
1811 }
1812
1813 /* Determine the "ultimate origin" of a block.  The block may be an inlined
1814    instance of an inlined instance of a block which is local to an inline
1815    function, so we have to trace all of the way back through the origin chain
1816    to find out what sort of node actually served as the original seed for the
1817    given block.  */
1818 static tree
1819 block_ultimate_origin (block)
1820      register tree block;
1821 {
1822   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1823
1824   if (immediate_origin == NULL)
1825     return NULL;
1826   else
1827     {
1828       register tree ret_val;
1829       register tree lookahead = immediate_origin;
1830
1831       do
1832         {
1833           ret_val = lookahead;
1834           lookahead = (TREE_CODE (ret_val) == BLOCK)
1835             ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1836             : NULL;
1837         }
1838       while (lookahead != NULL && lookahead != ret_val);
1839       return ret_val;
1840     }
1841 }
1842 \f
1843 /**************** DIE internal representation constturction *******************/
1844
1845 /* Add an attribute/value pair to a DIE */
1846 inline void
1847 add_dwarf_attr (die, attr)
1848      register dw_die_ref die;
1849      register dw_attr_ref attr;
1850 {
1851   if (die != NULL && attr != NULL)
1852     {
1853       if (die->die_attr == NULL)
1854         {
1855           die->die_attr = attr;
1856           die->die_attr_last = attr;
1857         }
1858       else
1859         {
1860           die->die_attr_last->dw_attr_next = attr;
1861           die->die_attr_last = attr;
1862         }
1863     }
1864 }
1865
1866 /* Add a flag value attribute to a DIE.  */
1867 inline void
1868 add_AT_flag (die, attr_kind, flag)
1869      register dw_die_ref die;
1870      register enum dwarf_attribute attr_kind;
1871      register unsigned flag;
1872 {
1873   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1874   if (attr != NULL)
1875     {
1876       attr->dw_attr_next = NULL;
1877       attr->dw_attr = attr_kind;
1878       attr->dw_attr_val.val_class = dw_val_class_flag;
1879       attr->dw_attr_val.v.val_flag = flag;
1880       add_dwarf_attr (die, attr);
1881     }
1882 }
1883
1884 /* Add a signed integer attribute value to a DIE.  */
1885 inline void
1886 add_AT_int (die, attr_kind, int_val)
1887      register dw_die_ref die;
1888      register enum dwarf_attribute attr_kind;
1889      register long int int_val;
1890 {
1891   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1892   if (attr != NULL)
1893     {
1894       attr->dw_attr_next = NULL;
1895       attr->dw_attr = attr_kind;
1896       attr->dw_attr_val.val_class = dw_val_class_const;
1897       attr->dw_attr_val.v.val_int = int_val;
1898       add_dwarf_attr (die, attr);
1899     }
1900 }
1901
1902 /* Add an unsigned integer attribute value to a DIE.  */
1903 inline void
1904 add_AT_unsigned (die, attr_kind, unsigned_val)
1905      register dw_die_ref die;
1906      register enum dwarf_attribute attr_kind;
1907      register unsigned long unsigned_val;
1908 {
1909   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1910   if (attr != NULL)
1911     {
1912       attr->dw_attr_next = NULL;
1913       attr->dw_attr = attr_kind;
1914       attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
1915       attr->dw_attr_val.v.val_unsigned = unsigned_val;
1916       add_dwarf_attr (die, attr);
1917     }
1918 }
1919
1920 /* Add an unsigned double integer attribute value to a DIE.  */
1921 inline void
1922 add_AT_double (die, attr_kind, val_hi, val_low)
1923      register dw_die_ref die;
1924      register enum dwarf_attribute attr_kind;
1925      register unsigned long val_hi;
1926      register unsigned long val_low;
1927 {
1928   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1929   if (attr != NULL)
1930     {
1931       attr->dw_attr_next = NULL;
1932       attr->dw_attr = attr_kind;
1933       attr->dw_attr_val.val_class = dw_val_class_double_const;
1934       attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi;
1935       attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low;
1936       add_dwarf_attr (die, attr);
1937     }
1938 }
1939
1940 /* Add a string attribute value to a DIE.  */
1941 inline void
1942 add_AT_string (die, attr_kind, str)
1943      register dw_die_ref die;
1944      register enum dwarf_attribute attr_kind;
1945      register char *str;
1946 {
1947   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1948   if (attr != NULL)
1949     {
1950       attr->dw_attr_next = NULL;
1951       attr->dw_attr = attr_kind;
1952       attr->dw_attr_val.val_class = dw_val_class_str;
1953       attr->dw_attr_val.v.val_str = xstrdup (str);
1954       add_dwarf_attr (die, attr);
1955     }
1956 }
1957
1958 /* Add a DIE reference attribute value to a DIE.  */
1959 inline void
1960 add_AT_die_ref (die, attr_kind, targ_die)
1961      register dw_die_ref die;
1962      register enum dwarf_attribute attr_kind;
1963      register dw_die_ref targ_die;
1964 {
1965   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1966   if (attr != NULL)
1967     {
1968       attr->dw_attr_next = NULL;
1969       attr->dw_attr = attr_kind;
1970       attr->dw_attr_val.val_class = dw_val_class_die_ref;
1971       attr->dw_attr_val.v.val_die_ref = targ_die;
1972       add_dwarf_attr (die, attr);
1973     }
1974 }
1975
1976 /* Add an FDE reference attribute value to a DIE.  */
1977 inline void
1978 add_AT_fde_ref (die, attr_kind, targ_fde)
1979      register dw_die_ref die;
1980      register enum dwarf_attribute attr_kind;
1981      register unsigned targ_fde;
1982 {
1983   register dw_attr_ref attr;
1984
1985   attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1986   if (attr != NULL)
1987     {
1988       attr->dw_attr_next = NULL;
1989       attr->dw_attr = attr_kind;
1990       attr->dw_attr_val.val_class = dw_val_class_fde_ref;
1991       attr->dw_attr_val.v.val_fde_index = targ_fde;
1992       add_dwarf_attr (die, attr);
1993     }
1994 }
1995
1996 /* Add a location description attribute value to a DIE.  */
1997 inline void
1998 add_AT_loc (die, attr_kind, loc)
1999      register dw_die_ref die;
2000      register enum dwarf_attribute attr_kind;
2001      register dw_loc_descr_ref loc;
2002 {
2003   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2004   if (attr != NULL)
2005     {
2006       attr->dw_attr_next = NULL;
2007       attr->dw_attr = attr_kind;
2008       attr->dw_attr_val.val_class = dw_val_class_loc;
2009       attr->dw_attr_val.v.val_loc = loc;
2010       add_dwarf_attr (die, attr);
2011     }
2012 }
2013
2014 /* Add an address constant attribute value to a DIE.  */
2015 inline void
2016 add_AT_addr (die, attr_kind, addr)
2017      register dw_die_ref die;
2018      register enum dwarf_attribute attr_kind;
2019      char *addr;
2020 {
2021   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2022   if (attr != NULL)
2023     {
2024       attr->dw_attr_next = NULL;
2025       attr->dw_attr = attr_kind;
2026       attr->dw_attr_val.val_class = dw_val_class_addr;
2027       attr->dw_attr_val.v.val_addr = addr;
2028       add_dwarf_attr (die, attr);
2029     }
2030 }
2031
2032 /* Add a label identifier attribute value to a DIE.  */
2033 inline void
2034 add_AT_lbl_id (die, attr_kind, lbl_id)
2035      register dw_die_ref die;
2036      register enum dwarf_attribute attr_kind;
2037      register char *lbl_id;
2038 {
2039   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2040   if (attr != NULL)
2041     {
2042       attr->dw_attr_next = NULL;
2043       attr->dw_attr = attr_kind;
2044       attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2045       attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2046       add_dwarf_attr (die, attr);
2047     }
2048 }
2049
2050 /* Add a section offset attribute value to a DIE.  */
2051 inline void
2052 add_AT_section_offset (die, attr_kind, section)
2053      register dw_die_ref die;
2054      register enum dwarf_attribute attr_kind;
2055      register char *section;
2056 {
2057   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2058   if (attr != NULL)
2059     {
2060       attr->dw_attr_next = NULL;
2061       attr->dw_attr = attr_kind;
2062       attr->dw_attr_val.val_class = dw_val_class_section_offset;
2063       attr->dw_attr_val.v.val_section = section;
2064       add_dwarf_attr (die, attr);
2065     }
2066 }
2067
2068 /* Save a DIE reference attribute value to a DIE for later backchaining.  */
2069 inline void
2070 backchain_AT_die_ref (type, placeholder)
2071      register tree type;
2072      register dw_die_ref placeholder;
2073 {
2074   register backchain_ref back = (backchain_ref) xmalloc (sizeof (backchain_t));
2075   if (back != NULL)
2076     {
2077       back->type = type;
2078       back->placeholder = placeholder;
2079
2080       back->next = backchain;
2081       backchain = back;
2082     }
2083 }
2084
2085 /* Test if die refers to an external subroutine.  */
2086 inline int
2087 is_extern_subr_die (die)
2088      register dw_die_ref die;
2089 {
2090   register dw_attr_ref a;
2091   register int is_subr = FALSE;
2092   register int is_extern = FALSE;
2093   if (die != NULL && die->die_tag == DW_TAG_subprogram)
2094     {
2095       is_subr = TRUE;
2096       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2097         {
2098           if (a->dw_attr == DW_AT_external
2099               && a->dw_attr_val.val_class == dw_val_class_flag
2100               && a->dw_attr_val.v.val_flag != 0)
2101             {
2102               is_extern = TRUE;
2103               break;
2104             }
2105         }
2106     }
2107   return is_subr && is_extern;
2108 }
2109
2110 /* Return the "low pc" attribute value, typically associated with
2111    a subprogram DIE.  Return null if the "low pc" attribute is
2112    either not prsent, or if it cannot be represented as an
2113    assembler label identifier.  */
2114 inline char *
2115 get_AT_low_pc (die)
2116      register dw_die_ref die;
2117 {
2118   register dw_attr_ref a;
2119   register char *low_pc = NULL;
2120   if (die != NULL)
2121     {
2122       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2123         {
2124           if (a->dw_attr == DW_AT_low_pc
2125               && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2126             {
2127               low_pc = a->dw_attr_val.v.val_lbl_id;
2128               break;
2129             }
2130         }
2131     }
2132   return low_pc;
2133 }
2134
2135
2136 /* Return the "high pc" attribute value, typically associated with
2137    a subprogram DIE.  Return null if the "high pc" attribute is
2138    either not prsent, or if it cannot be represented as an
2139    assembler label identifier.  */
2140 inline char *
2141 get_AT_hi_pc (die)
2142      register dw_die_ref die;
2143 {
2144   register dw_attr_ref a;
2145   register char *hi_pc = NULL;
2146   if (die != NULL)
2147     {
2148       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2149         {
2150           if (a->dw_attr == DW_AT_high_pc
2151               && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2152             {
2153               hi_pc = a->dw_attr_val.v.val_lbl_id;
2154               break;
2155             }
2156         }
2157     }
2158   return hi_pc;
2159 }
2160
2161 /* Add a child DIE below its parent.  */
2162 inline void
2163 add_child_die (die, child_die)
2164      register dw_die_ref die;
2165      register dw_die_ref child_die;
2166 {
2167   if (die != NULL && child_die != NULL)
2168     {
2169       assert (die != child_die);
2170       child_die->die_parent = die;
2171       child_die->die_sib = NULL;
2172       if (die->die_child == NULL)
2173         {
2174           die->die_child = child_die;
2175           die->die_child_last = child_die;
2176         }
2177       else
2178         {
2179           die->die_child_last->die_sib = child_die;
2180           die->die_child_last = child_die;
2181         }
2182     }
2183 }
2184
2185 /* Return a pointer to a newly created DIE node.  */
2186 inline dw_die_ref
2187 new_die (tag_value, parent_die)
2188      register enum dwarf_tag tag_value;
2189      register dw_die_ref parent_die;
2190 {
2191   register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2192   if (die != NULL)
2193     {
2194       die->die_tag = tag_value;
2195       die->die_abbrev = 0;
2196       die->die_offset = 0;
2197       die->die_child = NULL;
2198       die->die_parent = NULL;
2199       die->die_sib = NULL;
2200       die->die_child_last = NULL;
2201       die->die_attr = NULL;
2202       die->die_attr_last = NULL;
2203       if (parent_die != NULL)
2204         {
2205           add_child_die (parent_die, die);
2206         }
2207     }
2208   return die;
2209 }
2210
2211 /* Return the DIE associated with the given type specifier.  */
2212 inline dw_die_ref
2213 lookup_type_die (type)
2214      register tree type;
2215 {
2216   register unsigned type_id = TYPE_UID (type);
2217   return (type_id < type_die_table_in_use)
2218     ? type_die_table[type_id] : NULL;
2219 }
2220
2221 /* Equate a DIE to a given type specifier.  */
2222 static void
2223 equate_type_number_to_die (type, type_die)
2224      register tree type;
2225      register dw_die_ref type_die;
2226 {
2227   register unsigned type_id = TYPE_UID (type);
2228   register unsigned i;
2229   register unsigned num_allocated;
2230   if (type_id >= type_die_table_allocated)
2231     {
2232       num_allocated = (((type_id + 1)
2233                         + TYPE_DIE_TABLE_INCREMENT - 1)
2234                        / TYPE_DIE_TABLE_INCREMENT)
2235         * TYPE_DIE_TABLE_INCREMENT;
2236       type_die_table = (dw_die_ref *) xrealloc (type_die_table,
2237                                        sizeof (dw_die_ref) * num_allocated);
2238       bzero (&type_die_table[type_die_table_allocated],
2239           (num_allocated - type_die_table_allocated) * sizeof (dw_die_ref));
2240       type_die_table_allocated = num_allocated;
2241     }
2242   if (type_id >= type_die_table_in_use)
2243     {
2244       type_die_table_in_use = (type_id + 1);
2245     }
2246   type_die_table[type_id] = type_die;
2247 }
2248
2249 /* Return the DIE associated with a given declaration.  */
2250 inline dw_die_ref
2251 lookup_decl_die (decl)
2252      register tree decl;
2253 {
2254   register unsigned decl_id = DECL_UID (decl);
2255   return (decl_id < decl_die_table_in_use)
2256     ? decl_die_table[decl_id] : NULL;
2257 }
2258
2259 /* Equate a DIE to a particular declaration.  */
2260 static void
2261 equate_decl_number_to_die (decl, decl_die)
2262      register tree decl;
2263      register dw_die_ref decl_die;
2264 {
2265   register unsigned decl_id = DECL_UID (decl);
2266   register unsigned i;
2267   register unsigned num_allocated;
2268   if (decl_id >= decl_die_table_allocated)
2269     {
2270       num_allocated = (((decl_id + 1)
2271                         + DECL_DIE_TABLE_INCREMENT - 1)
2272                        / DECL_DIE_TABLE_INCREMENT)
2273         * DECL_DIE_TABLE_INCREMENT;
2274       decl_die_table = (dw_die_ref *) xrealloc (decl_die_table,
2275                                        sizeof (dw_die_ref) * num_allocated);
2276       bzero (&decl_die_table[decl_die_table_allocated],
2277           (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2278       decl_die_table_allocated = num_allocated;
2279     }
2280   if (decl_id >= decl_die_table_in_use)
2281     {
2282       decl_die_table_in_use = (decl_id + 1);
2283     }
2284   decl_die_table[decl_id] = decl_die;
2285 }
2286
2287 /* Return a pointer to a newly allocated location description.  Location
2288    descriptions are simple expression terms that can be strung
2289    together to form more complicated location (address) descriptions.  */
2290 inline dw_loc_descr_ref
2291 new_loc_descr (op, oprnd1, oprnd2)
2292      register enum dwarf_location_atom op;
2293      register unsigned long oprnd1;
2294      register unsigned long oprnd2;
2295 {
2296   register dw_loc_descr_ref descr =
2297   (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2298   if (descr != NULL)
2299     {
2300       descr->dw_loc_next = NULL;
2301       descr->dw_loc_opc = op;
2302       descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2303       descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2304       descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2305       descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2306     }
2307   return descr;
2308 }
2309
2310 /* Add a location description term to a location description expression.  */
2311 inline void
2312 add_loc_descr (list_head, descr)
2313      register dw_loc_descr_ref *list_head;
2314      register dw_loc_descr_ref descr;
2315 {
2316   register dw_loc_descr_ref *d;
2317   /* find the end of the chain.  */
2318   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2319     {
2320       /* nothing */ ;
2321     }
2322   *d = descr;
2323 }
2324
2325 /* Return a pointer to a newly allocated Call Frame Instruction.  */
2326 inline dw_cfi_ref
2327 new_cfi ()
2328 {
2329   register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2330   if (cfi != NULL)
2331     {
2332       cfi->dw_cfi_next = NULL;
2333       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2334       cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2335     }
2336   return cfi;
2337 }
2338
2339 /* Add a Call Frame Instruction to list of instructions.  */
2340 inline void
2341 add_cfi (list_head, cfi)
2342      register dw_cfi_ref *list_head;
2343      register dw_cfi_ref cfi;
2344 {
2345   register dw_cfi_ref *p;
2346   /* find the end of the chain.  */
2347   for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2348     {
2349       /* nothing */ ;
2350     }
2351   *p = cfi;
2352 }
2353 \f
2354 /********* Print DWARF Internal Representation (debugging aids) ***************/
2355
2356 /* Keep track of the number of spaces used to indent the
2357    output of the debugging routines that print the structure of
2358    the DIE internal representation.  */
2359 static int print_indent;
2360
2361 /* Indent the line the number of spaces given by print_indent.  */
2362 inline void
2363 print_spaces (outfile)
2364      FILE *outfile;
2365 {
2366   fprintf (outfile, "%*s", print_indent, "");
2367 }
2368
2369 /* Print the information assoaciated with a given DIE, and its children.
2370    This routine is a debugging aid only.  */
2371 static void
2372 print_die (die, outfile)
2373      dw_die_ref die;
2374      FILE *outfile;
2375 {
2376   register dw_attr_ref a;
2377   register dw_die_ref c;
2378   print_spaces (outfile);
2379   fprintf (outfile, "DIE %4u: %s\n",
2380            die->die_offset, dwarf_tag_name (die->die_tag));
2381   print_spaces (outfile);
2382   fprintf (outfile, "  abbrev id: %u", die->die_abbrev);
2383   fprintf (outfile, " offset: %u\n", die->die_offset);
2384   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2385     {
2386       print_spaces (outfile);
2387       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
2388       switch (a->dw_attr_val.val_class)
2389         {
2390         case dw_val_class_addr:
2391           fprintf (outfile, "address");
2392           break;
2393         case dw_val_class_loc:
2394           fprintf (outfile, "location descriptor");
2395           break;
2396         case dw_val_class_const:
2397           fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2398           break;
2399         case dw_val_class_unsigned_const:
2400           fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2401           break;
2402         case dw_val_class_double_const:
2403           fprintf (outfile, "constant (%u,%u)",
2404                   a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
2405                   a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
2406           break;
2407         case dw_val_class_flag:
2408           fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2409           break;
2410         case dw_val_class_die_ref:
2411           if (a->dw_attr_val.v.val_die_ref != NULL)
2412             {
2413               fprintf (outfile, "die -> %u",
2414                        a->dw_attr_val.v.val_die_ref->die_offset);
2415             }
2416           else
2417             {
2418               fprintf (outfile, "die -> <null>");
2419             }
2420           break;
2421         case dw_val_class_lbl_id:
2422           fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2423           break;
2424         case dw_val_class_section_offset:
2425           fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2426           break;
2427         case dw_val_class_str:
2428           if (a->dw_attr_val.v.val_str != NULL)
2429             {
2430               fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2431             }
2432           else
2433             {
2434               fprintf (outfile, "<null>");
2435             }
2436           break;
2437         }
2438       fprintf (outfile, "\n");
2439     }
2440   if (die->die_child != NULL)
2441     {
2442       print_indent += 4;
2443       for (c = die->die_child; c != NULL; c = c->die_sib)
2444         {
2445           print_die (c, outfile);
2446         }
2447       print_indent -= 4;
2448     }
2449 }
2450
2451 /* Print the contents of the source code line number correspondence table.
2452    This routine is a debugging aid only.  */
2453 static void
2454 print_dwarf_line_table (outfile)
2455      FILE *outfile;
2456 {
2457   register unsigned i;
2458   register dw_line_info_ref line_info;
2459   fprintf (outfile, "\n\nDWARF source line information\n");
2460   for (i = 1; i < line_info_table_in_use; ++i)
2461     {
2462       line_info = &line_info_table[i];
2463       fprintf (outfile, "%5d: ", i);
2464       fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2465       fprintf (outfile, "%6d", line_info->dw_line_num);
2466       fprintf (outfile, "\n");
2467     }
2468   fprintf (outfile, "\n\n");
2469 }
2470
2471 /* Print the information collected for a given DIE.  */
2472 void
2473 debug_dwarf_die (die)
2474      dw_die_ref die;
2475 {
2476   print_die (die, stderr);
2477 }
2478
2479 /* Print all DWARF informaiton collected for the compilation unit.
2480    This routine is a debugging aid only.  */
2481 void
2482 debug_dwarf ()
2483 {
2484   print_indent = 0;
2485   print_die (comp_unit_die, stderr);
2486   print_dwarf_line_table (stderr);
2487 }
2488
2489 \f
2490 /***************** DWARF Information Construction Support *********************/
2491
2492 /* Traverse the DIE, and add a sibling attribute if it may have the
2493    effect of speeding up access to siblings.  To save some space,
2494    avoid generating sibling attributes for DIE's without children.  */
2495 static void
2496 add_sibling_attributes(die)
2497      register dw_die_ref die;
2498 {
2499   register dw_die_ref c;
2500   register dw_attr_ref attr;
2501   if (die != comp_unit_die && die->die_child != NULL)
2502     {
2503       attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2504       if (attr != NULL)
2505         {
2506           attr->dw_attr_next = NULL;
2507           attr->dw_attr = DW_AT_sibling;
2508           attr->dw_attr_val.val_class = dw_val_class_die_ref;
2509           attr->dw_attr_val.v.val_die_ref = die->die_sib;
2510         }
2511       /* add the sibling link to the front of the attribute list.  */
2512       attr->dw_attr_next = die->die_attr;
2513       if (die->die_attr == NULL)
2514         {
2515           die->die_attr_last = attr;
2516         }
2517       die->die_attr = attr;
2518     }
2519   for (c = die->die_child; c != NULL; c = c->die_sib)
2520     {
2521       add_sibling_attributes (c);
2522     }
2523 }
2524
2525 /* The format of each DIE (and its attribute value pairs)
2526    is encoded in an abbreviation table.  This routine builds the
2527    abbreviation table and assigns a unique abbreviation id for
2528    each abbreviation entry.  The children of each die are visited
2529    recursively.  */
2530 static void
2531 build_abbrev_table (die)
2532      register dw_die_ref die;
2533 {
2534   register unsigned long abbrev_id;
2535   register unsigned long n_alloc;
2536   register dw_die_ref c;
2537   register dw_attr_ref d_attr, a_attr;
2538   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2539     {
2540       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2541       if (abbrev->die_tag == die->die_tag)
2542         {
2543           if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2544             {
2545               a_attr = abbrev->die_attr;
2546               d_attr = die->die_attr;
2547               while (a_attr != NULL && d_attr != NULL)
2548                 {
2549                   if ((a_attr->dw_attr != d_attr->dw_attr)
2550                       || (a_attr->dw_attr_val.val_class
2551                           != d_attr->dw_attr_val.val_class))
2552                     {
2553                       break;
2554                     }
2555                   a_attr = a_attr->dw_attr_next;
2556                   d_attr = d_attr->dw_attr_next;
2557                 }
2558               if (a_attr == NULL && d_attr == NULL)
2559                 {
2560                   break;
2561                 }
2562             }
2563         }
2564     }
2565   if (abbrev_id >= abbrev_die_table_in_use)
2566     {
2567       if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2568         {
2569           n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2570           abbrev_die_table = (dw_die_ref *)
2571             xmalloc (abbrev_die_table,
2572                      sizeof (dw_die_ref) * n_alloc);
2573           bzero (&abbrev_die_table[abbrev_die_table_allocated],
2574               (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2575           abbrev_die_table_allocated = n_alloc;
2576         }
2577       ++abbrev_die_table_in_use;
2578       abbrev_die_table[abbrev_id] = die;
2579     }
2580   die->die_abbrev = abbrev_id;
2581   for (c = die->die_child; c != NULL; c = c->die_sib)
2582     {
2583       build_abbrev_table (c);
2584     }
2585 }
2586
2587 \f
2588 /**********************  DWARF Information Sizing *****************************/
2589
2590 /* Return the size of an unsigned LEB128 quantity.  */
2591 inline unsigned long
2592 size_of_uleb128 (value)
2593      register unsigned long value;
2594 {
2595   register unsigned long size = 0;
2596   register unsigned byte;
2597   do
2598     {
2599       byte = (value & 0x7f);
2600       value >>= 7;
2601       size += 1;
2602     }
2603   while (value != 0);
2604   return size;
2605 }
2606
2607 /* Return the size of a signed LEB128 quantity.  */
2608 inline unsigned long
2609 size_of_sleb128 (value)
2610      register long value;
2611 {
2612   register unsigned long size = 0;
2613   register unsigned byte;
2614   do
2615     {
2616       byte = (value & 0x7f);
2617       value >>= 7;
2618       size += 1;
2619     }
2620   while (!(((value == 0) && ((byte & 0x40) == 0))
2621            || ((value == -1) && ((byte & 0x40) != 0))));
2622   return size;
2623 }
2624
2625 /* Return the size of a string, including the null byte.  */
2626 static unsigned long
2627 size_of_string (str)
2628      register char *str;
2629 {
2630   register unsigned long size = 0;
2631   register unsigned long slen = strlen (str);
2632   register unsigned long i;
2633   register unsigned c;
2634   for (i = 0; i < slen; ++i)
2635     {
2636       c = str[i];
2637       if (c == '\\')
2638         {
2639           ++i;
2640         }
2641       size += 1;
2642     }
2643   /* Null terminator.  */
2644   size += 1;
2645   return size;
2646 }
2647
2648 /* Return the size of a location descriptor.  */
2649 static unsigned long
2650 size_of_loc_descr (loc)
2651      register dw_loc_descr_ref loc;
2652 {
2653   register unsigned long size = 1;
2654   switch (loc->dw_loc_opc)
2655     {
2656     case DW_OP_addr:
2657       size += PTR_SIZE;
2658       break;
2659     case DW_OP_const1u:
2660     case DW_OP_const1s:
2661       size += 1;
2662       break;
2663     case DW_OP_const2u:
2664     case DW_OP_const2s:
2665       size += 2;
2666       break;
2667     case DW_OP_const4u:
2668     case DW_OP_const4s:
2669       size += 4;
2670       break;
2671     case DW_OP_const8u:
2672     case DW_OP_const8s:
2673       size += 8;
2674       break;
2675     case DW_OP_constu:
2676       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2677       break;
2678     case DW_OP_consts:
2679       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2680       break;
2681     case DW_OP_pick:
2682       size += 1;
2683       break;
2684     case DW_OP_plus_uconst:
2685       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2686       break;
2687     case DW_OP_skip:
2688     case DW_OP_bra:
2689       size += 2;
2690       break;
2691     case DW_OP_breg0:
2692     case DW_OP_breg1:
2693     case DW_OP_breg2:
2694     case DW_OP_breg3:
2695     case DW_OP_breg4:
2696     case DW_OP_breg5:
2697     case DW_OP_breg6:
2698     case DW_OP_breg7:
2699     case DW_OP_breg8:
2700     case DW_OP_breg9:
2701     case DW_OP_breg10:
2702     case DW_OP_breg11:
2703     case DW_OP_breg12:
2704     case DW_OP_breg13:
2705     case DW_OP_breg14:
2706     case DW_OP_breg15:
2707     case DW_OP_breg16:
2708     case DW_OP_breg17:
2709     case DW_OP_breg18:
2710     case DW_OP_breg19:
2711     case DW_OP_breg20:
2712     case DW_OP_breg21:
2713     case DW_OP_breg22:
2714     case DW_OP_breg23:
2715     case DW_OP_breg24:
2716     case DW_OP_breg25:
2717     case DW_OP_breg26:
2718     case DW_OP_breg27:
2719     case DW_OP_breg28:
2720     case DW_OP_breg29:
2721     case DW_OP_breg30:
2722     case DW_OP_breg31:
2723       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2724       break;
2725     case DW_OP_regx:
2726       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2727       break;
2728     case DW_OP_fbreg:
2729       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2730       break;
2731     case DW_OP_bregx:
2732       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2733       size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2734       break;
2735     case DW_OP_piece:
2736       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2737       break;
2738     case DW_OP_deref_size:
2739     case DW_OP_xderef_size:
2740       size += 1;
2741       break;
2742     default:
2743       break;
2744     }
2745   return size;
2746 }
2747
2748 /* Return the size of a DIE, as it is represented in the
2749    .debug_info section.  */
2750 static unsigned long
2751 size_of_die (die)
2752      register dw_die_ref die;
2753 {
2754   register unsigned long size = 0;
2755   register dw_attr_ref a;
2756   register dw_loc_descr_ref loc;
2757   size += size_of_uleb128 (die->die_abbrev);
2758   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2759     {
2760       switch (a->dw_attr_val.val_class)
2761         {
2762         case dw_val_class_addr:
2763           size += 4;
2764           break;
2765         case dw_val_class_loc:
2766           /* Block length.  */
2767           size += 2;
2768           for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
2769                loc = loc->dw_loc_next)
2770             {
2771               size += size_of_loc_descr (loc);
2772             }
2773           break;
2774         case dw_val_class_const:
2775           size += 4;
2776           break;
2777         case dw_val_class_unsigned_const:
2778           size += 4;
2779           break;
2780         case dw_val_class_double_const:
2781           size += 8;
2782           break;
2783         case dw_val_class_flag:
2784           size += 1;
2785           break;
2786         case dw_val_class_die_ref:
2787           size += 4;
2788           break;
2789         case dw_val_class_fde_ref:
2790           size += 4;
2791           break;
2792         case dw_val_class_lbl_id:
2793           size += 4;
2794           break;
2795         case dw_val_class_section_offset:
2796           size += 4;
2797           break;
2798         case dw_val_class_str:
2799           size += size_of_string (a->dw_attr_val.v.val_str);
2800           break;
2801         default:
2802           abort ();
2803         }
2804     }
2805   return size;
2806 }
2807
2808 /* Size the debgging information associted with a given DIE.
2809    Visits the DIE's children recursively.  Updates the global
2810    variable next_die_offset, on each time through.  Uses the
2811    current value of next_die_offset to updete the die_offset
2812    field in each DIE.  */
2813 static void
2814 calc_die_sizes (die)
2815      dw_die_ref die;
2816 {
2817   register dw_die_ref c;
2818   register unsigned long die_size;
2819   die->die_offset = next_die_offset;
2820   next_die_offset += size_of_die (die);
2821   for (c = die->die_child; c != NULL; c = c->die_sib)
2822     {
2823       calc_die_sizes (c);
2824     }
2825   if (die->die_child != NULL)
2826     {
2827       /* Count the null byte used to terminate sibling lists.  */
2828       next_die_offset += 1;
2829     }
2830 }
2831
2832 /* Return the size of the line information prolog generated for the
2833    compilation unit.  */
2834 static unsigned long
2835 size_of_line_prolog ()
2836 {
2837   register unsigned long size;
2838   register unsigned opc;
2839   register unsigned n_op_args;
2840   register unsigned long ft_index;
2841   size = DWARF_LINE_PROLOG_HEADER_SIZE;
2842   /* Count the size of the table giving number of args for each
2843      standard opcode.  */
2844   size += DWARF_LINE_OPCODE_BASE - 1;
2845   /* Include directory table is empty (at present).  Count only the
2846      the null byte used to terminate the table.  */
2847   size += 1;
2848   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
2849     {
2850       /* File name entry.  */
2851       size += size_of_string (file_table[ft_index]);
2852       /* Include directory index.  */
2853       size += size_of_uleb128 (0);
2854       /* Modification time.  */
2855       size += size_of_uleb128 (0);
2856       /* File length in bytes.  */
2857       size += size_of_uleb128 (0);
2858     }
2859   /* Count the file table terminator.  */
2860   size += 1;
2861   return size;
2862 }
2863
2864 /* Return the size of the line information generated for this
2865    compilation unit.  */
2866 static unsigned long
2867 size_of_line_info ()
2868 {
2869   register unsigned long size;
2870   register dw_line_info_ref line_info;
2871   register unsigned long lt_index;
2872   register unsigned long current_line;
2873   register long line_offset;
2874   register long line_delta;
2875   register unsigned long current_file;
2876   /* Version number.  */
2877   size = 2;
2878   /* Prolog length specifier.  */
2879   size += 4;
2880   /* Prolog.  */
2881   size += size_of_line_prolog ();
2882   /* Set address register instruction.  */
2883   size += 1 + size_of_uleb128 (1 + PTR_SIZE)
2884     + 1 + PTR_SIZE;
2885   current_file = 1;
2886   current_line = 1;
2887   for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
2888     {
2889       /* Advance pc instruction.  */
2890       size += 1 + 2;
2891       line_info = &line_info_table[lt_index];
2892       if (line_info->dw_file_num != current_file)
2893         {
2894           /* Set file number instruction.  */
2895           size += 1;
2896           current_file = line_info->dw_file_num;
2897           size += size_of_uleb128 (current_file);
2898         }
2899       if (line_info->dw_line_num != current_line)
2900         {
2901           line_offset = line_info->dw_line_num - current_line;
2902           line_delta = line_offset - DWARF_LINE_BASE;
2903           current_line = line_info->dw_line_num;
2904           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
2905             {
2906               /* 1-byte special line number instruction.  */
2907               size += 1;
2908             }
2909           else
2910             {
2911               /* Advance line instruction.  */
2912               size += 1;
2913               size += size_of_sleb128 (line_offset);
2914               /* Generate line entry instruction.  */
2915               size += 1;
2916             }
2917         }
2918     }
2919   /* Set address register instruction.  */
2920   size += 1 + size_of_uleb128 (1 + PTR_SIZE)
2921     + 1 + PTR_SIZE;
2922   /* End of line number info. marker.  */
2923   size += 1 + size_of_uleb128 (1) + 1;
2924   return size;
2925 }
2926
2927 /* Return the size of the .debug_pubnames table  generated for the
2928    compilation unit.  */
2929 static unsigned long
2930 size_of_pubnames ()
2931 {
2932   dw_die_ref die;
2933   register unsigned long size;
2934   size = DWARF_PUBNAMES_HEADER_SIZE;
2935   for (die = comp_unit_die->die_child; die != NULL; die = die->die_sib)
2936     {
2937       if (is_extern_subr_die (die))
2938         {
2939           char *low_pc = get_AT_low_pc (die);
2940           if (low_pc != NULL)
2941             {
2942               size += 4;
2943               size += size_of_string (low_pc);
2944             }
2945         }
2946     }
2947   size += 4;
2948   return size;
2949 }
2950
2951 /* Return the size of the information in the .debug_aranges seciton.  */
2952 static unsigned long
2953 size_of_aranges ()
2954 {
2955   register unsigned long size;
2956   size = DWARF_ARANGES_HEADER_SIZE;
2957   /* Count the address/length pair for this compilation unit.  */
2958   size += 8;
2959   /* Count the two zero words used to terminated the address range table.  */
2960   size += 8;
2961   return size;
2962 }
2963 \f
2964 /**************** DWARF Debug Information Output *****************************/
2965
2966 /* Output an unsigned LEB128 quantity.  */
2967 static void
2968 output_uleb128 (value)
2969      register unsigned long value;
2970 {
2971   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
2972   do
2973     {
2974       register unsigned byte = (value & 0x7f);
2975       value >>= 7;
2976       if (value != 0)
2977         {
2978           /* More bytes to follow.  */
2979           byte |= 0x80;
2980         }
2981       fprintf (asm_out_file, "0x%x", byte);
2982       if (value != 0)
2983         {
2984           fprintf (asm_out_file, ",");
2985         }
2986     }
2987   while (value != 0);
2988 }
2989
2990 /* Output an signed LEB128 quantity.  */
2991 static void
2992 output_sleb128 (value)
2993      register long value;
2994 {
2995   register int more;
2996   register unsigned byte;
2997   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
2998   do
2999     {
3000       byte = (value & 0x7f);
3001       /* arithmetic shift */
3002       value >>= 7;
3003       more = !((((value == 0) && ((byte & 0x40) == 0))
3004                 || ((value == -1) && ((byte & 0x40) != 0))));
3005       if (more)
3006         {
3007           byte |= 0x80;
3008         }
3009       fprintf (asm_out_file, "0x%x", byte);
3010       if (more)
3011         {
3012           fprintf (asm_out_file, ",");
3013         }
3014     }
3015   while (more);
3016 }
3017
3018 /* Output the encoding of an attribute value.  */
3019 static void
3020 output_value_format (v)
3021      dw_val_ref v;
3022 {
3023   enum dwarf_form form;
3024   switch (v->val_class)
3025     {
3026     case dw_val_class_addr:
3027       form = DW_FORM_addr;
3028       break;
3029     case dw_val_class_loc:
3030       form = DW_FORM_block2;
3031       break;
3032     case dw_val_class_const:
3033       form = DW_FORM_data4;
3034       break;
3035     case dw_val_class_unsigned_const:
3036       form = DW_FORM_data4;
3037       break;
3038     case dw_val_class_double_const:
3039       form = DW_FORM_data8;
3040       break;
3041     case dw_val_class_flag:
3042       form = DW_FORM_flag;
3043       break;
3044     case dw_val_class_die_ref:
3045       form = DW_FORM_ref4;
3046       break;
3047     case dw_val_class_fde_ref:
3048       form = DW_FORM_data4;
3049       break;
3050     case dw_val_class_lbl_id:
3051       form = DW_FORM_addr;
3052       break;
3053     case dw_val_class_section_offset:
3054       form = DW_FORM_data4;
3055       break;
3056     case dw_val_class_str:
3057       form = DW_FORM_string;
3058       break;
3059     default:
3060       abort ();
3061     }
3062   output_uleb128 (form);
3063   if (flag_verbose_asm)
3064     {
3065       fprintf (asm_out_file, "\t%s %s",
3066                ASM_COMMENT_START, dwarf_form_name (form));
3067     }
3068   fputc ('\n', asm_out_file);
3069 }
3070
3071 /* Output the .debug_abbrev section which defines the DIE abbreviation
3072    table.  */
3073 static void
3074 output_abbrev_section ()
3075 {
3076   unsigned long abbrev_id;
3077   dw_attr_ref a_attr;
3078   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3079     {
3080       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3081       output_uleb128 (abbrev_id);
3082       if (flag_verbose_asm)
3083         {
3084           fprintf (asm_out_file, "\t%s abbrev code = %u",
3085                    ASM_COMMENT_START, abbrev_id);
3086         }
3087       fputc ('\n', asm_out_file);
3088       output_uleb128 (abbrev->die_tag);
3089       if (flag_verbose_asm)
3090         {
3091           fprintf (asm_out_file, "\t%s TAG: %s",
3092                    ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag));
3093         }
3094       fputc ('\n', asm_out_file);
3095       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3096                (abbrev->die_child != NULL)
3097                ? DW_children_yes : DW_children_no);
3098       if (flag_verbose_asm)
3099         {
3100           fprintf (asm_out_file, "\t%s %s",
3101                    ASM_COMMENT_START,
3102                    (abbrev->die_child != NULL)
3103                    ? "DW_children_yes" : "DW_children_no");
3104         }
3105       fputc ('\n', asm_out_file);
3106       for (a_attr = abbrev->die_attr; a_attr != NULL;
3107            a_attr = a_attr->dw_attr_next)
3108         {
3109           output_uleb128 (a_attr->dw_attr);
3110           if (flag_verbose_asm)
3111             {
3112               fprintf (asm_out_file, "\t%s %s",
3113                        ASM_COMMENT_START,
3114                        dwarf_attr_name (a_attr->dw_attr));
3115             }
3116           fputc ('\n', asm_out_file);
3117           output_value_format (&a_attr->dw_attr_val);
3118         }
3119       fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3120     }
3121 }
3122
3123 /* Output location description stack opcode's operands (if any).  */
3124 static void
3125 output_loc_operands (loc)
3126      register dw_loc_descr_ref loc;
3127 {
3128   register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3129   register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3130   switch (loc->dw_loc_opc)
3131     {
3132     case DW_OP_addr:
3133       ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3134       fputc ('\n', asm_out_file);
3135       break;
3136     case DW_OP_const1u:
3137     case DW_OP_const1s:
3138       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3139       fputc ('\n', asm_out_file);
3140       break;
3141     case DW_OP_const2u:
3142     case DW_OP_const2s:
3143       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3144       fputc ('\n', asm_out_file);
3145       break;
3146     case DW_OP_const4u:
3147     case DW_OP_const4s:
3148       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3149       fputc ('\n', asm_out_file);
3150       break;
3151     case DW_OP_const8u:
3152     case DW_OP_const8s:
3153       ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3154                               val1->v.val_dbl_const.dw_dbl_hi,
3155                               val2->v.val_dbl_const.dw_dbl_low);
3156       fputc ('\n', asm_out_file);
3157       break;
3158     case DW_OP_constu:
3159       output_uleb128 (val1->v.val_unsigned);
3160       fputc ('\n', asm_out_file);
3161       break;
3162     case DW_OP_consts:
3163       output_sleb128 (val1->v.val_unsigned);
3164       fputc ('\n', asm_out_file);
3165       break;
3166     case DW_OP_pick:
3167       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3168       fputc ('\n', asm_out_file);
3169       break;
3170     case DW_OP_plus_uconst:
3171       output_uleb128 (val1->v.val_unsigned);
3172       fputc ('\n', asm_out_file);
3173       break;
3174     case DW_OP_skip:
3175     case DW_OP_bra:
3176       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3177       fputc ('\n', asm_out_file);
3178       break;
3179     case DW_OP_breg0:
3180     case DW_OP_breg1:
3181     case DW_OP_breg2:
3182     case DW_OP_breg3:
3183     case DW_OP_breg4:
3184     case DW_OP_breg5:
3185     case DW_OP_breg6:
3186     case DW_OP_breg7:
3187     case DW_OP_breg8:
3188     case DW_OP_breg9:
3189     case DW_OP_breg10:
3190     case DW_OP_breg11:
3191     case DW_OP_breg12:
3192     case DW_OP_breg13:
3193     case DW_OP_breg14:
3194     case DW_OP_breg15:
3195     case DW_OP_breg16:
3196     case DW_OP_breg17:
3197     case DW_OP_breg18:
3198     case DW_OP_breg19:
3199     case DW_OP_breg20:
3200     case DW_OP_breg21:
3201     case DW_OP_breg22:
3202     case DW_OP_breg23:
3203     case DW_OP_breg24:
3204     case DW_OP_breg25:
3205     case DW_OP_breg26:
3206     case DW_OP_breg27:
3207     case DW_OP_breg28:
3208     case DW_OP_breg29:
3209     case DW_OP_breg30:
3210     case DW_OP_breg31:
3211       output_sleb128 (val1->v.val_int);
3212       fputc ('\n', asm_out_file);
3213       break;
3214     case DW_OP_regx:
3215       output_uleb128 (val1->v.val_unsigned);
3216       fputc ('\n', asm_out_file);
3217       break;
3218     case DW_OP_fbreg:
3219       output_sleb128 (val1->v.val_unsigned);
3220       fputc ('\n', asm_out_file);
3221       break;
3222     case DW_OP_bregx:
3223       output_uleb128 (val1->v.val_unsigned);
3224       fputc ('\n', asm_out_file);
3225       output_sleb128 (val2->v.val_unsigned);
3226       fputc ('\n', asm_out_file);
3227       break;
3228     case DW_OP_piece:
3229       output_uleb128 (val1->v.val_unsigned);
3230       fputc ('\n', asm_out_file);
3231       break;
3232     case DW_OP_deref_size:
3233     case DW_OP_xderef_size:
3234       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3235       fputc ('\n', asm_out_file);
3236       break;
3237     default:
3238       break;
3239     }
3240 }
3241
3242 /* Compute the offset of a sibling.  */
3243 static unsigned long
3244 sibling_offset (die)
3245      dw_die_ref die;
3246 {
3247   unsigned long offset;
3248   if (die->die_child_last == NULL)
3249     {
3250       offset = die->die_offset + size_of_die (die);
3251     }
3252   else
3253     {
3254       offset = sibling_offset (die->die_child_last) + 1;
3255     }
3256   return offset;
3257 }
3258
3259 /* Output the DIE and its attributes.  Called recursively to generate
3260    the definitions of each child DIE.  */
3261 static void
3262 output_die (die)
3263      register dw_die_ref die;
3264 {
3265   register dw_attr_ref a;
3266   register dw_die_ref c;
3267   register unsigned long ref_offset;
3268   register unsigned long size;
3269   register dw_loc_descr_ref loc;
3270   output_uleb128 (die->die_abbrev);
3271   if (flag_verbose_asm)
3272     {
3273       fprintf (asm_out_file, "\t%s DIE (0x%x) %s",
3274                ASM_COMMENT_START,
3275                die->die_offset,
3276                dwarf_tag_name (die->die_tag));
3277     }
3278   fputc ('\n', asm_out_file);
3279   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3280     {
3281       switch (a->dw_attr_val.val_class)
3282         {
3283         case dw_val_class_addr:
3284           ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3285                                        a->dw_attr_val.v.val_addr);
3286           break;
3287         case dw_val_class_loc:
3288           size = 0;
3289           for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3290                loc = loc->dw_loc_next)
3291             {
3292               size += size_of_loc_descr (loc);
3293             }
3294           /* Output the block length for this list of location operations.  */
3295           ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3296           if (flag_verbose_asm)
3297             {
3298               fprintf (asm_out_file, "\t%s %s",
3299                        ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3300             }
3301           fputc ('\n', asm_out_file);
3302           for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3303                loc = loc->dw_loc_next)
3304             {
3305               /* Output the opcode.  */
3306               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3307               if (flag_verbose_asm)
3308                 {
3309                   fprintf (asm_out_file, "\t%s %s",
3310                            ASM_COMMENT_START,
3311                            dwarf_stack_op_name (loc->dw_loc_opc));
3312                 }
3313               fputc ('\n', asm_out_file);
3314               /* Output the operand(s) (if any).  */
3315               output_loc_operands (loc);
3316             }
3317           break;
3318         case dw_val_class_const:
3319           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3320           break;
3321         case dw_val_class_unsigned_const:
3322           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3323           break;
3324         case dw_val_class_double_const:
3325           ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3326                                   a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
3327                                   a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
3328           break;
3329         case dw_val_class_flag:
3330           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3331           break;
3332         case dw_val_class_die_ref:
3333           if (a->dw_attr_val.v.val_die_ref != NULL)
3334             {
3335               ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3336             }
3337           else if (a->dw_attr == DW_AT_sibling)
3338             {
3339               ref_offset = sibling_offset(die);
3340             }
3341           else
3342             {
3343               abort ();
3344             }
3345           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, ref_offset);
3346           break;
3347         case dw_val_class_fde_ref:
3348           ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
3349           fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_INT_ASM_OP,
3350                    stripattributes (FRAME_SECTION), ref_offset);
3351           break;
3352         case dw_val_class_lbl_id:
3353           ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3354           break;
3355         case dw_val_class_section_offset:
3356           ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3357                                  stripattributes (a->dw_attr_val.v.val_section));
3358           break;
3359         case dw_val_class_str:
3360           ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3361           break;
3362         default:
3363           abort ();
3364         }
3365       if (a->dw_attr_val.val_class != dw_val_class_loc)
3366         {
3367           if (flag_verbose_asm)
3368             {
3369               fprintf (asm_out_file, "\t%s %s",
3370                        ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3371             }
3372           fputc ('\n', asm_out_file);
3373         }
3374     }
3375   for (c = die->die_child; c != NULL; c = c->die_sib)
3376     {
3377       output_die (c);
3378     }
3379   if (die->die_child != NULL)
3380     {
3381       /* Add null byte to terminate sibling list. */
3382       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3383       fputc ('\n', asm_out_file);
3384     }
3385 }
3386
3387 /* Output the compilation unit that appears at the beginning of the
3388    .debug_info section, and precedes the DIE descriptions.  */
3389 static void
3390 output_compilation_unit_header ()
3391 {
3392   /* ??? The dwarf standard says this must be a 4 byte integer, but the
3393      SGI dwarf reader assumes this is the same size as a pointer.  */
3394   fprintf (asm_out_file, "\t%s\t0x%x",
3395            UNALIGNED_INT_ASM_OP, next_die_offset - 4);
3396   if (flag_verbose_asm)
3397     {
3398       fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3399                ASM_COMMENT_START);
3400     }
3401   fputc ('\n', asm_out_file);
3402   fprintf (asm_out_file, "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, DWARF_VERSION);
3403   if (flag_verbose_asm)
3404     {
3405       fprintf (asm_out_file, "\t%s DWARF version number",
3406                ASM_COMMENT_START);
3407     }
3408   fputc ('\n', asm_out_file);
3409   fprintf (asm_out_file, "\t%s\t%s", UNALIGNED_INT_ASM_OP,
3410            stripattributes (ABBREV_SECTION));
3411   if (flag_verbose_asm)
3412     {
3413       fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3414                ASM_COMMENT_START);
3415     }
3416   fputc ('\n', asm_out_file);
3417   fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, PTR_SIZE);
3418   if (flag_verbose_asm)
3419     {
3420       fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3421                ASM_COMMENT_START);
3422     }
3423   fputc ('\n', asm_out_file);
3424 }
3425
3426 /* Return the size of a Call Frame Instruction.  */
3427 static unsigned long
3428 size_of_cfi (cfi)
3429      dw_cfi_ref cfi;
3430 {
3431   register unsigned long size;
3432   /* count the 1-byte opcode */
3433   size = 1;
3434   switch (cfi->dw_cfi_opc)
3435     {
3436     case DW_CFA_offset:
3437       size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3438       break;
3439     case DW_CFA_set_loc:
3440       size += PTR_SIZE;
3441       break;
3442     case DW_CFA_advance_loc1:
3443       size += 1;
3444       break;
3445     case DW_CFA_advance_loc2:
3446       size += 2;
3447       break;
3448     case DW_CFA_advance_loc4:
3449       size += 4;
3450       break;
3451 #ifdef MIPS_DEBUGGING_INFO
3452     case DW_CFA_MIPS_advance_loc8:
3453       size += 8;
3454       break;
3455 #endif
3456     case DW_CFA_offset_extended:
3457     case DW_CFA_def_cfa:
3458       size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3459       size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3460       break;
3461     case DW_CFA_restore_extended:
3462     case DW_CFA_undefined:
3463       size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3464       break;
3465     case DW_CFA_same_value:
3466     case DW_CFA_def_cfa_register:
3467       size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3468       break;
3469     case DW_CFA_register:
3470       size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3471       size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3472       break;
3473     case DW_CFA_def_cfa_offset:
3474       size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3475       break;
3476     default:
3477       break;
3478     }
3479     return size;
3480 }
3481
3482 /* Return the size of an FDE sans the length word.  */
3483 inline unsigned long
3484 size_of_fde (fde, npad)
3485     dw_fde_ref fde;
3486     unsigned long *npad;
3487 {
3488   register dw_cfi_ref cfi;
3489   register unsigned long aligned_size;
3490   register unsigned long size;
3491   size = DWARF_FDE_HEADER_SIZE;
3492   for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3493     {
3494         size += size_of_cfi(cfi);
3495     }
3496   /* Round the size up to an 8 byte boundary.  */
3497   aligned_size = (size + 7) & ~7;
3498   *npad = aligned_size - size;
3499   return aligned_size;
3500 }
3501
3502 /* Calculate the size of the FDE table, and establish the offset
3503    of each FDE in the .debug_frame section.  */
3504 static void
3505 calc_fde_sizes ()
3506 {
3507   register unsigned long i;
3508   register dw_fde_ref fde;
3509   register unsigned long fde_size;
3510   unsigned long fde_pad;
3511   for (i = 0; i < fde_table_in_use; ++i)
3512     {
3513       fde = &fde_table[i];
3514       fde->dw_fde_offset = next_fde_offset;
3515       fde_size = size_of_fde (fde, &fde_pad);
3516       next_fde_offset += fde_size;
3517     }
3518 }
3519
3520 /* Output a Call Frame Information opcode and its operand(s).  */
3521 static void
3522 output_cfi (cfi, fde)
3523      register dw_cfi_ref cfi;
3524      register dw_fde_ref fde;
3525 {
3526   if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3527     {
3528       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3529                               cfi->dw_cfi_opc
3530                               | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
3531       if (flag_verbose_asm)
3532         {
3533           fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3534         }
3535       fputc ('\n', asm_out_file);
3536     }
3537   else if (cfi->dw_cfi_opc == DW_CFA_offset)
3538     {
3539       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3540                               cfi->dw_cfi_opc
3541                               | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3542       if (flag_verbose_asm)
3543         {
3544           fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3545         }
3546       fputc ('\n', asm_out_file);
3547       output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3548       fputc ('\n', asm_out_file);
3549     }
3550   else if (cfi->dw_cfi_opc == DW_CFA_restore)
3551     {
3552       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3553                               cfi->dw_cfi_opc
3554                               | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3555       if (flag_verbose_asm)
3556         {
3557           fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3558         }
3559       fputc ('\n', asm_out_file);
3560     }
3561   else
3562     {
3563       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3564       if (flag_verbose_asm)
3565         {
3566           fprintf (asm_out_file, "\t%s %s",
3567                    ASM_COMMENT_START,
3568                    dwarf_cfi_name (cfi->dw_cfi_opc));
3569         }
3570       fputc ('\n', asm_out_file);
3571       switch (cfi->dw_cfi_opc)
3572         {
3573         case DW_CFA_set_loc:
3574           ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3575                                  cfi->dw_cfi_oprnd1.dw_cfi_addr);
3576           fputc ('\n', asm_out_file);
3577           break;
3578         case DW_CFA_advance_loc1:
3579           /* TODO: not currently implemented.  */
3580           abort ();
3581           break;
3582         case DW_CFA_advance_loc2:
3583           ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
3584                                  cfi->dw_cfi_oprnd1.dw_cfi_addr,
3585                                  fde->dw_fde_begin);
3586           fputc ('\n', asm_out_file);
3587           break;
3588         case DW_CFA_advance_loc4:
3589           ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
3590                                  cfi->dw_cfi_oprnd1.dw_cfi_addr,
3591                                  fde->dw_fde_begin);
3592           fputc ('\n', asm_out_file);
3593           break;
3594 #ifdef MIPS_DEBUGGING_INFO
3595         case DW_CFA_MIPS_advance_loc8:
3596           /* TODO: not currently implemented.  */
3597           abort ();
3598           break;
3599 #endif
3600         case DW_CFA_offset_extended:
3601         case DW_CFA_def_cfa:
3602           output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3603           fputc ('\n', asm_out_file);
3604           output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3605           fputc ('\n', asm_out_file);
3606           break;
3607         case DW_CFA_restore_extended:
3608         case DW_CFA_undefined:
3609           output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3610           fputc ('\n', asm_out_file);
3611           break;
3612         case DW_CFA_same_value:
3613         case DW_CFA_def_cfa_register:
3614           output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3615           fputc ('\n', asm_out_file);
3616           break;
3617         case DW_CFA_register:
3618           output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3619           fputc ('\n', asm_out_file);
3620           output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3621           fputc ('\n', asm_out_file);
3622           break;
3623         case DW_CFA_def_cfa_offset:
3624           output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3625           fputc ('\n', asm_out_file);
3626           break;
3627         default:
3628           break;
3629         }
3630      }
3631 }
3632
3633 /* Output the call frame information used to used to record information
3634    that relates to calculating the frame pointer, and records the
3635    location of saved registers.  */
3636 static void
3637 output_call_frame_info ()
3638 {
3639   register unsigned long i, j;
3640   register dw_fde_ref fde;
3641   register unsigned long fde_size;
3642   dw_cfi_node cfi_node;
3643   register dw_cfi_ref cfi;
3644   unsigned long fde_pad;
3645
3646   /* Output the CIE. */
3647   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DWARF_CIE_SIZE - 4);
3648   if (flag_verbose_asm)
3649     {
3650       fprintf (asm_out_file, "\t%s Length of Common Information Entry",
3651                ASM_COMMENT_START);
3652     }
3653   fputc ('\n', asm_out_file);
3654   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3655   if (flag_verbose_asm)
3656     {
3657       fprintf (asm_out_file, "\t%s CIE Identifier Tag",
3658                ASM_COMMENT_START);
3659     }
3660   fputc ('\n', asm_out_file);
3661   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
3662   if (flag_verbose_asm)
3663     {
3664       fprintf (asm_out_file, "\t%s CIE Version",
3665                ASM_COMMENT_START);
3666     }
3667   fputc ('\n', asm_out_file);
3668   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3669   if (flag_verbose_asm)
3670     {
3671       fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
3672                ASM_COMMENT_START);
3673     }
3674   fputc ('\n', asm_out_file);
3675   output_uleb128 (1);
3676   if (flag_verbose_asm)
3677     {
3678       fprintf (asm_out_file, "\t%s CIE Code Alignment Factor",
3679                ASM_COMMENT_START);
3680     }
3681   fputc ('\n', asm_out_file);
3682   output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
3683   if (flag_verbose_asm)
3684     {
3685       fprintf (asm_out_file, "\t%s CIE Data Alignment Factor",
3686                ASM_COMMENT_START);
3687     }
3688   fputc ('\n', asm_out_file);
3689   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_FRAME_RA_COL);
3690   if (flag_verbose_asm)
3691     {
3692       fprintf (asm_out_file, "\t%s CIE RA Column",
3693                ASM_COMMENT_START);
3694     }
3695   fputc ('\n', asm_out_file);
3696
3697   /* Output the CFA instructions common to all FDE's. */
3698
3699 #ifdef MIPS_DEBUGGING_INFO
3700
3701   /* Set the RA on entry to be the contents of r31.  */
3702   bzero (&cfi_node, sizeof (dw_cfi_node));
3703   cfi = &cfi_node;
3704   cfi->dw_cfi_opc = DW_CFA_register;
3705   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
3706   cfi->dw_cfi_oprnd2.dw_cfi_reg_num = DW_FRAME_REG31;
3707   output_cfi (cfi);
3708
3709 #endif
3710
3711   /* Pad the CIE out to an address sized boundary.  */
3712   for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i)
3713     {
3714       /* Pad out to a pointer size boundary */
3715       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
3716       if (flag_verbose_asm)
3717         {
3718           fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
3719                    ASM_COMMENT_START);
3720         }
3721       fputc ('\n', asm_out_file);
3722     }
3723
3724   /* Loop through all of the FDE's.  */
3725   for (i = 0; i < fde_table_in_use; ++i)
3726     {
3727       fde = &fde_table[i];
3728       fde_size = size_of_fde (fde, &fde_pad);
3729       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, fde_size - 4);
3730       if (flag_verbose_asm)
3731         {
3732           fprintf (asm_out_file, "\t%s FDE Length",
3733                    ASM_COMMENT_START);
3734         }
3735       fputc ('\n', asm_out_file);
3736       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3737       if (flag_verbose_asm)
3738         {
3739           fprintf (asm_out_file, "\t%s FDE CIE offset",
3740                    ASM_COMMENT_START);
3741         }
3742       fputc ('\n', asm_out_file);
3743       ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
3744       if (flag_verbose_asm)
3745         {
3746           fprintf (asm_out_file, "\t%s FDE initial location",
3747                    ASM_COMMENT_START);
3748         }
3749       fputc ('\n', asm_out_file);
3750       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
3751                                fde->dw_fde_end, fde->dw_fde_begin);
3752       if (flag_verbose_asm)
3753         {
3754           fprintf (asm_out_file, "\t%s FDE address range",
3755                    ASM_COMMENT_START);
3756         }
3757       fputc ('\n', asm_out_file);
3758
3759       /* Loop through the Call Frame Instructions associated with
3760          this FDE.  */
3761       for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3762         {
3763           output_cfi (cfi, fde);
3764         }
3765
3766       /* Pad to a double word boundary.  */
3767       for (j = 0; j < fde_pad; ++j)
3768         {
3769           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
3770           if (flag_verbose_asm)
3771             {
3772               fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
3773                        ASM_COMMENT_START);
3774             }
3775           fputc ('\n', asm_out_file);
3776         }
3777     }
3778 }
3779
3780 /* Output the public names table used to speed up access to externally
3781    visible names.  For now, only generate entries for externally
3782    visible procedures.  */
3783 static void
3784 output_pubnames ()
3785 {
3786   dw_die_ref die;
3787   register unsigned long pubnames_length = size_of_pubnames ();
3788   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, pubnames_length);
3789   if (flag_verbose_asm)
3790     {
3791       fprintf (asm_out_file, "\t%s Length of Public Names Info.",
3792                ASM_COMMENT_START);
3793     }
3794   fputc ('\n', asm_out_file);
3795   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3796   if (flag_verbose_asm)
3797     {
3798       fprintf (asm_out_file, "\t%s DWARF Version",
3799                ASM_COMMENT_START);
3800     }
3801   fputc ('\n', asm_out_file);
3802   ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (DEBUG_SECTION));
3803   if (flag_verbose_asm)
3804     {
3805       fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
3806                ASM_COMMENT_START);
3807     }
3808   fputc ('\n', asm_out_file);
3809   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, next_die_offset);
3810   if (flag_verbose_asm)
3811     {
3812       fprintf (asm_out_file, "\t%s Compilation Unit Length",
3813                ASM_COMMENT_START);
3814     }
3815   fputc ('\n', asm_out_file);
3816   for (die = comp_unit_die->die_child; die != NULL; die = die->die_sib)
3817     {
3818       if (is_extern_subr_die (die))
3819         {
3820           char *low_pc = get_AT_low_pc (die);
3821           if (low_pc != NULL)
3822             {
3823               ASM_OUTPUT_DWARF_DATA4 (asm_out_file, die->die_offset);
3824               if (flag_verbose_asm)
3825                 {
3826                   fprintf (asm_out_file, "\t%s DIE offset",
3827                            ASM_COMMENT_START);
3828                 }
3829               fputc ('\n', asm_out_file);
3830               ASM_OUTPUT_DWARF_STRING (asm_out_file, low_pc);
3831               if (flag_verbose_asm)
3832                 {
3833                   fprintf (asm_out_file, "%s external name",
3834                            ASM_COMMENT_START);
3835                 }
3836               fputc ('\n', asm_out_file);
3837             }
3838         }
3839     }
3840   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3841   fputc ('\n', asm_out_file);
3842 }
3843
3844 /* Output the information that goes into the .debug_aranges table.
3845    Namely, define the beginning and ending address range of the
3846    text section generated for this compilation unit.  */
3847 static void
3848 output_aranges ()
3849 {
3850   dw_die_ref die;
3851   register unsigned long aranges_length = size_of_aranges ();
3852   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, aranges_length);
3853   if (flag_verbose_asm)
3854     {
3855       fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
3856                ASM_COMMENT_START);
3857     }
3858   fputc ('\n', asm_out_file);
3859   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3860   if (flag_verbose_asm)
3861     {
3862       fprintf (asm_out_file, "\t%s DWARF Version",
3863                ASM_COMMENT_START);
3864     }
3865   fputc ('\n', asm_out_file);
3866   ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (DEBUG_SECTION));
3867   if (flag_verbose_asm)
3868     {
3869       fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
3870                ASM_COMMENT_START);
3871     }
3872   fputc ('\n', asm_out_file);
3873   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
3874   if (flag_verbose_asm)
3875     {
3876       fprintf (asm_out_file, "\t%s Size of Address",
3877                ASM_COMMENT_START);
3878     }
3879   fputc ('\n', asm_out_file);
3880   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3881   if (flag_verbose_asm)
3882     {
3883       fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
3884                ASM_COMMENT_START);
3885     }
3886   fputc ('\n', asm_out_file);
3887   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3888   if (flag_verbose_asm)
3889     {
3890       fprintf (asm_out_file, "\t%s Pad to 8 byte boundary",
3891                ASM_COMMENT_START);
3892     }
3893   fputc ('\n', asm_out_file);
3894   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
3895   if (flag_verbose_asm)
3896     {
3897       fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
3898     }
3899   fputc ('\n', asm_out_file);
3900   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
3901   if (flag_verbose_asm)
3902     {
3903       fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
3904     }
3905   fputc ('\n', asm_out_file);
3906   /* Output the terminator words.  */
3907   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3908   fputc ('\n', asm_out_file);
3909   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
3910   fputc ('\n', asm_out_file);
3911 }
3912
3913 /* Output the source line number correspondence information.  This
3914    information goes into the .debug_line section.  */
3915 static void
3916 output_line_info ()
3917 {
3918   register unsigned long line_info_len;
3919   register unsigned long line_info_prolog_len;
3920   char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
3921   char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
3922   register unsigned opc;
3923   register unsigned n_op_args;
3924   register dw_line_info_ref line_info;
3925   register unsigned long ft_index;
3926   register unsigned long lt_index;
3927   register unsigned long current_line;
3928   register long line_offset;
3929   register long line_delta;
3930   register unsigned long current_file;
3931   line_info_len = size_of_line_info ();
3932   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, line_info_len);
3933   if (flag_verbose_asm)
3934     {
3935       fprintf (asm_out_file, "\t%s Length of Source Line Info.",
3936                ASM_COMMENT_START);
3937     }
3938   fputc ('\n', asm_out_file);
3939   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3940   if (flag_verbose_asm)
3941     {
3942       fprintf (asm_out_file, "\t%s DWARF Version",
3943                ASM_COMMENT_START);
3944     }
3945   fputc ('\n', asm_out_file);
3946   line_info_prolog_len = size_of_line_prolog ();
3947   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, line_info_prolog_len);
3948   if (flag_verbose_asm)
3949     {
3950       fprintf (asm_out_file, "\t%s Prolog Length",
3951                ASM_COMMENT_START);
3952     }
3953   fputc ('\n', asm_out_file);
3954   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
3955   if (flag_verbose_asm)
3956     {
3957       fprintf (asm_out_file, "\t%s Minimum Instruction Length",
3958                ASM_COMMENT_START);
3959     }
3960   fputc ('\n', asm_out_file);
3961   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
3962   if (flag_verbose_asm)
3963     {
3964       fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
3965                ASM_COMMENT_START);
3966     }
3967   fputc ('\n', asm_out_file);
3968   fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
3969   if (flag_verbose_asm)
3970     {
3971       fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
3972                ASM_COMMENT_START);
3973     }
3974   fputc ('\n', asm_out_file);
3975   fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
3976   if (flag_verbose_asm)
3977     {
3978       fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
3979                ASM_COMMENT_START);
3980     }
3981   fputc ('\n', asm_out_file);
3982   fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
3983   if (flag_verbose_asm)
3984     {
3985       fprintf (asm_out_file, "\t%s Special Opcode Base",
3986                ASM_COMMENT_START);
3987     }
3988   fputc ('\n', asm_out_file);
3989   for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
3990     {
3991       switch (opc)
3992         {
3993         case DW_LNS_advance_pc:
3994         case DW_LNS_advance_line:
3995         case DW_LNS_set_file:
3996         case DW_LNS_set_column:
3997         case DW_LNS_fixed_advance_pc:
3998           n_op_args = 1;
3999           break;
4000         default:
4001           n_op_args = 0;
4002           break;
4003         }
4004       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4005       if (flag_verbose_asm)
4006         {
4007           fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4008                    ASM_COMMENT_START, opc, n_op_args);
4009         }
4010       fputc ('\n', asm_out_file);
4011     }
4012   if (flag_verbose_asm)
4013     {
4014       fprintf (asm_out_file, "%s Include Directory Table\n",
4015                ASM_COMMENT_START);
4016     }
4017   /* Include directory table is empty, at present */
4018   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4019   fputc ('\n', asm_out_file);
4020   if (flag_verbose_asm)
4021     {
4022       fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4023     }
4024   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4025     {
4026       ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4027       if (flag_verbose_asm)
4028         {
4029           fprintf (asm_out_file, "%s File Entry: 0x%x",
4030                    ASM_COMMENT_START, ft_index);
4031         }
4032       fputc ('\n', asm_out_file);
4033       /* Include directory index */
4034       output_uleb128 (0);
4035       fputc ('\n', asm_out_file);
4036       /* Modification time */
4037       output_uleb128 (0);
4038       fputc ('\n', asm_out_file);
4039       /* File length in bytes */
4040       output_uleb128 (0);
4041       fputc ('\n', asm_out_file);
4042     }
4043   /* Terminate the file name table */
4044   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4045   fputc ('\n', asm_out_file);
4046
4047   /* Set the address register to the first location in the text section */
4048   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4049   if (flag_verbose_asm)
4050     {
4051       fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4052     }
4053   fputc ('\n', asm_out_file);
4054   output_uleb128 (1 + PTR_SIZE);
4055   fputc ('\n', asm_out_file);
4056   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4057   fputc ('\n', asm_out_file);
4058   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4059   fputc ('\n', asm_out_file);
4060
4061   /* Generate the line number to PC correspondence table, encoded as
4062      a series of state machine operations.  */
4063   current_file = 1;
4064   current_line = 1;
4065   strcpy (prev_line_label, TEXT_BEGIN_LABEL);
4066   for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4067     {
4068       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4069       if (flag_verbose_asm)
4070         {
4071           fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4072                    ASM_COMMENT_START);
4073         }
4074       fputc ('\n', asm_out_file);
4075       sprintf (line_label, LINE_CODE_LABEL_FMT, lt_index);
4076       ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4077       fputc ('\n', asm_out_file);
4078       line_info = &line_info_table[lt_index];
4079       if (line_info->dw_file_num != current_file)
4080         {
4081           current_file = line_info->dw_file_num;
4082           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4083           if (flag_verbose_asm)
4084             {
4085               fprintf (asm_out_file,
4086                        "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4087             }
4088           fputc ('\n', asm_out_file);
4089           output_uleb128 (current_file);
4090           if (flag_verbose_asm)
4091             {
4092               fprintf (asm_out_file, "\t%s \"%s\"",
4093                        ASM_COMMENT_START, file_table[current_file]);
4094             }
4095           fputc ('\n', asm_out_file);
4096         }
4097       if (line_info->dw_line_num != current_line)
4098         {
4099           line_offset = line_info->dw_line_num - current_line;
4100           line_delta = line_offset - DWARF_LINE_BASE;
4101           current_line = line_info->dw_line_num;
4102           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4103             {
4104               ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4105                                       DWARF_LINE_OPCODE_BASE + line_delta);
4106               if (flag_verbose_asm)
4107                 {
4108                   fprintf (asm_out_file,
4109                            "\t%s line %d", ASM_COMMENT_START, current_line);
4110                 }
4111               fputc ('\n', asm_out_file);
4112             }
4113           else
4114             {
4115               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4116               if (flag_verbose_asm)
4117                 {
4118                   fprintf (asm_out_file,
4119                            "\t%s advance to line %d",
4120                            ASM_COMMENT_START, current_line);
4121                 }
4122               fputc ('\n', asm_out_file);
4123               output_sleb128 (line_offset);
4124               fputc ('\n', asm_out_file);
4125               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4126               fputc ('\n', asm_out_file);
4127             }
4128         }
4129       strcpy (prev_line_label, line_label);
4130     }
4131
4132   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4133   if (flag_verbose_asm)
4134     {
4135       fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4136     }
4137   fputc ('\n', asm_out_file);
4138   output_uleb128 (1 + PTR_SIZE);
4139   fputc ('\n', asm_out_file);
4140   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4141   fputc ('\n', asm_out_file);
4142   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
4143   fputc ('\n', asm_out_file);
4144   /* Output the marker for the end of the line number info.  */
4145   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4146   if (flag_verbose_asm)
4147     {
4148       fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4149     }
4150   fputc ('\n', asm_out_file);
4151   output_uleb128 (1);
4152   fputc ('\n', asm_out_file);
4153   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4154   fputc ('\n', asm_out_file);
4155 }
4156 \f
4157 /**************** attribute support utilities ********************************/
4158
4159 /*
4160  * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4161  * in question represents the outermost pair of curly braces (i.e. the "body
4162  * block") of a function or method.
4163  *
4164  * For any BLOCK node representing a "body block" of a function or method, the
4165  * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4166  * represents the outermost (function) scope for the function or method (i.e.
4167  * the one which includes the formal parameters).  The BLOCK_SUPERCONTEXT of
4168  * *that* node in turn will point to the relevant FUNCTION_DECL node.
4169  */
4170 inline int
4171 is_body_block (stmt)
4172      register tree stmt;
4173 {
4174   if (TREE_CODE (stmt) == BLOCK)
4175     {
4176       register tree parent = BLOCK_SUPERCONTEXT (stmt);
4177
4178       if (TREE_CODE (parent) == BLOCK)
4179         {
4180           register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4181
4182           if (TREE_CODE (grandparent) == FUNCTION_DECL)
4183             return 1;
4184         }
4185     }
4186   return 0;
4187 }
4188
4189 /* Reset the base type to DIE table, and build a special predefined
4190    base type entry for the "int" signed integer base type.  The
4191    "int" base type is used to construct subscript index range
4192    definitions, in situations where an anonymous integer type
4193    is required.  */
4194 inline void
4195 init_base_type_table ()
4196 {
4197   register int i;
4198   register base_type_ref bt;
4199   for (i = 0; i < NUM_BASE_TYPES; ++i)
4200     {
4201       base_type_die_table[i] = NULL;
4202     }
4203   assert (comp_unit_die != 0);
4204   for (i = 0; i < NUM_BASE_TYPES; ++i)
4205     {
4206       bt = &base_type_table[i];
4207       if (strcmp (bt->bt_name, "int") == 0)
4208         {
4209           int_base_type_die = new_die (DW_TAG_base_type, comp_unit_die);
4210           base_type_die_table[i] = int_base_type_die;
4211           add_AT_string (int_base_type_die, DW_AT_name, bt->bt_name);
4212           add_AT_unsigned (int_base_type_die,
4213                            DW_AT_byte_size, bt->bt_size / 8);
4214           add_AT_unsigned (int_base_type_die, DW_AT_encoding, bt->bt_type);
4215           break;
4216         }
4217     }
4218 }
4219
4220 /* Given a pointer to a tree node for some base type, return a pointer to
4221    a DIE that describes the given type.
4222
4223    This routine must only be called for GCC type nodes that correspond to
4224    Dwarf base (fundamental) types.  */
4225 static dw_die_ref
4226 base_type_die (type)
4227      register tree type;
4228 {
4229   register dw_die_ref base_type_result = NULL;
4230   register char *type_name = NULL;
4231   register int type_index = 0;
4232   register base_type_ref bt;
4233   register int i;
4234
4235   if (TREE_CODE (type) == ERROR_MARK)
4236     return 0;
4237
4238   switch (TREE_CODE (type))
4239     {
4240     case VOID_TYPE:
4241     case ERROR_MARK:
4242       break;
4243
4244     case INTEGER_TYPE:
4245       /* Carefully distinguish all the standard types of C, without messing
4246          up if the language is not C. Note that we check only for the names
4247          that contain spaces; other names might occur by coincidence in other 
4248          languages.  */
4249       if (TYPE_NAME (type) != 0
4250           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
4251           && DECL_NAME (TYPE_NAME (type)) != 0
4252           && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
4253         {
4254           type_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
4255           for (i = 0; i < NUM_BASE_TYPES; ++i)
4256             {
4257               bt = &base_type_table[i];
4258               if (strcmp (type_name, bt->bt_name) == 0)
4259                 {
4260                   type_index = i;
4261                   break;
4262                 }
4263             }
4264         }
4265
4266       /* Most integer types will be sorted out above, however, for the sake
4267          of special `array index' integer types, the following code is also
4268          provided.  */
4269       if (type_index == 0)
4270         {
4271           for (i = 0; i < NUM_BASE_TYPES; ++i)
4272             {
4273               bt = &base_type_table[i];
4274               if (bt->bt_size == TYPE_PRECISION (type)
4275                   && (TREE_UNSIGNED (type) == 0) == bt->bt_is_signed)
4276                 {
4277                   type_index = i;
4278                   break;
4279                 }
4280             }
4281         }
4282       break;
4283
4284     case REAL_TYPE:
4285       /* Carefully distinguish all the standard types of C, without messing
4286          up if the language is not C.  */
4287       for (i = 0; i < NUM_BASE_TYPES; ++i)
4288         {
4289           bt = &base_type_table[i];
4290           if ((bt->bt_type == DW_ATE_float)
4291               && (bt->bt_size == TYPE_PRECISION (type)))
4292             {
4293               type_index = i;
4294               break;
4295             }
4296         }
4297       break;
4298
4299     case COMPLEX_TYPE:
4300       for (i = 0; i < NUM_BASE_TYPES; ++i)
4301         {
4302           bt = &base_type_table[i];
4303           if ((bt->bt_type == DW_ATE_complex_float)
4304               && (bt->bt_size == TYPE_PRECISION (type)))
4305             {
4306               type_index = i;
4307               break;
4308             }
4309         }
4310       break;
4311
4312     case CHAR_TYPE:
4313       /* GNU Pascal/Ada CHAR type.  Not used in C.  */
4314       for (i = 0; i < NUM_BASE_TYPES; ++i)
4315         {
4316           bt = &base_type_table[i];
4317           if (bt->bt_type == DW_ATE_signed_char
4318               || bt->bt_type == DW_ATE_unsigned_char)
4319             {
4320               if (bt->bt_size == TYPE_PRECISION (type)
4321                   && ((TREE_UNSIGNED (type) == 0) == bt->bt_is_signed))
4322                 {
4323                   type_index = i;
4324                   break;
4325                 }
4326             }
4327         }
4328       break;
4329
4330     case BOOLEAN_TYPE:
4331       /* GNU FORTRAN/Ada BOOLEAN type.  */
4332       for (i = 0; i < NUM_BASE_TYPES; ++i)
4333         {
4334           bt = &base_type_table[i];
4335           if (bt->bt_type == DW_ATE_boolean
4336               && bt->bt_size == TYPE_PRECISION (type))
4337             {
4338               type_index = i;
4339               break;
4340             }
4341         }
4342       break;
4343
4344     default:
4345       abort ();                 /* No other TREE_CODEs are Dwarf fundamental
4346                                    types.  */
4347     }
4348
4349   if (type_index == 0)
4350     {
4351       base_type_result = NULL;
4352     }
4353   else
4354     {
4355       base_type_result = base_type_die_table[type_index];
4356       if (base_type_result == NULL)
4357         {
4358           bt = &base_type_table[type_index];
4359           base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
4360           base_type_die_table[type_index] = base_type_result;
4361           add_AT_string (base_type_result, DW_AT_name, bt->bt_name);
4362           add_AT_unsigned (base_type_result, DW_AT_byte_size, bt->bt_size / 8);
4363           add_AT_unsigned (base_type_result, DW_AT_encoding, bt->bt_type);
4364         }
4365
4366     }
4367
4368   return base_type_result;
4369 }
4370
4371 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4372    the Dwarf "root" type for the given input type.  The Dwarf "root" type of
4373    a given type is generally the same as the given type, except that if the
4374    given type is a pointer or reference type, then the root type of the given
4375    type is the root type of the "basis" type for the pointer or reference
4376    type.  (This definition of the "root" type is recursive.) Also, the root
4377    type of a `const' qualified type or a `volatile' qualified type is the
4378    root type of the given type without the qualifiers.  */
4379 static tree
4380 root_type (type)
4381      register tree type;
4382 {
4383   if (TREE_CODE (type) == ERROR_MARK)
4384     return error_mark_node;
4385
4386   switch (TREE_CODE (type))
4387     {
4388     case ERROR_MARK:
4389       return error_mark_node;
4390
4391     case POINTER_TYPE:
4392     case REFERENCE_TYPE:
4393       return type_main_variant (root_type (TREE_TYPE (type)));
4394
4395     default:
4396       return type_main_variant (type);
4397     }
4398 }
4399
4400 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4401    given input type is a Dwarf "fundamental" type.  Otherwise return null.  */
4402 inline int
4403 is_base_type (type)
4404      register tree type;
4405 {
4406   switch (TREE_CODE (type))
4407     {
4408     case ERROR_MARK:
4409     case VOID_TYPE:
4410     case INTEGER_TYPE:
4411     case REAL_TYPE:
4412     case COMPLEX_TYPE:
4413     case BOOLEAN_TYPE:
4414     case CHAR_TYPE:
4415       return 1;
4416
4417     case SET_TYPE:
4418     case ARRAY_TYPE:
4419     case RECORD_TYPE:
4420     case UNION_TYPE:
4421     case QUAL_UNION_TYPE:
4422     case ENUMERAL_TYPE:
4423     case FUNCTION_TYPE:
4424     case METHOD_TYPE:
4425     case POINTER_TYPE:
4426     case REFERENCE_TYPE:
4427     case FILE_TYPE:
4428     case OFFSET_TYPE:
4429     case LANG_TYPE:
4430       return 0;
4431
4432     default:
4433       abort ();
4434     }
4435   return 0;
4436 }
4437
4438 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4439    entry that chains various modifiers in front of the given type.  */
4440 static dw_die_ref
4441 modified_type_die (type, is_const_type, is_volatile_type, context_die)
4442      register tree type;
4443      register int is_const_type;
4444      register int is_volatile_type;
4445      register dw_die_ref context_die;
4446 {
4447   register enum tree_code code = TREE_CODE (type);
4448   register dw_die_ref mod_type_die = NULL;
4449   register dw_die_ref sub_die = NULL;
4450   register tree item_type;
4451
4452   if (code != ERROR_MARK)
4453     {
4454       if (is_const_type)
4455         {
4456           mod_type_die = new_die (DW_TAG_const_type, context_die);
4457           sub_die = modified_type_die (type,
4458                                        0, is_volatile_type, context_die);
4459         }
4460       else if (is_volatile_type)
4461         {
4462           mod_type_die = new_die (DW_TAG_volatile_type, context_die);
4463           sub_die = modified_type_die (type, 0, 0, context_die);
4464         }
4465       else if (code == POINTER_TYPE)
4466         {
4467           mod_type_die = new_die (DW_TAG_pointer_type, context_die);
4468           add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4469           add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
4470           item_type = TREE_TYPE (type);
4471           sub_die = modified_type_die (item_type,
4472                                        TYPE_READONLY (item_type),
4473                                        TYPE_VOLATILE (item_type),
4474                                        context_die);
4475         }
4476       else if (code == REFERENCE_TYPE)
4477         {
4478           mod_type_die = new_die (DW_TAG_reference_type, context_die);
4479           add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4480           add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
4481           item_type = TREE_TYPE (type);
4482           sub_die = modified_type_die (item_type,
4483                                        TYPE_READONLY (item_type),
4484                                        TYPE_VOLATILE (item_type),
4485                                        context_die);
4486         }
4487       else if (is_base_type (type))
4488         {
4489           mod_type_die = base_type_die (type);
4490         }
4491       else
4492         {
4493           /* We have to get the type_main_variant here (and pass that to the
4494              `lookup_type_die' routine) because the ..._TYPE node we have
4495              might simply be a *copy* of some original type node (where the
4496              copy was created to help us keep track of typedef names) and
4497              that copy might have a different TYPE_UID from the original
4498              ..._TYPE node.  (Note that when `equate_type_number_to_die' is
4499              labeling a given type DIE for future reference, it always only
4500              handles DIEs representing *main variants*, and it never even
4501              knows about non-main-variants.).  */
4502           mod_type_die = lookup_type_die (type_main_variant (type));
4503
4504           /* Normally, we assume that all types are defined before they are
4505              referenced.  If this is not the case, then mod_type_die will
4506              be NULL here, and we must backchain.  This can happen as the
4507              result of a forward declaration of a structure tag.  */
4508           if (mod_type_die == NULL)
4509             {
4510               dw_die_ref placeholder_die = new_die (DW_TAG_padding,
4511                                                     context_die);
4512               backchain_AT_die_ref (type, placeholder_die);
4513             }
4514         }
4515     }
4516   if (sub_die != NULL)
4517     {
4518       add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
4519     }
4520   return mod_type_die;
4521 }
4522
4523 /* Fix all unresolved die references that resulted from forward
4524    declarations.  */
4525 static void
4526 resolve_backchains ()
4527 {
4528   register backchain_ref back;
4529
4530   back = backchain;
4531   while (back)
4532     {
4533       register dw_die_ref type_die;
4534
4535       type_die = lookup_type_die (type_main_variant (back->type));
4536
4537       assert (type_die != NULL);
4538                                     
4539       /* ??? It would be cleaner to find the die attribute, and change
4540          the val_dir_ref field to point to this new die.  Just overwriting
4541          the temporary die with the correct one is easier though, and seems
4542          to work just as well.  */
4543       memcpy (back->placeholder, type_die, sizeof (die_node));
4544
4545       back = back->next;
4546     }
4547 }
4548
4549 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
4550    an enumerated type.   */
4551 inline int
4552 type_is_enum (type)
4553      register tree type;
4554 {
4555   return TREE_CODE (type) == ENUMERAL_TYPE;
4556 }
4557
4558 /* Return the register number described by a given RTL node.  */
4559 static unsigned
4560 reg_number (rtl)
4561      register rtx rtl;
4562 {
4563   register unsigned regno = REGNO (rtl);
4564
4565   if (regno >= FIRST_PSEUDO_REGISTER)
4566     {
4567       warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
4568                          regno);
4569       regno = 0;
4570     }
4571   regno = DBX_REGISTER_NUMBER (regno);
4572   return regno;
4573 }
4574
4575 /* Return a location descriptor that designates a machine register.  */
4576 static dw_loc_descr_ref
4577 reg_loc_descriptor (rtl)
4578      register rtx rtl;
4579 {
4580   register dw_loc_descr_ref loc_result = NULL;
4581   register unsigned reg = reg_number (rtl);
4582   if (reg >= 0 && reg <= 31)
4583     {
4584       loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
4585     }
4586   else
4587     {
4588       loc_result = new_loc_descr (DW_OP_regx, reg, 0);
4589     }
4590   return loc_result;
4591 }
4592
4593 /* Return a location descriptor that designates a base+offset location.  */
4594 static dw_loc_descr_ref
4595 based_loc_descr (reg, offset)
4596      unsigned reg;
4597      long int offset;
4598 {
4599   register dw_loc_descr_ref loc_result;
4600   register unsigned fp_reg = (frame_pointer_needed)
4601                                       ? FRAME_POINTER_REGNUM
4602                                       : STACK_POINTER_REGNUM;
4603   if (reg == fp_reg)
4604     {
4605       loc_result = new_loc_descr (DW_OP_fbreg,
4606                                   offset - current_funcdef_frame_size, 0);
4607     }
4608   else if (reg >= 0 && reg <= 31)
4609     {
4610       loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
4611     }
4612   else
4613     {
4614       loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
4615     }
4616   return loc_result;
4617 }
4618
4619 /* Return true if this RTL expression describes a base+offset calculation.  */
4620 inline int
4621 is_based_loc (rtl)
4622      register rtx rtl;
4623 {
4624     return GET_CODE (rtl) == PLUS
4625            && ((GET_CODE (XEXP (rtl, 0)) == REG
4626                 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
4627 }
4628
4629 /* The following routine converts the RTL for a variable or parameter
4630    (resident in memory) into an equivalent Dwarf representation of a
4631    mechanism for getting the address of that same variable onto the top of a
4632    hypothetical "address evaluation" stack.
4633    When creating memory location descriptors, we are effectively transforming
4634    the RTL for a memory-resident object into its Dwarf postfix expression
4635    equivalent.  This routine recursively descends an RTL tree, turning
4636    it into Dwarf postfix code as it goes.  */
4637 static dw_loc_descr_ref
4638 mem_loc_descriptor (rtl)
4639      register rtx rtl;
4640 {
4641   dw_loc_descr_ref mem_loc_result = NULL;
4642   /* Note that for a dynamically sized array, the location we will generate a 
4643      description of here will be the lowest numbered location which is
4644      actually within the array.  That's *not* necessarily the same as the
4645      zeroth element of the array.  */
4646   switch (GET_CODE (rtl))
4647     {
4648     case SUBREG:
4649       /* The case of a subreg may arise when we have a local (register)
4650          variable or a formal (register) parameter which doesn't quite fill
4651          up an entire register.  For now, just assume that it is
4652          legitimate to make the Dwarf info refer to the whole register which
4653          contains the given subreg.  */
4654       rtl = XEXP (rtl, 0);
4655       /* Drop thru.  */
4656
4657     case REG:
4658       /* Whenever a register number forms a part of the description of the
4659          method for calculating the (dynamic) address of a memory resident
4660          object, DWARF rules require the register number be referred to as 
4661          a "base register".  This distinction is not based in any way upon
4662          what category of register the hardware believes the given register
4663          belongs to.  This is strictly DWARF terminology we're dealing with
4664          here. Note that in cases where the location of a memory-resident
4665          data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
4666          OP_CONST (0)) the actual DWARF location descriptor that we generate
4667          may just be OP_BASEREG (basereg).  This may look deceptively like
4668          the object in question was allocated to a register (rather than in
4669          memory) so DWARF consumers need to be aware of the subtle
4670          distinction between OP_REG and OP_BASEREG.  */
4671       mem_loc_result = based_loc_descr (reg_number (rtl), 0);
4672       break;
4673
4674     case MEM:
4675       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
4676       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
4677       break;
4678
4679     case CONST:
4680     case SYMBOL_REF:
4681       mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
4682       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
4683       mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
4684       break;
4685
4686     case PLUS:
4687       if (is_based_loc (rtl))
4688         {
4689           mem_loc_result = based_loc_descr (
4690                               reg_number (XEXP (rtl, 0)),
4691                               INTVAL (XEXP (rtl, 1)));
4692         }
4693       else
4694         {
4695           add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
4696           add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
4697           add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
4698         }
4699       break;
4700
4701     case CONST_INT:
4702       mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
4703       break;
4704
4705     default:
4706       abort ();
4707     }
4708   return mem_loc_result;
4709 }
4710
4711 /* Output a proper Dwarf location descriptor for a variable or parameter
4712    which is either allocated in a register or in a memory location.  For a
4713    register, we just generate an OP_REG and the register number.  For a
4714    memory location we provide a Dwarf postfix expression describing how to
4715    generate the (dynamic) address of the object onto the address stack.  */
4716 static dw_loc_descr_ref
4717 loc_descriptor (rtl)
4718      register rtx rtl;
4719 {
4720   dw_loc_descr_ref loc_result = NULL;
4721   switch (GET_CODE (rtl))
4722     {
4723     case SUBREG:
4724
4725       /* The case of a subreg may arise when we have a local (register)
4726          variable or a formal (register) parameter which doesn't quite fill
4727          up an entire register.       For now, just assume that it is
4728          legitimate to make the Dwarf info refer to the whole register which
4729          contains the given subreg.  */
4730
4731       rtl = XEXP (rtl, 0);
4732       loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
4733       break;
4734
4735     case REG:
4736       loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
4737       break;
4738
4739     case MEM:
4740       loc_result = mem_loc_descriptor (XEXP (rtl, 0));
4741       break;
4742
4743     default:
4744       abort ();                 /* Should never happen */
4745     }
4746   return loc_result;
4747 }
4748
4749 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
4750    which is not less than the value itself.  */
4751 inline unsigned
4752 ceiling (value, boundary)
4753      register unsigned value;
4754      register unsigned boundary;
4755 {
4756   return (((value + boundary - 1) / boundary) * boundary);
4757 }
4758
4759 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
4760    pointer to the declared type for the relevant field variable, or return
4761    `integer_type_node' if the given node turns out to be an
4762    ERROR_MARK node.  */
4763 inline tree
4764 field_type (decl)
4765      register tree decl;
4766 {
4767   register tree type;
4768
4769   if (TREE_CODE (decl) == ERROR_MARK)
4770     return integer_type_node;
4771
4772   type = DECL_BIT_FIELD_TYPE (decl);
4773   if (type == NULL)
4774     type = TREE_TYPE (decl);
4775
4776   return type;
4777 }
4778
4779 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
4780    node, return the alignment in bits for the type, or else return
4781    BITS_PER_WORD if the node actually turns out to be an
4782    ERROR_MARK node.  */
4783 inline unsigned
4784 simple_type_align_in_bits (type)
4785      register tree type;
4786 {
4787   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
4788 }
4789
4790 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
4791    node, return the size in bits for the type if it is a constant, or else
4792    return the alignment for the type if the type's size is not constant, or
4793    else return BITS_PER_WORD if the type actually turns out to be an
4794    ERROR_MARK node.  */
4795 inline unsigned
4796 simple_type_size_in_bits (type)
4797      register tree type;
4798 {
4799   if (TREE_CODE (type) == ERROR_MARK)
4800     return BITS_PER_WORD;
4801   else
4802     {
4803       register tree type_size_tree = TYPE_SIZE (type);
4804
4805       if (TREE_CODE (type_size_tree) != INTEGER_CST)
4806         return TYPE_ALIGN (type);
4807
4808       return (unsigned) TREE_INT_CST_LOW (type_size_tree);
4809     }
4810 }
4811
4812 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
4813    return the byte offset of the lowest addressed byte of the "containing
4814    object" for the given FIELD_DECL, or return 0 if we are unable to
4815    determine what that offset is, either because the argument turns out to
4816    be a pointer to an ERROR_MARK node, or because the offset is actually
4817    variable.  (We can't handle the latter case just yet).  */
4818 static unsigned
4819 field_byte_offset (decl)
4820      register tree decl;
4821 {
4822   register unsigned type_align_in_bytes;
4823   register unsigned type_align_in_bits;
4824   register unsigned type_size_in_bits;
4825   register unsigned object_offset_in_align_units;
4826   register unsigned object_offset_in_bits;
4827   register unsigned object_offset_in_bytes;
4828   register tree type;
4829   register tree bitpos_tree;
4830   register tree field_size_tree;
4831   register unsigned bitpos_int;
4832   register unsigned deepest_bitpos;
4833   register unsigned field_size_in_bits;
4834
4835   if (TREE_CODE (decl) == ERROR_MARK)
4836     return 0;
4837
4838   if (TREE_CODE (decl) != FIELD_DECL)
4839     abort ();
4840
4841   type = field_type (decl);
4842
4843   bitpos_tree = DECL_FIELD_BITPOS (decl);
4844   field_size_tree = DECL_SIZE (decl);
4845
4846   /* We cannot yet cope with fields whose positions or sizes are variable, so 
4847      for now, when we see such things, we simply return 0.  Someday, we may
4848      be able to handle such cases, but it will be damn difficult.  */
4849   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
4850     return 0;
4851   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
4852
4853   if (TREE_CODE (field_size_tree) != INTEGER_CST)
4854     return 0;
4855   field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
4856
4857   type_size_in_bits = simple_type_size_in_bits (type);
4858
4859   type_align_in_bits = simple_type_align_in_bits (type);
4860   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
4861
4862   /* Note that the GCC front-end doesn't make any attempt to keep track of
4863      the starting bit offset (relative to the start of the containing
4864      structure type) of the hypothetical "containing object" for a bit-
4865      field.  Thus, when computing the byte offset value for the start of the
4866      "containing object" of a bit-field, we must deduce this information on 
4867      our own. This can be rather tricky to do in some cases.  For example,
4868      handling the following structure type definition when compiling for an
4869      i386/i486 target (which only aligns long long's to 32-bit boundaries)
4870      can be very tricky:
4871
4872          struct S { int field1; long long field2:31; };
4873
4874      Fortunately, there is a simple rule-of-thumb which can be
4875      used in such cases.  When compiling for an i386/i486, GCC will allocate
4876      8 bytes for the structure shown above.  It decides to do this based upon 
4877      one simple rule for bit-field allocation.  Quite simply, GCC allocates
4878      each "containing object" for each bit-field at the first (i.e. lowest
4879      addressed) legitimate alignment boundary (based upon the required
4880      minimum alignment for the declared type of the field) which it can
4881      possibly use, subject to the condition that there is still enough
4882      available space remaining in the containing object (when allocated at
4883      the selected point) to fully accommodate all of the bits of the
4884      bit-field itself.  This simple rule makes it obvious why GCC allocates
4885      8 bytes for each object of the structure type shown above.  When looking
4886      for a place to allocate the "containing object" for `field2', the
4887      compiler simply tries to allocate a 64-bit "containing object" at each
4888      successive 32-bit boundary (starting at zero) until it finds a place to
4889      allocate that 64- bit field such that at least 31 contiguous (and
4890      previously unallocated) bits remain within that selected 64 bit field.
4891      (As it turns out, for the example above, the compiler finds that it is
4892      OK to allocate the "containing object" 64-bit field at bit-offset zero
4893      within the structure type.) Here we attempt to work backwards from the
4894      limited set of facts we're given, and we try to deduce from those facts, 
4895      where GCC must have believed that the containing object started (within
4896      the structure type). The value we deduce is then used (by the callers of 
4897      this routine) to generate DW_AT_location and DW_AT_bit_offset attributes 
4898      for fields (both bit-fields and, in the case of DW_AT_location, regular
4899      fields as well).  */
4900
4901   /* Figure out the bit-distance from the start of the structure to the
4902      "deepest" bit of the bit-field.  */
4903   deepest_bitpos = bitpos_int + field_size_in_bits;
4904
4905   /* This is the tricky part.  Use some fancy footwork to deduce where the
4906      lowest addressed bit of the containing object must be.  */
4907   object_offset_in_bits
4908     = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
4909
4910   /* Compute the offset of the containing object in "alignment units".  */
4911   object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
4912
4913   /* Compute the offset of the containing object in bytes.  */
4914   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
4915
4916   return object_offset_in_bytes;
4917 }
4918
4919
4920 \f
4921 /****************************** attributes *********************************/
4922
4923 /* The following routines define various Dwarf attributes
4924    (and any data associated with them).  */
4925
4926
4927 /* Output the form of location attributes suitable for whole variables and
4928    whole parameters.  Note that the location attributes for struct fields are
4929    generated by the routine `data_member_location_attribute' below.  */
4930 static void
4931 add_location_attribute (die, rtl)
4932      dw_die_ref die;
4933      register rtx rtl;
4934 {
4935   dw_loc_descr_ref loc_descr = NULL;
4936
4937   /* Handle a special case.  If we are about to output a location descriptor
4938      for a variable or parameter which has been optimized out of existence,
4939      don't do that.  Instead we output a null location descriptor value as
4940      part of the location attribute. A variable which has been optimized out
4941      of existence will have a DECL_RTL value which denotes a pseudo-reg.
4942      Currently, in some rare cases, variables can have DECL_RTL values which
4943      look like (MEM (REG pseudo-reg#)).  These cases are due to bugs
4944      elsewhere in the compiler.  We treat such cases as if the variable(s) in 
4945      question had been optimized out of existence. Note that in all cases
4946      where we wish to express the fact that a variable has been optimized out 
4947      of existence, we do not simply suppress the generation of the entire
4948      location attribute because the absence of a location attribute in
4949      certain kinds of DIEs is used to indicate something else entirely...
4950      i.e. that the DIE represents an object declaration, but not a
4951      definition.  So sayeth the PLSIG.  */
4952   if (!is_pseudo_reg (rtl)
4953       && (GET_CODE (rtl) != MEM
4954           || !is_pseudo_reg (XEXP (rtl, 0))))
4955     {
4956       loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
4957     }
4958
4959 #ifdef MIPS_DEBUGGING_INFO
4960   /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
4961      location descriptor.  Lets just use r0 for now to represent a
4962      variable that has been optimized away.  */
4963   if (loc_descr == NULL)
4964     {
4965       loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
4966     }
4967 #endif
4968
4969   add_AT_loc (die, DW_AT_location, loc_descr);
4970 }
4971
4972 /* Attach the specialized form of location attribute used for data
4973    members of struct and union types.  In the special case of a
4974    FIELD_DECL node which represents a bit-field, the "offset" part
4975    of this special location descriptor must indicate the distance
4976    in bytes from the lowest-addressed byte of the containing struct
4977    or union type to the lowest-addressed byte of the "containing
4978    object" for the bit-field.  (See the `field_byte_offset' function
4979    above).. For any given bit-field, the "containing object" is a
4980    hypothetical object (of some integral or enum type) within which
4981    the given bit-field lives.  The type of this hypothetical
4982    "containing object" is always the same as the declared type of
4983    the individual bit-field itself (for GCC anyway... the DWARF
4984    spec doesn't actually mandate this).  Note that it is the size
4985    (in bytes) of the hypothetical "containing object" which will
4986    be given in the DW_AT_byte_size attribute for this bit-field.
4987    (See the `byte_size_attribute' function below.)  It is also used
4988    when calculating the value of the DW_AT_bit_offset attribute.
4989    (See the `bit_offset_attribute' function below).  */
4990 static void
4991 add_data_member_location_attribute (die, decl)
4992      register dw_die_ref die;
4993      register tree decl;
4994 {
4995   register unsigned long offset = field_byte_offset (decl);
4996   register dw_loc_descr_ref loc_descr;
4997   register enum dwarf_location_atom op;
4998
4999   /* The DWARF2 standard says that we should assume that the structure address
5000      is already on the stack, so we can specify a structure field address
5001      by using DW_OP_plus_uconst.  */
5002 #ifdef MIPS_DEBUGGING_INFO
5003   /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5004      correctly.  It works only if we leave the offset on the stack.  */
5005   op = DW_OP_constu;
5006 #else
5007   op = DW_OP_plus_uconst;
5008 #endif
5009   loc_descr = new_loc_descr (op, offset, 0);
5010   add_AT_loc (die, DW_AT_data_member_location, loc_descr);
5011 }
5012
5013 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5014    does not have a "location" either in memory or in a register.  These
5015    things can arise in GNU C when a constant is passed as an actual parameter
5016    to an inlined function.  They can also arise in C++ where declared
5017    constants do not necessarily get memory "homes".  */
5018 static void
5019 add_const_value_attribute (die, rtl)
5020      register dw_die_ref die;
5021      register rtx rtl;
5022 {
5023   switch (GET_CODE (rtl))
5024     {
5025     case CONST_INT:
5026       /* Note that a CONST_INT rtx could represent either an integer or a
5027          floating-point constant.  A CONST_INT is used whenever the constant
5028          will fit into a single word.  In all such cases, the original mode
5029          of the constant value is wiped out, and the CONST_INT rtx is
5030          assigned VOIDmode.  */
5031       add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
5032       break;
5033
5034     case CONST_DOUBLE:
5035       /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5036          floating-point constant.  A CONST_DOUBLE is used whenever the
5037          constant requires more than one word in order to be adequately
5038          represented.  In all such cases, the original mode of the constant
5039          value is preserved as the mode of the CONST_DOUBLE rtx, but for
5040          simplicity we always just output CONST_DOUBLEs using 8 bytes.  */
5041       add_AT_double (die, DW_AT_const_value,
5042                      (unsigned) CONST_DOUBLE_HIGH (rtl),
5043                      (unsigned) CONST_DOUBLE_LOW (rtl));
5044       break;
5045
5046     case CONST_STRING:
5047       add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5048       break;
5049
5050     case SYMBOL_REF:
5051     case LABEL_REF:
5052     case CONST:
5053       add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
5054       break;
5055
5056     case PLUS:
5057       /* In cases where an inlined instance of an inline function is passed
5058          the address of an `auto' variable (which is local to the caller) we
5059          can get a situation where the DECL_RTL of the artificial local
5060          variable (for the inlining) which acts as a stand-in for the
5061          corresponding formal parameter (of the inline function) will look
5062          like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).  This is not
5063          exactly a compile-time constant expression, but it isn't the address 
5064          of the (artificial) local variable either.  Rather, it represents the 
5065          *value* which the artificial local variable always has during its
5066          lifetime.  We currently have no way to represent such quasi-constant 
5067          values in Dwarf, so for now we just punt and generate an
5068          DW_AT_const_value attribute with null address.  */
5069       add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
5070       break;
5071
5072     default:
5073       /* No other kinds of rtx should be possible here.  */
5074       abort ();
5075     }
5076
5077 }
5078
5079 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5080    data attribute for a variable or a parameter.  We generate the
5081    DW_AT_const_value attribute only in those cases where the given variable
5082    or parameter does not have a true "location" either in memory or in a
5083    register.  This can happen (for example) when a constant is passed as an
5084    actual argument in a call to an inline function.  (It's possible that
5085    these things can crop up in other ways also.)  Note that one type of
5086    constant value which can be passed into an inlined function is a constant
5087    pointer.  This can happen for example if an actual argument in an inlined
5088    function call evaluates to a compile-time constant address.  */
5089 static void
5090 add_location_or_const_value_attribute (die, decl)
5091      register dw_die_ref die;
5092      register tree decl;
5093 {
5094   register rtx rtl;
5095   register tree declared_type;
5096   register tree passed_type;
5097
5098   if (TREE_CODE (decl) == ERROR_MARK)
5099     {
5100       return;
5101     }
5102   if ((TREE_CODE (decl) != VAR_DECL)
5103       && (TREE_CODE (decl) != PARM_DECL))
5104     {
5105       /* Should never happen.  */
5106       abort ();
5107       return;
5108     }
5109   /* Here we have to decide where we are going to say the parameter "lives"
5110      (as far as the debugger is concerned).  We only have a couple of
5111      choices.  GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5112      DECL_RTL normally indicates where the parameter lives during most of the 
5113      activa- tion of the function.  If optimization is enabled however, this
5114      could be either NULL or else a pseudo-reg.  Both of those cases indicate 
5115      that the parameter doesn't really live anywhere (as far as the code
5116      generation parts of GCC are concerned) during most of the function's
5117      activation.  That will happen (for example) if the parameter is never
5118      referenced within the function.  We could just generate a location
5119      descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5120      ignore all of the rest, but we can be a little nicer than that if we
5121      also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5122      pseudo-reg. Note however that we can only get away with using
5123      DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited 
5124      cases.  In cases where DECL_ARG_TYPE(decl) indicates the same type as
5125      TREE_TYPE(decl) we can be sure that the parameter was passed using the
5126      same type as it is declared to have within the function, and that its
5127      DECL_INCOMING_RTL points us to a place where a value of that type is
5128      passed.  In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5129      different types however, we cannot (in general) use DECL_INCOMING_RTL as 
5130      a backup substitute for DECL_RTL because in these cases,
5131      DECL_INCOMING_RTL points us to a value of some type which is *different* 
5132      from the type of the parameter itself.  Thus, if we tried to use
5133      DECL_INCOMING_RTL to generate a location attribute in such cases, the
5134      debugger would end up (for example) trying to fetch a `float' from a
5135      place which actually contains the first part of a `double'.  That would
5136      lead to really incorrect and confusing output at debug-time, and we
5137      don't want that now do we? So in general, we DO NOT use
5138      DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5139      DECL_ARG_TYPE(decl) != TREE_TYPE(decl).  There are a couple of cute
5140      exceptions however.  On little-endian machines we can get away with
5141      using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as 
5142      TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5143      which is smaller than TREE_TYPE(decl). These cases arise when (on a
5144      little-endian machine) a non-prototyped function has a parameter
5145      declared to be of type `short' or `char'.  In such cases,
5146      TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5147      `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5148      passed `int' value.  If the debugger then uses that address to fetch a
5149      `short' or a `char' (on a little-endian machine) the result will be the
5150      correct data, so we allow for such exceptional cases below. Note that
5151      our goal here is to describe the place where the given formal parameter
5152      lives during most of the function's activation (i.e. between the end of
5153      the prologue and the start of the epilogue).  We'll do that as best as
5154      we can. Note however that if the given formal parameter is modified
5155      sometime during the execution of the function, then a stack backtrace
5156      (at debug-time) will show the function as having been called with the
5157      *new* value rather than the value which was originally passed in.  This
5158      happens rarely enough that it is not a major problem, but it *is* a
5159      problem, and I'd like to fix it.  A future version of dwarfout.c may
5160      generate two additional attributes for any given DW_TAG_formal_parameter 
5161      DIE which will describe the "passed type" and the "passed location" for
5162      the given formal parameter in addition to the attributes we now generate 
5163      to indicate the "declared type" and the "active location" for each
5164      parameter.  This additional set of attributes could be used by debuggers 
5165      for stack backtraces. Separately, note that sometimes DECL_RTL can be
5166      NULL and DECL_INCOMING_RTL can be NULL also.  This happens (for example) 
5167      for inlined-instances of inline function formal parameters which are
5168      never referenced.  This really shouldn't be happening.  All PARM_DECL
5169      nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5170      integrate.c doesn't currently generate these values for inlined
5171      instances of inline function parameters, so when we see such cases, we
5172      are just SOL (shit-out-of-luck) for the time being (until integrate.c
5173      gets fixed).  */
5174
5175   /* Use DECL_RTL as the "location" unless we find something better.  */
5176   rtl = DECL_RTL (decl);
5177
5178   if (TREE_CODE (decl) == PARM_DECL)
5179     {
5180       if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5181         {
5182           declared_type = type_main_variant (TREE_TYPE (decl));
5183           passed_type = type_main_variant (DECL_ARG_TYPE (decl));
5184           /* This decl represents a formal parameter which was
5185              optimized out.
5186
5187              Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5188              all* cases where (rtl == NULL_RTX) just below.  */
5189           if (declared_type == passed_type)
5190             {
5191               rtl = DECL_INCOMING_RTL (decl);
5192             }
5193           else if (!BYTES_BIG_ENDIAN)
5194             {
5195               if (TREE_CODE (declared_type) == INTEGER_TYPE)
5196                 {
5197                   if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5198                     {
5199                       rtl = DECL_INCOMING_RTL (decl);
5200                     }
5201                 }
5202             }
5203           if (rtl == NULL_RTX)
5204             {
5205               return;
5206             }
5207         }
5208     }
5209   switch (GET_CODE (rtl))
5210     {
5211     case CONST_INT:
5212     case CONST_DOUBLE:
5213     case CONST_STRING:
5214     case SYMBOL_REF:
5215     case LABEL_REF:
5216     case CONST:
5217     case PLUS:
5218       /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5219       add_const_value_attribute (die, rtl);
5220       break;
5221
5222     case MEM:
5223     case REG:
5224     case SUBREG:
5225       add_location_attribute (die, rtl);
5226       break;
5227
5228     default:
5229       abort ();                 /* Should never happen.  */
5230     }
5231 }
5232
5233 /* Generate an DW_AT_name attribute given some string value to be included as
5234    the value of the attribute.  */
5235 inline void
5236 add_name_attribute (die, name_string)
5237      register dw_die_ref die;
5238      register char *name_string;
5239 {
5240   if (name_string && *name_string)
5241     {
5242       add_AT_string (die, DW_AT_name, name_string);
5243     }
5244 }
5245
5246 /* Given a tree node describing an array bound (either lower or upper) output
5247    a representation for that bound.  */
5248 static void
5249 add_bound_info (subrange_die, bound_attr, bound)
5250      register dw_die_ref subrange_die;
5251      register enum dwarf_attribute bound_attr;
5252      register tree bound;
5253 {
5254   register dw_loc_descr_ref bound_loc = NULL;
5255   register unsigned bound_value = 0;
5256   switch (TREE_CODE (bound))
5257     {
5258     case ERROR_MARK:
5259       return;
5260
5261     /* All fixed-bounds are represented by INTEGER_CST nodes.        */
5262     case INTEGER_CST:
5263       bound_value = TREE_INT_CST_LOW (bound);
5264       /* TODO: we need to check for C language below, or some flag
5265          derived from the language.  C implies a lower bound of 0.   */
5266       if (!(bound_attr == DW_AT_lower_bound && bound_value == 0))
5267         {
5268           add_AT_unsigned (subrange_die, bound_attr, bound_value);
5269         }
5270       break;
5271
5272     /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5273        SAVE_EXPR nodes.  */
5274     case NOP_EXPR:
5275       bound = TREE_OPERAND (bound, 0);
5276       /* ... fall thru...  */
5277
5278     case SAVE_EXPR:
5279       /* If optimization is turned on, the SAVE_EXPRs that describe how to
5280          access the upper bound values are essentially bogus. They only
5281          describe (at best) how to get at these values at the points in the
5282          generated code right after they have just been computed.  Worse yet, 
5283          in the typical case, the upper bound values will not even *be*
5284          computed in the optimized code, so these SAVE_EXPRs are entirely
5285          bogus. In order to compensate for this fact, we check here to see if
5286          optimization is enabled, and if so, we effectively create an empty
5287          location description for the (unknown and unknowable) upper bound.
5288          This should not cause too much trouble for existing (stupid?)
5289          debuggers because they have to deal with empty upper bounds location
5290          descriptions anyway in order to be able to deal with incomplete array 
5291          types.  Of course an intelligent debugger (GDB?) should be able to
5292          comprehend that a missing upper bound specification in a array type
5293          used for a storage class `auto' local array variable indicates that
5294          the upper bound is both unknown (at compile- time) and unknowable (at
5295          run-time) due to optimization.  */
5296       if (!optimize)
5297         {
5298           bound_loc = mem_loc_descriptor (
5299                                       eliminate_regs (SAVE_EXPR_RTL (bound),
5300                                                       0, NULL_RTX));
5301         }
5302       else
5303         {
5304           bound_loc = NULL;
5305         }
5306       add_AT_loc (subrange_die, bound_attr, bound_loc);
5307       break;
5308
5309     default:
5310       abort ();
5311     }
5312 }
5313
5314 /* Note that the block of subscript information for an array type also
5315    includes information about the element type of type given array type.  */
5316 static void
5317 add_subscript_info (type_die, type)
5318      register dw_die_ref type_die;
5319      register tree type;
5320 {
5321   register unsigned dimension_number;
5322   register tree lower, upper;
5323   register dw_die_ref subrange_die;
5324
5325   /* The GNU compilers represent multidimensional array types as sequences of 
5326      one dimensional array types whose element types are themselves array
5327      types.  Here we squish that down, so that each multidimensional array
5328      type gets only one array_type DIE in the Dwarf debugging info. The draft 
5329      Dwarf specification say that we are allowed to do this kind of
5330      compression in C (because there is no difference between an array or
5331      arrays and a multidimensional array in C) but for other source languages 
5332      (e.g. Ada) we probably shouldn't do this.  */
5333   /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5334      const enum type.  E.g. const enum machine_mode insn_operand_mode[2][10].
5335      We work around this by disabling this feature.  See also
5336      gen_array_type_die.  */
5337 #ifndef MIPS_DEBUGGING_INFO
5338   for (dimension_number = 0;
5339        TREE_CODE (type) == ARRAY_TYPE;
5340        type = TREE_TYPE (type), dimension_number++)
5341     {
5342 #endif
5343       register tree domain = TYPE_DOMAIN (type);
5344
5345       /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5346          and (in GNU C only) variable bounds.  Handle all three forms 
5347          here.  */
5348       subrange_die = new_die (DW_TAG_subrange_type, type_die);
5349       if (domain)
5350         {
5351           /* We have an array type with specified bounds.  */
5352           lower = TYPE_MIN_VALUE (domain);
5353           upper = TYPE_MAX_VALUE (domain);
5354
5355           /* TODO: establish DW_AT_type for the basis type a byte_size
5356              attribute if the byte size is non-standard */
5357           add_bound_info (subrange_die, DW_AT_lower_bound, lower);
5358           add_bound_info (subrange_die, DW_AT_upper_bound, upper);
5359         }
5360       else
5361         {
5362           /* We have an array type with an unspecified length. For C and C++
5363              we can assume that this really means that (a) the index type is
5364              an integral type, and (b) the lower bound is zero. Note that
5365              Dwarf defines the representation of an unspecified (upper) bound 
5366              as being a zero-length location description.  */
5367
5368           /* define the (assumed) index type.  */
5369           add_AT_die_ref (subrange_die, DW_AT_type, int_base_type_die);
5370
5371           /* Add the (assumed) lower bound (constant) value.   */
5372           add_AT_unsigned (subrange_die, DW_AT_lower_bound, 0);
5373
5374           /* Add the (empty) location description for the upper bound.  */
5375           add_AT_loc (subrange_die, DW_AT_upper_bound, NULL);
5376         }
5377 #ifndef MIPS_DEBUGGING_INFO
5378     }
5379 #endif
5380 }
5381
5382 static void
5383 add_byte_size_attribute (die, tree_node)
5384      dw_die_ref die;
5385      register tree tree_node;
5386 {
5387   register unsigned size;
5388
5389   switch (TREE_CODE (tree_node))
5390     {
5391     case ERROR_MARK:
5392       size = 0;
5393       break;
5394     case ENUMERAL_TYPE:
5395     case RECORD_TYPE:
5396     case UNION_TYPE:
5397     case QUAL_UNION_TYPE:
5398       size = int_size_in_bytes (tree_node);
5399       break;
5400     case FIELD_DECL:
5401       /* For a data member of a struct or union, the DW_AT_byte_size is
5402          generally given as the number of bytes normally allocated for an
5403          object of the *declared* type of the member itself.  This is true
5404          even for bit-fields.  */
5405       size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
5406       break;
5407     default:
5408       abort ();
5409     }
5410
5411   /* Note that `size' might be -1 when we get to this point.  If it is, that
5412      indicates that the byte size of the entity in question is variable.  We
5413      have no good way of expressing this fact in Dwarf at the present time,
5414      so just let the -1 pass on through.  */
5415
5416   add_AT_unsigned (die, DW_AT_byte_size, size);
5417 }
5418
5419 /* For a FIELD_DECL node which represents a bit-field, output an attribute
5420    which specifies the distance in bits from the highest order bit of the
5421    "containing object" for the bit-field to the highest order bit of the
5422    bit-field itself.
5423
5424    For any given bit-field, the "containing object" is a hypothetical object (of
5425    some integral or enum type) within which the given bit-field lives.  The
5426    type of this hypothetical "containing object" is always the same as the
5427    declared type of the individual bit-field itself.
5428    The determination of the exact location of the "containing object" for a
5429    bit-field is rather complicated.  It's handled by the `field_byte_offset'
5430    function (above).
5431
5432    Note that it is the size (in bytes) of the hypothetical "containing object"
5433    which will be given in the DW_AT_byte_size attribute for this bit-field.
5434    (See `byte_size_attribute' above).  */
5435 inline void
5436 add_bit_offset_attribute (die, decl)
5437      register dw_die_ref die;
5438      register tree decl;
5439 {
5440   register unsigned object_offset_in_bytes = field_byte_offset (decl);
5441   register tree type = DECL_BIT_FIELD_TYPE (decl);
5442   register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
5443   register unsigned bitpos_int;
5444   register unsigned highest_order_object_bit_offset;
5445   register unsigned highest_order_field_bit_offset;
5446   register unsigned bit_offset;
5447
5448   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
5449   assert (type);                                /* Must be a bit field.  */
5450
5451   /* We can't yet handle bit-fields whose offsets are variable, so if we
5452      encounter such things, just return without generating any attribute
5453      whatsoever.  */
5454   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5455     {
5456       return;
5457     }
5458   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5459
5460   /* Note that the bit offset is always the distance (in bits) from the
5461      highest-order bit of the "containing object" to the highest-order bit of 
5462      the bit-field itself.  Since the "high-order end" of any object or field 
5463      is different on big-endian and little-endian machines, the computation
5464      below must take account of these differences.  */
5465   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
5466   highest_order_field_bit_offset = bitpos_int;
5467
5468   if (!BYTES_BIG_ENDIAN)
5469     {
5470       highest_order_field_bit_offset
5471         += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5472
5473       highest_order_object_bit_offset += simple_type_size_in_bits (type);
5474     }
5475   bit_offset =
5476     (!BYTES_BIG_ENDIAN
5477      ? highest_order_object_bit_offset - highest_order_field_bit_offset
5478      : highest_order_field_bit_offset - highest_order_object_bit_offset);
5479
5480   add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5481 }
5482
5483 /* For a FIELD_DECL node which represents a bit field, output an attribute
5484    which specifies the length in bits of the given field.  */
5485 inline void
5486 add_bit_size_attribute (die, decl)
5487      register dw_die_ref die;
5488      register tree decl;
5489 {
5490   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
5491   assert (DECL_BIT_FIELD_TYPE (decl));          /* Must be a bit field.  */
5492   add_AT_unsigned (die, DW_AT_bit_size,
5493                    (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
5494 }
5495
5496 inline void
5497 add_member_attribute (die, context)
5498      register dw_die_ref die;
5499      register tree context;
5500 {
5501   register dw_die_ref type_die;
5502
5503   /* Generate this attribute only for members in C++.  */
5504   if (context != NULL && is_tagged_type (context))
5505     {
5506       type_die = lookup_type_die (context);
5507       add_AT_die_ref (die, DW_AT_member, type_die);
5508     }
5509 }
5510
5511 /* If the compiled language is GNU C, then add a 'prototyped'
5512    attribute, if arg types are given for the parameters of a function.  */
5513 inline void
5514 add_prototyped_attribute (die, func_type)
5515      register dw_die_ref die;
5516      register tree func_type;
5517 {
5518   if ((strcmp (language_string, "GNU C") == 0)
5519       && (TYPE_ARG_TYPES (func_type) != NULL))
5520     {
5521       add_AT_flag (die, DW_AT_prototyped, 0);
5522     }
5523 }
5524
5525
5526 /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is found
5527    by looking in either the type declaration or object declaration
5528    equate table.  */
5529 inline void
5530 add_abstract_origin_attribute (die, origin)
5531      register dw_die_ref die;
5532      register tree origin;
5533 {
5534   dw_die_ref origin_die = NULL;
5535   if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
5536     {
5537       origin_die = lookup_decl_die (origin);
5538     }
5539   else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
5540     {
5541       origin_die = lookup_type_die (origin);
5542     }
5543   add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
5544 }
5545
5546 /* If the compiled source program is  C++, define the pure_virtual
5547    attribute.  */
5548 inline void
5549 add_pure_or_virtual_attribute (die, func_decl)
5550      register dw_die_ref die;
5551      register tree func_decl;
5552 {
5553   if (DECL_VIRTUAL_P (func_decl))
5554     {
5555       if ((strcmp (language_string, "GNU C++") == 0)
5556           && (DECL_VIRTUAL_P (func_decl)))
5557         {
5558           add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_pure_virtual);
5559         }
5560       else
5561         {
5562           add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
5563         }
5564     }
5565 }
5566 \f
5567 /********************* utility routines for DIEs *************************/
5568
5569 /* Add an DW_AT_name attribute and source coordinate attribute for the
5570    given decl, but only if it actually has a name.  */
5571 static void
5572 add_name_and_src_coords_attributes (die, decl)
5573      register dw_die_ref die;
5574      register tree decl;
5575 {
5576   register tree decl_name = DECL_NAME (decl);
5577   register unsigned file_index;
5578   if (decl_name && IDENTIFIER_POINTER (decl_name))
5579     {
5580       add_name_attribute (die, IDENTIFIER_POINTER (decl_name));
5581       file_index = lookup_filename (DECL_SOURCE_FILE (decl));
5582       add_AT_unsigned (die, DW_AT_decl_file, file_index);
5583       add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
5584     }
5585 }
5586
5587 /* Push a new declaration scope. */
5588 static void
5589 push_decl_scope (scope)
5590      tree scope;
5591 {
5592   /* Make room in the decl_scope_table, if necessary.  */
5593   if (decl_scope_table_allocated == decl_scope_depth)
5594     {
5595       decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
5596       decl_scope_table = (tree *) xrealloc (decl_scope_table,
5597                            decl_scope_table_allocated * sizeof (tree));
5598     }
5599   decl_scope_table[decl_scope_depth++] = scope;
5600 }
5601
5602 /* Return the DIE for the scope the immediately contains this declaration.  */
5603 static dw_die_ref
5604 scope_die_for_type (type, context_die)
5605     register tree type; 
5606     register dw_die_ref context_die;
5607 {
5608   register dw_die_ref scope_die = NULL;
5609   register tree containing_scope;
5610   register unsigned long i;
5611
5612   /* Walk back up the declaration tree looking for a place to define
5613      this type.  */
5614   containing_scope = TYPE_CONTEXT (type);
5615   if (containing_scope == NULL)
5616     {
5617       scope_die = comp_unit_die;
5618     }
5619   else
5620     {
5621       for (i = decl_scope_depth - 1, scope_die = context_die;
5622            i >= 0
5623            && scope_die != NULL
5624            && decl_scope_table[i] != containing_scope;
5625            --i, scope_die = scope_die->die_parent)
5626         {
5627           /* nothing */ ;
5628         }
5629       if (scope_die == NULL)
5630         {
5631           scope_die = context_die;
5632         }
5633     }
5634   return scope_die;
5635 }
5636
5637 /* Pop a declaration scope.  */
5638 inline void
5639 pop_decl_scope ()
5640 {
5641   assert (decl_scope_depth > 0);
5642   --decl_scope_depth;
5643 }
5644
5645 /* Many forms of DIEs require a "type description" attribute.  This
5646    routine locates the proper "type descriptor" die for the type given
5647    by 'type', and adds an DW_AT_type attribute below the given die.  */
5648 static void
5649 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
5650      register dw_die_ref object_die;
5651      register tree type;
5652      register int decl_const;
5653      register int decl_volatile;
5654      register dw_die_ref context_die;
5655 {
5656   register enum tree_code code  = TREE_CODE (type);
5657   register dw_die_ref scope_die = NULL;
5658   register dw_die_ref type_die  = NULL;
5659
5660   if (code == ERROR_MARK)
5661     {
5662       return;
5663     }
5664
5665   /* Handle a special case.  For functions whose return type is void, we
5666      generate *no* type attribute.  (Note that no object may have type
5667      `void', so this only applies to function return types).  */
5668   if (code == VOID_TYPE)
5669     {
5670       return;
5671     }
5672
5673   scope_die = scope_die_for_type (type, context_die);
5674   type_die = modified_type_die (type,
5675                                 decl_const || TYPE_READONLY (type),
5676                                 decl_volatile || TYPE_VOLATILE (type),
5677                                 scope_die);
5678   if (type_die != NULL)
5679     {
5680       add_AT_die_ref (object_die, DW_AT_type, type_die);
5681     }
5682 }
5683
5684 /* Given a tree pointer to a struct, class, union, or enum type node, return
5685    a pointer to the (string) tag name for the given type, or zero if the type
5686    was declared without a tag.  */
5687 static char *
5688 type_tag (type)
5689      register tree type;
5690 {
5691   register char *name = 0;
5692
5693   if (TYPE_NAME (type) != 0)
5694     {
5695       register tree t = 0;
5696
5697       /* Find the IDENTIFIER_NODE for the type name.  */
5698       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
5699         t = TYPE_NAME (type);
5700 #if 0
5701       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to 
5702          a TYPE_DECL node, regardless of whether or not a `typedef' was
5703          involved.  This is distinctly different from what the gcc front-end
5704          does.  It always makes the TYPE_NAME for each tagged type be either
5705          NULL (signifying an anonymous tagged type) or else a pointer to an
5706          IDENTIFIER_NODE.  Obviously, we would like to generate correct Dwarf 
5707          for both C and C++, but given this inconsistency in the TREE
5708          representation of tagged types for C and C++ in the GNU front-ends,
5709          we cannot support both languages correctly unless we introduce some
5710          front-end specific code here, and rms objects to that, so we can
5711          only generate correct Dwarf for one of these two languages.  C is
5712          more important, so for now we'll do the right thing for C and let
5713          g++ go fish.  */
5714       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
5715         t = DECL_NAME (TYPE_NAME (type));
5716 #endif
5717       /* Now get the name as a string, or invent one.  */
5718       if (t != 0)
5719         {
5720           name = IDENTIFIER_POINTER (t);
5721         }
5722     }
5723   return (name == 0 || *name == '\0') ? 0 : name;
5724 }
5725
5726 /* Return the type associated with a data member, make a special check
5727    for bit field types.  */
5728 inline tree
5729 member_declared_type (member)
5730      register tree member;
5731 {
5732   return (DECL_BIT_FIELD_TYPE (member))
5733     ? DECL_BIT_FIELD_TYPE (member)
5734     : TREE_TYPE (member);
5735 }
5736
5737 /* Get the function's label, as described by its RTL. This may be different
5738    from the DECL_NAME name used in the source file.  */
5739 static char *
5740 function_start_label (decl)
5741      register tree decl;
5742 {
5743   rtx x;
5744   char *fnname;
5745   x = DECL_RTL (decl);
5746   if (GET_CODE (x) != MEM)
5747     {
5748       abort ();
5749     }
5750   x = XEXP (x, 0);
5751   if (GET_CODE (x) != SYMBOL_REF)
5752     {
5753       abort ();
5754     }
5755   fnname = XSTR (x, 0);
5756   return fnname;
5757 }
5758 \f
5759 /******************************* DIE Generation *************************/
5760
5761 /* These routines generate the internnal representation of the DIE's for
5762    the compilation unit.  Debugging information is collected by walking
5763    the declaration trees passed in from dwarfout_file_scope_decl().  */
5764
5765 static void
5766 gen_array_type_die (type, context_die)
5767      register tree type;
5768      register dw_die_ref context_die;
5769 {
5770   register dw_die_ref scope_die = scope_die_for_type (type, context_die);
5771   register dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die);
5772   register tree element_type;
5773   /* TODO: why a member_attribute under an array?
5774      member_attribute (array_die, TYPE_CONTEXT (type)); */
5775 #if 0
5776   /* We default the array ordering.  SDB will probably do
5777      the right things even if DW_AT_ordering is not present.  It's not even
5778      an issue until we start to get into multidimensional arrays anyway.  If
5779      SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
5780      then we'll have to put the DW_AT_ordering attribute back in.  (But if
5781      and when we find out that we need to put these in, we will only do so
5782      for multidimensional arrays.  */
5783   add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
5784 #endif
5785
5786   add_subscript_info (array_die, type);
5787
5788   equate_type_number_to_die (type, array_die);
5789
5790   /* Add representation of the type of the elements of this array type.  */
5791   element_type = TREE_TYPE (type);
5792   /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5793      const enum type.  E.g. const enum machine_mode insn_operand_mode[2][10].
5794      We work around this by disabling this feature.  See also
5795      add_subscript_info.  */
5796 #ifndef MIPS_DEBUGGING_INFO
5797   while (TREE_CODE (element_type) == ARRAY_TYPE)
5798     {
5799       element_type = TREE_TYPE (element_type);
5800     }
5801 #endif
5802   gen_type_die (element_type, context_die);
5803
5804   add_type_attribute (array_die, element_type, 0, 0, context_die);
5805 }
5806
5807 static void
5808 gen_set_type_die (type, context_die)
5809      register tree type;
5810      register dw_die_ref context_die;
5811 {
5812   register dw_die_ref type_die;
5813   type_die = new_die (DW_TAG_set_type, scope_die_for_type (type, context_die));
5814   equate_type_number_to_die (type, type_die);
5815   add_member_attribute (type_die, TYPE_CONTEXT (type));
5816   add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
5817 }
5818
5819 static void
5820 gen_entry_point_die (decl, context_die)
5821      register tree decl;
5822      register dw_die_ref context_die;
5823 {
5824   register tree origin = decl_ultimate_origin (decl);
5825   register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
5826   if (origin != NULL)
5827     {
5828       add_abstract_origin_attribute (decl_die, origin);
5829     }
5830   else
5831     {
5832       add_name_and_src_coords_attributes (decl_die, decl);
5833       add_member_attribute (decl_die, DECL_CONTEXT (decl));
5834       add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
5835                           0, 0, context_die);
5836     }
5837   if (DECL_ABSTRACT (decl))
5838     {
5839       equate_decl_number_to_die (decl, decl_die);
5840     }
5841   else
5842     {
5843       add_AT_lbl_id (decl_die, DW_AT_low_pc, function_start_label (decl));
5844     }
5845 }
5846
5847 /* Generate a DIE to represent an inlined instance of an enumeration type.  */
5848 static void
5849 gen_inlined_enumeration_type_die (type, context_die)
5850      register tree type;
5851      register dw_die_ref context_die;
5852 {
5853   register dw_die_ref type_die;
5854   type_die = new_die (DW_TAG_enumeration_type,
5855                       scope_die_for_type (type, context_die));
5856   assert (TREE_ASM_WRITTEN (type));
5857   add_abstract_origin_attribute (type_die, type);
5858 }
5859
5860 /* Generate a DIE to represent an inlined instance of a structure type.  */
5861 static void
5862 gen_inlined_structure_type_die (type, context_die)
5863      register tree type;
5864      register dw_die_ref context_die;
5865 {
5866   register dw_die_ref type_die;
5867   type_die = new_die (DW_TAG_structure_type,
5868                       scope_die_for_type (type, context_die));
5869   assert (TREE_ASM_WRITTEN (type));
5870   add_abstract_origin_attribute (type_die, type);
5871 }
5872
5873 /* Generate a DIE to represent an inlined instance of a union type.  */
5874 static void
5875 gen_inlined_union_type_die (type, context_die)
5876      register tree type;
5877      register dw_die_ref context_die;
5878 {
5879   register dw_die_ref type_die;
5880   type_die = new_die (DW_TAG_union_type,
5881                       scope_die_for_type (type, context_die));
5882   assert (TREE_ASM_WRITTEN (type));
5883   add_abstract_origin_attribute (type_die, type);
5884 }
5885
5886 /* Generate a DIE to represent an enumeration type.  Note that these DIEs
5887    include all of the information about the enumeration values also. Each
5888    enumerated type name/value is listed as a child of the enumerated type DIE */
5889 static void
5890 gen_enumeration_type_die (type, is_complete, context_die)
5891      register tree type;
5892      register unsigned is_complete;
5893      register dw_die_ref context_die;
5894 {
5895   register dw_die_ref type_die;
5896   register dw_die_ref enum_die;
5897   register tree link;
5898   type_die = lookup_type_die (type);
5899   if (type_die == NULL)
5900     {
5901       type_die = new_die (DW_TAG_enumeration_type,
5902                           scope_die_for_type (type, context_die));
5903       equate_type_number_to_die (type, type_die);
5904       add_name_attribute (type_die, type_tag (type));
5905       add_member_attribute (type_die, TYPE_CONTEXT (type));
5906     }
5907   if (is_complete)
5908     {
5909       /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
5910          given enum type is incomplete, do not generate the DW_AT_byte_size
5911          attribute or the DW_AT_element_list attribute.  */
5912       if (TYPE_SIZE (type))
5913         {
5914           add_byte_size_attribute (type_die, type);
5915           for (link = TYPE_FIELDS (type);
5916                link != NULL; link = TREE_CHAIN (link))
5917             {
5918               enum_die = new_die (DW_TAG_enumerator, type_die);
5919               add_name_attribute (enum_die,
5920                                   IDENTIFIER_POINTER (TREE_PURPOSE (link)));
5921               add_AT_unsigned (enum_die, DW_AT_const_value,
5922                            (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
5923             }
5924         }
5925     }
5926 }
5927
5928
5929 /* Generate a DIE to represent either a real live formal parameter decl or to
5930    represent just the type of some formal parameter position in some function
5931    type.
5932    Note that this routine is a bit unusual because its argument may be a
5933    ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
5934    represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
5935    node.  If it's the former then this function is being called to output a
5936    DIE to represent a formal parameter object (or some inlining thereof).  If
5937    it's the latter, then this function is only being called to output a
5938    DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
5939    argument type of some subprogram type.  */
5940 static void
5941 gen_formal_parameter_die (node, context_die)
5942      register tree node;
5943      register dw_die_ref context_die;
5944 {
5945   register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter,
5946                                           context_die);
5947   register tree origin;
5948   switch (TREE_CODE_CLASS (TREE_CODE (node)))
5949     {
5950       /* We were called with some kind of a ..._DECL node.  */
5951     case 'd':
5952       origin = decl_ultimate_origin (node);
5953       if (origin != NULL)
5954         {
5955           add_abstract_origin_attribute (parm_die, origin);
5956         }
5957       else
5958         {
5959           add_name_and_src_coords_attributes (parm_die, node);
5960           add_type_attribute (parm_die, TREE_TYPE (node),
5961                               TREE_READONLY (node),
5962                               TREE_THIS_VOLATILE (node),
5963                               context_die);
5964         }
5965       if (DECL_ABSTRACT (node))
5966         {
5967           equate_decl_number_to_die (node, parm_die);
5968         }
5969       else
5970         {
5971           add_location_or_const_value_attribute (parm_die, node);
5972         }
5973       break;
5974
5975       /* We were called with some kind of a ..._TYPE node.  */
5976     case 't':
5977       add_type_attribute (parm_die, node, 0, 0, context_die);
5978       break;
5979
5980       /* Should never happen.  */
5981     default:
5982       abort ();
5983     }
5984 }
5985
5986 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
5987    at the end of an (ANSI prototyped) formal parameters list.  */
5988 static void
5989 gen_unspecified_parameters_die (decl_or_type, context_die)
5990      register tree decl_or_type;
5991      register dw_die_ref context_die;
5992 {
5993   register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
5994                                           context_die);
5995   /* This kludge is here only for the sake of being compatible with what the
5996      USL CI5 C compiler does.  The specification of Dwarf Version 1 doesn't
5997      say that DW_TAG_unspecified_parameters DIEs should contain any
5998      attributes other than the DW_AT_sibling attribute, but they are
5999      certainly allowed to contain additional attributes, and the CI5 compiler 
6000      generates DW_AT_name, DW_AT_base_type, and DW_AT_location attributes
6001      within DW_TAG_unspecified_parameters DIEs which appear in the child
6002      lists for DIEs representing function definitions, so we do likewise
6003      here.  */
6004   if (TREE_CODE (decl_or_type) == FUNCTION_DECL
6005       && DECL_INITIAL (decl_or_type))
6006     {
6007       add_name_attribute (parm_die, "...");
6008       add_AT_die_ref (parm_die, DW_AT_type, int_base_type_die);
6009     }
6010 }
6011
6012 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6013    DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6014    parameters as specified in some function type specification (except for
6015    those which appear as part of a function *definition*).
6016    Note that we must be careful here to output all of the parameter DIEs before*
6017    we output any DIEs needed to represent the types of the formal parameters.
6018    This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6019    non-parameter DIE it sees ends the formal parameter list.  */
6020 static void
6021 gen_formal_types_die (function_or_method_type, context_die)
6022      register tree function_or_method_type;
6023      register dw_die_ref context_die;
6024 {
6025   register tree link;
6026   register tree formal_type = NULL;
6027   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6028
6029   /* In the case where we are generating a formal types list for a C++
6030      non-static member function type, skip over the first thing on the
6031      TYPE_ARG_TYPES list because it only represents the type of the hidden
6032      `this pointer'.  The debugger should be able to figure out (without
6033      being explicitly told) that this non-static member function type takes a 
6034      `this pointer' and should be able to figure what the type of that hidden 
6035      parameter is from the DW_AT_member attribute of the parent
6036      DW_TAG_subroutine_type DIE.  */
6037   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
6038     first_parm_type = TREE_CHAIN (first_parm_type);
6039
6040   /* Make our first pass over the list of formal parameter types and output a 
6041      DW_TAG_formal_parameter DIE for each one.  */
6042   for (link = first_parm_type; link; link = TREE_CHAIN (link))
6043     {
6044       formal_type = TREE_VALUE (link);
6045       if (formal_type == void_type_node)
6046         break;
6047
6048       /* Output a (nameless) DIE to represent the formal parameter itself.  */
6049       gen_formal_parameter_die (formal_type, context_die);
6050     }
6051
6052   /* If this function type has an ellipsis, add a
6053      DW_TAG_unspecified_parameters DIE to the end of the parameter list.  */
6054   if (formal_type != void_type_node)
6055     gen_unspecified_parameters_die (function_or_method_type, context_die);
6056
6057   /* Make our second (and final) pass over the list of formal parameter types 
6058      and output DIEs to represent those types (as necessary).  */
6059   for (link = TYPE_ARG_TYPES (function_or_method_type);
6060        link;
6061        link = TREE_CHAIN (link))
6062     {
6063       formal_type = TREE_VALUE (link);
6064       if (formal_type == void_type_node)
6065         break;
6066
6067       gen_type_die (formal_type, function_or_method_type, context_die);
6068     }
6069 }
6070
6071 /* Generate a DIE to represent a declared function (either file-scope or
6072    block-local).  */
6073 static void
6074 gen_subprogram_die (decl, context_die)
6075      register tree decl;
6076      register dw_die_ref context_die;
6077 {
6078   char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6079   register tree origin = decl_ultimate_origin (decl);
6080   register dw_die_ref subr_die = new_die (DW_TAG_subprogram, context_die);
6081   register dw_loc_descr_ref fp_loc = NULL;
6082   register unsigned fp_reg;
6083   register tree type;
6084   register tree fn_arg_types;
6085   register tree outer_scope;
6086   register tree label;
6087
6088   if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
6089     {
6090       add_AT_flag (subr_die, DW_AT_external, 1);
6091     }
6092   if (origin != NULL)
6093     {
6094       add_abstract_origin_attribute (subr_die, origin);
6095     }
6096   else
6097     {
6098       type = TREE_TYPE (decl);
6099       add_name_and_src_coords_attributes (subr_die, decl);
6100       if (DECL_INLINE (decl))
6101         {
6102           add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6103         }
6104       add_prototyped_attribute (subr_die, type);
6105       add_member_attribute (subr_die, DECL_CONTEXT (decl));
6106       add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6107       add_pure_or_virtual_attribute (subr_die, decl);
6108     }
6109   if (DECL_ABSTRACT (decl))
6110     {
6111       equate_decl_number_to_die (decl, subr_die);
6112     }
6113   else if (!DECL_EXTERNAL (decl))
6114     {
6115       equate_decl_number_to_die (decl, subr_die);
6116       add_AT_lbl_id (subr_die, DW_AT_low_pc, function_start_label (decl));
6117       sprintf (label_id, FUNC_END_LABEL_FMT, current_funcdef_number);
6118       add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6119
6120 #ifdef MIPS_DEBUGGING_INFO
6121
6122       /* Add a reference to the FDE for this routine.  */
6123       add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
6124 #endif
6125
6126       /* Define the frame pointer location for this routine.  */
6127       fp_reg = (frame_pointer_needed) ? FRAME_POINTER_REGNUM
6128                                       : STACK_POINTER_REGNUM;
6129       assert (fp_reg >= 0 && fp_reg <= 31);
6130       fp_loc = new_loc_descr (DW_OP_breg0 + fp_reg, current_funcdef_frame_size);
6131       add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6132
6133 #ifdef DWARF_GNU_EXTENSIONS
6134       sprintf (label_id, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
6135       add_AT_lbl_id (subr_die, DW_AT_body_begin, label_id);
6136       sprintf (label_id, BODY_END_LABEL_FMT, current_funcdef_number);
6137       add_AT_lbl_id (subr_die, DW_AT_body_end, label_id);
6138 #endif
6139
6140     }
6141
6142   /* Now output descriptions of the arguments for this function. This gets
6143      (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list 
6144      for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6145      `...' at the end of the formal parameter list.  In order to find out if
6146      there was a trailing ellipsis or not, we must instead look at the type
6147      associated with the FUNCTION_DECL.  This will be a node of type
6148      FUNCTION_TYPE. If the chain of type nodes hanging off of this
6149      FUNCTION_TYPE node ends with a void_type_node then there should *not* be 
6150      an ellipsis at the end.  */
6151
6152   /* In the case where we are describing a mere function declaration, all we
6153      need to do here (and all we *can* do here) is to describe the *types* of 
6154      its formal parameters.  */
6155   if (DECL_INITIAL (decl) == NULL_TREE)
6156     {
6157       gen_formal_types_die (TREE_TYPE (decl), subr_die);
6158     }
6159   else
6160     {
6161       /* Generate DIEs to represent all known formal parameters */
6162       register tree arg_decls = DECL_ARGUMENTS (decl);
6163       register tree parm;
6164
6165       /* When generating DIEs, generate the unspecified_parameters DIE
6166          instead if we come across the arg "__builtin_va_alist" */
6167       for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
6168         {
6169           if (TREE_CODE (parm) == PARM_DECL)
6170             {
6171               if (DECL_NAME (parm) &&
6172                   !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6173                            "__builtin_va_alist"))
6174                 {
6175                   gen_unspecified_parameters_die (parm, subr_die);
6176                 }
6177               else
6178                 {
6179                   gen_decl_die (parm, subr_die);
6180                 }
6181             }
6182         }
6183
6184       /* Decide whether we need a unspecified_parameters DIE at the end.
6185          There are 2 more cases to do this for: 1) the ansi ... declaration - 
6186          this is detectable when the end of the arg list is not a
6187          void_type_node 2) an unprototyped function declaration (not a
6188          definition).  This just means that we have no info about the
6189          parameters at all.  */
6190       fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
6191       if (fn_arg_types)
6192         {
6193           /* this is the prototyped case, check for ...  */
6194           if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6195             {
6196               gen_unspecified_parameters_die (decl, subr_die);
6197             }
6198         }
6199       else
6200         {
6201           /* this is unprotoyped, check for undefined (just declaration) */
6202           if (!DECL_INITIAL (decl))
6203             {
6204               gen_unspecified_parameters_die (decl, subr_die);
6205             }
6206         }
6207     }
6208
6209   /* Output Dwarf info for all of the stuff within the body of the function
6210      (if it has one - it may be just a declaration).  */
6211   outer_scope = DECL_INITIAL (decl);
6212
6213   if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
6214     {
6215       /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6216          node created to represent a function. This outermost BLOCK actually
6217          represents the outermost binding contour for the function, i.e. the
6218          contour in which the function's formal parameters and labels get
6219          declared. Curiously, it appears that the front end doesn't actually
6220          put the PARM_DECL nodes for the current function onto the BLOCK_VARS 
6221          list for this outer scope.  (They are strung off of the
6222          DECL_ARGUMENTS list for the function instead.) The BLOCK_VARS list
6223          for the `outer_scope' does provide us with a list of the LABEL_DECL
6224          nodes for the function however, and we output DWARF info for those
6225          here. Just within the `outer_scope' there will be another BLOCK node
6226          representing the function's outermost pair of curly braces.  We
6227          musn't generate a lexical_block DIE for this outermost pair of curly
6228          braces because that is not really an independent scope according to
6229          ANSI C rules.  Rather, it is the same scope in which the parameters
6230          were declared.  */
6231       for (label = BLOCK_VARS (outer_scope);
6232            label;
6233            label = TREE_CHAIN (label))
6234         {
6235           gen_decl_die (label, subr_die);
6236         }
6237
6238       /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a list of
6239          BLOCK nodes which is always only one element long. That one element
6240          represents the outermost pair of curley braces for the function
6241          body.  */
6242       decls_for_scope (BLOCK_SUBBLOCKS (outer_scope), subr_die);
6243     }
6244 }
6245
6246 /* Generate a DIE to represent a declared data object.  */
6247 static void
6248 gen_variable_die (decl, context_die)
6249      register tree decl;
6250      register dw_die_ref context_die;
6251 {
6252   register tree origin = decl_ultimate_origin (decl);
6253   register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
6254   if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
6255     {
6256       add_AT_flag (var_die, DW_AT_external, 1);
6257     }
6258   if (origin != NULL)
6259     {
6260       add_abstract_origin_attribute (var_die, origin);
6261     }
6262   else
6263     {
6264       add_name_and_src_coords_attributes (var_die, decl);
6265       add_member_attribute (var_die, DECL_CONTEXT (decl));
6266       add_type_attribute (var_die, TREE_TYPE (decl),
6267                           TREE_READONLY (decl),
6268                           TREE_THIS_VOLATILE (decl), context_die);
6269     }
6270   if (DECL_ABSTRACT (decl))
6271     {
6272       equate_decl_number_to_die (decl, var_die);
6273     }
6274   else if (!DECL_EXTERNAL (decl))
6275     {
6276       add_location_or_const_value_attribute (var_die, decl);
6277     }
6278 }
6279
6280 /* Generate a DIE to represent a label identifier.  */
6281 static void
6282 gen_label_die (decl, context_die)
6283      register tree decl;
6284      register dw_die_ref context_die;
6285 {
6286   register tree origin = decl_ultimate_origin (decl);
6287   register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
6288   register rtx insn;
6289   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6290   if (origin != NULL)
6291     {
6292       add_abstract_origin_attribute (lbl_die, origin);
6293     }
6294   else
6295     {
6296       add_name_and_src_coords_attributes (lbl_die, decl);
6297     }
6298   if (DECL_ABSTRACT (decl))
6299     {
6300       equate_decl_number_to_die (decl, lbl_die);
6301     }
6302   else
6303     {
6304       insn = DECL_RTL (decl);
6305       if (GET_CODE (insn) == CODE_LABEL)
6306         {
6307           /* When optimization is enabled (via -O) some parts of the compiler 
6308              (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which 
6309              represent source-level labels which were explicitly declared by
6310              the user.  This really shouldn't be happening though, so catch
6311              it if it ever does happen.  */
6312           if (INSN_DELETED_P (insn))
6313             {
6314               abort ();         /* Should never happen.  */
6315             }
6316           sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
6317                    (unsigned) INSN_UID (insn));
6318           add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
6319         }
6320     }
6321 }
6322
6323 /* Generate a DIE for a lexical block.  */
6324 static void
6325 gen_lexical_block_die (stmt, context_die)
6326      register tree stmt;
6327      register dw_die_ref context_die;
6328 {
6329   register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
6330   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6331   if (!BLOCK_ABSTRACT (stmt))
6332     {
6333       sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6334       add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
6335       sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6336       add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
6337     }
6338   decls_for_scope (stmt, stmt_die);
6339 }
6340
6341 /* Generate a DIE for an inlined subprogram.  */
6342 static void
6343 gen_inlined_subroutine_die (stmt, context_die)
6344      register tree stmt;
6345      register dw_die_ref context_die;
6346 {
6347   register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
6348                                           context_die);
6349   char label[MAX_ARTIFICIAL_LABEL_BYTES];
6350   add_abstract_origin_attribute (subr_die, block_ultimate_origin (stmt));
6351   if (!BLOCK_ABSTRACT (stmt))
6352     {
6353       sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6354       add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
6355       sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6356       add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
6357     }
6358   decls_for_scope (stmt, subr_die);
6359 }
6360
6361 /* Generate a DIE for a field in a record, or structure.  */
6362 static void
6363 gen_field_die (decl, context_die)
6364      register tree decl;
6365      register dw_die_ref context_die;
6366 {
6367   register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
6368   add_name_and_src_coords_attributes (decl_die, decl);
6369   add_member_attribute (decl_die, DECL_CONTEXT (decl));
6370   add_type_attribute (decl_die, member_declared_type (decl),
6371                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
6372                       context_die);
6373   /* If this is a bit field...  */
6374   if (DECL_BIT_FIELD_TYPE (decl))
6375     {
6376       add_byte_size_attribute (decl_die, decl);
6377       add_bit_size_attribute (decl_die, decl);
6378       add_bit_offset_attribute (decl_die, decl);
6379     }
6380   add_data_member_location_attribute (decl_die, decl);
6381 }
6382
6383 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6384    Use modified type DIE's instead.
6385    We keep this code here just in case these types of DIEs may be needed to
6386    represent certain things in other languages (e.g. Pascal) someday.  */
6387 static void
6388 gen_pointer_type_die (type, context_die)
6389      register tree type;
6390      register dw_die_ref context_die;
6391 {
6392   register dw_die_ref ptr_die = new_die (DW_TAG_pointer_type, context_die);
6393   equate_type_number_to_die (type, ptr_die);
6394   add_member_attribute (ptr_die, TYPE_CONTEXT (type));
6395   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6396 }
6397
6398 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6399    Use modified type DIE's instead.
6400    We keep this code here just in case these types of DIEs may be needed to
6401    represent certain things in other languages (e.g. Pascal) someday.  */
6402 static void
6403 gen_reference_type_die (type, context_die)
6404      register tree type;
6405      register dw_die_ref context_die;
6406 {
6407   register dw_die_ref ref_die = new_die (DW_TAG_reference_type, context_die);
6408   equate_type_number_to_die (type, ref_die);
6409   add_member_attribute (ref_die, TYPE_CONTEXT (type));
6410   add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
6411 }
6412
6413 /* Generate a DIE for a pointer to a member type.  */
6414 static void
6415 gen_ptr_to_mbr_type_die (type, context_die)
6416      register tree type;
6417      register dw_die_ref context_die;
6418 {
6419   register dw_die_ref ptr_die = new_die (DW_TAG_ptr_to_member_type,
6420                                          context_die);
6421   equate_type_number_to_die (type, ptr_die);
6422   add_member_attribute (ptr_die, TYPE_CONTEXT (type));
6423   add_AT_die_ref (ptr_die, DW_AT_containing_type,
6424               lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
6425   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6426 }
6427
6428 /* Generate the DIE for the compilation unit.  */
6429 static void
6430 gen_compile_unit_die (main_input_filename)
6431      register char *main_input_filename;
6432 {
6433   char producer[250];
6434   char full_src_name[1024];
6435   char *wd = getpwd ();
6436
6437   comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
6438
6439   /* MIPS/SGI requires the full pathname of the input file.  */
6440   if (main_input_filename[0] == '/')
6441     {
6442       add_name_attribute (comp_unit_die, main_input_filename);
6443     }
6444   else
6445     {
6446       sprintf (full_src_name, "%s/%s", wd, main_input_filename);
6447       add_name_attribute (comp_unit_die, full_src_name);
6448     }
6449
6450   sprintf (producer, "%s %s", language_string, version_string);
6451
6452 #ifdef MIPS_DEBUGGING_INFO
6453   /* The MIPS/SGI compilers place the 'cc' command line options in the producer
6454      string.  The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
6455      not appear in the producer string, the debugger reaches the conclusion
6456      that the object file is stripped and has no debugging information.
6457      To get the MIPS/SGI debugger to believe that there is debugging
6458      information in the object file, we add a -g to the producer string.  */
6459   if (write_symbols != NO_DEBUG)
6460     {
6461        strcpy (producer, " -g");
6462     }
6463
6464 #endif
6465
6466   add_AT_string (comp_unit_die, DW_AT_producer, producer);
6467   if (strcmp (language_string, "GNU C++") == 0)
6468     {
6469       add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
6470     }
6471   else if (strcmp (language_string, "GNU Ada") == 0)
6472     {
6473       add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
6474     }
6475   else if (flag_traditional)
6476     {
6477       add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
6478     }
6479   else
6480     {
6481       add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
6482     }
6483   add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_BEGIN_LABEL);
6484   add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, TEXT_END_LABEL);
6485   if (wd)
6486     {
6487       add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
6488     }
6489   if (debug_info_level >= DINFO_LEVEL_NORMAL)
6490     {
6491       add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
6492       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6493         {
6494           add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
6495         }
6496     }
6497 }
6498
6499 /* Generate a DIE for a string type.  */
6500 static void
6501 gen_string_type_die (type, context_die)
6502      register tree type;
6503      register dw_die_ref context_die;
6504 {
6505   register dw_die_ref type_die;
6506   type_die = new_die (DW_TAG_string_type,
6507                       scope_die_for_type (type, context_die));
6508   add_member_attribute (type_die, TYPE_CONTEXT (type));
6509
6510   /* Fudge the string length attribute for now.  */
6511
6512   /* TODO: add string length info.
6513      string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6514                               bound_representation (upper_bound, 0, 'u'); */
6515 }
6516
6517 /* Genearate a DIE for a class member.  */
6518 static void
6519 gen_member_die (type, context_die)
6520      register tree type;
6521      register dw_die_ref context_die;
6522 {
6523   register tree normal_member;
6524   register tree vec_base;
6525   register tree first_func_member;
6526   register tree func_member;
6527   /* If this is not an incomplete type, output descriptions of each of its
6528      members. Note that as we output the DIEs necessary to represent the
6529      members of this record or union type, we will also be trying to output
6530      DIEs to represent the *types* of those members. However the `type'
6531      function (above) will specifically avoid generating type DIEs for member 
6532      types *within* the list of member DIEs for this (containing) type execpt 
6533      for those types (of members) which are explicitly marked as also being
6534      members of this (containing) type themselves.  The g++ front- end can
6535      force any given type to be treated as a member of some other
6536      (containing) type by setting the TYPE_CONTEXT of the given (member) type 
6537      to point to the TREE node representing the appropriate (containing)
6538      type.  */
6539
6540   /* First output info about the data members and type members.  */
6541   for (normal_member = TYPE_FIELDS (type);
6542        normal_member;
6543        normal_member = TREE_CHAIN (normal_member))
6544     {
6545       gen_decl_die (normal_member, context_die);
6546     }
6547
6548   /* Now output info about the function members (if any).  */
6549   vec_base = TYPE_METHODS (type);
6550   if (vec_base)
6551     {
6552       first_func_member = TREE_VEC_ELT (vec_base, 0);
6553       /* This isn't documented, but the first element of the vector of member 
6554          functions can be NULL in cases where the class type in question
6555          didn't have either a constructor or a destructor declared for it.
6556          We have to make allowances for that here.  */
6557       if (first_func_member == NULL)
6558         {
6559           first_func_member = TREE_VEC_ELT (vec_base, 1);
6560         }
6561
6562       for (func_member = first_func_member;
6563            func_member;
6564            func_member = TREE_CHAIN (func_member))
6565         {
6566           gen_decl_die (func_member, context_die);
6567         }
6568     }
6569 }
6570
6571 /* Generate a DIE for a structure or union type.  */
6572 static void
6573 gen_struct_or_union_type_die (type, is_complete, context_die)
6574      register tree type;
6575      register unsigned is_complete;
6576      register dw_die_ref context_die;
6577 {
6578   register dw_die_ref type_die;
6579   type_die = lookup_type_die (type);
6580   if (type_die == NULL)
6581     {
6582       type_die = new_die (TREE_CODE (type) == RECORD_TYPE
6583                           ? DW_TAG_structure_type : DW_TAG_union_type,
6584                           scope_die_for_type (type, context_die));
6585       equate_type_number_to_die (type, type_die);
6586       add_name_attribute (type_die, type_tag (type));
6587       add_member_attribute (type_die, TYPE_CONTEXT (type));
6588     }
6589
6590   /* If this type has been completed, then give it a byte_size attribute and
6591      then give a list of members.  */
6592   if (is_complete)
6593     {
6594       /* Prevent infinite recursion in cases where the type of some member of 
6595          this type is expressed in terms of this type itself.  */
6596       TREE_ASM_WRITTEN (type) = 1;
6597       if (TYPE_SIZE (type))
6598         {
6599           add_byte_size_attribute (type_die, type);
6600           gen_member_die (type, type_die);
6601         }
6602     }
6603 }
6604
6605 /* Generate a DIE for a subroutine _type_.  */
6606 static void
6607 gen_subroutine_type_die (type, context_die)
6608      register tree type;
6609      register dw_die_ref context_die;
6610 {
6611   register tree return_type = TREE_TYPE (type);
6612   register dw_die_ref subr_die = new_die (DW_TAG_subroutine_type, context_die);
6613   equate_type_number_to_die (type, subr_die);
6614   add_prototyped_attribute (subr_die, type);
6615   add_member_attribute (subr_die, TYPE_CONTEXT (type));
6616   add_type_attribute (subr_die, return_type, 0, 0, context_die);
6617   gen_formal_types_die (type, context_die);
6618 }
6619
6620 /* Generate a DIE for a type definition */
6621 static void
6622 gen_typedef_die (decl, context_die)
6623      register tree decl;
6624      register dw_die_ref context_die;
6625 {
6626   register tree origin = decl_ultimate_origin (decl);
6627   register dw_die_ref type_die;
6628   type_die = new_die (DW_TAG_typedef,
6629                       scope_die_for_type (decl, context_die));
6630   if (origin != NULL)
6631     {
6632       add_abstract_origin_attribute (type_die, origin);
6633     }
6634   else
6635     {
6636       add_name_and_src_coords_attributes (type_die, decl);
6637       add_member_attribute (type_die, DECL_CONTEXT (decl));
6638       add_type_attribute (type_die, TREE_TYPE (decl),
6639                           TREE_READONLY (decl),
6640                           TREE_THIS_VOLATILE (decl),
6641                           context_die);
6642     }
6643   if (DECL_ABSTRACT (decl))
6644     {
6645       equate_decl_number_to_die (decl, type_die);
6646     }
6647 }
6648
6649 /* Generate a type description DIE.  */
6650 static void
6651 gen_type_die (type, context_die)
6652      register tree type;
6653      register dw_die_ref context_die;
6654 {
6655   register unsigned is_complete;
6656   if (type == 0 || type == error_mark_node)
6657     {
6658       return;
6659     }
6660
6661   /* We are going to output a DIE to represent the unqualified version of of
6662      this type (i.e. without any const or volatile qualifiers) so get the
6663      main variant (i.e. the unqualified version) of this type now.  */
6664   type = type_main_variant (type);
6665
6666   if (TREE_ASM_WRITTEN (type))
6667     {
6668       return;
6669     }
6670
6671   switch (TREE_CODE (type))
6672     {
6673     case ERROR_MARK:
6674       break;
6675
6676     case POINTER_TYPE:
6677     case REFERENCE_TYPE:
6678       /* For these types, all that is required is that we output a DIE (or a
6679          set of DIEs) to represent the "basis" type.  */
6680       gen_type_die (TREE_TYPE (type), context_die);
6681       break;
6682
6683     case OFFSET_TYPE:
6684       /* This code is used for C++ pointer-to-data-member types.  */
6685       /* Output a description of the relevant class type.  */
6686       gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
6687       /* Output a description of the type of the object pointed to.  */
6688       gen_type_die (TREE_TYPE (type), context_die);
6689       /* Now output a DIE to represent this pointer-to-data-member type
6690          itself.  */
6691       gen_ptr_to_mbr_type_die (type, context_die);
6692       break;
6693
6694     case SET_TYPE:
6695       gen_type_die (TYPE_DOMAIN (type), context_die);
6696       gen_set_type_die (type, context_die);
6697       break;
6698
6699     case FILE_TYPE:
6700       gen_type_die (TREE_TYPE (type), context_die);
6701       abort ();                 /* No way to represent these in Dwarf yet!  */
6702       break;
6703
6704     case FUNCTION_TYPE:
6705       /* Force out return type (in case it wasn't forced out already).  */
6706       gen_type_die (TREE_TYPE (type), context_die);
6707       gen_subroutine_type_die (type, context_die);
6708       break;
6709
6710     case METHOD_TYPE:
6711       /* Force out return type (in case it wasn't forced out already).  */
6712       gen_type_die (TREE_TYPE (type), context_die);
6713       gen_subroutine_type_die (type, context_die);
6714       break;
6715
6716     case ARRAY_TYPE:
6717       if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
6718         {
6719           gen_type_die (TREE_TYPE (type), context_die);
6720           gen_string_type_die (type, context_die);
6721         }
6722       else
6723         {
6724           gen_array_type_die (type, context_die);
6725         }
6726       break;
6727
6728     case ENUMERAL_TYPE:
6729     case RECORD_TYPE:
6730     case UNION_TYPE:
6731     case QUAL_UNION_TYPE:
6732       /* For a non-file-scope tagged type, we can always go ahead and output
6733          a Dwarf description of this type right now, even if the type in
6734          question is still incomplete, because if this local type *was* ever
6735          completed anywhere within its scope, that complete definition would
6736          already have been attached to this RECORD_TYPE, UNION_TYPE,
6737          QUAL_UNION_TYPE or ENUMERAL_TYPE node by the time we reach this
6738          point.  That's true because of the way the front-end does its
6739          processing of file-scope declarations (of functions and class types) 
6740          within which other types might be nested.  The C and C++ front-ends
6741          always gobble up such "local scope" things en-mass before they try
6742          to output *any* debugging information for any of the stuff contained 
6743          inside them and thus, we get the benefit here of what is (in effect) 
6744          a pre-resolution of forward references to tagged types in local
6745          scopes. Note however that for file-scope tagged types we cannot
6746          assume that such pre-resolution of forward references has taken
6747          place. A given file-scope tagged type may appear to be incomplete
6748          when we reach this point, but it may yet be given a full definition
6749          (at file-scope) later on during compilation.  In order to avoid
6750          generating a premature (and possibly incorrect) set of Dwarf DIEs
6751          for such (as yet incomplete) file-scope tagged types, we generate
6752          nothing at all for as-yet incomplete file-scope tagged types here
6753          unless we are making our special "finalization" pass for file-scope
6754          things at the very end of compilation.  At that time, we will
6755          certainly know as much about each file-scope tagged type as we are
6756          ever going to know, so at that point in time, we can safely generate 
6757          correct Dwarf descriptions for these file-scope tagged types.  */
6758       is_complete = TYPE_SIZE (type) != 0
6759         || TYPE_CONTEXT (type) != NULL
6760         || finalizing;
6761       if (TREE_CODE (type) == ENUMERAL_TYPE)
6762         {
6763           gen_enumeration_type_die (type, is_complete, context_die);
6764         }
6765       else
6766         {
6767           gen_struct_or_union_type_die (type, is_complete, context_die);
6768         }
6769       break;
6770
6771     case VOID_TYPE:
6772     case INTEGER_TYPE:
6773     case REAL_TYPE:
6774     case COMPLEX_TYPE:
6775     case BOOLEAN_TYPE:
6776     case CHAR_TYPE:
6777       /* No DIEs needed for fundamental types.  */
6778       break;
6779
6780     case LANG_TYPE:
6781       /* No Dwarf representation currently defined.  */
6782       break;
6783
6784     default:
6785       abort ();
6786     }
6787
6788   TREE_ASM_WRITTEN (type) = 1;
6789 }
6790
6791 /* Generate a DIE for a tagged type instantiation.  */
6792 static void
6793 gen_tagged_type_instantiation_die (type, context_die)
6794      register tree type;
6795      register dw_die_ref context_die;
6796 {
6797   if (type == 0 || type == error_mark_node)
6798     {
6799       return;
6800     }
6801
6802   /* We are going to output a DIE to represent the unqualified version of of
6803      this type (i.e. without any const or volatile qualifiers) so make sure
6804      that we have the main variant (i.e. the unqualified version) of this
6805      type now.  */
6806   assert (type == type_main_variant (type));
6807   assert (TREE_ASM_WRITTEN (type));
6808
6809   switch (TREE_CODE (type))
6810     {
6811     case ERROR_MARK:
6812       break;
6813
6814     case ENUMERAL_TYPE:
6815       gen_inlined_enumeration_type_die (type, context_die);
6816       break;
6817
6818     case RECORD_TYPE:
6819       gen_inlined_structure_type_die (type, context_die);
6820       break;
6821
6822     case UNION_TYPE:
6823     case QUAL_UNION_TYPE:
6824       gen_inlined_union_type_die (type, context_die);
6825       break;
6826
6827     default:
6828       abort ();                 /* Should never happen.  */
6829     }
6830 }
6831
6832 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
6833    things which are local to the given block.  */
6834 static void
6835 gen_block_die (stmt, context_die)
6836      register tree stmt;
6837      register dw_die_ref context_die;
6838 {
6839   register int must_output_die = 0;
6840   register tree origin;
6841   register tree decl;
6842   register enum tree_code origin_code;
6843
6844   /* Ignore blocks never really used to make RTL.  */
6845
6846   if (!stmt || !TREE_USED (stmt))
6847     {
6848       return;
6849     }
6850
6851   /* Determine the "ultimate origin" of this block.  This block may be an
6852      inlined instance of an inlined instance of inline function, so we have
6853      to trace all of the way back through the origin chain to find out what
6854      sort of node actually served as the original seed for the creation of
6855      the current block.  */
6856   origin = block_ultimate_origin (stmt);
6857   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
6858
6859   /* Determine if we need to output any Dwarf DIEs at all to represent this
6860      block.  */
6861   if (origin_code == FUNCTION_DECL)
6862     {
6863       /* The outer scopes for inlinings *must* always be represented.  We
6864          generate DW_TAG_inlined_subroutine DIEs for them.  (See below.) */
6865       must_output_die = 1;
6866     }
6867   else
6868     {
6869       /* In the case where the current block represents an inlining of the
6870          "body block" of an inline function, we must *NOT* output any DIE for 
6871          this block because we have already output a DIE to represent the
6872          whole inlined function scope and the "body block" of any function
6873          doesn't really represent a different scope according to ANSI C
6874          rules.  So we check here to make sure that this block does not
6875          represent a "body block inlining" before trying to set the
6876          `must_output_die' flag.  */
6877       if (origin == NULL || !is_body_block (origin))
6878         {
6879           /* Determine if this block directly contains any "significant"
6880              local declarations which we will need to output DIEs for.  */
6881           if (debug_info_level > DINFO_LEVEL_TERSE)
6882             {
6883               /* We are not in terse mode so *any* local declaration counts
6884                  as being a "significant" one.  */
6885               must_output_die = (BLOCK_VARS (stmt) != NULL);
6886             }
6887           else
6888             {
6889               /* We are in terse mode, so only local (nested) function
6890                  definitions count as "significant" local declarations.  */
6891               for (decl = BLOCK_VARS (stmt);
6892                    decl != NULL; decl = TREE_CHAIN (decl))
6893                 {
6894                   if (TREE_CODE (decl) == FUNCTION_DECL
6895                       && DECL_INITIAL (decl))
6896                     {
6897                       must_output_die = 1;
6898                       break;
6899                     }
6900                 }
6901             }
6902         }
6903     }
6904
6905   /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
6906      DIE for any block which contains no significant local declarations at
6907      all.  Rather, in such cases we just call `decls_for_scope' so that any
6908      needed Dwarf info for any sub-blocks will get properly generated. Note
6909      that in terse mode, our definition of what constitutes a "significant"
6910      local declaration gets restricted to include only inlined function
6911      instances and local (nested) function definitions.  */
6912   if (must_output_die)
6913     {
6914       if (origin_code == FUNCTION_DECL)
6915         {
6916           gen_inlined_subroutine_die (stmt, context_die);
6917         }
6918       else
6919         {
6920           gen_lexical_block_die (stmt, context_die);
6921         }
6922     }
6923   else
6924     decls_for_scope (stmt, context_die);
6925 }
6926
6927 /* Generate all of the decls declared within a given scope and (recursively)
6928    all of it's sub-blocks.  */
6929 static void
6930 decls_for_scope (stmt, context_die)
6931      register tree stmt;
6932      register dw_die_ref context_die;
6933 {
6934   register tree decl;
6935   register tree subblocks;
6936   /* Ignore blocks never really used to make RTL.  */
6937   if (!stmt || !TREE_USED (stmt))
6938     {
6939       return;
6940     }
6941   if (!BLOCK_ABSTRACT (stmt))
6942     {
6943       next_block_number++;
6944     }
6945
6946   /* Output the DIEs to represent all of the data objects, functions,
6947      typedefs, and tagged types declared directly within this block but not
6948      within any nested sub-blocks.  */
6949   for (decl = BLOCK_VARS (stmt);
6950        decl != NULL; decl = TREE_CHAIN (decl))
6951     {
6952       gen_decl_die (decl, context_die);
6953     }
6954
6955   /* Output the DIEs to represent all sub-blocks (and the items declared
6956      therein) of this block.  */
6957   for (subblocks = BLOCK_SUBBLOCKS (stmt);
6958        subblocks != NULL;
6959        subblocks = BLOCK_CHAIN (subblocks))
6960     {
6961       gen_block_die (subblocks, context_die);
6962     }
6963 }
6964
6965 /* Generate Dwarf debug information for a decl described by DECL.  */
6966 static void
6967 gen_decl_die (decl, context_die)
6968      register tree decl;
6969      register dw_die_ref context_die;
6970 {
6971   register tree origin;
6972   /* Make a note of the decl node we are going to be working on.  We may need 
6973      to give the user the source coordinates of where it appeared in case we
6974      notice (later on) that something about it looks screwy.  */
6975   dwarf_last_decl = decl;
6976
6977   if (TREE_CODE (decl) == ERROR_MARK)
6978     {
6979       return;
6980     }
6981
6982   /* If this ..._DECL node is marked to be ignored, then ignore it. But don't 
6983      ignore a function definition, since that would screw up our count of
6984      blocks, and that it turn will completely screw up the the labels we will 
6985      reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
6986      subsequent blocks).  */
6987   if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
6988     {
6989       return;
6990     }
6991
6992   push_decl_scope (DECL_CONTEXT (decl));
6993   switch (TREE_CODE (decl))
6994     {
6995     case CONST_DECL:
6996       /* The individual enumerators of an enum type get output when we output 
6997          the Dwarf representation of the relevant enum type itself.  */
6998       break;
6999
7000     case FUNCTION_DECL:
7001       /* If we are in terse mode, don't output any DIEs to represent mere
7002          function declarations.  */
7003       if (DECL_INITIAL (decl) == NULL_TREE)
7004         {
7005           break;
7006         }
7007       /* Before we describe the FUNCTION_DECL itself, make sure that we have
7008          described its return type.  */
7009       gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
7010
7011       /* Now output a DIE to represent the function itself.  */
7012       gen_subprogram_die (decl, context_die);
7013       break;
7014
7015     case TYPE_DECL:
7016       /* If we are in terse mode, don't generate any DIEs to represent any
7017          actual typedefs.  Note that even when we are in terse mode, we must
7018          still output DIEs to represent those tagged types which are used
7019          (directly or indirectly) in the specification of either a return
7020          type or a formal parameter type of some function.  */
7021       if (debug_info_level <= DINFO_LEVEL_TERSE)
7022         {
7023           if (DECL_NAME (decl) != NULL
7024               || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7025             {
7026               break;
7027             }
7028         }
7029
7030       /* In the special case of a null-named TYPE_DECL node (representing the 
7031          declaration of some type tag), if the given TYPE_DECL is marked as
7032          having been instantiated from some other (original) TYPE_DECL node
7033          (e.g. one which was generated within the original definition of an
7034          inline function) we have to generate a special (abbreviated)
7035          DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type 
7036          DIE here.  */
7037       if (!DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
7038         {
7039           gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7040           break;
7041         }
7042       gen_type_die (TREE_TYPE (decl), context_die);
7043
7044       /* Note that unlike the gcc front end (which generates a NULL named
7045          TYPE_DECL node for each complete tagged type, each array type, and
7046          each function type node created) the g++ front end generates a
7047          _named_ TYPE_DECL node for each tagged type node created.
7048          Unfortunately, these g++ TYPE_DECL nodes cause us to output many
7049          superfluous and unnecessary DW_TAG_typedef DIEs here.  When g++ is
7050          fixed to stop generating these superfluous named TYPE_DECL nodes,
7051          the superfluous DW_TAG_typedef DIEs will likewise cease.  */
7052       if (DECL_NAME (decl))
7053         {
7054           /* Output a DIE to represent the typedef itself.  */
7055           gen_typedef_die (decl, context_die);
7056         }
7057       break;
7058
7059     case LABEL_DECL:
7060       if (debug_info_level >= DINFO_LEVEL_NORMAL)
7061         {
7062           gen_label_die (decl, context_die);
7063         }
7064       break;
7065
7066     case VAR_DECL:
7067       /* If we are in terse mode, don't generate any DIEs to represent any
7068          variable declarations or definitions.  */
7069       if (debug_info_level <= DINFO_LEVEL_TERSE)
7070         {
7071           break;
7072         }
7073
7074       /* Output any DIEs that are needed to specify the type of this data
7075          object.  */
7076       gen_type_die (TREE_TYPE (decl), context_die);
7077
7078       /* Now output the DIE to represent the data object itself.  This gets
7079          complicated because of the possibility that the VAR_DECL really
7080          represents an inlined instance of a formal parameter for an inline
7081          function.  */
7082       origin = decl_ultimate_origin (decl);
7083       if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
7084         {
7085           gen_formal_parameter_die (decl, context_die);
7086         }
7087       else
7088         {
7089           gen_variable_die (decl, context_die);
7090         }
7091       break;
7092
7093     case FIELD_DECL:
7094       /* Ignore the nameless fields that are used to skip bits.  */
7095       if (DECL_NAME (decl) != 0)
7096         {
7097           gen_type_die (member_declared_type (decl), context_die);
7098           gen_field_die (decl, context_die);
7099         }
7100       break;
7101
7102     case PARM_DECL:
7103       gen_type_die (TREE_TYPE (decl), context_die);
7104       gen_formal_parameter_die (decl, context_die);
7105       break;
7106
7107     default:
7108       abort ();
7109     }
7110   pop_decl_scope ();
7111 }
7112 \f
7113 /***************** Debug Information Generation Hooks ***********************/
7114 void
7115 dwarfout_file_scope_decl (decl, set_finalizing)
7116      register tree decl;
7117      register int set_finalizing;
7118 {
7119   if (TREE_CODE (decl) == ERROR_MARK)
7120     {
7121       return;
7122     }
7123
7124   /* If this ..._DECL node is marked to be ignored, then ignore it.  We gotta 
7125      hope that the node in question doesn't represent a function definition.
7126      If it does, then totally ignoring it is bound to screw up our count of
7127      blocks, and that it turn will completely screw up the the labels we will 
7128      reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7129      subsequent blocks).  (It's too bad that BLOCK nodes don't carry their
7130      own sequence numbers with them!) */
7131   if (DECL_IGNORED_P (decl))
7132     {
7133       if (TREE_CODE (decl) == FUNCTION_DECL
7134           && DECL_INITIAL (decl) != NULL)
7135         {
7136           abort ();
7137         }
7138       return;
7139     }
7140
7141   switch (TREE_CODE (decl))
7142     {
7143     case FUNCTION_DECL:
7144       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a 
7145          builtin function.  Explicit programmer-supplied declarations of
7146          these same functions should NOT be ignored however.  */
7147       if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
7148         {
7149           return;
7150         }
7151
7152       /* What we would really like to do here is to filter out all mere
7153          file-scope declarations of file-scope functions which are never
7154          referenced later within this translation unit (and keep all of ones
7155          that *are* referenced later on) but we aren't clarvoiant, so we have 
7156          no idea which functions will be referenced in the future (i.e. later 
7157          on within the current translation unit). So here we just ignore all
7158          file-scope function declarations which are not also definitions.  If 
7159          and when the debugger needs to know something about these funcstion, 
7160          it wil have to hunt around and find the DWARF information associated 
7161          with the definition of the function. Note that we can't just check
7162          `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7163          definitions and which ones represent mere declarations.  We have to
7164          check `DECL_INITIAL' instead. That's because the C front-end
7165          supports some weird semantics for "extern inline" function
7166          definitions.  These can get inlined within the current translation
7167          unit (an thus, we need to generate DWARF info for their abstract
7168          instances so that the DWARF info for the concrete inlined instances
7169          can have something to refer to) but the compiler never generates any 
7170          out-of-lines instances of such things (despite the fact that they
7171          *are* definitions).  The important point is that the C front-end
7172          marks these "extern inline" functions as DECL_EXTERNAL, but we need
7173          to generate DWARf for them anyway. Note that the C++ front-end also
7174          plays some similar games for inline function definitions appearing
7175          within include files which also contain 
7176          `#pragma interface' pragmas.  */
7177       if (DECL_INITIAL (decl) == NULL_TREE)
7178         {
7179           return;
7180         }
7181       break;
7182
7183     case VAR_DECL:
7184       /* Ignore this VAR_DECL if it refers to a file-scope extern data object 
7185          declaration and if the declaration was never even referenced from
7186          within this entire compilation unit.  We suppress these DIEs in
7187          order to save space in the .debug section (by eliminating entries
7188          which are probably useless).  Note that we must not suppress
7189          block-local extern declarations (whether used or not) because that
7190          would screw-up the debugger's name lookup mechanism and cause it to
7191          miss things which really ought to be in scope at a given point.  */
7192       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
7193         {
7194           return;
7195         }
7196
7197       /* If we are in terse mode, don't generate any DIEs to represent any
7198          variable declarations or definitions.  */
7199       if (debug_info_level <= DINFO_LEVEL_TERSE)
7200         {
7201           return;
7202         }
7203       break;
7204
7205     case TYPE_DECL:
7206       /* Don't bother trying to generate any DIEs to represent any of the
7207          normal built-in types for the language we are compiling, except in
7208          cases where the types in question are *not* DWARF fundamental types. 
7209          We make an exception in the case of non-fundamental types for the
7210          sake of objective C (and perhaps C++) because the GNU front-ends for 
7211          these languages may in fact create certain "built-in" types which
7212          are (for example) RECORD_TYPEs.  In such cases, we really need to
7213          output these (non-fundamental) types because other DIEs may contain
7214          references to them.  */
7215       if (DECL_SOURCE_LINE (decl) == 0
7216           && is_base_type (TREE_TYPE (decl)))
7217         {
7218           return;
7219         }
7220
7221       /* If we are in terse mode, don't generate any DIEs to represent any
7222          actual typedefs.  Note that even when we are in terse mode, we must
7223          still output DIEs to represent those tagged types which are used
7224          (directly or indirectly) in the specification of either a return
7225          type or a formal parameter type of some function.  */
7226       if (debug_info_level <= DINFO_LEVEL_TERSE)
7227         {
7228           if (DECL_NAME (decl) != NULL
7229               || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7230             {
7231               return;
7232             }
7233         }
7234       break;
7235
7236     default:
7237       return;
7238     }
7239
7240   finalizing = set_finalizing;
7241   gen_decl_die (decl, comp_unit_die);
7242
7243   if (TREE_CODE (decl) == FUNCTION_DECL
7244       && DECL_INITIAL (decl) != NULL)
7245     {
7246       current_funcdef_number++;
7247     }
7248
7249 }
7250
7251 /* Output a marker (i.e. a label) for the beginning of the generated code for
7252    a lexical block.  */
7253 void
7254 dwarfout_begin_block (blocknum)
7255      register unsigned blocknum;
7256 {
7257   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7258
7259   function_section (current_function_decl);
7260   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
7261   ASM_OUTPUT_LABEL (asm_out_file, label);
7262 }
7263
7264 /* Output a marker (i.e. a label) for the end of the generated code for a
7265    lexical block.  */
7266 void
7267 dwarfout_end_block (blocknum)
7268      register unsigned blocknum;
7269 {
7270   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7271
7272   function_section (current_function_decl);
7273   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
7274   ASM_OUTPUT_LABEL (asm_out_file, label);
7275 }
7276
7277 /* Output a marker (i.e. a label) at a point in the assembly code which
7278    corresponds to a given source level label.  */
7279 void
7280 dwarfout_label (insn)
7281      register rtx insn;
7282 {
7283   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7284   if (debug_info_level >= DINFO_LEVEL_NORMAL)
7285     {
7286       function_section (current_function_decl);
7287       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
7288                (unsigned) INSN_UID (insn));
7289       ASM_OUTPUT_LABEL (asm_out_file, label);
7290     }
7291 }
7292
7293 /* Output a marker (i.e. a label) for the point in the generated code where
7294    the real body of the function begins (after parameters have been moved to
7295    their home locations).  */
7296 void
7297 dwarfout_begin_function ()
7298 {
7299   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7300   register long int offset;
7301   register dw_fde_ref fde;
7302   register dw_cfi_ref cfi;
7303
7304   function_section (current_function_decl);
7305   sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
7306   ASM_OUTPUT_LABEL (asm_out_file, label);
7307
7308   /* Expand the fde table if necessary.  */
7309   if (fde_table_in_use == fde_table_allocated)
7310     {
7311       fde_table_allocated += FDE_TABLE_INCREMENT;
7312       fde_table = (dw_fde_ref) xrealloc (fde_table,
7313                fde_table_allocated * sizeof (dw_fde_node));
7314     }
7315
7316   /* Record the FDE associated with this function.  */
7317   current_funcdef_fde = fde_table_in_use;
7318
7319   /* Add the new FDE at the end of the fde_table.  */
7320   fde = &fde_table[fde_table_in_use++];
7321   fde->dw_fde_begin = xstrdup (function_start_label (current_function_decl));
7322   fde->dw_fde_end_prolog = xstrdup (label);
7323   fde->dw_fde_begin_epilogue = NULL;
7324   fde->dw_fde_end = NULL;
7325   fde->dw_fde_cfi = NULL;
7326
7327 #ifdef MIPS_DEBUGGING_INFO
7328
7329   /* On entry, the Call Frame Address is in the stack pointer register.  */
7330   cfi = new_cfi ();
7331   cfi->dw_cfi_opc = DW_CFA_def_cfa;
7332   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM;
7333   cfi->dw_cfi_oprnd2.dw_cfi_offset = 0;
7334   add_cfi (&fde->dw_fde_cfi, cfi);
7335
7336   /* Set the location counter to the end of the function prolog.  */
7337   cfi = new_cfi ();
7338   cfi->dw_cfi_opc = DW_CFA_advance_loc4;
7339   cfi->dw_cfi_oprnd1.dw_cfi_addr = xstrdup (label);
7340   add_cfi (&fde->dw_fde_cfi, cfi);
7341
7342   /* Define the CFA as either an explicit frame pointer register,
7343      or an offset from the stack pointer.  */
7344   cfi = new_cfi ();
7345   cfi->dw_cfi_opc = DW_CFA_def_cfa;
7346   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = (frame_pointer_needed)
7347                                        ? FRAME_POINTER_REGNUM
7348                                        : STACK_POINTER_REGNUM;
7349   offset = current_frame_info.total_size;
7350   cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7351   add_cfi (&fde->dw_fde_cfi, cfi);
7352
7353   /* record the frame size for later definition of the DW_AT_frame_base
7354      attribute.  */
7355   current_funcdef_frame_size = offset;
7356
7357   /* Define the rule for restoring the stack pointer.  */
7358   if (frame_pointer_needed)
7359     {
7360       /* Restore the stack register from the frame pointer.  */
7361       cfi = new_cfi ();
7362       cfi->dw_cfi_opc = DW_CFA_register;
7363       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM;
7364       cfi->dw_cfi_oprnd2.dw_cfi_reg_num = FRAME_POINTER_REGNUM;
7365       add_cfi (&fde->dw_fde_cfi, cfi);
7366     }
7367
7368   /* If RA is saved on the stack, define it here.  */
7369   if (regs_ever_live[31])
7370     {
7371       offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
7372       assert (offset >= 0);
7373       cfi = new_cfi ();
7374       cfi->dw_cfi_opc = DW_CFA_offset_extended;
7375       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
7376       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7377       add_cfi (&fde->dw_fde_cfi, cfi);
7378     }
7379
7380   /* If FP is saved on the stack, define it here.  */
7381   if (current_frame_info.mask & (1 << 30))
7382     {
7383       offset = (current_frame_info.gp_save_offset
7384                  - (((current_frame_info.mask >> 31) & 1) * 4))
7385                / DWARF_CIE_DATA_ALIGNMENT;
7386       assert (offset >= 0);
7387       cfi = new_cfi ();
7388       cfi->dw_cfi_opc = DW_CFA_offset;
7389       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = FRAME_POINTER_REGNUM;
7390       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7391       add_cfi (&fde->dw_fde_cfi, cfi);
7392     }
7393
7394 #endif
7395
7396 }
7397
7398 /* Output a marker (i.e. a label) for the point in the generated code where
7399    the real body of the function ends (just before the epilogue code).  */
7400 void
7401 dwarfout_end_function ()
7402 {
7403   dw_fde_ref fde;
7404   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7405   function_section (current_function_decl);
7406   sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
7407   ASM_OUTPUT_LABEL (asm_out_file, label);
7408   /* Record the ending code location in the FDE.  */
7409   fde = &fde_table[fde_table_in_use - 1];
7410   fde->dw_fde_begin_epilogue = xstrdup(label);
7411 }
7412
7413 /* Output a marker (i.e. a label) for the absolute end of the generated code
7414    for a function definition.  This gets called *after* the epilogue code has
7415    been generated.  */
7416 void
7417 dwarfout_end_epilogue ()
7418 {
7419   dw_fde_ref fde;
7420   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7421   /* Output a label to mark the endpoint of the code generated for this
7422      function.        */
7423   sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
7424   ASM_OUTPUT_LABEL (asm_out_file, label);
7425   fde = &fde_table[fde_table_in_use - 1];
7426   fde->dw_fde_end = xstrdup (label);
7427 }
7428
7429 /* Lookup a filename (in the list of filenames that we know about here in
7430    dwarfout.c) and return its "index".  The index of each (known) filename is
7431    just a unique number which is associated with only that one filename.
7432    We need such numbers for the sake of generating labels
7433    (in the .debug_sfnames section) and references to those
7434    files  numbers (in the .debug_srcinfo and.debug_macinfo sections).
7435    If the filename given as an argument is not found in our current list,
7436    add it to the list and assign it the next available unique index number.
7437    In order to speed up searches, we remember the index of the filename
7438    was looked up last.  This handles the majority of all searches.  */
7439 static unsigned
7440 lookup_filename (file_name)
7441      char *file_name;
7442 {
7443   static unsigned last_file_lookup_index = 0;
7444   register char *fn;
7445   register unsigned i;
7446
7447   /* Check to see if the file name that was searched on the previous call
7448      matches this file name. If so, return the index.  */
7449   if (last_file_lookup_index != 0)
7450     {
7451       fn = file_table[last_file_lookup_index];
7452       if (strcmp (file_name, fn) == 0)
7453         {
7454           return last_file_lookup_index;
7455         }
7456     }
7457
7458   /* Didn't match the previous lookup, search the table */
7459   for (i = 1; i < file_table_in_use; ++i)
7460     {
7461       fn = file_table[i];
7462       if (strcmp (file_name, fn) == 0)
7463         {
7464           last_file_lookup_index = i;
7465           return i;
7466         }
7467     }
7468
7469   /* Prepare to add a new table entry by making sure there is enough space in 
7470      the table to do so.  If not, expand the current table.  */
7471   if (file_table_in_use == file_table_allocated)
7472     {
7473       file_table_allocated += FILE_TABLE_INCREMENT;
7474       file_table
7475         = (char **)
7476         xrealloc (file_table, file_table_allocated * sizeof (char *));
7477     }
7478
7479   /* add the new entry to the end of the filename table.  */
7480   file_table[file_table_in_use] = xstrdup (file_name);
7481   last_file_lookup_index = file_table_in_use++;
7482   return last_file_lookup_index;
7483 }
7484
7485 /* Output a label to mark the beginning of a source code line entry
7486    and record information relating to this source line, in
7487    'line_info_table' for later output of the .debug_line section.  */
7488 void
7489 dwarfout_line (filename, line)
7490      register char *filename;
7491      register unsigned line;
7492 {
7493   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7494   register unsigned this_file_entry_num = lookup_filename (filename);
7495   register dw_line_info_ref line_info;
7496   if (debug_info_level >= DINFO_LEVEL_NORMAL)
7497     {
7498       function_section (current_function_decl);
7499       sprintf (label, LINE_CODE_LABEL_FMT, line_info_table_in_use);
7500       ASM_OUTPUT_LABEL (asm_out_file, label);
7501       fputc ('\n', asm_out_file);
7502
7503       /* expand the line info table if necessary */
7504       if (line_info_table_in_use == line_info_table_allocated)
7505         {
7506           line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
7507           line_info_table
7508             = (dw_line_info_ref)
7509             xrealloc (line_info_table,
7510                    line_info_table_allocated * sizeof (dw_line_info_entry));
7511         }
7512       /* add the new entry at the end of the line_info_table.  */
7513       line_info = &line_info_table[line_info_table_in_use++];
7514       line_info->dw_file_num = lookup_filename (filename);
7515       line_info->dw_line_num = line;
7516     }
7517 }
7518
7519 /* Record the beginning of a new source file, for later output
7520    of the .debug_macinfo section.  At present, unimplemented.  */
7521 void
7522 dwarfout_start_new_source_file (filename)
7523      register char *filename;
7524 {
7525 }
7526
7527 /* Record the resumption of a source file, for later output
7528    of the .debug_macinfo section.  At present, unimplemented.  */
7529 void
7530 dwarfout_resume_previous_source_file (lineno)
7531      register unsigned lineno;
7532 {
7533 }
7534
7535 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
7536    the tail part of the directive line, i.e. the part which is past the
7537    initial whitespace, #, whitespace, directive-name, whitespace part.  */
7538 void
7539 dwarfout_define (lineno, buffer)
7540      register unsigned lineno;
7541      register char *buffer;
7542 {
7543   static int initialized = 0;
7544   if (!initialized)
7545     {
7546       dwarfout_start_new_source_file (primary_filename);
7547       initialized = 1;
7548     }
7549 }
7550
7551 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
7552    the tail part of the directive line, i.e. the part which is past the
7553    initial whitespace, #, whitespace, directive-name, whitespace part.  */
7554 void
7555 dwarfout_undef (lineno, buffer)
7556      register unsigned lineno;
7557      register char *buffer;
7558 {
7559 }
7560
7561 /* Set up for Dwarf output at the start of compilation.  */
7562 void
7563 dwarfout_init (asm_out_file, main_input_filename)
7564      register FILE *asm_out_file;
7565      register char *main_input_filename;
7566 {
7567
7568   /* Remember the name of the primary input file.  */
7569   primary_filename = main_input_filename;
7570
7571   /* Allocate the initial hunk of the file_table.  */
7572   file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
7573   bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *));
7574   file_table_allocated = FILE_TABLE_INCREMENT;
7575   /* skip the first entry - file numbers begin at 1 */
7576   file_table_in_use = 1;
7577
7578   /* Allocate the initial hunk of the type_die_table.  */
7579   type_die_table
7580     = (dw_die_ref *) xmalloc (TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7581   bzero (type_die_table, TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7582   type_die_table_allocated = TYPE_DIE_TABLE_INCREMENT;
7583   type_die_table_in_use = 0;
7584
7585   /* Allocate the initial hunk of the decl_die_table.  */
7586   decl_die_table
7587     = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7588   bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7589   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
7590   decl_die_table_in_use = 0;
7591
7592   /* Allocate the initial hunk of the decl_scope_table.  */
7593   decl_scope_table
7594     = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
7595   bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
7596   decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
7597   decl_scope_depth = 0;
7598
7599   /* Allocate the initial hunk of the abbrev_die_table.  */
7600   abbrev_die_table
7601     = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
7602                               * sizeof (dw_die_ref));
7603   bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
7604   abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
7605   /* zero-th entry is allocated, but unused */
7606   abbrev_die_table_in_use = 1;
7607
7608   /* Allocate the initial hunk of the line_info_table.  */
7609   line_info_table
7610     = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
7611                                   * sizeof (dw_line_info_entry));
7612   bzero (line_info_table, LINE_INFO_TABLE_INCREMENT
7613          * sizeof (dw_line_info_entry));
7614   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
7615   /* zero-th entry is allocated, but unused */
7616   line_info_table_in_use = 1;
7617
7618   /* Allocate the initial hunk of the fde_table.  */
7619   fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
7620   bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
7621   fde_table_allocated = FDE_TABLE_INCREMENT;
7622   fde_table_in_use = 0;
7623
7624   /* Output a starting label for the .text section.  */
7625   fputc ('\n', asm_out_file);
7626   ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
7627   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
7628
7629   /* Output a starting label for the .data section.  */
7630   fputc ('\n', asm_out_file);
7631   ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
7632   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
7633
7634   /* Output a starting label for the .rodata section.  */
7635   fputc ('\n', asm_out_file);
7636   ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
7637   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
7638
7639   /* Output a starting label for the .bss section.  */
7640   fputc ('\n', asm_out_file);
7641   ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
7642   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
7643
7644   /* Generate the initial DIE for the .debug section.  Note that the (string) 
7645      value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
7646      will (typically) be a relative pathname and that this pathname should be 
7647      taken as being relative to the directory from which the compiler was
7648      invoked when the given (base) source file was compiled.  */
7649   gen_compile_unit_die (main_input_filename);
7650
7651   /* clear the association between base types and their DIE's */
7652   init_base_type_table ();
7653
7654   /* clear the backchain list.  */
7655   backchain = NULL;
7656 }
7657
7658 /* Output stuff that dwarf requires at the end of every file,
7659    and generate the DWARF-2 debugging info.  */
7660 void
7661 dwarfout_finish ()
7662 {
7663
7664   resolve_backchains ();
7665
7666   /* Traverse the DIE tree and add sibling attributes to those DIE's
7667      that have children.  */
7668   add_sibling_attributes (comp_unit_die);
7669
7670   /* Output a terminator label for the .text section.  */
7671   fputc ('\n', asm_out_file);
7672   ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
7673   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
7674
7675   /* Output a terminator label for the .data section.  */
7676   fputc ('\n', asm_out_file);
7677   ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
7678   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
7679
7680   /* Output a terminator label for the .rodata section.  */
7681   fputc ('\n', asm_out_file);
7682   ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
7683   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
7684
7685   /* Output a terminator label for the .bss section.  */
7686   fputc ('\n', asm_out_file);
7687   ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
7688   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
7689
7690   /* Output the abbreviation table.  */
7691   fputc ('\n', asm_out_file);
7692   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
7693   build_abbrev_table (comp_unit_die);
7694   output_abbrev_section ();
7695
7696   /* Output the source line correspondence table.  */
7697   fputc ('\n', asm_out_file);
7698   ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
7699   output_line_info ();
7700
7701   /* Initialize the beginning DIE offset - and calculate sizes/offsets.   */
7702   next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7703   calc_die_sizes (comp_unit_die);
7704
7705   /* Initialize the beginning FDE offset - and calculate sizes/offsets.  */
7706   next_fde_offset = DWARF_CIE_SIZE;
7707   calc_fde_sizes ();
7708
7709   /* Output debugging information.  */
7710   fputc ('\n', asm_out_file);
7711   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
7712   output_compilation_unit_header ();
7713   output_die (comp_unit_die);
7714
7715   if (fde_table_in_use)
7716     {
7717       /* Output call frame information.  */
7718       fputc ('\n', asm_out_file);
7719       ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
7720       output_call_frame_info ();
7721
7722       /* Output public names table.  */
7723       fputc ('\n', asm_out_file);
7724       ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
7725       output_pubnames ();
7726
7727       /* Output the address range information.  */
7728       fputc ('\n', asm_out_file);
7729       ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
7730       output_aranges ();
7731     }
7732 }
7733 #endif /* DWARF_DEBUGGING_INFO  && DWARF_VERSION == 2 */