OSDN Git Service

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