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