OSDN Git Service

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