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