OSDN Git Service

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