OSDN Git Service

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