OSDN Git Service

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