OSDN Git Service

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