OSDN Git Service

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