OSDN Git Service

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