OSDN Git Service

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