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