OSDN Git Service

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