OSDN Git Service

1341ed712ddadc264b1690a032acfb130e5f4b0c
[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, 1997 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    Extensively modified by Jason Merrill (jason@cygnus.com).
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
22
23 #include "config.h"
24
25 #ifdef DWARF2_DEBUGGING_INFO
26 #include <stdio.h>
27 #include <setjmp.h>
28 #include "dwarf2.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "rtl.h"
32 #include "hard-reg-set.h"
33 #include "regs.h"
34 #include "insn-config.h"
35 #include "reload.h"
36 #include "output.h"
37 #include "defaults.h"
38 #include "expr.h"
39
40 /* #define NDEBUG 1 */
41 #include "assert.h"
42
43 extern char *getpwd ();
44
45 /* NOTE: In the comments in this file, many references are made to
46    "Debugging Information Entries".  This term is abbreviated as `DIE'
47    throughout the remainder of this file.  */
48
49 #ifndef __GNUC__
50 #define inline
51 #endif
52
53 /* An internal representation of the DWARF output is built, and then
54    walked to generate the DWARF debugging info.  The walk of the internal
55    representation is done after the entire program has been compiled.
56    The types below are used to describe the internal representation.  */
57
58 /* Each DIE may have a series of attribute/value pairs.  Values
59    can take on several forms.  The forms that are used in this
60    implementation are listed below.  */
61
62 typedef enum
63 {
64   dw_val_class_addr,
65   dw_val_class_loc,
66   dw_val_class_const,
67   dw_val_class_unsigned_const,
68   dw_val_class_long_long,
69   dw_val_class_float,
70   dw_val_class_flag,
71   dw_val_class_die_ref,
72   dw_val_class_fde_ref,
73   dw_val_class_lbl_id,
74   dw_val_class_section_offset,
75   dw_val_class_str
76 }
77 dw_val_class;
78
79 /* Various DIE's use offsets relative to the beginning of the
80    .debug_info section to refer to each other.  */
81
82 typedef long int dw_offset;
83
84 /* Define typedefs here to avoid circular dependencies.  */
85
86 typedef struct die_struct *dw_die_ref;
87 typedef struct dw_attr_struct *dw_attr_ref;
88 typedef struct dw_val_struct *dw_val_ref;
89 typedef struct dw_line_info_struct *dw_line_info_ref;
90 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
91 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
92 typedef struct dw_cfi_struct *dw_cfi_ref;
93 typedef struct dw_fde_struct *dw_fde_ref;
94 typedef union  dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
95 typedef struct pubname_struct *pubname_ref;
96 typedef dw_die_ref *arange_ref;
97
98 /* Describe a double word constant value.  */
99
100 typedef struct dw_long_long_struct
101 {
102   unsigned long hi;
103   unsigned long low;
104 }
105 dw_long_long_const;
106
107 /* Describe a floating point constant value.  */
108
109 typedef struct dw_fp_struct
110 {
111   long *array;
112   unsigned length;
113 }
114 dw_float_const;
115
116 /* Each entry in the line_info_table maintains the file and
117    line nuber associated with the label generated for that
118    entry.  The label gives the PC value associated with
119    the line number entry.  */
120
121 typedef struct dw_line_info_struct
122 {
123   unsigned long dw_file_num;
124   unsigned long dw_line_num;
125 }
126 dw_line_info_entry;
127
128 /* Line information for functions in separate sections; each one gets its
129    own sequence.  */
130 typedef struct dw_separate_line_info_struct
131 {
132   unsigned long dw_file_num;
133   unsigned long dw_line_num;
134   unsigned long function;
135 }
136 dw_separate_line_info_entry;
137
138 /* The dw_val_node describes an attibute's value, as it is
139    represented internally.  */
140
141 typedef struct dw_val_struct
142 {
143   dw_val_class val_class;
144   union
145     {
146       char *val_addr;
147       dw_loc_descr_ref val_loc;
148       long int val_int;
149       long unsigned val_unsigned;
150       dw_long_long_const val_long_long;
151       dw_float_const val_float;
152       dw_die_ref val_die_ref;
153       unsigned val_fde_index;
154       char *val_str;
155       char *val_lbl_id;
156       char *val_section;
157       unsigned char val_flag;
158     }
159   v;
160 }
161 dw_val_node;
162
163 /* Locations in memory are described using a sequence of stack machine
164    operations.  */
165
166 typedef struct dw_loc_descr_struct
167 {
168   dw_loc_descr_ref dw_loc_next;
169   enum dwarf_location_atom dw_loc_opc;
170   dw_val_node dw_loc_oprnd1;
171   dw_val_node dw_loc_oprnd2;
172 }
173 dw_loc_descr_node;
174
175 /* Each DIE attribute has a field specifying the attribute kind,
176    a link to the next attribute in the chain, and an attribute value.
177    Attributes are typically linked below the DIE they modify.  */
178
179 typedef struct dw_attr_struct
180 {
181   enum dwarf_attribute dw_attr;
182   dw_attr_ref dw_attr_next;
183   dw_val_node dw_attr_val;
184 }
185 dw_attr_node;
186
187 /* Call frames are described using a sequence of Call Frame
188    Information instructions.  The register number, offset
189    and address fields are provided as possible operands;
190    their use is selected by the opcode field.  */
191
192 typedef union dw_cfi_oprnd_struct
193 {
194   unsigned long dw_cfi_reg_num;
195   long int dw_cfi_offset;
196   char *dw_cfi_addr;
197 }
198 dw_cfi_oprnd;
199
200 typedef struct dw_cfi_struct
201 {
202   dw_cfi_ref dw_cfi_next;
203   enum dwarf_call_frame_info dw_cfi_opc;
204   dw_cfi_oprnd dw_cfi_oprnd1;
205   dw_cfi_oprnd dw_cfi_oprnd2;
206 }
207 dw_cfi_node;
208
209 /* All call frame descriptions (FDE's) in the GCC generated DWARF
210    refer to a single Common Information Entry (CIE), defined at
211    the beginning of the .debug_frame section.  This used of a single
212    CIE obviates the need to keep track of multiple CIE's
213    in the DWARF generation routines below.  */
214
215 typedef struct dw_fde_struct
216 {
217   unsigned long dw_fde_offset;
218   char *dw_fde_begin;
219   char *dw_fde_current_label;
220   char *dw_fde_end;
221   dw_cfi_ref dw_fde_cfi;
222 }
223 dw_fde_node;
224
225 /* The Debugging Information Entry (DIE) structure */
226
227 typedef struct die_struct
228 {
229   enum dwarf_tag die_tag;
230   dw_attr_ref die_attr;
231   dw_attr_ref die_attr_last;
232   dw_die_ref die_parent;
233   dw_die_ref die_child;
234   dw_die_ref die_child_last;
235   dw_die_ref die_sib;
236   dw_offset die_offset;
237   unsigned long die_abbrev;
238 }
239 die_node;
240
241 /* The pubname structure */
242
243 typedef struct pubname_struct
244 {
245   dw_die_ref die;
246   char * name;
247 }
248 pubname_entry;
249
250 /* How to start an assembler comment.  */
251 #ifndef ASM_COMMENT_START
252 #define ASM_COMMENT_START ";#"
253 #endif
254
255 /* Define a macro which returns non-zero for a TYPE_DECL which was
256    implicitly generated for a tagged type.
257
258    Note that unlike the gcc front end (which generates a NULL named
259    TYPE_DECL node for each complete tagged type, each array type, and
260    each function type node created) the g++ front end generates a
261    _named_ TYPE_DECL node for each tagged type node created.
262    These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
263    generate a DW_TAG_typedef DIE for them.  */
264
265 #define TYPE_DECL_IS_STUB(decl)                         \
266   (DECL_NAME (decl) == NULL_TREE                        \
267    || (DECL_ARTIFICIAL (decl)                           \
268        && is_tagged_type (TREE_TYPE (decl))             \
269        && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
270
271 /* Information concerning the compilation unit's programming
272    language, and compiler version.  */
273
274 extern int flag_traditional;
275 extern char *version_string;
276 extern char *language_string;
277
278 /* Maximum size (in bytes) of an artificially generated label.   */
279 #define MAX_ARTIFICIAL_LABEL_BYTES      30
280
281 /* Make sure we know the sizes of the various types dwarf can describe. These
282    are only defaults.  If the sizes are different for your target, you should
283    override these values by defining the appropriate symbols in your tm.h
284    file.  */
285
286 #ifndef CHAR_TYPE_SIZE
287 #define CHAR_TYPE_SIZE BITS_PER_UNIT
288 #endif
289 #ifndef PTR_SIZE
290 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
291 #endif
292
293 /* The size in bytes of a DWARF field indicating an offset or length
294    relative to a debug info section, specified to be 4 bytes in the DWARF-2
295    specification.  The SGI/MIPS ABI defines it to be the same as PTR_SIZE.  */
296
297 #ifndef DWARF_OFFSET_SIZE
298 #define DWARF_OFFSET_SIZE 4
299 #endif
300
301 #define DWARF_VERSION 2
302
303 /* Fixed size portion of the DWARF compilation unit header.  */
304 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
305
306 /* Fixed size portion of debugging line information prolog.  */
307 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
308
309 /* Fixed size portion of public names info.  */
310 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
311
312 /* Round SIZE up to the nearest BOUNDARY.  */
313 #define DWARF_ROUND(SIZE,BOUNDARY) \
314   (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
315
316 /* Fixed size portion of the address range info.  */
317 #define DWARF_ARANGES_HEADER_SIZE \
318   (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
319
320 /* Fixed size portion of the CIE (including the length field).  */
321 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
322
323 /* The un-padded size of the CIE.  Initialized in calc_fde_sizes, used
324    in output_call_frame_info.  */
325 static unsigned cie_size;
326
327 /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
330 #else
331 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
332 #endif
333
334 /* Fixed size portion of the FDE.  */
335 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
336
337 /* Define the architecture-dependent minimum instruction length (in bytes).
338    In this implementation of DWARF, this field is used for information
339    purposes only.  Since GCC generates assembly language, we have
340    no a priori knowledge of how many instruction bytes are generated
341    for each source line, and therefore can use only the  DW_LNE_set_address
342    and DW_LNS_fixed_advance_pc line information commands.  */
343
344 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
345 #define DWARF_LINE_MIN_INSTR_LENGTH 4
346 #endif
347
348 /* Minimum line offset in a special line info. opcode.
349    This value was chosen to give a reasonable range of values.  */
350 #define DWARF_LINE_BASE  -10
351
352 /* First special line opcde - leave room for the standard opcodes.  */
353 #define DWARF_LINE_OPCODE_BASE  10
354
355 /* Range of line offsets in a special line info. opcode.  */
356 #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
357
358 /* Flag that indicates the initial value of the is_stmt_start flag.
359    In the present implementation, we do not mark any lines as
360    the beginning of a source statement, because that information
361    is not made available by the GCC front-end.  */
362 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
363
364 /* This location is used by calc_die_sizes() to keep track
365    the offset of each DIE within the .debug_info section.  */
366 static unsigned long next_die_offset;
367
368 /* This location is used by calc_fde_sizes() to keep track
369    the offset of each FDE within the .debug_frame section.  */
370 static unsigned long next_fde_offset;
371
372 /* Record the root of the DIE's built for the current compilation unit.  */
373 static dw_die_ref comp_unit_die;
374
375 /* The number of DIEs with a NULL parent waiting to be relocated.  */
376 static int limbo_die_count;
377
378 /* Pointer to an array of filenames referenced by this compilation unit.  */
379 static char **file_table;
380
381 /* Total number of entries in the table (i.e. array) pointed to by
382    `file_table'.  This is the *total* and includes both used and unused
383    slots.  */
384 static unsigned file_table_allocated;
385
386 /* Number of entries in the file_table which are actually in use.  */
387 static unsigned file_table_in_use;
388
389 /* Size (in elements) of increments by which we may expand the filename
390    table.  */
391 #define FILE_TABLE_INCREMENT 64
392
393 /* Local pointer to the name of the main input file.  Initialized in
394    dwarf2out_init.  */
395 static char *primary_filename;
396
397 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
398    which their beginnings are encountered. We output Dwarf debugging info
399    that refers to the beginnings and ends of the ranges of code for each
400    lexical block.  The labels themselves are generated in final.c, which
401    assigns numbers to the blocks in the same way.  */
402 static unsigned next_block_number = 2;
403
404 /* A pointer to the base of a table of references to DIE's that describe
405    declarations.  The table is indexed by DECL_UID() which is a unique
406    number, indentifying each decl.  */
407 static dw_die_ref *decl_die_table;
408
409 /* Number of elements currently allocated for the decl_die_table.  */
410 static unsigned decl_die_table_allocated;
411
412 /* Number of elements in decl_die_table currently in use.  */
413 static unsigned decl_die_table_in_use;
414
415 /* Size (in elements) of increments by which we may expand the
416    decl_die_table.  */
417 #define DECL_DIE_TABLE_INCREMENT 256
418
419 /* A pointer to the base of a table of references to declaration
420    scopes.  This table is a display which tracks the nesting
421    of declaration scopes at the current scope and containing
422    scopes.  This table is used to find the proper place to
423    define type declaration DIE's.  */
424 static tree *decl_scope_table;
425
426 /* Number of elements currently allocated for the decl_scope_table.  */
427 static unsigned decl_scope_table_allocated;
428
429 /* Current level of nesting of declataion scopes.  */
430 static unsigned decl_scope_depth;
431
432 /* Size (in elements) of increments by which we may expand the
433    decl_scope_table.  */
434 #define DECL_SCOPE_TABLE_INCREMENT 64
435
436 /* A pointer to the base of a list of references to DIE's that
437    are uniquely identified by their tag, presence/absence of
438    children DIE's, and list of attribute/value pairs.  */
439 static dw_die_ref *abbrev_die_table;
440
441 /* Number of elements currently allocated for abbrev_die_table.  */
442 static unsigned abbrev_die_table_allocated;
443
444 /* Number of elements in type_die_table currently in use.  */
445 static unsigned abbrev_die_table_in_use;
446
447 /* Size (in elements) of increments by which we may expand the
448    abbrev_die_table.  */
449 #define ABBREV_DIE_TABLE_INCREMENT 256
450
451 /* A pointer to the base of a table that contains line information
452    for each source code line in .text in the compilation unit.  */
453 static dw_line_info_ref line_info_table;
454
455 /* Number of elements currently allocated for line_info_table.  */
456 static unsigned line_info_table_allocated;
457
458 /* Number of elements in separate_line_info_table currently in use.  */
459 static unsigned separate_line_info_table_in_use;
460
461 /* A pointer to the base of a table that contains line information
462    for each source code line outside of .text in the compilation unit.  */
463 static dw_separate_line_info_ref separate_line_info_table;
464
465 /* Number of elements currently allocated for separate_line_info_table.  */
466 static unsigned separate_line_info_table_allocated;
467
468 /* Number of elements in line_info_table currently in use.  */
469 static unsigned line_info_table_in_use;
470
471 /* Size (in elements) of increments by which we may expand the
472    line_info_table.  */
473 #define LINE_INFO_TABLE_INCREMENT 1024
474
475 /* A pointer to the base of a table that contains frame description
476    information for each routine.  */
477 static dw_fde_ref fde_table;
478
479 /* Number of elements currently allocated for fde_table.  */
480 static unsigned fde_table_allocated;
481
482 /* Number of elements in fde_table currently in use.  */
483 static unsigned fde_table_in_use;
484
485 /* Size (in elements) of increments by which we may expand the
486    fde_table.  */
487 #define FDE_TABLE_INCREMENT 256
488
489 /* A list of call frame insns for the CIE.  */
490 static dw_cfi_ref cie_cfi_head;
491
492 /* A pointer to the base of a table that contains a list of publicly
493    accessible names.  */
494 static pubname_ref pubname_table;
495
496 /* Number of elements currently allocated for pubname_table.  */
497 static unsigned pubname_table_allocated;
498
499 /* Number of elements in pubname_table currently in use.  */
500 static unsigned pubname_table_in_use;
501
502 /* Size (in elements) of increments by which we may expand the
503    pubname_table.  */
504 #define PUBNAME_TABLE_INCREMENT 64
505
506 /* A pointer to the base of a table that contains a list of publicly
507    accessible names.  */
508 static arange_ref arange_table;
509
510 /* Number of elements currently allocated for arange_table.  */
511 static unsigned arange_table_allocated;
512
513 /* Number of elements in arange_table currently in use.  */
514 static unsigned arange_table_in_use;
515
516 /* Size (in elements) of increments by which we may expand the
517    arange_table.  */
518 #define ARANGE_TABLE_INCREMENT 64
519
520 /* A pointer to the base of a list of pending types which we haven't
521    generated DIEs for yet, but which we will have to come back to
522    later on.  */
523
524 static tree *pending_types_list;
525
526 /* Number of elements currently allocated for the pending_types_list.  */
527 static unsigned pending_types_allocated;
528
529 /* Number of elements of pending_types_list currently in use.  */
530 static unsigned pending_types;
531
532 /* Size (in elements) of increments by which we may expand the pending
533    types list.  Actually, a single hunk of space of this size should
534    be enough for most typical programs.  */
535 #define PENDING_TYPES_INCREMENT 64
536
537 /* The number of the current function definition for which debugging
538    information is being generated.  These numbers range from 1 up to the
539    maximum number of function definitions contained within the current
540    compilation unit.  These numbers are used to create unique label id's
541    unique to each function definition.  */
542 static unsigned current_funcdef_number = 1;
543
544 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
545    attribute that accelerates the lookup of the FDE associated
546    with the subprogram.  This variable holds the table index of the FDE 
547    associated with the current function (body) definition.  */
548 static unsigned current_funcdef_fde;
549
550 /* Record whether the function being analyzed contains inlined functions.  */
551 static int current_function_has_inlines;
552 static int comp_unit_has_inlines;
553
554 /* A pointer to the ..._DECL node which we have most recently been working
555    on.  We keep this around just in case something about it looks screwy and
556    we want to tell the user what the source coordinates for the actual
557    declaration are.  */
558 static tree dwarf_last_decl;
559
560 /* Forward declarations for functions defined in this file.  */
561
562 static char *stripattributes            PROTO((char *));
563 static void addr_const_to_string        PROTO((char *, rtx));
564 static char *addr_to_string             PROTO((rtx));
565 static int is_pseudo_reg                PROTO((rtx));
566 static tree type_main_variant           PROTO((tree));
567 static int is_tagged_type               PROTO((tree));
568 static char *dwarf_tag_name             PROTO((unsigned));
569 static char *dwarf_attr_name            PROTO((unsigned));
570 static char *dwarf_form_name            PROTO((unsigned));
571 static char *dwarf_stack_op_name        PROTO((unsigned));
572 static char *dwarf_type_encoding_name   PROTO((unsigned));
573 static char *dward_cfi_name             PROTO((unsigned));
574 static tree decl_ultimate_origin        PROTO((tree));
575 static tree block_ultimate_origin       PROTO((tree));
576 static tree decl_class_context          PROTO((tree));
577 static void add_dwarf_attr              PROTO((dw_die_ref, dw_attr_ref));
578 static void add_AT_flag                 PROTO((dw_die_ref,
579                                                enum dwarf_attribute,
580                                                unsigned));
581 static void add_AT_int                  PROTO((dw_die_ref,
582                                                enum dwarf_attribute, long));
583 static void add_AT_unsigned             PROTO((dw_die_ref,
584                                                enum dwarf_attribute,
585                                                unsigned long));
586 static void add_AT_long_long            PROTO((dw_die_ref,
587                                                enum dwarf_attribute,
588                                                unsigned long, unsigned long));
589 static void add_AT_float                PROTO((dw_die_ref,
590                                                enum dwarf_attribute,
591                                                unsigned, long *));
592 static void add_AT_string               PROTO((dw_die_ref,
593                                                enum dwarf_attribute, char *));
594 static void add_AT_die_ref              PROTO((dw_die_ref,
595                                                enum dwarf_attribute,
596                                                dw_die_ref));
597 static void add_AT_fde_ref              PROTO((dw_die_ref,
598                                                enum dwarf_attribute,
599                                                unsigned));
600 static void add_AT_loc                  PROTO((dw_die_ref,
601                                                enum dwarf_attribute,
602                                                dw_loc_descr_ref));
603 static void add_AT_addr                 PROTO((dw_die_ref,
604                                                enum dwarf_attribute, char *));
605 static void add_AT_lbl_id               PROTO((dw_die_ref,
606                                                enum dwarf_attribute, char *));
607 static void add_AT_setion_offset        PROTO((dw_die_ref,
608                                                enum dwarf_attribute, char *));
609 static int is_extern_subr_die           PROTO((dw_die_ref));
610 static dw_attr_ref get_AT               PROTO((dw_die_ref,
611                                                enum dwarf_attribute));
612 static char *get_AT_low_pc              PROTO((dw_die_ref));
613 static char *get_AT_hi_pc               PROTO((dw_die_ref));
614 static char *get_AT_string              PROTO((dw_die_ref,
615                                                enum dwarf_attribute));
616 static int get_AT_flag                  PROTO((dw_die_ref,
617                                                enum dwarf_attribute));
618 static unsigned get_AT_unsigned         PROTO((dw_die_ref,
619                                                enum dwarf_attribute));
620 static int is_c_family                  PROTO((void));
621 static int is_fortran                   PROTO((void));
622 static void remove_AT                   PROTO((dw_die_ref,
623                                                enum dwarf_attribute));
624 static void remove_children             PROTO((dw_die_ref));
625 static void add_child_die               PROTO((dw_die_ref, dw_die_ref));
626 static dw_die_ref new_die               PROTO((enum dwarf_tag, dw_die_ref));
627 static dw_die_ref lookup_type_die       PROTO((tree));
628 static void equate_type_number_to_die   PROTO((tree, dw_die_ref));
629 static dw_die_ref lookup_decl_die       PROTO((tree));
630 static void equate_decl_number_to_die   PROTO((tree, dw_die_ref));
631 static dw_loc_descr_ref new_loc_descr   PROTO((enum dwarf_location_atom,
632                                                unsigned long, unsigned long));
633 static void add_loc_descr               PROTO((dw_loc_descr_ref *,
634                                                dw_loc_descr_ref));
635 static dw_cfi_ref new_cfe               PROTO((void));
636 static void add_cfe                     PROTO((dw_cfi_ref *, dw_cfi_ref));
637 static void print_spaces                PROTO((FILE *));
638 static void print_die                   PROTO((dw_die_ref, FILE *));
639 static void print_dwarf_line_table      PROTO((FILE *));
640 static void add_sibling_atttributes     PROTO((dw_die_ref));
641 static void build_abbrev_table          PROTO((dw_die_ref));
642 static unsigned long size_of_uleb128    PROTO((unsigned long));
643 static unsigned long size_of_sleb128    PROTO((long));
644 static unsigned long size_of_string     PROTO((char *));
645 static unsigned long size_of_loc_descr  PROTO((dw_loc_descr_ref));
646 static unsigned long size_of_locs       PROTO((dw_loc_descr_ref));
647 static int constant_size                PROTO((long unsigned));
648 static unsigned long size_of_die        PROTO((dw_die_ref));
649 static void calc_die_sizes              PROTO((dw_die_ref));
650 static unsigned long size_of_prolog     PROTO((void));
651 static unsigned long size_of_line_info  PROTO((void));
652 static unsigned long size_of_pubnames   PROTO((void));
653 static unsigned long size_of_aranges    PROTO((void));
654 static void output_uleb128              PROTO((unsigned long));
655 static void output_sleb128              PROTO((long));
656 static enum dwarf_form value_format     PROTO((dw_val_ref));
657 static void output_value_format         PROTO((dw_val_ref));
658 static void output_abbrev_section       PROTO((void));
659 static void output_loc_operands         PROTO((dw_loc_descr_ref));
660 static unsigned long sibling_offset     PROTO((dw_die_ref));
661 static void output_die                  PROTO((dw_die_ref));
662 static void output_compilation_unit_header PROTO((void));
663 static char *dwarf2out_cfi_label        PROTO((void));
664 static void add_fde_cfi                 PROTO((char *, dw_cfi_ref));
665 static void lookup_cfa_1                PROTO((dw_cfi_ref, unsigned long *,
666                                                long *));
667 static void lookup_cfa                  PROTO((unsigned long *, long *));
668 static void reg_save                    PROTO((char *, unsigned, unsigned,
669                                                long));
670 static void initial_return_save         PROTO((rtx));
671 static unsigned long size_of_cfi        PROTO((dw_cfi_ref));
672 static unsigned long size_of_fde        PROTO((dw_fde_ref, unsigned long *));
673 static void calc_fde_sizes              PROTO((void));
674 static void output_cfi                  PROTO((dw_cfi_ref, dw_fde_ref));
675 static void output_call_frame_info      PROTO((void));
676 static char *dwarf2_name                PROTO((tree, int));
677 static void add_pubname                 PROTO((tree, dw_die_ref));
678 static void output_pubnames             PROTO((void));
679 static void add_arrange                 PROTO((tree, dw_die_ref));
680 static void output_arranges             PROTO((void));
681 static void output_line_info            PROTO((void));
682 static int is_body_block                PROTO((tree));
683 static dw_die_ref base_type_die         PROTO((tree));
684 static tree root_type                   PROTO((tree));
685 static int is_base_type                 PROTO((tree));
686 static dw_die_ref modified_type_die     PROTO((tree, int, int, dw_die_ref));
687 static int type_is_enum                 PROTO((tree));
688 static unsigned reg_number              PROTO((rtx));
689 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
690 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
691 static int is_based_loc                 PROTO((rtx));
692 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
693 static dw_loc_descr_ref loc_descriptor  PROTO((rtx));
694 static unsigned ceiling                 PROTO((unsigned, unsigned));
695 static tree field_type                  PROTO((tree));
696 static unsigned simple_type_align_in_bits PROTO((tree));
697 static unsigned simple_type_size_in_bits PROTO((tree));
698 static unsigned field_byte_offset               PROTO((tree));
699 static void add_location_attribute      PROTO((dw_die_ref, rtx));
700 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
701 static void add_const_value_attribute   PROTO((dw_die_ref, rtx));
702 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
703 static void add_name_attribute          PROTO((dw_die_ref, char *));
704 static void add_bound_info              PROTO((dw_die_ref,
705                                                enum dwarf_attribute, tree));
706 static void add_subscript_info          PROTO((dw_die_ref, tree));
707 static void add_byte_size_attribute     PROTO((dw_die_ref, tree));
708 static void add_bit_offset_attribute    PROTO((dw_die_ref, tree));
709 static void add_bit_size_attribute      PROTO((dw_die_ref, tree));
710 static void add_prototyped_attribute    PROTO((dw_die_ref, tree));
711 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
712 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
713 static void add_src_coords_attributes   PROTO((dw_die_ref, tree));
714 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
715 static void push_decl_scope             PROTO((tree));
716 static dw_die_ref scope_die_for         PROTO((tree, dw_die_ref));
717 static void pop_decl_scope              PROTO((void));
718 static void add_type_attribute          PROTO((dw_die_ref, tree, int, int,
719                                                dw_die_ref));
720 static char *type_tag                   PROTO((tree));
721 static tree member_declared_type        PROTO((tree));
722 static char *decl_start_label           PROTO((tree));
723 static void gen_arrqay_type_die         PROTO((tree, dw_die_ref));
724 static void gen_set_type_die            PROTO((tree, dw_die_ref));
725 static void gen_entry_point_die         PROTO((tree, dw_die_ref));
726 static void pend_type                   PROTO((tree));
727 static void output_pending_types_for_scope PROTO((dw_die_ref));
728 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
729 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
730 static void gen_inlined_union_type_die  PROTO((tree, dw_die_ref));
731 static void gen_enumeration_type_die    PROTO((tree, dw_die_ref));
732 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
733 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
734 static void gen_formal_types_die        PROTO((tree, dw_die_ref));
735 static void gen_subprogram_die          PROTO((tree, dw_die_ref));
736 static void gen_variable_die            PROTO((tree, dw_die_ref));
737 static void gen_labeld_die              PROTO((tree, dw_die_ref));
738 static void gen_lexical_block_die       PROTO((tree, dw_die_ref, int));
739 static void gen_inlined_subprogram_die  PROTO((tree, dw_die_ref, int));
740 static void gen_field_die               PROTO((tree, dw_die_ref));
741 static void gen_ptr_to_mbr_type_die     PROTO((tree, dw_die_ref));
742 static void gen_compile_unit_die        PROTO((char *));
743 static void gen_string_type_die         PROTO((tree, dw_die_ref));
744 static void gen_inheritance_die         PROTO((tree, dw_die_ref));
745 static void gen_member_die              PROTO((tree, dw_die_ref));
746 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
747 static void gen_subroutine_type_die     PROTO((tree, dw_die_ref));
748 static void gen_typedef_die             PROTO((tree, dw_die_ref));
749 static void gen_type_die                PROTO((tree, dw_die_ref));
750 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
751 static void gen_block_die               PROTO((tree, dw_die_ref, int));
752 static void decls_for_scope             PROTO((tree, dw_die_ref, int));
753 static int is_redundant_typedef         PROTO((tree));
754 static void gen_decl_die                PROTO((tree, dw_die_ref));
755 static unsigned lookup_filename         PROTO((char *));
756
757 /* Definitions of defaults for assembler-dependent names of various
758    pseudo-ops and section names.
759    Theses may be overridden in the tm.h file (if necessary) for a particular
760    assembler.  */
761
762 #ifndef UNALIGNED_SHORT_ASM_OP
763 #define UNALIGNED_SHORT_ASM_OP  ".2byte"
764 #endif
765 #ifndef UNALIGNED_INT_ASM_OP
766 #define UNALIGNED_INT_ASM_OP    ".4byte"
767 #endif
768 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
769 #define UNALIGNED_DOUBLE_INT_ASM_OP     ".8byte"
770 #endif
771 #ifndef ASM_BYTE_OP
772 #define ASM_BYTE_OP             ".byte"
773 #endif
774
775 #ifndef UNALIGNED_OFFSET_ASM_OP
776 #define UNALIGNED_OFFSET_ASM_OP \
777   (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
778 #endif
779
780 #ifndef UNALIGNED_WORD_ASM_OP
781 #define UNALIGNED_WORD_ASM_OP \
782   (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
783 #endif
784
785 /* Data and reference forms for relocatable data.  */
786 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
787 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
788
789 /* Pseudo-op for defining a new section.  */
790 #ifndef SECTION_ASM_OP
791 #define SECTION_ASM_OP  ".section"
792 #endif
793
794 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
795    print the SECTION_ASM_OP and the section name.  The default here works for
796    almost all svr4 assemblers, except for the sparc, where the section name
797    must be enclosed in double quotes.  (See sparcv4.h).  */
798 #ifndef SECTION_FORMAT
799 #define SECTION_FORMAT  "\t%s\t%s\n"
800 #endif
801
802 /* Section names used to hold DWARF debugging information.  */
803 #ifndef DEBUG_SECTION
804 #define DEBUG_SECTION           ".debug_info"
805 #endif
806 #ifndef ABBREV_SECTION
807 #define ABBREV_SECTION          ".debug_abbrev"
808 #endif
809 #ifndef ARANGES_SECTION
810 #define ARANGES_SECTION         ".debug_aranges"
811 #endif
812 #ifndef DW_MACINFO_SECTION
813 #define DW_MACINFO_SECTION      ".debug_macinfo"
814 #endif
815 #ifndef FRAME_SECTION
816 #define FRAME_SECTION           ".debug_frame"
817 #endif
818 #ifndef LINE_SECTION
819 #define LINE_SECTION            ".debug_line"
820 #endif
821 #ifndef LOC_SECTION
822 #define LOC_SECTION             ".debug_loc"
823 #endif
824 #ifndef PUBNAMES_SECTION
825 #define PUBNAMES_SECTION        ".debug_pubnames"
826 #endif
827 #ifndef STR_SECTION
828 #define STR_SECTION             ".debug_str"
829 #endif
830
831 /* Standerd ELF section names for compiled code and data.  */
832 #ifndef TEXT_SECTION
833 #define TEXT_SECTION            ".text"
834 #endif
835 #ifndef DATA_SECTION
836 #define DATA_SECTION            ".data"
837 #endif
838 #ifndef BSS_SECTION
839 #define BSS_SECTION             ".bss"
840 #endif
841
842
843 /* Definitions of defaults for formats and names of various special
844    (artificial) labels which may be generated within this file (when the -g
845    options is used and DWARF_DEBUGGING_INFO is in effect.
846    If necessary, these may be overridden from within the tm.h file, but
847    typically, overriding these defaults is unnecessary.  */
848
849 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
850
851 #ifndef TEXT_END_LABEL
852 #define TEXT_END_LABEL          "Letext"
853 #endif
854 #ifndef DATA_END_LABEL
855 #define DATA_END_LABEL          "Ledata"
856 #endif
857 #ifndef BSS_END_LABEL
858 #define BSS_END_LABEL           "Lebss"
859 #endif
860 #ifndef INSN_LABEL_FMT
861 #define INSN_LABEL_FMT          "LI%u_"
862 #endif
863 #ifndef BLOCK_BEGIN_LABEL
864 #define BLOCK_BEGIN_LABEL       "LBB"
865 #endif
866 #ifndef BLOCK_END_LABEL
867 #define BLOCK_END_LABEL         "LBE"
868 #endif
869 #ifndef BODY_BEGIN_LABEL
870 #define BODY_BEGIN_LABEL        "Lbb"
871 #endif
872 #ifndef BODY_END_LABEL
873 #define BODY_END_LABEL          "Lbe"
874 #endif
875 #ifndef FUNC_BEGIN_LABEL
876 #define FUNC_BEGIN_LABEL        "LFB"
877 #endif
878 #ifndef FUNC_END_LABEL
879 #define FUNC_END_LABEL          "LFE"
880 #endif
881 #ifndef LINE_CODE_LABEL
882 #define LINE_CODE_LABEL         "LM"
883 #endif
884 #ifndef SEPARATE_LINE_CODE_LABEL
885 #define SEPARATE_LINE_CODE_LABEL        "LSM"
886 #endif
887
888 /* Definitions of defaults for various types of primitive assembly language
889    output operations.  These may be overridden from within the tm.h file,
890    but typically, that is unecessary.  */
891
892 #ifndef ASM_OUTPUT_SECTION
893 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
894   fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
895 #endif
896
897 #ifndef ASM_OUTPUT_DWARF_DELTA2
898 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
899  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);             \
900         assemble_name (FILE, LABEL1);                                   \
901         fprintf (FILE, "-");                                            \
902         assemble_name (FILE, LABEL2);                                   \
903   } while (0)
904 #endif
905
906 #ifndef ASM_OUTPUT_DWARF_DELTA4
907 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
908  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
909         assemble_name (FILE, LABEL1);                                   \
910         fprintf (FILE, "-");                                            \
911         assemble_name (FILE, LABEL2);                                   \
912   } while (0)
913 #endif
914
915 #ifndef ASM_OUTPUT_DWARF_DELTA
916 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2)                      \
917  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP);            \
918         assemble_name (FILE, LABEL1);                                   \
919         fprintf (FILE, "-");                                            \
920         assemble_name (FILE, LABEL2);                                   \
921   } while (0)
922 #endif
923
924 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
925 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2)                 \
926  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP);              \
927         assemble_name (FILE, LABEL1);                                   \
928         fprintf (FILE, "-");                                            \
929         assemble_name (FILE, LABEL2);                                   \
930   } while (0)
931 #endif
932
933 #ifndef ASM_OUTPUT_DWARF_ADDR
934 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
935  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP);              \
936         assemble_name (FILE, LABEL);                                    \
937   } while (0)
938 #endif
939
940 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
941 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR)                          \
942   fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
943 #endif
944
945 #ifndef ASM_OUTPUT_DWARF_OFFSET
946 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL)                             \
947  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP);            \
948         assemble_name (FILE, LABEL);                                    \
949   } while (0)
950 #endif
951
952 #ifndef ASM_OUTPUT_DWARF_DATA1
953 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
954   fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
955 #endif
956
957 #ifndef ASM_OUTPUT_DWARF_DATA2
958 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
959   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
960 #endif
961
962 #ifndef ASM_OUTPUT_DWARF_DATA4
963 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
964   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
965 #endif
966
967 #ifndef ASM_OUTPUT_DWARF_DATA
968 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
969   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
970            (unsigned long) VALUE)
971 #endif
972
973 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
974 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
975   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
976            (unsigned long) VALUE)
977 #endif
978
979 #ifndef ASM_OUTPUT_DWARF_DATA8
980 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
981   do {                                                                  \
982     if (WORDS_BIG_ENDIAN)                                               \
983       {                                                                 \
984         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
985         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
986       }                                                                 \
987     else                                                                \
988       {                                                                 \
989         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
990         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
991       }                                                                 \
992   } while (0)
993 #endif
994
995 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
996    newline is produced.  When flag_verbose_asm is asserted, we add commnetary
997    at the end of the line, so we must avoid output of a newline here.  */
998 #ifndef ASM_OUTPUT_DWARF_STRING
999 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
1000   do {                                                                        \
1001     register int slen = strlen(P);                                            \
1002     register char *p = (P);                                                   \
1003     register int i;                                                           \
1004     fprintf (FILE, "\t.ascii \"");                                            \
1005     for (i = 0; i < slen; i++)                                                \
1006       {                                                                       \
1007           register int c = p[i];                                              \
1008           if (c == '\"' || c == '\\')                                         \
1009             putc ('\\', FILE);                                                \
1010           if (c >= ' ' && c < 0177)                                           \
1011             putc (c, FILE);                                                   \
1012           else                                                                \
1013             {                                                                 \
1014               fprintf (FILE, "\\%o", c);                                      \
1015             }                                                                 \
1016       }                                                                       \
1017     fprintf (FILE, "\\0\"");                                                  \
1018   }                                                                           \
1019   while (0)
1020 #endif
1021
1022 /* Convert a reference to the assembler name of a C-level name.  This
1023    macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
1024    a string rather than writing to a file.  */
1025 #ifndef ASM_NAME_TO_STRING
1026 #define ASM_NAME_TO_STRING(STR, NAME) \
1027   do {                                                                        \
1028       if ((NAME)[0] == '*')                                                   \
1029         strcpy (STR, NAME+1);                                                 \
1030       else                                                                    \
1031         strcpy (STR, NAME);                                                   \
1032   }                                                                           \
1033   while (0)
1034 #endif
1035
1036 /* The DWARF 2 CFA column which tracks the return address.  Normally this
1037    is the column for PC, or the first column after all of the hard
1038    registers.  */
1039 #ifndef DWARF_FRAME_RETURN_COLUMN
1040 #ifdef PC_REGNUM
1041 #define DWARF_FRAME_RETURN_COLUMN       DWARF_FRAME_REGNUM (PC_REGNUM)
1042 #else
1043 #define DWARF_FRAME_RETURN_COLUMN       FIRST_PSEUDO_REGISTER
1044 #endif
1045 #endif
1046
1047 /* The mapping from gcc register number to DWARF 2 CFA column number.  By
1048    default, we just provide columns for all registers.  */
1049 #ifndef DWARF_FRAME_REGNUM
1050 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
1051 #endif
1052 \f
1053 /* Return a pointer to a copy of the section string name S with all
1054    attributes stripped off.  */
1055
1056 static inline char *
1057 stripattributes (s)
1058      char *s;
1059 {
1060   char *stripped = xstrdup (s);
1061   char *p = stripped;
1062
1063   while (*p && *p != ',')
1064     p++;
1065
1066   *p = '\0';
1067   return stripped;
1068 }
1069
1070 /* Convert an integer constant expression into assembler syntax.  Addition
1071    and subtraction are the only arithmetic that may appear in these
1072    expressions.   This is an adaptation of output_addr_const in final.c.
1073    Here, the target of the conversion is a string buffer.  We can't use
1074    output_addr_const directly, because it writes to a file.  */
1075
1076 static void
1077 addr_const_to_string (str, x)
1078      char *str;
1079      rtx x;
1080 {
1081   char buf1[256];
1082   char buf2[256];
1083
1084 restart:
1085   str[0] = '\0';
1086   switch (GET_CODE (x))
1087     {
1088     case PC:
1089       if (flag_pic)
1090         strcat (str, ",");
1091       else
1092         abort ();
1093       break;
1094
1095     case SYMBOL_REF:
1096       ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
1097       strcat (str, buf1);
1098       break;
1099
1100     case LABEL_REF:
1101       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1102       ASM_NAME_TO_STRING (buf2, buf1);
1103       strcat (str, buf2);
1104       break;
1105
1106     case CODE_LABEL:
1107       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
1108       ASM_NAME_TO_STRING (buf2, buf1);
1109       strcat (str, buf2);
1110       break;
1111
1112     case CONST_INT:
1113       sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
1114       strcat (str, buf1);
1115       break;
1116
1117     case CONST:
1118       /* This used to output parentheses around the expression, but that does 
1119          not work on the 386 (either ATT or BSD assembler).  */
1120       addr_const_to_string (buf1, XEXP (x, 0));
1121       strcat (str, buf1);
1122       break;
1123
1124     case CONST_DOUBLE:
1125       if (GET_MODE (x) == VOIDmode)
1126         {
1127           /* We can use %d if the number is one word and positive.  */
1128           if (CONST_DOUBLE_HIGH (x))
1129             sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1130                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
1131           else if (CONST_DOUBLE_LOW (x) < 0)
1132             sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
1133           else
1134             sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
1135                      CONST_DOUBLE_LOW (x));
1136           strcat (str, buf1);
1137         }
1138       else
1139         /* We can't handle floating point constants; PRINT_OPERAND must
1140            handle them.  */
1141         output_operand_lossage ("floating constant misused");
1142       break;
1143
1144     case PLUS:
1145       /* Some assemblers need integer constants to appear last (eg masm).  */
1146       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1147         {
1148           addr_const_to_string (buf1, XEXP (x, 1));
1149           strcat (str, buf1);
1150           if (INTVAL (XEXP (x, 0)) >= 0)
1151             strcat (str, "+");
1152
1153           addr_const_to_string (buf1, XEXP (x, 0));
1154           strcat (str, buf1);
1155         }
1156       else
1157         {
1158           addr_const_to_string (buf1, XEXP (x, 0));
1159           strcat (str, buf1);
1160           if (INTVAL (XEXP (x, 1)) >= 0)
1161             strcat (str, "+");
1162
1163           addr_const_to_string (buf1, XEXP (x, 1));
1164           strcat (str, buf1);
1165         }
1166       break;
1167
1168     case MINUS:
1169       /* Avoid outputting things like x-x or x+5-x, since some assemblers
1170          can't handle that.  */
1171       x = simplify_subtraction (x);
1172       if (GET_CODE (x) != MINUS)
1173         goto restart;
1174
1175       addr_const_to_string (buf1, XEXP (x, 0));
1176       strcat (str, buf1);
1177       strcat (str, "-");
1178       if (GET_CODE (XEXP (x, 1)) == CONST_INT
1179           && INTVAL (XEXP (x, 1)) < 0)
1180         {
1181           strcat (str, ASM_OPEN_PAREN);
1182           addr_const_to_string (buf1, XEXP (x, 1));
1183           strcat (str, buf1);
1184           strcat (str, ASM_CLOSE_PAREN);
1185         }
1186       else
1187         {
1188           addr_const_to_string (buf1, XEXP (x, 1));
1189           strcat (str, buf1);
1190         }
1191       break;
1192
1193     case ZERO_EXTEND:
1194     case SIGN_EXTEND:
1195       addr_const_to_string (buf1, XEXP (x, 0));
1196       strcat (str, buf1);
1197       break;
1198
1199     default:
1200       output_operand_lossage ("invalid expression as operand");
1201     }
1202 }
1203
1204 /* Convert an address constant to a string, and return a pointer to
1205    a copy of the result, located on the heap.  */
1206
1207 static char *
1208 addr_to_string (x)
1209      rtx x;
1210 {
1211   char buf[1024];
1212   addr_const_to_string (buf, x);
1213   return xstrdup (buf);
1214 }
1215
1216 /* Test if rtl node points to a psuedo register.  */
1217
1218 static inline int
1219 is_pseudo_reg (rtl)
1220      register rtx rtl;
1221 {
1222   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1223           || ((GET_CODE (rtl) == SUBREG)
1224               && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1225 }
1226
1227 /* Return a reference to a type, with its const and volatile qualifiers
1228    removed.  */
1229
1230 static inline tree
1231 type_main_variant (type)
1232      register tree type;
1233 {
1234   type = TYPE_MAIN_VARIANT (type);
1235
1236   /* There really should be only one main variant among any group of variants 
1237      of a given type (and all of the MAIN_VARIANT values for all members of
1238      the group should point to that one type) but sometimes the C front-end
1239      messes this up for array types, so we work around that bug here.  */
1240
1241   if (TREE_CODE (type) == ARRAY_TYPE)
1242     while (type != TYPE_MAIN_VARIANT (type))
1243       type = TYPE_MAIN_VARIANT (type);
1244
1245   return type;
1246 }
1247
1248 /* Return non-zero if the given type node represents a tagged type.  */
1249
1250 static inline int
1251 is_tagged_type (type)
1252      register tree type;
1253 {
1254   register enum tree_code code = TREE_CODE (type);
1255
1256   return (code == RECORD_TYPE || code == UNION_TYPE
1257           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1258 }
1259
1260 /* Convert a DIE tag into its string name.  */
1261
1262 static char *
1263 dwarf_tag_name (tag)
1264      register unsigned tag;
1265 {
1266   switch (tag)
1267     {
1268     case DW_TAG_padding:
1269       return "DW_TAG_padding";
1270     case DW_TAG_array_type:
1271       return "DW_TAG_array_type";
1272     case DW_TAG_class_type:
1273       return "DW_TAG_class_type";
1274     case DW_TAG_entry_point:
1275       return "DW_TAG_entry_point";
1276     case DW_TAG_enumeration_type:
1277       return "DW_TAG_enumeration_type";
1278     case DW_TAG_formal_parameter:
1279       return "DW_TAG_formal_parameter";
1280     case DW_TAG_imported_declaration:
1281       return "DW_TAG_imported_declaration";
1282     case DW_TAG_label:
1283       return "DW_TAG_label";
1284     case DW_TAG_lexical_block:
1285       return "DW_TAG_lexical_block";
1286     case DW_TAG_member:
1287       return "DW_TAG_member";
1288     case DW_TAG_pointer_type:
1289       return "DW_TAG_pointer_type";
1290     case DW_TAG_reference_type:
1291       return "DW_TAG_reference_type";
1292     case DW_TAG_compile_unit:
1293       return "DW_TAG_compile_unit";
1294     case DW_TAG_string_type:
1295       return "DW_TAG_string_type";
1296     case DW_TAG_structure_type:
1297       return "DW_TAG_structure_type";
1298     case DW_TAG_subroutine_type:
1299       return "DW_TAG_subroutine_type";
1300     case DW_TAG_typedef:
1301       return "DW_TAG_typedef";
1302     case DW_TAG_union_type:
1303       return "DW_TAG_union_type";
1304     case DW_TAG_unspecified_parameters:
1305       return "DW_TAG_unspecified_parameters";
1306     case DW_TAG_variant:
1307       return "DW_TAG_variant";
1308     case DW_TAG_common_block:
1309       return "DW_TAG_common_block";
1310     case DW_TAG_common_inclusion:
1311       return "DW_TAG_common_inclusion";
1312     case DW_TAG_inheritance:
1313       return "DW_TAG_inheritance";
1314     case DW_TAG_inlined_subroutine:
1315       return "DW_TAG_inlined_subroutine";
1316     case DW_TAG_module:
1317       return "DW_TAG_module";
1318     case DW_TAG_ptr_to_member_type:
1319       return "DW_TAG_ptr_to_member_type";
1320     case DW_TAG_set_type:
1321       return "DW_TAG_set_type";
1322     case DW_TAG_subrange_type:
1323       return "DW_TAG_subrange_type";
1324     case DW_TAG_with_stmt:
1325       return "DW_TAG_with_stmt";
1326     case DW_TAG_access_declaration:
1327       return "DW_TAG_access_declaration";
1328     case DW_TAG_base_type:
1329       return "DW_TAG_base_type";
1330     case DW_TAG_catch_block:
1331       return "DW_TAG_catch_block";
1332     case DW_TAG_const_type:
1333       return "DW_TAG_const_type";
1334     case DW_TAG_constant:
1335       return "DW_TAG_constant";
1336     case DW_TAG_enumerator:
1337       return "DW_TAG_enumerator";
1338     case DW_TAG_file_type:
1339       return "DW_TAG_file_type";
1340     case DW_TAG_friend:
1341       return "DW_TAG_friend";
1342     case DW_TAG_namelist:
1343       return "DW_TAG_namelist";
1344     case DW_TAG_namelist_item:
1345       return "DW_TAG_namelist_item";
1346     case DW_TAG_packed_type:
1347       return "DW_TAG_packed_type";
1348     case DW_TAG_subprogram:
1349       return "DW_TAG_subprogram";
1350     case DW_TAG_template_type_param:
1351       return "DW_TAG_template_type_param";
1352     case DW_TAG_template_value_param:
1353       return "DW_TAG_template_value_param";
1354     case DW_TAG_thrown_type:
1355       return "DW_TAG_thrown_type";
1356     case DW_TAG_try_block:
1357       return "DW_TAG_try_block";
1358     case DW_TAG_variant_part:
1359       return "DW_TAG_variant_part";
1360     case DW_TAG_variable:
1361       return "DW_TAG_variable";
1362     case DW_TAG_volatile_type:
1363       return "DW_TAG_volatile_type";
1364     case DW_TAG_MIPS_loop:
1365       return "DW_TAG_MIPS_loop";
1366     case DW_TAG_format_label:
1367       return "DW_TAG_format_label";
1368     case DW_TAG_function_template:
1369       return "DW_TAG_function_template";
1370     case DW_TAG_class_template:
1371       return "DW_TAG_class_template";
1372     default:
1373       return "DW_TAG_<unknown>";
1374     }
1375 }
1376
1377 /* Convert a DWARF attribute code into its string name.  */
1378
1379 static char *
1380 dwarf_attr_name (attr)
1381      register unsigned attr;
1382 {
1383   switch (attr)
1384     {
1385     case DW_AT_sibling:
1386       return "DW_AT_sibling";
1387     case DW_AT_location:
1388       return "DW_AT_location";
1389     case DW_AT_name:
1390       return "DW_AT_name";
1391     case DW_AT_ordering:
1392       return "DW_AT_ordering";
1393     case DW_AT_subscr_data:
1394       return "DW_AT_subscr_data";
1395     case DW_AT_byte_size:
1396       return "DW_AT_byte_size";
1397     case DW_AT_bit_offset:
1398       return "DW_AT_bit_offset";
1399     case DW_AT_bit_size:
1400       return "DW_AT_bit_size";
1401     case DW_AT_element_list:
1402       return "DW_AT_element_list";
1403     case DW_AT_stmt_list:
1404       return "DW_AT_stmt_list";
1405     case DW_AT_low_pc:
1406       return "DW_AT_low_pc";
1407     case DW_AT_high_pc:
1408       return "DW_AT_high_pc";
1409     case DW_AT_language:
1410       return "DW_AT_language";
1411     case DW_AT_member:
1412       return "DW_AT_member";
1413     case DW_AT_discr:
1414       return "DW_AT_discr";
1415     case DW_AT_discr_value:
1416       return "DW_AT_discr_value";
1417     case DW_AT_visibility:
1418       return "DW_AT_visibility";
1419     case DW_AT_import:
1420       return "DW_AT_import";
1421     case DW_AT_string_length:
1422       return "DW_AT_string_length";
1423     case DW_AT_common_reference:
1424       return "DW_AT_common_reference";
1425     case DW_AT_comp_dir:
1426       return "DW_AT_comp_dir";
1427     case DW_AT_const_value:
1428       return "DW_AT_const_value";
1429     case DW_AT_containing_type:
1430       return "DW_AT_containing_type";
1431     case DW_AT_default_value:
1432       return "DW_AT_default_value";
1433     case DW_AT_inline:
1434       return "DW_AT_inline";
1435     case DW_AT_is_optional:
1436       return "DW_AT_is_optional";
1437     case DW_AT_lower_bound:
1438       return "DW_AT_lower_bound";
1439     case DW_AT_producer:
1440       return "DW_AT_producer";
1441     case DW_AT_prototyped:
1442       return "DW_AT_prototyped";
1443     case DW_AT_return_addr:
1444       return "DW_AT_return_addr";
1445     case DW_AT_start_scope:
1446       return "DW_AT_start_scope";
1447     case DW_AT_stride_size:
1448       return "DW_AT_stride_size";
1449     case DW_AT_upper_bound:
1450       return "DW_AT_upper_bound";
1451     case DW_AT_abstract_origin:
1452       return "DW_AT_abstract_origin";
1453     case DW_AT_accessibility:
1454       return "DW_AT_accessibility";
1455     case DW_AT_address_class:
1456       return "DW_AT_address_class";
1457     case DW_AT_artificial:
1458       return "DW_AT_artificial";
1459     case DW_AT_base_types:
1460       return "DW_AT_base_types";
1461     case DW_AT_calling_convention:
1462       return "DW_AT_calling_convention";
1463     case DW_AT_count:
1464       return "DW_AT_count";
1465     case DW_AT_data_member_location:
1466       return "DW_AT_data_member_location";
1467     case DW_AT_decl_column:
1468       return "DW_AT_decl_column";
1469     case DW_AT_decl_file:
1470       return "DW_AT_decl_file";
1471     case DW_AT_decl_line:
1472       return "DW_AT_decl_line";
1473     case DW_AT_declaration:
1474       return "DW_AT_declaration";
1475     case DW_AT_discr_list:
1476       return "DW_AT_discr_list";
1477     case DW_AT_encoding:
1478       return "DW_AT_encoding";
1479     case DW_AT_external:
1480       return "DW_AT_external";
1481     case DW_AT_frame_base:
1482       return "DW_AT_frame_base";
1483     case DW_AT_friend:
1484       return "DW_AT_friend";
1485     case DW_AT_identifier_case:
1486       return "DW_AT_identifier_case";
1487     case DW_AT_macro_info:
1488       return "DW_AT_macro_info";
1489     case DW_AT_namelist_items:
1490       return "DW_AT_namelist_items";
1491     case DW_AT_priority:
1492       return "DW_AT_priority";
1493     case DW_AT_segment:
1494       return "DW_AT_segment";
1495     case DW_AT_specification:
1496       return "DW_AT_specification";
1497     case DW_AT_static_link:
1498       return "DW_AT_static_link";
1499     case DW_AT_type:
1500       return "DW_AT_type";
1501     case DW_AT_use_location:
1502       return "DW_AT_use_location";
1503     case DW_AT_variable_parameter:
1504       return "DW_AT_variable_parameter";
1505     case DW_AT_virtuality:
1506       return "DW_AT_virtuality";
1507     case DW_AT_vtable_elem_location:
1508       return "DW_AT_vtable_elem_location";
1509
1510     case DW_AT_MIPS_fde:
1511       return "DW_AT_MIPS_fde";
1512     case DW_AT_MIPS_loop_begin:
1513       return "DW_AT_MIPS_loop_begin";
1514     case DW_AT_MIPS_tail_loop_begin:
1515       return "DW_AT_MIPS_tail_loop_begin";
1516     case DW_AT_MIPS_epilog_begin:
1517       return "DW_AT_MIPS_epilog_begin";
1518     case DW_AT_MIPS_loop_unroll_factor:
1519       return "DW_AT_MIPS_loop_unroll_factor";
1520     case DW_AT_MIPS_software_pipeline_depth:
1521       return "DW_AT_MIPS_software_pipeline_depth";
1522     case DW_AT_MIPS_linkage_name:
1523       return "DW_AT_MIPS_linkage_name";
1524     case DW_AT_MIPS_stride:
1525       return "DW_AT_MIPS_stride";
1526     case DW_AT_MIPS_abstract_name:
1527       return "DW_AT_MIPS_abstract_name";
1528     case DW_AT_MIPS_clone_origin:
1529       return "DW_AT_MIPS_clone_origin";
1530     case DW_AT_MIPS_has_inlines:
1531       return "DW_AT_MIPS_has_inlines";
1532
1533     case DW_AT_sf_names:
1534       return "DW_AT_sf_names";
1535     case DW_AT_src_info:
1536       return "DW_AT_src_info";
1537     case DW_AT_mac_info:
1538       return "DW_AT_mac_info";
1539     case DW_AT_src_coords:
1540       return "DW_AT_src_coords";
1541     case DW_AT_body_begin:
1542       return "DW_AT_body_begin";
1543     case DW_AT_body_end:
1544       return "DW_AT_body_end";
1545     default:
1546       return "DW_AT_<unknown>";
1547     }
1548 }
1549
1550 /* Convert a DWARF value form code into its string name.  */
1551
1552 static char *
1553 dwarf_form_name (form)
1554      register unsigned form;
1555 {
1556   switch (form)
1557     {
1558     case DW_FORM_addr:
1559       return "DW_FORM_addr";
1560     case DW_FORM_block2:
1561       return "DW_FORM_block2";
1562     case DW_FORM_block4:
1563       return "DW_FORM_block4";
1564     case DW_FORM_data2:
1565       return "DW_FORM_data2";
1566     case DW_FORM_data4:
1567       return "DW_FORM_data4";
1568     case DW_FORM_data8:
1569       return "DW_FORM_data8";
1570     case DW_FORM_string:
1571       return "DW_FORM_string";
1572     case DW_FORM_block:
1573       return "DW_FORM_block";
1574     case DW_FORM_block1:
1575       return "DW_FORM_block1";
1576     case DW_FORM_data1:
1577       return "DW_FORM_data1";
1578     case DW_FORM_flag:
1579       return "DW_FORM_flag";
1580     case DW_FORM_sdata:
1581       return "DW_FORM_sdata";
1582     case DW_FORM_strp:
1583       return "DW_FORM_strp";
1584     case DW_FORM_udata:
1585       return "DW_FORM_udata";
1586     case DW_FORM_ref_addr:
1587       return "DW_FORM_ref_addr";
1588     case DW_FORM_ref1:
1589       return "DW_FORM_ref1";
1590     case DW_FORM_ref2:
1591       return "DW_FORM_ref2";
1592     case DW_FORM_ref4:
1593       return "DW_FORM_ref4";
1594     case DW_FORM_ref8:
1595       return "DW_FORM_ref8";
1596     case DW_FORM_ref_udata:
1597       return "DW_FORM_ref_udata";
1598     case DW_FORM_indirect:
1599       return "DW_FORM_indirect";
1600     default:
1601       return "DW_FORM_<unknown>";
1602     }
1603 }
1604
1605 /* Convert a DWARF stack opcode into its string name.  */
1606
1607 static char *
1608 dwarf_stack_op_name (op)
1609      register unsigned op;
1610 {
1611   switch (op)
1612     {
1613     case DW_OP_addr:
1614       return "DW_OP_addr";
1615     case DW_OP_deref:
1616       return "DW_OP_deref";
1617     case DW_OP_const1u:
1618       return "DW_OP_const1u";
1619     case DW_OP_const1s:
1620       return "DW_OP_const1s";
1621     case DW_OP_const2u:
1622       return "DW_OP_const2u";
1623     case DW_OP_const2s:
1624       return "DW_OP_const2s";
1625     case DW_OP_const4u:
1626       return "DW_OP_const4u";
1627     case DW_OP_const4s:
1628       return "DW_OP_const4s";
1629     case DW_OP_const8u:
1630       return "DW_OP_const8u";
1631     case DW_OP_const8s:
1632       return "DW_OP_const8s";
1633     case DW_OP_constu:
1634       return "DW_OP_constu";
1635     case DW_OP_consts:
1636       return "DW_OP_consts";
1637     case DW_OP_dup:
1638       return "DW_OP_dup";
1639     case DW_OP_drop:
1640       return "DW_OP_drop";
1641     case DW_OP_over:
1642       return "DW_OP_over";
1643     case DW_OP_pick:
1644       return "DW_OP_pick";
1645     case DW_OP_swap:
1646       return "DW_OP_swap";
1647     case DW_OP_rot:
1648       return "DW_OP_rot";
1649     case DW_OP_xderef:
1650       return "DW_OP_xderef";
1651     case DW_OP_abs:
1652       return "DW_OP_abs";
1653     case DW_OP_and:
1654       return "DW_OP_and";
1655     case DW_OP_div:
1656       return "DW_OP_div";
1657     case DW_OP_minus:
1658       return "DW_OP_minus";
1659     case DW_OP_mod:
1660       return "DW_OP_mod";
1661     case DW_OP_mul:
1662       return "DW_OP_mul";
1663     case DW_OP_neg:
1664       return "DW_OP_neg";
1665     case DW_OP_not:
1666       return "DW_OP_not";
1667     case DW_OP_or:
1668       return "DW_OP_or";
1669     case DW_OP_plus:
1670       return "DW_OP_plus";
1671     case DW_OP_plus_uconst:
1672       return "DW_OP_plus_uconst";
1673     case DW_OP_shl:
1674       return "DW_OP_shl";
1675     case DW_OP_shr:
1676       return "DW_OP_shr";
1677     case DW_OP_shra:
1678       return "DW_OP_shra";
1679     case DW_OP_xor:
1680       return "DW_OP_xor";
1681     case DW_OP_bra:
1682       return "DW_OP_bra";
1683     case DW_OP_eq:
1684       return "DW_OP_eq";
1685     case DW_OP_ge:
1686       return "DW_OP_ge";
1687     case DW_OP_gt:
1688       return "DW_OP_gt";
1689     case DW_OP_le:
1690       return "DW_OP_le";
1691     case DW_OP_lt:
1692       return "DW_OP_lt";
1693     case DW_OP_ne:
1694       return "DW_OP_ne";
1695     case DW_OP_skip:
1696       return "DW_OP_skip";
1697     case DW_OP_lit0:
1698       return "DW_OP_lit0";
1699     case DW_OP_lit1:
1700       return "DW_OP_lit1";
1701     case DW_OP_lit2:
1702       return "DW_OP_lit2";
1703     case DW_OP_lit3:
1704       return "DW_OP_lit3";
1705     case DW_OP_lit4:
1706       return "DW_OP_lit4";
1707     case DW_OP_lit5:
1708       return "DW_OP_lit5";
1709     case DW_OP_lit6:
1710       return "DW_OP_lit6";
1711     case DW_OP_lit7:
1712       return "DW_OP_lit7";
1713     case DW_OP_lit8:
1714       return "DW_OP_lit8";
1715     case DW_OP_lit9:
1716       return "DW_OP_lit9";
1717     case DW_OP_lit10:
1718       return "DW_OP_lit10";
1719     case DW_OP_lit11:
1720       return "DW_OP_lit11";
1721     case DW_OP_lit12:
1722       return "DW_OP_lit12";
1723     case DW_OP_lit13:
1724       return "DW_OP_lit13";
1725     case DW_OP_lit14:
1726       return "DW_OP_lit14";
1727     case DW_OP_lit15:
1728       return "DW_OP_lit15";
1729     case DW_OP_lit16:
1730       return "DW_OP_lit16";
1731     case DW_OP_lit17:
1732       return "DW_OP_lit17";
1733     case DW_OP_lit18:
1734       return "DW_OP_lit18";
1735     case DW_OP_lit19:
1736       return "DW_OP_lit19";
1737     case DW_OP_lit20:
1738       return "DW_OP_lit20";
1739     case DW_OP_lit21:
1740       return "DW_OP_lit21";
1741     case DW_OP_lit22:
1742       return "DW_OP_lit22";
1743     case DW_OP_lit23:
1744       return "DW_OP_lit23";
1745     case DW_OP_lit24:
1746       return "DW_OP_lit24";
1747     case DW_OP_lit25:
1748       return "DW_OP_lit25";
1749     case DW_OP_lit26:
1750       return "DW_OP_lit26";
1751     case DW_OP_lit27:
1752       return "DW_OP_lit27";
1753     case DW_OP_lit28:
1754       return "DW_OP_lit28";
1755     case DW_OP_lit29:
1756       return "DW_OP_lit29";
1757     case DW_OP_lit30:
1758       return "DW_OP_lit30";
1759     case DW_OP_lit31:
1760       return "DW_OP_lit31";
1761     case DW_OP_reg0:
1762       return "DW_OP_reg0";
1763     case DW_OP_reg1:
1764       return "DW_OP_reg1";
1765     case DW_OP_reg2:
1766       return "DW_OP_reg2";
1767     case DW_OP_reg3:
1768       return "DW_OP_reg3";
1769     case DW_OP_reg4:
1770       return "DW_OP_reg4";
1771     case DW_OP_reg5:
1772       return "DW_OP_reg5";
1773     case DW_OP_reg6:
1774       return "DW_OP_reg6";
1775     case DW_OP_reg7:
1776       return "DW_OP_reg7";
1777     case DW_OP_reg8:
1778       return "DW_OP_reg8";
1779     case DW_OP_reg9:
1780       return "DW_OP_reg9";
1781     case DW_OP_reg10:
1782       return "DW_OP_reg10";
1783     case DW_OP_reg11:
1784       return "DW_OP_reg11";
1785     case DW_OP_reg12:
1786       return "DW_OP_reg12";
1787     case DW_OP_reg13:
1788       return "DW_OP_reg13";
1789     case DW_OP_reg14:
1790       return "DW_OP_reg14";
1791     case DW_OP_reg15:
1792       return "DW_OP_reg15";
1793     case DW_OP_reg16:
1794       return "DW_OP_reg16";
1795     case DW_OP_reg17:
1796       return "DW_OP_reg17";
1797     case DW_OP_reg18:
1798       return "DW_OP_reg18";
1799     case DW_OP_reg19:
1800       return "DW_OP_reg19";
1801     case DW_OP_reg20:
1802       return "DW_OP_reg20";
1803     case DW_OP_reg21:
1804       return "DW_OP_reg21";
1805     case DW_OP_reg22:
1806       return "DW_OP_reg22";
1807     case DW_OP_reg23:
1808       return "DW_OP_reg23";
1809     case DW_OP_reg24:
1810       return "DW_OP_reg24";
1811     case DW_OP_reg25:
1812       return "DW_OP_reg25";
1813     case DW_OP_reg26:
1814       return "DW_OP_reg26";
1815     case DW_OP_reg27:
1816       return "DW_OP_reg27";
1817     case DW_OP_reg28:
1818       return "DW_OP_reg28";
1819     case DW_OP_reg29:
1820       return "DW_OP_reg29";
1821     case DW_OP_reg30:
1822       return "DW_OP_reg30";
1823     case DW_OP_reg31:
1824       return "DW_OP_reg31";
1825     case DW_OP_breg0:
1826       return "DW_OP_breg0";
1827     case DW_OP_breg1:
1828       return "DW_OP_breg1";
1829     case DW_OP_breg2:
1830       return "DW_OP_breg2";
1831     case DW_OP_breg3:
1832       return "DW_OP_breg3";
1833     case DW_OP_breg4:
1834       return "DW_OP_breg4";
1835     case DW_OP_breg5:
1836       return "DW_OP_breg5";
1837     case DW_OP_breg6:
1838       return "DW_OP_breg6";
1839     case DW_OP_breg7:
1840       return "DW_OP_breg7";
1841     case DW_OP_breg8:
1842       return "DW_OP_breg8";
1843     case DW_OP_breg9:
1844       return "DW_OP_breg9";
1845     case DW_OP_breg10:
1846       return "DW_OP_breg10";
1847     case DW_OP_breg11:
1848       return "DW_OP_breg11";
1849     case DW_OP_breg12:
1850       return "DW_OP_breg12";
1851     case DW_OP_breg13:
1852       return "DW_OP_breg13";
1853     case DW_OP_breg14:
1854       return "DW_OP_breg14";
1855     case DW_OP_breg15:
1856       return "DW_OP_breg15";
1857     case DW_OP_breg16:
1858       return "DW_OP_breg16";
1859     case DW_OP_breg17:
1860       return "DW_OP_breg17";
1861     case DW_OP_breg18:
1862       return "DW_OP_breg18";
1863     case DW_OP_breg19:
1864       return "DW_OP_breg19";
1865     case DW_OP_breg20:
1866       return "DW_OP_breg20";
1867     case DW_OP_breg21:
1868       return "DW_OP_breg21";
1869     case DW_OP_breg22:
1870       return "DW_OP_breg22";
1871     case DW_OP_breg23:
1872       return "DW_OP_breg23";
1873     case DW_OP_breg24:
1874       return "DW_OP_breg24";
1875     case DW_OP_breg25:
1876       return "DW_OP_breg25";
1877     case DW_OP_breg26:
1878       return "DW_OP_breg26";
1879     case DW_OP_breg27:
1880       return "DW_OP_breg27";
1881     case DW_OP_breg28:
1882       return "DW_OP_breg28";
1883     case DW_OP_breg29:
1884       return "DW_OP_breg29";
1885     case DW_OP_breg30:
1886       return "DW_OP_breg30";
1887     case DW_OP_breg31:
1888       return "DW_OP_breg31";
1889     case DW_OP_regx:
1890       return "DW_OP_regx";
1891     case DW_OP_fbreg:
1892       return "DW_OP_fbreg";
1893     case DW_OP_bregx:
1894       return "DW_OP_bregx";
1895     case DW_OP_piece:
1896       return "DW_OP_piece";
1897     case DW_OP_deref_size:
1898       return "DW_OP_deref_size";
1899     case DW_OP_xderef_size:
1900       return "DW_OP_xderef_size";
1901     case DW_OP_nop:
1902       return "DW_OP_nop";
1903     default:
1904       return "OP_<unknown>";
1905     }
1906 }
1907
1908 /* Convert a DWARF type code into its string name.  */
1909
1910 static char *
1911 dwarf_type_encoding_name (enc)
1912      register unsigned enc;
1913 {
1914   switch (enc)
1915     {
1916     case DW_ATE_address:
1917       return "DW_ATE_address";
1918     case DW_ATE_boolean:
1919       return "DW_ATE_boolean";
1920     case DW_ATE_complex_float:
1921       return "DW_ATE_complex_float";
1922     case DW_ATE_float:
1923       return "DW_ATE_float";
1924     case DW_ATE_signed:
1925       return "DW_ATE_signed";
1926     case DW_ATE_signed_char:
1927       return "DW_ATE_signed_char";
1928     case DW_ATE_unsigned:
1929       return "DW_ATE_unsigned";
1930     case DW_ATE_unsigned_char:
1931       return "DW_ATE_unsigned_char";
1932     default:
1933       return "DW_ATE_<unknown>";
1934     }
1935 }
1936
1937 /* Convert a DWARF call frame info. operation to its string name */
1938
1939 static char *
1940 dwarf_cfi_name (cfi_opc)
1941      register unsigned cfi_opc;
1942 {
1943   switch (cfi_opc)
1944     {
1945     case DW_CFA_advance_loc:
1946       return "DW_CFA_advance_loc";
1947     case DW_CFA_offset:
1948       return "DW_CFA_offset";
1949     case DW_CFA_restore:
1950       return "DW_CFA_restore";
1951     case DW_CFA_nop:
1952       return "DW_CFA_nop";
1953     case DW_CFA_set_loc:
1954       return "DW_CFA_set_loc";
1955     case DW_CFA_advance_loc1:
1956       return "DW_CFA_advance_loc1";
1957     case DW_CFA_advance_loc2:
1958       return "DW_CFA_advance_loc2";
1959     case DW_CFA_advance_loc4:
1960       return "DW_CFA_advance_loc4";
1961     case DW_CFA_offset_extended:
1962       return "DW_CFA_offset_extended";
1963     case DW_CFA_restore_extended:
1964       return "DW_CFA_restore_extended";
1965     case DW_CFA_undefined:
1966       return "DW_CFA_undefined";
1967     case DW_CFA_same_value:
1968       return "DW_CFA_same_value";
1969     case DW_CFA_register:
1970       return "DW_CFA_register";
1971     case DW_CFA_remember_state:
1972       return "DW_CFA_remember_state";
1973     case DW_CFA_restore_state:
1974       return "DW_CFA_restore_state";
1975     case DW_CFA_def_cfa:
1976       return "DW_CFA_def_cfa";
1977     case DW_CFA_def_cfa_register:
1978       return "DW_CFA_def_cfa_register";
1979     case DW_CFA_def_cfa_offset:
1980       return "DW_CFA_def_cfa_offset";
1981     /* SGI/MIPS specific */
1982     case DW_CFA_MIPS_advance_loc8:
1983       return "DW_CFA_MIPS_advance_loc8";
1984     default:
1985       return "DW_CFA_<unknown>";
1986     }
1987 }
1988 \f
1989 /* Determine the "ultimate origin" of a decl.  The decl may be an inlined
1990    instance of an inlined instance of a decl which is local to an inline
1991    function, so we have to trace all of the way back through the origin chain
1992    to find out what sort of node actually served as the original seed for the
1993    given block.  */
1994
1995 static tree
1996 decl_ultimate_origin (decl)
1997      register tree decl;
1998 {
1999   register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
2000
2001   if (immediate_origin == NULL_TREE || immediate_origin == decl)
2002     return NULL_TREE;
2003   else
2004     {
2005       register tree ret_val;
2006       register tree lookahead = immediate_origin;
2007
2008       do
2009         {
2010           ret_val = lookahead;
2011           lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
2012         }
2013       while (lookahead != NULL && lookahead != ret_val);
2014
2015       return ret_val;
2016     }
2017 }
2018
2019 /* Determine the "ultimate origin" of a block.  The block may be an inlined
2020    instance of an inlined instance of a block which is local to an inline
2021    function, so we have to trace all of the way back through the origin chain
2022    to find out what sort of node actually served as the original seed for the
2023    given block.  */
2024
2025 static tree
2026 block_ultimate_origin (block)
2027      register tree block;
2028 {
2029   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
2030
2031   if (immediate_origin == NULL_TREE)
2032     return NULL_TREE;
2033   else
2034     {
2035       register tree ret_val;
2036       register tree lookahead = immediate_origin;
2037
2038       do
2039         {
2040           ret_val = lookahead;
2041           lookahead = (TREE_CODE (ret_val) == BLOCK)
2042             ? BLOCK_ABSTRACT_ORIGIN (ret_val)
2043             : NULL;
2044         }
2045       while (lookahead != NULL && lookahead != ret_val);
2046
2047       return ret_val;
2048     }
2049 }
2050
2051 /* Get the class to which DECL belongs, if any.  In g++, the DECL_CONTEXT
2052    of a virtual function may refer to a base class, so we check the 'this'
2053    parameter.  */
2054
2055 static tree
2056 decl_class_context (decl)
2057      tree decl;
2058 {
2059   tree context = NULL_TREE;
2060
2061   if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
2062     context = DECL_CONTEXT (decl);
2063   else
2064     context = TYPE_MAIN_VARIANT
2065       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
2066
2067   if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
2068     context = NULL_TREE;
2069
2070   return context;
2071 }
2072 \f
2073 /* Add an attribute/value pair to a DIE */
2074
2075 static inline void
2076 add_dwarf_attr (die, attr)
2077      register dw_die_ref die;
2078      register dw_attr_ref attr;
2079 {
2080   if (die != NULL && attr != NULL)
2081     {
2082       if (die->die_attr == NULL)
2083         {
2084           die->die_attr = attr;
2085           die->die_attr_last = attr;
2086         }
2087       else
2088         {
2089           die->die_attr_last->dw_attr_next = attr;
2090           die->die_attr_last = attr;
2091         }
2092     }
2093 }
2094
2095 /* Add a flag value attribute to a DIE.  */
2096
2097 static inline void
2098 add_AT_flag (die, attr_kind, flag)
2099      register dw_die_ref die;
2100      register enum dwarf_attribute attr_kind;
2101      register unsigned flag;
2102 {
2103   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2104
2105   attr->dw_attr_next = NULL;
2106   attr->dw_attr = attr_kind;
2107   attr->dw_attr_val.val_class = dw_val_class_flag;
2108   attr->dw_attr_val.v.val_flag = flag;
2109   add_dwarf_attr (die, attr);
2110 }
2111
2112 /* Add a signed integer attribute value to a DIE.  */
2113
2114 static inline void
2115 add_AT_int (die, attr_kind, int_val)
2116      register dw_die_ref die;
2117      register enum dwarf_attribute attr_kind;
2118      register long int int_val;
2119 {
2120   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2121
2122   attr->dw_attr_next = NULL;
2123   attr->dw_attr = attr_kind;
2124   attr->dw_attr_val.val_class = dw_val_class_const;
2125   attr->dw_attr_val.v.val_int = int_val;
2126   add_dwarf_attr (die, attr);
2127 }
2128
2129 /* Add an unsigned integer attribute value to a DIE.  */
2130
2131 static inline void
2132 add_AT_unsigned (die, attr_kind, unsigned_val)
2133      register dw_die_ref die;
2134      register enum dwarf_attribute attr_kind;
2135      register unsigned long unsigned_val;
2136 {
2137   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2138
2139   attr->dw_attr_next = NULL;
2140   attr->dw_attr = attr_kind;
2141   attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
2142   attr->dw_attr_val.v.val_unsigned = unsigned_val;
2143   add_dwarf_attr (die, attr);
2144 }
2145
2146 /* Add an unsigned double integer attribute value to a DIE.  */
2147
2148 static inline void
2149 add_AT_long_long (die, attr_kind, val_hi, val_low)
2150      register dw_die_ref die;
2151      register enum dwarf_attribute attr_kind;
2152      register unsigned long val_hi;
2153      register unsigned long val_low;
2154 {
2155   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2156
2157   attr->dw_attr_next = NULL;
2158   attr->dw_attr = attr_kind;
2159   attr->dw_attr_val.val_class = dw_val_class_long_long;
2160   attr->dw_attr_val.v.val_long_long.hi = val_hi;
2161   attr->dw_attr_val.v.val_long_long.low = val_low;
2162   add_dwarf_attr (die, attr);
2163 }
2164
2165 /* Add a floating point attribute value to a DIE and return it.  */
2166
2167 static inline void
2168 add_AT_float (die, attr_kind, length, array)
2169      register dw_die_ref die;
2170      register enum dwarf_attribute attr_kind;
2171      register unsigned length;
2172      register long *array;
2173 {
2174   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2175
2176   attr->dw_attr_next = NULL;
2177   attr->dw_attr = attr_kind;
2178   attr->dw_attr_val.val_class = dw_val_class_float;
2179   attr->dw_attr_val.v.val_float.length = length;
2180   attr->dw_attr_val.v.val_float.array = array;
2181   add_dwarf_attr (die, attr);
2182 }
2183
2184 /* Add a string attribute value to a DIE.  */
2185
2186 static inline void
2187 add_AT_string (die, attr_kind, str)
2188      register dw_die_ref die;
2189      register enum dwarf_attribute attr_kind;
2190      register char *str;
2191 {
2192   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2193
2194   attr->dw_attr_next = NULL;
2195   attr->dw_attr = attr_kind;
2196   attr->dw_attr_val.val_class = dw_val_class_str;
2197   attr->dw_attr_val.v.val_str = xstrdup (str);
2198   add_dwarf_attr (die, attr);
2199 }
2200
2201 /* Add a DIE reference attribute value to a DIE.  */
2202
2203 static inline void
2204 add_AT_die_ref (die, attr_kind, targ_die)
2205      register dw_die_ref die;
2206      register enum dwarf_attribute attr_kind;
2207      register dw_die_ref targ_die;
2208 {
2209   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2210
2211   attr->dw_attr_next = NULL;
2212   attr->dw_attr = attr_kind;
2213   attr->dw_attr_val.val_class = dw_val_class_die_ref;
2214   attr->dw_attr_val.v.val_die_ref = targ_die;
2215   add_dwarf_attr (die, attr);
2216 }
2217
2218 /* Add an FDE reference attribute value to a DIE.  */
2219
2220 static inline void
2221 add_AT_fde_ref (die, attr_kind, targ_fde)
2222      register dw_die_ref die;
2223      register enum dwarf_attribute attr_kind;
2224      register unsigned targ_fde;
2225 {
2226   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2227
2228   attr->dw_attr_next = NULL;
2229   attr->dw_attr = attr_kind;
2230   attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2231   attr->dw_attr_val.v.val_fde_index = targ_fde;
2232   add_dwarf_attr (die, attr);
2233 }
2234
2235 /* Add a location description attribute value to a DIE.  */
2236
2237 static inline void
2238 add_AT_loc (die, attr_kind, loc)
2239      register dw_die_ref die;
2240      register enum dwarf_attribute attr_kind;
2241      register dw_loc_descr_ref loc;
2242 {
2243   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2244
2245   attr->dw_attr_next = NULL;
2246   attr->dw_attr = attr_kind;
2247   attr->dw_attr_val.val_class = dw_val_class_loc;
2248   attr->dw_attr_val.v.val_loc = loc;
2249   add_dwarf_attr (die, attr);
2250 }
2251
2252 /* Add an address constant attribute value to a DIE.  */
2253
2254 static inline void
2255 add_AT_addr (die, attr_kind, addr)
2256      register dw_die_ref die;
2257      register enum dwarf_attribute attr_kind;
2258      char *addr;
2259 {
2260   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2261
2262   attr->dw_attr_next = NULL;
2263   attr->dw_attr = attr_kind;
2264   attr->dw_attr_val.val_class = dw_val_class_addr;
2265   attr->dw_attr_val.v.val_addr = addr;
2266   add_dwarf_attr (die, attr);
2267 }
2268
2269 /* Add a label identifier attribute value to a DIE.  */
2270
2271 static inline void
2272 add_AT_lbl_id (die, attr_kind, lbl_id)
2273      register dw_die_ref die;
2274      register enum dwarf_attribute attr_kind;
2275      register char *lbl_id;
2276 {
2277   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2278
2279   attr->dw_attr_next = NULL;
2280   attr->dw_attr = attr_kind;
2281   attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2282   attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2283   add_dwarf_attr (die, attr);
2284 }
2285
2286 /* Add a section offset attribute value to a DIE.  */
2287
2288 static inline void
2289 add_AT_section_offset (die, attr_kind, section)
2290      register dw_die_ref die;
2291      register enum dwarf_attribute attr_kind;
2292      register char *section;
2293 {
2294   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2295
2296   attr->dw_attr_next = NULL;
2297   attr->dw_attr = attr_kind;
2298   attr->dw_attr_val.val_class = dw_val_class_section_offset;
2299   attr->dw_attr_val.v.val_section = section;
2300   add_dwarf_attr (die, attr);
2301   
2302 }
2303
2304 /* Test if die refers to an external subroutine.  */
2305
2306 static inline int
2307 is_extern_subr_die (die)
2308      register dw_die_ref die;
2309 {
2310   register dw_attr_ref a;
2311   register int is_subr = FALSE;
2312   register int is_extern = FALSE;
2313
2314   if (die != NULL && die->die_tag == DW_TAG_subprogram)
2315     {
2316       is_subr = TRUE;
2317       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2318         {
2319           if (a->dw_attr == DW_AT_external
2320               && a->dw_attr_val.val_class == dw_val_class_flag
2321               && a->dw_attr_val.v.val_flag != 0)
2322             {
2323               is_extern = TRUE;
2324               break;
2325             }
2326         }
2327     }
2328
2329   return is_subr && is_extern;
2330 }
2331
2332 /* Get the attribute of type attr_kind.  */
2333
2334 static inline dw_attr_ref
2335 get_AT (die, attr_kind)
2336      register dw_die_ref die;
2337      register enum dwarf_attribute attr_kind;
2338 {
2339   register dw_attr_ref a;
2340   register dw_die_ref spec = NULL;
2341   
2342   if (die != NULL)
2343     {
2344       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2345         {
2346           if (a->dw_attr == attr_kind)
2347             return a;
2348
2349           if (a->dw_attr == DW_AT_specification
2350               || a->dw_attr == DW_AT_abstract_origin)
2351             spec = a->dw_attr_val.v.val_die_ref;
2352         }
2353
2354       if (spec)
2355         return get_AT (spec, attr_kind);
2356     }
2357
2358   return NULL;
2359 }
2360
2361 /* Return the "low pc" attribute value, typically associated with
2362    a subprogram DIE.  Return null if the "low pc" attribute is
2363    either not prsent, or if it cannot be represented as an
2364    assembler label identifier.  */
2365
2366 static inline char *
2367 get_AT_low_pc (die)
2368      register dw_die_ref die;
2369 {
2370   register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2371
2372   if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2373     return a->dw_attr_val.v.val_lbl_id;
2374
2375   return NULL;
2376 }
2377
2378 /* Return the "high pc" attribute value, typically associated with
2379    a subprogram DIE.  Return null if the "high pc" attribute is
2380    either not prsent, or if it cannot be represented as an
2381    assembler label identifier.  */
2382
2383 static inline char *
2384 get_AT_hi_pc (die)
2385      register dw_die_ref die;
2386 {
2387   register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2388
2389   if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2390     return a->dw_attr_val.v.val_lbl_id;
2391
2392   return NULL;
2393 }
2394
2395 /* Return the value of the string attribute designated by ATTR_KIND, or
2396    NULL if it is not present.  */
2397
2398 static inline char *
2399 get_AT_string (die, attr_kind)
2400      register dw_die_ref die;
2401      register enum dwarf_attribute attr_kind;
2402 {
2403   register dw_attr_ref a = get_AT (die, attr_kind);
2404
2405   if (a && a->dw_attr_val.val_class == dw_val_class_str)
2406     return a->dw_attr_val.v.val_str;
2407
2408   return NULL;
2409 }
2410
2411 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2412    if it is not present.  */
2413
2414 static inline int
2415 get_AT_flag (die, attr_kind)
2416      register dw_die_ref die;
2417      register enum dwarf_attribute attr_kind;
2418 {
2419   register dw_attr_ref a = get_AT (die, attr_kind);
2420
2421   if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2422     return a->dw_attr_val.v.val_flag;
2423
2424   return -1;
2425 }
2426
2427 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2428    if it is not present.  */
2429
2430 static inline unsigned
2431 get_AT_unsigned (die, attr_kind)
2432      register dw_die_ref die;
2433      register enum dwarf_attribute attr_kind;
2434 {
2435   register dw_attr_ref a = get_AT (die, attr_kind);
2436
2437   if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2438     return a->dw_attr_val.v.val_unsigned;
2439
2440   return 0;
2441 }
2442
2443 static inline int
2444 is_c_family ()
2445 {
2446   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2447
2448   return (lang == DW_LANG_C || lang == DW_LANG_C89
2449           || lang == DW_LANG_C_plus_plus);
2450
2451
2452 static inline int
2453 is_fortran ()
2454 {
2455   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2456
2457   return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
2458
2459
2460 /* Remove the specified attribute if present.  */
2461
2462 static inline void
2463 remove_AT (die, attr_kind)
2464      register dw_die_ref die;
2465      register enum dwarf_attribute attr_kind;
2466 {
2467   register dw_attr_ref a;
2468   register dw_attr_ref removed = NULL;;
2469
2470   if (die != NULL)
2471     {
2472       if (die->die_attr->dw_attr == attr_kind)
2473         {
2474           removed = die->die_attr;
2475           if (die->die_attr_last == die->die_attr)
2476             die->die_attr_last = NULL;
2477
2478           die->die_attr = die->die_attr->dw_attr_next;
2479         }
2480
2481       else
2482         for (a = die->die_attr; a->dw_attr_next != NULL;
2483              a = a->dw_attr_next)
2484           if (a->dw_attr_next->dw_attr == attr_kind)
2485             {
2486               removed = a->dw_attr_next;
2487               if (die->die_attr_last == a->dw_attr_next)
2488                 die->die_attr_last = a;
2489
2490               a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2491               break;
2492             }
2493
2494       if (removed != 0)
2495         free (removed);
2496     }
2497 }
2498
2499 /* Discard the children of this DIE.  */
2500
2501 static inline void
2502 remove_children (die)
2503      register dw_die_ref die;
2504 {
2505   register dw_die_ref child_die = die->die_child;
2506
2507   die->die_child = NULL;
2508   die->die_child_last = NULL;
2509
2510   while (child_die != NULL)
2511     {
2512       register dw_die_ref tmp_die = child_die;
2513       register dw_attr_ref a;
2514
2515       child_die = child_die->die_sib;
2516       
2517       for (a = tmp_die->die_attr; a != NULL; )
2518         {
2519           register dw_attr_ref tmp_a = a;
2520
2521           a = a->dw_attr_next;
2522           free (tmp_a);
2523         }
2524
2525       free (tmp_die);
2526     }
2527 }
2528
2529 /* Add a child DIE below its parent.  */
2530
2531 static inline void
2532 add_child_die (die, child_die)
2533      register dw_die_ref die;
2534      register dw_die_ref child_die;
2535 {
2536   if (die != NULL && child_die != NULL)
2537     {
2538       assert (die != child_die);
2539       child_die->die_parent = die;
2540       child_die->die_sib = NULL;
2541
2542       if (die->die_child == NULL)
2543         {
2544           die->die_child = child_die;
2545           die->die_child_last = child_die;
2546         }
2547       else
2548         {
2549           die->die_child_last->die_sib = child_die;
2550           die->die_child_last = child_die;
2551         }
2552     }
2553 }
2554
2555 /* Return a pointer to a newly created DIE node.  */
2556
2557 static inline dw_die_ref
2558 new_die (tag_value, parent_die)
2559      register enum dwarf_tag tag_value;
2560      register dw_die_ref parent_die;
2561 {
2562   register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2563
2564   die->die_tag = tag_value;
2565   die->die_abbrev = 0;
2566   die->die_offset = 0;
2567   die->die_child = NULL;
2568   die->die_parent = NULL;
2569   die->die_sib = NULL;
2570   die->die_child_last = NULL;
2571   die->die_attr = NULL;
2572   die->die_attr_last = NULL;
2573
2574   if (parent_die != NULL)
2575     add_child_die (parent_die, die);
2576   else
2577     ++limbo_die_count;
2578
2579   return die;
2580 }
2581
2582 /* Return the DIE associated with the given type specifier.  */
2583
2584 static inline dw_die_ref
2585 lookup_type_die (type)
2586      register tree type;
2587 {
2588   return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
2589 }
2590
2591 /* Equate a DIE to a given type specifier.  */
2592
2593 static void
2594 equate_type_number_to_die (type, type_die)
2595      register tree type;
2596      register dw_die_ref type_die;
2597 {
2598   TYPE_SYMTAB_POINTER (type) = (char *) type_die;
2599 }
2600
2601 /* Return the DIE associated with a given declaration.  */
2602
2603 static inline dw_die_ref
2604 lookup_decl_die (decl)
2605      register tree decl;
2606 {
2607   register unsigned decl_id = DECL_UID (decl);
2608
2609   return (decl_id < decl_die_table_in_use
2610           ? decl_die_table[decl_id] : NULL);
2611 }
2612
2613 /* Equate a DIE to a particular declaration.  */
2614
2615 static void
2616 equate_decl_number_to_die (decl, decl_die)
2617      register tree decl;
2618      register dw_die_ref decl_die;
2619 {
2620   register unsigned decl_id = DECL_UID (decl);
2621   register unsigned i;
2622   register unsigned num_allocated;
2623
2624   if (decl_id >= decl_die_table_allocated)
2625     {
2626       num_allocated
2627         = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
2628            / DECL_DIE_TABLE_INCREMENT)
2629           * DECL_DIE_TABLE_INCREMENT;
2630
2631       decl_die_table
2632         = (dw_die_ref *) xrealloc (decl_die_table,
2633                                    sizeof (dw_die_ref) * num_allocated);
2634
2635       bzero ((char *) &decl_die_table[decl_die_table_allocated],
2636              (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2637       decl_die_table_allocated = num_allocated;
2638     }
2639
2640   if (decl_id >= decl_die_table_in_use)
2641     decl_die_table_in_use = (decl_id + 1);
2642
2643   decl_die_table[decl_id] = decl_die;
2644 }
2645
2646 /* Return a pointer to a newly allocated location description.  Location
2647    descriptions are simple expression terms that can be strung
2648    together to form more complicated location (address) descriptions.  */
2649
2650 static inline dw_loc_descr_ref
2651 new_loc_descr (op, oprnd1, oprnd2)
2652      register enum dwarf_location_atom op;
2653      register unsigned long oprnd1;
2654      register unsigned long oprnd2;
2655 {
2656   register dw_loc_descr_ref descr
2657     = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2658
2659   descr->dw_loc_next = NULL;
2660   descr->dw_loc_opc = op;
2661   descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2662   descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2663   descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2664   descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2665
2666   return descr;
2667 }
2668
2669 /* Add a location description term to a location description expression.  */
2670
2671 static inline void
2672 add_loc_descr (list_head, descr)
2673      register dw_loc_descr_ref *list_head;
2674      register dw_loc_descr_ref descr;
2675 {
2676   register dw_loc_descr_ref *d;
2677
2678   /* Find the end of the chain.  */
2679   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2680     ;
2681
2682   *d = descr;
2683 }
2684
2685 /* Return a pointer to a newly allocated Call Frame Instruction.  */
2686
2687 static inline dw_cfi_ref
2688 new_cfi ()
2689 {
2690   register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2691
2692   cfi->dw_cfi_next = NULL;
2693   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2694   cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2695
2696   return cfi;
2697 }
2698
2699 /* Add a Call Frame Instruction to list of instructions.  */
2700
2701 static inline void
2702 add_cfi (list_head, cfi)
2703      register dw_cfi_ref *list_head;
2704      register dw_cfi_ref cfi;
2705 {
2706   register dw_cfi_ref *p;
2707
2708   /* Find the end of the chain.  */
2709   for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2710     ;
2711
2712   *p = cfi;
2713 }
2714 \f
2715 /* Keep track of the number of spaces used to indent the
2716    output of the debugging routines that print the structure of
2717    the DIE internal representation.  */
2718 static int print_indent;
2719
2720 /* Indent the line the number of spaces given by print_indent.  */
2721
2722 static inline void
2723 print_spaces (outfile)
2724      FILE *outfile;
2725 {
2726   fprintf (outfile, "%*s", print_indent, "");
2727 }
2728
2729 /* Print the information assoaciated with a given DIE, and its children.
2730    This routine is a debugging aid only.  */
2731
2732 static void
2733 print_die (die, outfile)
2734      dw_die_ref die;
2735      FILE *outfile;
2736 {
2737   register dw_attr_ref a;
2738   register dw_die_ref c;
2739
2740   print_spaces (outfile);
2741   fprintf (outfile, "DIE %4u: %s\n",
2742            die->die_offset, dwarf_tag_name (die->die_tag));
2743   print_spaces (outfile);
2744   fprintf (outfile, "  abbrev id: %u", die->die_abbrev);
2745   fprintf (outfile, " offset: %u\n", die->die_offset);
2746
2747   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2748     {
2749       print_spaces (outfile);
2750       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
2751
2752       switch (a->dw_attr_val.val_class)
2753         {
2754         case dw_val_class_addr:
2755           fprintf (outfile, "address");
2756           break;
2757         case dw_val_class_loc:
2758           fprintf (outfile, "location descriptor");
2759           break;
2760         case dw_val_class_const:
2761           fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2762           break;
2763         case dw_val_class_unsigned_const:
2764           fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2765           break;
2766         case dw_val_class_long_long:
2767           fprintf (outfile, "constant (%u,%u)",
2768                   a->dw_attr_val.v.val_long_long.hi,
2769                   a->dw_attr_val.v.val_long_long.low);
2770           break;
2771         case dw_val_class_float:
2772           fprintf (outfile, "floating-point constant");
2773           break;
2774         case dw_val_class_flag:
2775           fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2776           break;
2777         case dw_val_class_die_ref:
2778           if (a->dw_attr_val.v.val_die_ref != NULL)
2779             fprintf (outfile, "die -> %u",
2780                      a->dw_attr_val.v.val_die_ref->die_offset);
2781           else
2782             fprintf (outfile, "die -> <null>");
2783           break;
2784         case dw_val_class_lbl_id:
2785           fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2786           break;
2787         case dw_val_class_section_offset:
2788           fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2789           break;
2790         case dw_val_class_str:
2791           if (a->dw_attr_val.v.val_str != NULL)
2792             fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2793           else
2794             fprintf (outfile, "<null>");
2795           break;
2796         }
2797
2798       fprintf (outfile, "\n");
2799     }
2800
2801   if (die->die_child != NULL)
2802     {
2803       print_indent += 4;
2804       for (c = die->die_child; c != NULL; c = c->die_sib)
2805         print_die (c, outfile);
2806
2807       print_indent -= 4;
2808     }
2809 }
2810
2811 /* Print the contents of the source code line number correspondence table.
2812    This routine is a debugging aid only.  */
2813
2814 static void
2815 print_dwarf_line_table (outfile)
2816      FILE *outfile;
2817 {
2818   register unsigned i;
2819   register dw_line_info_ref line_info;
2820
2821   fprintf (outfile, "\n\nDWARF source line information\n");
2822   for (i = 1; i < line_info_table_in_use; ++i)
2823     {
2824       line_info = &line_info_table[i];
2825       fprintf (outfile, "%5d: ", i);
2826       fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2827       fprintf (outfile, "%6d", line_info->dw_line_num);
2828       fprintf (outfile, "\n");
2829     }
2830
2831   fprintf (outfile, "\n\n");
2832 }
2833
2834 /* Print the information collected for a given DIE.  */
2835
2836 void
2837 debug_dwarf_die (die)
2838      dw_die_ref die;
2839 {
2840   print_die (die, stderr);
2841 }
2842
2843 /* Print all DWARF information collected for the compilation unit.
2844    This routine is a debugging aid only.  */
2845
2846 void
2847 debug_dwarf ()
2848 {
2849   print_indent = 0;
2850   print_die (comp_unit_die, stderr);
2851   print_dwarf_line_table (stderr);
2852 }
2853 \f
2854 /* Traverse the DIE, and add a sibling attribute if it may have the
2855    effect of speeding up access to siblings.  To save some space,
2856    avoid generating sibling attributes for DIE's without children.  */
2857
2858 static void
2859 add_sibling_attributes(die)
2860      register dw_die_ref die;
2861 {
2862   register dw_die_ref c;
2863   register dw_attr_ref attr;
2864   if (die != comp_unit_die && die->die_child != NULL)
2865     {
2866       attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2867       attr->dw_attr_next = NULL;
2868       attr->dw_attr = DW_AT_sibling;
2869       attr->dw_attr_val.val_class = dw_val_class_die_ref;
2870       attr->dw_attr_val.v.val_die_ref = die->die_sib;
2871
2872       /* Add the sibling link to the front of the attribute list.  */
2873       attr->dw_attr_next = die->die_attr;
2874       if (die->die_attr == NULL)
2875         die->die_attr_last = attr;
2876
2877       die->die_attr = attr;
2878     }
2879
2880   for (c = die->die_child; c != NULL; c = c->die_sib)
2881     add_sibling_attributes (c);
2882 }
2883
2884 /* The format of each DIE (and its attribute value pairs)
2885    is encoded in an abbreviation table.  This routine builds the
2886    abbreviation table and assigns a unique abbreviation id for
2887    each abbreviation entry.  The children of each die are visited
2888    recursively.  */
2889
2890 static void
2891 build_abbrev_table (die)
2892      register dw_die_ref die;
2893 {
2894   register unsigned long abbrev_id;
2895   register unsigned long n_alloc;
2896   register dw_die_ref c;
2897   register dw_attr_ref d_attr, a_attr;
2898   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2899     {
2900       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2901
2902       if (abbrev->die_tag == die->die_tag)
2903         {
2904           if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2905             {
2906               a_attr = abbrev->die_attr;
2907               d_attr = die->die_attr;
2908
2909               while (a_attr != NULL && d_attr != NULL)
2910                 {
2911                   if ((a_attr->dw_attr != d_attr->dw_attr)
2912                       || (value_format (&a_attr->dw_attr_val)
2913                           != value_format (&d_attr->dw_attr_val)))
2914                     break;
2915
2916                   a_attr = a_attr->dw_attr_next;
2917                   d_attr = d_attr->dw_attr_next;
2918                 }
2919
2920               if (a_attr == NULL && d_attr == NULL)
2921                 break;
2922             }
2923         }
2924     }
2925
2926   if (abbrev_id >= abbrev_die_table_in_use)
2927     {
2928       if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2929         {
2930           n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2931           abbrev_die_table 
2932             = (dw_die_ref *) xmalloc (abbrev_die_table,
2933                                       sizeof (dw_die_ref) * n_alloc);
2934
2935           bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
2936                  (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2937           abbrev_die_table_allocated = n_alloc;
2938         }
2939
2940       ++abbrev_die_table_in_use;
2941       abbrev_die_table[abbrev_id] = die;
2942     }
2943
2944   die->die_abbrev = abbrev_id;
2945   for (c = die->die_child; c != NULL; c = c->die_sib)
2946     build_abbrev_table (c);
2947 }
2948 \f
2949 /* Return the size of an unsigned LEB128 quantity.  */
2950
2951 static inline unsigned long
2952 size_of_uleb128 (value)
2953      register unsigned long value;
2954 {
2955   register unsigned long size = 0;
2956   register unsigned byte;
2957
2958   do
2959     {
2960       byte = (value & 0x7f);
2961       value >>= 7;
2962       size += 1;
2963     }
2964   while (value != 0);
2965
2966   return size;
2967 }
2968
2969 /* Return the size of a signed LEB128 quantity.  */
2970
2971 static inline unsigned long
2972 size_of_sleb128 (value)
2973      register long value;
2974 {
2975   register unsigned long size = 0;
2976   register unsigned byte;
2977
2978   do
2979     {
2980       byte = (value & 0x7f);
2981       value >>= 7;
2982       size += 1;
2983     }
2984   while (!(((value == 0) && ((byte & 0x40) == 0))
2985            || ((value == -1) && ((byte & 0x40) != 0))));
2986
2987   return size;
2988 }
2989
2990 /* Return the size of a string, including the null byte.  */
2991
2992 static unsigned long
2993 size_of_string (str)
2994      register char *str;
2995 {
2996   register unsigned long size = 0;
2997   register unsigned long slen = strlen (str);
2998   register unsigned long i;
2999   register unsigned c;
3000
3001   for (i = 0; i < slen; ++i)
3002     {
3003       c = str[i];
3004       if (c == '\\')
3005         ++i;
3006
3007       size += 1;
3008     }
3009
3010   /* Null terminator.  */
3011   size += 1;
3012   return size;
3013 }
3014
3015 /* Return the size of a location descriptor.  */
3016
3017 static unsigned long
3018 size_of_loc_descr (loc)
3019      register dw_loc_descr_ref loc;
3020 {
3021   register unsigned long size = 1;
3022
3023   switch (loc->dw_loc_opc)
3024     {
3025     case DW_OP_addr:
3026       size += PTR_SIZE;
3027       break;
3028     case DW_OP_const1u:
3029     case DW_OP_const1s:
3030       size += 1;
3031       break;
3032     case DW_OP_const2u:
3033     case DW_OP_const2s:
3034       size += 2;
3035       break;
3036     case DW_OP_const4u:
3037     case DW_OP_const4s:
3038       size += 4;
3039       break;
3040     case DW_OP_const8u:
3041     case DW_OP_const8s:
3042       size += 8;
3043       break;
3044     case DW_OP_constu:
3045       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3046       break;
3047     case DW_OP_consts:
3048       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3049       break;
3050     case DW_OP_pick:
3051       size += 1;
3052       break;
3053     case DW_OP_plus_uconst:
3054       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3055       break;
3056     case DW_OP_skip:
3057     case DW_OP_bra:
3058       size += 2;
3059       break;
3060     case DW_OP_breg0:
3061     case DW_OP_breg1:
3062     case DW_OP_breg2:
3063     case DW_OP_breg3:
3064     case DW_OP_breg4:
3065     case DW_OP_breg5:
3066     case DW_OP_breg6:
3067     case DW_OP_breg7:
3068     case DW_OP_breg8:
3069     case DW_OP_breg9:
3070     case DW_OP_breg10:
3071     case DW_OP_breg11:
3072     case DW_OP_breg12:
3073     case DW_OP_breg13:
3074     case DW_OP_breg14:
3075     case DW_OP_breg15:
3076     case DW_OP_breg16:
3077     case DW_OP_breg17:
3078     case DW_OP_breg18:
3079     case DW_OP_breg19:
3080     case DW_OP_breg20:
3081     case DW_OP_breg21:
3082     case DW_OP_breg22:
3083     case DW_OP_breg23:
3084     case DW_OP_breg24:
3085     case DW_OP_breg25:
3086     case DW_OP_breg26:
3087     case DW_OP_breg27:
3088     case DW_OP_breg28:
3089     case DW_OP_breg29:
3090     case DW_OP_breg30:
3091     case DW_OP_breg31:
3092       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3093       break;
3094     case DW_OP_regx:
3095       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3096       break;
3097     case DW_OP_fbreg:
3098       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3099       break;
3100     case DW_OP_bregx:
3101       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3102       size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3103       break;
3104     case DW_OP_piece:
3105       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3106       break;
3107     case DW_OP_deref_size:
3108     case DW_OP_xderef_size:
3109       size += 1;
3110       break;
3111     default:
3112       break;
3113     }
3114
3115   return size;
3116 }
3117
3118 /* Return the size of a series of location descriptors.  */
3119
3120 static unsigned long
3121 size_of_locs (loc)
3122      register dw_loc_descr_ref loc;
3123 {
3124   register unsigned long size = 0;
3125
3126   for (; loc != NULL; loc = loc->dw_loc_next)
3127     size += size_of_loc_descr (loc);
3128
3129   return size;
3130 }
3131
3132 /* Return the power-of-two number of bytes necessary to represent VALUE.  */
3133
3134 static int
3135 constant_size (value)
3136      long unsigned value;
3137 {
3138   int log;
3139
3140   if (value == 0)
3141     log = 0;
3142   else
3143     log = floor_log2 (value);
3144
3145   log = log / 8;
3146   log = 1 << (floor_log2 (log) + 1);
3147
3148   return MIN (log, 4);
3149 }
3150
3151 /* Return the size of a DIE, as it is represented in the
3152    .debug_info section.  */
3153
3154 static unsigned long
3155 size_of_die (die)
3156      register dw_die_ref die;
3157 {
3158   register unsigned long size = 0;
3159   register dw_attr_ref a;
3160
3161   size += size_of_uleb128 (die->die_abbrev);
3162   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3163     {
3164       switch (a->dw_attr_val.val_class)
3165         {
3166         case dw_val_class_addr:
3167           size += PTR_SIZE;
3168           break;
3169         case dw_val_class_loc:
3170           {
3171             register unsigned long lsize
3172               = size_of_locs (a->dw_attr_val.v.val_loc);
3173
3174             /* Block length.  */
3175             size += constant_size (lsize);
3176             size += lsize;
3177           }
3178           break;
3179         case dw_val_class_const:
3180           size += 4;
3181           break;
3182         case dw_val_class_unsigned_const:
3183           size += constant_size (a->dw_attr_val.v.val_unsigned);
3184           break;
3185         case dw_val_class_long_long:
3186           size += 1 + 8; /* block */
3187           break;
3188         case dw_val_class_float:
3189           size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
3190           break;
3191         case dw_val_class_flag:
3192           size += 1;
3193           break;
3194         case dw_val_class_die_ref:
3195           size += DWARF_OFFSET_SIZE;
3196           break;
3197         case dw_val_class_fde_ref:
3198           size += DWARF_OFFSET_SIZE;
3199           break;
3200         case dw_val_class_lbl_id:
3201           size += PTR_SIZE;
3202           break;
3203         case dw_val_class_section_offset:
3204           size += DWARF_OFFSET_SIZE;
3205           break;
3206         case dw_val_class_str:
3207           size += size_of_string (a->dw_attr_val.v.val_str);
3208           break;
3209         default:
3210           abort ();
3211         }
3212     }
3213
3214   return size;
3215 }
3216
3217 /* Size the debgging information associted with a given DIE.
3218    Visits the DIE's children recursively.  Updates the global
3219    variable next_die_offset, on each time through.  Uses the
3220    current value of next_die_offset to updete the die_offset
3221    field in each DIE.  */
3222
3223 static void
3224 calc_die_sizes (die)
3225      dw_die_ref die;
3226 {
3227   register dw_die_ref c;
3228   die->die_offset = next_die_offset;
3229   next_die_offset += size_of_die (die);
3230
3231   for (c = die->die_child; c != NULL; c = c->die_sib)
3232     calc_die_sizes (c);
3233
3234   if (die->die_child != NULL)
3235     /* Count the null byte used to terminate sibling lists.  */
3236     next_die_offset += 1;
3237 }
3238
3239 /* Return the size of the line information prolog generated for the
3240    compilation unit.  */
3241
3242 static unsigned long
3243 size_of_line_prolog ()
3244 {
3245   register unsigned long size;
3246   register unsigned long ft_index;
3247
3248   size = DWARF_LINE_PROLOG_HEADER_SIZE;
3249
3250   /* Count the size of the table giving number of args for each
3251      standard opcode.  */
3252   size += DWARF_LINE_OPCODE_BASE - 1;
3253
3254   /* Include directory table is empty (at present).  Count only the
3255      the null byte used to terminate the table.  */
3256   size += 1;
3257
3258   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3259     {
3260       /* File name entry.  */
3261       size += size_of_string (file_table[ft_index]);
3262
3263       /* Include directory index.  */
3264       size += size_of_uleb128 (0);
3265
3266       /* Modification time.  */
3267       size += size_of_uleb128 (0);
3268
3269       /* File length in bytes.  */
3270       size += size_of_uleb128 (0);
3271     }
3272
3273   /* Count the file table terminator.  */
3274   size += 1;
3275   return size;
3276 }
3277
3278 /* Return the size of the line information generated for this
3279    compilation unit.  */
3280
3281 static unsigned long
3282 size_of_line_info ()
3283 {
3284   register unsigned long size;
3285   register unsigned long lt_index;
3286   register unsigned long current_line;
3287   register long line_offset;
3288   register long line_delta;
3289   register unsigned long current_file;
3290   register unsigned long function;
3291
3292   /* Version number.  */
3293   size = 2;
3294
3295   /* Prolog length specifier.  */
3296   size += DWARF_OFFSET_SIZE;
3297
3298   /* Prolog.  */
3299   size += size_of_line_prolog ();
3300
3301   /* Set address register instruction.  */
3302   size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3303
3304   current_file = 1;
3305   current_line = 1;
3306   for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3307     {
3308       register dw_line_info_ref line_info;
3309
3310       /* Advance pc instruction.  */
3311       size += 1 + 2;
3312       line_info = &line_info_table[lt_index];
3313       if (line_info->dw_file_num != current_file)
3314         {
3315           /* Set file number instruction.  */
3316           size += 1;
3317           current_file = line_info->dw_file_num;
3318           size += size_of_uleb128 (current_file);
3319         }
3320
3321       if (line_info->dw_line_num != current_line)
3322         {
3323           line_offset = line_info->dw_line_num - current_line;
3324           line_delta = line_offset - DWARF_LINE_BASE;
3325           current_line = line_info->dw_line_num;
3326           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3327             /* 1-byte special line number instruction.  */
3328             size += 1;
3329           else
3330             {
3331               /* Advance line instruction.  */
3332               size += 1;
3333               size += size_of_sleb128 (line_offset);
3334               /* Generate line entry instruction.  */
3335               size += 1;
3336             }
3337         }
3338     }
3339
3340   /* Advance pc instruction.  */
3341   size += 1 + 2;
3342
3343   /* End of line number info. marker.  */
3344   size += 1 + size_of_uleb128 (1) + 1;
3345
3346   function = 0;
3347   current_file = 1;
3348   current_line = 1;
3349   for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3350     {
3351       register dw_separate_line_info_ref line_info
3352         = &separate_line_info_table[lt_index];
3353       if (function != line_info->function)
3354         {
3355           function = line_info->function;
3356           /* Set address register instruction.  */
3357           size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3358         }
3359       else
3360         /* Advance pc instruction.  */
3361         size += 1 + 2;
3362
3363       if (line_info->dw_file_num != current_file)
3364         {
3365           /* Set file number instruction.  */
3366           size += 1;
3367           current_file = line_info->dw_file_num;
3368           size += size_of_uleb128 (current_file);
3369         }
3370
3371       if (line_info->dw_line_num != current_line)
3372         {
3373           line_offset = line_info->dw_line_num - current_line;
3374           line_delta = line_offset - DWARF_LINE_BASE;
3375           current_line = line_info->dw_line_num;
3376           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3377             /* 1-byte special line number instruction.  */
3378             size += 1;
3379           else
3380             {
3381               /* Advance line instruction.  */
3382               size += 1;
3383               size += size_of_sleb128 (line_offset);
3384
3385               /* Generate line entry instruction.  */
3386               size += 1;
3387             }
3388         }
3389
3390       ++lt_index;
3391
3392       /* If we're done with a function, end its sequence.  */
3393       if (lt_index == separate_line_info_table_in_use
3394           || separate_line_info_table[lt_index].function != function)
3395         {
3396           current_file = 1;
3397           current_line = 1;
3398
3399           /* Advance pc instruction.  */
3400           size += 1 + 2;
3401
3402           /* End of line number info. marker.  */
3403           size += 1 + size_of_uleb128 (1) + 1;
3404         }
3405     }
3406
3407   return size;
3408 }
3409
3410 /* Return the size of the .debug_pubnames table  generated for the
3411    compilation unit.  */
3412
3413 static unsigned long
3414 size_of_pubnames ()
3415 {
3416   register unsigned long size;
3417   register unsigned i;
3418
3419   size = DWARF_PUBNAMES_HEADER_SIZE;
3420   for (i = 0; i < pubname_table_in_use; ++i)
3421     {
3422       register pubname_ref p = &pubname_table[i];
3423       size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3424     }
3425
3426   size += DWARF_OFFSET_SIZE;
3427   return size;
3428 }
3429
3430 /* Return the size of the information in the .debug_aranges seciton.  */
3431
3432 static unsigned long
3433 size_of_aranges ()
3434 {
3435   register unsigned long size;
3436
3437   size = DWARF_ARANGES_HEADER_SIZE;
3438
3439   /* Count the address/length pair for this compilation unit.  */
3440   size += 2 * PTR_SIZE;
3441   size += 2 * PTR_SIZE * arange_table_in_use;
3442
3443   /* Count the two zero words used to terminated the address range table.  */
3444   size += 2 * PTR_SIZE;
3445   return size;
3446 }
3447 \f
3448 /* Output an unsigned LEB128 quantity.  */
3449
3450 static void
3451 output_uleb128 (value)
3452      register unsigned long value;
3453 {
3454   unsigned long save_value = value;
3455
3456   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3457   do
3458     {
3459       register unsigned byte = (value & 0x7f);
3460       value >>= 7;
3461       if (value != 0)
3462         /* More bytes to follow.  */
3463         byte |= 0x80;
3464
3465       fprintf (asm_out_file, "0x%x", byte);
3466       if (value != 0)
3467         fprintf (asm_out_file, ",");
3468     }
3469   while (value != 0);
3470
3471   if (flag_verbose_asm)
3472     fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
3473 }
3474
3475 /* Output an signed LEB128 quantity.  */
3476
3477 static void
3478 output_sleb128 (value)
3479      register long value;
3480 {
3481   register int more;
3482   register unsigned byte;
3483   long save_value = value;
3484
3485   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3486   do
3487     {
3488       byte = (value & 0x7f);
3489       /* arithmetic shift */
3490       value >>= 7;
3491       more = !((((value == 0) && ((byte & 0x40) == 0))
3492                 || ((value == -1) && ((byte & 0x40) != 0))));
3493       if (more)
3494         byte |= 0x80;
3495
3496       fprintf (asm_out_file, "0x%x", byte);
3497       if (more)
3498         fprintf (asm_out_file, ",");
3499     }
3500
3501   while (more);
3502   if (flag_verbose_asm)
3503     fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
3504 }
3505
3506 /* Select the encoding of an attribute value.  */
3507
3508 static enum dwarf_form
3509 value_format (v)
3510      dw_val_ref v;
3511 {
3512   switch (v->val_class)
3513     {
3514     case dw_val_class_addr:
3515       return DW_FORM_addr;
3516     case dw_val_class_loc:
3517       switch (constant_size (size_of_locs (v->v.val_loc)))
3518         {
3519         case 1:
3520           return DW_FORM_block1;
3521         case 2:
3522           return DW_FORM_block2;
3523         default:
3524           abort ();
3525         }
3526     case dw_val_class_const:
3527       return DW_FORM_data4;
3528     case dw_val_class_unsigned_const:
3529       switch (constant_size (v->v.val_unsigned))
3530         {
3531         case 1:
3532           return DW_FORM_data1;
3533         case 2:
3534           return DW_FORM_data2;
3535         case 4:
3536           return DW_FORM_data4;
3537         case 8:
3538           return DW_FORM_data8;
3539         default:
3540           abort ();
3541         }
3542     case dw_val_class_long_long:
3543       return DW_FORM_block1;
3544     case dw_val_class_float:
3545       return DW_FORM_block1;
3546     case dw_val_class_flag:
3547       return DW_FORM_flag;
3548     case dw_val_class_die_ref:
3549       return DW_FORM_ref;
3550     case dw_val_class_fde_ref:
3551       return DW_FORM_data;
3552     case dw_val_class_lbl_id:
3553       return DW_FORM_addr;
3554     case dw_val_class_section_offset:
3555       return DW_FORM_data;
3556     case dw_val_class_str:
3557       return DW_FORM_string;
3558     default:
3559       abort ();
3560     }
3561 }
3562
3563 /* Output the encoding of an attribute value.  */
3564
3565 static void
3566 output_value_format (v)
3567      dw_val_ref v;
3568 {
3569   enum dwarf_form form = value_format (v);
3570
3571   output_uleb128 (form);
3572   if (flag_verbose_asm)
3573     fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
3574
3575   fputc ('\n', asm_out_file);
3576 }
3577
3578 /* Output the .debug_abbrev section which defines the DIE abbreviation
3579    table.  */
3580
3581 static void
3582 output_abbrev_section ()
3583 {
3584   unsigned long abbrev_id;
3585
3586   dw_attr_ref a_attr;
3587   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3588     {
3589       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3590
3591       output_uleb128 (abbrev_id);
3592       if (flag_verbose_asm)
3593         fprintf (asm_out_file, " (abbrev code)");
3594
3595       fputc ('\n', asm_out_file);
3596       output_uleb128 (abbrev->die_tag);
3597       if (flag_verbose_asm)
3598         fprintf (asm_out_file, " (TAG: %s)",
3599                  dwarf_tag_name (abbrev->die_tag));
3600
3601       fputc ('\n', asm_out_file);
3602       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3603                abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
3604
3605       if (flag_verbose_asm)
3606         fprintf (asm_out_file, "\t%s %s",
3607                  ASM_COMMENT_START,
3608                  (abbrev->die_child != NULL
3609                   ? "DW_children_yes" : "DW_children_no"));
3610
3611       fputc ('\n', asm_out_file);
3612
3613       for (a_attr = abbrev->die_attr; a_attr != NULL;
3614            a_attr = a_attr->dw_attr_next)
3615         {
3616           output_uleb128 (a_attr->dw_attr);
3617           if (flag_verbose_asm)
3618             fprintf (asm_out_file, " (%s)",
3619                      dwarf_attr_name (a_attr->dw_attr));
3620
3621           fputc ('\n', asm_out_file);
3622           output_value_format (&a_attr->dw_attr_val);
3623         }
3624
3625       fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3626     }
3627 }
3628
3629 /* Output location description stack opcode's operands (if any).  */
3630
3631 static void
3632 output_loc_operands (loc)
3633      register dw_loc_descr_ref loc;
3634 {
3635   register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3636   register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3637
3638   switch (loc->dw_loc_opc)
3639     {
3640     case DW_OP_addr:
3641       ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3642       fputc ('\n', asm_out_file);
3643       break;
3644     case DW_OP_const1u:
3645     case DW_OP_const1s:
3646       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3647       fputc ('\n', asm_out_file);