OSDN Git Service

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