OSDN Git Service

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