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