OSDN Git Service

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