OSDN Git Service

*** empty log message ***
[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 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 "insn-config.h"
32 #include "reload.h"
33 #include "output.h"
34
35 /* #define NDEBUG 1 */
36 #include <assert.h>
37
38 #if defined(DWARF_TIMESTAMPS)
39 #if defined(POSIX)
40 #include <time.h>
41 #else /* !defined(POSIX) */
42 #include <sys/types.h>
43 #if defined(__STDC__)
44 extern time_t time (time_t *);
45 #else /* !defined(__STDC__) */
46 extern time_t time ();
47 #endif /* !defined(__STDC__) */
48 #endif /* !defined(POSIX) */
49 #endif /* defined(DWARF_TIMESTAMPS) */
50
51 #if defined(USG) || defined(POSIX)
52 #include <string.h>
53 #else
54 #include <strings.h>
55 #define strrchr rindex
56 #endif
57
58 char *getpwd ();
59
60
61 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
62    regarding the GNU implementation of Dwarf.  */
63
64 /* NOTE: In the comments in this file, many references are made to
65    so called "Debugging Information Entries".  For the sake of brevity,
66    this term is abbreviated to `DIE' throughout the remainder of this
67    file.  */
68
69 /* Note that the implementation of C++ support herein is (as yet) unfinished.
70    If you want to try to complete it, more power to you.  */
71
72 #if defined(__GNUC__) && (NDEBUG == 1)
73 #define inline static inline
74 #else
75 #define inline static
76 #endif
77
78 /* How to start an assembler comment.  */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
81 #endif
82
83 /* Define a macro which, when given a pointer to some BLOCK node, returns
84    a pointer to the FUNCTION_DECL node from which the given BLOCK node
85    was instantiated (as an inline expansion).  This macro needs to be
86    defined properly in tree.h, however for the moment, we just fake it.  */
87
88 #define BLOCK_INLINE_FUNCTION(block) 0
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 #define BITFIELD_OFFSET_BITS(DECL) \
108   ((unsigned) TREE_INT_CST_LOW (DECL_FIELD_BITPOS (DECL)))
109 #define BITFIELD_OFFSET_UNITS(DECL) \
110   (BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_UNIT)
111 #define BITFIELD_OFFSET_WORDS_IN_UNITS(DECL) \
112   ((BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_WORD) * UNITS_PER_WORD)
113
114 extern int flag_traditional;
115 extern char *version_string;
116 extern char *language_string;
117
118 /* Maximum size (in bytes) of an artificially generated label.  */
119
120 #define MAX_ARTIFICIAL_LABEL_BYTES      30
121 \f
122 /* Make sure we know the sizes of the various types dwarf can describe.
123    These are only defaults.  If the sizes are different for your target,
124    you should override these values by defining the appropriate symbols
125    in your tm.h file.  */
126
127 #ifndef CHAR_TYPE_SIZE
128 #define CHAR_TYPE_SIZE BITS_PER_UNIT
129 #endif
130
131 #ifndef SHORT_TYPE_SIZE
132 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
133 #endif
134
135 #ifndef INT_TYPE_SIZE
136 #define INT_TYPE_SIZE BITS_PER_WORD
137 #endif
138
139 #ifndef LONG_TYPE_SIZE
140 #define LONG_TYPE_SIZE BITS_PER_WORD
141 #endif
142
143 #ifndef LONG_LONG_TYPE_SIZE
144 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
145 #endif
146
147 #ifndef WCHAR_TYPE_SIZE
148 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
149 #endif
150
151 #ifndef WCHAR_UNSIGNED
152 #define WCHAR_UNSIGNED 0
153 #endif
154
155 #ifndef FLOAT_TYPE_SIZE
156 #define FLOAT_TYPE_SIZE BITS_PER_WORD
157 #endif
158
159 #ifndef DOUBLE_TYPE_SIZE
160 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
161 #endif
162
163 #ifndef LONG_DOUBLE_TYPE_SIZE
164 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
165 #endif
166 \f
167 /* Structure to keep track of source filenames.  */
168
169 struct filename_entry {
170   unsigned      number;
171   char *        name;
172 };
173
174 typedef struct filename_entry filename_entry;
175
176 /* Pointer to an array of elements, each one having the structure above. */
177
178 static filename_entry *filename_table;
179
180 /* Total number of entries in the table (i.e. array) pointed to by
181    `filename_table'.  This is the *total* and includes both used and
182    unused slots.  */
183
184 static unsigned ft_entries_allocated;
185
186 /* Number of entries in the filename_table which are actually in use.  */
187
188 static unsigned ft_entries;
189
190 /* Size (in elements) of increments by which we may expand the filename
191    table.  Actually, a single hunk of space of this size should be enough
192    for most typical programs.    */
193
194 #define FT_ENTRIES_INCREMENT 64
195
196 /* Local pointer to the name of the main input file.  Initialized in
197    dwarfout_init.  */
198
199 static char *primary_filename;
200
201 /* Pointer to the most recent filename for which we produced some line info.  */
202
203 static char *last_filename;
204
205 /* For Dwarf output, we must assign lexical-blocks id numbers
206    in the order in which their beginnings are encountered.
207    We output Dwarf debugging info that refers to the beginnings
208    and ends of the ranges of code for each lexical block with
209    assembler labels ..Bn and ..Bn.e, where n is the block number.
210    The labels themselves are generated in final.c, which assigns
211    numbers to the blocks in the same way.  */
212
213 static unsigned next_block_number = 2;
214
215 /* Counter to generate unique names for DIEs. */
216
217 static unsigned next_unused_dienum = 1;
218
219 /* Number of the DIE which is currently being generated.  */
220
221 static unsigned current_dienum;
222
223 /* Number to use for the special "pubname" label on the next DIE which
224    represents a function or data object defined in this compilation
225    unit which has "extern" linkage.  */
226
227 static next_pubname_number = 0;
228
229 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
230
231 /* Pointer to a dynamically allocated list of pre-reserved and still
232    pending sibling DIE numbers.  Note that this list will grow as needed.  */
233
234 static unsigned *pending_sibling_stack;
235
236 /* Counter to keep track of the number of pre-reserved and still pending
237    sibling DIE numbers.  */
238
239 static unsigned pending_siblings;
240
241 /* The currently allocated size of the above list (expressed in number of
242    list elements).  */
243
244 static unsigned pending_siblings_allocated;
245
246 /* Size (in elements) of increments by which we may expand the pending
247    sibling stack.  Actually, a single hunk of space of this size should
248    be enough for most typical programs.  */
249
250 #define PENDING_SIBLINGS_INCREMENT 64
251
252 /* Non-zero if we are performing our file-scope finalization pass and if
253    we should force out Dwarf decsriptions of any and all file-scope
254    tagged types which are still incomplete types.  */
255
256 static int finalizing = 0;
257
258 /* A pointer to the base of a list of pending types which we haven't
259    generated DIEs for yet, but which we will have to come back to
260    later on.  */
261
262 static tree *pending_types_list;
263
264 /* Number of elements currently allocated for the pending_types_list.  */
265
266 static unsigned pending_types_allocated;
267
268 /* Number of elements of pending_types_list currently in use.  */
269
270 static unsigned pending_types;
271
272 /* Size (in elements) of increments by which we may expand the pending
273    types list.  Actually, a single hunk of space of this size should
274    be enough for most typical programs.  */
275
276 #define PENDING_TYPES_INCREMENT 64
277
278 /* Pointer to an artifical RECORD_TYPE which we create in dwarfout_init.
279    This is used in a hack to help us get the DIEs describing types of
280    formal parameters to come *after* all of the DIEs describing the formal
281    parameters themselves.  That's necessary in order to be compatible
282    with what the brain-dammaged svr4 SDB debugger requires.  */
283
284 static tree fake_containing_scope;
285
286 /* The number of the current function definition that we are generating
287    debugging information for.  These numbers range from 1 up to the maximum
288    number of function definitions contained within the current compilation
289    unit.  These numbers are used to create unique labels for various things
290    contained within various function definitions.  */
291
292 static unsigned current_funcdef_number = 1;
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 DEF_ASM_OP
322 #define DEF_ASM_OP              ".set"
323 #endif
324 #ifndef ASM_BYTE_OP
325 #define ASM_BYTE_OP             "\t.byte"
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 might be 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      "\t.section"
338 #endif
339 #ifndef POPSECTION_ASM_OP
340 #define POPSECTION_ASM_OP       "\t.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 #ifndef TEXT_BEGIN_LABEL
400 #define TEXT_BEGIN_LABEL        "._text_b"
401 #endif
402 #ifndef TEXT_END_LABEL
403 #define TEXT_END_LABEL          "._text_e"
404 #endif
405
406 #ifndef DATA_BEGIN_LABEL
407 #define DATA_BEGIN_LABEL        "._data_b"
408 #endif
409 #ifndef DATA_END_LABEL
410 #define DATA_END_LABEL          "._data_e"
411 #endif
412
413 #ifndef DATA1_BEGIN_LABEL
414 #define DATA1_BEGIN_LABEL       "._data1_b"
415 #endif
416 #ifndef DATA1_END_LABEL
417 #define DATA1_END_LABEL         "._data1_e"
418 #endif
419
420 #ifndef RODATA_BEGIN_LABEL
421 #define RODATA_BEGIN_LABEL      "._rodata_b"
422 #endif
423 #ifndef RODATA_END_LABEL
424 #define RODATA_END_LABEL        "._rodata_e"
425 #endif
426
427 #ifndef RODATA1_BEGIN_LABEL
428 #define RODATA1_BEGIN_LABEL     "._rodata1_b"
429 #endif
430 #ifndef RODATA1_END_LABEL
431 #define RODATA1_END_LABEL       "._rodata1_e"
432 #endif
433
434 #ifndef BSS_BEGIN_LABEL
435 #define BSS_BEGIN_LABEL         "._bss_b"
436 #endif
437 #ifndef BSS_END_LABEL
438 #define BSS_END_LABEL           "._bss_e"
439 #endif
440
441 #ifndef LINE_BEGIN_LABEL
442 #define LINE_BEGIN_LABEL        "._line_b"
443 #endif
444 #ifndef LINE_LAST_ENTRY_LABEL
445 #define LINE_LAST_ENTRY_LABEL   "._line_last"
446 #endif
447 #ifndef LINE_END_LABEL
448 #define LINE_END_LABEL          "._line_e"
449 #endif
450
451 #ifndef DEBUG_BEGIN_LABEL
452 #define DEBUG_BEGIN_LABEL       "._debug_b"
453 #endif
454 #ifndef SFNAMES_BEGIN_LABEL
455 #define SFNAMES_BEGIN_LABEL     "._sfnames_b"
456 #endif
457 #ifndef SRCINFO_BEGIN_LABEL
458 #define SRCINFO_BEGIN_LABEL     "._srcinfo_b"
459 #endif
460 #ifndef MACINFO_BEGIN_LABEL
461 #define MACINFO_BEGIN_LABEL     "._macinfo_b"
462 #endif
463
464 #ifndef DIE_BEGIN_LABEL_FMT
465 #define DIE_BEGIN_LABEL_FMT     "._D%u"
466 #endif
467 #ifndef DIE_END_LABEL_FMT
468 #define DIE_END_LABEL_FMT       "._D%u_e"
469 #endif
470 #ifndef PUB_DIE_LABEL_FMT
471 #define PUB_DIE_LABEL_FMT       "._P%u"
472 #endif
473 #ifndef INSN_LABEL_FMT
474 #define INSN_LABEL_FMT          "._I%u_%u"
475 #endif
476 #ifndef BLOCK_BEGIN_LABEL_FMT
477 #define BLOCK_BEGIN_LABEL_FMT   "._B%u"
478 #endif
479 #ifndef BLOCK_END_LABEL_FMT
480 #define BLOCK_END_LABEL_FMT     "._B%u_e"
481 #endif
482 #ifndef SS_BEGIN_LABEL_FMT
483 #define SS_BEGIN_LABEL_FMT      "._s%u"
484 #endif
485 #ifndef SS_END_LABEL_FMT
486 #define SS_END_LABEL_FMT        "._s%u_e"
487 #endif
488 #ifndef EE_BEGIN_LABEL_FMT
489 #define EE_BEGIN_LABEL_FMT      "._e%u"
490 #endif
491 #ifndef EE_END_LABEL_FMT
492 #define EE_END_LABEL_FMT        "._e%u_e"
493 #endif
494 #ifndef MT_BEGIN_LABEL_FMT
495 #define MT_BEGIN_LABEL_FMT      "._t%u"
496 #endif
497 #ifndef MT_END_LABEL_FMT
498 #define MT_END_LABEL_FMT        "._t%u_e"
499 #endif
500 #ifndef LOC_BEGIN_LABEL_FMT
501 #define LOC_BEGIN_LABEL_FMT     "._l%u"
502 #endif
503 #ifndef LOC_END_LABEL_FMT
504 #define LOC_END_LABEL_FMT       "._l%u_e"
505 #endif
506 #ifndef BOUND_BEGIN_LABEL_FMT
507 #define BOUND_BEGIN_LABEL_FMT   "._b%u_%u_%c"
508 #endif
509 #ifndef BOUND_END_LABEL_FMT
510 #define BOUND_END_LABEL_FMT     "._b%u_%u_%c_e"
511 #endif
512 #ifndef DERIV_BEGIN_LABEL_FMT
513 #define DERIV_BEGIN_LABEL_FMT   "._d%u"
514 #endif
515 #ifndef DERIV_END_LABEL_FMT
516 #define DERIV_END_LABEL_FMT     "._d%u_e"
517 #endif
518 #ifndef SL_BEGIN_LABEL_FMT
519 #define SL_BEGIN_LABEL_FMT      "._sl%u"
520 #endif
521 #ifndef SL_END_LABEL_FMT
522 #define SL_END_LABEL_FMT        "._sl%u_e"
523 #endif
524 #ifndef FUNC_END_LABEL_FMT
525 #define FUNC_END_LABEL_FMT      "._f%u_e"
526 #endif
527 #ifndef TYPE_NAME_FMT
528 #define TYPE_NAME_FMT           "._T%u"
529 #endif
530 #ifndef LINE_CODE_LABEL_FMT
531 #define LINE_CODE_LABEL_FMT     "._LC%u"
532 #endif
533 #ifndef SFNAMES_ENTRY_LABEL_FMT
534 #define SFNAMES_ENTRY_LABEL_FMT "._F%u"
535 #endif
536 #ifndef LINE_ENTRY_LABEL_FMT
537 #define LINE_ENTRY_LABEL_FMT    "._LE%u"
538 #endif
539 \f
540 /* Definitions of defaults for various types of primitive assembly language
541    output operations.
542
543    If necessary, these may be overridden from within your tm.h file,
544    but typically, you shouldn't need to override these.  Two known
545    exceptions are the ASM_OUTPUT_PUSH_SECTION and ASM_OUTPUT_POP_SECTION
546    definitions, which need to be somewhat special for a sparc running svr4.
547 */
548
549 #ifndef ASM_OUTPUT_PUSH_SECTION
550 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
551   fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
552 #endif
553
554 #ifndef ASM_OUTPUT_POP_SECTION
555 #define ASM_OUTPUT_POP_SECTION(FILE) \
556   fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
557 #endif
558
559 #ifndef ASM_OUTPUT_SOURCE_FILENAME
560 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
561   fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
562 #endif
563
564 #ifndef ASM_OUTPUT_DEF
565 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                              \
566  do {   fprintf ((FILE), "\t%s\t", DEF_ASM_OP);                         \
567         assemble_name (FILE, LABEL1);                                   \
568         fprintf (FILE, ",");                                            \
569         assemble_name (FILE, LABEL2);                                   \
570         fprintf (FILE, "\n");                                           \
571   } while (0)
572 #endif
573
574 #ifndef ASM_OUTPUT_DWARF_DELTA2
575 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
576  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);             \
577         assemble_name (FILE, LABEL1);                                   \
578         fprintf (FILE, "-");                                            \
579         assemble_name (FILE, LABEL2);                                   \
580         fprintf (FILE, "\n");                                           \
581   } while (0)
582 #endif
583
584 #ifndef ASM_OUTPUT_DWARF_DELTA4
585 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
586  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
587         assemble_name (FILE, LABEL1);                                   \
588         fprintf (FILE, "-");                                            \
589         assemble_name (FILE, LABEL2);                                   \
590         fprintf (FILE, "\n");                                           \
591   } while (0)
592 #endif
593
594 #ifndef ASM_OUTPUT_DWARF_TAG
595 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG)                                  \
596   fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP,       \
597         (unsigned) TAG, ASM_COMMENT_START, tag_name (TAG))
598 #endif
599
600 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
601 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTRIBUTE)                      \
602   fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP,       \
603         (unsigned) ATTRIBUTE, ASM_COMMENT_START, attribute_name (ATTRIBUTE))
604 #endif
605
606 #ifndef ASM_OUTPUT_DWARF_STACK_OP
607 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP)                              \
608   fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP,                    \
609         (unsigned) OP, ASM_COMMENT_START, stack_op_name (OP))
610 #endif
611
612 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
613 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT)                             \
614   fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP,       \
615         (unsigned) FT, ASM_COMMENT_START, fundamental_type_name (FT))
616 #endif
617
618 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
619 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT)                             \
620   fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP,                    \
621         (unsigned) FMT, ASM_COMMENT_START, format_byte_name (FMT))
622 #endif
623
624 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
625 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD)                        \
626   fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP,                    \
627         (unsigned) MOD, ASM_COMMENT_START, modifier_name (MOD))
628 #endif
629 \f
630 #ifndef ASM_OUTPUT_DWARF_ADDR
631 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
632  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
633         assemble_name (FILE, LABEL);                                    \
634         fprintf (FILE, "\n");                                           \
635   } while (0)
636 #endif
637
638 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
639 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX)                           \
640   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);                     \
641   output_addr_const ((FILE), (RTX));                                    \
642   fputc ('\n', (FILE))
643 #endif
644
645 #ifndef ASM_OUTPUT_DWARF_REF
646 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL)                                \
647  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
648         assemble_name (FILE, LABEL);                                    \
649         fprintf (FILE, "\n");                                           \
650   } while (0)
651 #endif
652
653 #ifndef ASM_OUTPUT_DWARF_DATA1
654 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
655   fprintf ((FILE), "%s\t0x%x\n", ASM_BYTE_OP, VALUE)
656 #endif
657
658 #ifndef ASM_OUTPUT_DWARF_DATA2
659 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
660   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
661 #endif
662
663 #ifndef ASM_OUTPUT_DWARF_DATA4
664 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
665   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
666 #endif
667
668 #ifndef ASM_OUTPUT_DWARF_DATA8
669 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
670   do {                                                                  \
671     if (WORDS_BIG_ENDIAN)                                               \
672       {                                                                 \
673         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
674         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
675       }                                                                 \
676     else                                                                \
677       {                                                                 \
678         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
679         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
680       }                                                                 \
681   } while (0)
682 #endif
683
684 /* choose a reasonable default for ASM_OUTPUT_ASCII, as that is what
685    varasm.c does.  If the below is changed, please also change
686    definition in varasm.c Both of these should be factored out, into a
687    higher layer.  */
688 #ifndef ASM_OUTPUT_ASCII
689 #define ASM_OUTPUT_ASCII(MYFILE, MYSTRING, MYLENGTH) \
690   do {                                                                        \
691     FILE *_hide_asm_out_file = MYFILE;                                        \
692     char *_hide_p = MYSTRING;                                                 \
693     int _hide_thissize = MYLENGTH;                                            \
694     {                                                                         \
695       FILE *asm_out_file = _hide_asm_out_file;                                \
696       char *p = _hide_p;                                                      \
697       int thissize = _hide_thissize;                                          \
698       int i;                                                                  \
699       fprintf (asm_out_file, "\t.ascii \"");                                  \
700                                                                               \
701       for (i = 0; i < thissize; i++)                                          \
702         {                                                                     \
703           register int c = p[i];                                              \
704           if (c == '\"' || c == '\\')                                         \
705             putc ('\\', asm_out_file);                                        \
706           if (c >= ' ' && c < 0177)                                           \
707             putc (c, asm_out_file);                                           \
708           else                                                                \
709             {                                                                 \
710               fprintf (asm_out_file, "\\%o", c);                              \
711               /* After an octal-escape, if a digit follows,                   \
712                  terminate one string constant and start another.             \
713                  The Vax assembler fails to stop reading the escape           \
714                  after three digits, so this is the only way we               \
715                  can get it to parse the data properly.  */                   \
716               if (i < thissize - 1                                            \
717                   && p[i + 1] >= '0' && p[i + 1] <= '9')                      \
718                 fprintf (asm_out_file, "\"\n\t.ascii \"");                    \
719           }                                                                   \
720         }                                                                     \
721       fprintf (asm_out_file, "\"\n");                                         \
722     }                                                                         \
723   }                                                                           \
724   while (0)
725 #endif
726
727 #ifndef ASM_OUTPUT_DWARF_STRING
728 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
729   ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
730 #endif
731 \f
732 /************************ general utility functions **************************/
733
734 inline char *
735 xstrdup (s)
736      register char *s;
737 {
738   register char *p = (char *) xmalloc (strlen (s) + 1);
739
740   strcpy (p, s);
741   return p;
742 }
743
744 static char *
745 tag_name (tag)
746      register unsigned tag;
747 {
748   switch (tag)
749     {
750     case TAG_padding:           return "TAG_padding";
751     case TAG_array_type:        return "TAG_array_type";
752     case TAG_class_type:        return "TAG_class_type";
753     case TAG_entry_point:       return "TAG_entry_point";
754     case TAG_enumeration_type:  return "TAG_enumeration_type";
755     case TAG_formal_parameter:  return "TAG_formal_parameter";
756     case TAG_global_subroutine: return "TAG_global_subroutine";
757     case TAG_global_variable:   return "TAG_global_variable";
758     case TAG_imported_declaration:      return "TAG_imported_declaration";
759     case TAG_label:             return "TAG_label";
760     case TAG_lexical_block:     return "TAG_lexical_block";
761     case TAG_local_variable:    return "TAG_local_variable";
762     case TAG_member:            return "TAG_member";
763     case TAG_pointer_type:      return "TAG_pointer_type";
764     case TAG_reference_type:    return "TAG_reference_type";
765     case TAG_compile_unit:      return "TAG_compile_unit";
766     case TAG_string_type:       return "TAG_string_type";
767     case TAG_structure_type:    return "TAG_structure_type";
768     case TAG_subroutine:        return "TAG_subroutine";
769     case TAG_subroutine_type:   return "TAG_subroutine_type";
770     case TAG_typedef:           return "TAG_typedef";
771     case TAG_union_type:        return "TAG_union_type";
772     case TAG_unspecified_parameters:    return "TAG_unspecified_parameters";
773     case TAG_variant:           return "TAG_variant";
774     case TAG_format:            return "TAG_format";
775     case TAG_with_stmt:         return "TAG_with_stmt";
776     case TAG_set_type:          return "TAG_set_type";
777     default:                    return "<unknown tag>";
778     }
779 }
780
781 static char *
782 attribute_name (attr)
783      register unsigned attr;
784 {
785   switch (attr)
786     {
787     case AT_sibling:            return "AT_sibling";
788     case AT_location:           return "AT_location";
789     case AT_name:               return "AT_name";
790     case AT_fund_type:          return "AT_fund_type";
791     case AT_mod_fund_type:      return "AT_mod_fund_type";
792     case AT_user_def_type:      return "AT_user_def_type";
793     case AT_mod_u_d_type:       return "AT_mod_u_d_type";
794     case AT_ordering:           return "AT_ordering";
795     case AT_subscr_data:        return "AT_subscr_data";
796     case AT_byte_size:          return "AT_byte_size";
797     case AT_bit_offset:         return "AT_bit_offset";
798     case AT_bit_size:           return "AT_bit_size";
799     case AT_element_list:       return "AT_element_list";
800     case AT_stmt_list:          return "AT_stmt_list";
801     case AT_low_pc:             return "AT_low_pc";
802     case AT_high_pc:            return "AT_high_pc";
803     case AT_language:           return "AT_language";
804     case AT_member:             return "AT_member";
805     case AT_discr:              return "AT_discr";
806     case AT_discr_value:        return "AT_discr_value";
807     case AT_visibility:         return "AT_visibility";
808     case AT_import:             return "AT_import";
809     case AT_string_length:      return "AT_string_length";
810     case AT_comp_dir:           return "AT_comp_dir";
811     case AT_producer:           return "AT_producer";
812     case AT_frame_base:         return "AT_frame_base";
813     case AT_start_scope:        return "AT_start_scope";
814     case AT_stride_size:        return "AT_stride_size";
815     case AT_src_info:           return "AT_src_info";
816     case AT_prototyped:         return "AT_prototyped";
817     case AT_const_value_block4:         return "AT_const_value_block4";
818     case AT_sf_names:           return "AT_sf_names";
819     case AT_mac_info:           return "AT_mac_info";
820     default:                    return "<unknown attribute>";
821     }
822 }
823
824 static char *
825 stack_op_name (op)
826      register unsigned op;
827 {
828   switch (op)
829     {
830     case OP_REG:                return "OP_REG";
831     case OP_BASEREG:            return "OP_BASEREG";
832     case OP_ADDR:               return "OP_ADDR";
833     case OP_CONST:              return "OP_CONST";
834     case OP_DEREF2:             return "OP_DEREF2";
835     case OP_DEREF4:             return "OP_DEREF4";
836     case OP_ADD:                return "OP_ADD";
837     default:                    return "<unknown stack operator>";
838     }
839 }
840
841 static char *
842 modifier_name (mod)
843      register unsigned mod;
844 {
845   switch (mod)
846     {
847     case MOD_pointer_to:        return "MOD_pointer_to";
848     case MOD_reference_to:      return "MOD_reference_to";
849     case MOD_const:             return "MOD_const";
850     case MOD_volatile:          return "MOD_volatile";
851     default:                    return "<unknown modifier>";
852     }
853 }
854
855 static char *
856 format_byte_name (fmt)
857      register unsigned fmt;
858 {
859   switch (fmt)
860     {
861     case FMT_FT_C_C:    return "FMT_FT_C_C";
862     case FMT_FT_C_X:    return "FMT_FT_C_X";
863     case FMT_FT_X_C:    return "FMT_FT_X_C";
864     case FMT_FT_X_X:    return "FMT_FT_X_X";
865     case FMT_UT_C_C:    return "FMT_UT_C_C";
866     case FMT_UT_C_X:    return "FMT_UT_C_X";
867     case FMT_UT_X_C:    return "FMT_UT_X_C";
868     case FMT_UT_X_X:    return "FMT_UT_X_X";
869     case FMT_ET:        return "FMT_ET";
870     default:            return "<unknown array bound format byte>";
871     }
872 }
873 static char *
874 fundamental_type_name (ft)
875      register unsigned ft;
876 {
877   switch (ft)
878     {
879     case FT_char:               return "FT_char";
880     case FT_signed_char:        return "FT_signed_char";
881     case FT_unsigned_char:      return "FT_unsigned_char";
882     case FT_short:              return "FT_short";
883     case FT_signed_short:       return "FT_signed_short";
884     case FT_unsigned_short:     return "FT_unsigned_short";
885     case FT_integer:            return "FT_integer";
886     case FT_signed_integer:     return "FT_signed_integer";
887     case FT_unsigned_integer:   return "FT_unsigned_integer";
888     case FT_long:               return "FT_long";
889     case FT_signed_long:        return "FT_signed_long";
890     case FT_unsigned_long:      return "FT_unsigned_long";
891     case FT_pointer:            return "FT_pointer";
892     case FT_float:              return "FT_float";
893     case FT_dbl_prec_float:     return "FT_dbl_prec_float";
894     case FT_ext_prec_float:     return "FT_ext_prec_float";
895     case FT_complex:            return "FT_complex";
896     case FT_dbl_prec_complex:   return "FT_dbl_prec_complex";
897     case FT_void:               return "FT_void";
898     case FT_boolean:            return "FT_boolean";
899     case FT_long_long:          return "FT_long_long";
900     case FT_signed_long_long:   return "FT_signed_long_long";
901     case FT_unsigned_long_long: return "FT_unsigned_long_long";
902     default:                    return "<unknown fundamental type>";
903     }
904 }
905 \f
906 /**************** utility functions for attribute functions ******************/
907
908 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
909    type code for the given type.
910
911    This routine must only be called for GCC type nodes that correspond to
912    Dwarf fundamental types.
913
914    The current Dwarf draft specification calls for Dwarf fundamental types
915    to accurately reflect the fact that a given type was either a "plain"
916    integral type or an explicitly "signed" integral type.  Unfortuantely,
917    we can't always do this, because GCC may already have thrown away the
918    information about the precise way in which the type was originally
919    specified, as in:
920
921         typedef signed int field_type;
922
923         struct s { field_type f; };
924
925    Since we may be stuck here without enought information to do exactly
926    what is called for in the Dwarf draft specification, we do the best
927    that we can under the circumstances and always use the "plain" integral
928    fundamental type codes for int, short, and long types.  That's probably
929    good enough.  The additional accuracy called for in the current DWARF
930    draft specification is probably never even useful in practice.  */
931
932 static int
933 fundamental_type_code (type)
934      register tree type;
935 {
936   if (TREE_CODE (type) == ERROR_MARK)
937     return 0;
938
939   switch (TREE_CODE (type))
940     {
941       case ERROR_MARK:
942         return FT_void;
943
944       case VOID_TYPE:
945         return FT_void;
946
947       case INTEGER_TYPE:
948         /* Carefully distinguish all the standard types of C,
949            without messing up if the language is not C.
950            Note that we check only for the names that contain spaces;
951            other names might occur by coincidence in other languages.  */
952         if (TYPE_NAME (type) != 0
953             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
954             && DECL_NAME (TYPE_NAME (type)) != 0
955             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
956           {
957             char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
958
959             if (!strcmp (name, "unsigned char"))
960               return FT_unsigned_char;
961             if (!strcmp (name, "signed char"))
962               return FT_signed_char;
963             if (!strcmp (name, "unsigned int"))
964               return FT_unsigned_integer;
965             if (!strcmp (name, "short int"))
966               return FT_short;
967             if (!strcmp (name, "short unsigned int"))
968               return FT_unsigned_short;
969             if (!strcmp (name, "long int"))
970               return FT_long;
971             if (!strcmp (name, "long unsigned int"))
972               return FT_unsigned_long;
973             if (!strcmp (name, "long long int"))
974               return FT_long_long;              /* Not grok'ed by svr4 SDB */
975             if (!strcmp (name, "long long unsigned int"))
976               return FT_unsigned_long_long;     /* Not grok'ed by svr4 SDB */
977           }
978
979         /* Most integer types will be sorted out above, however, for the
980            sake of special `array index' integer types, the following code
981            is also provided.  */
982
983         if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
984           return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
985
986         if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
987           return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
988
989         if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
990           return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
991
992         if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
993           return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
994
995         if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
996           return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
997
998         abort ();
999
1000       case REAL_TYPE:
1001         /* Carefully distinguish all the standard types of C,
1002            without messing up if the language is not C.  */
1003         if (TYPE_NAME (type) != 0
1004             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1005             && DECL_NAME (TYPE_NAME (type)) != 0
1006             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1007           {
1008             char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1009
1010             /* Note that here we can run afowl of a serious bug in "classic"
1011                svr4 SDB debuggers.  They don't seem to understand the
1012                FT_ext_prec_float type (even though they should).  */
1013
1014             if (!strcmp (name, "long double"))
1015               return FT_ext_prec_float;
1016           }
1017
1018         if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1019           return FT_dbl_prec_float;
1020         if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1021           return FT_float;
1022
1023         /* Note that here we can run afowl of a serious bug in "classic"
1024            svr4 SDB debuggers.  They don't seem to understand the
1025            FT_ext_prec_float type (even though they should).  */
1026
1027         if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1028           return FT_ext_prec_float;
1029         abort ();
1030
1031       case COMPLEX_TYPE:
1032         return FT_complex;      /* GNU FORTRAN COMPLEX type.  */
1033
1034       case CHAR_TYPE:
1035         return FT_char;         /* GNU Pascal CHAR type.  Not used in C.  */
1036
1037       case BOOLEAN_TYPE:
1038         return FT_boolean;      /* GNU FORTRAN BOOLEAN type.  */
1039
1040       default:
1041         abort ();       /* No other TREE_CODEs are Dwarf fundamental types.  */
1042     }
1043   return 0;
1044 }
1045 \f
1046 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1047    the Dwarf "root" type for the given input type.  The Dwarf "root" type
1048    of a given type is generally the same as the given type, except that if
1049    the  given type is a pointer or reference type, then the root type of
1050    the given type is the root type of the "basis" type for the pointer or
1051    reference type.  (This definition of the "root" type is recursive.)
1052    Also, the root type of a `const' qualified type or a `volatile'
1053    qualified type is the root type of the given type without the
1054    qualifiers.  */
1055
1056 static tree
1057 root_type (type)
1058      register tree type;
1059 {
1060   if (TREE_CODE (type) == ERROR_MARK)
1061     return error_mark_node;
1062
1063   switch (TREE_CODE (type))
1064     {
1065       case ERROR_MARK:
1066         return error_mark_node;
1067
1068       case POINTER_TYPE:
1069       case REFERENCE_TYPE:
1070         return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1071
1072       default:
1073         return TYPE_MAIN_VARIANT (type);
1074     }
1075 }
1076
1077 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1078    of zero or more Dwarf "type-modifier" bytes applicable to the type.  */
1079
1080 static void
1081 write_modifier_bytes (type, decl_const, decl_volatile)
1082      register tree type;
1083      register int decl_const;
1084      register int decl_volatile;
1085 {
1086   if (TREE_CODE (type) == ERROR_MARK)
1087     return;
1088
1089   if (TYPE_READONLY (type) || decl_const)
1090     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1091   if (TYPE_VOLATILE (type) || decl_volatile)
1092     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1093   switch (TREE_CODE (type))
1094     {
1095       case POINTER_TYPE:
1096         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1097         write_modifier_bytes (TREE_TYPE (type), 0, 0);
1098         return;
1099
1100       case REFERENCE_TYPE:
1101         ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1102         write_modifier_bytes (TREE_TYPE (type), 0, 0);
1103         return;
1104
1105       case ERROR_MARK:
1106       default:
1107         return;
1108     }
1109 }
1110 \f
1111 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1112    given input type is a Dwarf "fundamental" type.  Otherwise return zero.  */
1113
1114 inline int
1115 type_is_fundamental (type)
1116      register tree type;
1117 {
1118   switch (TREE_CODE (type))
1119     {
1120       case ERROR_MARK:
1121       case VOID_TYPE:
1122       case INTEGER_TYPE:
1123       case REAL_TYPE:
1124       case COMPLEX_TYPE:
1125       case BOOLEAN_TYPE:
1126       case CHAR_TYPE:
1127         return 1;
1128
1129       case SET_TYPE:
1130       case ARRAY_TYPE:
1131       case RECORD_TYPE:
1132       case UNION_TYPE:
1133       case ENUMERAL_TYPE:
1134       case FUNCTION_TYPE:
1135       case METHOD_TYPE:
1136       case POINTER_TYPE:
1137       case REFERENCE_TYPE:
1138       case STRING_TYPE:
1139       case FILE_TYPE:
1140       case OFFSET_TYPE:
1141       case LANG_TYPE:
1142         return 0;
1143
1144       default:
1145         abort ();
1146     }
1147   return 0;
1148 }
1149
1150 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1151    equate directive which will associate an easily remembered symbolic name
1152    with the current DIE.
1153
1154    The name used is an artificial label generated from the TYPE_UID number
1155    associated with the given type node.  The name it gets equated to is the
1156    symbolic label that we (previously) output at the start of the DIE that
1157    we are currently generating.
1158
1159    Calling this function while generating some "type related" form of DIE
1160    makes it easy to later refer to the DIE which represents the given type
1161    simply by re-generating the alternative name from the ..._TYPE node's
1162    UID number.  */
1163
1164 inline void
1165 equate_type_number_to_die_number (type)
1166      register tree type;
1167 {
1168   char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1169   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1170
1171   /* We are generating a DIE to represent the main variant of this type
1172      (i.e the type without any const or volatile qualifiers) so in order
1173      to get the equate to come out right, we need to get the main variant
1174      itself here.  */
1175
1176   type = TYPE_MAIN_VARIANT (type);
1177
1178   sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1179   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1180   ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1181 }
1182
1183 /* The following routine is a nice and simple transducer.  It converts the
1184    RTL for a variable or parameter (resident in memory) into an equivalent
1185    Dwarf representation of a mechanism for getting the address of that same
1186    variable onto the top of a hypothetical "address evaluation" stack.
1187
1188    When creating memory location descriptors, we are effectively trans-
1189    forming the RTL for a memory-resident object into its Dwarf postfix
1190    expression equivalent.  This routine just recursively descends an
1191    RTL tree, turning it into Dwarf postfix code as it goes.  */
1192
1193 static void
1194 output_mem_loc_descriptor (rtl)
1195       register rtx rtl;
1196 {
1197   /* Note that for a dynamically sized array, the location we will
1198      generate a description of here will be the lowest numbered location
1199      which is actually within the array.  That's *not* necessarily the
1200      same as the zeroth element of the array.  */
1201
1202   switch (GET_CODE (rtl))
1203     {
1204       case SUBREG:
1205
1206         /* The case of a subreg may arise when we have a local (register)
1207            variable or a formal (register) parameter which doesn't quite
1208            fill up an entire register.  For now, just assume that it is
1209            legitimate to make the Dwarf info refer to the whole register
1210            which contains the given subreg.  */
1211
1212         rtl = XEXP (rtl, 0);
1213         /* Drop thru.  */
1214
1215       case REG:
1216
1217         /* Whenever a register number forms a part of the description of
1218            the method for calculating the (dynamic) address of a memory
1219            resident object, Dwarf rules require the register number to
1220            be referred to as a "base register".  This distinction is not
1221            based in any way upon what category of register the hardware
1222            believes the given register belongs to.  This is strictly
1223            Dwarf terminology we're dealing with here.  */
1224
1225         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1226         ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1227                                 DBX_REGISTER_NUMBER (REGNO (rtl)));
1228         break;
1229
1230       case MEM:
1231         output_mem_loc_descriptor (XEXP (rtl, 0));
1232         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1233         break;
1234
1235       case CONST:
1236       case SYMBOL_REF:
1237         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1238         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1239         break;
1240
1241       case PLUS:
1242         output_mem_loc_descriptor (XEXP (rtl, 0));
1243         output_mem_loc_descriptor (XEXP (rtl, 1));
1244         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1245         break;
1246
1247       case CONST_INT:
1248         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1249         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1250         break;
1251
1252       default:
1253         abort ();
1254     }
1255 }
1256
1257 /* Output a proper Dwarf location descriptor for a variable or parameter
1258    which is either allocated in a register or in a memory location.  For
1259    a register, we just generate an OP_REG and the register number.  For a
1260    memory location we provide a Dwarf postfix expression describing how to
1261    generate the (dynamic) address of the object onto the address stack.  */
1262
1263 static void
1264 output_loc_descriptor (rtl)
1265      register rtx rtl;
1266 {
1267   switch (GET_CODE (rtl))
1268     {
1269     case SUBREG:
1270
1271         /* The case of a subreg may arise when we have a local (register)
1272            variable or a formal (register) parameter which doesn't quite
1273            fill up an entire register.  For now, just assume that it is
1274            legitimate to make the Dwarf info refer to the whole register
1275            which contains the given subreg.  */
1276
1277         rtl = XEXP (rtl, 0);
1278         /* Drop thru.  */
1279
1280     case REG:
1281         ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1282         ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1283                                 DBX_REGISTER_NUMBER (REGNO (rtl)));
1284         break;
1285
1286     case MEM:
1287       output_mem_loc_descriptor (XEXP (rtl, 0));
1288       break;
1289
1290     default:
1291       abort ();         /* Should never happen */
1292     }
1293 }
1294
1295 /* Given a tree node describing an array bound (either lower or upper)
1296    output a representation for that bound.  */
1297
1298 static void
1299 output_bound_representation (bound, dim_num, u_or_l)
1300      register tree bound;
1301      register unsigned dim_num; /* For multi-dimensional arrays.  */
1302      register char u_or_l;      /* Designates upper or lower bound.  */
1303 {
1304   switch (TREE_CODE (bound))
1305     {
1306
1307       case ERROR_MARK:
1308         return;
1309
1310       /* All fixed-bounds are represented by INTEGER_CST nodes.  */
1311
1312       case INTEGER_CST:
1313         ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1314                                 (unsigned) TREE_INT_CST_LOW (bound));
1315         break;
1316
1317       /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1318          SAVE_EXPR nodes.  */
1319
1320       case NOP_EXPR:
1321         bound = TREE_OPERAND (bound, 0);
1322         /* ... fall thru... */
1323
1324       case SAVE_EXPR:
1325         {
1326           char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1327           char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1328
1329           sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1330                                 current_dienum, dim_num, u_or_l);
1331
1332           sprintf (end_label,   BOUND_END_LABEL_FMT,
1333                                 current_dienum, dim_num, u_or_l);
1334
1335           ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1336           ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1337
1338           /* If we are working on a bound for a dynamic dimension in C,
1339              the dynamic dimension in question had better have a static
1340              (zero) lower bound and a dynamic *upper* bound.  */
1341
1342           if (u_or_l != 'u')
1343             abort ();
1344
1345           /* If optimization is turned on, the SAVE_EXPRs that describe
1346              how to access the upper bound values are essentially bogus.
1347              They only describe (at best) how to get at these values at
1348              the points in the generated code right after they have just
1349              been computed.  Worse yet, in the typical case, the upper
1350              bound values will not even *be* computed in the optimized
1351              code, so these SAVE_EXPRs are entirely bogus.
1352
1353              In order to compensate for this fact, we check here to see
1354              if optimization is enabled, and if so, we effectively create
1355              an empty location description for the (unknown and unknowable)
1356              upper bound.
1357
1358              This should not cause too much trouble for existing (stupid?)
1359              debuggers because they have to deal with empty upper bounds
1360              location descriptions anyway in order to be able to deal with
1361              incomplete array types.
1362
1363              Of course an intelligent debugger (GDB?) should be able to
1364              comprehend that a missing upper bound specification in a
1365              array type used for a storage class `auto' local array variable
1366              indicates that the upper bound is both unknown (at compile-
1367              time) and unknowable (at run-time) due to optimization.
1368           */
1369
1370           if (! optimize)
1371             output_loc_descriptor
1372               (eliminate_regs (SAVE_EXPR_RTL (bound), 0, 0));
1373
1374           ASM_OUTPUT_LABEL (asm_out_file, end_label);
1375         }
1376         break;
1377
1378       default:
1379         abort ();
1380     }
1381 }
1382
1383 /* Recursive function to output a sequence of value/name pairs for
1384    enumeration constants in reversed order.  This is called from
1385    enumeration_type_die.  */
1386
1387 static void
1388 output_enumeral_list (link)
1389      register tree link;
1390 {
1391   if (link)
1392     {
1393       output_enumeral_list (TREE_CHAIN (link));
1394       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1395                               (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1396       ASM_OUTPUT_DWARF_STRING (asm_out_file,
1397                                IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1398     }
1399 }
1400
1401 /****************************** attributes *********************************/
1402
1403 /* The following routines are responsible for writing out the various types
1404    of Dwarf attributes (and any following data bytes associated with them).
1405    These routines are listed in order based on the numerical codes of their
1406    associated attributes.  */
1407
1408 /* Generate an AT_sibling attribute.  */
1409
1410 inline void
1411 sibling_attribute ()
1412 {
1413   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1414
1415   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1416   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1417   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1418 }
1419
1420 /* Output the form of location attributes suitable for whole variables and
1421    whole parameters.  Note that the location attributes for struct fields
1422    are generated by the routine `data_member_location_attribute' below.  */
1423
1424 static void
1425 location_attribute (rtl)
1426      register rtx rtl;
1427 {
1428   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1429   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1430
1431   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1432   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1433   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1434   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1435   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1436
1437   /* Handle a special case.  If we are about to output a location descriptor
1438      for a variable or parameter which has been optimized out of existence,
1439      don't do that.  Instead we output a zero-length location descriptor
1440      value as part of the location attribute.  Note that we cannot simply
1441      suppress the entire location attribute, because the absence of a
1442      location attribute in certain kinds of DIEs is used to indicate some-
1443      thing entirely different... i.e. that the DIE represents an object
1444      declaration, but not a definition.  So sayeth the PLSIG.  */
1445
1446   if (((GET_CODE (rtl) != REG) || (REGNO (rtl) < FIRST_PSEUDO_REGISTER))
1447       && ((GET_CODE (rtl) != SUBREG)
1448           || (REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER)))
1449     output_loc_descriptor (eliminate_regs (rtl, 0, 0));
1450
1451   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1452 }
1453
1454 /* Output the specialized form of location attribute used for data members
1455    of struct types.  */
1456
1457 static void
1458 data_member_location_attribute (decl)
1459      register tree decl;
1460 {
1461   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1462   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1463
1464   if (TREE_CODE (decl) == ERROR_MARK)
1465     return;
1466
1467   if (TREE_CODE (decl) != FIELD_DECL)
1468     abort ();
1469
1470   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1471   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1472   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1473   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1474   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1475   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1476
1477   /* This is pretty strange, but existing compilers producing DWARF
1478      apparently calculate the byte offset of a field differently
1479      depending upon whether or not it is a bit-field.  If the given
1480      field is *not* a bit-field, then the offset is simply the
1481      the byte offset of the given field from the beginning of the
1482      struct.  For bit-fields however, the offset is the offset (in
1483      bytes) of the beginning of the *containing word* from the
1484      beginning of the whole struct.  */
1485
1486   ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1487                           (DECL_BIT_FIELD_TYPE (decl))
1488                                 ? BITFIELD_OFFSET_WORDS_IN_UNITS (decl)
1489                                 : BITFIELD_OFFSET_UNITS (decl));
1490   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1491   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1492 }
1493
1494 /* Output an AT_const_value attribute for a variable or a parameter which
1495    does not have a "location" either in memory or in a register.  These
1496    things can arise in GNU C when a constant is passed as an actual
1497    parameter to an inlined function.  They can also arise in C++ where
1498    declared constants do not necessarily get memory "homes".  */
1499
1500 static void
1501 const_value_attribute (rtl)
1502      register rtx rtl;
1503 {
1504   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1505   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1506
1507   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
1508   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1509   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1510   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1511   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1512
1513   switch (GET_CODE (rtl))
1514     {
1515       case CONST_INT:
1516         /* Note that a CONST_INT rtx could represent either an integer or
1517            a floating-point constant.  A CONST_INT is used whenever the
1518            constant will fit into a single word.  In all such cases, the
1519            original mode of the constant value is wiped out, and the
1520            CONST_INT rtx is assigned VOIDmode.  Since we no longer have
1521            precise mode information for these constants, we always just
1522            output them using 4 bytes.  */
1523
1524         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
1525         break;
1526
1527       case CONST_DOUBLE:
1528         /* Note that a CONST_DOUBLE rtx could represent either an integer
1529            or a floating-point constant.  A CONST_DOUBLE is used whenever
1530            the constant requires more than one word in order to be adequately
1531            represented.  In all such cases, the original mode of the constant
1532            value is preserved as the mode of the CONST_DOUBLE rtx, but for
1533            simplicity we always just output CONST_DOUBLEs using 8 bytes.  */
1534
1535         ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
1536                                 (unsigned) CONST_DOUBLE_HIGH (rtl),
1537                                 (unsigned) CONST_DOUBLE_LOW (rtl));
1538         break;
1539
1540       case CONST_STRING:
1541         ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
1542         break;
1543
1544       case SYMBOL_REF:
1545       case LABEL_REF:
1546       case CONST:
1547         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1548         break;
1549
1550       case PLUS:
1551         /* In cases where an inlined instance of an inline function is passed
1552            the address of an `auto' variable (which is local to the caller)
1553            we can get a situation where the DECL_RTL of the artificial
1554            local variable (for the inlining) which acts as a stand-in for
1555            the corresponding formal parameter (of the inline function)
1556            will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
1557            This is not exactly a compile-time constant expression, but it
1558            isn't the address of the (artificial) local variable either.
1559            Rather, it represents the *value* which the artificial local
1560            variable always has during its lifetime.  We currently have no
1561            way to represent such quasi-constant values in Dwarf, so for now
1562            we just punt and generate an AT_const_value attribute with form
1563            FORM_BLOCK4 and a length of zero.  */
1564         break;
1565     }
1566
1567   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1568 }
1569
1570 /* Generate *either* an AT_location attribute or else an AT_const_value
1571    data attribute for a variable or a parameter.  We generate the
1572    AT_const_value attribute only in those cases where the given
1573    variable or parameter does not have a true "location" either in
1574    memory or in a register.  This can happen (for example) when a
1575    constant is passed as an actual argument in a call to an inline
1576    function.  (It's possible that these things can crop up in other
1577    ways also.)  Note that one type of constant value which can be
1578    passed into an inlined function is a constant pointer.  This can
1579    happen for example if an actual argument in an inlined function
1580    call evaluates to a compile-time constant address.  */
1581
1582 static void
1583 location_or_const_value_attribute (decl)
1584      register tree decl;
1585 {
1586   register rtx rtl;
1587
1588   if (TREE_CODE (decl) == ERROR_MARK)
1589     return;
1590
1591   if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
1592     abort ();
1593
1594   /* It's not really clear what existing Dwarf debuggers need or expect
1595      as regards to location information for formal parameters.  A later
1596      version of the Dwarf specification should resolve such issues, but
1597      for the time being, we assume here that debuggers want information
1598      about the location where the parameter was passed into the function.
1599      That seems to be what USL's CI5 compiler generates.  Note that this
1600      will probably be different from the place where the parameter actual
1601      resides during function execution.  Dwarf Version 2 will provide us
1602      with a means to describe that location also, but for now we can only
1603      describe the "passing" location.  */
1604
1605 #if 1 /* This is probably right, but it leads to a lot of trouble.
1606          Fixing one problem has been exposing another,
1607          all of which seemed to have no ill effects before.
1608          Let's try it again for now.  */
1609   rtl = (TREE_CODE (decl) == PARM_DECL)
1610          ? DECL_INCOMING_RTL (decl)
1611          : DECL_RTL (decl);
1612 #else
1613   rtl = DECL_RTL (decl);
1614 #endif
1615
1616   if (rtl == NULL)
1617     return;
1618
1619   switch (GET_CODE (rtl))
1620     {
1621     case CONST_INT:
1622     case CONST_DOUBLE:
1623     case CONST_STRING:
1624     case SYMBOL_REF:
1625     case LABEL_REF:
1626     case CONST:
1627     case PLUS:  /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
1628       const_value_attribute (rtl);
1629       break;
1630
1631     case MEM:
1632     case REG:
1633     case SUBREG:
1634       location_attribute (rtl);
1635       break;
1636
1637     default:
1638       abort ();         /* Should never happen.  */
1639     }
1640 }
1641
1642 /* Generate an AT_name attribute given some string value to be included as
1643    the value of the attribute.  If the name is null, don't do anything.  */
1644
1645 inline void
1646 name_attribute (name_string)
1647      register char *name_string;
1648 {
1649   if (name_string && *name_string)
1650     {
1651       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
1652       ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
1653     }
1654 }
1655
1656 inline void
1657 fund_type_attribute (ft_code)
1658      register unsigned ft_code;
1659 {
1660   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
1661   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
1662 }
1663
1664 static void
1665 mod_fund_type_attribute (type, decl_const, decl_volatile)
1666      register tree type;
1667      register int decl_const;
1668      register int decl_volatile;
1669 {
1670   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1671   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1672
1673   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
1674   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1675   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1676   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1677   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1678   write_modifier_bytes (type, decl_const, decl_volatile);
1679   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
1680                               fundamental_type_code (root_type (type)));
1681   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1682 }
1683
1684 inline void
1685 user_def_type_attribute (type)
1686      register tree type;
1687 {
1688   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1689
1690   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
1691   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
1692   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1693 }
1694
1695 static void
1696 mod_u_d_type_attribute (type, decl_const, decl_volatile)
1697      register tree type;
1698      register int decl_const;
1699      register int decl_volatile;
1700 {
1701   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1702   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1703   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1704
1705   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
1706   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1707   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1708   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1709   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1710   write_modifier_bytes (type, decl_const, decl_volatile);
1711   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
1712   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1713   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1714 }
1715
1716 inline void
1717 ordering_attribute (ordering)
1718      register unsigned ordering;
1719 {
1720   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
1721   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
1722 }
1723
1724 /* Note that the block of subscript information for an array type also
1725    includes information about the element type of type given array type.  */
1726
1727 static void
1728 subscript_data_attribute (type)
1729      register tree type;
1730 {
1731   register unsigned dimension_number;
1732   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1733   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1734
1735   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
1736   sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
1737   sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
1738   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1739   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1740
1741   /* The GNU compilers represent multidimensional array types as sequences
1742      of one dimensional array types whose element types are themselves array
1743      types.  Here we squish that down, so that each multidimensional array
1744      type gets only one array_type DIE in the Dwarf debugging info.  The
1745      draft Dwarf specification say that we are allowed to do this kind
1746      of compression in C (because there is no difference between an
1747      array or arrays and a multidimensional array in C) but for other
1748      source languages (e.g. Ada) we probably shouldn't do this.  */
1749
1750   for (dimension_number = 0;
1751         TREE_CODE (type) == ARRAY_TYPE;
1752         type = TREE_TYPE (type), dimension_number++)
1753     {
1754       register tree domain = TYPE_DOMAIN (type);
1755
1756       /* Arrays come in three flavors.  Unspecified bounds, fixed
1757          bounds, and (in GNU C only) variable bounds.  Handle all
1758          three forms here.  */
1759
1760       if (domain)
1761         {
1762           /* We have an array type with specified bounds.  */
1763
1764           register tree lower = TYPE_MIN_VALUE (domain);
1765           register tree upper = TYPE_MAX_VALUE (domain);
1766
1767           /* Handle only fundamental types as index types for now.  */
1768
1769           if (! type_is_fundamental (domain))
1770             abort ();
1771
1772           /* Output the representation format byte for this dimension. */
1773
1774           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
1775                                   FMT_CODE (1,
1776                                             TREE_CODE (lower) == INTEGER_CST,
1777                                             TREE_CODE (upper) == INTEGER_CST));
1778
1779           /* Output the index type for this dimension.  */
1780
1781           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
1782                                       fundamental_type_code (domain));
1783
1784           /* Output the representation for the lower bound.  */
1785
1786           output_bound_representation (lower, dimension_number, 'l');
1787
1788           /* Output the representation for the upper bound.  */
1789
1790           output_bound_representation (upper, dimension_number, 'u');
1791         }
1792       else
1793         {
1794           /* We have an array type with an unspecified length.  For C and
1795              C++ we can assume that this really means that (a) the index
1796              type is an integral type, and (b) the lower bound is zero.
1797              Note that Dwarf defines the representation of an unspecified
1798              (upper) bound as being a zero-length location description.  */
1799
1800           /* Output the array-bounds format byte.  */
1801
1802           ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
1803
1804           /* Output the (assumed) index type.  */
1805
1806           ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
1807
1808           /* Output the (assumed) lower bound (constant) value.  */
1809
1810           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1811
1812           /* Output the (empty) location description for the upper bound.  */
1813
1814           ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
1815         }
1816     }
1817
1818   /* Output the prefix byte that says that the element type is comming up.  */
1819
1820   ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
1821
1822   /* Output a representation of the type of the elements of this array type.  */
1823
1824   type_attribute (type, 0, 0);
1825
1826   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1827 }
1828
1829 static void
1830 byte_size_attribute (tree_node)
1831      register tree tree_node;
1832 {
1833   register unsigned size;
1834
1835   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
1836   switch (TREE_CODE (tree_node))
1837     {
1838       case ERROR_MARK:
1839         size = 0;
1840         break;
1841
1842       case ENUMERAL_TYPE:
1843       case RECORD_TYPE:
1844       case UNION_TYPE:
1845         size = int_size_in_bytes (tree_node);
1846         break;
1847
1848       case FIELD_DECL:
1849         {
1850           register unsigned words;
1851           register unsigned bits;
1852
1853           bits = TREE_INT_CST_LOW (DECL_SIZE (tree_node));
1854           words = (bits + (BITS_PER_WORD-1)) / BITS_PER_WORD;
1855           size = words * (BITS_PER_WORD / BITS_PER_UNIT);
1856         }
1857         break;
1858
1859       default:
1860         abort ();
1861     }
1862   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
1863 }
1864
1865 /* For a FIELD_DECL node which represents a bit field, output an attribute
1866    which specifies the distance in bits from the start of the *word*
1867    containing the given field to the first bit of the field.  */
1868
1869 inline void
1870 bit_offset_attribute (decl)
1871     register tree decl;
1872 {
1873   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
1874   assert (DECL_BIT_FIELD_TYPE (decl));          /* Must be a bit field.  */
1875
1876   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
1877   ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
1878         BITFIELD_OFFSET_BITS (decl) % (unsigned) BITS_PER_WORD);
1879 }
1880
1881 /* For a FIELD_DECL node which represents a bit field, output an attribute
1882    which specifies the length in bits of the given field.  */
1883
1884 inline void
1885 bit_size_attribute (decl)
1886     register tree decl;
1887 {
1888   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
1889   assert (DECL_BIT_FIELD_TYPE (decl));          /* Must be a bit field.  */
1890
1891   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
1892   ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1893                           (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
1894 }
1895
1896 /* The following routine outputs the `element_list' attribute for enumeration
1897    type DIEs.  The element_lits attribute includes the names and values of
1898    all of the enumeration constants associated with the given enumeration
1899    type.  */
1900
1901 inline void
1902 element_list_attribute (element)
1903      register tree element;
1904 {
1905   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1906   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1907
1908   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
1909   sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
1910   sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
1911   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1912   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1913
1914   /* Here we output a list of value/name pairs for each enumeration constant
1915      defined for this enumeration type (as required), but we do it in REVERSE
1916      order.  The order is the one required by the draft #5 Dwarf specification
1917      published by the UI/PLSIG.  */
1918
1919   output_enumeral_list (element);   /* Recursively output the whole list.  */
1920
1921   ASM_OUTPUT_LABEL (asm_out_file, end_label);
1922 }
1923
1924 /* Generate an AT_stmt_list attribute.  These are normally present only in
1925    DIEs with a TAG_compile_unit tag.  */
1926
1927 inline void
1928 stmt_list_attribute (label)
1929     register char *label;
1930 {
1931   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
1932   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
1933   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
1934 }
1935
1936 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
1937    for a subroutine DIE.  */
1938
1939 inline void
1940 low_pc_attribute (asm_low_label)
1941      register char *asm_low_label;
1942 {
1943   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
1944   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
1945 }
1946
1947 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
1948    subroutine DIE.  */
1949
1950 inline void
1951 high_pc_attribute (asm_high_label)
1952     register char *asm_high_label;
1953 {
1954   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
1955   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
1956 }
1957
1958 /* Generate an AT_language attribute given a LANG value.  These attributes
1959    are used only within TAG_compile_unit DIEs.  */
1960
1961 inline void
1962 language_attribute (language_code)
1963      register unsigned language_code;
1964 {
1965   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
1966   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
1967 }
1968
1969 inline void
1970 member_attribute (context)
1971     register tree context;
1972 {
1973   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1974
1975   /* Generate this attribute only for members in C++.  */
1976
1977   if (context != NULL
1978       && (TREE_CODE (context) == RECORD_TYPE
1979           || TREE_CODE (context) == UNION_TYPE))
1980     {
1981       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
1982       sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
1983       ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1984     }
1985 }
1986
1987 inline void
1988 string_length_attribute (upper_bound)
1989      register tree upper_bound;
1990 {
1991   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1992   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1993
1994   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
1995   sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
1996   sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
1997   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1998   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1999   output_bound_representation (upper_bound, 0, 'u');
2000   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2001 }
2002
2003 inline void
2004 comp_dir_attribute (dirname)
2005      register char *dirname;
2006 {
2007   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2008   ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2009 }
2010
2011 inline void
2012 sf_names_attribute (sf_names_start_label)
2013      register char *sf_names_start_label;
2014 {
2015   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2016   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2017   ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2018 }
2019
2020 inline void
2021 src_info_attribute (src_info_start_label)
2022      register char *src_info_start_label;
2023 {
2024   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2025   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2026   ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2027 }
2028
2029 inline void
2030 mac_info_attribute (mac_info_start_label)
2031      register char *mac_info_start_label;
2032 {
2033   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2034   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
2035   ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2036 }
2037
2038 inline void
2039 prototyped_attribute (func_type)
2040      register tree func_type;
2041 {
2042   if ((strcmp (language_string, "GNU C") == 0)
2043       && (TYPE_ARG_TYPES (func_type) != NULL))
2044     {
2045       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2046       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2047     }
2048 }
2049
2050 inline void
2051 producer_attribute (producer)
2052      register char *producer;
2053 {
2054   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2055   ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2056 }
2057
2058 inline void
2059 inline_attribute (decl)
2060      register tree decl;
2061 {
2062   if (TREE_INLINE (decl))
2063     {
2064       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2065       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2066     }
2067 }
2068
2069 inline void
2070 containing_type_attribute (containing_type)
2071      register tree containing_type;
2072 {
2073   char label[MAX_ARTIFICIAL_LABEL_BYTES];
2074
2075   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2076   sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2077   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2078 }
2079
2080 /************************* end of attributes *****************************/
2081
2082 /********************* utility routines for DIEs *************************/
2083
2084 /* Many forms of DIEs contain a "type description" part.  The following
2085    routine writes out these "type descriptor" parts.  */
2086
2087 static void
2088 type_attribute (type, decl_const, decl_volatile)
2089      register tree type;
2090      register int decl_const;
2091      register int decl_volatile;
2092 {
2093   register enum tree_code code = TREE_CODE (type);
2094   register int root_type_modified;
2095
2096   if (TREE_CODE (type) == ERROR_MARK)
2097     return;
2098
2099   /* Handle a special case.  For functions whose return type is void,
2100      we generate *no* type attribute.  (Note that no object may have
2101      type `void', so this only applies to function return types.  */
2102
2103   if (TREE_CODE (type) == VOID_TYPE)
2104     return;
2105
2106   root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2107                         || decl_const || decl_volatile
2108                         || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2109
2110   if (type_is_fundamental (root_type (type)))
2111     if (root_type_modified)
2112         mod_fund_type_attribute (type, decl_const, decl_volatile);
2113     else
2114         fund_type_attribute (fundamental_type_code (type));
2115   else
2116     if (root_type_modified)
2117         mod_u_d_type_attribute (type, decl_const, decl_volatile);
2118     else
2119         user_def_type_attribute (type);
2120 }
2121
2122 /* Given a tree pointer to a struct, class, union, or enum type node, return
2123    a pointer to the (string) tag name for the given type, or zero if the
2124    type was declared without a tag.  */
2125
2126 static char *
2127 type_tag (type)
2128      register tree type;
2129 {
2130   register char *name = 0;
2131
2132   if (TYPE_NAME (type) != 0)
2133     {
2134       register tree t = 0;
2135
2136       /* Find the IDENTIFIER_NODE for the type name.  */
2137       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2138         t = TYPE_NAME (type);
2139 #if 0
2140       /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2141          to a TYPE_DECL node, regardless of whether or not a `typedef' was
2142          involved.  This is distinctly different from what the gcc front-end
2143          does.  It always makes the TYPE_NAME for each tagged type be either
2144          NULL (signifying an anonymous tagged type) or else a pointer to an
2145          IDENTIFIER_NODE.  Obviously, we would like to generate correct Dwarf
2146          for both C and C++, but given this inconsistancy in the TREE
2147          representation of tagged types for C and C++ in the GNU front-ends,
2148          we cannot support both languages correctly unless we introduce some
2149          front-end specific code here, and rms objects to that, so we can
2150          only generate correct Dwarf for one of these two languages.  C is
2151          more important, so for now we'll do the right thing for C and let
2152          g++ go fish.  */
2153
2154       else
2155         if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2156           t = DECL_NAME (TYPE_NAME (type));
2157 #endif
2158       /* Now get the name as a string, or invent one.  */
2159       if (t != 0)
2160         name = IDENTIFIER_POINTER (t);
2161     }
2162
2163   return (name == 0 || *name == '\0') ? 0 : name;
2164 }
2165
2166 inline void
2167 dienum_push ()
2168 {
2169   /* Start by checking if the pending_sibling_stack needs to be expanded.
2170      If necessary, expand it.  */
2171
2172   if (pending_siblings == pending_siblings_allocated)
2173     {
2174       pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2175       pending_sibling_stack
2176         = (unsigned *) xrealloc (pending_sibling_stack,
2177                                  pending_siblings_allocated * sizeof(unsigned));
2178     }
2179
2180   pending_siblings++;
2181   NEXT_DIE_NUM = next_unused_dienum++;
2182 }
2183
2184 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2185    NEXT_DIE_NUM.  */
2186
2187 inline void
2188 dienum_pop ()
2189 {
2190   pending_siblings--;
2191 }
2192
2193 inline tree
2194 member_declared_type (member)
2195      register tree member;
2196 {
2197   return (DECL_BIT_FIELD_TYPE (member))
2198            ? DECL_BIT_FIELD_TYPE (member)
2199            : TREE_TYPE (member);
2200 }
2201
2202 /******************************* DIEs ************************************/
2203
2204 /* Output routines for individual types of DIEs.  */
2205
2206 /* Note that every type of DIE (except a null DIE) gets a sibling.  */
2207
2208 static void
2209 output_array_type_die (arg)
2210      register void *arg;
2211 {
2212   register tree type = arg;
2213
2214   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2215   sibling_attribute ();
2216   equate_type_number_to_die_number (type);
2217   member_attribute (TYPE_CONTEXT (type));
2218
2219   /* I believe that we can default the array ordering.  SDB will probably
2220      do the right things even if AT_ordering is not present.  It's not
2221      even an issue until we start to get into multidimensional arrays
2222      anyway.  If SDB is shown to do the wrong thing in those cases, then
2223      we'll have to put the AT_ordering attribute back in, but only for
2224      multidimensional array.  (After all, we don't want to waste space
2225      in the .debug section now do we?)  */
2226
2227 #if 0
2228   ordering_attribute (ORD_row_major);
2229 #endif
2230
2231   subscript_data_attribute (type);
2232 }
2233
2234 static void
2235 output_set_type_die (arg)
2236      register void *arg;
2237 {
2238   register tree type = arg;
2239
2240   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2241   sibling_attribute ();
2242   equate_type_number_to_die_number (type);
2243   member_attribute (TYPE_CONTEXT (type));
2244   type_attribute (TREE_TYPE (type), 0, 0);
2245 }
2246
2247 #if 0
2248 /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
2249 static void
2250 output_entry_point_die (arg)
2251      register void *arg;
2252 {
2253   register tree decl = arg;
2254   register tree type = TREE_TYPE (decl);
2255   register tree return_type = TREE_TYPE (type);
2256
2257   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2258   sibling_attribute ();
2259   dienum_push ();
2260   if (DECL_NAME (decl))
2261     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2262   member_attribute (DECL_CONTEXT (decl));
2263   type_attribute (return_type, 0, 0);
2264 }
2265 #endif
2266
2267 /* Output a DIE to represent an enumeration type.  Note that these DIEs
2268    include all of the information about the enumeration values also.
2269    This information is encoded into the element_list attribute.  */
2270
2271 static void
2272 output_enumeration_type_die (arg)
2273      register void *arg;
2274 {
2275   register tree type = arg;
2276
2277   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2278   sibling_attribute ();
2279   equate_type_number_to_die_number (type);
2280   name_attribute (type_tag (type));
2281   member_attribute (TYPE_CONTEXT (type));
2282
2283   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
2284      given enum type is incomplete, do not generate the AT_byte_size
2285      attribute or the AT_element_list attribute.  */
2286
2287   if (TYPE_SIZE (type))
2288     {
2289       byte_size_attribute (type);
2290       element_list_attribute (TYPE_FIELDS (type));
2291     }
2292 }
2293
2294 /* Output a DIE to represent either a real live formal parameter decl or
2295    to represent just the type of some formal parameter position in some
2296    function type.
2297
2298    Note that this routine is a bit unusual because its argument may be
2299    either a PARM_DECL node or else some sort of a ..._TYPE node.  If it's
2300    the formar then this function is being called to output a real live
2301    formal parameter declaration.  If it's the latter, then this function
2302    is only being called to output a TAG_formal_parameter DIE to stand as
2303    a placeholder for some formal argument type of some subprogram type.  */
2304
2305 static void
2306 output_formal_parameter_die (arg)
2307      register void *arg;
2308 {
2309   register tree decl = arg;
2310   register tree type;
2311
2312   if (TREE_CODE (decl) == PARM_DECL)
2313     type = TREE_TYPE (decl);
2314   else
2315     {
2316       type = decl;      /* we were called with a type, not a decl */
2317       decl = NULL;
2318     }
2319
2320   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
2321   sibling_attribute ();
2322   if (decl)
2323     {
2324       if (DECL_NAME (decl))
2325         name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2326       type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2327       location_or_const_value_attribute (decl);
2328     }
2329   else
2330     type_attribute (type, 0, 0);
2331 }
2332
2333 /* Output a DIE to represent a declared function (either file-scope
2334    or block-local) which has "external linkage" (according to ANSI-C).  */
2335
2336 static void
2337 output_global_subroutine_die (arg)
2338      register void *arg;
2339 {
2340   register tree decl = arg;
2341   register tree type = TREE_TYPE (decl);
2342   register tree return_type = TREE_TYPE (type);
2343
2344   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
2345   sibling_attribute ();
2346   dienum_push ();
2347   if (DECL_NAME (decl))
2348     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2349   inline_attribute (decl);
2350   prototyped_attribute (type);
2351   member_attribute (DECL_CONTEXT (decl));
2352   type_attribute (return_type, 0, 0);
2353   if (!TREE_EXTERNAL (decl))
2354     {
2355       char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2356
2357       low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2358       sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2359       high_pc_attribute (func_end_label);
2360     }
2361 }
2362
2363 /* Output a DIE to represent a declared data object (either file-scope
2364    or block-local) which has "external linkage" (according to ANSI-C).  */
2365
2366 static void
2367 output_global_variable_die (arg)
2368      register void *arg;
2369 {
2370   register tree decl = arg;
2371   register tree type = TREE_TYPE (decl);
2372
2373   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
2374   sibling_attribute ();
2375   if (DECL_NAME (decl))
2376     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2377   member_attribute (DECL_CONTEXT (decl));
2378   type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2379   if (!TREE_EXTERNAL (decl))
2380     location_or_const_value_attribute (decl);
2381 }
2382
2383 #if 0
2384 /* TAG_inline_subroutine has been retired by the UI/PLSIG.  We're
2385    now supposed to use either TAG_subroutine or TAG_global_subroutine
2386    (depending on whether or not the function in question has internal
2387    or external linkage) and we're supposed to just put in an AT_inline
2388    attribute.  */
2389 static void
2390 output_inline_subroutine_die (arg)
2391      register void *arg;
2392 {
2393   register tree decl = arg;
2394   register tree type = TREE_TYPE (decl);
2395   register tree return_type = TREE_TYPE (type);
2396
2397   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine);
2398   sibling_attribute ();
2399   dienum_push ();
2400   if (DECL_NAME (decl))
2401     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2402   prototyped_attribute (type);
2403   member_attribute (DECL_CONTEXT (decl));
2404   type_attribute (return_type, 0, 0);
2405
2406   /* Note:  For each inline function which gets an out-of-line body
2407      generated for it, we want to generate AT_low_pc and AT_high_pc
2408      attributes here for the function's out-of-line body.
2409
2410      Unfortunately, the decision as to whether or not to generate an
2411      out-of-line body for any given inline function may not be made
2412      until we reach the end of the containing scope for the given
2413      inline function (because only then will it be known if the
2414      function was ever even called).
2415
2416      For this reason, the output of DIEs representing file-scope inline
2417      functions gets delayed until a special post-pass which happens only
2418      after we have reached the end of the compilation unit.  Because of
2419      this mechanism, we can always be sure (by the time we reach here)
2420      that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not
2421      there was an out-of-line body generated for this inline function.
2422   */
2423
2424   if (!TREE_EXTERNAL (decl))
2425     {
2426       if (TREE_ASM_WRITTEN (decl))
2427         {
2428           char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2429
2430           low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2431           sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2432           high_pc_attribute (func_end_label);
2433         }
2434     }
2435 }
2436 #endif
2437
2438 static void
2439 output_label_die (arg)
2440      register void *arg;
2441 {
2442   register tree decl = arg;
2443   register rtx insn = DECL_RTL (decl);
2444
2445   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
2446   sibling_attribute ();
2447   name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2448
2449   /* When optimization is enabled (with -O) the code in jump.c and in flow.c
2450      may cause insns representing one of more of the user's own labels to
2451      be deleted.  This happens whenever it is determined that a given label
2452      is unreachable.
2453
2454      In such cases, we here generate an abbreviated form of a label DIE.
2455      This abbreviated version does *not* have a low_pc attribute.  This
2456      should signify to the debugger that the label has been optimized away.
2457
2458      Note that a CODE_LABEL can get deleted either by begin converted into
2459      a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag
2460      set to true.  We handle both cases here.
2461   */
2462
2463   if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn))
2464     {
2465       char label[MAX_ARTIFICIAL_LABEL_BYTES];
2466
2467       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
2468                                       (unsigned) INSN_UID (insn));
2469       low_pc_attribute (label);
2470     }
2471 }
2472
2473 static void
2474 output_lexical_block_die (arg)
2475      register void *arg;
2476 {
2477   register tree stmt = arg;
2478   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2479   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2480
2481   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
2482   sibling_attribute ();
2483   dienum_push ();
2484   sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2485   low_pc_attribute (begin_label);
2486   sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2487   high_pc_attribute (end_label);
2488 }
2489
2490 static void
2491 output_inlined_subroutine_die (arg)
2492      register void *arg;
2493 {
2494   register tree stmt = arg;
2495   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2497
2498   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
2499   sibling_attribute ();
2500   dienum_push ();
2501   sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2502   low_pc_attribute (begin_label);
2503   sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2504   high_pc_attribute (end_label);
2505 }
2506
2507 /* Output a DIE to represent a declared data object (either file-scope
2508    or block-local) which has "internal linkage" (according to ANSI-C).  */
2509
2510 static void
2511 output_local_variable_die (arg)
2512      register void *arg;
2513 {
2514   register tree decl = arg;
2515   register tree type = TREE_TYPE (decl);
2516
2517   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
2518   sibling_attribute ();
2519   if (DECL_NAME (decl))
2520     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2521   member_attribute (DECL_CONTEXT (decl));
2522   type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2523   location_or_const_value_attribute (decl);
2524 }
2525
2526 static void
2527 output_member_die (arg)
2528      register void *arg;
2529 {
2530   register tree decl = arg;
2531
2532   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
2533   sibling_attribute ();
2534   if (DECL_NAME (decl))
2535     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2536   member_attribute (DECL_CONTEXT (decl));
2537   type_attribute (member_declared_type (decl),
2538                   TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2539   if (DECL_BIT_FIELD_TYPE (decl))       /* If this is a bit field... */
2540     {
2541       byte_size_attribute (decl);
2542       bit_size_attribute (decl);
2543       bit_offset_attribute (decl);
2544     }
2545   data_member_location_attribute (decl);
2546 }
2547
2548 #if 0
2549 /* Don't generate either pointer_type DIEs or reference_type DIEs.  According
2550    to the 4-4-90 Dwarf draft spec (just after requirement #47):
2551
2552         These two type entries are not currently generated by any compiler.
2553         Since the only way to name a pointer (or reference) type is C or C++
2554         is via a "typedef", an entry with the "typedef" tag is generated
2555         instead.
2556
2557    We keep this code here just in case these types of DIEs may be needed
2558    to represent certain things in other languages (e.g. Pascal) someday.
2559 */
2560
2561 static void
2562 output_pointer_type_die (arg)
2563      register void *arg;
2564 {
2565   register tree type = arg;
2566
2567   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
2568   sibling_attribute ();
2569   equate_type_number_to_die_number (type);
2570   member_attribute (TYPE_CONTEXT (type));
2571   type_attribute (TREE_TYPE (type), 0, 0);
2572 }
2573
2574 static void
2575 output_reference_type_die (arg)
2576      register void *arg;
2577 {
2578   register tree type = arg;
2579
2580   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
2581   sibling_attribute ();
2582   equate_type_number_to_die_number (type);
2583   member_attribute (TYPE_CONTEXT (type));
2584   type_attribute (TREE_TYPE (type), 0, 0);
2585 }
2586 #endif
2587
2588 output_ptr_to_mbr_type_die (arg)
2589      register void *arg;
2590 {
2591   register tree type = arg;
2592
2593   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
2594   sibling_attribute ();
2595   equate_type_number_to_die_number (type);
2596   member_attribute (TYPE_CONTEXT (type));
2597   containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
2598   type_attribute (TREE_TYPE (type), 0, 0);
2599 }
2600
2601 static void
2602 output_compile_unit_die (arg)
2603      register void *arg;
2604 {
2605   register char *main_input_filename = arg;
2606
2607   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
2608   sibling_attribute ();
2609   dienum_push ();
2610   name_attribute (main_input_filename);
2611
2612   {
2613     char producer[250];
2614
2615     sprintf (producer, "%s %s", language_string, version_string);
2616     producer_attribute (producer);
2617   }
2618
2619   if (strcmp (language_string, "GNU C++") == 0)
2620     language_attribute (LANG_C_PLUS_PLUS);
2621   else if (flag_traditional)
2622     language_attribute (LANG_C);
2623   else
2624     language_attribute (LANG_C89);
2625   low_pc_attribute (TEXT_BEGIN_LABEL);
2626   high_pc_attribute (TEXT_END_LABEL);
2627   if (debug_info_level >= DINFO_LEVEL_NORMAL)
2628     stmt_list_attribute (LINE_BEGIN_LABEL);
2629   last_filename = xstrdup (main_input_filename);
2630
2631   {
2632     char *wd = getpwd ();
2633     if (wd)
2634       comp_dir_attribute (wd);
2635   }
2636
2637   if (debug_info_level >= DINFO_LEVEL_NORMAL)
2638     {
2639       sf_names_attribute (SFNAMES_BEGIN_LABEL);
2640       src_info_attribute (SRCINFO_BEGIN_LABEL);
2641       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
2642         mac_info_attribute (MACINFO_BEGIN_LABEL);
2643     }
2644 }
2645
2646 static void
2647 output_string_type_die (arg)
2648      register void *arg;
2649 {
2650   register tree type = arg;
2651
2652   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
2653   sibling_attribute ();
2654   member_attribute (TYPE_CONTEXT (type));
2655
2656   /* Fudge the string length attribute for now.  */
2657
2658   string_length_attribute (
2659         TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
2660 }
2661
2662 static void
2663 output_structure_type_die (arg)
2664      register void *arg;
2665 {
2666   register tree type = arg;
2667
2668   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
2669   sibling_attribute ();
2670   equate_type_number_to_die_number (type);
2671   name_attribute (type_tag (type));
2672   member_attribute (TYPE_CONTEXT (type));
2673
2674   /* If this type has been completed, then give it a byte_size attribute
2675      and prepare to give a list of members.  Otherwise, don't do either of
2676      these things.  In the latter case, we will not be generating a list
2677      of members (since we don't have any idea what they might be for an
2678      incomplete type).  */
2679
2680   if (TYPE_SIZE (type))
2681     {
2682       dienum_push ();
2683       byte_size_attribute (type);
2684     }
2685 }
2686
2687 /* Output a DIE to represent a declared function (either file-scope
2688    or block-local) which has "internal linkage" (according to ANSI-C).  */
2689
2690 static void
2691 output_local_subroutine_die (arg)
2692      register void *arg;
2693 {
2694   register tree decl = arg;
2695   register tree type = TREE_TYPE (decl);
2696   register tree return_type = TREE_TYPE (type);
2697   char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2698
2699   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
2700   sibling_attribute ();
2701   dienum_push ();
2702   if (DECL_NAME (decl))
2703     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2704   inline_attribute (decl);
2705   prototyped_attribute (type);
2706   member_attribute (DECL_CONTEXT (decl));
2707   type_attribute (return_type, 0, 0);
2708
2709   /* Avoid getting screwed up in cases where a function was declared static
2710      but where no definition was ever given for it.  */
2711
2712   if (TREE_ASM_WRITTEN (decl))
2713     {
2714       low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2715       sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2716       high_pc_attribute (func_end_label);
2717     }
2718 }
2719
2720 static void
2721 output_subroutine_type_die (arg)
2722      register void *arg;
2723 {
2724   register tree type = arg;
2725   register tree return_type = TREE_TYPE (type);
2726
2727   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
2728   sibling_attribute ();
2729   dienum_push ();
2730   equate_type_number_to_die_number (type);
2731   prototyped_attribute (type);
2732   member_attribute (TYPE_CONTEXT (type));
2733   type_attribute (return_type, 0, 0);
2734 }
2735
2736 static void
2737 output_typedef_die (arg)
2738      register void *arg;
2739 {
2740   register tree decl = arg;
2741   register tree type = TREE_TYPE (decl);
2742
2743   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
2744   sibling_attribute ();
2745   if (DECL_NAME (decl))
2746     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2747   member_attribute (DECL_CONTEXT (decl));
2748   type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2749 }
2750
2751 static void
2752 output_union_type_die (arg)
2753      register void *arg;
2754 {
2755   register tree type = arg;
2756
2757   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
2758   sibling_attribute ();
2759   equate_type_number_to_die_number (type);
2760   name_attribute (type_tag (type));
2761   member_attribute (TYPE_CONTEXT (type));
2762
2763   /* If this type has been completed, then give it a byte_size attribute
2764      and prepare to give a list of members.  Otherwise, don't do either of
2765      these things.  In the latter case, we will not be generating a list
2766      of members (since we don't have any idea what they might be for an
2767      incomplete type).  */
2768
2769   if (TYPE_SIZE (type))
2770     {
2771       dienum_push ();
2772       byte_size_attribute (type);
2773     }
2774 }
2775
2776 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
2777    at the end of an (ANSI prototyped) formal parameters list.  */
2778
2779 static void
2780 output_unspecified_parameters_die (arg)
2781      register void *arg;
2782 {
2783   register tree decl_or_type = arg;
2784
2785   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
2786   sibling_attribute ();
2787
2788   /* This kludge is here only for the sake of being compatible with what
2789      the USL CI5 C compiler does.  The specification of Dwarf Version 1
2790      doesn't say that TAG_unspecified_parameters DIEs should contain any
2791      attributes other than the AT_sibling attribute, but they are certainly
2792      allowed to contain additional attributes, and the CI5 compiler
2793      generates AT_name, AT_fund_type, and AT_location attributes within
2794      TAG_unspecified_parameters DIEs which appear in the child lists for
2795      DIEs representing function definitions, so we do likewise here.  */
2796
2797   if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
2798     {
2799       name_attribute ("...");
2800       fund_type_attribute (FT_pointer);
2801       /* location_attribute (?); */
2802     }
2803 }
2804
2805 static void
2806 output_padded_null_die (arg)
2807      register void *arg;
2808 {
2809   ASM_OUTPUT_ALIGN (asm_out_file, 2);   /* 2**2 == 4 */
2810 }
2811
2812 /*************************** end of DIEs *********************************/
2813
2814 /* Generate some type of DIE.  This routine generates the generic outer
2815    wrapper stuff which goes around all types of DIE's (regardless of their
2816    TAGs.  All forms of DIEs start with a DIE-specific label, followed by a
2817    DIE-length word, followed by the guts of the DIE itself.  After the guts
2818    of the DIE, there must always be a terminator label for the DIE.  */
2819
2820 static void
2821 output_die (die_specific_output_function, param)
2822      register void (*die_specific_output_function)();
2823      register void *param;
2824 {
2825   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2826   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2827
2828   current_dienum = NEXT_DIE_NUM;
2829   NEXT_DIE_NUM = next_unused_dienum;
2830
2831   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2832   sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
2833
2834   /* Write a label which will act as the name for the start of this DIE.  */
2835
2836   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2837
2838   /* Write the DIE-length word.  */
2839
2840   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2841
2842   /* Fill in the guts of the DIE.  */
2843
2844   next_unused_dienum++;
2845   die_specific_output_function (param);
2846
2847   /* Write a label which will act as the name for the end of this DIE.  */
2848
2849   ASM_OUTPUT_LABEL (asm_out_file, end_label);
2850 }
2851
2852 static void
2853 end_sibling_chain ()
2854 {
2855   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2856
2857   current_dienum = NEXT_DIE_NUM;
2858   NEXT_DIE_NUM = next_unused_dienum;
2859
2860   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2861
2862   /* Write a label which will act as the name for the start of this DIE.  */
2863
2864   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2865
2866   /* Write the DIE-length word.  */
2867
2868   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
2869
2870   dienum_pop ();
2871 }
2872 \f
2873 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
2874    TAG_unspecified_parameters DIE) to represent the types of the formal
2875    parameters as specified in some function type specification (except
2876    for those which appear as part of a function *definition*).
2877
2878    Note that we must be careful here to output all of the parameter DIEs
2879    *before* we output any DIEs needed to represent the types of the formal
2880    parameters.  This keeps svr4 SDB happy because it (incorrectly) thinks
2881    that the first non-parameter DIE it sees ends the formal parameter list.
2882 */
2883
2884 static void
2885 output_formal_types (function_or_method_type)
2886      register tree function_or_method_type;
2887 {
2888   register tree link;
2889   register tree formal_type;
2890   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
2891
2892   /* In the case where we are generating a formal types list for a C++
2893      non-static member function type, skip over the first thing on the
2894      TYPE_ARG_TYPES list because it only represents the type of the
2895      hidden `this pointer'.  The debugger should be able to figure
2896      out (without being explicitly told) that this non-static member
2897      function type takes a `this pointer' and should be able to figure
2898      what the type of that hidden parameter is from the AT_member
2899      attribute of the parent TAG_subroutine_type DIE.  */
2900
2901   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
2902     first_parm_type = TREE_CHAIN (first_parm_type);
2903
2904   /* Make our first pass over the list of formal parameter types and output
2905      a TAG_formal_parameter DIE for each one.  */
2906
2907   for (link = first_parm_type; link; link = TREE_CHAIN (link))
2908     {
2909       formal_type = TREE_VALUE (link);
2910       if (formal_type == void_type_node)
2911         break;
2912
2913       /* Output a (nameless) DIE to represent the formal parameter itself.  */
2914
2915       output_die (output_formal_parameter_die, formal_type);
2916     }
2917
2918   /* If this function type has an ellipsis, add a TAG_unspecified_parameters
2919      DIE to the end of the parameter list.  */
2920
2921   if (formal_type != void_type_node)
2922     output_die (output_unspecified_parameters_die, function_or_method_type);
2923
2924   /* Make our second (and final) pass over the list of formal parameter types
2925      and output DIEs to represent those types (as necessary).  */
2926
2927   for (link = TYPE_ARG_TYPES (function_or_method_type);
2928        link;
2929        link = TREE_CHAIN (link))
2930     {
2931       formal_type = TREE_VALUE (link);
2932       if (formal_type == void_type_node)
2933         break;
2934
2935       output_type (formal_type, function_or_method_type);
2936     }
2937 }
2938 \f
2939 /* Remember a type in the pending_types_list.  */
2940
2941 static void
2942 pend_type (type)
2943      register tree type;
2944 {
2945   if (pending_types == pending_types_allocated)
2946     {
2947       pending_types_allocated += PENDING_TYPES_INCREMENT;
2948       pending_types_list
2949         = (tree *) xrealloc (pending_types_list,
2950                              sizeof (tree) * pending_types_allocated);
2951     }
2952   pending_types_list[pending_types++] = type;
2953
2954   /* Mark the pending type as having been output already (even though
2955      it hasn't been).  This prevents the type from being added to the
2956      pending_types_list more than once.  */
2957
2958   TREE_ASM_WRITTEN (type) = 1;
2959 }
2960
2961 /* Return non-zero if it is legitimate to output DIEs to represent a
2962    given type while we are generating the list of child DIEs for some
2963    DIE associated with a given scope.
2964
2965    This function returns non-zero if *either* of the following two conditions
2966    is satisfied:
2967
2968          o      the type actually belongs to the given scope (as evidenced
2969                 by its TYPE_CONTEXT value), or
2970
2971          o      the type is anonymous, and the `scope' in question is *not*
2972                 a RECORD_TYPE or UNION_TYPE.
2973
2974    In theory, we should be able to generate DIEs for anonymous types
2975    *anywhere* (since the scope of an anonymous type is irrelevant)
2976    however svr4 SDB doesn't want to see other type DIEs within the
2977    lists of child DIEs for a TAG_structure_type or TAG_union_type DIE.
2978
2979    Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
2980    or it may point to a BLOCK node (for types local to a block), or to a
2981    FUNCTION_DECL node (for types local to the heading of some function
2982    definition), or to a FUNCTION_TYPE node (for types local to the
2983    prototyped parameter list of a function type specification), or to a
2984    RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
2985
2986    The `scope' parameter should likewise be NULL or should point to a
2987    BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
2988    node, or a UNION_TYPE node.
2989
2990    This function is used only for deciding when to "pend" and when to
2991    "un-pend" types to/from the pending_types_list.
2992
2993    Note that we sometimes make use of this "type pending" feature in a
2994    rather twisted way to temporarily delay the production of DIEs for the
2995    types of formal parameters.  (We do this just to make svr4 SDB happy.)
2996    It order to delay the production of DIEs representing types of formal
2997    parameters, callers of this function supply `fake_containing_scope' as
2998    the `scope' parameter to this function.  Given that fake_containing_scope
2999    is *not* the containing scope for *any* other type, the desired effect
3000    is achieved, i.e. output of DIEs representing types is temporarily
3001    suspended, and any type DIEs which would have been output otherwise
3002    are instead placed onto the pending_types_list.  Later on, we can force
3003    these (temporarily pended) types to be output simply by calling
3004    `output_pending_types_for_scope' with an actual argument equal to the
3005    true scope of the types we temporarily pended.
3006 */
3007
3008 static int
3009 type_ok_for_scope (type, scope)
3010     register tree type;
3011     register tree scope;
3012 {
3013   return (TYPE_CONTEXT (type) == scope
3014           || (TYPE_NAME (type) == NULL
3015               && TREE_CODE (scope) != RECORD_TYPE
3016               && TREE_CODE (scope) != UNION_TYPE));
3017 }
3018
3019 /* Output any pending types (from the pending_types list) which we can output
3020    now (given the limitations of the scope that we are working on now).
3021
3022    For each type output, remove the given type from the pending_types_list
3023    *before* we try to output it.
3024
3025    Note that we have to process the list in beginning-to-end order,
3026    because the call made here to output_type may cause yet more types
3027    to be added to the end of the list, and we may have to output some
3028    of them too.
3029 */
3030
3031 static void
3032 output_pending_types_for_scope (containing_scope)
3033      register tree containing_scope;
3034 {
3035   register unsigned i;
3036
3037   for (i = 0; i < pending_types; )
3038     {
3039       register tree type = pending_types_list[i];
3040
3041       if (type_ok_for_scope (type, containing_scope))
3042         {
3043           register tree *mover;
3044           register tree *limit;
3045
3046           pending_types--;
3047           limit = &pending_types_list[pending_types];
3048           for (mover = &pending_types_list[i]; mover < limit; mover++)
3049             *mover = *(mover+1);
3050
3051           /* Un-mark the type as having been output already (because it
3052              hasn't been, really).  Then call output_type to generate a
3053              Dwarf representation of it.  */
3054
3055           TREE_ASM_WRITTEN (type) = 0;
3056           output_type (type, containing_scope);
3057
3058           /* Don't increment the loop counter in this case because we
3059              have shifted all of the subsequent pending types down one
3060              element in the pending_types_list array.  */
3061         }
3062       else
3063         i++;
3064     }
3065 }
3066
3067 static void
3068 output_type (type, containing_scope)
3069      register tree type;
3070      register tree containing_scope;
3071 {
3072   if (type == 0 || type == error_mark_node)
3073     return;
3074
3075   /* We are going to output a DIE to represent the unqualified version of
3076      of this type (i.e. without any const or volatile qualifiers) so get
3077      the main variant (i.e. the unqualified version) of this type now.  */
3078
3079   type = TYPE_MAIN_VARIANT (type);
3080
3081   if (TREE_ASM_WRITTEN (type))
3082     return;
3083
3084   /* Don't generate any DIEs for this type now unless it is OK to do so
3085      (based upon what `type_ok_for_scope' tells us).  */
3086
3087   if (! type_ok_for_scope (type, containing_scope))
3088     {
3089       pend_type (type);
3090       return;
3091     }
3092
3093   switch (TREE_CODE (type))
3094     {
3095       case ERROR_MARK:
3096         break;
3097
3098       case POINTER_TYPE:
3099       case REFERENCE_TYPE:
3100         /* For these types, all that is required is that we output a DIE
3101            (or a set of DIEs) to represent that "basis" type.  */
3102         output_type (TREE_TYPE (type), containing_scope);
3103         break;
3104
3105       case OFFSET_TYPE:
3106         /* This code is used for C++ pointer-to-data-member types.  */
3107         /* Output a description of the relevant class type.  */
3108         output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3109         /* Output a description of the type of the object pointed to.  */
3110         output_type (TREE_TYPE (type), containing_scope);
3111         /* Now output a DIE to represent this pointer-to-data-member type
3112            itself.  */
3113         output_die (output_ptr_to_mbr_type_die, type);
3114         break;
3115
3116       case SET_TYPE:
3117         output_type (TREE_TYPE (type), containing_scope);
3118         output_die (output_set_type_die, type);
3119         break;
3120
3121       case FILE_TYPE:
3122         output_type (TREE_TYPE (type), containing_scope);
3123         abort ();       /* No way to reprsent these in Dwarf yet!  */
3124         break;
3125
3126       case STRING_TYPE:
3127         output_type (TREE_TYPE (type), containing_scope);
3128         output_die (output_string_type_die, type);
3129         break;
3130
3131       case FUNCTION_TYPE:
3132         /* Force out return type (in case it wasn't forced out already).  */
3133         output_type (TREE_TYPE (type), containing_scope);
3134         output_die (output_subroutine_type_die, type);
3135         output_formal_types (type);
3136         end_sibling_chain ();
3137         break;
3138
3139       case METHOD_TYPE:
3140         /* Force out return type (in case it wasn't forced out already).  */
3141         output_type (TREE_TYPE (type), containing_scope);
3142         output_die (output_subroutine_type_die, type);
3143         output_formal_types (type);
3144         end_sibling_chain ();
3145         break;
3146
3147       case ARRAY_TYPE:
3148         {
3149           register tree element_type;
3150
3151           element_type = TREE_TYPE (type);
3152           while (TREE_CODE (element_type) == ARRAY_TYPE)
3153             element_type = TREE_TYPE (element_type);
3154
3155           output_type (element_type, containing_scope);
3156           output_die (output_array_type_die, type);
3157         }
3158         break;
3159
3160       case ENUMERAL_TYPE:
3161       case RECORD_TYPE:
3162       case UNION_TYPE:
3163
3164         /* For a non-file-scope tagged type, we can always go ahead and
3165            output a Dwarf description of this type right now, even if
3166            the type in question is still incomplete, because if this
3167            local type *was* ever completed anywhere within its scope,
3168            that complete definition would already have been attached to
3169            this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3170            time we reach this point.  That's true because of the way the
3171            front-end does its processing of file-scope declarations (of
3172            functions and class types) within which other types might be
3173            nested.  The C and C++ front-ends always gobble up such "local
3174            scope" things en-mass before they try to output *any* debugging
3175            information for any of the stuff contained inside them and thus,
3176            we get the benefit here of what is (in effect) a pre-resolution
3177            of forward references to tagged types in local scopes.
3178
3179            Note however that for file-scope tagged types we cannot assume
3180            that such pre-resolution of forward references has taken place.
3181            A given file-scope tagged type may appear to be incomplete when
3182            we reach this point, but it may yet be given a full definition
3183            (at file-scope) later on during compilation.  In order to avoid
3184            generating a premature (and possibly incorrect) set of Dwarf
3185            DIEs for such (as yet incomplete) file-scope tagged types, we
3186            generate nothing at all for as-yet incomplete file-scope tagged
3187            types here unless we are making our special "finalization" pass
3188            for file-scope things at the very end of compilation.  At that
3189            time, we will certainly know as much about each file-scope tagged
3190            type as we are ever going to know, so at that point in time, we
3191            can safely generate correct Dwarf descriptions for these file-
3192            scope tagged types.
3193         */
3194
3195         if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3196           return;       /* EARLY EXIT!  Avoid setting TREE_ASM_WRITTEN.  */
3197
3198         /* Prevent infinite recursion in cases where the type of some
3199            member of this type is expressed in terms of this type itself.  */
3200
3201         TREE_ASM_WRITTEN (type) = 1;
3202
3203         /* Output a DIE to represent the tagged type itself.  */
3204
3205         switch (TREE_CODE (type))
3206           {
3207           case ENUMERAL_TYPE:
3208             output_die (output_enumeration_type_die, type);
3209             return;  /* a special case -- nothing left to do so just return */
3210
3211           case RECORD_TYPE:
3212             output_die (output_structure_type_die, type);
3213             break;
3214
3215           case UNION_TYPE:
3216             output_die (output_union_type_die, type);
3217             break;
3218           }
3219
3220         /* If this is not an incomplete type, output descriptions of
3221            each of its members.
3222
3223            Note that as we output the DIEs necessary to represent the
3224            members of this record or union type, we will also be trying
3225            to output DIEs to represent the *types* of those members.
3226            However the `output_type' function (above) will specifically
3227            avoid generating type DIEs for member types *within* the list
3228            of member DIEs for this (containing) type execpt for those
3229            types (of members) which are explicitly marked as also being
3230            members of this (containing) type themselves.  The g++ front-
3231            end can force any given type to be treated as a member of some
3232            other (containing) type by setting the TYPE_CONTEXT of the
3233            given (member) type to point to the TREE node representing the
3234            appropriate (containing) type.
3235         */
3236
3237         if (TYPE_SIZE (type))
3238           {
3239             register tree member;
3240
3241             /* First output info about the data members and type members.  */
3242
3243             for (member = TYPE_FIELDS (type);
3244                  member;
3245                  member = TREE_CHAIN (member))
3246               output_decl (member, type);
3247
3248             /* Now output info about the function members (if any).  */
3249
3250             if (TYPE_METHODS (type))
3251               for (member = TREE_VEC_ELT (TYPE_METHODS (type), 0);
3252                    member;
3253                    member = TREE_CHAIN (member))
3254                 output_decl (member, type);
3255
3256             end_sibling_chain ();       /* Terminate member chain.  */
3257           }
3258
3259         break;
3260
3261       case VOID_TYPE:
3262       case INTEGER_TYPE:
3263       case REAL_TYPE:
3264       case COMPLEX_TYPE:
3265       case BOOLEAN_TYPE:
3266       case CHAR_TYPE:
3267         break;          /* No DIEs needed for fundamental types.  */
3268
3269       case LANG_TYPE:   /* No Dwarf representation currently defined.  */
3270         break;
3271
3272       default:
3273         abort ();
3274     }
3275
3276   TREE_ASM_WRITTEN (type) = 1;
3277 }
3278 \f
3279 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
3280    the things which are local to the given block.  */
3281
3282 static void
3283 output_block (stmt)
3284     register tree stmt;
3285 {
3286   register int have_significant_locals = 0;
3287
3288   /* Ignore blocks never really used to make RTL.  */
3289
3290   if (! stmt || ! TREE_USED (stmt))
3291     return;
3292
3293   /* Determine if this block contains any "significant" local declarations
3294      which we need to output DIEs for.  */
3295
3296   if (BLOCK_INLINE_FUNCTION (stmt))
3297     /* The outer scopes for inlinings *must* always be represented.  */
3298     have_significant_locals = 1;
3299   else
3300     if (debug_info_level > DINFO_LEVEL_TERSE)
3301       have_significant_locals = (BLOCK_VARS (stmt) != NULL);
3302     else
3303       {
3304         register tree decl;
3305
3306         for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3307           if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
3308             {
3309               have_significant_locals = 1;
3310               break;
3311             }
3312       }
3313
3314   /* It would be a waste of space to generate a Dwarf TAG_lexical_block
3315      DIE for any block which contains no significant local declarations
3316      at all.  Rather, in such cases we just call `output_decls_for_scope'
3317      so that any needed Dwarf info for any sub-blocks will get properly
3318      generated.  Note that in terse mode, our definition of what constitutes
3319      a "significant" local declaration gets restricted to include only
3320      inlined function instances and local (nested) function definitions.  */
3321
3322   if (have_significant_locals)
3323     {
3324       output_die (BLOCK_INLINE_FUNCTION (stmt)
3325                         ? output_inlined_subroutine_die
3326                         : output_lexical_block_die,
3327                   stmt);
3328       output_decls_for_scope (stmt);
3329       end_sibling_chain ();
3330     }
3331   else
3332     output_decls_for_scope (stmt);
3333 }
3334
3335 /* Output all of the decls declared within a given scope (also called
3336    a `binding contour') and (recursively) all of it's sub-blocks.  */
3337
3338 static void
3339 output_decls_for_scope (stmt)
3340      register tree stmt;
3341 {
3342   /* Ignore blocks never really used to make RTL.  */
3343
3344   if (! stmt || ! TREE_USED (stmt))
3345     return;
3346
3347   next_block_number++;
3348
3349   /* Output the DIEs to represent all of the data objects, functions,
3350      typedefs, and tagged types declared directly within this block
3351      but not within any nested sub-blocks.  */
3352
3353   {
3354     register tree decl;
3355
3356     for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3357       output_decl (decl, stmt);
3358   }
3359
3360   output_pending_types_for_scope (stmt);
3361
3362   /* Output the DIEs to represent all sub-blocks (and the items declared
3363      therein) of this block.     */
3364
3365   {
3366     register tree subblocks;
3367
3368     for (subblocks = BLOCK_SUBBLOCKS (stmt);
3369          subblocks;
3370          subblocks = BLOCK_CHAIN (subblocks))
3371       output_block (subblocks);
3372   }
3373 }
3374
3375 /* Output Dwarf .debug information for a decl described by DECL.  */
3376
3377 static void
3378 output_decl (decl, containing_scope)
3379      register tree decl;
3380      register tree containing_scope;
3381 {
3382   switch (TREE_CODE (decl))
3383     {
3384     case ERROR_MARK:
3385       break;
3386
3387     case CONST_DECL:
3388       /* The individual enumerators of an enum type get output when we
3389          output the Dwarf representation of the relevant enum type itself.  */
3390       break;
3391
3392     case FUNCTION_DECL:
3393       /* If we are in terse mode, don't output any DIEs to represent
3394          mere external function declarations.  */
3395
3396       if (TREE_EXTERNAL (decl) && debug_info_level <= DINFO_LEVEL_TERSE)
3397         break;
3398
3399       /* Before we describe the FUNCTION_DECL itself, make sure that we
3400          have described its return type.  */
3401
3402       output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
3403
3404       /* If the following DIE will represent a function definition for a
3405          function with "extern" linkage, output a special "pubnames" DIE
3406          label just ahead of the actual DIE.  A reference to this label
3407          was already generated in the .debug_pubnames section sub-entry
3408          for this function definition.  */
3409
3410       if (TREE_PUBLIC (decl))
3411         {
3412           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3413
3414           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3415           ASM_OUTPUT_LABEL (asm_out_file, label);
3416         }
3417
3418       /* Now output a DIE to represent the function itself.  */
3419
3420       output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3421                                 ? output_global_subroutine_die
3422                                 : output_local_subroutine_die,
3423                   decl);
3424
3425       /* Now output descriptions of the arguments for this function.
3426          This gets (unnecessarily?) complex because of the fact that
3427          the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
3428          cases where there was a trailing `...' at the end of the formal
3429          parameter list.  In order to find out if there was a trailing
3430          ellipsis or not, we must instead look at the type associated
3431          with the FUNCTION_DECL.  This will be a node of type FUNCTION_TYPE.
3432          If the chain of type nodes hanging off of this FUNCTION_TYPE node
3433          ends with a void_type_node then there should *not* be an ellipsis
3434          at the end.  */
3435
3436       /* In the case where we are describing an external function, all
3437          we need to do here (and all we *can* do here) is to describe
3438          the *types* of its formal parameters.  */
3439
3440       if (TREE_EXTERNAL (decl))
3441         output_formal_types (TREE_TYPE (decl));
3442       else
3443         {
3444           register tree arg_decls = DECL_ARGUMENTS (decl);
3445
3446           /* In the case where the FUNCTION_DECL represents a C++ non-static
3447              member function, skip over the first thing on the DECL_ARGUMENTS
3448              chain.  It only represents the hidden `this pointer' parameter
3449              and the debugger should know implicitly that non-static member
3450              functions have such a thing, and should be able to figure out
3451              exactly what the type of each `this pointer' is (from the
3452              AT_member attribute of the parent TAG_subroutine DIE)  without
3453              being explicitly told.  */
3454
3455           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
3456             arg_decls = TREE_CHAIN (arg_decls);
3457
3458           {
3459             register tree last_arg;
3460
3461             last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
3462                         ? tree_last (arg_decls)
3463                         : NULL;
3464
3465             /* Generate DIEs to represent all known formal parameters, but
3466                don't do it if this looks like a varargs function.  A given
3467                function is considered to be a varargs function if (and only
3468                if) its last named argument is named `__builtin_va_alist'.  */
3469
3470             if (! last_arg
3471                 || ! DECL_NAME (last_arg)
3472                 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
3473                            "__builtin_va_alist"))
3474               {
3475                 register tree parm;
3476
3477                 /* WARNING!  Kludge zone ahead!  Here we have a special
3478                    hack for svr4 SDB compatibility.  Instead of passing the
3479                    current FUNCTION_DECL node as the second parameter (i.e.
3480                    the `containing_scope' parameter) to `output_decl' (as
3481                    we ought to) we instead pass a pointer to our own private
3482                    fake_containing_scope node.  That node is a RECORD_TYPE
3483                    node which NO OTHER TYPE may ever actually be a member of.
3484
3485                    This pointer will ultimately get passed into `output_type'
3486                    as its `containing_scope' parameter.  `Output_type' will
3487                    then perform its part in the hack... i.e. it will pend
3488                    the type of the formal parameter onto the pending_types
3489                    list.  Later on, when we are done generating the whole
3490                    sequence of formal parameter DIEs for this function
3491                    definition, we will un-pend all previously pended types
3492                    of formal parameters for this function definition.
3493
3494                    This whole kludge prevents any type DIEs from being
3495                    mixed in with the formal parameter DIEs.  That's good
3496                    because svr4 SDB believes that the list of formal
3497                    parameter DIEs for a function ends wherever the first
3498                    non-formal-parameter DIE appears.  Thus, we have to
3499                    keep the formal parameter DIEs segregated.  They must
3500                    all appear (consecutively) at the start of the list of
3501                    children for the DIE representing the function definition.
3502                    Then (and only then) may we output any additional DIEs
3503                    needed to represent the types of these formal parameters.
3504                 */
3505
3506                 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
3507                   if (TREE_CODE (parm) == PARM_DECL)
3508                     output_decl (parm, fake_containing_scope);
3509
3510                 /* Now that we have finished generating all of the DIEs to
3511                    represent the formal parameters themselves, force out
3512                    any DIEs needed to represent their types.  We do this
3513                    simply by un-pending all previously pended types which
3514                    can legitimately go into the chain of children DIEs for
3515                    the current FUNCTION_DECL.  */
3516
3517                 output_pending_types_for_scope (decl);
3518               }
3519           }
3520
3521           /* Now try to decide if we should put an ellipsis at the end. */
3522
3523           {
3524             register int has_ellipsis = TRUE;   /* default assumption */
3525             register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
3526
3527             if (fn_arg_types)
3528               {
3529                 /* This function declaration/definition was prototyped.  */
3530
3531                 /* If the list of formal argument types ends with a
3532                    void_type_node, then the formals list did *not* end
3533                    with an ellipsis.  */
3534
3535                 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
3536                   has_ellipsis = FALSE;
3537               }
3538             else
3539               {
3540                 /* This function declaration/definition was not prototyped.  */
3541
3542                 /* Note that all non-prototyped function *declarations* are
3543                    assumed to represent varargs functions (until proven
3544                    otherwise).  */
3545
3546                 if (DECL_INITIAL (decl)) /* if this is a func definition */
3547                   {
3548                     if (!arg_decls)
3549                       has_ellipsis = FALSE; /* no args == (void) */
3550                     else
3551                       {
3552                         /* For a non-prototyped function definition which
3553                            declares one or more formal parameters, if the name
3554                            of the first formal parameter is *not*
3555                            __builtin_va_alist then we must assume that this
3556                            is *not* a varargs function.  */
3557
3558                         if (DECL_NAME (arg_decls)
3559                           && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
3560                                      "__builtin_va_alist"))
3561                           has_ellipsis = FALSE;
3562                       }
3563                   }
3564               }
3565
3566             if (has_ellipsis)
3567               output_die (output_unspecified_parameters_die, decl);
3568           }
3569         }
3570
3571       /* Output Dwarf info for all of the stuff within the body of the
3572          function (if it has one - it may be just a declaration).  */
3573
3574       {
3575         register tree outer_scope = DECL_INITIAL (decl);
3576
3577         if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
3578           {
3579             /* Note that here, `outer_scope' is a pointer to the outermost
3580                BLOCK node created to represent the body of a function.
3581                This outermost BLOCK actually represents the outermost
3582                binding contour for the function, i.e. the contour in which
3583                the function's formal parameters get declared.  Just within
3584                this contour, there will be another (nested) BLOCK which
3585                represents the function's outermost block.  We don't want
3586                to generate a lexical_block DIE to represent the outermost
3587                block of a function body, because that is not really an
3588                independent scope according to ANSI C rules.  Rather, it is
3589                the same scope in which the parameters were declared and
3590                for Dwarf, we do not generate a TAG_lexical_block DIE for
3591                that scope.  We must however see to it that the LABEL_DECLs
3592                associated with `outer_scope' get DIEs generated for them.  */
3593
3594             {
3595               register tree label;
3596
3597               for (label = BLOCK_VARS (outer_scope);
3598                    label;
3599                    label = TREE_CHAIN (label))
3600                 output_decl (label, outer_scope);
3601             }
3602
3603             output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
3604
3605             /* Finally, force out any pending types which are local to the
3606                outermost block of this function definition.  These will
3607                all have a TYPE_CONTEXT which points to the FUNCTION_DECL
3608                node itself.  */
3609
3610             output_pending_types_for_scope (decl);
3611           }
3612       }
3613
3614       /* Generate a terminator for the list of stuff `owned' by this
3615          function.  */
3616
3617       end_sibling_chain ();
3618
3619       break;
3620
3621     case TYPE_DECL:
3622       /* If we are in terse mode, don't generate any DIEs to represent
3623          any actual typedefs.  Note that even when we are in terse mode,
3624          we must still output DIEs to represent those tagged types which
3625          are used (directly or indirectly) in the specification of either
3626          a return type or a formal parameter type of some function.  */
3627
3628       if (debug_info_level <= DINFO_LEVEL_TERSE)
3629         if (DECL_NAME (decl) != NULL
3630             || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
3631           return;
3632
3633       output_type (TREE_TYPE (decl), containing_scope);
3634
3635       /* Note that unlike the gcc front end (which generates a NULL named
3636          TYPE_DECL node for each complete tagged type, each array type,
3637          and each function type node created) the g++ front end generates
3638          a *named* TYPE_DECL node for each tagged type node created.
3639          Unfortunately, these g++ TYPE_DECL nodes cause us to output many
3640          superfluous and unnecessary TAG_typedef DIEs here.  When g++ is
3641          fixed to stop generating these superfluous named TYPE_DECL nodes,
3642          the superfluous TAG_typedef DIEs will likewise cease.  */
3643
3644       if (DECL_NAME (decl))
3645         /* Output a DIE to represent the typedef itself.  */
3646         output_die (output_typedef_die, decl);
3647       break;
3648
3649     case LABEL_DECL:
3650       if (debug_info_level >= DINFO_LEVEL_NORMAL)
3651         output_die (output_label_die, decl);
3652       break;
3653
3654     case VAR_DECL:
3655       /* If we are in terse mode, don't generate any DIEs to represent
3656          any variable declarations or definitions.  */
3657
3658       if (debug_info_level <= DINFO_LEVEL_TERSE)
3659         break;
3660
3661       /* Output any DIEs that are needed to specify the type of this data
3662          object.  */
3663
3664       output_type (TREE_TYPE (decl), containing_scope);
3665
3666       /* If the following DIE will represent a data object definition for a
3667          data object with "extern" linkage, output a special "pubnames" DIE
3668          label just ahead of the actual DIE.  A reference to this label
3669          was already generated in the .debug_pubnames section sub-entry
3670          for this data object definition.  */
3671
3672       if (TREE_PUBLIC (decl))
3673         {
3674           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3675
3676           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3677           ASM_OUTPUT_LABEL (asm_out_file, label);
3678         }
3679
3680       /* Now output the DIE to represent the data object itself.  */
3681
3682       output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3683                    ? output_global_variable_die : output_local_variable_die,
3684                   decl);
3685       break;
3686
3687     case FIELD_DECL:
3688       /* Ignore the nameless fields that are used to skip bits.  */
3689       if (DECL_NAME (decl) != 0)
3690         {
3691           output_type (member_declared_type (decl), containing_scope);
3692           output_die (output_member_die, decl);
3693         }
3694       break;
3695
3696     case PARM_DECL:
3697      /* Force out the type of this formal, if it was not forced out yet.
3698         Note that here we can run afowl of a bug in "classic" svr4 SDB.
3699         It should be able to grok the presence of type DIEs within a list
3700         of TAG_formal_parameter DIEs, but it doesn't.  */
3701
3702       output_type (TREE_TYPE (decl), containing_scope);
3703       output_die (output_formal_parameter_die, decl);
3704       break;
3705
3706     default:
3707       abort ();
3708     }
3709 }
3710 \f
3711 void
3712 dwarfout_file_scope_decl (decl, set_finalizing)
3713      register tree decl;
3714      register int set_finalizing;
3715 {
3716   switch (TREE_CODE (decl))
3717     {
3718     case FUNCTION_DECL:
3719
3720       /* Ignore this FUNCTION_DECL if it refers to a builtin function.  */
3721
3722       if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
3723         return;
3724
3725       /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
3726          function declaration and if the declaration was never even
3727          referenced from within this entire compilation unit.  We
3728          suppress these DIEs in order to save space in the .debug section
3729          (by eliminating entries which are probably useless).  Note that
3730          we must not suppress block-local extern declarations (whether
3731          used or not) because that would screw-up the debugger's name
3732          lookup mechanism and cause it to miss things which really ought
3733          to be in scope at a given point.  */
3734
3735       if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
3736         return;
3737
3738       if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
3739         {
3740           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3741
3742           /* Output a .debug_pubnames entry for a public function
3743              defined in this compilation unit.  */
3744
3745           fputc ('\n', asm_out_file);
3746           ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
3747           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
3748           ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3749           ASM_OUTPUT_DWARF_STRING (asm_out_file,
3750                                    IDENTIFIER_POINTER (DECL_NAME (decl)));
3751           ASM_OUTPUT_POP_SECTION (asm_out_file);
3752         }
3753
3754       break;
3755
3756     case VAR_DECL:
3757
3758       /* Ignore this VAR_DECL if it refers to a file-scope extern data
3759          object declaration and if the declaration was never even
3760          referenced from within this entire compilation unit.  We
3761          suppress these DIEs in order to save space in the .debug section
3762          (by eliminating entries which are probably useless).  Note that
3763          we must not suppress block-local extern declarations (whether
3764          used or not) because that would screw-up the debugger's name
3765          lookup mechanism and cause it to miss things which really ought
3766          to be in scope at a given point.  */
3767
3768       if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
3769         return;
3770
3771       if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
3772         {
3773           char label[MAX_ARTIFICIAL_LABEL_BYTES];
3774
3775           if (debug_info_level >= DINFO_LEVEL_NORMAL)
3776             {
3777               /* Output a .debug_pubnames entry for a public variable
3778                  defined in this compilation unit.  */
3779
3780               fputc ('\n', asm_out_file);
3781               ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
3782               sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
3783               ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3784               ASM_OUTPUT_DWARF_STRING (asm_out_file,
3785                                        IDENTIFIER_POINTER (DECL_NAME (decl)));
3786               ASM_OUTPUT_POP_SECTION (asm_out_file);
3787             }
3788
3789           if (DECL_INITIAL (decl) == NULL)
3790             {
3791               /* Output a .debug_aranges entry for a public variable
3792                  which is tenatively defined in this compilation unit.  */
3793
3794               fputc ('\n', asm_out_file);
3795               ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
3796               ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3797                                      IDENTIFIER_POINTER (DECL_NAME (decl)));
3798               ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 
3799                         (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
3800               ASM_OUTPUT_POP_SECTION (asm_out_file);
3801             }
3802         }
3803
3804       /* If we are in terse mode, don't generate any DIEs to represent
3805          any variable declarations or definitions.  */
3806
3807       if (debug_info_level <= DINFO_LEVEL_TERSE)
3808         return;
3809
3810       break;
3811
3812     case TYPE_DECL:
3813       /* Don't generate any DIEs to represent the standard built-in types.  */
3814
3815       if (DECL_SOURCE_LINE (decl) == 0)
3816         return;
3817
3818       /* If we are in terse mode, don't generate any DIEs to represent
3819          any actual typedefs.  Note that even when we are in terse mode,
3820          we must still output DIEs to represent those tagged types which
3821          are used (directly or indirectly) in the specification of either
3822          a return type or a formal parameter type of some function.  */
3823
3824       if (debug_info_level <= DINFO_LEVEL_TERSE)
3825         if (DECL_NAME (decl) != NULL
3826             || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
3827           return;
3828
3829       break;
3830
3831     default:
3832       return;
3833     }
3834
3835   fputc ('\n', asm_out_file);
3836   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3837   finalizing = set_finalizing;
3838   output_decl (decl, NULL);
3839
3840   /* NOTE:  The call above to `output_decl' may have caused one or more
3841      file-scope named types (i.e. tagged types) to be placed onto the
3842      pending_types_list.  We have to get those types off of that list
3843      at some point, and this is the perfect time to do it.  If we didn't
3844      take them off now, they might still be on the list when cc1 finally
3845      exits.  That might be OK if it weren't for the fact that when we put
3846      types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
3847      for these types, and that causes them never to be output unless
3848      `output_pending_types_for_scope' takes them off of the list and un-sets
3849      their TREE_ASM_WRITTEN flags.  */
3850
3851   output_pending_types_for_scope (NULL);
3852
3853   /* The above call should have totally emptied the pending_types_list.  */
3854
3855   assert (pending_types == 0);
3856
3857   ASM_OUTPUT_POP_SECTION (asm_out_file);
3858
3859   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
3860     current_funcdef_number++;
3861 }
3862 \f
3863 /* Output a marker (i.e. a label) for the beginning of the generated code
3864    for a lexical block.  */
3865
3866 void
3867 dwarfout_begin_block (blocknum)
3868      register unsigned blocknum;
3869 {
3870   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3871
3872   text_section ();
3873   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
3874   ASM_OUTPUT_LABEL (asm_out_file, label);
3875 }
3876
3877 /* Output a marker (i.e. a label) for the end of the generated code
3878    for a lexical block.  */
3879
3880 void
3881 dwarfout_end_block (blocknum)
3882      register unsigned blocknum;
3883 {
3884   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3885
3886   text_section ();
3887   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
3888   ASM_OUTPUT_LABEL (asm_out_file, label);
3889 }
3890
3891 /* Output a marker (i.e. a label) at a point in the assembly code which
3892    corresponds to a given source level label.  */
3893
3894 void
3895 dwarfout_label (insn)
3896      register rtx insn;
3897 {
3898   if (debug_info_level >= DINFO_LEVEL_NORMAL)
3899     {
3900       char label[MAX_ARTIFICIAL_LABEL_BYTES];
3901
3902       text_section ();
3903       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3904                                       (unsigned) INSN_UID (insn));
3905       ASM_OUTPUT_LABEL (asm_out_file, label);
3906     }
3907 }
3908
3909 /* Output a marker (i.e. a label) for the absolute end of the generated code
3910    for a function definition.  This gets called *after* the epilogue code
3911    has been generated.  */
3912
3913 void
3914 dwarfout_end_epilogue ()
3915 {
3916   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3917
3918   /* Output a label to mark the endpoint of the code generated for this
3919      function.  */
3920
3921   sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3922   ASM_OUTPUT_LABEL (asm_out_file, label);
3923 }
3924
3925 static void
3926 shuffle_filename_entry (new_zeroth)
3927      register filename_entry *new_zeroth;
3928 {
3929   filename_entry temp_entry;
3930   register filename_entry *limit_p;
3931   register filename_entry *move_p;
3932
3933   if (new_zeroth == &filename_table[0])
3934     return;
3935
3936   temp_entry = *new_zeroth;
3937
3938   /* Shift entries up in the table to make room at [0].  */
3939
3940   limit_p = &filename_table[0];
3941   for (move_p = new_zeroth; move_p > limit_p; move_p--)
3942     *move_p = *(move_p-1);
3943
3944   /* Install the found entry at [0].  */
3945
3946   filename_table[0] = temp_entry;
3947 }
3948
3949 /* Create a new (string) entry for the .debug_sfnames section.  */
3950
3951 static void
3952 generate_new_sfname_entry ()
3953 {
3954   char label[MAX_ARTIFICIAL_LABEL_BYTES];
3955
3956   fputc ('\n', asm_out_file);
3957   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
3958   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
3959   ASM_OUTPUT_LABEL (asm_out_file, label);
3960   ASM_OUTPUT_DWARF_STRING (asm_out_file,
3961                            filename_table[0].name
3962                              ? filename_table[0].name
3963                              : "");
3964   ASM_OUTPUT_POP_SECTION (asm_out_file);
3965 }
3966
3967 /* Lookup a filename (in the list of filenames that we know about here in
3968    dwarfout.c) and return its "index".  The index of each (known) filename
3969    is just a unique number which is associated with only that one filename.
3970    We need such numbers for the sake of generating labels (in the
3971    .debug_sfnames section) and references to those unique labels (in the
3972    .debug_srcinfo and .debug_macinfo sections).
3973
3974    If the filename given as an argument is not found in our current list,
3975    add it to the list and assign it the next available unique index number.
3976
3977    Whatever we do (i.e. whether we find a pre-existing filename or add a new
3978    one), we shuffle the filename found (or added) up to the zeroth entry of
3979    our list of filenames (which is always searched linearly).  We do this so
3980    as to optimize the most common case for these filename lookups within
3981    dwarfout.c.  The most common case by far is the case where we call
3982    lookup_filename to lookup the very same filename that we did a lookup
3983    on the last time we called lookup_filename.  We make sure that this
3984    common case is fast because such cases will constitute 99.9% of the
3985    lookups we ever do (in practice).
3986
3987    If we add a new filename entry to our table, we go ahead and generate
3988    the corresponding entry in the .debug_sfnames section right away.
3989    Doing so allows us to avoid tickling an assembler bug (present in some
3990    m68k assemblers) which yields assembly-time errors in cases where the
3991    difference of two label addresses is taken and where the two labels
3992    are in a section *other* than the one where the difference is being
3993    calculated, and where at least one of the two symbol references is a
3994    forward reference.  (This bug could be tickled by our .debug_srcinfo
3995    entries if we don't output their corresponding .debug_sfnames entries
3996    before them.)
3997 */
3998
3999 static unsigned
4000 lookup_filename (file_name)
4001      char *file_name;
4002 {
4003   register filename_entry *search_p;
4004   register filename_entry *limit_p = &filename_table[ft_entries];
4005
4006   for (search_p = filename_table; search_p < limit_p; search_p++)
4007     if (!strcmp (file_name, search_p->name))
4008       {
4009         /* When we get here, we have found the filename that we were
4010            looking for in the filename_table.  Now we want to make sure
4011            that it gets moved to the zero'th entry in the table (if it
4012            is not already there) so that subsequent attempts to find the
4013            same filename will find it as quickly as possible.  */
4014
4015         shuffle_filename_entry (search_p);
4016         return filename_table[0].number;
4017       }
4018
4019   /* We come here whenever we have a new filename which is not registered
4020      in the current table.  Here we add it to the table.  */
4021
4022   /* Prepare to add a new table entry by making sure there is enough space
4023      in the table to do so.  If not, expand the current table.  */
4024
4025   if (ft_entries == ft_entries_allocated)
4026     {
4027       ft_entries_allocated += FT_ENTRIES_INCREMENT;
4028       filename_table
4029         = (filename_entry *)
4030           xrealloc (filename_table,
4031                     ft_entries_allocated * sizeof (filename_entry));
4032     }
4033
4034   /* Initially, add the new entry at the end of the filename table.  */
4035
4036   filename_table[ft_entries].number = ft_entries;
4037   filename_table[ft_entries].name = xstrdup (file_name);
4038
4039   /* Shuffle the new entry into filename_table[0].  */
4040
4041   shuffle_filename_entry (&filename_table[ft_entries]);
4042
4043   if (debug_info_level >= DINFO_LEVEL_NORMAL)
4044     generate_new_sfname_entry ();
4045
4046   ft_entries++;
4047   return filename_table[0].number;
4048 }
4049
4050 static void
4051 generate_srcinfo_entry (line_entry_num, files_entry_num)
4052      unsigned line_entry_num;
4053      unsigned files_entry_num;
4054 {
4055   char label[MAX_ARTIFICIAL_LABEL_BYTES];
4056
4057   fputc ('\n', asm_out_file);
4058   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4059   sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4060   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4061   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4062   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
4063   ASM_OUTPUT_POP_SECTION (asm_out_file);
4064 }
4065
4066 void
4067 dwarfout_line (filename, line)
4068      register char *filename;
4069      register unsigned line;
4070 {
4071   if (debug_info_level >= DINFO_LEVEL_NORMAL)
4072     {
4073       char label[MAX_ARTIFICIAL_LABEL_BYTES];
4074       static unsigned last_line_entry_num = 0;
4075       static unsigned prev_file_entry_num = (unsigned) -1;
4076       register unsigned this_file_entry_num = lookup_filename (filename);
4077
4078       text_section ();
4079       sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
4080       ASM_OUTPUT_LABEL (asm_out_file, label);
4081
4082       fputc ('\n', asm_out_file);
4083       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4084
4085       if (this_file_entry_num != prev_file_entry_num)
4086         {
4087           char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
4088
4089           sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
4090           ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
4091         }
4092
4093       {
4094         register char *tail = strrchr (filename, '/');
4095
4096         if (tail != NULL)
4097           filename = tail;
4098       }
4099
4100       fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
4101                UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
4102                filename, line);
4103       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4104       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
4105       ASM_OUTPUT_POP_SECTION (asm_out_file);
4106
4107       if (this_file_entry_num != prev_file_entry_num)
4108         generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
4109       prev_file_entry_num = this_file_entry_num;
4110     }
4111 }
4112
4113 /* Generate an entry in the .debug_macinfo section.  */
4114
4115 static void
4116 generate_macinfo_entry (type_and_offset, string)
4117      register char *type_and_offset;
4118      register char *string;
4119 {
4120   fputc ('\n', asm_out_file);
4121   ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4122   fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
4123   ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
4124   ASM_OUTPUT_POP_SECTION (asm_out_file);
4125 }
4126
4127 void
4128 dwarfout_start_new_source_file (filename)
4129      register char *filename;
4130 {
4131   char label[MAX_ARTIFICIAL_LABEL_BYTES];
4132   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
4133
4134   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
4135   sprintf (type_and_offset, "0x%08x+%s-%s",
4136            ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
4137   generate_macinfo_entry (type_and_offset, "");
4138 }
4139
4140 void
4141 dwarfout_resume_previous_source_file (lineno)
4142      register unsigned lineno;
4143 {
4144   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4145
4146   sprintf (type_and_offset, "0x%08x+%u",
4147            ((unsigned) MACINFO_resume << 24), lineno);
4148   generate_macinfo_entry (type_and_offset, "");
4149 }
4150
4151 /* Called from check_newline in c-parse.y.  The `buffer' parameter
4152    contains the tail part of the directive line, i.e. the part which
4153    is past the initial whitespace, #, whitespace, directive-name,
4154    whitespace part.  */
4155
4156 void
4157 dwarfout_define (lineno, buffer)
4158      register unsigned lineno;
4159      register char *buffer;
4160 {
4161   static int initialized = 0;
4162   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4163
4164   if (!initialized)
4165     {
4166       dwarfout_start_new_source_file (primary_filename);
4167       initialized = 1;
4168     }
4169   sprintf (type_and_offset, "0x%08x+%u",
4170            ((unsigned) MACINFO_define << 24), lineno);
4171   generate_macinfo_entry (type_and_offset, buffer);
4172 }
4173
4174 /* Called from check_newline in c-parse.y.  The `buffer' parameter
4175    contains the tail part of the directive line, i.e. the part which
4176    is past the initial whitespace, #, whitespace, directive-name,
4177    whitespace part.  */
4178
4179 void
4180 dwarfout_undef (lineno, buffer)
4181      register unsigned lineno;
4182      register char *buffer;
4183 {
4184   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4185
4186   sprintf (type_and_offset, "0x%08x+%u",
4187            ((unsigned) MACINFO_undef << 24), lineno);
4188   generate_macinfo_entry (type_and_offset, buffer);
4189 }
4190
4191 /* Set up for Dwarf output at the start of compilation.  */
4192
4193 void
4194 dwarfout_init (asm_out_file, main_input_filename)
4195      register FILE *asm_out_file;
4196      register char *main_input_filename;
4197 {
4198   /* Remember the name of the primary input file.  */
4199
4200   primary_filename = main_input_filename;
4201
4202   /* Allocate the initial hunk of the pending_sibling_stack.  */
4203
4204   pending_sibling_stack
4205     = (unsigned *)
4206         xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
4207   pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
4208   pending_siblings = 1;
4209
4210   /* Allocate the initial hunk of the filename_table.  */
4211
4212   filename_table
4213     = (filename_entry *)
4214         xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
4215   ft_entries_allocated = FT_ENTRIES_INCREMENT;
4216   ft_entries = 0;
4217
4218   /* Allocate the initial hunk of the pending_types_list.  */
4219
4220   pending_types_list
4221     = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
4222   pending_types_allocated = PENDING_TYPES_INCREMENT;
4223   pending_types = 0;
4224
4225   /* Create an artificial RECORD_TYPE node which we can use in our hack
4226      to get the DIEs representing types of formal parameters to come out
4227      only *after* the DIEs for the formal parameters themselves.  */
4228
4229   fake_containing_scope = make_node (RECORD_TYPE);
4230
4231   /* Output a starting label for the .text section.  */
4232
4233   fputc ('\n', asm_out_file);
4234   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4235   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
4236   ASM_OUTPUT_POP_SECTION (asm_out_file);
4237
4238   /* Output a starting label for the .data section.  */
4239
4240   fputc ('\n', asm_out_file);
4241   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4242   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
4243   ASM_OUTPUT_POP_SECTION (asm_out_file);
4244
4245   /* Output a starting label for the .data1 section.  */
4246
4247   fputc ('\n', asm_out_file);
4248   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4249   ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
4250   ASM_OUTPUT_POP_SECTION (asm_out_file);
4251
4252   /* Output a starting label for the .rodata section.  */
4253
4254   fputc ('\n', asm_out_file);
4255   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
4256   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
4257   ASM_OUTPUT_POP_SECTION (asm_out_file);
4258
4259   /* Output a starting label for the .rodata1 section.  */
4260
4261   fputc ('\n', asm_out_file);
4262   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
4263   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
4264   ASM_OUTPUT_POP_SECTION (asm_out_file);
4265
4266   /* Output a starting label for the .bss section.  */
4267
4268   fputc ('\n', asm_out_file);
4269   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
4270   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
4271   ASM_OUTPUT_POP_SECTION (asm_out_file);
4272
4273   if (debug_info_level >= DINFO_LEVEL_NORMAL)
4274     {
4275       /* Output a starting label and an initial (compilation directory)
4276          entry for the .debug_sfnames section.  The starting label will be
4277          referenced by the initial entry in the .debug_srcinfo section.  */
4278     
4279       fputc ('\n', asm_out_file);
4280       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4281       ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
4282       {
4283         register char *pwd = getpwd ();
4284         register unsigned len = strlen (pwd);
4285         register char *dirname = (char *) xmalloc (len + 2);
4286     
4287         strcpy (dirname, pwd);
4288         strcpy (dirname + len, "/");
4289         ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
4290         free (dirname);
4291       }
4292       ASM_OUTPUT_POP_SECTION (asm_out_file);
4293     
4294       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4295         {
4296           /* Output a starting label for the .debug_macinfo section.  This
4297              label will be referenced by the AT_mac_info attribute in the
4298              TAG_compile_unit DIE.  */
4299         
4300           fputc ('\n', asm_out_file);
4301           ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4302           ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
4303           ASM_OUTPUT_POP_SECTION (asm_out_file);
4304         }
4305
4306       /* Generate the initial entry for the .line section.  */
4307     
4308       fputc ('\n', asm_out_file);
4309       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4310       ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
4311       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
4312       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4313       ASM_OUTPUT_POP_SECTION (asm_out_file);
4314     
4315       /* Generate the initial entry for the .debug_srcinfo section.  */
4316     
4317       fputc ('\n', asm_out_file);
4318       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4319       ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
4320       ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
4321       ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
4322       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4323       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
4324 #ifdef DWARF_TIMESTAMPS
4325       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
4326 #else
4327       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4328 #endif
4329       ASM_OUTPUT_POP_SECTION (asm_out_file);
4330     
4331       /* Generate the initial entry for the .debug_pubnames section.  */
4332     
4333       fputc ('\n', asm_out_file);
4334       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4335       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4336       ASM_OUTPUT_POP_SECTION (asm_out_file);
4337     
4338       /* Generate the initial entry for the .debug_aranges section.  */
4339     
4340       fputc ('\n', asm_out_file);
4341       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4342       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4343       ASM_OUTPUT_POP_SECTION (asm_out_file);
4344     }
4345
4346   /* Setup first DIE number == 1.  */
4347   NEXT_DIE_NUM = next_unused_dienum++;
4348
4349   /* Generate the initial DIE for the .debug section.  Note that the
4350      (string) value given in the AT_name attribute of the TAG_compile_unit
4351      DIE will (typically) be a relative pathname and that this pathname
4352      should be taken as being relative to the directory from which the
4353      compiler was invoked when the given (base) source file was compiled.  */
4354
4355   fputc ('\n', asm_out_file);
4356   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4357   ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
4358   output_die (output_compile_unit_die, main_input_filename);
4359   ASM_OUTPUT_POP_SECTION (asm_out_file);
4360
4361   fputc ('\n', asm_out_file);
4362 }
4363
4364 /* Output stuff that dwarf requires at the end of every file.  */
4365
4366 void
4367 dwarfout_finish ()
4368 {
4369   char label[MAX_ARTIFICIAL_LABEL_BYTES];
4370
4371   fputc ('\n', asm_out_file);
4372   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4373
4374   /* Mark the end of the chain of siblings which represent all file-scope
4375      declarations in this compilation unit.  */
4376
4377   /* The (null) DIE which represents the terminator for the (sibling linked)
4378      list of file-scope items is *special*.  Normally, we would just call
4379      end_sibling_chain at this point in order to output a word with the
4380      value `4' and that word would act as the terminator for the list of
4381      DIEs describing file-scope items.  Unfortunately, if we were to simply
4382      do that, the label that would follow this DIE in the .debug section
4383      (i.e. `..D2') would *not* be properly aligned (as it must be on some
4384      machines) to a 4 byte boundary.
4385
4386      In order to force the label `..D2' to get aligned to a 4 byte boundary,
4387      the trick used is to insert extra (otherwise useless) padding bytes
4388      into the (null) DIE that we know must preceed the ..D2 label in the
4389      .debug section.  The amount of padding required can be anywhere between
4390      0 and 3 bytes.  The length word at the start of this DIE (i.e. the one
4391      with the padding) would normally contain the value 4, but now it will
4392      also have to include the padding bytes, so it will instead have some
4393      value in the range 4..7.
4394
4395      Fortunately, the rules of Dwarf say that any DIE whose length word
4396      contains *any* value less than 8 should be treated as a null DIE, so
4397      this trick works out nicely.  Clever, eh?  Don't give me any credit
4398      (or blame).  I didn't think of this scheme.  I just conformed to it.
4399   */
4400
4401   output_die (output_padded_null_die, (void *)0);
4402   dienum_pop ();
4403
4404   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
4405   ASM_OUTPUT_LABEL (asm_out_file, label);       /* should be ..D2 */
4406   ASM_OUTPUT_POP_SECTION (asm_out_file);
4407
4408   /* Output a terminator label for the .text section.  */
4409
4410   fputc ('\n', asm_out_file);
4411   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4412   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
4413   ASM_OUTPUT_POP_SECTION (asm_out_file);
4414
4415   /* Output a terminator label for the .data section.  */
4416
4417   fputc ('\n', asm_out_file);
4418   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4419   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
4420   ASM_OUTPUT_POP_SECTION (asm_out_file);
4421
4422   /* Output a terminator label for the .data1 section.  */
4423
4424   fputc ('\n', asm_out_file);
4425   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4426   ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
4427   ASM_OUTPUT_POP_SECTION (asm_out_file);
4428
4429   /* Output a terminator label for the .rodata section.  */
4430
4431   fputc ('\n', asm_out_file);
4432   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
4433   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
4434   ASM_OUTPUT_POP_SECTION (asm_out_file);
4435
4436   /* Output a terminator label for the .rodata1 section.  */
4437
4438   fputc ('\n', asm_out_file);
4439   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
4440   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
4441   ASM_OUTPUT_POP_SECTION (asm_out_file);
4442
4443   /* Output a terminator label for the .bss section.  */
4444
4445   fputc ('\n', asm_out_file);
4446   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
4447   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
4448   ASM_OUTPUT_POP_SECTION (asm_out_file);
4449
4450   if (debug_info_level >= DINFO_LEVEL_NORMAL)
4451     {
4452       /* Output a terminating entry for the .line section.  */
4453     
4454       fputc ('\n', asm_out_file);
4455       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4456       ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
4457       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4458       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4459       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4460       ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
4461       ASM_OUTPUT_POP_SECTION (asm_out_file);
4462     
4463       /* Output a terminating entry for the .debug_srcinfo section.  */
4464     
4465       fputc ('\n', asm_out_file);
4466       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4467       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
4468                                LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
4469       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4470       ASM_OUTPUT_POP_SECTION (asm_out_file);
4471
4472       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4473         {
4474           /* Output terminating entries for the .debug_macinfo section.  */
4475         
4476           dwarfout_resume_previous_source_file (0);
4477
4478           fputc ('\n', asm_out_file);
4479           ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4480           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4481           ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
4482           ASM_OUTPUT_POP_SECTION (asm_out_file);
4483         }
4484     
4485       /* Generate the terminating entry for the .debug_pubnames section.  */
4486     
4487       fputc ('\n', asm_out_file);
4488       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4489       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4490       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
4491       ASM_OUTPUT_POP_SECTION (asm_out_file);
4492     
4493       /* Generate the terminating entries for the .debug_aranges section.
4494
4495          Note that we want to do this only *after* we have output the end
4496          labels (for the various program sections) which we are going to
4497          refer to here.  This allows us to work around a bug in the m68k
4498          svr4 assembler.  That assembler gives bogus assembly-time errors
4499          if (within any given section) you try to take the difference of
4500          two relocatable symbols, both of which are located within some
4501          other section, and if one (or both?) of the symbols involved is
4502          being forward-referenced.  By generating the .debug_aranges
4503          entries at this late point in the assembly output, we skirt the
4504          issue simply by avoiding forward-references.
4505       */
4506     
4507       fputc ('\n', asm_out_file);
4508       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4509
4510       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4511       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4512
4513       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
4514       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
4515
4516       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
4517       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
4518                                              DATA1_BEGIN_LABEL);
4519
4520       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
4521       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
4522                                              RODATA_BEGIN_LABEL);
4523
4524       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
4525       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
4526                                              RODATA1_BEGIN_LABEL);
4527
4528       ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
4529       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
4530
4531       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4532       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4533
4534       ASM_OUTPUT_POP_SECTION (asm_out_file);
4535     }
4536 }
4537
4538 #endif /* DWARF_DEBUGGING_INFO */