OSDN Git Service

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