OSDN Git Service

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