OSDN Git Service

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