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