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