OSDN Git Service

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