OSDN Git Service

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