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