OSDN Git Service

eb5b7dd2116613602ec18809838a4811552dfdee
[pf3gnuchains/gcc-fork.git] / gcc / dwarfout.c
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2    Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3    Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23
24 #ifdef DWARF_DEBUGGING_INFO
25 #include <stdio.h>
26 #include "dwarf.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "rtl.h"
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "reload.h"
33 #include "output.h"
34 #include "defaults.h"
35
36 /* #define NDEBUG 1 */
37 #include "assert.h"
38
39 #if defined(DWARF_TIMESTAMPS)
40 #if defined(POSIX)
41 #include <time.h>
42 #else /* !defined(POSIX) */
43 #include <sys/types.h>
44 #if defined(__STDC__)
45 extern time_t time (time_t *);
46 #else /* !defined(__STDC__) */
47 extern time_t time ();
48 #endif /* !defined(__STDC__) */
49 #endif /* !defined(POSIX) */
50 #endif /* defined(DWARF_TIMESTAMPS) */
51
52 extern char *getpwd ();
53
54 extern char *index ();
55 extern char *rindex ();
56
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58    regarding the GNU implementation of Dwarf.  */
59
60 /* NOTE: In the comments in this file, many references are made to
61    so called "Debugging Information Entries".  For the sake of brevity,
62    this term is abbreviated to `DIE' throughout the remainder of this
63    file.  */
64
65 /* Note that the implementation of C++ support herein is (as yet) unfinished.
66    If you want to try to complete it, more power to you.  */
67
68 #if !defined(__GNUC__) || (NDEBUG != 1)
69 #define inline
70 #endif
71
72 /* How to start an assembler comment.  */
73 #ifndef ASM_COMMENT_START
74 #define ASM_COMMENT_START ";#"
75 #endif
76
77 /* How to print out a register name.  */
78 #ifndef PRINT_REG
79 #define PRINT_REG(RTX, CODE, FILE) \
80   fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
81 #endif
82
83 /* Define a macro which returns non-zero for any tagged type which is
84    used (directly or indirectly) in the specification of either some
85    function's return type or some formal parameter of some function.
86    We use this macro when we are operating in "terse" mode to help us
87    know what tagged types have to be represented in Dwarf (even in
88    terse mode) and which ones don't.
89
90    A flag bit with this meaning really should be a part of the normal
91    GCC ..._TYPE nodes, but at the moment, there is no such bit defined
92    for these nodes.  For now, we have to just fake it.  It it safe for
93    us to simply return zero for all complete tagged types (which will
94    get forced out anyway if they were used in the specification of some
95    formal or return type) and non-zero for all incomplete tagged types.
96 */
97
98 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
99
100 extern int flag_traditional;
101 extern char *version_string;
102 extern char *language_string;
103
104 /* Maximum size (in bytes) of an artificially generated label.  */
105
106 #define MAX_ARTIFICIAL_LABEL_BYTES      30
107 \f
108 /* Make sure we know the sizes of the various types dwarf can describe.
109    These are only defaults.  If the sizes are different for your target,
110    you should override these values by defining the appropriate symbols
111    in your tm.h file.  */
112
113 #ifndef CHAR_TYPE_SIZE
114 #define CHAR_TYPE_SIZE BITS_PER_UNIT
115 #endif
116
117 #ifndef SHORT_TYPE_SIZE
118 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
119 #endif
120
121 #ifndef INT_TYPE_SIZE
122 #define INT_TYPE_SIZE BITS_PER_WORD
123 #endif
124
125 #ifndef LONG_TYPE_SIZE
126 #define LONG_TYPE_SIZE BITS_PER_WORD
127 #endif
128
129 #ifndef LONG_LONG_TYPE_SIZE
130 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
131 #endif
132
133 #ifndef WCHAR_TYPE_SIZE
134 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
135 #endif
136
137 #ifndef WCHAR_UNSIGNED
138 #define WCHAR_UNSIGNED 0
139 #endif
140
141 #ifndef FLOAT_TYPE_SIZE
142 #define FLOAT_TYPE_SIZE BITS_PER_WORD
143 #endif
144
145 #ifndef DOUBLE_TYPE_SIZE
146 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
147 #endif
148
149 #ifndef LONG_DOUBLE_TYPE_SIZE
150 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
151 #endif
152 \f
153 /* Structure to keep track of source filenames.  */
154
155 struct filename_entry {
156   unsigned      number;
157   char *        name;
158 };
159
160 typedef struct filename_entry filename_entry;
161
162 /* Pointer to an array of elements, each one having the structure above.  */
163
164 static filename_entry *filename_table;
165
166 /* Total number of entries in the table (i.e. array) pointed to by
167    `filename_table'.  This is the *total* and includes both used and
168    unused slots.  */
169
170 static unsigned ft_entries_allocated;
171
172 /* Number of entries in the filename_table which are actually in use.  */
173
174 static unsigned ft_entries;
175
176 /* Size (in elements) of increments by which we may expand the filename
177    table.  Actually, a single hunk of space of this size should be enough
178    for most typical programs.    */
179
180 #define FT_ENTRIES_INCREMENT 64
181
182 /* Local pointer to the name of the main input file.  Initialized in
183    dwarfout_init.  */
184
185 static char *primary_filename;
186
187 /* Pointer to the most recent filename for which we produced some line info.  */
188
189 static char *last_filename;
190
191 /* For Dwarf output, we must assign lexical-blocks id numbers
192    in the order in which their beginnings are encountered.
193    We output Dwarf debugging info that refers to the beginnings
194    and ends of the ranges of code for each lexical block with
195    assembler labels ..Bn and ..Bn.e, where n is the block number.
196    The labels themselves are generated in final.c, which assigns
197    numbers to the blocks in the same way.  */
198
199 static unsigned next_block_number = 2;
200
201 /* Counter to generate unique names for DIEs.  */
202
203 static unsigned next_unused_dienum = 1;
204
205 /* Number of the DIE which is currently being generated.  */
206
207 static unsigned current_dienum;
208
209 /* Number to use for the special "pubname" label on the next DIE which
210    represents a function or data object defined in this compilation
211    unit which has "extern" linkage.  */
212
213 static next_pubname_number = 0;
214
215 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
216
217 /* Pointer to a dynamically allocated list of pre-reserved and still
218    pending sibling DIE numbers.  Note that this list will grow as needed.  */
219
220 static unsigned *pending_sibling_stack;
221
222 /* Counter to keep track of the number of pre-reserved and still pending
223    sibling DIE numbers.  */
224
225 static unsigned pending_siblings;
226
227 /* The currently allocated size of the above list (expressed in number of
228    list elements).  */
229
230 static unsigned pending_siblings_allocated;
231
232 /* Size (in elements) of increments by which we may expand the pending
233    sibling stack.  Actually, a single hunk of space of this size should
234    be enough for most typical programs.  */
235
236 #define PENDING_SIBLINGS_INCREMENT 64
237
238 /* Non-zero if we are performing our file-scope finalization pass and if
239    we should force out Dwarf descriptions of any and all file-scope
240    tagged types which are still incomplete types.  */
241
242 static int finalizing = 0;
243
244 /* A pointer to the base of a list of pending types which we haven't
245    generated DIEs for yet, but which we will have to come back to
246    later on.  */
247
248 static tree *pending_types_list;
249
250 /* Number of elements currently allocated for the pending_types_list.  */
251
252 static unsigned pending_types_allocated;
253
254 /* Number of elements of pending_types_list currently in use.  */
255
256 static unsigned pending_types;
257
258 /* Size (in elements) of increments by which we may expand the pending
259    types list.  Actually, a single hunk of space of this size should
260    be enough for most typical programs.  */
261
262 #define PENDING_TYPES_INCREMENT 64
263
264 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
265    This is used in a hack to help us get the DIEs describing types of
266    formal parameters to come *after* all of the DIEs describing the formal
267    parameters themselves.  That's necessary in order to be compatible
268    with what the brain-damaged svr4 SDB debugger requires.  */
269
270 static tree fake_containing_scope;
271
272 /* The number of the current function definition that we are generating
273    debugging information for.  These numbers range from 1 up to the maximum
274    number of function definitions contained within the current compilation
275    unit.  These numbers are used to create unique labels for various things
276    contained within various function definitions.  */
277
278 static unsigned current_funcdef_number = 1;
279
280 /* A pointer to the ..._DECL node which we have most recently been working
281    on.  We keep this around just in case something about it looks screwy
282    and we want to tell the user what the source coordinates for the actual
283    declaration are.  */
284
285 static tree dwarf_last_decl;
286
287 /* Forward declarations for functions defined in this file.  */
288
289 static char *dwarf_tag_name             PROTO((unsigned));
290 static char *dwarf_attr_name            PROTO((unsigned));
291 static char *dwarf_stack_op_name        PROTO((unsigned));
292 static char *dwarf_typemod_name         PROTO((unsigned));
293 static char *dwarf_fmt_byte_name        PROTO((unsigned));
294 static char *dwarf_fund_type_name       PROTO((unsigned));
295 static tree decl_ultimate_origin        PROTO((tree));
296 static tree block_ultimate_origin       PROTO((tree));
297 static void output_unsigned_leb128      PROTO((unsigned long));
298 static void output_signed_leb128        PROTO((long));
299 static inline int is_body_block         PROTO((tree));
300 static int fundamental_type_code        PROTO((tree));
301 static tree root_type                   PROTO((tree));
302 static void write_modifier_bytes        PROTO((tree, int, int));
303 static inline int type_is_fundamental   PROTO((tree));
304 static void equate_decl_number_to_die_number PROTO((tree));
305 static inline void equate_type_number_to_die_number PROTO((tree));
306 static void output_reg_number           PROTO((rtx));
307 static void output_mem_loc_descriptor   PROTO((rtx));
308 static void output_loc_descriptor       PROTO((rtx));
309 static void output_bound_representation PROTO((tree, unsigned, int));
310 static void output_enumeral_list        PROTO((tree));
311 static inline unsigned ceiling          PROTO((unsigned, unsigned));
312 static inline tree field_type           PROTO((tree));
313 static inline unsigned simple_type_align_in_bits PROTO((tree));
314 static inline unsigned simple_type_size_in_bits  PROTO((tree));
315 static unsigned field_byte_offset       PROTO((tree));
316 static inline void sibling_attribute    PROTO((void));
317 static void location_attribute          PROTO((rtx));
318 static void data_member_location_attribute PROTO((tree));
319 static void const_value_attribute       PROTO((rtx));
320 static void location_or_const_value_attribute PROTO((tree));
321 static inline void name_attribute       PROTO((char *));
322 static inline void fund_type_attribute  PROTO((unsigned));
323 static void mod_fund_type_attribute     PROTO((tree, int, int));
324 static inline void user_def_type_attribute PROTO((tree));
325 static void mod_u_d_type_attribute      PROTO((tree, int, int));
326 static inline void ordering_attribute   PROTO((unsigned));
327 static void subscript_data_attribute    PROTO((tree));
328 static void byte_size_attribute         PROTO((tree));
329 static inline void bit_offset_attribute PROTO((tree));
330 static inline void bit_size_attribute   PROTO((tree));
331 static inline void element_list_attribute PROTO((tree));
332 static inline void stmt_list_attribute  PROTO((char *));
333 static inline void low_pc_attribute     PROTO((char *));
334 static inline void high_pc_attribute    PROTO((char *));
335 static inline void body_begin_attribute PROTO((char *));
336 static inline void body_end_attribute   PROTO((char *));
337 static inline void langauge_attribute   PROTO((unsigned));
338 static inline void member_attribute     PROTO((tree));
339 static inline void string_length_attribute PROTO((tree));
340 static inline void comp_dir_attribute   PROTO((char *));
341 static inline void sf_names_attribute   PROTO((char *));
342 static inline void src_info_attribute   PROTO((char *));
343 static inline void mac_info_attribute   PROTO((char *));
344 static inline void prototyped_attribute PROTO((tree));
345 static inline void producer_attribute   PROTO((char *));
346 static inline void inline_attribute     PROTO((tree));
347 static inline void containing_type_attribute PROTO((tree));
348 static inline void abstract_origin_attribute PROTO((tree));
349 static inline void src_coords_attribute PROTO((unsigned, unsigned));
350 static inline void pure_or_virtual_attribute PROTO((tree));
351 static void name_and_src_coords_attributes PROTO((tree));
352 static void type_attribute              PROTO((tree, int, int));
353 static char *type_tag                   PROTO((tree));
354 static inline void dienum_push          PROTO((void));
355 static inline void dienum_pop           PROTO((void));
356 static inline tree member_declared_type PROTO((tree));
357 static char *function_start_label       PROTO((tree));
358 static void output_array_type_die       PROTO((void *));
359 static void output_set_type_die         PROTO((void *));
360 static void output_entry_point_die      PROTO((void *));
361 static void output_inlined_enumeration_type_die PROTO((void *));
362 static void output_inlined_structure_type_die PROTO((void *));
363 static void output_inlined_union_type_die PROTO((void *));
364 static void output_enumeration_type_die PROTO((void *));
365 static void output_formal_parameter_die PROTO((void *));
366 static void output_global_subroutine_die PROTO((void *));
367 static void output_global_variable_die  PROTO((void *));
368 static void output_label_die            PROTO((void *));
369 static void output_lexical_block_die    PROTO((void *));
370 static void output_inlined_subroutine_die PROTO((void *));
371 static void output_local_variable_die   PROTO((void *));
372 static void output_member_die           PROTO((void *));
373 static void output_pointer_type_die     PROTO((void *));
374 static void output_reference_type_die   PROTO((void *));
375 static void output_ptr_to_mbr_type_die  PROTO((void *));
376 static void output_compile_unit_die     PROTO((void *));
377 static void output_string_type_die      PROTO((void *));
378 static void output_structure_type_die   PROTO((void *));
379 static void output_local_subroutine_die PROTO((void *));
380 static void output_subroutine_type_die  PROTO((void *));
381 static void output_typedef_die          PROTO((void *));
382 static void output_union_type_die       PROTO((void *));
383 static void output_unspecified_parameters_die PROTO((void *));
384 static void output_padded_null_die      PROTO((void *));
385 static void output_die                  PROTO((void (*) (), void *));
386 static void end_sibling_chain           PROTO((void));
387 static void output_formal_types         PROTO((tree));
388 static void pend_type                   PROTO((tree));
389 static inline int type_of_for_scope     PROTO((tree, tree));
390 static void output_pending_types_for_scope PROTO((tree));
391 static void output_type                 PROTO((tree, tree));
392 static void output_tagged_type_instantiation PROTO((tree));
393 static void output_block                PROTO((tree, int));
394 static void output_decls_for_scope      PROTO((tree, int));
395 static void output_decl                 PROTO((tree, tree));
396 static void shuffle_filename_entry      PROTO((filename_entry *));
397 static void geneate_new_sfname_entry    PROTO((void));
398 static unsigned lookup_filename         PROTO((char *));
399 static void generate_srcinfo_entry      PROTO((unsigned, unsigned));
400 static void generate_macinfo_entry      PROTO((char *, char *));
401 \f
402 /* Definitions of defaults for assembler-dependent names of various
403    pseudo-ops and section names.
404
405    Theses may be overridden in your tm.h file (if necessary) for your
406    particular assembler.  The default values provided here correspond to
407    what is expected by "standard" AT&T System V.4 assemblers.  */
408
409 #ifndef FILE_ASM_OP
410 #define FILE_ASM_OP             ".file"
411 #endif
412 #ifndef VERSION_ASM_OP
413 #define VERSION_ASM_OP          ".version"
414 #endif
415 #ifndef UNALIGNED_SHORT_ASM_OP
416 #define UNALIGNED_SHORT_ASM_OP  ".2byte"
417 #endif
418 #ifndef UNALIGNED_INT_ASM_OP
419 #define UNALIGNED_INT_ASM_OP    ".4byte"
420 #endif
421 #ifndef ASM_BYTE_OP
422 #define ASM_BYTE_OP             ".byte"
423 #endif
424 #ifndef SET_ASM_OP
425 #define SET_ASM_OP              ".set"
426 #endif
427
428 /* Pseudo-ops for pushing the current section onto the section stack (and
429    simultaneously changing to a new section) and for poping back to the
430    section we were in immediately before this one.  Note that most svr4
431    assemblers only maintain a one level stack... you can push all the
432    sections you want, but you can only pop out one level.  (The sparc
433    svr4 assembler is an exception to this general rule.)  That's
434    OK because we only use at most one level of the section stack herein.  */
435
436 #ifndef PUSHSECTION_ASM_OP
437 #define PUSHSECTION_ASM_OP      ".section"
438 #endif
439 #ifndef POPSECTION_ASM_OP
440 #define POPSECTION_ASM_OP       ".previous"
441 #endif
442
443 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
444    to print the PUSHSECTION_ASM_OP and the section name.  The default here
445    works for almost all svr4 assemblers, except for the sparc, where the
446    section name must be enclosed in double quotes.  (See sparcv4.h.)  */
447
448 #ifndef PUSHSECTION_FORMAT
449 #define PUSHSECTION_FORMAT      "\t%s\t%s\n"
450 #endif
451
452 #ifndef DEBUG_SECTION
453 #define DEBUG_SECTION           ".debug"
454 #endif
455 #ifndef LINE_SECTION
456 #define LINE_SECTION            ".line"
457 #endif
458 #ifndef SFNAMES_SECTION
459 #define SFNAMES_SECTION         ".debug_sfnames"
460 #endif
461 #ifndef SRCINFO_SECTION
462 #define SRCINFO_SECTION         ".debug_srcinfo"
463 #endif
464 #ifndef MACINFO_SECTION
465 #define MACINFO_SECTION         ".debug_macinfo"
466 #endif
467 #ifndef PUBNAMES_SECTION
468 #define PUBNAMES_SECTION        ".debug_pubnames"
469 #endif
470 #ifndef ARANGES_SECTION
471 #define ARANGES_SECTION         ".debug_aranges"
472 #endif
473 #ifndef TEXT_SECTION
474 #define TEXT_SECTION            ".text"
475 #endif
476 #ifndef DATA_SECTION
477 #define DATA_SECTION            ".data"
478 #endif
479 #ifndef DATA1_SECTION
480 #define DATA1_SECTION           ".data1"
481 #endif
482 #ifndef RODATA_SECTION
483 #define RODATA_SECTION          ".rodata"
484 #endif
485 #ifndef RODATA1_SECTION
486 #define RODATA1_SECTION         ".rodata1"
487 #endif
488 #ifndef BSS_SECTION
489 #define BSS_SECTION             ".bss"
490 #endif
491 \f
492 /* Definitions of defaults for formats and names of various special
493    (artificial) labels which may be generated within this file (when
494    the -g options is used and DWARF_DEBUGGING_INFO is in effect.
495
496    If necessary, these may be overridden from within your tm.h file,
497    but typically, you should never need to override these.
498
499    These labels have been hacked (temporarily) so that they all begin with
500    a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
501    stock m88k/svr4 assembler, both of which need to see .L at the start of
502    a label in order to prevent that label from going into the linker symbol
503    table).  When I get time, I'll have to fix this the right way so that we
504    will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
505    but that will require a rather massive set of changes.  For the moment,
506    the following definitions out to produce the right results for all svr4
507    and svr3 assemblers. -- rfg
508 */
509
510 #ifndef TEXT_BEGIN_LABEL
511 #define TEXT_BEGIN_LABEL        ".L_text_b"
512 #endif
513 #ifndef TEXT_END_LABEL
514 #define TEXT_END_LABEL          ".L_text_e"
515 #endif
516
517 #ifndef DATA_BEGIN_LABEL
518 #define DATA_BEGIN_LABEL        ".L_data_b"
519 #endif
520 #ifndef DATA_END_LABEL
521 #define DATA_END_LABEL          ".L_data_e"
522 #endif
523
524 #ifndef DATA1_BEGIN_LABEL
525 #define DATA1_BEGIN_LABEL       ".L_data1_b"
526 #endif
527 #ifndef DATA1_END_LABEL
528 #define DATA1_END_LABEL         ".L_data1_e"
529 #endif
530
531 #ifndef RODATA_BEGIN_LABEL
532 #define RODATA_BEGIN_LABEL      ".L_rodata_b"
533 #endif
534 #ifndef RODATA_END_LABEL
535 #define RODATA_END_LABEL        ".L_rodata_e"
536 #endif
537
538 #ifndef RODATA1_BEGIN_LABEL
539 #define RODATA1_BEGIN_LABEL     ".L_rodata1_b"
540 #endif
541 #ifndef RODATA1_END_LABEL
542 #define RODATA1_END_LABEL       ".L_rodata1_e"
543 #endif
544
545 #ifndef BSS_BEGIN_LABEL
546 #define BSS_BEGIN_LABEL         ".L_bss_b"
547 #endif
548 #ifndef BSS_END_LABEL
549 #define BSS_END_LABEL           ".L_bss_e"
550 #endif
551
552 #ifndef LINE_BEGIN_LABEL
553 #define LINE_BEGIN_LABEL        ".L_line_b"
554 #endif
555 #ifndef LINE_LAST_ENTRY_LABEL
556 #define LINE_LAST_ENTRY_LABEL   ".L_line_last"
557 #endif
558 #ifndef LINE_END_LABEL
559 #define LINE_END_LABEL          ".L_line_e"
560 #endif
561
562 #ifndef DEBUG_BEGIN_LABEL
563 #define DEBUG_BEGIN_LABEL       ".L_debug_b"
564 #endif
565 #ifndef SFNAMES_BEGIN_LABEL
566 #define SFNAMES_BEGIN_LABEL     ".L_sfnames_b"
567 #endif
568 #ifndef SRCINFO_BEGIN_LABEL
569 #define SRCINFO_BEGIN_LABEL     ".L_srcinfo_b"
570 #endif
571 #ifndef MACINFO_BEGIN_LABEL
572 #define MACINFO_BEGIN_LABEL     ".L_macinfo_b"
573 #endif
574
575 #ifndef DIE_BEGIN_LABEL_FMT
576 #define DIE_BEGIN_LABEL_FMT     ".L_D%u"
577 #endif
578 #ifndef DIE_END_LABEL_FMT
579 #define DIE_END_LABEL_FMT       ".L_D%u_e"
580 #endif
581 #ifndef PUB_DIE_LABEL_FMT
582 #define PUB_DIE_LABEL_FMT       ".L_P%u"
583 #endif
584 #ifndef INSN_LABEL_FMT
585 #define INSN_LABEL_FMT          ".L_I%u_%u"
586 #endif
587 #ifndef BLOCK_BEGIN_LABEL_FMT
588 #define BLOCK_BEGIN_LABEL_FMT   ".L_B%u"
589 #endif
590 #ifndef BLOCK_END_LABEL_FMT
591 #define BLOCK_END_LABEL_FMT     ".L_B%u_e"
592 #endif
593 #ifndef SS_BEGIN_LABEL_FMT
594 #define SS_BEGIN_LABEL_FMT      ".L_s%u"
595 #endif
596 #ifndef SS_END_LABEL_FMT
597 #define SS_END_LABEL_FMT        ".L_s%u_e"
598 #endif
599 #ifndef EE_BEGIN_LABEL_FMT
600 #define EE_BEGIN_LABEL_FMT      ".L_e%u"
601 #endif
602 #ifndef EE_END_LABEL_FMT
603 #define EE_END_LABEL_FMT        ".L_e%u_e"
604 #endif
605 #ifndef MT_BEGIN_LABEL_FMT
606 #define MT_BEGIN_LABEL_FMT      ".L_t%u"
607 #endif
608 #ifndef MT_END_LABEL_FMT
609 #define MT_END_LABEL_FMT        ".L_t%u_e"
610 #endif
611 #ifndef LOC_BEGIN_LABEL_FMT
612 #define LOC_BEGIN_LABEL_FMT     ".L_l%u"
613 #endif
614 #ifndef LOC_END_LABEL_FMT
615 #define LOC_END_LABEL_FMT       ".L_l%u_e"
616 #endif
617 #ifndef BOUND_BEGIN_LABEL_FMT
618 #define BOUND_BEGIN_LABEL_FMT   ".L_b%u_%u_%c"
619 #endif
620 #ifndef BOUND_END_LABEL_FMT
621 #define BOUND_END_LABEL_FMT     ".L_b%u_%u_%c_e"
622 #endif
623 #ifndef DERIV_BEGIN_LABEL_FMT
624 #define DERIV_BEGIN_LABEL_FMT   ".L_d%u"
625 #endif
626 #ifndef DERIV_END_LABEL_FMT
627 #define DERIV_END_LABEL_FMT     ".L_d%u_e"
628 #endif
629 #ifndef SL_BEGIN_LABEL_FMT
630 #define SL_BEGIN_LABEL_FMT      ".L_sl%u"
631 #endif
632 #ifndef SL_END_LABEL_FMT
633 #define SL_END_LABEL_FMT        ".L_sl%u_e"
634 #endif
635 #ifndef BODY_BEGIN_LABEL_FMT
636 #define BODY_BEGIN_LABEL_FMT    ".L_b%u"
637 #endif
638 #ifndef BODY_END_LABEL_FMT
639 #define BODY_END_LABEL_FMT      ".L_b%u_e"
640 #endif
641 #ifndef FUNC_END_LABEL_FMT
642 #define FUNC_END_LABEL_FMT      ".L_f%u_e"
643 #endif
644 #ifndef TYPE_NAME_FMT
645 #define TYPE_NAME_FMT           ".L_T%u"
646 #endif
647 #ifndef DECL_NAME_FMT
648 #define DECL_NAME_FMT           ".L_E%u"
649 #endif
650 #ifndef LINE_CODE_LABEL_FMT
651 #define LINE_CODE_LABEL_FMT     ".L_LC%u"
652 #endif
653 #ifndef SFNAMES_ENTRY_LABEL_FMT
654 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
655 #endif
656 #ifndef LINE_ENTRY_LABEL_FMT
657 #define LINE_ENTRY_LABEL_FMT    ".L_LE%u"
658 #endif
659 \f
660 /* Definitions of defaults for various types of primitive assembly language
661    output operations.
662
663    If necessary, these may be overridden from within your tm.h file,
664    but typically, you shouldn't need to override these.  */
665
666 #ifndef ASM_OUTPUT_PUSH_SECTION
667 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
668   fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
669 #endif
670
671 #ifndef ASM_OUTPUT_POP_SECTION
672 #define ASM_OUTPUT_POP_SECTION(FILE) \
673   fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
674 #endif
675
676 #ifndef ASM_OUTPUT_SOURCE_FILENAME
677 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
678   do {  fprintf (FILE, "\t%s\t", FILE_ASM_OP);                          \
679         output_quoted_string (FILE, NAME);                              \
680         fputc ('\n', FILE);                                             \
681   } while (0)
682 #endif
683
684 #ifndef ASM_OUTPUT_DWARF_DELTA2
685 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
686  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);             \
687         assemble_name (FILE, LABEL1);                                   \
688         fprintf (FILE, "-");                                            \
689         assemble_name (FILE, LABEL2);                                   \
690         fprintf (FILE, "\n");                                           \
691   } while (0)
692 #endif
693
694 #ifndef ASM_OUTPUT_DWARF_DELTA4
695 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
696  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
697         assemble_name (FILE, LABEL1);                                   \
698         fprintf (FILE, "-");                                            \
699         assemble_name (FILE, LABEL2);                                   \
700         fprintf (FILE, "\n");                                           \
701   } while (0)
702 #endif
703
704 #ifndef ASM_OUTPUT_DWARF_TAG
705 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG)                                  \
706   do {                                                                  \
707     fprintf ((FILE), "\t%s\t0x%x",                                      \
708                      UNALIGNED_SHORT_ASM_OP, (unsigned) TAG);           \
709     if (flag_debug_asm)                                                 \
710       fprintf ((FILE), "\t%s %s",                                       \
711                        ASM_COMMENT_START, dwarf_tag_name (TAG));        \
712     fputc ('\n', (FILE));                                               \
713   } while (0)
714 #endif
715
716 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
717 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR)                           \
718   do {                                                                  \
719     fprintf ((FILE), "\t%s\t0x%x",                                      \
720                      UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR);          \
721     if (flag_debug_asm)                                                 \
722       fprintf ((FILE), "\t%s %s",                                       \
723                        ASM_COMMENT_START, dwarf_attr_name (ATTR));      \
724     fputc ('\n', (FILE));                                               \
725   } while (0)
726 #endif
727
728 #ifndef ASM_OUTPUT_DWARF_STACK_OP
729 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP)                              \
730   do {                                                                  \
731     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP);         \
732     if (flag_debug_asm)                                                 \
733       fprintf ((FILE), "\t%s %s",                                       \
734                        ASM_COMMENT_START, dwarf_stack_op_name (OP));    \
735     fputc ('\n', (FILE));                                               \
736   } while (0)
737 #endif
738
739 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
740 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT)                             \
741   do {                                                                  \
742     fprintf ((FILE), "\t%s\t0x%x",                                      \
743                      UNALIGNED_SHORT_ASM_OP, (unsigned) FT);            \
744     if (flag_debug_asm)                                                 \
745       fprintf ((FILE), "\t%s %s",                                       \
746                        ASM_COMMENT_START, dwarf_fund_type_name (FT));   \
747     fputc ('\n', (FILE));                                               \
748   } while (0)
749 #endif
750
751 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
752 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT)                             \
753   do {                                                                  \
754     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT);        \
755     if (flag_debug_asm)                                                 \
756       fprintf ((FILE), "\t%s %s",                                       \
757                        ASM_COMMENT_START, dwarf_fmt_byte_name (FMT));   \
758     fputc ('\n', (FILE));                                               \
759   } while (0)
760 #endif
761
762 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
763 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD)                        \
764   do {                                                                  \
765     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD);        \
766     if (flag_debug_asm)                                                 \
767       fprintf ((FILE), "\t%s %s",                                       \
768                        ASM_COMMENT_START, dwarf_typemod_name (MOD));    \
769     fputc ('\n', (FILE));                                               \
770   } while (0)
771 #endif
772 \f
773 #ifndef ASM_OUTPUT_DWARF_ADDR
774 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
775  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
776         assemble_name (FILE, LABEL);                                    \
777         fprintf (FILE, "\n");                                           \
778   } while (0)
779 #endif
780
781 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
782 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX)                           \
783   do {                                                                  \
784     fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);                   \
785     output_addr_const ((FILE), (RTX));                                  \
786     fputc ('\n', (FILE));                                               \
787   } while (0)
788 #endif
789
790 #ifndef ASM_OUTPUT_DWARF_REF
791 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL)                                \
792  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
793         assemble_name (FILE, LABEL);                                    \
794         fprintf (FILE, "\n");                                           \
795   } while (0)
796 #endif
797
798 #ifndef ASM_OUTPUT_DWARF_DATA1
799 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
800   fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
801 #endif
802
803 #ifndef ASM_OUTPUT_DWARF_DATA2
804 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
805   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
806 #endif
807
808 #ifndef ASM_OUTPUT_DWARF_DATA4
809 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
810   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
811 #endif
812
813 #ifndef ASM_OUTPUT_DWARF_DATA8
814 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
815   do {                                                                  \
816     if (WORDS_BIG_ENDIAN)                                               \
817       {                                                                 \
818         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
819         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
820       }                                                                 \
821     else                                                                \
822       {                                                                 \
823         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
824         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
825       }                                                                 \
826   } while (0)
827 #endif
828
829 #ifndef ASM_OUTPUT_DWARF_STRING
830 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
831   ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
832 #endif
833 \f
834 /************************ general utility functions **************************/
835
836 inline int
837 is_pseudo_reg (rtl)
838      register rtx rtl;
839 {
840   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
841           || ((GET_CODE (rtl) == SUBREG)
842               && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
843 }
844
845 inline tree
846 type_main_variant (type)
847      register tree type;
848 {
849   type = TYPE_MAIN_VARIANT (type);
850
851   /* There really should be only one main variant among any group of variants
852      of a given type (and all of the MAIN_VARIANT values for all members of
853      the group should point to that one type) but sometimes the C front-end
854      messes this up for array types, so we work around that bug here.  */
855
856   if (TREE_CODE (type) == ARRAY_TYPE)
857     {
858       while (type != TYPE_MAIN_VARIANT (type))
859         type = TYPE_MAIN_VARIANT (type);
860     }
861
862   return type;
863 }
864
865 /* Return non-zero if the given type node represents a tagged type.  */
866
867 inline int
868 is_tagged_type (type)
869      register tree type;
870 {
871   register enum tree_code code = TREE_CODE (type);
872
873   return (code == RECORD_TYPE || code == UNION_TYPE
874           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
875 }
876
877 static char *
878 dwarf_tag_name (tag)
879      register unsigned tag;
880 {
881   switch (tag)
882     {
883     case TAG_padding:                   return "TAG_padding";
884     case TAG_array_type:                return "TAG_array_type";
885     case TAG_class_type:                return "TAG_class_type";
886     case TAG_entry_point:               return "TAG_entry_point";
887     case TAG_enumeration_type:          return "TAG_enumeration_type";
888     case TAG_formal_parameter:          return "TAG_formal_parameter";
889     case TAG_global_subroutine:         return "TAG_global_subroutine";
890     case TAG_global_variable:           return "TAG_global_variable";
891     case TAG_label:                     return "TAG_label";
892     case TAG_lexical_block:             return "TAG_lexical_block";
893     case TAG_local_variable:            return "TAG_local_variable";
894     case TAG_member:                    return "TAG_member";
895     case TAG_pointer_type:              return "TAG_pointer_type";
896     case TAG_reference_type:            return "TAG_reference_type";
897     case TAG_compile_unit:              return "TAG_compile_unit";
898     case TAG_string_type:               return "TAG_string_type";
899     case TAG_structure_type:            return "TAG_structure_type";
900     case TAG_subroutine:                return "TAG_subroutine";
901     case TAG_subroutine_type:           return "TAG_subroutine_type";
902     case TAG_typedef:                   return "TAG_typedef";
903     case TAG_union_type:                return "TAG_union_type";
904     case TAG_unspecified_parameters:    return "TAG_unspecified_parameters";
905     case TAG_variant:                   return "TAG_variant";
906     case TAG_common_block:              return "TAG_common_block";
907     case TAG_common_inclusion:          return "TAG_common_inclusion";
908     case TAG_inheritance:               return "TAG_inheritance";
909     case TAG_inlined_subroutine:        return "TAG_inlined_subroutine";
910     case TAG_module:                    return "TAG_module";
911     case TAG_ptr_to_member_type:        return "TAG_ptr_to_member_type";
912     case TAG_set_type:                  return "TAG_set_type";
913     case TAG_subrange_type:             return "TAG_subrange_type";
914     case TAG_with_stmt:                 return "TAG_with_stmt";
915
916     /* GNU extensions.  */
917
918     case TAG_format_label:              return "TAG_format_label";
919     case TAG_namelist:                  return "TAG_namelist";
920     case TAG_function_template:         return "TAG_function_template";
921     case TAG_class_template:            return "TAG_class_template";
922
923     default:                            return "TAG_<unknown>";
924     }
925 }
926
927 static char *
928 dwarf_attr_name (attr)
929      register unsigned attr;
930 {
931   switch (attr)
932     {
933     case AT_sibling:                    return "AT_sibling";
934     case AT_location:                   return "AT_location";
935     case AT_name:                       return "AT_name";
936     case AT_fund_type:                  return "AT_fund_type";
937     case AT_mod_fund_type:              return "AT_mod_fund_type";
938     case AT_user_def_type:              return "AT_user_def_type";
939     case AT_mod_u_d_type:               return "AT_mod_u_d_type";
940     case AT_ordering:                   return "AT_ordering";
941     case AT_subscr_data:                return "AT_subscr_data";
942     case AT_byte_size:                  return "AT_byte_size";
943     case AT_bit_offset:                 return "AT_bit_offset";
944     case AT_bit_size:                   return "AT_bit_size";
945     case AT_element_list:               return "AT_element_list";
946     case AT_stmt_list:                  return "AT_stmt_list";
947     case AT_low_pc:                     return "AT_low_pc";
948     case AT_high_pc:                    return "AT_high_pc";
949     case AT_language:                   return "AT_language";
950     case AT_member:                     return "AT_member";
951     case AT_discr:                      return "AT_discr";
952     case AT_discr_value:                return "AT_discr_value";
953     case AT_string_length:              return "AT_string_length";
954     case AT_common_reference:           return "AT_common_reference";
955     case AT_comp_dir:                   return "AT_comp_dir";
956     case AT_const_value_string:         return "AT_const_value_string";
957     case AT_const_value_data2:          return "AT_const_value_data2";
958     case AT_const_value_data4:          return "AT_const_value_data4";
959     case AT_const_value_data8:          return "AT_const_value_data8";
960     case AT_const_value_block2:         return "AT_const_value_block2";
961     case AT_const_value_block4:         return "AT_const_value_block4";
962     case AT_containing_type:            return "AT_containing_type";
963     case AT_default_value_addr:         return "AT_default_value_addr";
964     case AT_default_value_data2:        return "AT_default_value_data2";
965     case AT_default_value_data4:        return "AT_default_value_data4";
966     case AT_default_value_data8:        return "AT_default_value_data8";
967     case AT_default_value_string:       return "AT_default_value_string";
968     case AT_friends:                    return "AT_friends";
969     case AT_inline:                     return "AT_inline";
970     case AT_is_optional:                return "AT_is_optional";
971     case AT_lower_bound_ref:            return "AT_lower_bound_ref";
972     case AT_lower_bound_data2:          return "AT_lower_bound_data2";
973     case AT_lower_bound_data4:          return "AT_lower_bound_data4";
974     case AT_lower_bound_data8:          return "AT_lower_bound_data8";
975     case AT_private:                    return "AT_private";
976     case AT_producer:                   return "AT_producer";
977     case AT_program:                    return "AT_program";
978     case AT_protected:                  return "AT_protected";
979     case AT_prototyped:                 return "AT_prototyped";
980     case AT_public:                     return "AT_public";
981     case AT_pure_virtual:               return "AT_pure_virtual";
982     case AT_return_addr:                return "AT_return_addr";
983     case AT_abstract_origin:            return "AT_abstract_origin";
984     case AT_start_scope:                return "AT_start_scope";
985     case AT_stride_size:                return "AT_stride_size";
986     case AT_upper_bound_ref:            return "AT_upper_bound_ref";
987     case AT_upper_bound_data2:          return "AT_upper_bound_data2";
988     case AT_upper_bound_data4:          return "AT_upper_bound_data4";
989     case AT_upper_bound_data8:          return "AT_upper_bound_data8";
990     case AT_virtual:                    return "AT_virtual";
991
992     /* GNU extensions */
993
994     case AT_sf_names:                   return "AT_sf_names";
995     case AT_src_info:                   return "AT_src_info";
996     case AT_mac_info:                   return "AT_mac_info";
997     case AT_src_coords:                 return "AT_src_coords";
998     case AT_body_begin:                 return "AT_body_begin";
999     case AT_body_end:                   return "AT_body_end";
1000
1001     default:                            return "AT_<unknown>";
1002     }
1003 }
1004
1005 static char *
1006 dwarf_stack_op_name (op)
1007      register unsigned op;
1008 {
1009   switch (op)
1010     {
1011     case OP_REG:                return "OP_REG";
1012     case OP_BASEREG:            return "OP_BASEREG";
1013     case OP_ADDR:               return "OP_ADDR";
1014     case OP_CONST:              return "OP_CONST";
1015     case OP_DEREF2:             return "OP_DEREF2";
1016     case OP_DEREF4:             return "OP_DEREF4";
1017     case OP_ADD:                return "OP_ADD";
1018     default:                    return "OP_<unknown>";
1019     }
1020 }
1021
1022 static char *
1023 dwarf_typemod_name (mod)
1024      register unsigned mod;
1025 {
1026   switch (mod)
1027     {
1028     case MOD_pointer_to:        return "MOD_pointer_to";
1029     case MOD_reference_to:      return "MOD_reference_to";
1030     case MOD_const:             return "MOD_const";
1031     case MOD_volatile:          return "MOD_volatile";
1032     default:                    return "MOD_<unknown>";
1033     }
1034 }
1035
1036 static char *
1037 dwarf_fmt_byte_name (fmt)
1038      register unsigned fmt;
1039 {
1040   switch (fmt)
1041     {
1042     case FMT_FT_C_C:    return "FMT_FT_C_C";
1043     case FMT_FT_C_X:    return "FMT_FT_C_X";
1044     case FMT_FT_X_C:    return "FMT_FT_X_C";
1045     case FMT_FT_X_X:    return "FMT_FT_X_X";
1046     case FMT_UT_C_C:    return "FMT_UT_C_C";
1047     case FMT_UT_C_X:    return "FMT_UT_C_X";
1048     case FMT_UT_X_C:    return "FMT_UT_X_C";
1049     case FMT_UT_X_X:    return "FMT_UT_X_X";
1050     case FMT_ET:        return "FMT_ET";
1051     default:            return "FMT_<unknown>";
1052     }
1053 }
1054
1055 static char *
1056 dwarf_fund_type_name (ft)
1057      register unsigned ft;
1058 {
1059   switch (ft)
1060     {
1061     case FT_char:               return "FT_char";
1062     case FT_signed_char:        return "FT_signed_char";
1063     case FT_unsigned_char:      return "FT_unsigned_char";
1064     case FT_short:              return "FT_short";
1065     case FT_signed_short:       return "FT_signed_short";
1066     case FT_unsigned_short:     return "FT_unsigned_short";
1067     case FT_integer:            return "FT_integer";
1068     case FT_signed_integer:     return "FT_signed_integer";
1069     case FT_unsigned_integer:   return "FT_unsigned_integer";
1070     case FT_long:               return "FT_long";
1071     case FT_signed_long:        return "FT_signed_long";
1072     case FT_unsigned_long:      return "FT_unsigned_long";
1073     case FT_pointer:            return "FT_pointer";
1074     case FT_float:              return "FT_float";
1075     case FT_dbl_prec_float:     return "FT_dbl_prec_float";
1076     case FT_ext_prec_float:     return "FT_ext_prec_float";
1077     case FT_complex:            return "FT_complex";
1078     case FT_dbl_prec_complex:   return "FT_dbl_prec_complex";
1079     case FT_void:               return "FT_void";
1080     case FT_boolean:            return "FT_boolean";
1081     case FT_ext_prec_complex:   return "FT_ext_prec_complex";
1082     case FT_label:              return "FT_label";
1083
1084     /* GNU extensions.  */
1085
1086     case FT_long_long:          return "FT_long_long";
1087     case FT_signed_long_long:   return "FT_signed_long_long";
1088     case FT_unsigned_long_long: return "FT_unsigned_long_long";
1089
1090     case FT_int8:               return "FT_int8";
1091     case FT_signed_int8:        return "FT_signed_int8";
1092     case FT_unsigned_int8:      return "FT_unsigned_int8";
1093     case FT_int16:              return "FT_int16";
1094     case FT_signed_int16:       return "FT_signed_int16";
1095     case FT_unsigned_int16:     return "FT_unsigned_int16";
1096     case FT_int32:              return "FT_int32";
1097     case FT_signed_int32:       return "FT_signed_int32";
1098     case FT_unsigned_int32:     return "FT_unsigned_int32";
1099     case FT_int64:              return "FT_int64";
1100     case FT_signed_int64:       return "FT_signed_int64";
1101     case FT_unsigned_int64:     return "FT_signed_int64";
1102
1103     case FT_real32:             return "FT_real32";
1104     case FT_real64:             return "FT_real64";
1105     case FT_real96:             return "FT_real96";
1106     case FT_real128:            return "FT_real128";
1107
1108     default:                    return "FT_<unknown>";
1109     }
1110 }
1111
1112 /* Determine the "ultimate origin" of a decl.  The decl may be an
1113    inlined instance of an inlined instance of a decl which is local
1114    to an inline function, so we have to trace all of the way back
1115    through the origin chain to find out what sort of node actually
1116    served as the original seed for the given block.  */
1117
1118 static tree
1119 decl_ultimate_origin (decl)
1120      register tree decl;
1121 {
1122   register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1123
1124   if (immediate_origin == NULL)
1125     return NULL;
1126   else
1127     {
1128       register tree ret_val;
1129       register tree lookahead = immediate_origin;
1130
1131       do
1132         {
1133           ret_val = lookahead;
1134           lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1135         }
1136       while (lookahead != NULL && lookahead != ret_val);
1137       return ret_val;
1138     }
1139 }
1140
1141 /* Determine the "ultimate origin" of a block.  The block may be an
1142    inlined instance of an inlined instance of a block which is local
1143    to an inline function, so we have to trace all of the way back
1144    through the origin chain to find out what sort of node actually
1145    served as the original seed for the given block.  */
1146
1147 static tree
1148 block_ultimate_origin (block)
1149      register tree block;
1150 {
1151   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1152
1153   if (immediate_origin == NULL)
1154     return NULL;
1155   else
1156     {
1157       register tree ret_val;
1158       register tree lookahead = immediate_origin;
1159
1160       do
1161         {
1162           ret_val = lookahead;
1163           lookahead = (TREE_CODE (ret_val) == BLOCK)
1164                        ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1165                        : NULL;
1166         }
1167       while (lookahead != NULL && lookahead != ret_val);
1168       return ret_val;
1169     }
1170 }
1171
1172 static void
1173 output_unsigned_leb128 (value)
1174      register unsigned long value;
1175 {
1176   register unsigned long orig_value = value;
1177
1178   do
1179     {
1180       register unsigned byte = (value & 0x7f);
1181
1182       value >>= 7;
1183       if (value != 0)   /* more bytes to follow */
1184         byte |= 0x80;
1185       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1186       if (flag_debug_asm && value == 0)
1187         fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1188                  ASM_COMMENT_START, orig_value);
1189       fputc ('\n', asm_out_file);
1190     }
1191   while (value != 0);
1192 }
1193
1194 static void
1195 output_signed_leb128 (value)
1196      register long value;
1197 {
1198   register long orig_value = value;
1199   register int negative = (value < 0);
1200   register int more;
1201
1202   do
1203     {
1204       register unsigned byte = (value & 0x7f);
1205
1206       value >>= 7;
1207       if (negative)
1208         value |= 0xfe000000;  /* manually sign extend */
1209       if (((value == 0) && ((byte & 0x40) == 0))
1210           || ((value == -1) && ((byte & 0x40) == 1)))
1211         more = 0;
1212       else
1213         {
1214           byte |= 0x80;
1215           more = 1;
1216         }
1217       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1218       if (flag_debug_asm && more == 0)
1219         fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1220                  ASM_COMMENT_START, orig_value);
1221       fputc ('\n', asm_out_file);
1222     }
1223   while (more);
1224 }
1225 \f
1226 /**************** utility functions for attribute functions ******************/
1227
1228 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1229    node in question represents the outermost pair of curly braces (i.e.
1230    the "body block") of a function or method.
1231
1232    For any BLOCK node representing a "body block" of a function or method,
1233    the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1234    which represents the outermost (function) scope for the function or
1235    method (i.e. the one which includes the formal parameters).  The
1236    BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1237    FUNCTION_DECL node.
1238 */
1239
1240 static inline int
1241 is_body_block (stmt)
1242      register tree stmt;
1243 {
1244   if (TREE_CODE (stmt) == BLOCK)
1245     {
1246       register tree parent = BLOCK_SUPERCONTEXT (stmt);
1247
1248       if (TREE_CODE (parent) == BLOCK)
1249         {
1250           register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1251
1252           if (TREE_CODE (grandparent) == FUNCTION_DECL)
1253             return 1;
1254         }
1255     }
1256   return 0;
1257 }
1258
1259 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1260    type code for the given type.
1261
1262    This routine must only be called for GCC type nodes that correspond to
1263    Dwarf fundamental types.
1264
1265    The current Dwarf draft specification calls for Dwarf fundamental types
1266    to accurately reflect the fact that a given type was either a "plain"
1267    integral type or an explicitly "signed" integral type.  Unfortunately,
1268    we can't always do this, because GCC may already have thrown away the
1269    information about the precise way in which the type was originally
1270    specified, as in:
1271
1272         typedef signed int my_type;
1273
1274         struct s { my_type f; };
1275
1276    Since we may be stuck here without enought information to do exactly
1277    what is called for in the Dwarf draft specification, we do the best
1278    that we can under the circumstances and always use the "plain" integral
1279    fundamental type codes for int, short, and long types.  That's probably
1280    good enough.  The additional accuracy called for in the current DWARF
1281    draft specification is probably never even useful in practice.  */
1282
1283 static int
1284 fundamental_type_code (type)
1285      register tree type;
1286 {
1287   if (TREE_CODE (type) == ERROR_MARK)
1288     return 0;
1289
1290   switch (TREE_CODE (type))
1291     {
1292       case ERROR_MARK:
1293         return FT_void;
1294
1295       case VOID_TYPE:
1296         return FT_void;
1297
1298       case INTEGER_TYPE:
1299         /* Carefully distinguish all the standard types of C,
1300            without messing up if the language is not C.
1301            Note that we check only for the names that contain spaces;
1302            other names might occur by coincidence in other languages.  */
1303         if (TYPE_NAME (type) != 0
1304             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1305             && DECL_NAME (TYPE_NAME (type)) != 0
1306             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1307           {
1308             char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1309
1310             if (!strcmp (name, "unsigned char"))
1311               return FT_unsigned_char;
1312             if (!strcmp (name, "signed char"))
1313               return FT_signed_char;
1314             if (!strcmp (name, "unsigned int"))
1315               return FT_unsigned_integer;
1316             if (!strcmp (name, "short int"))
1317               return FT_short;
1318             if (!strcmp (name, "short unsigned int"))
1319               return FT_unsigned_short;
1320             if (!strcmp (name, "long int"))
1321               return FT_long;
1322             if (!strcmp (name, "long unsigned int"))
1323               return FT_unsigned_long;
1324             if (!strcmp (name, "long long int"))
1325               return FT_long_long;              /* Not grok'ed by svr4 SDB */
1326             if (!strcmp (name, "long long unsigned int"))
1327               return FT_unsigned_long_long;     /* Not grok'ed by svr4 SDB */
1328           }
1329
1330         /* Most integer types will be sorted out above, however, for the
1331            sake of special `array index' integer types, the following code
1332            is also provided.  */
1333
1334         if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1335           return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1336
1337         if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1338           return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1339
1340         if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1341           return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1342
1343         if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1344           return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1345
1346         if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1347           return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1348
1349         abort ();
1350
1351       case REAL_TYPE:
1352         /* Carefully distinguish all the standard types of C,
1353            without messing up if the language is not C.  */
1354         if (TYPE_NAME (type) != 0
1355             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1356             && DECL_NAME (TYPE_NAME (type)) != 0
1357             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1358           {
1359             char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1360
1361             /* Note that here we can run afowl of a serious bug in "classic"
1362                svr4 SDB debuggers.  They don't seem to understand the
1363                FT_ext_prec_float type (even though they should).  */
1364
1365             if (!strcmp (name, "long double"))
1366               return FT_ext_prec_float;
1367           }
1368
1369         if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1370           return FT_dbl_prec_float;
1371         if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1372           return FT_float;
1373
1374         /* Note that here we can run afowl of a serious bug in "classic"
1375            svr4 SDB debuggers.  They don't seem to understand the
1376            FT_ext_prec_float type (even though they should).  */
1377
1378         if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1379           return FT_ext_prec_float;
1380         abort ();
1381
1382       case COMPLEX_TYPE:
1383         return FT_complex;      /* GNU FORTRAN COMPLEX type.  */
1384
1385       case CHAR_TYPE:
1386         return FT_char;         /* GNU Pascal CHAR type.  Not used in C.  */
1387
1388       case BOOLEAN_TYPE:
1389         return FT_boolean;      /* GNU FORTRAN BOOLEAN type.  */
1390
1391       default:
1392         abort ();       /* No other TREE_CODEs are Dwarf fundamental types.  */
1393     }
1394   return 0;
1395 }
1396 \f
1397 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1398    the Dwarf "root" type for the given input type.  The Dwarf "root" type
1399    of a given type is generally the same as the given type, except that if
1400    the  given type is a pointer or reference type, then the root type of
1401    the given type is the root type of the "basis" type for the pointer or
1402    reference type.  (This definition of the "root" type is recursive.)
1403    Also, the root type of a `const' qualified type or a `volatile'
1404    qualified type is the root type of the given type without the
1405    qualifiers.  */
1406
1407 static tree
1408 root_type (type)
1409      register tree type;
1410 {
1411   if (TREE_CODE (type) == ERROR_MARK)
1412     return error_mark_node;
1413
1414   switch (TREE_CODE (type))
1415     {
1416       case ERROR_MARK:
1417         return error_mark_node;
1418
1419       case POINTER_TYPE:
1420       case REFERENCE_TYPE:
1421         return type_main_variant (root_type (TREE_TYPE (type)));
1422
1423       default:
1424         return type_main_variant (type);
1425     }
1426 }
1427
1428 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1429    of zero or more Dwarf "type-modifier" bytes applicable to the type.  */
1430
1431 static void
1432 write_modifier_bytes (type, decl_const, decl_volatile)
1433      register tree type;
1434      register int decl_const;
1435      register int decl_volatile;
1436 {
1437   if (TREE_CODE (type) == ERROR_MARK)
1438     return;
1439
1440   if (TYPE_READONLY (type) || decl_const)
1441     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1442   if (TYPE_VOLATILE (type) || decl_volatile)
1443     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1444   switch (TREE_CODE (type))
1445     {
1446       case POINTER_TYPE:
1447         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1448         write_modifier_bytes (TREE_TYPE (type), 0, 0);
1449         return;
1450
1451       case REFERENCE_TYPE:
1452         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1453         write_modifier_bytes (TREE_TYPE (type), 0, 0);
1454         return;
1455
1456       case ERROR_MARK:
1457       default:
1458         return;
1459     }
1460 }
1461 \f
1462 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1463    given input type is a Dwarf "fundamental" type.  Otherwise return zero.  */
1464
1465 static inline int
1466 type_is_fundamental (type)
1467      register tree type;
1468 {
1469   switch (TREE_CODE (type))
1470     {
1471       case ERROR_MARK:
1472       case VOID_TYPE:
1473       case INTEGER_TYPE:
1474       case REAL_TYPE:
1475       case COMPLEX_TYPE:
1476       case BOOLEAN_TYPE:
1477       case CHAR_TYPE:
1478         return 1;
1479
1480       case SET_TYPE:
1481       case ARRAY_TYPE:
1482       case RECORD_TYPE:
1483       case UNION_TYPE:
1484       case QUAL_UNION_TYPE:
1485       case ENUMERAL_TYPE:
1486       case FUNCTION_TYPE:
1487       case METHOD_TYPE:
1488       case POINTER_TYPE:
1489       case REFERENCE_TYPE:
1490       case FILE_TYPE:
1491       case OFFSET_TYPE:
1492       case LANG_TYPE:
1493         return 0;
1494
1495       default:
1496         abort ();
1497     }
1498   return 0;
1499 }
1500
1501 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1502    equate directive which will associate a symbolic name with the current DIE.
1503
1504    The name used is an artificial label generated from the DECL_UID number
1505    associated with the given decl node.  The name it gets equated to is the
1506    symbolic label that we (previously) output at the start of the DIE that
1507    we are currently generating.
1508
1509    Calling this function while generating some "decl related" form of DIE
1510    makes it possible to later refer to the DIE which represents the given
1511    decl simply by re-generating the symbolic name from the ..._DECL node's
1512    UID number.  */
1513
1514 static void
1515 equate_decl_number_to_die_number (decl)
1516      register tree decl;
1517 {
1518   /* In the case where we are generating a DIE for some ..._DECL node
1519      which represents either some inline function declaration or some
1520      entity declared within an inline function declaration/definition,
1521      setup a symbolic name for the current DIE so that we have a name
1522      for this DIE that we can easily refer to later on within
1523      AT_abstract_origin attributes.  */
1524
1525   char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1526   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1527
1528   sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1529   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1530   ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1531 }
1532
1533 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1534    equate directive which will associate a symbolic name with the current DIE.
1535
1536    The name used is an artificial label generated from the TYPE_UID number
1537    associated with the given type node.  The name it gets equated to is the
1538    symbolic label that we (previously) output at the start of the DIE that
1539    we are currently generating.
1540
1541    Calling this function while generating some "type related" form of DIE
1542    makes it easy to later refer to the DIE which represents the given type
1543    simply by re-generating the alternative name from the ..._TYPE node's
1544    UID number.  */
1545
1546 static inline void
1547 equate_type_number_to_die_number (type)
1548      register tree type;
1549 {
1550   char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1551   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1552
1553   /* We are generating a DIE to represent the main variant of this type
1554      (i.e the type without any const or volatile qualifiers) so in order
1555      to get the equate to come out right, we need to get the main variant
1556      itself here.  */
1557
1558   type = type_main_variant (type);
1559
1560   sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1561   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1562   ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1563 }
1564
1565 static void
1566 output_reg_number (rtl)
1567      register rtx rtl;
1568 {
1569   register unsigned regno = REGNO (rtl);
1570
1571   if (regno >= FIRST_PSEUDO_REGISTER)
1572     {
1573       warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1574                          regno);
1575       regno = 0;
1576     }
1577   fprintf (asm_out_file, "\t%s\t0x%x",
1578            UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1579   if (flag_debug_asm)
1580     {
1581       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1582       PRINT_REG (rtl, 0, asm_out_file);
1583     }
1584   fputc ('\n', asm_out_file);
1585 }
1586
1587 /* The following routine is a nice and simple transducer.  It converts the
1588    RTL for a variable or parameter (resident in memory) into an equivalent
1589    Dwarf representation of a mechanism for getting the address of that same
1590    variable onto the top of a hypothetical "address evaluation" stack.
1591
1592    When creating memory location descriptors, we are effectively trans-
1593    forming the RTL for a memory-resident object into its Dwarf postfix
1594    expression equivalent.  This routine just recursively descends an
1595    RTL tree, turning it into Dwarf postfix code as it goes.  */
1596
1597 static void
1598 output_mem_loc_descriptor (rtl)
1599       register rtx rtl;
1600 {
1601   /* Note that for a dynamically sized array, the location we will
1602      generate a description of here will be the lowest numbered location
1603      which is actually within the array.  That's *not* necessarily the
1604      same as the zeroth element of the array.  */
1605
1606   switch (GET_CODE (rtl))
1607     {
1608       case SUBREG:
1609
1610         /* The case of a subreg may arise when we have a local (register)
1611            variable or a formal (register) parameter which doesn't quite
1612            fill up an entire register.  For now, just assume that it is
1613            legitimate to make the Dwarf info refer to the whole register
1614            which contains the given subreg.  */
1615
1616         rtl = XEXP (rtl, 0);
1617         /* Drop thru.  */
1618
1619       case REG:
1620
1621         /* Whenever a register number forms a part of the description of
1622            the method for calculating the (dynamic) address of a memory
1623            resident object, DWARF rules require the register number to
1624            be referred to as a "base register".  This distinction is not
1625            based in any way upon what category of register the hardware
1626            believes the given register belongs to.  This is strictly
1627            DWARF terminology we're dealing with here.
1628
1629            Note that in cases where the location of a memory-resident data
1630            object could be expressed as:
1631
1632                     OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1633
1634            the actual DWARF location descriptor that we generate may just
1635            be OP_BASEREG (basereg).  This may look deceptively like the
1636            object in question was allocated to a register (rather than
1637            in memory) so DWARF consumers need to be aware of the subtle
1638            distinction between OP_REG and OP_BASEREG.  */
1639
1640         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1641         output_reg_number (rtl);
1642         break;
1643
1644       case MEM:
1645         output_mem_loc_descriptor (XEXP (rtl, 0));
1646         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1647         break;
1648
1649       case CONST:
1650       case SYMBOL_REF:
1651         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1652         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1653         break;
1654
1655       case PLUS:
1656         output_mem_loc_descriptor (XEXP (rtl, 0));
1657         output_mem_loc_descriptor (XEXP (rtl, 1));
1658         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1659         break;
1660
1661       case CONST_INT:
1662         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1663         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1664         break;
1665
1666       default:
1667         abort ();
1668     }
1669 }
1670
1671 /* Output a proper Dwarf location descriptor for a variable or parameter
1672    which is either allocated in a register or in a memory location.  For
1673    a register, we just generate an OP_REG and the register number.  For a
1674    memory location we provide a Dwarf postfix expression describing how to
1675    generate the (dynamic) address of the object onto the address stack.  */
1676
1677 static void
1678 output_loc_descriptor (rtl)
1679      register rtx rtl;
1680 {
1681   switch (GET_CODE (rtl))
1682     {
1683     case SUBREG:
1684
1685         /* The case of a subreg may arise when we have a local (register)
1686            variable or a formal (register) parameter which doesn't quite
1687            fill up an entire register.  For now, just assume that it is
1688            legitimate to make the Dwarf info refer to the whole register
1689            which contains the given subreg.  */
1690
1691         rtl = XEXP (rtl, 0);
1692         /* Drop thru.  */
1693
1694     case REG:
1695         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1696         output_reg_number (rtl);
1697         break;
1698
1699     case MEM:
1700       output_mem_loc_descriptor (XEXP (rtl, 0));
1701       break;
1702
1703     default:
1704       abort ();         /* Should never happen */
1705     }
1706 }
1707
1708 /* Given a tree node describing an array bound (either lower or upper)
1709    output a representation for that bound.  */
1710
1711 static void
1712 output_bound_representation (bound, dim_num, u_or_l)
1713      register tree bound;
1714      register unsigned dim_num; /* For multi-dimensional arrays.  */
1715      register char u_or_l;      /* Designates upper or lower bound.  */
1716 {
1717   switch (TREE_CODE (bound))
1718     {
1719
1720     case ERROR_MARK:
1721       return;
1722
1723       /* All fixed-bounds are represented by INTEGER_CST nodes.  */
1724
1725     case INTEGER_CST:
1726       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1727                               (unsigned) TREE_INT_CST_LOW (bound));
1728       break;
1729
1730     default:
1731
1732       /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1733          SAVE_EXPR nodes, in which case we can do something, or as
1734          an expression, which we cannot represent.  */
1735       {
1736         char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1737         char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1738
1739         sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1740                  current_dienum, dim_num, u_or_l);
1741
1742         sprintf (end_label, BOUND_END_LABEL_FMT,
1743                  current_dienum, dim_num, u_or_l);
1744
1745         ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1746         ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1747
1748         /* If optimization is turned on, the SAVE_EXPRs that describe
1749            how to access the upper bound values are essentially bogus.
1750            They only describe (at best) how to get at these values at
1751            the points in the generated code right after they have just
1752            been computed.  Worse yet, in the typical case, the upper
1753            bound values will not even *be* computed in the optimized
1754            code, so these SAVE_EXPRs are entirely bogus.
1755
1756            In order to compensate for this fact, we check here to see
1757            if optimization is enabled, and if so, we effectively create
1758            an empty location description for the (unknown and unknowable)
1759            upper bound.
1760
1761            This should not cause too much trouble for existing (stupid?)
1762            debuggers because they have to deal with empty upper bounds
1763            location descriptions anyway in order to be able to deal with
1764            incomplete array types.
1765
1766            Of course an intelligent debugger (GDB?) should be able to
1767            comprehend that a missing upper bound specification in a
1768            array type used for a storage class `auto' local array variable
1769            indicates that the upper bound is both unknown (at compile-
1770            time) and unknowable (at run-time) due to optimization. */
1771
1772         if (! optimize)
1773           {
1774             while (TREE_CODE (bound) == NOP_EXPR
1775                    || TREE_CODE (bound) == CONVERT_EXPR)
1776               bound = TREE_OPERAND (bound, 0);
1777
1778             if (TREE_CODE (bound) == SAVE_EXPR)
1779               output_loc_descriptor
1780                 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1781           }
1782
1783         ASM_OUTPUT_LABEL (asm_out_file, end_label);
1784       }
1785       break;
1786
1787     }
1788 }
1789
1790 /* Recursive function to output a sequence of value/name pairs for
1791    enumeration constants in reversed order.  This is called from
1792    enumeration_type_die.  */
1793
1794 static void
1795 output_enumeral_list (link)
1796      register tree link;
1797 {
1798   if (link)
1799     {
1800       output_enumeral_list (TREE_CHAIN (link));
1801       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1802                               (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1803       ASM_OUTPUT_DWARF_STRING (asm_out_file,
1804                                IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1805     }
1806 }
1807
1808 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1809    which is not less than the value itself.  */
1810
1811 static inline unsigned
1812 ceiling (value, boundary)
1813      register unsigned value;
1814      register unsigned boundary;
1815 {
1816   return (((value + boundary - 1) / boundary) * boundary);
1817 }
1818
1819 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1820    pointer to the declared type for the relevant field variable, or return
1821    `integer_type_node' if the given node turns out to be an ERROR_MARK node.  */
1822
1823 static inline tree
1824 field_type (decl)
1825      register tree decl;
1826 {
1827   register tree type;
1828
1829   if (TREE_CODE (decl) == ERROR_MARK)
1830     return integer_type_node;
1831
1832   type = DECL_BIT_FIELD_TYPE (decl);
1833   if (type == NULL)
1834     type = TREE_TYPE (decl);
1835   return type;
1836 }
1837
1838 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1839    node, return the alignment in bits for the type, or else return
1840    BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node.  */
1841
1842 static inline unsigned
1843 simple_type_align_in_bits (type)
1844      register tree type;
1845 {
1846   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1847 }
1848
1849 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1850    node, return the size in bits for the type if it is a constant, or
1851    else return the alignment for the type if the type's size is not
1852    constant, or else return BITS_PER_WORD if the type actually turns out
1853    to be an ERROR_MARK node.  */
1854
1855 static inline unsigned
1856 simple_type_size_in_bits (type)
1857      register tree type;
1858 {
1859   if (TREE_CODE (type) == ERROR_MARK)
1860     return BITS_PER_WORD;
1861   else
1862     {
1863       register tree type_size_tree = TYPE_SIZE (type);
1864
1865       if (TREE_CODE (type_size_tree) != INTEGER_CST)
1866         return TYPE_ALIGN (type);
1867
1868       return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1869     }
1870 }
1871
1872 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1873    return the byte offset of the lowest addressed byte of the "containing
1874    object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1875    mine what that offset is, either because the argument turns out to be a
1876    pointer to an ERROR_MARK node, or because the offset is actually variable.
1877    (We can't handle the latter case just yet.)  */
1878
1879 static unsigned
1880 field_byte_offset (decl)
1881      register tree decl;
1882 {
1883   register unsigned type_align_in_bytes;
1884   register unsigned type_align_in_bits;
1885   register unsigned type_size_in_bits;
1886   register unsigned object_offset_in_align_units;
1887   register unsigned object_offset_in_bits;
1888   register unsigned object_offset_in_bytes;
1889   register tree type;
1890   register tree bitpos_tree;
1891   register tree field_size_tree;
1892   register unsigned bitpos_int;
1893   register unsigned deepest_bitpos;
1894   register unsigned field_size_in_bits;
1895
1896   if (TREE_CODE (decl) == ERROR_MARK)
1897     return 0;
1898
1899   if (TREE_CODE (decl) != FIELD_DECL)
1900     abort ();
1901
1902   type = field_type (decl);
1903
1904   bitpos_tree = DECL_FIELD_BITPOS (decl);
1905   field_size_tree = DECL_SIZE (decl);
1906
1907   /* We cannot yet cope with fields whose positions or sizes are variable,
1908      so for now, when we see such things, we simply return 0.  Someday,
1909      we may be able to handle such cases, but it will be damn difficult.  */
1910
1911   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1912     return 0;
1913   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1914
1915   if (TREE_CODE (field_size_tree) != INTEGER_CST)
1916     return 0;
1917   field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
1918
1919   type_size_in_bits = simple_type_size_in_bits (type);
1920
1921   type_align_in_bits = simple_type_align_in_bits (type);
1922   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1923
1924   /* Note that the GCC front-end doesn't make any attempt to keep track
1925      of the starting bit offset (relative to the start of the containing
1926      structure type) of the hypothetical "containing object" for a bit-
1927      field.  Thus, when computing the byte offset value for the start of
1928      the "containing object" of a bit-field, we must deduce this infor-
1929      mation on our own.
1930
1931      This can be rather tricky to do in some cases.  For example, handling
1932      the following structure type definition when compiling for an i386/i486
1933      target (which only aligns long long's to 32-bit boundaries) can be very
1934      tricky:
1935
1936                 struct S {
1937                         int             field1;
1938                         long long       field2:31;
1939                 };
1940
1941      Fortunately, there is a simple rule-of-thumb which can be used in such
1942      cases.  When compiling for an i386/i486, GCC will allocate 8 bytes for
1943      the structure shown above.  It decides to do this based upon one simple
1944      rule for bit-field allocation.  Quite simply, GCC allocates each "con-
1945      taining object" for each bit-field at the first (i.e. lowest addressed)
1946      legitimate alignment boundary (based upon the required minimum alignment
1947      for the declared type of the field) which it can possibly use, subject
1948      to the condition that there is still enough available space remaining
1949      in the containing object (when allocated at the selected point) to
1950      fully accommodate all of the bits of the bit-field itself.
1951
1952      This simple rule makes it obvious why GCC allocates 8 bytes for each
1953      object of the structure type shown above.  When looking for a place to
1954      allocate the "containing object" for `field2', the compiler simply tries
1955      to allocate a 64-bit "containing object" at each successive 32-bit
1956      boundary (starting at zero) until it finds a place to allocate that 64-
1957      bit field such that at least 31 contiguous (and previously unallocated)
1958      bits remain within that selected 64 bit field.  (As it turns out, for
1959      the example above, the compiler finds that it is OK to allocate the
1960      "containing object" 64-bit field at bit-offset zero within the
1961      structure type.)
1962
1963      Here we attempt to work backwards from the limited set of facts we're
1964      given, and we try to deduce from those facts, where GCC must have
1965      believed that the containing object started (within the structure type).
1966
1967      The value we deduce is then used (by the callers of this routine) to
1968      generate AT_location and AT_bit_offset attributes for fields (both
1969      bit-fields and, in the case of AT_location, regular fields as well).
1970   */
1971
1972   /* Figure out the bit-distance from the start of the structure to the
1973      "deepest" bit of the bit-field.  */
1974   deepest_bitpos = bitpos_int + field_size_in_bits;
1975
1976   /* This is the tricky part.  Use some fancy footwork to deduce where the
1977      lowest addressed bit of the containing object must be.  */
1978   object_offset_in_bits
1979     = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
1980
1981   /* Compute the offset of the containing object in "alignment units".  */
1982   object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
1983
1984   /* Compute the offset of the containing object in bytes.  */
1985   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
1986
1987   return object_offset_in_bytes;
1988 }
1989
1990 /****************************** attributes *********************************/
1991
1992 /* The following routines are responsible for writing out the various types
1993    of Dwarf attributes (and any following data bytes associated with them).
1994    These routines are listed in order based on the numerical codes of their
1995    associated attributes.  */
1996
1997 /* Generate an AT_sibling attribute.  */
1998
1999 static inline void
2000 sibling_attribute ()
2001 {
2002   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2003
2004   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2005   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2006   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2007 }
2008
2009 /* Output the form of location attributes suitable for whole variables and
2010    whole parameters.  Note that the location attributes for struct fields
2011    are generated by the routine `data_member_location_attribute' below.  */
2012
2013 static void
2014 location_attribute (rtl)
2015      register rtx rtl;
2016 {
2017   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2018   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2019
2020   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2021   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2022   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2023   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2024   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2025
2026   /* Handle a special case.  If we are about to output a location descriptor
2027      for a variable or parameter which has been optimized out of existence,
2028      don't do that.  Instead we output a zero-length location descriptor
2029      value as part of the location attribute.
2030
2031      A variable which has been optimized out of existence will have a
2032      DECL_RTL value which denotes a pseudo-reg.
2033
2034      Currently, in some rare cases, variables can have DECL_RTL values
2035      which look like (MEM (REG pseudo-reg#)).  These cases are due to
2036      bugs elsewhere in the compiler.  We treat such cases
2037      as if the variable(s) in question had been optimized out of existence.
2038
2039      Note that in all cases where we wish to express the fact that a
2040      variable has been optimized out of existence, we do not simply
2041      suppress the generation of the entire location attribute because
2042      the absence of a location attribute in certain kinds of DIEs is
2043      used to indicate something else entirely... i.e. that the DIE
2044      represents an object declaration, but not a definition.  So saith
2045      the PLSIG.
2046   */
2047
2048   if (! is_pseudo_reg (rtl)
2049       && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2050     output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
2051
2052   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2053 }
2054
2055 /* Output the specialized form of location attribute used for data members
2056    of struct and union types.
2057
2058    In the special case of a FIELD_DECL node which represents a bit-field,
2059    the "offset" part of this special location descriptor must indicate the
2060    distance in bytes from the lowest-addressed byte of the containing
2061    struct or union type to the lowest-addressed byte of the "containing
2062    object" for the bit-field.  (See the `field_byte_offset' function above.)
2063
2064    For any given bit-field, the "containing object" is a hypothetical
2065    object (of some integral or enum type) within which the given bit-field
2066    lives.  The type of this hypothetical "containing object" is always the
2067    same as the declared type of the individual bit-field itself (for GCC
2068    anyway... the DWARF spec doesn't actually mandate this).
2069
2070    Note that it is the size (in bytes) of the hypothetical "containing
2071    object" which will be given in the AT_byte_size attribute for this
2072    bit-field.  (See the `byte_size_attribute' function below.)  It is
2073    also used when calculating the value of the AT_bit_offset attribute.
2074    (See the `bit_offset_attribute' function below.)  */
2075
2076 static void
2077 data_member_location_attribute (t)
2078      register tree t;
2079 {
2080   register unsigned object_offset_in_bytes;
2081   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2082   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2083
2084   if (TREE_CODE (t) == TREE_VEC)
2085     object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2086   else
2087     object_offset_in_bytes = field_byte_offset (t);
2088
2089   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2090   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2091   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2092   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2093   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2094   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2095   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2096   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2097   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2098 }
2099
2100 /* Output an AT_const_value attribute for a variable or a parameter which
2101    does not have a "location" either in memory or in a register.  These
2102    things can arise in GNU C when a constant is passed as an actual
2103    parameter to an inlined function.  They can also arise in C++ where
2104    declared constants do not necessarily get memory "homes".  */
2105
2106 static void
2107 const_value_attribute (rtl)
2108      register rtx rtl;
2109 {
2110   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2111   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2112
2113   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2114   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2115   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2116   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2117   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2118
2119   switch (GET_CODE (rtl))
2120     {
2121       case CONST_INT:
2122         /* Note that a CONST_INT rtx could represent either an integer or
2123            a floating-point constant.  A CONST_INT is used whenever the
2124            constant will fit into a single word.  In all such cases, the
2125            original mode of the constant value is wiped out, and the
2126            CONST_INT rtx is assigned VOIDmode.  Since we no longer have
2127            precise mode information for these constants, we always just
2128            output them using 4 bytes.  */
2129
2130         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2131         break;
2132
2133       case CONST_DOUBLE:
2134         /* Note that a CONST_DOUBLE rtx could represent either an integer
2135            or a floating-point constant.  A CONST_DOUBLE is used whenever
2136            the constant requires more than one word in order to be adequately
2137            represented.  In all such cases, the original mode of the constant
2138            value is preserved as the mode of the CONST_DOUBLE rtx, but for
2139            simplicity we always just output CONST_DOUBLEs using 8 bytes.  */
2140
2141         ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2142                                 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2143                                 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2144         break;
2145
2146       case CONST_STRING:
2147         ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2148         break;
2149
2150       case SYMBOL_REF:
2151       case LABEL_REF:
2152       case CONST:
2153         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2154         break;
2155
2156       case PLUS:
2157         /* In cases where an inlined instance of an inline function is passed
2158            the address of an `auto' variable (which is local to the caller)
2159            we can get a situation where the DECL_RTL of the artificial
2160            local variable (for the inlining) which acts as a stand-in for
2161            the corresponding formal parameter (of the inline function)
2162            will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2163            This is not exactly a compile-time constant expression, but it
2164            isn't the address of the (artificial) local variable either.
2165            Rather, it represents the *value* which the artificial local
2166            variable always has during its lifetime.  We currently have no
2167            way to represent such quasi-constant values in Dwarf, so for now
2168            we just punt and generate an AT_const_value attribute with form
2169            FORM_BLOCK4 and a length of zero.  */
2170         break;
2171
2172       default:
2173         abort ();  /* No other kinds of rtx should be possible here.  */
2174     }
2175
2176   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2177 }
2178
2179 /* Generate *either* an AT_location attribute or else an AT_const_value
2180    data attribute for a variable or a parameter.  We generate the
2181    AT_const_value attribute only in those cases where the given
2182    variable or parameter does not have a true "location" either in
2183    memory or in a register.  This can happen (for example) when a
2184    constant is passed as an actual argument in a call to an inline
2185    function.  (It's possible that these things can crop up in other
2186    ways also.)  Note that one type of constant value which can be
2187    passed into an inlined function is a constant pointer.  This can
2188    happen for example if an actual argument in an inlined function
2189    call evaluates to a compile-time constant address.  */
2190
2191 static void
2192 location_or_const_value_attribute (decl)
2193      register tree decl;
2194 {
2195   register rtx rtl;
2196
2197   if (TREE_CODE (decl) == ERROR_MARK)
2198     return;
2199
2200   if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2201     {
2202       /* Should never happen.  */
2203       abort ();
2204       return;
2205     }
2206
2207   /* Here we have to decide where we are going to say the parameter "lives"
2208      (as far as the debugger is concerned).  We only have a couple of choices.
2209      GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.  DECL_RTL
2210      normally indicates where the parameter lives during most of the activa-
2211      tion of the function.  If optimization is enabled however, this could
2212      be either NULL or else a pseudo-reg.  Both of those cases indicate that
2213      the parameter doesn't really live anywhere (as far as the code generation
2214      parts of GCC are concerned) during most of the function's activation.
2215      That will happen (for example) if the parameter is never referenced
2216      within the function.
2217
2218      We could just generate a location descriptor here for all non-NULL
2219      non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2220      be a little nicer than that if we also consider DECL_INCOMING_RTL in
2221      cases where DECL_RTL is NULL or is a pseudo-reg.
2222
2223      Note however that we can only get away with using DECL_INCOMING_RTL as
2224      a backup substitute for DECL_RTL in certain limited cases.  In cases
2225      where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2226      we can be sure that the parameter was passed using the same type as it
2227      is declared to have within the function, and that its DECL_INCOMING_RTL
2228      points us to a place where a value of that type is passed.  In cases
2229      where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2230      however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2231      substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2232      points us to a value of some type which is *different* from the type
2233      of the parameter itself.  Thus, if we tried to use DECL_INCOMING_RTL
2234      to generate a location attribute in such cases, the debugger would
2235      end up (for example) trying to fetch a `float' from a place which
2236      actually contains the first part of a `double'.  That would lead to
2237      really incorrect and confusing output at debug-time, and we don't
2238      want that now do we?
2239
2240      So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2241      in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl).  There are a
2242      couple of cute exceptions however.  On little-endian machines we can
2243      get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2244      not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2245      an integral type which is smaller than TREE_TYPE(decl).  These cases
2246      arise when (on a little-endian machine) a non-prototyped function has
2247      a parameter declared to be of type `short' or `char'.  In such cases,
2248      TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2249      `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2250      passed `int' value.  If the debugger then uses that address to fetch a
2251      `short' or a `char' (on a little-endian machine) the result will be the
2252      correct data, so we allow for such exceptional cases below.
2253
2254      Note that our goal here is to describe the place where the given formal
2255      parameter lives during most of the function's activation (i.e. between
2256      the end of the prologue and the start of the epilogue).  We'll do that
2257      as best as we can.  Note however that if the given formal parameter is
2258      modified sometime during the execution of the function, then a stack
2259      backtrace (at debug-time) will show the function as having been called
2260      with the *new* value rather than the value which was originally passed
2261      in.  This happens rarely enough that it is not a major problem, but it
2262      *is* a problem, and I'd like to fix it.  A future version of dwarfout.c
2263      may generate two additional attributes for any given TAG_formal_parameter
2264      DIE which will describe the "passed type" and the "passed location" for
2265      the given formal parameter in addition to the attributes we now generate
2266      to indicate the "declared type" and the "active location" for each
2267      parameter.  This additional set of attributes could be used by debuggers
2268      for stack backtraces.
2269
2270      Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2271      can be NULL also.  This happens (for example) for inlined-instances of
2272      inline function formal parameters which are never referenced.  This really
2273      shouldn't be happening.  All PARM_DECL nodes should get valid non-NULL
2274      DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2275      these values for inlined instances of inline function parameters, so
2276      when we see such cases, we are just SOL (shit-out-of-luck) for the time
2277      being (until integrate.c gets fixed).
2278   */
2279
2280   /* Use DECL_RTL as the "location" unless we find something better.  */
2281   rtl = DECL_RTL (decl);
2282
2283   if (TREE_CODE (decl) == PARM_DECL)
2284     if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2285       {
2286         /* This decl represents a formal parameter which was optimized out.  */
2287         register tree declared_type = type_main_variant (TREE_TYPE (decl));
2288         register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2289
2290         /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2291            *all* cases where (rtl == NULL_RTX) just below.  */
2292
2293         if (declared_type == passed_type)
2294           rtl = DECL_INCOMING_RTL (decl);
2295         else if (! BYTES_BIG_ENDIAN)
2296           if (TREE_CODE (declared_type) == INTEGER_TYPE)
2297             if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2298               rtl = DECL_INCOMING_RTL (decl);
2299       }
2300
2301   if (rtl == NULL_RTX)
2302     return;
2303
2304   switch (GET_CODE (rtl))
2305     {
2306     case CONST_INT:
2307     case CONST_DOUBLE:
2308     case CONST_STRING:
2309     case SYMBOL_REF:
2310     case LABEL_REF:
2311     case CONST:
2312     case PLUS:  /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2313       const_value_attribute (rtl);
2314       break;
2315
2316     case MEM:
2317     case REG:
2318     case SUBREG:
2319       location_attribute (rtl);
2320       break;
2321
2322     default:
2323       abort ();         /* Should never happen.  */
2324     }
2325 }
2326
2327 /* Generate an AT_name attribute given some string value to be included as
2328    the value of the attribute.  */
2329
2330 static inline void
2331 name_attribute (name_string)
2332      register char *name_string;
2333 {
2334   if (name_string && *name_string)
2335     {
2336       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2337       ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2338     }
2339 }
2340
2341 static inline void
2342 fund_type_attribute (ft_code)
2343      register unsigned ft_code;
2344 {
2345   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2346   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2347 }
2348
2349 static void
2350 mod_fund_type_attribute (type, decl_const, decl_volatile)
2351      register tree type;
2352      register int decl_const;
2353      register int decl_volatile;
2354 {
2355   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2356   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2357
2358   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2359   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2360   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2361   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2362   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2363   write_modifier_bytes (type, decl_const, decl_volatile);
2364   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2365                               fundamental_type_code (root_type (type)));
2366   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2367 }
2368
2369 static inline void
2370 user_def_type_attribute (type)
2371      register tree type;
2372 {
2373   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2374
2375   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2376   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2377   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2378 }
2379
2380 static void
2381 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2382      register tree type;
2383      register int decl_const;
2384      register int decl_volatile;
2385 {
2386   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2387   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2388   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2389
2390   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2391   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2392   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2393   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2394   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2395   write_modifier_bytes (type, decl_const, decl_volatile);
2396   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2397   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2398   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2399 }
2400
2401 #ifdef USE_ORDERING_ATTRIBUTE
2402 static inline void
2403 ordering_attribute (ordering)
2404      register unsigned ordering;
2405 {
2406   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2407   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2408 }
2409 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2410
2411 /* Note that the block of subscript information for an array type also
2412    includes information about the element type of type given array type.  */
2413
2414 static void
2415 subscript_data_attribute (type)
2416      register tree type;
2417 {
2418   register unsigned dimension_number;
2419   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2420   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2421
2422   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2423   sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2424   sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2425   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2426   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2427
2428   /* The GNU compilers represent multidimensional array types as sequences
2429      of one dimensional array types whose element types are themselves array
2430      types.  Here we squish that down, so that each multidimensional array
2431      type gets only one array_type DIE in the Dwarf debugging info.  The
2432      draft Dwarf specification say that we are allowed to do this kind
2433      of compression in C (because there is no difference between an
2434      array or arrays and a multidimensional array in C) but for other
2435      source languages (e.g. Ada) we probably shouldn't do this.  */
2436
2437   for (dimension_number = 0;
2438         TREE_CODE (type) == ARRAY_TYPE;
2439         type = TREE_TYPE (type), dimension_number++)
2440     {
2441       register tree domain = TYPE_DOMAIN (type);
2442
2443       /* Arrays come in three flavors.  Unspecified bounds, fixed
2444          bounds, and (in GNU C only) variable bounds.  Handle all
2445          three forms here.  */
2446
2447       if (domain)
2448         {
2449           /* We have an array type with specified bounds.  */
2450
2451           register tree lower = TYPE_MIN_VALUE (domain);
2452           register tree upper = TYPE_MAX_VALUE (domain);
2453
2454           /* Handle only fundamental types as index types for now.  */
2455
2456           if (! type_is_fundamental (domain))
2457             abort ();
2458
2459           /* Output the representation format byte for this dimension.  */
2460
2461           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2462                                   FMT_CODE (1,
2463                                             TREE_CODE (lower) == INTEGER_CST,
2464                                             TREE_CODE (upper) == INTEGER_CST));
2465
2466           /* Output the index type for this dimension.  */
2467
2468           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2469                                       fundamental_type_code (domain));
2470
2471           /* Output the representation for the lower bound.  */
2472
2473           output_bound_representation (lower, dimension_number, 'l');
2474
2475           /* Output the representation for the upper bound.  */
2476
2477           output_bound_representation (upper, dimension_number, 'u');
2478         }
2479       else
2480         {
2481           /* We have an array type with an unspecified length.  For C and
2482              C++ we can assume that this really means that (a) the index
2483              type is an integral type, and (b) the lower bound is zero.
2484              Note that Dwarf defines the representation of an unspecified
2485              (upper) bound as being a zero-length location description.  */
2486
2487           /* Output the array-bounds format byte.  */
2488
2489           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2490
2491           /* Output the (assumed) index type.  */
2492
2493           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2494
2495           /* Output the (assumed) lower bound (constant) value.  */
2496
2497           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2498
2499           /* Output the (empty) location description for the upper bound.  */
2500
2501           ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2502         }
2503     }
2504
2505   /* Output the prefix byte that says that the element type is coming up.  */
2506
2507   ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2508
2509   /* Output a representation of the type of the elements of this array type.  */
2510
2511   type_attribute (type, 0, 0);
2512
2513   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2514 }
2515
2516 static void
2517 byte_size_attribute (tree_node)
2518      register tree tree_node;
2519 {
2520   register unsigned size;
2521
2522   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2523   switch (TREE_CODE (tree_node))
2524     {
2525       case ERROR_MARK:
2526         size = 0;
2527         break;
2528
2529       case ENUMERAL_TYPE:
2530       case RECORD_TYPE:
2531       case UNION_TYPE:
2532       case QUAL_UNION_TYPE:
2533         size = int_size_in_bytes (tree_node);
2534         break;
2535
2536       case FIELD_DECL:
2537         /* For a data member of a struct or union, the AT_byte_size is
2538            generally given as the number of bytes normally allocated for
2539            an object of the *declared* type of the member itself.  This
2540            is true even for bit-fields.  */
2541         size = simple_type_size_in_bits (field_type (tree_node))
2542                / BITS_PER_UNIT;
2543         break;
2544
2545       default:
2546         abort ();
2547     }
2548
2549   /* Note that `size' might be -1 when we get to this point.  If it
2550      is, that indicates that the byte size of the entity in question
2551      is variable.  We have no good way of expressing this fact in Dwarf
2552      at the present time, so just let the -1 pass on through.  */
2553
2554   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2555 }
2556
2557 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2558    which specifies the distance in bits from the highest order bit of the
2559    "containing object" for the bit-field to the highest order bit of the
2560    bit-field itself.
2561
2562    For any given bit-field, the "containing object" is a hypothetical
2563    object (of some integral or enum type) within which the given bit-field
2564    lives.  The type of this hypothetical "containing object" is always the
2565    same as the declared type of the individual bit-field itself.
2566
2567    The determination of the exact location of the "containing object" for
2568    a bit-field is rather complicated.  It's handled by the `field_byte_offset'
2569    function (above).
2570
2571    Note that it is the size (in bytes) of the hypothetical "containing
2572    object" which will be given in the AT_byte_size attribute for this
2573    bit-field.  (See `byte_size_attribute' above.) */
2574
2575 static inline void
2576 bit_offset_attribute (decl)
2577     register tree decl;
2578 {
2579   register unsigned object_offset_in_bytes = field_byte_offset (decl);
2580   register tree type = DECL_BIT_FIELD_TYPE (decl);
2581   register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2582   register unsigned bitpos_int;
2583   register unsigned highest_order_object_bit_offset;
2584   register unsigned highest_order_field_bit_offset;
2585   register unsigned bit_offset;
2586
2587   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
2588   assert (type);                                /* Must be a bit field.  */
2589
2590   /* We can't yet handle bit-fields whose offsets are variable, so if we
2591      encounter such things, just return without generating any attribute
2592      whatsoever.  */
2593
2594   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2595     return;
2596   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2597
2598   /* Note that the bit offset is always the distance (in bits) from the
2599      highest-order bit of the "containing object" to the highest-order
2600      bit of the bit-field itself.  Since the "high-order end" of any
2601      object or field is different on big-endian and little-endian machines,
2602      the computation below must take account of these differences.  */
2603
2604   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2605   highest_order_field_bit_offset = bitpos_int;
2606
2607   if (! BYTES_BIG_ENDIAN)
2608     {
2609       highest_order_field_bit_offset
2610         += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2611
2612       highest_order_object_bit_offset += simple_type_size_in_bits (type);
2613     }
2614
2615   bit_offset =
2616     (! BYTES_BIG_ENDIAN
2617      ? highest_order_object_bit_offset - highest_order_field_bit_offset
2618      : highest_order_field_bit_offset - highest_order_object_bit_offset);
2619
2620   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2621   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2622 }
2623
2624 /* For a FIELD_DECL node which represents a bit field, output an attribute
2625    which specifies the length in bits of the given field.  */
2626
2627 static inline void
2628 bit_size_attribute (decl)
2629     register tree decl;
2630 {
2631   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
2632   assert (DECL_BIT_FIELD_TYPE (decl));          /* Must be a bit field.  */
2633
2634   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2635   ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2636                           (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2637 }
2638
2639 /* The following routine outputs the `element_list' attribute for enumeration
2640    type DIEs.  The element_lits attribute includes the names and values of
2641    all of the enumeration constants associated with the given enumeration
2642    type.  */
2643
2644 static inline void
2645 element_list_attribute (element)
2646      register tree element;
2647 {
2648   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2649   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2650
2651   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2652   sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2653   sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2654   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2655   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2656
2657   /* Here we output a list of value/name pairs for each enumeration constant
2658      defined for this enumeration type (as required), but we do it in REVERSE
2659      order.  The order is the one required by the draft #5 Dwarf specification
2660      published by the UI/PLSIG.  */
2661
2662   output_enumeral_list (element);   /* Recursively output the whole list.  */
2663
2664   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2665 }
2666
2667 /* Generate an AT_stmt_list attribute.  These are normally present only in
2668    DIEs with a TAG_compile_unit tag.  */
2669
2670 static inline void
2671 stmt_list_attribute (label)
2672     register char *label;
2673 {
2674   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2675   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2676   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2677 }
2678
2679 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2680    for a subroutine DIE.  */
2681
2682 static inline void
2683 low_pc_attribute (asm_low_label)
2684      register char *asm_low_label;
2685 {
2686   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2687   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2688 }
2689
2690 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2691    subroutine DIE.  */
2692
2693 static inline void
2694 high_pc_attribute (asm_high_label)
2695     register char *asm_high_label;
2696 {
2697   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2698   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2699 }
2700
2701 /* Generate an AT_body_begin attribute for a subroutine DIE.  */
2702
2703 static inline void
2704 body_begin_attribute (asm_begin_label)
2705      register char *asm_begin_label;
2706 {
2707   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2708   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2709 }
2710
2711 /* Generate an AT_body_end attribute for a subroutine DIE.  */
2712
2713 static inline void
2714 body_end_attribute (asm_end_label)
2715      register char *asm_end_label;
2716 {
2717   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2718   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2719 }
2720
2721 /* Generate an AT_language attribute given a LANG value.  These attributes
2722    are used only within TAG_compile_unit DIEs.  */
2723
2724 static inline void
2725 language_attribute (language_code)
2726      register unsigned language_code;
2727 {
2728   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2729   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2730 }
2731
2732 static inline void
2733 member_attribute (context)
2734     register tree context;
2735 {
2736   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2737
2738   /* Generate this attribute only for members in C++.  */
2739
2740   if (context != NULL && is_tagged_type (context))
2741     {
2742       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2743       sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2744       ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2745     }
2746 }
2747
2748 static inline void
2749 string_length_attribute (upper_bound)
2750      register tree upper_bound;
2751 {
2752   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2753   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2754
2755   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2756   sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2757   sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2758   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2759   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2760   output_bound_representation (upper_bound, 0, 'u');
2761   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2762 }
2763
2764 static inline void
2765 comp_dir_attribute (dirname)
2766      register char *dirname;
2767 {
2768   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2769   ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2770 }
2771
2772 static inline void
2773 sf_names_attribute (sf_names_start_label)
2774      register char *sf_names_start_label;
2775 {
2776   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2777   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2778   ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2779 }
2780
2781 static inline void
2782 src_info_attribute (src_info_start_label)
2783      register char *src_info_start_label;
2784 {
2785   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2786   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2787   ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2788 }
2789
2790 static inline void
2791 mac_info_attribute (mac_info_start_label)
2792      register char *mac_info_start_label;
2793 {
2794   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2795   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2796   ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2797 }
2798
2799 static inline void
2800 prototyped_attribute (func_type)
2801      register tree func_type;
2802 {
2803   if ((strcmp (language_string, "GNU C") == 0)
2804       && (TYPE_ARG_TYPES (func_type) != NULL))
2805     {
2806       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2807       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2808     }
2809 }
2810
2811 static inline void
2812 producer_attribute (producer)
2813      register char *producer;
2814 {
2815   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2816   ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2817 }
2818
2819 static inline void
2820 inline_attribute (decl)
2821      register tree decl;
2822 {
2823   if (DECL_INLINE (decl))
2824     {
2825       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2826       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2827     }
2828 }
2829
2830 static inline void
2831 containing_type_attribute (containing_type)
2832      register tree containing_type;
2833 {
2834   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2835
2836   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2837   sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2838   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2839 }
2840
2841 static inline void
2842 abstract_origin_attribute (origin)
2843      register tree origin;
2844 {
2845   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2846
2847   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2848   switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2849     {
2850     case 'd':
2851       sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2852       break;
2853
2854     case 't':
2855       sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2856       break;
2857
2858     default:
2859       abort ();         /* Should never happen.  */
2860
2861     }
2862   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2863 }
2864
2865 #ifdef DWARF_DECL_COORDINATES
2866 static inline void
2867 src_coords_attribute (src_fileno, src_lineno)
2868      register unsigned src_fileno;
2869      register unsigned src_lineno;
2870 {
2871   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2872   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2873   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2874 }
2875 #endif /* defined(DWARF_DECL_COORDINATES) */
2876
2877 static inline void
2878 pure_or_virtual_attribute (func_decl)
2879      register tree func_decl;
2880 {
2881   if (DECL_VIRTUAL_P (func_decl))
2882     {
2883 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific.  */
2884       if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2885         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2886       else
2887 #endif
2888         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2889       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2890     }
2891 }
2892
2893 /************************* end of attributes *****************************/
2894
2895 /********************* utility routines for DIEs *************************/
2896
2897 /* Output an AT_name attribute and an AT_src_coords attribute for the
2898    given decl, but only if it actually has a name.  */
2899
2900 static void
2901 name_and_src_coords_attributes (decl)
2902     register tree decl;
2903 {
2904   register tree decl_name = DECL_NAME (decl);
2905
2906   if (decl_name && IDENTIFIER_POINTER (decl_name))
2907     {
2908       name_attribute (IDENTIFIER_POINTER (decl_name));
2909 #ifdef DWARF_DECL_COORDINATES
2910       {
2911         register unsigned file_index;
2912
2913         /* This is annoying, but we have to pop out of the .debug section
2914            for a moment while we call `lookup_filename' because calling it
2915            may cause a temporary switch into the .debug_sfnames section and
2916            most svr4 assemblers are not smart enough be be able to nest
2917            section switches to any depth greater than one.  Note that we
2918            also can't skirt this issue by delaying all output to the
2919            .debug_sfnames section unit the end of compilation because that
2920            would cause us to have inter-section forward references and
2921            Fred Fish sez that m68k/svr4 assemblers botch those.  */
2922
2923         ASM_OUTPUT_POP_SECTION (asm_out_file);
2924         file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2925         ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2926
2927         src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2928       }
2929 #endif /* defined(DWARF_DECL_COORDINATES) */
2930     }
2931 }
2932
2933 /* Many forms of DIEs contain a "type description" part.  The following
2934    routine writes out these "type descriptor" parts.  */
2935
2936 static void
2937 type_attribute (type, decl_const, decl_volatile)
2938      register tree type;
2939      register int decl_const;
2940      register int decl_volatile;
2941 {
2942   register enum tree_code code = TREE_CODE (type);
2943   register int root_type_modified;
2944
2945   if (TREE_CODE (type) == ERROR_MARK)
2946     return;
2947
2948   /* Handle a special case.  For functions whose return type is void,
2949      we generate *no* type attribute.  (Note that no object may have
2950      type `void', so this only applies to function return types.  */
2951
2952   if (TREE_CODE (type) == VOID_TYPE)
2953     return;
2954
2955   root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2956                         || decl_const || decl_volatile
2957                         || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2958
2959   if (type_is_fundamental (root_type (type)))
2960     if (root_type_modified)
2961         mod_fund_type_attribute (type, decl_const, decl_volatile);
2962     else
2963         fund_type_attribute (fundamental_type_code (type));
2964   else
2965     if (root_type_modified)
2966         mod_u_d_type_attribute (type, decl_const, decl_volatile);
2967     else
2968         /* We have to get the type_main_variant here (and pass that to the
2969            `user_def_type_attribute' routine) because the ..._TYPE node we
2970            have might simply be a *copy* of some original type node (where
2971            the copy was created to help us keep track of typedef names)
2972            and that copy might have a different TYPE_UID from the original
2973            ..._TYPE node.  (Note that when `equate_type_number_to_die_number'
2974            is labeling a given type DIE for future reference, it always and
2975            only creates labels for DIEs representing *main variants*, and it
2976            never even knows about non-main-variants.)  */
2977         user_def_type_attribute (type_main_variant (type));
2978 }
2979
2980 /* Given a tree pointer to a struct, class, union, or enum type node, return
2981    a pointer to the (string) tag name for the given type, or zero if the
2982    type was declared without a tag.  */
2983
2984 static char *
2985 type_tag (type)
2986      register tree type;
2987 {
2988   register char *name = 0;
2989
2990   if (TYPE_NAME (type) != 0)
2991     {
2992       register tree t = 0;
2993
2994       /* Find the IDENTIFIER_NODE for the type name.  */
2995       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2996         t = TYPE_NAME (type);
2997
2998       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to 
2999          a TYPE_DECL node, regardless of whether or not a `typedef' was
3000          involved.  */
3001       else
3002         if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
3003           t = DECL_NAME (TYPE_NAME (type));
3004
3005       /* Now get the name as a string, or invent one.  */
3006       if (t != 0)
3007         name = IDENTIFIER_POINTER (t);
3008     }
3009
3010   return (name == 0 || *name == '\0') ? 0 : name;
3011 }
3012
3013 static inline void
3014 dienum_push ()
3015 {
3016   /* Start by checking if the pending_sibling_stack needs to be expanded.
3017      If necessary, expand it.  */
3018
3019   if (pending_siblings == pending_siblings_allocated)
3020     {
3021       pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3022       pending_sibling_stack
3023         = (unsigned *) xrealloc (pending_sibling_stack,
3024                                  pending_siblings_allocated * sizeof(unsigned));
3025     }
3026
3027   pending_siblings++;
3028   NEXT_DIE_NUM = next_unused_dienum++;
3029 }
3030
3031 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3032    NEXT_DIE_NUM.  */
3033
3034 static inline void
3035 dienum_pop ()
3036 {
3037   pending_siblings--;
3038 }
3039
3040 static inline tree
3041 member_declared_type (member)
3042      register tree member;
3043 {
3044   return (DECL_BIT_FIELD_TYPE (member))
3045            ? DECL_BIT_FIELD_TYPE (member)
3046            : TREE_TYPE (member);
3047 }
3048
3049 /* Get the function's label, as described by its RTL.
3050    This may be different from the DECL_NAME name used
3051    in the source file.  */
3052
3053 static char *
3054 function_start_label (decl)
3055     register tree decl;
3056 {
3057   rtx x;
3058   char *fnname;
3059
3060   x = DECL_RTL (decl);
3061   if (GET_CODE (x) != MEM)
3062     abort ();
3063   x = XEXP (x, 0);
3064   if (GET_CODE (x) != SYMBOL_REF)
3065                abort ();
3066   fnname = XSTR (x, 0);
3067   return fnname;
3068 }
3069
3070
3071 /******************************* DIEs ************************************/
3072
3073 /* Output routines for individual types of DIEs.  */
3074
3075 /* Note that every type of DIE (except a null DIE) gets a sibling.  */
3076
3077 static void
3078 output_array_type_die (arg)
3079      register void *arg;
3080 {
3081   register tree type = arg;
3082
3083   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3084   sibling_attribute ();
3085   equate_type_number_to_die_number (type);
3086   member_attribute (TYPE_CONTEXT (type));
3087
3088   /* I believe that we can default the array ordering.  SDB will probably
3089      do the right things even if AT_ordering is not present.  It's not
3090      even an issue until we start to get into multidimensional arrays
3091      anyway.  If SDB is ever caught doing the Wrong Thing for multi-
3092      dimensional arrays, then we'll have to put the AT_ordering attribute
3093      back in.  (But if and when we find out that we need to put these in,
3094      we will only do so for multidimensional arrays.  After all, we don't
3095      want to waste space in the .debug section now do we?)  */
3096
3097 #ifdef USE_ORDERING_ATTRIBUTE
3098   ordering_attribute (ORD_row_major);
3099 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3100
3101   subscript_data_attribute (type);
3102 }
3103
3104 static void
3105 output_set_type_die (arg)
3106      register void *arg;
3107 {
3108   register tree type = arg;
3109
3110   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3111   sibling_attribute ();
3112   equate_type_number_to_die_number (type);
3113   member_attribute (TYPE_CONTEXT (type));
3114   type_attribute (TREE_TYPE (type), 0, 0);
3115 }
3116
3117 #if 0
3118 /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
3119
3120 static void
3121 output_entry_point_die (arg)
3122      register void *arg;
3123 {
3124   register tree decl = arg;
3125   register tree origin = decl_ultimate_origin (decl);
3126
3127   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3128   sibling_attribute ();
3129   dienum_push ();
3130   if (origin != NULL)
3131     abstract_origin_attribute (origin);
3132   else
3133     {
3134       name_and_src_coords_attributes (decl);
3135       member_attribute (DECL_CONTEXT (decl));
3136       type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3137     }
3138   if (DECL_ABSTRACT (decl))
3139     equate_decl_number_to_die_number (decl);
3140   else
3141     low_pc_attribute (function_start_label (decl));
3142 }
3143 #endif
3144
3145 /* Output a DIE to represent an inlined instance of an enumeration type.  */
3146
3147 static void
3148 output_inlined_enumeration_type_die (arg)
3149      register void *arg;
3150 {
3151   register tree type = arg;
3152
3153   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3154   sibling_attribute ();
3155   assert (TREE_ASM_WRITTEN (type));
3156   abstract_origin_attribute (type);
3157 }
3158
3159 /* Output a DIE to represent an inlined instance of a structure type.  */
3160
3161 static void
3162 output_inlined_structure_type_die (arg)
3163      register void *arg;
3164 {
3165   register tree type = arg;
3166
3167   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3168   sibling_attribute ();
3169   assert (TREE_ASM_WRITTEN (type));
3170   abstract_origin_attribute (type);
3171 }
3172
3173 /* Output a DIE to represent an inlined instance of a union type.  */
3174
3175 static void
3176 output_inlined_union_type_die (arg)
3177      register void *arg;
3178 {
3179   register tree type = arg;
3180
3181   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3182   sibling_attribute ();
3183   assert (TREE_ASM_WRITTEN (type));
3184   abstract_origin_attribute (type);
3185 }
3186
3187 /* Output a DIE to represent an enumeration type.  Note that these DIEs
3188    include all of the information about the enumeration values also.
3189    This information is encoded into the element_list attribute.  */
3190
3191 static void
3192 output_enumeration_type_die (arg)
3193      register void *arg;
3194 {
3195   register tree type = arg;
3196
3197   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3198   sibling_attribute ();
3199   equate_type_number_to_die_number (type);
3200   name_attribute (type_tag (type));
3201   member_attribute (TYPE_CONTEXT (type));
3202
3203   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
3204      given enum type is incomplete, do not generate the AT_byte_size
3205      attribute or the AT_element_list attribute.  */
3206
3207   if (TYPE_SIZE (type))
3208     {
3209       byte_size_attribute (type);
3210       element_list_attribute (TYPE_FIELDS (type));
3211     }
3212 }
3213
3214 /* Output a DIE to represent either a real live formal parameter decl or
3215    to represent just the type of some formal parameter position in some
3216    function type.
3217
3218    Note that this routine is a bit unusual because its argument may be
3219    a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3220    represents an inlining of some PARM_DECL) or else some sort of a
3221    ..._TYPE node.  If it's the former then this function is being called
3222    to output a DIE to represent a formal parameter object (or some inlining
3223    thereof).  If it's the latter, then this function is only being called
3224    to output a TAG_formal_parameter DIE to stand as a placeholder for some
3225    formal argument type of some subprogram type.  */
3226
3227 static void
3228 output_formal_parameter_die (arg)
3229      register void *arg;
3230 {
3231   register tree node = arg;
3232
3233   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3234   sibling_attribute ();
3235
3236   switch (TREE_CODE_CLASS (TREE_CODE (node)))
3237     {
3238     case 'd':   /* We were called with some kind of a ..._DECL node.  */
3239       {
3240         register tree origin = decl_ultimate_origin (node);
3241
3242         if (origin != NULL)
3243           abstract_origin_attribute (origin);
3244         else
3245           {
3246             name_and_src_coords_attributes (node);
3247             type_attribute (TREE_TYPE (node),
3248                             TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3249           }
3250         if (DECL_ABSTRACT (node))
3251           equate_decl_number_to_die_number (node);
3252         else
3253           location_or_const_value_attribute (node);
3254       }
3255       break;
3256
3257     case 't':   /* We were called with some kind of a ..._TYPE node.  */
3258       type_attribute (node, 0, 0);
3259       break;
3260
3261     default:
3262       abort (); /* Should never happen.  */
3263     }
3264 }
3265
3266 /* Output a DIE to represent a declared function (either file-scope
3267    or block-local) which has "external linkage" (according to ANSI-C).  */
3268
3269 static void
3270 output_global_subroutine_die (arg)
3271      register void *arg;
3272 {
3273   register tree decl = arg;
3274   register tree origin = decl_ultimate_origin (decl);
3275
3276   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3277   sibling_attribute ();
3278   dienum_push ();
3279   if (origin != NULL)
3280     abstract_origin_attribute (origin);
3281   else
3282     {
3283       register tree type = TREE_TYPE (decl);
3284
3285       name_and_src_coords_attributes (decl);
3286       inline_attribute (decl);
3287       prototyped_attribute (type);
3288       member_attribute (DECL_CONTEXT (decl));
3289       type_attribute (TREE_TYPE (type), 0, 0);
3290       pure_or_virtual_attribute (decl);
3291     }
3292   if (DECL_ABSTRACT (decl))
3293     equate_decl_number_to_die_number (decl);
3294   else
3295     {
3296       if (! DECL_EXTERNAL (decl))
3297         {
3298           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3299
3300           low_pc_attribute (function_start_label (decl));
3301           sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3302           high_pc_attribute (label);
3303           sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3304           body_begin_attribute (label);
3305           sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3306           body_end_attribute (label);
3307         }
3308     }
3309 }
3310
3311 /* Output a DIE to represent a declared data object (either file-scope
3312    or block-local) which has "external linkage" (according to ANSI-C).  */
3313
3314 static void
3315 output_global_variable_die (arg)
3316      register void *arg;
3317 {
3318   register tree decl = arg;
3319   register tree origin = decl_ultimate_origin (decl);
3320
3321   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3322   sibling_attribute ();
3323   if (origin != NULL)
3324     abstract_origin_attribute (origin);
3325   else
3326     {
3327       name_and_src_coords_attributes (decl);
3328       member_attribute (DECL_CONTEXT (decl));
3329       type_attribute (TREE_TYPE (decl),
3330                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3331     }
3332   if (DECL_ABSTRACT (decl))
3333     equate_decl_number_to_die_number (decl);
3334   else
3335     {
3336       if (!DECL_EXTERNAL (decl))
3337         location_or_const_value_attribute (decl);
3338     }
3339 }
3340
3341 static void
3342 output_label_die (arg)
3343      register void *arg;
3344 {
3345   register tree decl = arg;
3346   register tree origin = decl_ultimate_origin (decl);
3347
3348   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3349   sibling_attribute ();
3350   if (origin != NULL)
3351     abstract_origin_attribute (origin);
3352   else
3353     name_and_src_coords_attributes (decl);
3354   if (DECL_ABSTRACT (decl))
3355     equate_decl_number_to_die_number (decl);
3356   else
3357     {
3358       register rtx insn = DECL_RTL (decl);
3359
3360       if (GET_CODE (insn) == CODE_LABEL)
3361         {
3362           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3363
3364           /* When optimization is enabled (via -O) some parts of the compiler
3365              (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3366              represent source-level labels which were explicitly declared by
3367              the user.  This really shouldn't be happening though, so catch
3368              it if it ever does happen.  */
3369
3370           if (INSN_DELETED_P (insn))
3371             abort ();   /* Should never happen.  */
3372
3373           sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3374                                           (unsigned) INSN_UID (insn));
3375           low_pc_attribute (label);
3376         }
3377     }
3378 }
3379
3380 static void
3381 output_lexical_block_die (arg)
3382      register void *arg;
3383 {
3384   register tree stmt = arg;
3385
3386   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3387   sibling_attribute ();
3388   dienum_push ();
3389   if (! BLOCK_ABSTRACT (stmt))
3390     {
3391       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3392       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3393
3394       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3395       low_pc_attribute (begin_label);
3396       sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3397       high_pc_attribute (end_label);
3398     }
3399 }
3400
3401 static void
3402 output_inlined_subroutine_die (arg)
3403      register void *arg;
3404 {
3405   register tree stmt = arg;
3406
3407   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3408   sibling_attribute ();
3409   dienum_push ();
3410   abstract_origin_attribute (block_ultimate_origin (stmt));
3411   if (! BLOCK_ABSTRACT (stmt))
3412     {
3413       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3414       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3415
3416       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3417       low_pc_attribute (begin_label);
3418       sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3419       high_pc_attribute (end_label);
3420     }
3421 }
3422
3423 /* Output a DIE to represent a declared data object (either file-scope
3424    or block-local) which has "internal linkage" (according to ANSI-C).  */
3425
3426 static void
3427 output_local_variable_die (arg)
3428      register void *arg;
3429 {
3430   register tree decl = arg;
3431   register tree origin = decl_ultimate_origin (decl);
3432
3433   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3434   sibling_attribute ();
3435   if (origin != NULL)
3436     abstract_origin_attribute (origin);
3437   else
3438     {
3439       name_and_src_coords_attributes (decl);
3440       member_attribute (DECL_CONTEXT (decl));
3441       type_attribute (TREE_TYPE (decl),
3442                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3443     }
3444   if (DECL_ABSTRACT (decl))
3445     equate_decl_number_to_die_number (decl);
3446   else
3447     location_or_const_value_attribute (decl);
3448 }
3449
3450 static void
3451 output_member_die (arg)
3452      register void *arg;
3453 {
3454   register tree decl = arg;
3455
3456   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3457   sibling_attribute ();
3458   name_and_src_coords_attributes (decl);
3459   member_attribute (DECL_CONTEXT (decl));
3460   type_attribute (member_declared_type (decl),
3461                   TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3462   if (DECL_BIT_FIELD_TYPE (decl))       /* If this is a bit field...  */
3463     {
3464       byte_size_attribute (decl);
3465       bit_size_attribute (decl);
3466       bit_offset_attribute (decl);
3467     }
3468   data_member_location_attribute (decl);
3469 }
3470
3471 #if 0
3472 /* Don't generate either pointer_type DIEs or reference_type DIEs.  Use
3473    modified types instead.
3474
3475    We keep this code here just in case these types of DIEs may be
3476    needed to represent certain things in other languages (e.g. Pascal)
3477    someday.  */
3478
3479 static void
3480 output_pointer_type_die (arg)
3481      register void *arg;
3482 {
3483   register tree type = arg;
3484
3485   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3486   sibling_attribute ();
3487   equate_type_number_to_die_number (type);
3488   member_attribute (TYPE_CONTEXT (type));
3489   type_attribute (TREE_TYPE (type), 0, 0);
3490 }
3491
3492 static void
3493 output_reference_type_die (arg)
3494      register void *arg;
3495 {
3496   register tree type = arg;
3497
3498   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3499   sibling_attribute ();
3500   equate_type_number_to_die_number (type);
3501   member_attribute (TYPE_CONTEXT (type));
3502   type_attribute (TREE_TYPE (type), 0, 0);
3503 }
3504 #endif
3505
3506 static void
3507 output_ptr_to_mbr_type_die (arg)
3508      register void *arg;
3509 {
3510   register tree type = arg;
3511
3512   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3513   sibling_attribute ();
3514   equate_type_number_to_die_number (type);
3515   member_attribute (TYPE_CONTEXT (type));
3516   containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3517   type_attribute (TREE_TYPE (type), 0, 0);
3518 }
3519
3520 static void
3521 output_compile_unit_die (arg)
3522      register void *arg;
3523 {
3524   register char *main_input_filename = arg;
3525
3526   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3527   sibling_attribute ();
3528   dienum_push ();
3529   name_attribute (main_input_filename);
3530
3531   {
3532     char producer[250];
3533
3534     sprintf (producer, "%s %s", language_string, version_string);
3535     producer_attribute (producer);
3536   }
3537
3538   if (strcmp (language_string, "GNU C++") == 0)
3539     language_attribute (LANG_C_PLUS_PLUS);
3540   else if (strcmp (language_string, "GNU Ada") == 0)
3541     language_attribute (LANG_ADA83);
3542   else if (strcmp (language_string, "GNU F77") == 0)
3543     language_attribute (LANG_FORTRAN77);
3544   else if (flag_traditional)
3545     language_attribute (LANG_C);
3546   else
3547     language_attribute (LANG_C89);
3548   low_pc_attribute (TEXT_BEGIN_LABEL);
3549   high_pc_attribute (TEXT_END_LABEL);
3550   if (debug_info_level >= DINFO_LEVEL_NORMAL)
3551     stmt_list_attribute (LINE_BEGIN_LABEL);
3552   last_filename = xstrdup (main_input_filename);
3553
3554   {
3555     char *wd = getpwd ();
3556     if (wd)
3557       comp_dir_attribute (wd);
3558   }
3559
3560   if (debug_info_level >= DINFO_LEVEL_NORMAL)
3561     {
3562       sf_names_attribute (SFNAMES_BEGIN_LABEL);
3563       src_info_attribute (SRCINFO_BEGIN_LABEL);
3564       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3565         mac_info_attribute (MACINFO_BEGIN_LABEL);
3566     }
3567 }
3568
3569 static void
3570 output_string_type_die (arg)
3571      register void *arg;
3572 {
3573   register tree type = arg;
3574
3575   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3576   sibling_attribute ();
3577   member_attribute (TYPE_CONTEXT (type));
3578
3579   /* Fudge the string length attribute for now.  */
3580
3581   string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3582 }
3583
3584 static void
3585 output_inheritance_die (arg)
3586      register void *arg;
3587 {
3588   register tree binfo = arg;
3589
3590   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3591   sibling_attribute ();
3592   type_attribute (BINFO_TYPE (binfo), 0, 0);
3593   data_member_location_attribute (binfo);
3594   if (TREE_VIA_VIRTUAL (binfo))
3595     {
3596       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3597       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3598     }
3599   if (TREE_VIA_PUBLIC (binfo))
3600     {
3601       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3602       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3603     }
3604   else if (TREE_VIA_PROTECTED (binfo))
3605     {
3606       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3607       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3608     }
3609 }  
3610
3611 static void
3612 output_structure_type_die (arg)
3613      register void *arg;
3614 {
3615   register tree type = arg;
3616
3617   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3618   sibling_attribute ();
3619   equate_type_number_to_die_number (type);
3620   name_attribute (type_tag (type));
3621   member_attribute (TYPE_CONTEXT (type));
3622
3623   /* If this type has been completed, then give it a byte_size attribute
3624      and prepare to give a list of members.  Otherwise, don't do either of
3625      these things.  In the latter case, we will not be generating a list
3626      of members (since we don't have any idea what they might be for an
3627      incomplete type).  */
3628
3629   if (TYPE_SIZE (type))
3630     {
3631       dienum_push ();
3632       byte_size_attribute (type);
3633     }
3634 }
3635
3636 /* Output a DIE to represent a declared function (either file-scope
3637    or block-local) which has "internal linkage" (according to ANSI-C).  */
3638
3639 static void
3640 output_local_subroutine_die (arg)
3641      register void *arg;
3642 {
3643   register tree decl = arg;
3644   register tree origin = decl_ultimate_origin (decl);
3645
3646   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3647   sibling_attribute ();
3648   dienum_push ();
3649   if (origin != NULL)
3650     abstract_origin_attribute (origin);
3651   else
3652     {
3653       register tree type = TREE_TYPE (decl);
3654
3655       name_and_src_coords_attributes (decl);
3656       inline_attribute (decl);
3657       prototyped_attribute (type);
3658       member_attribute (DECL_CONTEXT (decl));
3659       type_attribute (TREE_TYPE (type), 0, 0);
3660       pure_or_virtual_attribute (decl);
3661     }
3662   if (DECL_ABSTRACT (decl))
3663     equate_decl_number_to_die_number (decl);
3664   else
3665     {
3666       /* Avoid getting screwed up in cases where a function was declared
3667          static but where no definition was ever given for it.  */
3668
3669       if (TREE_ASM_WRITTEN (decl))
3670         {
3671           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3672           low_pc_attribute (function_start_label (decl));
3673           sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3674           high_pc_attribute (label);
3675           sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3676           body_begin_attribute (label);
3677           sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3678           body_end_attribute (label);
3679         }
3680     }
3681 }
3682
3683 static void
3684 output_subroutine_type_die (arg)
3685      register void *arg;
3686 {
3687   register tree type = arg;
3688   register tree return_type = TREE_TYPE (type);
3689
3690   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3691   sibling_attribute ();
3692   dienum_push ();
3693   equate_type_number_to_die_number (type);
3694   prototyped_attribute (type);
3695   member_attribute (TYPE_CONTEXT (type));
3696   type_attribute (return_type, 0, 0);
3697 }
3698
3699 static void
3700 output_typedef_die (arg)
3701      register void *arg;
3702 {
3703   register tree decl = arg;
3704   register tree origin = decl_ultimate_origin (decl);
3705
3706   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3707   sibling_attribute ();
3708   if (origin != NULL)
3709     abstract_origin_attribute (origin);
3710   else
3711     {
3712       name_and_src_coords_attributes (decl);
3713       member_attribute (DECL_CONTEXT (decl));
3714       type_attribute (TREE_TYPE (decl),
3715                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3716     }
3717   if (DECL_ABSTRACT (decl))
3718     equate_decl_number_to_die_number (decl);
3719 }
3720
3721 static void
3722 output_union_type_die (arg)
3723      register void *arg;
3724 {
3725   register tree type = arg;
3726
3727   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3728   sibling_attribute ();
3729   equate_type_number_to_die_number (type);
3730   name_attribute (type_tag (type));
3731   member_attribute (TYPE_CONTEXT (type));
3732
3733   /* If this type has been completed, then give it a byte_size attribute
3734      and prepare to give a list of members.  Otherwise, don't do either of
3735      these things.  In the latter case, we will not be generating a list
3736      of members (since we don't have any idea what they might be for an
3737      incomplete type).  */
3738
3739   if (TYPE_SIZE (type))
3740     {
3741       dienum_push ();
3742       byte_size_attribute (type);
3743     }
3744 }
3745
3746 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3747    at the end of an (ANSI prototyped) formal parameters list.  */
3748
3749 static void
3750 output_unspecified_parameters_die (arg)
3751      register void *arg;
3752 {
3753   register tree decl_or_type = arg;
3754
3755   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3756   sibling_attribute ();
3757
3758   /* This kludge is here only for the sake of being compatible with what
3759      the USL CI5 C compiler does.  The specification of Dwarf Version 1
3760      doesn't say that TAG_unspecified_parameters DIEs should contain any
3761      attributes other than the AT_sibling attribute, but they are certainly
3762      allowed to contain additional attributes, and the CI5 compiler
3763      generates AT_name, AT_fund_type, and AT_location attributes within
3764      TAG_unspecified_parameters DIEs which appear in the child lists for
3765      DIEs representing function definitions, so we do likewise here.  */
3766
3767   if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3768     {
3769       name_attribute ("...");
3770       fund_type_attribute (FT_pointer);
3771       /* location_attribute (?); */
3772     }
3773 }
3774
3775 static void
3776 output_padded_null_die (arg)
3777      register void *arg;
3778 {
3779   ASM_OUTPUT_ALIGN (asm_out_file, 2);   /* 2**2 == 4 */
3780 }
3781
3782 /*************************** end of DIEs *********************************/
3783
3784 /* Generate some type of DIE.  This routine generates the generic outer
3785    wrapper stuff which goes around all types of DIE's (regardless of their
3786    TAGs.  All forms of DIEs start with a DIE-specific label, followed by a
3787    DIE-length word, followed by the guts of the DIE itself.  After the guts
3788    of the DIE, there must always be a terminator label for the DIE.  */
3789
3790 static void
3791 output_die (die_specific_output_function, param)
3792      register void (*die_specific_output_function)();
3793      register void *param;
3794 {
3795   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3796   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3797
3798   current_dienum = NEXT_DIE_NUM;
3799   NEXT_DIE_NUM = next_unused_dienum;
3800
3801   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3802   sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3803
3804   /* Write a label which will act as the name for the start of this DIE.  */
3805
3806   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3807
3808   /* Write the DIE-length word.  */
3809
3810   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3811
3812   /* Fill in the guts of the DIE.  */
3813
3814   next_unused_dienum++;
3815   die_specific_output_function (param);
3816
3817   /* Write a label which will act as the name for the end of this DIE.  */
3818
3819   ASM_OUTPUT_LABEL (asm_out_file, end_label);
3820 }
3821
3822 static void
3823 end_sibling_chain ()
3824 {
3825   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3826
3827   current_dienum = NEXT_DIE_NUM;
3828   NEXT_DIE_NUM = next_unused_dienum;
3829
3830   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3831
3832   /* Write a label which will act as the name for the start of this DIE.  */
3833
3834   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3835
3836   /* Write the DIE-length word.  */
3837
3838   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3839
3840   dienum_pop ();
3841 }
3842 \f
3843 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3844    TAG_unspecified_parameters DIE) to represent the types of the formal
3845    parameters as specified in some function type specification (except
3846    for those which appear as part of a function *definition*).
3847
3848    Note that we must be careful here to output all of the parameter
3849    DIEs *before* we output any DIEs needed to represent the types of
3850    the formal parameters.  This keeps svr4 SDB happy because it
3851    (incorrectly) thinks that the first non-parameter DIE it sees ends
3852    the formal parameter list.  */
3853
3854 static void
3855 output_formal_types (function_or_method_type)
3856      register tree function_or_method_type;
3857 {
3858   register tree link;
3859   register tree formal_type = NULL;
3860   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3861
3862   /* In the case where we are generating a formal types list for a C++
3863      non-static member function type, skip over the first thing on the
3864      TYPE_ARG_TYPES list because it only represents the type of the
3865      hidden `this pointer'.  The debugger should be able to figure
3866      out (without being explicitly told) that this non-static member
3867      function type takes a `this pointer' and should be able to figure
3868      what the type of that hidden parameter is from the AT_member
3869      attribute of the parent TAG_subroutine_type DIE.  */
3870
3871   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3872     first_parm_type = TREE_CHAIN (first_parm_type);
3873
3874   /* Make our first pass over the list of formal parameter types and output
3875      a TAG_formal_parameter DIE for each one.  */
3876
3877   for (link = first_parm_type; link; link = TREE_CHAIN (link))
3878     {
3879       formal_type = TREE_VALUE (link);
3880       if (formal_type == void_type_node)
3881         break;
3882
3883       /* Output a (nameless) DIE to represent the formal parameter itself.  */
3884
3885       output_die (output_formal_parameter_die, formal_type);
3886     }
3887
3888   /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3889      DIE to the end of the parameter list.  */
3890
3891   if (formal_type != void_type_node)
3892     output_die (output_unspecified_parameters_die, function_or_method_type);
3893
3894   /* Make our second (and final) pass over the list of formal parameter types
3895      and output DIEs to represent those types (as necessary).  */
3896
3897   for (link = TYPE_ARG_TYPES (function_or_method_type);
3898        link;
3899        link = TREE_CHAIN (link))
3900     {
3901       formal_type = TREE_VALUE (link);
3902       if (formal_type == void_type_node)
3903         break;
3904
3905       output_type (formal_type, function_or_method_type);
3906     }
3907 }
3908 \f
3909 /* Remember a type in the pending_types_list.  */
3910
3911 static void
3912 pend_type (type)
3913      register tree type;
3914 {
3915   if (pending_types == pending_types_allocated)
3916     {
3917       pending_types_allocated += PENDING_TYPES_INCREMENT;
3918       pending_types_list
3919         = (tree *) xrealloc (pending_types_list,
3920                              sizeof (tree) * pending_types_allocated);
3921     }
3922   pending_types_list[pending_types++] = type;
3923
3924   /* Mark the pending type as having been output already (even though
3925      it hasn't been).  This prevents the type from being added to the
3926      pending_types_list more than once.  */
3927
3928   TREE_ASM_WRITTEN (type) = 1;
3929 }
3930
3931 /* Return non-zero if it is legitimate to output DIEs to represent a
3932    given type while we are generating the list of child DIEs for some
3933    DIE (e.g. a function or lexical block DIE) associated with a given scope.
3934
3935    See the comments within the function for a description of when it is
3936    considered legitimate to output DIEs for various kinds of types.
3937
3938    Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3939    or it may point to a BLOCK node (for types local to a block), or to a
3940    FUNCTION_DECL node (for types local to the heading of some function
3941    definition), or to a FUNCTION_TYPE node (for types local to the
3942    prototyped parameter list of a function type specification), or to a
3943    RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
3944    (in the case of C++ nested types).
3945
3946    The `scope' parameter should likewise be NULL or should point to a
3947    BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3948    node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
3949
3950    This function is used only for deciding when to "pend" and when to
3951    "un-pend" types to/from the pending_types_list.
3952
3953    Note that we sometimes make use of this "type pending" feature in a
3954    rather twisted way to temporarily delay the production of DIEs for the
3955    types of formal parameters.  (We do this just to make svr4 SDB happy.)
3956    It order to delay the production of DIEs representing types of formal
3957    parameters, callers of this function supply `fake_containing_scope' as
3958    the `scope' parameter to this function.  Given that fake_containing_scope
3959    is a tagged type which is *not* the containing scope for *any* other type,
3960    the desired effect is achieved, i.e. output of DIEs representing types
3961    is temporarily suspended, and any type DIEs which would have otherwise
3962    been output are instead placed onto the pending_types_list.  Later on,
3963    we force these (temporarily pended) types to be output simply by calling
3964    `output_pending_types_for_scope' with an actual argument equal to the
3965    true scope of the types we temporarily pended.  */
3966
3967 static inline int
3968 type_ok_for_scope (type, scope)
3969     register tree type;
3970     register tree scope;
3971 {
3972   /* Tagged types (i.e. struct, union, and enum types) must always be
3973      output only in the scopes where they actually belong (or else the
3974      scoping of their own tag names and the scoping of their member
3975      names will be incorrect).  Non-tagged-types on the other hand can
3976      generally be output anywhere, except that svr4 SDB really doesn't
3977      want to see them nested within struct or union types, so here we
3978      say it is always OK to immediately output any such a (non-tagged)
3979      type, so long as we are not within such a context.  Note that the
3980      only kinds of non-tagged types which we will be dealing with here
3981      (for C and C++ anyway) will be array types and function types.  */
3982
3983   return is_tagged_type (type)
3984          ? (TYPE_CONTEXT (type) == scope)
3985          : (scope == NULL_TREE || ! is_tagged_type (scope));
3986 }
3987
3988 /* Output any pending types (from the pending_types list) which we can output
3989    now (taking into account the scope that we are working on now).
3990
3991    For each type output, remove the given type from the pending_types_list
3992    *before* we try to output it.
3993
3994    Note that we have to process the list in beginning-to-end order,
3995    because the call made here to output_type may cause yet more types
3996    to be added to the end of the list, and we may have to output some
3997    of them too.  */
3998
3999 static void
4000 output_pending_types_for_scope (containing_scope)
4001      register tree containing_scope;
4002 {
4003   register unsigned i;
4004
4005   for (i = 0; i < pending_types; )
4006     {
4007       register tree type = pending_types_list[i];
4008
4009       if (type_ok_for_scope (type, containing_scope))
4010         {
4011           register tree *mover;
4012           register tree *limit;
4013
4014           pending_types--;
4015           limit = &pending_types_list[pending_types];
4016           for (mover = &pending_types_list[i]; mover < limit; mover++)
4017             *mover = *(mover+1);
4018
4019           /* Un-mark the type as having been output already (because it
4020              hasn't been, really).  Then call output_type to generate a
4021              Dwarf representation of it.  */
4022
4023           TREE_ASM_WRITTEN (type) = 0;
4024           output_type (type, containing_scope);
4025
4026           /* Don't increment the loop counter in this case because we
4027              have shifted all of the subsequent pending types down one
4028              element in the pending_types_list array.  */
4029         }
4030       else
4031         i++;
4032     }
4033 }
4034
4035 static void
4036 output_type (type, containing_scope)
4037      register tree type;
4038      register tree containing_scope;
4039 {
4040   if (type == 0 || type == error_mark_node)
4041     return;
4042
4043   /* We are going to output a DIE to represent the unqualified version of
4044      of this type (i.e. without any const or volatile qualifiers) so get
4045      the main variant (i.e. the unqualified version) of this type now.  */
4046
4047   type = type_main_variant (type);
4048
4049   if (TREE_ASM_WRITTEN (type))
4050     return;
4051
4052   /* Don't generate any DIEs for this type now unless it is OK to do so
4053      (based upon what `type_ok_for_scope' tells us).  */
4054
4055   if (! type_ok_for_scope (type, containing_scope))
4056     {
4057       pend_type (type);
4058       return;
4059     }
4060
4061   switch (TREE_CODE (type))
4062     {
4063       case ERROR_MARK:
4064         break;
4065
4066       case POINTER_TYPE:
4067       case REFERENCE_TYPE:
4068         /* For these types, all that is required is that we output a DIE
4069            (or a set of DIEs) to represent the "basis" type.  */
4070         output_type (TREE_TYPE (type), containing_scope);
4071         break;
4072
4073       case OFFSET_TYPE:
4074         /* This code is used for C++ pointer-to-data-member types.  */
4075         /* Output a description of the relevant class type.  */
4076         output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4077         /* Output a description of the type of the object pointed to.  */
4078         output_type (TREE_TYPE (type), containing_scope);
4079         /* Now output a DIE to represent this pointer-to-data-member type
4080            itself.  */
4081         output_die (output_ptr_to_mbr_type_die, type);
4082         break;
4083
4084       case SET_TYPE:
4085         output_type (TYPE_DOMAIN (type), containing_scope);
4086         output_die (output_set_type_die, type);
4087         break;
4088
4089       case FILE_TYPE:
4090         output_type (TREE_TYPE (type), containing_scope);
4091         abort ();       /* No way to represent these in Dwarf yet!  */
4092         break;
4093
4094       case FUNCTION_TYPE:
4095         /* Force out return type (in case it wasn't forced out already).  */
4096         output_type (TREE_TYPE (type), containing_scope);
4097         output_die (output_subroutine_type_die, type);
4098         output_formal_types (type);
4099         end_sibling_chain ();
4100         break;
4101
4102       case METHOD_TYPE:
4103         /* Force out return type (in case it wasn't forced out already).  */
4104         output_type (TREE_TYPE (type), containing_scope);
4105         output_die (output_subroutine_type_die, type);
4106         output_formal_types (type);
4107         end_sibling_chain ();
4108         break;
4109
4110       case ARRAY_TYPE:  
4111         if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4112           {
4113             output_type (TREE_TYPE (type), containing_scope);
4114             output_die (output_string_type_die, type);
4115           }
4116         else
4117           {
4118             register tree element_type;
4119
4120             element_type = TREE_TYPE (type);
4121             while (TREE_CODE (element_type) == ARRAY_TYPE)
4122               element_type = TREE_TYPE (element_type);
4123
4124             output_type (element_type, containing_scope);
4125             output_die (output_array_type_die, type);
4126           }
4127         break;
4128
4129       case ENUMERAL_TYPE:
4130       case RECORD_TYPE:
4131       case UNION_TYPE:
4132       case QUAL_UNION_TYPE:
4133
4134         /* For a non-file-scope tagged type, we can always go ahead and
4135            output a Dwarf description of this type right now, even if
4136            the type in question is still incomplete, because if this
4137            local type *was* ever completed anywhere within its scope,
4138            that complete definition would already have been attached to
4139            this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4140            node by the time we reach this point.  That's true because of the
4141            way the front-end does its processing of file-scope declarations (of
4142            functions and class types) within which other types might be
4143            nested.  The C and C++ front-ends always gobble up such "local
4144            scope" things en-mass before they try to output *any* debugging
4145            information for any of the stuff contained inside them and thus,
4146            we get the benefit here of what is (in effect) a pre-resolution
4147            of forward references to tagged types in local scopes.
4148
4149            Note however that for file-scope tagged types we cannot assume
4150            that such pre-resolution of forward references has taken place.
4151            A given file-scope tagged type may appear to be incomplete when
4152            we reach this point, but it may yet be given a full definition
4153            (at file-scope) later on during compilation.  In order to avoid
4154            generating a premature (and possibly incorrect) set of Dwarf
4155            DIEs for such (as yet incomplete) file-scope tagged types, we
4156            generate nothing at all for as-yet incomplete file-scope tagged
4157            types here unless we are making our special "finalization" pass
4158            for file-scope things at the very end of compilation.  At that
4159            time, we will certainly know as much about each file-scope tagged
4160            type as we are ever going to know, so at that point in time, we
4161            can safely generate correct Dwarf descriptions for these file-
4162            scope tagged types.
4163
4164            This loses for C++ nested types that are defined after their
4165            containing class, but I don't see a good way to fix it.  I doubt
4166            many people will be using DWARF 1 for C++ in any case.  */
4167
4168         if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
4169           return;       /* EARLY EXIT!  Avoid setting TREE_ASM_WRITTEN.  */
4170
4171         /* Prevent infinite recursion in cases where the type of some
4172            member of this type is expressed in terms of this type itself.  */
4173
4174         TREE_ASM_WRITTEN (type) = 1;
4175
4176         /* Output a DIE to represent the tagged type itself.  */
4177
4178         switch (TREE_CODE (type))
4179           {
4180           case ENUMERAL_TYPE:
4181             output_die (output_enumeration_type_die, type);
4182             return;  /* a special case -- nothing left to do so just return */
4183
4184           case RECORD_TYPE:
4185             output_die (output_structure_type_die, type);
4186             break;
4187
4188           case UNION_TYPE:
4189           case QUAL_UNION_TYPE:
4190             output_die (output_union_type_die, type);
4191             break;
4192
4193           default:
4194             abort ();   /* Should never happen.  */
4195           }
4196
4197         /* If this is not an incomplete type, output descriptions of
4198            each of its members.
4199
4200            Note that as we output the DIEs necessary to represent the
4201            members of this record or union type, we will also be trying
4202            to output DIEs to represent the *types* of those members.
4203            However the `output_type' function (above) will specifically
4204            avoid generating type DIEs for member types *within* the list
4205            of member DIEs for this (containing) type execpt for those
4206            types (of members) which are explicitly marked as also being
4207            members of this (containing) type themselves.  The g++ front-
4208            end can force any given type to be treated as a member of some
4209            other (containing) type by setting the TYPE_CONTEXT of the
4210            given (member) type to point to the TREE node representing the
4211            appropriate (containing) type.
4212         */
4213
4214         if (TYPE_SIZE (type))
4215           {
4216             /* First output info about the base classes.  */
4217             if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4218               {
4219                 register tree bases = TYPE_BINFO_BASETYPES (type);
4220                 register int n_bases = TREE_VEC_LENGTH (bases);
4221                 register int i;
4222
4223                 for (i = 0; i < n_bases; i++)
4224                   output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4225               }
4226
4227             {
4228               register tree normal_member;
4229
4230               /* Now output info about the data members and type members.  */
4231
4232               for (normal_member = TYPE_FIELDS (type);
4233                    normal_member;
4234                    normal_member = TREE_CHAIN (normal_member))
4235                 output_decl (normal_member, type);
4236             }
4237
4238             {
4239               register tree func_member;
4240
4241               /* Now output info about the function members (if any).  */
4242
4243               for (func_member = TYPE_METHODS (type);
4244                    func_member;
4245                    func_member = TREE_CHAIN (func_member))
4246                 output_decl (func_member, type);
4247             }
4248
4249             /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4250                scopes (at least in C++) so we must now output any nested
4251                pending types which are local just to this type.  */
4252
4253             output_pending_types_for_scope (type);
4254
4255             end_sibling_chain ();       /* Terminate member chain.  */
4256           }
4257
4258         break;
4259
4260       case VOID_TYPE:
4261       case INTEGER_TYPE:
4262       case REAL_TYPE:
4263       case COMPLEX_TYPE:
4264       case BOOLEAN_TYPE:
4265       case CHAR_TYPE:
4266         break;          /* No DIEs needed for fundamental types.  */
4267
4268       case LANG_TYPE:   /* No Dwarf representation currently defined.  */
4269         break;
4270
4271       default:
4272         abort ();
4273     }
4274
4275   TREE_ASM_WRITTEN (type) = 1;
4276 }
4277
4278 static void
4279 output_tagged_type_instantiation (type)
4280      register tree type;
4281 {
4282   if (type == 0 || type == error_mark_node)
4283     return;
4284
4285   /* We are going to output a DIE to represent the unqualified version of
4286      of this type (i.e. without any const or volatile qualifiers) so make
4287      sure that we have the main variant (i.e. the unqualified version) of
4288      this type now.  */
4289
4290   assert (type == type_main_variant (type));
4291
4292   assert (TREE_ASM_WRITTEN (type));
4293
4294   switch (TREE_CODE (type))
4295     {
4296       case ERROR_MARK:
4297         break;
4298
4299       case ENUMERAL_TYPE:
4300         output_die (output_inlined_enumeration_type_die, type);
4301         break;
4302
4303       case RECORD_TYPE:
4304         output_die (output_inlined_structure_type_die, type);
4305         break;
4306
4307       case UNION_TYPE:
4308       case QUAL_UNION_TYPE:
4309         output_die (output_inlined_union_type_die, type);
4310         break;
4311
4312       default:
4313         abort ();       /* Should never happen.  */
4314     }
4315 }
4316 \f
4317 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4318    the things which are local to the given block.  */
4319
4320 static void
4321 output_block (stmt, depth)
4322     register tree stmt;
4323     int depth;
4324 {
4325   register int must_output_die = 0;
4326   register tree origin;
4327   register enum tree_code origin_code;
4328
4329   /* Ignore blocks never really used to make RTL.  */
4330
4331   if (! stmt || ! TREE_USED (stmt))
4332     return;
4333
4334   /* Determine the "ultimate origin" of this block.  This block may be an
4335      inlined instance of an inlined instance of inline function, so we
4336      have to trace all of the way back through the origin chain to find
4337      out what sort of node actually served as the original seed for the
4338      creation of the current block.  */
4339
4340   origin = block_ultimate_origin (stmt);
4341   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4342
4343   /* Determine if we need to output any Dwarf DIEs at all to represent this
4344      block.  */
4345
4346   if (origin_code == FUNCTION_DECL)
4347     /* The outer scopes for inlinings *must* always be represented.  We
4348        generate TAG_inlined_subroutine DIEs for them.  (See below.)  */
4349     must_output_die = 1;
4350   else
4351     {
4352       /* In the case where the current block represents an inlining of the
4353          "body block" of an inline function, we must *NOT* output any DIE
4354          for this block because we have already output a DIE to represent
4355          the whole inlined function scope and the "body block" of any
4356          function doesn't really represent a different scope according to
4357          ANSI C rules.  So we check here to make sure that this block does
4358          not represent a "body block inlining" before trying to set the
4359          `must_output_die' flag.  */
4360
4361       if (! is_body_block (origin ? origin : stmt))
4362         {
4363           /* Determine if this block directly contains any "significant"
4364              local declarations which we will need to output DIEs for.  */
4365
4366           if (debug_info_level > DINFO_LEVEL_TERSE)
4367             /* We are not in terse mode so *any* local declaration counts
4368                as being a "significant" one.  */
4369             must_output_die = (BLOCK_VARS (stmt) != NULL);
4370           else
4371             {
4372               register tree decl;
4373
4374               /* We are in terse mode, so only local (nested) function
4375                  definitions count as "significant" local declarations.  */
4376
4377               for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4378                 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4379                   {
4380                     must_output_die = 1;
4381                     break;
4382                   }
4383             }
4384         }
4385     }
4386
4387   /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4388      DIE for any block which contains no significant local declarations
4389      at all.  Rather, in such cases we just call `output_decls_for_scope'
4390      so that any needed Dwarf info for any sub-blocks will get properly
4391      generated.  Note that in terse mode, our definition of what constitutes
4392      a "significant" local declaration gets restricted to include only
4393      inlined function instances and local (nested) function definitions.  */
4394
4395   if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4396     /* We don't care about an abstract inlined subroutine.  */;
4397   else if (must_output_die)
4398     {
4399       output_die ((origin_code == FUNCTION_DECL)
4400                     ? output_inlined_subroutine_die
4401                     : output_lexical_block_die,
4402                   stmt);
4403       output_decls_for_scope (stmt, depth);
4404       end_sibling_chain ();
4405     }
4406   else
4407     output_decls_for_scope (stmt, depth);
4408 }
4409
4410 /* Output all of the decls declared within a given scope (also called
4411    a `binding contour') and (recursively) all of it's sub-blocks.  */
4412
4413 static void
4414 output_decls_for_scope (stmt, depth)
4415      register tree stmt;
4416      int depth;
4417 {
4418   /* Ignore blocks never really used to make RTL.  */
4419
4420   if (! stmt || ! TREE_USED (stmt))
4421     return;
4422
4423   if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4424     next_block_number++;
4425
4426   /* Output the DIEs to represent all of the data objects, functions,
4427      typedefs, and tagged types declared directly within this block
4428      but not within any nested sub-blocks.  */
4429
4430   {
4431     register tree decl;
4432
4433     for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4434       output_decl (decl, stmt);
4435   }
4436
4437   output_pending_types_for_scope (stmt);
4438
4439   /* Output the DIEs to represent all sub-blocks (and the items declared
4440      therein) of this block.     */
4441
4442   {
4443     register tree subblocks;
4444
4445     for (subblocks = BLOCK_SUBBLOCKS (stmt);
4446          subblocks;
4447          subblocks = BLOCK_CHAIN (subblocks))
4448       output_block (subblocks, depth + 1);
4449   }
4450 }
4451
4452 /* Output Dwarf .debug information for a decl described by DECL.  */
4453
4454 static void
4455 output_decl (decl, containing_scope)
4456      register tree decl;
4457      register tree containing_scope;
4458 {
4459   /* Make a note of the decl node we are going to be working on.  We may
4460      need to give the user the source coordinates of where it appeared in
4461      case we notice (later on) that something about it looks screwy.  */
4462
4463   dwarf_last_decl = decl;
4464
4465   if (TREE_CODE (decl) == ERROR_MARK)
4466     return;
4467
4468   /* If a structure is declared within an initialization, e.g. as the
4469      operand of a sizeof, then it will not have a name.  We don't want
4470      to output a DIE for it, as the tree nodes are in the temporary obstack */
4471
4472   if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4473        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4474       && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4475           || (TYPE_FIELDS (TREE_TYPE (decl)) 
4476               && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4477     return;
4478   
4479   /* If this ..._DECL node is marked to be ignored, then ignore it.
4480      But don't ignore a function definition, since that would screw
4481      up our count of blocks, and that it turn will completely screw up the
4482      the labels we will reference in subsequent AT_low_pc and AT_high_pc
4483      attributes (for subsequent blocks).  */
4484
4485   if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4486     return;
4487
4488   switch (TREE_CODE (decl))
4489     {
4490     case CONST_DECL:
4491       /* The individual enumerators of an enum type get output when we
4492          output the Dwarf representation of the relevant enum type itself.  */
4493       break;
4494
4495     case FUNCTION_DECL:
4496       /* If we are in terse mode, don't output any DIEs to represent
4497          mere function declarations.  Also, if we are conforming
4498          to the DWARF version 1 specification, don't output DIEs for
4499          mere function declarations.  */
4500
4501       if (DECL_INITIAL (decl) == NULL_TREE)
4502 #if (DWARF_VERSION > 1)
4503         if (debug_info_level <= DINFO_LEVEL_TERSE)
4504 #endif
4505           break;
4506
4507       /* Before we describe the FUNCTION_DECL itself, make sure that we
4508          have described its return type.  */
4509
4510       output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4511
4512       /* If the following DIE will represent a function definition for a
4513          function with "extern" linkage, output a special "pubnames" DIE
4514          label just ahead of the actual DIE.  A reference to this label
4515          was already generated in the .debug_pubnames section sub-entry
4516          for this function definition.  */
4517
4518       if (TREE_PUBLIC (decl))
4519         {
4520           char label[MAX_ARTIFICIAL_LABEL_BYTES];
4521
4522           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4523           ASM_OUTPUT_LABEL (asm_out_file, label);
4524         }
4525
4526       /* Now output a DIE to represent the function itself.  */
4527
4528       output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4529                                 ? output_global_subroutine_die
4530                                 : output_local_subroutine_die,
4531                   decl);
4532
4533       /* Now output descriptions of the arguments for this function.
4534          This gets (unnecessarily?) complex because of the fact that
4535          the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4536          cases where there was a trailing `...' at the end of the formal
4537          parameter list.  In order to find out if there was a trailing
4538          ellipsis or not, we must instead look at the type associated
4539          with the FUNCTION_DECL.  This will be a node of type FUNCTION_TYPE.
4540          If the chain of type nodes hanging off of this FUNCTION_TYPE node
4541          ends with a void_type_node then there should *not* be an ellipsis
4542          at the end.  */
4543
4544       /* In the case where we are describing a mere function declaration, all
4545          we need to do here (and all we *can* do here) is to describe
4546          the *types* of its formal parameters.  */
4547
4548       if (DECL_INITIAL (decl) == NULL_TREE)
4549         output_formal_types (TREE_TYPE (decl));
4550       else
4551         {
4552           /* Generate DIEs to represent all known formal parameters */
4553
4554           register tree arg_decls = DECL_ARGUMENTS (decl);
4555           register tree parm;
4556
4557           /* WARNING!  Kludge zone ahead!  Here we have a special
4558              hack for svr4 SDB compatibility.  Instead of passing the
4559              current FUNCTION_DECL node as the second parameter (i.e.
4560              the `containing_scope' parameter) to `output_decl' (as
4561              we ought to) we instead pass a pointer to our own private
4562              fake_containing_scope node.  That node is a RECORD_TYPE
4563              node which NO OTHER TYPE may ever actually be a member of.
4564
4565              This pointer will ultimately get passed into `output_type'
4566              as its `containing_scope' parameter.  `Output_type' will
4567              then perform its part in the hack... i.e. it will pend
4568              the type of the formal parameter onto the pending_types
4569              list.  Later on, when we are done generating the whole
4570              sequence of formal parameter DIEs for this function
4571              definition, we will un-pend all previously pended types
4572              of formal parameters for this function definition.
4573
4574              This whole kludge prevents any type DIEs from being
4575              mixed in with the formal parameter DIEs.  That's good
4576              because svr4 SDB believes that the list of formal
4577              parameter DIEs for a function ends wherever the first
4578              non-formal-parameter DIE appears.  Thus, we have to
4579              keep the formal parameter DIEs segregated.  They must
4580              all appear (consecutively) at the start of the list of
4581              children for the DIE representing the function definition.
4582              Then (and only then) may we output any additional DIEs
4583              needed to represent the types of these formal parameters.
4584           */
4585
4586           /*
4587              When generating DIEs, generate the unspecified_parameters
4588              DIE instead if we come across the arg "__builtin_va_alist"
4589           */
4590
4591           for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4592             if (TREE_CODE (parm) == PARM_DECL)
4593               {
4594                 if (DECL_NAME(parm) &&
4595                     !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4596                             "__builtin_va_alist") )
4597                   output_die (output_unspecified_parameters_die, decl);
4598                 else
4599                   output_decl (parm, fake_containing_scope);
4600               }
4601
4602           /*
4603              Now that we have finished generating all of the DIEs to
4604              represent the formal parameters themselves, force out
4605              any DIEs needed to represent their types.  We do this
4606              simply by un-pending all previously pended types which
4607              can legitimately go into the chain of children DIEs for
4608              the current FUNCTION_DECL.
4609           */
4610
4611           output_pending_types_for_scope (decl);
4612
4613           /*
4614             Decide whether we need a unspecified_parameters DIE at the end.
4615             There are 2 more cases to do this for:
4616             1) the ansi ... declaration - this is detectable when the end
4617                 of the arg list is not a void_type_node
4618             2) an unprototyped function declaration (not a definition).  This
4619                 just means that we have no info about the parameters at all.
4620           */
4621
4622           {
4623             register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4624
4625             if (fn_arg_types)
4626               {
4627               /* this is the prototyped case, check for ...  */
4628               if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4629                 output_die (output_unspecified_parameters_die, decl);
4630               }
4631             else
4632               {
4633               /* this is unprototyped, check for undefined (just declaration) */
4634               if (!DECL_INITIAL (decl))
4635                 output_die (output_unspecified_parameters_die, decl);
4636               }
4637           }
4638         }
4639
4640       /* Output Dwarf info for all of the stuff within the body of the
4641          function (if it has one - it may be just a declaration).  */
4642
4643       {
4644         register tree outer_scope = DECL_INITIAL (decl);
4645
4646         if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4647           {
4648             /* Note that here, `outer_scope' is a pointer to the outermost
4649                BLOCK node created to represent a function.
4650                This outermost BLOCK actually represents the outermost
4651                binding contour for the function, i.e. the contour in which
4652                the function's formal parameters and labels get declared.
4653
4654                Curiously, it appears that the front end doesn't actually
4655                put the PARM_DECL nodes for the current function onto the
4656                BLOCK_VARS list for this outer scope.  (They are strung
4657                off of the DECL_ARGUMENTS list for the function instead.)
4658                The BLOCK_VARS list for the `outer_scope' does provide us
4659                with a list of the LABEL_DECL nodes for the function however,
4660                and we output DWARF info for those here.
4661
4662                Just within the `outer_scope' there will be a BLOCK node
4663                representing the function's outermost pair of curly braces,
4664                and any blocks used for the base and member initializers of
4665                a C++ constructor function.  */
4666
4667             output_decls_for_scope (outer_scope, 0);
4668
4669             /* Finally, force out any pending types which are local to the
4670                outermost block of this function definition.  These will
4671                all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4672                node itself.  */
4673
4674             output_pending_types_for_scope (decl);
4675           }
4676       }
4677
4678       /* Generate a terminator for the list of stuff `owned' by this
4679          function.  */
4680
4681       end_sibling_chain ();
4682
4683       break;
4684
4685     case TYPE_DECL:
4686       /* If we are in terse mode, don't generate any DIEs to represent
4687          any actual typedefs.  Note that even when we are in terse mode,
4688          we must still output DIEs to represent those tagged types which
4689          are used (directly or indirectly) in the specification of either
4690          a return type or a formal parameter type of some function.  */
4691
4692       if (debug_info_level <= DINFO_LEVEL_TERSE)
4693         if (DECL_NAME (decl) != NULL
4694             || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4695           return;
4696
4697       /* In the special case of a null-named TYPE_DECL node (representing
4698          the declaration of some type tag), if the given TYPE_DECL is
4699          marked as having been instantiated from some other (original)
4700          TYPE_DECL node (e.g. one which was generated within the original
4701          definition of an inline function) we have to generate a special
4702          (abbreviated) TAG_structure_type, TAG_union_type, or
4703          TAG_enumeration-type DIE here.  */
4704
4705       if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
4706         {
4707           output_tagged_type_instantiation (TREE_TYPE (decl));
4708           return;
4709         }
4710
4711       output_type (TREE_TYPE (decl), containing_scope);
4712
4713       /* Note that unlike the gcc front end (which generates a NULL named
4714          TYPE_DECL node for each complete tagged type, each array type,
4715          and each function type node created) the g++ front end generates
4716          a *named* TYPE_DECL node for each tagged type node created.
4717          These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4718          generate a DW_TAG_typedef DIE for them.  */
4719       if (DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
4720         /* Output a DIE to represent the typedef itself.  */
4721         output_die (output_typedef_die, decl);
4722       break;
4723
4724     case LABEL_DECL:
4725       if (debug_info_level >= DINFO_LEVEL_NORMAL)
4726         output_die (output_label_die, decl);
4727       break;
4728
4729     case VAR_DECL:
4730       /* If we are conforming to the DWARF version 1 specification, don't
4731          generated any DIEs to represent mere external object declarations.  */
4732
4733 #if (DWARF_VERSION <= 1)
4734       if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4735         break;
4736 #endif
4737
4738       /* If we are in terse mode, don't generate any DIEs to represent
4739          any variable declarations or definitions.  */
4740
4741       if (debug_info_level <= DINFO_LEVEL_TERSE)
4742         break;
4743
4744       /* Output any DIEs that are needed to specify the type of this data
4745          object.  */
4746
4747       output_type (TREE_TYPE (decl), containing_scope);
4748
4749       /* If the following DIE will represent a data object definition for a
4750          data object with "extern" linkage, output a special "pubnames" DIE
4751          label just ahead of the actual DIE.  A reference to this label
4752          was already generated in the .debug_pubnames section sub-entry
4753          for this data object definition.  */
4754
4755       if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4756         {
4757           char label[MAX_ARTIFICIAL_LABEL_BYTES];
4758
4759           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4760           ASM_OUTPUT_LABEL (asm_out_file, label);
4761         }
4762
4763       /* Now output the DIE to represent the data object itself.  This gets
4764          complicated because of the possibility that the VAR_DECL really
4765          represents an inlined instance of a formal parameter for an inline
4766          function.  */
4767
4768       {
4769         register void (*func) ();
4770         register tree origin = decl_ultimate_origin (decl);
4771
4772         if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4773           func = output_formal_parameter_die;
4774         else
4775           {
4776             if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
4777               func = output_global_variable_die;
4778             else
4779               func = output_local_variable_die;
4780           }
4781         output_die (func, decl);
4782       }
4783       break;
4784
4785     case FIELD_DECL:
4786       /* Ignore the nameless fields that are used to skip bits.  */
4787       if (DECL_NAME (decl) != 0)
4788         {
4789           output_type (member_declared_type (decl), containing_scope);
4790           output_die (output_member_die, decl);
4791         }
4792       break;
4793
4794     case PARM_DECL:
4795      /* Force out the type of this formal, if it was not forced out yet.
4796         Note that here we can run afowl of a bug in "classic" svr4 SDB.
4797         It should be able to grok the presence of type DIEs within a list
4798         of TAG_formal_parameter DIEs, but it doesn't.  */
4799
4800       output_type (TREE_TYPE (decl), containing_scope);
4801       output_die (output_formal_parameter_die, decl);
4802       break;
4803
4804     default:
4805       abort ();
4806     }
4807 }
4808 \f
4809 void
4810 dwarfout_file_scope_decl (decl, set_finalizing)
4811      register tree decl;
4812      register int set_finalizing;
4813 {
4814   if (TREE_CODE (decl) == ERROR_MARK)
4815     return;
4816
4817   /* If this ..._DECL node is marked to be ignored, then ignore it.  We
4818      gotta hope that the node in question doesn't represent a function
4819      definition.  If it does, then totally ignoring it is bound to screw
4820      up our count of blocks, and that it turn will completely screw up the
4821      the labels we will reference in subsequent AT_low_pc and AT_high_pc
4822      attributes (for subsequent blocks).  (It's too bad that BLOCK nodes
4823      don't carry their own sequence numbers with them!)  */
4824
4825   if (DECL_IGNORED_P (decl))
4826     {
4827       if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4828         abort ();
4829       return;
4830     }
4831
4832   switch (TREE_CODE (decl))
4833     {
4834     case FUNCTION_DECL:
4835
4836       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4837          a builtin function.  Explicit programmer-supplied declarations of
4838          these same functions should NOT be ignored however.  */
4839
4840       if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4841         return;
4842
4843       /* What we would really like to do here is to filter out all mere
4844          file-scope declarations of file-scope functions which are never
4845          referenced later within this translation unit (and keep all of
4846          ones that *are* referenced later on) but we aren't clairvoyant,
4847          so we have no idea which functions will be referenced in the
4848          future (i.e. later on within the current translation unit).
4849          So here we just ignore all file-scope function declarations
4850          which are not also definitions.  If and when the debugger needs
4851          to know something about these functions, it wil have to hunt
4852          around and find the DWARF information associated with the
4853          *definition* of the function.
4854
4855          Note that we can't just check `DECL_EXTERNAL' to find out which
4856          FUNCTION_DECL nodes represent definitions and which ones represent
4857          mere declarations.  We have to check `DECL_INITIAL' instead.  That's
4858          because the C front-end supports some weird semantics for "extern
4859          inline" function definitions.  These can get inlined within the
4860          current translation unit (an thus, we need to generate DWARF info
4861          for their abstract instances so that the DWARF info for the
4862          concrete inlined instances can have something to refer to) but
4863          the compiler never generates any out-of-lines instances of such
4864          things (despite the fact that they *are* definitions).  The
4865          important point is that the C front-end marks these "extern inline"
4866          functions as DECL_EXTERNAL, but we need to generate DWARF for them
4867          anyway.
4868
4869          Note that the C++ front-end also plays some similar games for inline
4870          function definitions appearing within include files which also
4871          contain `#pragma interface' pragmas.  */
4872
4873       if (DECL_INITIAL (decl) == NULL_TREE)
4874         return;
4875
4876       if (TREE_PUBLIC (decl)
4877           && ! DECL_EXTERNAL (decl)
4878           && ! DECL_ABSTRACT (decl))
4879         {
4880           char label[MAX_ARTIFICIAL_LABEL_BYTES];
4881
4882           /* Output a .debug_pubnames entry for a public function
4883              defined in this compilation unit.  */
4884
4885           fputc ('\n', asm_out_file);
4886           ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4887           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4888           ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4889           ASM_OUTPUT_DWARF_STRING (asm_out_file,
4890                                    IDENTIFIER_POINTER (DECL_NAME (decl)));
4891           ASM_OUTPUT_POP_SECTION (asm_out_file);
4892         }
4893
4894       break;
4895
4896     case VAR_DECL:
4897
4898       /* Ignore this VAR_DECL if it refers to a file-scope extern data
4899          object declaration and if the declaration was never even
4900          referenced from within this entire compilation unit.  We
4901          suppress these DIEs in order to save space in the .debug section
4902          (by eliminating entries which are probably useless).  Note that
4903          we must not suppress block-local extern declarations (whether
4904          used or not) because that would screw-up the debugger's name
4905          lookup mechanism and cause it to miss things which really ought
4906          to be in scope at a given point.  */
4907
4908       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
4909         return;
4910
4911       if (TREE_PUBLIC (decl)
4912           && ! DECL_EXTERNAL (decl)
4913           && GET_CODE (DECL_RTL (decl)) == MEM
4914           && ! DECL_ABSTRACT (decl))
4915         {
4916           char label[MAX_ARTIFICIAL_LABEL_BYTES];
4917
4918           if (debug_info_level >= DINFO_LEVEL_NORMAL)
4919             {
4920               /* Output a .debug_pubnames entry for a public variable
4921                  defined in this compilation unit.  */
4922
4923               fputc ('\n', asm_out_file);
4924               ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4925               sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4926               ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4927               ASM_OUTPUT_DWARF_STRING (asm_out_file,
4928                                        IDENTIFIER_POINTER (DECL_NAME (decl)));
4929               ASM_OUTPUT_POP_SECTION (asm_out_file);
4930             }
4931
4932           if (DECL_INITIAL (decl) == NULL)
4933             {
4934               /* Output a .debug_aranges entry for a public variable
4935                  which is tentatively defined in this compilation unit.  */
4936
4937               fputc ('\n', asm_out_file);
4938               ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4939               ASM_OUTPUT_DWARF_ADDR (asm_out_file,
4940                               IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4941               ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 
4942                         (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
4943               ASM_OUTPUT_POP_SECTION (asm_out_file);
4944             }
4945         }
4946
4947       /* If we are in terse mode, don't generate any DIEs to represent
4948          any variable declarations or definitions.  */
4949
4950       if (debug_info_level <= DINFO_LEVEL_TERSE)
4951         return;
4952
4953       break;
4954
4955     case TYPE_DECL:
4956       /* Don't bother trying to generate any DIEs to represent any of the
4957          normal built-in types for the language we are compiling, except
4958          in cases where the types in question are *not* DWARF fundamental
4959          types.  We make an exception in the case of non-fundamental types
4960          for the sake of objective C (and perhaps C++) because the GNU
4961          front-ends for these languages may in fact create certain "built-in"
4962          types which are (for example) RECORD_TYPEs.  In such cases, we
4963          really need to output these (non-fundamental) types because other
4964          DIEs may contain references to them.  */
4965
4966       if (DECL_SOURCE_LINE (decl) == 0
4967           && type_is_fundamental (TREE_TYPE (decl)))
4968         return;
4969
4970       /* If we are in terse mode, don't generate any DIEs to represent
4971          any actual typedefs.  Note that even when we are in terse mode,
4972          we must still output DIEs to represent those tagged types which
4973          are used (directly or indirectly) in the specification of either
4974          a return type or a formal parameter type of some function.  */
4975
4976       if (debug_info_level <= DINFO_LEVEL_TERSE)
4977         if (DECL_NAME (decl) != NULL
4978             || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4979           return;
4980
4981       break;
4982
4983     default:
4984       return;
4985     }
4986
4987   fputc ('\n', asm_out_file);
4988   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4989   finalizing = set_finalizing;
4990   output_decl (decl, NULL_TREE);
4991
4992   /* NOTE:  The call above to `output_decl' may have caused one or more
4993      file-scope named types (i.e. tagged types) to be placed onto the
4994      pending_types_list.  We have to get those types off of that list
4995      at some point, and this is the perfect time to do it.  If we didn't
4996      take them off now, they might still be on the list when cc1 finally
4997      exits.  That might be OK if it weren't for the fact that when we put
4998      types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4999      for these types, and that causes them never to be output unless
5000      `output_pending_types_for_scope' takes them off of the list and un-sets
5001      their TREE_ASM_WRITTEN flags.  */
5002
5003   output_pending_types_for_scope (NULL_TREE);
5004
5005   /* The above call should have totally emptied the pending_types_list.  */
5006
5007   assert (pending_types == 0);
5008
5009   ASM_OUTPUT_POP_SECTION (asm_out_file);
5010
5011   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5012     current_funcdef_number++;
5013 }
5014 \f
5015 /* Output a marker (i.e. a label) for the beginning of the generated code
5016    for a lexical block.  */
5017
5018 void
5019 dwarfout_begin_block (blocknum)
5020      register unsigned blocknum;
5021 {
5022   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5023
5024   function_section (current_function_decl);
5025   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5026   ASM_OUTPUT_LABEL (asm_out_file, label);
5027 }
5028
5029 /* Output a marker (i.e. a label) for the end of the generated code
5030    for a lexical block.  */
5031
5032 void
5033 dwarfout_end_block (blocknum)
5034      register unsigned blocknum;
5035 {
5036   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5037
5038   function_section (current_function_decl);
5039   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5040   ASM_OUTPUT_LABEL (asm_out_file, label);
5041 }
5042
5043 /* Output a marker (i.e. a label) at a point in the assembly code which
5044    corresponds to a given source level label.  */
5045
5046 void
5047 dwarfout_label (insn)
5048      register rtx insn;
5049 {
5050   if (debug_info_level >= DINFO_LEVEL_NORMAL)
5051     {
5052       char label[MAX_ARTIFICIAL_LABEL_BYTES];
5053
5054       function_section (current_function_decl);
5055       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5056                                       (unsigned) INSN_UID (insn));
5057       ASM_OUTPUT_LABEL (asm_out_file, label);
5058     }
5059 }
5060
5061 /* Output a marker (i.e. a label) for the point in the generated code where
5062    the real body of the function begins (after parameters have been moved
5063    to their home locations).  */
5064
5065 void
5066 dwarfout_begin_function ()
5067 {
5068   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5069
5070   function_section (current_function_decl);
5071   sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5072   ASM_OUTPUT_LABEL (asm_out_file, label);
5073 }
5074
5075 /* Output a marker (i.e. a label) for the point in the generated code where
5076    the real body of the function ends (just before the epilogue code).  */
5077
5078 void
5079 dwarfout_end_function ()
5080 {
5081   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5082
5083   function_section (current_function_decl);
5084   sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5085   ASM_OUTPUT_LABEL (asm_out_file, label);
5086 }
5087
5088 /* Output a marker (i.e. a label) for the absolute end of the generated code
5089    for a function definition.  This gets called *after* the epilogue code
5090    has been generated.  */
5091
5092 void
5093 dwarfout_end_epilogue ()
5094 {
5095   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5096
5097   /* Output a label to mark the endpoint of the code generated for this
5098      function.  */
5099
5100   sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5101   ASM_OUTPUT_LABEL (asm_out_file, label);
5102 }
5103
5104 static void
5105 shuffle_filename_entry (new_zeroth)
5106      register filename_entry *new_zeroth;
5107 {
5108   filename_entry temp_entry;
5109   register filename_entry *limit_p;
5110   register filename_entry *move_p;
5111
5112   if (new_zeroth == &filename_table[0])
5113     return;
5114
5115   temp_entry = *new_zeroth;
5116
5117   /* Shift entries up in the table to make room at [0].  */
5118
5119   limit_p = &filename_table[0];
5120   for (move_p = new_zeroth; move_p > limit_p; move_p--)
5121     *move_p = *(move_p-1);
5122
5123   /* Install the found entry at [0].  */
5124
5125   filename_table[0] = temp_entry;
5126 }
5127
5128 /* Create a new (string) entry for the .debug_sfnames section.  */
5129
5130 static void
5131 generate_new_sfname_entry ()
5132 {
5133   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5134
5135   fputc ('\n', asm_out_file);
5136   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5137   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5138   ASM_OUTPUT_LABEL (asm_out_file, label);
5139   ASM_OUTPUT_DWARF_STRING (asm_out_file,
5140                            filename_table[0].name
5141                              ? filename_table[0].name
5142                              : "");
5143   ASM_OUTPUT_POP_SECTION (asm_out_file);
5144 }
5145
5146 /* Lookup a filename (in the list of filenames that we know about here in
5147    dwarfout.c) and return its "index".  The index of each (known) filename
5148    is just a unique number which is associated with only that one filename.
5149    We need such numbers for the sake of generating labels (in the
5150    .debug_sfnames section) and references to those unique labels (in the
5151    .debug_srcinfo and .debug_macinfo sections).
5152
5153    If the filename given as an argument is not found in our current list,
5154    add it to the list and assign it the next available unique index number.
5155
5156    Whatever we do (i.e. whether we find a pre-existing filename or add a new
5157    one), we shuffle the filename found (or added) up to the zeroth entry of
5158    our list of filenames (which is always searched linearly).  We do this so
5159    as to optimize the most common case for these filename lookups within
5160    dwarfout.c.  The most common case by far is the case where we call
5161    lookup_filename to lookup the very same filename that we did a lookup
5162    on the last time we called lookup_filename.  We make sure that this
5163    common case is fast because such cases will constitute 99.9% of the
5164    lookups we ever do (in practice).
5165
5166    If we add a new filename entry to our table, we go ahead and generate
5167    the corresponding entry in the .debug_sfnames section right away.
5168    Doing so allows us to avoid tickling an assembler bug (present in some
5169    m68k assemblers) which yields assembly-time errors in cases where the
5170    difference of two label addresses is taken and where the two labels
5171    are in a section *other* than the one where the difference is being
5172    calculated, and where at least one of the two symbol references is a
5173    forward reference.  (This bug could be tickled by our .debug_srcinfo
5174    entries if we don't output their corresponding .debug_sfnames entries
5175    before them.) */
5176
5177 static unsigned
5178 lookup_filename (file_name)
5179      char *file_name;
5180 {
5181   register filename_entry *search_p;
5182   register filename_entry *limit_p = &filename_table[ft_entries];
5183
5184   for (search_p = filename_table; search_p < limit_p; search_p++)
5185     if (!strcmp (file_name, search_p->name))
5186       {
5187         /* When we get here, we have found the filename that we were
5188            looking for in the filename_table.  Now we want to make sure
5189            that it gets moved to the zero'th entry in the table (if it
5190            is not already there) so that subsequent attempts to find the
5191            same filename will find it as quickly as possible.  */
5192
5193         shuffle_filename_entry (search_p);
5194         return filename_table[0].number;
5195       }
5196
5197   /* We come here whenever we have a new filename which is not registered
5198      in the current table.  Here we add it to the table.  */
5199
5200   /* Prepare to add a new table entry by making sure there is enough space
5201      in the table to do so.  If not, expand the current table.  */
5202
5203   if (ft_entries == ft_entries_allocated)
5204     {
5205       ft_entries_allocated += FT_ENTRIES_INCREMENT;
5206       filename_table
5207         = (filename_entry *)
5208           xrealloc (filename_table,
5209                     ft_entries_allocated * sizeof (filename_entry));
5210     }
5211
5212   /* Initially, add the new entry at the end of the filename table.  */
5213
5214   filename_table[ft_entries].number = ft_entries;
5215   filename_table[ft_entries].name = xstrdup (file_name);
5216
5217   /* Shuffle the new entry into filename_table[0].  */
5218
5219   shuffle_filename_entry (&filename_table[ft_entries]);
5220
5221   if (debug_info_level >= DINFO_LEVEL_NORMAL)
5222     generate_new_sfname_entry ();
5223
5224   ft_entries++;
5225   return filename_table[0].number;
5226 }
5227
5228 static void
5229 generate_srcinfo_entry (line_entry_num, files_entry_num)
5230      unsigned line_entry_num;
5231      unsigned files_entry_num;
5232 {
5233   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5234
5235   fputc ('\n', asm_out_file);
5236   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5237   sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5238   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5239   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5240   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5241   ASM_OUTPUT_POP_SECTION (asm_out_file);
5242 }
5243
5244 void
5245 dwarfout_line (filename, line)
5246      register char *filename;
5247      register unsigned line;
5248 {
5249   if (debug_info_level >= DINFO_LEVEL_NORMAL
5250       /* We can't emit line number info for functions in separate sections,
5251          because the assembler can't subtract labels in different sections.  */
5252       && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5253     {
5254       char label[MAX_ARTIFICIAL_LABEL_BYTES];
5255       static unsigned last_line_entry_num = 0;
5256       static unsigned prev_file_entry_num = (unsigned) -1;
5257       register unsigned this_file_entry_num = lookup_filename (filename);
5258
5259       function_section (current_function_decl);
5260       sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5261       ASM_OUTPUT_LABEL (asm_out_file, label);
5262
5263       fputc ('\n', asm_out_file);
5264       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5265
5266       if (this_file_entry_num != prev_file_entry_num)
5267         {
5268           char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5269
5270           sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5271           ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5272         }
5273
5274       {
5275         register char *tail = rindex (filename, '/');
5276
5277         if (tail != NULL)
5278           filename = tail;
5279       }
5280
5281       fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5282                UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5283                filename, line);
5284       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5285       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5286       ASM_OUTPUT_POP_SECTION (asm_out_file);
5287
5288       if (this_file_entry_num != prev_file_entry_num)
5289         generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5290       prev_file_entry_num = this_file_entry_num;
5291     }
5292 }
5293
5294 /* Generate an entry in the .debug_macinfo section.  */
5295
5296 static void
5297 generate_macinfo_entry (type_and_offset, string)
5298      register char *type_and_offset;
5299      register char *string;
5300 {
5301   fputc ('\n', asm_out_file);
5302   ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5303   fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5304   ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5305   ASM_OUTPUT_POP_SECTION (asm_out_file);
5306 }
5307
5308 void
5309 dwarfout_start_new_source_file (filename)
5310      register char *filename;
5311 {
5312   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5313   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5314
5315   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5316   sprintf (type_and_offset, "0x%08x+%s-%s",
5317            ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5318   generate_macinfo_entry (type_and_offset, "");
5319 }
5320
5321 void
5322 dwarfout_resume_previous_source_file (lineno)
5323      register unsigned lineno;
5324 {
5325   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5326
5327   sprintf (type_and_offset, "0x%08x+%u",
5328            ((unsigned) MACINFO_resume << 24), lineno);
5329   generate_macinfo_entry (type_and_offset, "");
5330 }
5331
5332 /* Called from check_newline in c-parse.y.  The `buffer' parameter
5333    contains the tail part of the directive line, i.e. the part which
5334    is past the initial whitespace, #, whitespace, directive-name,
5335    whitespace part.  */
5336
5337 void
5338 dwarfout_define (lineno, buffer)
5339      register unsigned lineno;
5340      register char *buffer;
5341 {
5342   static int initialized = 0;
5343   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5344
5345   if (!initialized)
5346     {
5347       dwarfout_start_new_source_file (primary_filename);
5348       initialized = 1;
5349     }
5350   sprintf (type_and_offset, "0x%08x+%u",
5351            ((unsigned) MACINFO_define << 24), lineno);
5352   generate_macinfo_entry (type_and_offset, buffer);
5353 }
5354
5355 /* Called from check_newline in c-parse.y.  The `buffer' parameter
5356    contains the tail part of the directive line, i.e. the part which
5357    is past the initial whitespace, #, whitespace, directive-name,
5358    whitespace part.  */
5359
5360 void
5361 dwarfout_undef (lineno, buffer)
5362      register unsigned lineno;
5363      register char *buffer;
5364 {
5365   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5366
5367   sprintf (type_and_offset, "0x%08x+%u",
5368            ((unsigned) MACINFO_undef << 24), lineno);
5369   generate_macinfo_entry (type_and_offset, buffer);
5370 }
5371
5372 /* Set up for Dwarf output at the start of compilation.  */
5373
5374 void
5375 dwarfout_init (asm_out_file, main_input_filename)
5376      register FILE *asm_out_file;
5377      register char *main_input_filename;
5378 {
5379   /* Remember the name of the primary input file.  */
5380
5381   primary_filename = main_input_filename;
5382
5383   /* Allocate the initial hunk of the pending_sibling_stack.  */
5384
5385   pending_sibling_stack
5386     = (unsigned *)
5387         xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5388   pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5389   pending_siblings = 1;
5390
5391   /* Allocate the initial hunk of the filename_table.  */
5392
5393   filename_table
5394     = (filename_entry *)
5395         xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5396   ft_entries_allocated = FT_ENTRIES_INCREMENT;
5397   ft_entries = 0;
5398
5399   /* Allocate the initial hunk of the pending_types_list.  */
5400
5401   pending_types_list
5402     = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5403   pending_types_allocated = PENDING_TYPES_INCREMENT;
5404   pending_types = 0;
5405
5406   /* Create an artificial RECORD_TYPE node which we can use in our hack
5407      to get the DIEs representing types of formal parameters to come out
5408      only *after* the DIEs for the formal parameters themselves.  */
5409
5410   fake_containing_scope = make_node (RECORD_TYPE);
5411
5412   /* Output a starting label for the .text section.  */
5413
5414   fputc ('\n', asm_out_file);
5415   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5416   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5417   ASM_OUTPUT_POP_SECTION (asm_out_file);
5418
5419   /* Output a starting label for the .data section.  */
5420
5421   fputc ('\n', asm_out_file);
5422   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5423   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5424   ASM_OUTPUT_POP_SECTION (asm_out_file);
5425
5426 #if 0 /* GNU C doesn't currently use .data1.  */
5427   /* Output a starting label for the .data1 section.  */
5428
5429   fputc ('\n', asm_out_file);
5430   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5431   ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5432   ASM_OUTPUT_POP_SECTION (asm_out_file);
5433 #endif
5434
5435   /* Output a starting label for the .rodata section.  */
5436
5437   fputc ('\n', asm_out_file);
5438   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5439   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5440   ASM_OUTPUT_POP_SECTION (asm_out_file);
5441
5442 #if 0 /* GNU C doesn't currently use .rodata1.  */
5443   /* Output a starting label for the .rodata1 section.  */
5444
5445   fputc ('\n', asm_out_file);
5446   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5447   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5448   ASM_OUTPUT_POP_SECTION (asm_out_file);
5449 #endif
5450
5451   /* Output a starting label for the .bss section.  */
5452
5453   fputc ('\n', asm_out_file);
5454   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5455   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5456   ASM_OUTPUT_POP_SECTION (asm_out_file);
5457
5458   if (debug_info_level >= DINFO_LEVEL_NORMAL)
5459     {
5460       /* Output a starting label and an initial (compilation directory)
5461          entry for the .debug_sfnames section.  The starting label will be
5462          referenced by the initial entry in the .debug_srcinfo section.  */
5463     
5464       fputc ('\n', asm_out_file);
5465       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5466       ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5467       {
5468         register char *pwd;
5469         register unsigned len;
5470         register char *dirname;
5471
5472         pwd = getpwd ();
5473         if (!pwd)
5474           pfatal_with_name ("getpwd");
5475         len = strlen (pwd);
5476         dirname = (char *) xmalloc (len + 2);
5477     
5478         strcpy (dirname, pwd);
5479         strcpy (dirname + len, "/");
5480         ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5481         free (dirname);
5482       }
5483       ASM_OUTPUT_POP_SECTION (asm_out_file);
5484     
5485       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5486         {
5487           /* Output a starting label for the .debug_macinfo section.  This
5488              label will be referenced by the AT_mac_info attribute in the
5489              TAG_compile_unit DIE.  */
5490         
5491           fputc ('\n', asm_out_file);
5492           ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5493           ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5494           ASM_OUTPUT_POP_SECTION (asm_out_file);
5495         }
5496
5497       /* Generate the initial entry for the .line section.  */
5498     
5499       fputc ('\n', asm_out_file);
5500       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5501       ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5502       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5503       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5504       ASM_OUTPUT_POP_SECTION (asm_out_file);
5505     
5506       /* Generate the initial entry for the .debug_srcinfo section.  */
5507     
5508       fputc ('\n', asm_out_file);
5509       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5510       ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5511       ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5512       ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5513       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5514       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5515 #ifdef DWARF_TIMESTAMPS
5516       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5517 #else
5518       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5519 #endif
5520       ASM_OUTPUT_POP_SECTION (asm_out_file);
5521     
5522       /* Generate the initial entry for the .debug_pubnames section.  */
5523     
5524       fputc ('\n', asm_out_file);
5525       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5526       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5527       ASM_OUTPUT_POP_SECTION (asm_out_file);
5528     
5529       /* Generate the initial entry for the .debug_aranges section.  */
5530     
5531       fputc ('\n', asm_out_file);
5532       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5533       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5534       ASM_OUTPUT_POP_SECTION (asm_out_file);
5535     }
5536
5537   /* Setup first DIE number == 1.  */
5538   NEXT_DIE_NUM = next_unused_dienum++;
5539
5540   /* Generate the initial DIE for the .debug section.  Note that the
5541      (string) value given in the AT_name attribute of the TAG_compile_unit
5542      DIE will (typically) be a relative pathname and that this pathname
5543      should be taken as being relative to the directory from which the
5544      compiler was invoked when the given (base) source file was compiled.  */
5545
5546   fputc ('\n', asm_out_file);
5547   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5548   ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5549   output_die (output_compile_unit_die, main_input_filename);
5550   ASM_OUTPUT_POP_SECTION (asm_out_file);
5551
5552   fputc ('\n', asm_out_file);
5553 }
5554
5555 /* Output stuff that dwarf requires at the end of every file.  */
5556
5557 void
5558 dwarfout_finish ()
5559 {
5560   char label[MAX_ARTIFICIAL_LABEL_BYTES];
5561
5562   fputc ('\n', asm_out_file);
5563   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5564
5565   /* Mark the end of the chain of siblings which represent all file-scope
5566      declarations in this compilation unit.  */
5567
5568   /* The (null) DIE which represents the terminator for the (sibling linked)
5569      list of file-scope items is *special*.  Normally, we would just call
5570      end_sibling_chain at this point in order to output a word with the
5571      value `4' and that word would act as the terminator for the list of
5572      DIEs describing file-scope items.  Unfortunately, if we were to simply
5573      do that, the label that would follow this DIE in the .debug section
5574      (i.e. `..D2') would *not* be properly aligned (as it must be on some
5575      machines) to a 4 byte boundary.
5576
5577      In order to force the label `..D2' to get aligned to a 4 byte boundary,
5578      the trick used is to insert extra (otherwise useless) padding bytes
5579      into the (null) DIE that we know must precede the ..D2 label in the
5580      .debug section.  The amount of padding required can be anywhere between
5581      0 and 3 bytes.  The length word at the start of this DIE (i.e. the one
5582      with the padding) would normally contain the value 4, but now it will
5583      also have to include the padding bytes, so it will instead have some
5584      value in the range 4..7.
5585
5586      Fortunately, the rules of Dwarf say that any DIE whose length word
5587      contains *any* value less than 8 should be treated as a null DIE, so
5588      this trick works out nicely.  Clever, eh?  Don't give me any credit
5589      (or blame).  I didn't think of this scheme.  I just conformed to it.
5590   */
5591
5592   output_die (output_padded_null_die, (void *) 0);
5593   dienum_pop ();
5594
5595   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5596   ASM_OUTPUT_LABEL (asm_out_file, label);       /* should be ..D2 */
5597   ASM_OUTPUT_POP_SECTION (asm_out_file);
5598
5599   /* Output a terminator label for the .text section.  */
5600
5601   fputc ('\n', asm_out_file);
5602   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5603   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5604   ASM_OUTPUT_POP_SECTION (asm_out_file);
5605
5606   /* Output a terminator label for the .data section.  */
5607
5608   fputc ('\n', asm_out_file);
5609   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5610   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5611   ASM_OUTPUT_POP_SECTION (asm_out_file);
5612
5613 #if 0 /* GNU C doesn't currently use .data1.  */
5614   /* Output a terminator label for the .data1 section.  */
5615
5616   fputc ('\n', asm_out_file);
5617   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5618   ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5619   ASM_OUTPUT_POP_SECTION (asm_out_file);
5620 #endif
5621
5622   /* Output a terminator label for the .rodata section.  */
5623
5624   fputc ('\n', asm_out_file);
5625   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5626   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5627   ASM_OUTPUT_POP_SECTION (asm_out_file);
5628
5629 #if 0 /* GNU C doesn't currently use .rodata1.  */
5630   /* Output a terminator label for the .rodata1 section.  */
5631
5632   fputc ('\n', asm_out_file);
5633   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5634   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5635   ASM_OUTPUT_POP_SECTION (asm_out_file);
5636 #endif
5637
5638   /* Output a terminator label for the .bss section.  */
5639
5640   fputc ('\n', asm_out_file);
5641   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5642   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5643   ASM_OUTPUT_POP_SECTION (asm_out_file);
5644
5645   if (debug_info_level >= DINFO_LEVEL_NORMAL)
5646     {
5647       /* Output a terminating entry for the .line section.  */
5648     
5649       fputc ('\n', asm_out_file);
5650       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5651       ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5652       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5653       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5654       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5655       ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5656       ASM_OUTPUT_POP_SECTION (asm_out_file);
5657     
5658       /* Output a terminating entry for the .debug_srcinfo section.  */
5659     
5660       fputc ('\n', asm_out_file);
5661       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5662       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5663                                LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5664       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5665       ASM_OUTPUT_POP_SECTION (asm_out_file);
5666
5667       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5668         {
5669           /* Output terminating entries for the .debug_macinfo section.  */
5670         
5671           dwarfout_resume_previous_source_file (0);
5672
5673           fputc ('\n', asm_out_file);
5674           ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5675           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5676           ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5677           ASM_OUTPUT_POP_SECTION (asm_out_file);
5678         }
5679     
5680       /* Generate the terminating entry for the .debug_pubnames section.  */
5681     
5682       fputc ('\n', asm_out_file);
5683       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5684       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5685       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5686       ASM_OUTPUT_POP_SECTION (asm_out_file);
5687     
5688       /* Generate the terminating entries for the .debug_aranges section.
5689
5690          Note that we want to do this only *after* we have output the end
5691          labels (for the various program sections) which we are going to
5692          refer to here.  This allows us to work around a bug in the m68k
5693          svr4 assembler.  That assembler gives bogus assembly-time errors
5694          if (within any given section) you try to take the difference of
5695          two relocatable symbols, both of which are located within some
5696          other section, and if one (or both?) of the symbols involved is
5697          being forward-referenced.  By generating the .debug_aranges
5698          entries at this late point in the assembly output, we skirt the
5699          issue simply by avoiding forward-references.
5700       */
5701     
5702       fputc ('\n', asm_out_file);
5703       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5704
5705       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5706       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5707
5708       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5709       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5710
5711 #if 0 /* GNU C doesn't currently use .data1.  */
5712       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5713       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5714                                              DATA1_BEGIN_LABEL);
5715 #endif
5716
5717       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5718       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5719                                              RODATA_BEGIN_LABEL);
5720
5721 #if 0 /* GNU C doesn't currently use .rodata1.  */
5722       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5723       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5724                                              RODATA1_BEGIN_LABEL);
5725 #endif
5726
5727       ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5728       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5729
5730       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5731       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5732
5733       ASM_OUTPUT_POP_SECTION (asm_out_file);
5734     }
5735 }
5736
5737 #endif /* DWARF_DEBUGGING_INFO */