OSDN Git Service

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