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