]>
Commit | Line | Data |
---|---|---|
340ccaab TW |
1 | /* This file contains code written by Ron Guilmette (rfg@ncd.com) for |
2 | Network Computing Devices, August, September, October, November 1990. | |
3 | ||
4 | Output Dwarf format symbol table information from the GNU C compiler. | |
5 | Copyright (C) 1992 Free Software Foundation, Inc. | |
6 | ||
7 | This file is part of GNU CC. | |
8 | ||
9 | GNU CC is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2, or (at your option) | |
12 | any later version. | |
13 | ||
14 | GNU CC is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GNU CC; see the file COPYING. If not, write to | |
21 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
22 | ||
23 | #include "config.h" | |
24 | ||
25 | #ifdef DWARF_DEBUGGING_INFO | |
26 | #include <stdio.h> | |
27 | #include "dwarf.h" | |
28 | #include "tree.h" | |
29 | #include "flags.h" | |
30 | #include "rtl.h" | |
31 | #include "insn-config.h" | |
32 | #include "reload.h" | |
33 | #include "output.h" | |
9a631e8e | 34 | #include "defaults.h" |
340ccaab TW |
35 | |
36 | /* #define NDEBUG 1 */ | |
37 | #include <assert.h> | |
38 | ||
39 | #if defined(DWARF_TIMESTAMPS) | |
40 | #if defined(POSIX) | |
41 | #include <time.h> | |
42 | #else /* !defined(POSIX) */ | |
43 | #include <sys/types.h> | |
44 | #if defined(__STDC__) | |
45 | extern time_t time (time_t *); | |
46 | #else /* !defined(__STDC__) */ | |
47 | extern time_t time (); | |
48 | #endif /* !defined(__STDC__) */ | |
49 | #endif /* !defined(POSIX) */ | |
50 | #endif /* defined(DWARF_TIMESTAMPS) */ | |
51 | ||
52 | #if defined(USG) || defined(POSIX) | |
53 | #include <string.h> | |
54 | #else | |
55 | #include <strings.h> | |
56 | #define strrchr rindex | |
340ccaab TW |
57 | #endif |
58 | ||
9a631e8e | 59 | extern char *getpwd (); |
2e494f70 | 60 | |
340ccaab TW |
61 | /* IMPORTANT NOTE: Please see the file README.DWARF for important details |
62 | regarding the GNU implementation of Dwarf. */ | |
63 | ||
64 | /* NOTE: In the comments in this file, many references are made to | |
65 | so called "Debugging Information Entries". For the sake of brevity, | |
66 | this term is abbreviated to `DIE' throughout the remainder of this | |
67 | file. */ | |
68 | ||
69 | /* Note that the implementation of C++ support herein is (as yet) unfinished. | |
70 | If you want to try to complete it, more power to you. */ | |
71 | ||
72 | #if defined(__GNUC__) && (NDEBUG == 1) | |
73 | #define inline static inline | |
74 | #else | |
75 | #define inline static | |
76 | #endif | |
77 | ||
78 | /* How to start an assembler comment. */ | |
79 | #ifndef ASM_COMMENT_START | |
80 | #define ASM_COMMENT_START ";#" | |
81 | #endif | |
82 | ||
83 | /* Define a macro which, when given a pointer to some BLOCK node, returns | |
84 | a pointer to the FUNCTION_DECL node from which the given BLOCK node | |
85 | was instantiated (as an inline expansion). This macro needs to be | |
86 | defined properly in tree.h, however for the moment, we just fake it. */ | |
87 | ||
88 | #define BLOCK_INLINE_FUNCTION(block) 0 | |
89 | ||
90 | /* Define a macro which returns non-zero for any tagged type which is | |
91 | used (directly or indirectly) in the specification of either some | |
92 | function's return type or some formal parameter of some function. | |
93 | We use this macro when we are operating in "terse" mode to help us | |
94 | know what tagged types have to be represented in Dwarf (even in | |
95 | terse mode) and which ones don't. | |
96 | ||
97 | A flag bit with this meaning really should be a part of the normal | |
98 | GCC ..._TYPE nodes, but at the moment, there is no such bit defined | |
99 | for these nodes. For now, we have to just fake it. It it safe for | |
100 | us to simply return zero for all complete tagged types (which will | |
101 | get forced out anyway if they were used in the specification of some | |
102 | formal or return type) and non-zero for all incomplete tagged types. | |
103 | */ | |
104 | ||
105 | #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) | |
106 | ||
340ccaab TW |
107 | extern int flag_traditional; |
108 | extern char *version_string; | |
109 | extern char *language_string; | |
110 | ||
111 | /* Maximum size (in bytes) of an artificially generated label. */ | |
112 | ||
113 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
114 | \f | |
115 | /* Make sure we know the sizes of the various types dwarf can describe. | |
116 | These are only defaults. If the sizes are different for your target, | |
117 | you should override these values by defining the appropriate symbols | |
118 | in your tm.h file. */ | |
119 | ||
120 | #ifndef CHAR_TYPE_SIZE | |
121 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
122 | #endif | |
123 | ||
124 | #ifndef SHORT_TYPE_SIZE | |
125 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) | |
126 | #endif | |
127 | ||
128 | #ifndef INT_TYPE_SIZE | |
129 | #define INT_TYPE_SIZE BITS_PER_WORD | |
130 | #endif | |
131 | ||
132 | #ifndef LONG_TYPE_SIZE | |
133 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
134 | #endif | |
135 | ||
136 | #ifndef LONG_LONG_TYPE_SIZE | |
137 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
138 | #endif | |
139 | ||
140 | #ifndef WCHAR_TYPE_SIZE | |
141 | #define WCHAR_TYPE_SIZE INT_TYPE_SIZE | |
142 | #endif | |
143 | ||
144 | #ifndef WCHAR_UNSIGNED | |
145 | #define WCHAR_UNSIGNED 0 | |
146 | #endif | |
147 | ||
148 | #ifndef FLOAT_TYPE_SIZE | |
149 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
150 | #endif | |
151 | ||
152 | #ifndef DOUBLE_TYPE_SIZE | |
153 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
154 | #endif | |
155 | ||
156 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
157 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
158 | #endif | |
159 | \f | |
160 | /* Structure to keep track of source filenames. */ | |
161 | ||
162 | struct filename_entry { | |
163 | unsigned number; | |
164 | char * name; | |
165 | }; | |
166 | ||
167 | typedef struct filename_entry filename_entry; | |
168 | ||
169 | /* Pointer to an array of elements, each one having the structure above. */ | |
170 | ||
171 | static filename_entry *filename_table; | |
172 | ||
173 | /* Total number of entries in the table (i.e. array) pointed to by | |
174 | `filename_table'. This is the *total* and includes both used and | |
175 | unused slots. */ | |
176 | ||
177 | static unsigned ft_entries_allocated; | |
178 | ||
179 | /* Number of entries in the filename_table which are actually in use. */ | |
180 | ||
181 | static unsigned ft_entries; | |
182 | ||
183 | /* Size (in elements) of increments by which we may expand the filename | |
184 | table. Actually, a single hunk of space of this size should be enough | |
185 | for most typical programs. */ | |
186 | ||
187 | #define FT_ENTRIES_INCREMENT 64 | |
188 | ||
189 | /* Local pointer to the name of the main input file. Initialized in | |
190 | dwarfout_init. */ | |
191 | ||
192 | static char *primary_filename; | |
193 | ||
194 | /* Pointer to the most recent filename for which we produced some line info. */ | |
195 | ||
196 | static char *last_filename; | |
197 | ||
198 | /* For Dwarf output, we must assign lexical-blocks id numbers | |
199 | in the order in which their beginnings are encountered. | |
200 | We output Dwarf debugging info that refers to the beginnings | |
201 | and ends of the ranges of code for each lexical block with | |
202 | assembler labels ..Bn and ..Bn.e, where n is the block number. | |
203 | The labels themselves are generated in final.c, which assigns | |
204 | numbers to the blocks in the same way. */ | |
205 | ||
206 | static unsigned next_block_number = 2; | |
207 | ||
208 | /* Counter to generate unique names for DIEs. */ | |
209 | ||
210 | static unsigned next_unused_dienum = 1; | |
211 | ||
212 | /* Number of the DIE which is currently being generated. */ | |
213 | ||
214 | static unsigned current_dienum; | |
215 | ||
216 | /* Number to use for the special "pubname" label on the next DIE which | |
217 | represents a function or data object defined in this compilation | |
218 | unit which has "extern" linkage. */ | |
219 | ||
220 | static next_pubname_number = 0; | |
221 | ||
222 | #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1] | |
223 | ||
224 | /* Pointer to a dynamically allocated list of pre-reserved and still | |
225 | pending sibling DIE numbers. Note that this list will grow as needed. */ | |
226 | ||
227 | static unsigned *pending_sibling_stack; | |
228 | ||
229 | /* Counter to keep track of the number of pre-reserved and still pending | |
230 | sibling DIE numbers. */ | |
231 | ||
232 | static unsigned pending_siblings; | |
233 | ||
234 | /* The currently allocated size of the above list (expressed in number of | |
235 | list elements). */ | |
236 | ||
237 | static unsigned pending_siblings_allocated; | |
238 | ||
239 | /* Size (in elements) of increments by which we may expand the pending | |
240 | sibling stack. Actually, a single hunk of space of this size should | |
241 | be enough for most typical programs. */ | |
242 | ||
243 | #define PENDING_SIBLINGS_INCREMENT 64 | |
244 | ||
245 | /* Non-zero if we are performing our file-scope finalization pass and if | |
246 | we should force out Dwarf decsriptions of any and all file-scope | |
247 | tagged types which are still incomplete types. */ | |
248 | ||
249 | static int finalizing = 0; | |
250 | ||
251 | /* A pointer to the base of a list of pending types which we haven't | |
252 | generated DIEs for yet, but which we will have to come back to | |
253 | later on. */ | |
254 | ||
255 | static tree *pending_types_list; | |
256 | ||
257 | /* Number of elements currently allocated for the pending_types_list. */ | |
258 | ||
259 | static unsigned pending_types_allocated; | |
260 | ||
261 | /* Number of elements of pending_types_list currently in use. */ | |
262 | ||
263 | static unsigned pending_types; | |
264 | ||
265 | /* Size (in elements) of increments by which we may expand the pending | |
266 | types list. Actually, a single hunk of space of this size should | |
267 | be enough for most typical programs. */ | |
268 | ||
269 | #define PENDING_TYPES_INCREMENT 64 | |
270 | ||
271 | /* Pointer to an artifical RECORD_TYPE which we create in dwarfout_init. | |
272 | This is used in a hack to help us get the DIEs describing types of | |
273 | formal parameters to come *after* all of the DIEs describing the formal | |
274 | parameters themselves. That's necessary in order to be compatible | |
275 | with what the brain-dammaged svr4 SDB debugger requires. */ | |
276 | ||
277 | static tree fake_containing_scope; | |
278 | ||
279 | /* The number of the current function definition that we are generating | |
280 | debugging information for. These numbers range from 1 up to the maximum | |
281 | number of function definitions contained within the current compilation | |
282 | unit. These numbers are used to create unique labels for various things | |
283 | contained within various function definitions. */ | |
284 | ||
285 | static unsigned current_funcdef_number = 1; | |
286 | ||
287 | /* Forward declarations for functions defined in this file. */ | |
288 | ||
289 | static void output_type (); | |
290 | static void type_attribute (); | |
291 | static void output_decls_for_scope (); | |
292 | static void output_decl (); | |
293 | static unsigned lookup_filename (); | |
294 | \f | |
295 | /* Definitions of defaults for assembler-dependent names of various | |
296 | pseudo-ops and section names. | |
297 | ||
298 | Theses may be overridden in your tm.h file (if necessary) for your | |
299 | particular assembler. The default values provided here correspond to | |
300 | what is expected by "standard" AT&T System V.4 assemblers. */ | |
301 | ||
302 | #ifndef FILE_ASM_OP | |
2e494f70 | 303 | #define FILE_ASM_OP ".file" |
340ccaab TW |
304 | #endif |
305 | #ifndef VERSION_ASM_OP | |
2e494f70 | 306 | #define VERSION_ASM_OP ".version" |
340ccaab | 307 | #endif |
340ccaab | 308 | #ifndef UNALIGNED_SHORT_ASM_OP |
2e494f70 | 309 | #define UNALIGNED_SHORT_ASM_OP ".2byte" |
340ccaab TW |
310 | #endif |
311 | #ifndef UNALIGNED_INT_ASM_OP | |
2e494f70 | 312 | #define UNALIGNED_INT_ASM_OP ".4byte" |
340ccaab | 313 | #endif |
9a631e8e RS |
314 | #ifndef ASM_BYTE_OP |
315 | #define ASM_BYTE_OP ".byte" | |
316 | #endif | |
340ccaab | 317 | #ifndef DEF_ASM_OP |
2e494f70 | 318 | #define DEF_ASM_OP ".set" |
340ccaab | 319 | #endif |
85595d1a RS |
320 | |
321 | /* Pseudo-ops for pushing the current section onto the section stack (and | |
322 | simultaneously changing to a new section) and for poping back to the | |
323 | section we were in immediately before this one. Note that most svr4 | |
324 | assemblers only maintain a one level stack... you can push all the | |
325 | sections you want, but you can only pop out one level. (The sparc | |
326 | svr4 assembler might be an exception to this general rule.) That's | |
327 | OK because we only use at most one level of the section stack herein. */ | |
328 | ||
329 | #ifndef PUSHSECTION_ASM_OP | |
9a631e8e | 330 | #define PUSHSECTION_ASM_OP ".section" |
85595d1a RS |
331 | #endif |
332 | #ifndef POPSECTION_ASM_OP | |
9a631e8e | 333 | #define POPSECTION_ASM_OP ".previous" |
85595d1a RS |
334 | #endif |
335 | ||
336 | /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below) | |
337 | to print the PUSHSECTION_ASM_OP and the section name. The default here | |
338 | works for almost all svr4 assemblers, except for the sparc, where the | |
339 | section name must be enclosed in double quotes. (See sparcv4.h.) */ | |
340 | ||
341 | #ifndef PUSHSECTION_FORMAT | |
342 | #define PUSHSECTION_FORMAT "%s\t%s\n" | |
343 | #endif | |
344 | ||
345 | #ifndef DEBUG_SECTION | |
346 | #define DEBUG_SECTION ".debug" | |
347 | #endif | |
348 | #ifndef LINE_SECTION | |
349 | #define LINE_SECTION ".line" | |
350 | #endif | |
351 | #ifndef SFNAMES_SECTION | |
352 | #define SFNAMES_SECTION ".debug_sfnames" | |
353 | #endif | |
354 | #ifndef SRCINFO_SECTION | |
355 | #define SRCINFO_SECTION ".debug_srcinfo" | |
356 | #endif | |
357 | #ifndef MACINFO_SECTION | |
358 | #define MACINFO_SECTION ".debug_macinfo" | |
359 | #endif | |
360 | #ifndef PUBNAMES_SECTION | |
361 | #define PUBNAMES_SECTION ".debug_pubnames" | |
362 | #endif | |
363 | #ifndef ARANGES_SECTION | |
364 | #define ARANGES_SECTION ".debug_aranges" | |
365 | #endif | |
366 | #ifndef TEXT_SECTION | |
367 | #define TEXT_SECTION ".text" | |
368 | #endif | |
369 | #ifndef DATA_SECTION | |
370 | #define DATA_SECTION ".data" | |
371 | #endif | |
372 | #ifndef DATA1_SECTION | |
373 | #define DATA1_SECTION ".data1" | |
374 | #endif | |
375 | #ifndef RODATA_SECTION | |
376 | #define RODATA_SECTION ".rodata" | |
377 | #endif | |
378 | #ifndef RODATA1_SECTION | |
379 | #define RODATA1_SECTION ".rodata1" | |
380 | #endif | |
381 | #ifndef BSS_SECTION | |
382 | #define BSS_SECTION ".bss" | |
383 | #endif | |
340ccaab TW |
384 | \f |
385 | /* Definitions of defaults for formats and names of various special | |
386 | (artificial) labels which may be generated within this file (when | |
387 | the -g options is used and DWARF_DEBUGGING_INFO is in effect. | |
388 | ||
389 | If necessary, these may be overridden from within your tm.h file, | |
9a631e8e RS |
390 | but typically, you should never need to override these. |
391 | ||
392 | These labels have been hacked (temporarily) so that they all begin with | |
393 | a `.L' sequence so as to appease the sparc/svr4 assmebler (which needs | |
394 | to see .L at the start of a label in order to prevent that label from | |
395 | going into the linker symbol table). When I get time, I'll have to | |
396 | fix this the right way so that we use ASM_GENERATE_INTERNAL_LABEL and | |
397 | ASM_OUTPUT_INTERNAL_LABEL throughout dwarfout.c, but that will require | |
398 | a rather massive set of changes. For the moment, the following definitions | |
399 | out to produce the right results for all svr4 and svr3 assemblers. -- rfg | |
400 | */ | |
340ccaab TW |
401 | |
402 | #ifndef TEXT_BEGIN_LABEL | |
9a631e8e | 403 | #define TEXT_BEGIN_LABEL ".L_text_b" |
340ccaab TW |
404 | #endif |
405 | #ifndef TEXT_END_LABEL | |
9a631e8e | 406 | #define TEXT_END_LABEL ".L_text_e" |
340ccaab TW |
407 | #endif |
408 | ||
409 | #ifndef DATA_BEGIN_LABEL | |
9a631e8e | 410 | #define DATA_BEGIN_LABEL ".L_data_b" |
340ccaab TW |
411 | #endif |
412 | #ifndef DATA_END_LABEL | |
9a631e8e | 413 | #define DATA_END_LABEL ".L_data_e" |
340ccaab TW |
414 | #endif |
415 | ||
416 | #ifndef DATA1_BEGIN_LABEL | |
9a631e8e | 417 | #define DATA1_BEGIN_LABEL ".L_data1_b" |
340ccaab TW |
418 | #endif |
419 | #ifndef DATA1_END_LABEL | |
9a631e8e | 420 | #define DATA1_END_LABEL ".L_data1_e" |
340ccaab TW |
421 | #endif |
422 | ||
423 | #ifndef RODATA_BEGIN_LABEL | |
9a631e8e | 424 | #define RODATA_BEGIN_LABEL ".L_rodata_b" |
340ccaab TW |
425 | #endif |
426 | #ifndef RODATA_END_LABEL | |
9a631e8e | 427 | #define RODATA_END_LABEL ".L_rodata_e" |
340ccaab TW |
428 | #endif |
429 | ||
430 | #ifndef RODATA1_BEGIN_LABEL | |
9a631e8e | 431 | #define RODATA1_BEGIN_LABEL ".L_rodata1_b" |
340ccaab TW |
432 | #endif |
433 | #ifndef RODATA1_END_LABEL | |
9a631e8e | 434 | #define RODATA1_END_LABEL ".L_rodata1_e" |
340ccaab TW |
435 | #endif |
436 | ||
437 | #ifndef BSS_BEGIN_LABEL | |
9a631e8e | 438 | #define BSS_BEGIN_LABEL ".L_bss_b" |
340ccaab TW |
439 | #endif |
440 | #ifndef BSS_END_LABEL | |
9a631e8e | 441 | #define BSS_END_LABEL ".L_bss_e" |
340ccaab TW |
442 | #endif |
443 | ||
444 | #ifndef LINE_BEGIN_LABEL | |
9a631e8e | 445 | #define LINE_BEGIN_LABEL ".L_line_b" |
340ccaab TW |
446 | #endif |
447 | #ifndef LINE_LAST_ENTRY_LABEL | |
9a631e8e | 448 | #define LINE_LAST_ENTRY_LABEL ".L_line_last" |
340ccaab TW |
449 | #endif |
450 | #ifndef LINE_END_LABEL | |
9a631e8e | 451 | #define LINE_END_LABEL ".L_line_e" |
340ccaab TW |
452 | #endif |
453 | ||
454 | #ifndef DEBUG_BEGIN_LABEL | |
9a631e8e | 455 | #define DEBUG_BEGIN_LABEL ".L_debug_b" |
340ccaab TW |
456 | #endif |
457 | #ifndef SFNAMES_BEGIN_LABEL | |
9a631e8e | 458 | #define SFNAMES_BEGIN_LABEL ".L_sfnames_b" |
340ccaab TW |
459 | #endif |
460 | #ifndef SRCINFO_BEGIN_LABEL | |
9a631e8e | 461 | #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b" |
340ccaab TW |
462 | #endif |
463 | #ifndef MACINFO_BEGIN_LABEL | |
9a631e8e | 464 | #define MACINFO_BEGIN_LABEL ".L_macinfo_b" |
340ccaab TW |
465 | #endif |
466 | ||
467 | #ifndef DIE_BEGIN_LABEL_FMT | |
9a631e8e | 468 | #define DIE_BEGIN_LABEL_FMT ".L_D%u" |
340ccaab TW |
469 | #endif |
470 | #ifndef DIE_END_LABEL_FMT | |
9a631e8e | 471 | #define DIE_END_LABEL_FMT ".L_D%u_e" |
340ccaab TW |
472 | #endif |
473 | #ifndef PUB_DIE_LABEL_FMT | |
9a631e8e | 474 | #define PUB_DIE_LABEL_FMT ".L_P%u" |
340ccaab TW |
475 | #endif |
476 | #ifndef INSN_LABEL_FMT | |
9a631e8e | 477 | #define INSN_LABEL_FMT ".L_I%u_%u" |
340ccaab TW |
478 | #endif |
479 | #ifndef BLOCK_BEGIN_LABEL_FMT | |
9a631e8e | 480 | #define BLOCK_BEGIN_LABEL_FMT ".L_B%u" |
340ccaab TW |
481 | #endif |
482 | #ifndef BLOCK_END_LABEL_FMT | |
9a631e8e | 483 | #define BLOCK_END_LABEL_FMT ".L_B%u_e" |
340ccaab TW |
484 | #endif |
485 | #ifndef SS_BEGIN_LABEL_FMT | |
9a631e8e | 486 | #define SS_BEGIN_LABEL_FMT ".L_s%u" |
340ccaab TW |
487 | #endif |
488 | #ifndef SS_END_LABEL_FMT | |
9a631e8e | 489 | #define SS_END_LABEL_FMT ".L_s%u_e" |
340ccaab TW |
490 | #endif |
491 | #ifndef EE_BEGIN_LABEL_FMT | |
9a631e8e | 492 | #define EE_BEGIN_LABEL_FMT ".L_e%u" |
340ccaab TW |
493 | #endif |
494 | #ifndef EE_END_LABEL_FMT | |
9a631e8e | 495 | #define EE_END_LABEL_FMT ".L_e%u_e" |
340ccaab TW |
496 | #endif |
497 | #ifndef MT_BEGIN_LABEL_FMT | |
9a631e8e | 498 | #define MT_BEGIN_LABEL_FMT ".L_t%u" |
340ccaab TW |
499 | #endif |
500 | #ifndef MT_END_LABEL_FMT | |
9a631e8e | 501 | #define MT_END_LABEL_FMT ".L_t%u_e" |
340ccaab TW |
502 | #endif |
503 | #ifndef LOC_BEGIN_LABEL_FMT | |
9a631e8e | 504 | #define LOC_BEGIN_LABEL_FMT ".L_l%u" |
340ccaab TW |
505 | #endif |
506 | #ifndef LOC_END_LABEL_FMT | |
9a631e8e | 507 | #define LOC_END_LABEL_FMT ".L_l%u_e" |
340ccaab TW |
508 | #endif |
509 | #ifndef BOUND_BEGIN_LABEL_FMT | |
9a631e8e | 510 | #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c" |
340ccaab TW |
511 | #endif |
512 | #ifndef BOUND_END_LABEL_FMT | |
9a631e8e | 513 | #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e" |
340ccaab TW |
514 | #endif |
515 | #ifndef DERIV_BEGIN_LABEL_FMT | |
9a631e8e | 516 | #define DERIV_BEGIN_LABEL_FMT ".L_d%u" |
340ccaab TW |
517 | #endif |
518 | #ifndef DERIV_END_LABEL_FMT | |
9a631e8e | 519 | #define DERIV_END_LABEL_FMT ".L_d%u_e" |
340ccaab TW |
520 | #endif |
521 | #ifndef SL_BEGIN_LABEL_FMT | |
9a631e8e | 522 | #define SL_BEGIN_LABEL_FMT ".L_sl%u" |
340ccaab TW |
523 | #endif |
524 | #ifndef SL_END_LABEL_FMT | |
9a631e8e | 525 | #define SL_END_LABEL_FMT ".L_sl%u_e" |
340ccaab TW |
526 | #endif |
527 | #ifndef FUNC_END_LABEL_FMT | |
9a631e8e | 528 | #define FUNC_END_LABEL_FMT ".L_f%u_e" |
340ccaab TW |
529 | #endif |
530 | #ifndef TYPE_NAME_FMT | |
9a631e8e | 531 | #define TYPE_NAME_FMT ".L_T%u" |
340ccaab TW |
532 | #endif |
533 | #ifndef LINE_CODE_LABEL_FMT | |
9a631e8e | 534 | #define LINE_CODE_LABEL_FMT ".L_LC%u" |
340ccaab TW |
535 | #endif |
536 | #ifndef SFNAMES_ENTRY_LABEL_FMT | |
9a631e8e | 537 | #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u" |
340ccaab TW |
538 | #endif |
539 | #ifndef LINE_ENTRY_LABEL_FMT | |
9a631e8e | 540 | #define LINE_ENTRY_LABEL_FMT ".L_LE%u" |
340ccaab TW |
541 | #endif |
542 | \f | |
543 | /* Definitions of defaults for various types of primitive assembly language | |
544 | output operations. | |
545 | ||
546 | If necessary, these may be overridden from within your tm.h file, | |
85595d1a RS |
547 | but typically, you shouldn't need to override these. Two known |
548 | exceptions are the ASM_OUTPUT_PUSH_SECTION and ASM_OUTPUT_POP_SECTION | |
549 | definitions, which need to be somewhat special for a sparc running svr4. | |
550 | */ | |
551 | ||
552 | #ifndef ASM_OUTPUT_PUSH_SECTION | |
553 | #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \ | |
554 | fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION) | |
555 | #endif | |
556 | ||
557 | #ifndef ASM_OUTPUT_POP_SECTION | |
558 | #define ASM_OUTPUT_POP_SECTION(FILE) \ | |
9a631e8e | 559 | fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP) |
85595d1a | 560 | #endif |
340ccaab TW |
561 | |
562 | #ifndef ASM_OUTPUT_SOURCE_FILENAME | |
563 | #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \ | |
2e494f70 | 564 | fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME) |
340ccaab TW |
565 | #endif |
566 | ||
567 | #ifndef ASM_OUTPUT_DEF | |
568 | #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ | |
2e494f70 | 569 | do { fprintf ((FILE), "\t%s\t", DEF_ASM_OP); \ |
340ccaab TW |
570 | assemble_name (FILE, LABEL1); \ |
571 | fprintf (FILE, ","); \ | |
572 | assemble_name (FILE, LABEL2); \ | |
573 | fprintf (FILE, "\n"); \ | |
574 | } while (0) | |
575 | #endif | |
576 | ||
340ccaab TW |
577 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
578 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
2e494f70 | 579 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ |
340ccaab TW |
580 | assemble_name (FILE, LABEL1); \ |
581 | fprintf (FILE, "-"); \ | |
582 | assemble_name (FILE, LABEL2); \ | |
583 | fprintf (FILE, "\n"); \ | |
584 | } while (0) | |
585 | #endif | |
586 | ||
587 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
588 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
2e494f70 | 589 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ |
340ccaab TW |
590 | assemble_name (FILE, LABEL1); \ |
591 | fprintf (FILE, "-"); \ | |
592 | assemble_name (FILE, LABEL2); \ | |
593 | fprintf (FILE, "\n"); \ | |
594 | } while (0) | |
595 | #endif | |
596 | ||
597 | #ifndef ASM_OUTPUT_DWARF_TAG | |
598 | #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \ | |
9a631e8e RS |
599 | do { \ |
600 | fprintf ((FILE), "\t%s\t0x%x", \ | |
601 | UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \ | |
602 | if (flag_verbose_asm) \ | |
603 | fprintf ((FILE), "\t%s %s", \ | |
604 | ASM_COMMENT_START, dwarf_tag_name (TAG)); \ | |
605 | fputc ('\n', (FILE)); \ | |
606 | } while (0) | |
340ccaab TW |
607 | #endif |
608 | ||
609 | #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE | |
9a631e8e RS |
610 | #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \ |
611 | do { \ | |
612 | fprintf ((FILE), "\t%s\t0x%x", \ | |
613 | UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \ | |
614 | if (flag_verbose_asm) \ | |
615 | fprintf ((FILE), "\t%s %s", \ | |
616 | ASM_COMMENT_START, dwarf_attr_name (ATTR)); \ | |
617 | fputc ('\n', (FILE)); \ | |
618 | } while (0) | |
340ccaab TW |
619 | #endif |
620 | ||
621 | #ifndef ASM_OUTPUT_DWARF_STACK_OP | |
622 | #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \ | |
9a631e8e RS |
623 | do { \ |
624 | fprintf ((FILE), "%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \ | |
625 | if (flag_verbose_asm) \ | |
626 | fprintf ((FILE), "\t%s %s", \ | |
627 | ASM_COMMENT_START, dwarf_stack_op_name (OP)); \ | |
628 | fputc ('\n', (FILE)); \ | |
629 | } while (0) | |
340ccaab TW |
630 | #endif |
631 | ||
632 | #ifndef ASM_OUTPUT_DWARF_FUND_TYPE | |
633 | #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \ | |
9a631e8e RS |
634 | do { \ |
635 | fprintf ((FILE), "\t%s\t0x%x", \ | |
636 | UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \ | |
637 | if (flag_verbose_asm) \ | |
638 | fprintf ((FILE), "\t%s %s", \ | |
639 | ASM_COMMENT_START, dwarf_fund_type_name (FT)); \ | |
640 | fputc ('\n', (FILE)); \ | |
641 | } while (0) | |
340ccaab TW |
642 | #endif |
643 | ||
644 | #ifndef ASM_OUTPUT_DWARF_FMT_BYTE | |
645 | #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \ | |
9a631e8e RS |
646 | do { \ |
647 | fprintf ((FILE), "%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \ | |
648 | if (flag_verbose_asm) \ | |
649 | fprintf ((FILE), "\t%s %s", \ | |
650 | ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \ | |
651 | fputc ('\n', (FILE)); \ | |
652 | } while (0) | |
340ccaab TW |
653 | #endif |
654 | ||
655 | #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER | |
656 | #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \ | |
9a631e8e RS |
657 | do { \ |
658 | fprintf ((FILE), "%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \ | |
659 | if (flag_verbose_asm) \ | |
660 | fprintf ((FILE), "\t%s %s", \ | |
661 | ASM_COMMENT_START, dwarf_typemod_name (MOD)); \ | |
662 | fputc ('\n', (FILE)); \ | |
663 | } while (0) | |
340ccaab TW |
664 | #endif |
665 | \f | |
666 | #ifndef ASM_OUTPUT_DWARF_ADDR | |
667 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
2e494f70 | 668 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ |
340ccaab TW |
669 | assemble_name (FILE, LABEL); \ |
670 | fprintf (FILE, "\n"); \ | |
671 | } while (0) | |
672 | #endif | |
673 | ||
674 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
675 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ | |
2e494f70 | 676 | fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ |
340ccaab TW |
677 | output_addr_const ((FILE), (RTX)); \ |
678 | fputc ('\n', (FILE)) | |
679 | #endif | |
680 | ||
681 | #ifndef ASM_OUTPUT_DWARF_REF | |
682 | #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \ | |
2e494f70 | 683 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ |
340ccaab TW |
684 | assemble_name (FILE, LABEL); \ |
685 | fprintf (FILE, "\n"); \ | |
686 | } while (0) | |
687 | #endif | |
688 | ||
689 | #ifndef ASM_OUTPUT_DWARF_DATA1 | |
690 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
691 | fprintf ((FILE), "%s\t0x%x\n", ASM_BYTE_OP, VALUE) | |
692 | #endif | |
693 | ||
694 | #ifndef ASM_OUTPUT_DWARF_DATA2 | |
695 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
2e494f70 | 696 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) |
340ccaab TW |
697 | #endif |
698 | ||
699 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
700 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
2e494f70 | 701 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) |
340ccaab TW |
702 | #endif |
703 | ||
704 | #ifndef ASM_OUTPUT_DWARF_DATA8 | |
705 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
706 | do { \ | |
707 | if (WORDS_BIG_ENDIAN) \ | |
708 | { \ | |
2e494f70 RS |
709 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ |
710 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
340ccaab TW |
711 | } \ |
712 | else \ | |
713 | { \ | |
2e494f70 RS |
714 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ |
715 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
340ccaab TW |
716 | } \ |
717 | } while (0) | |
718 | #endif | |
719 | ||
720 | #ifndef ASM_OUTPUT_DWARF_STRING | |
721 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
722 | ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1) | |
723 | #endif | |
724 | \f | |
725 | /************************ general utility functions **************************/ | |
726 | ||
727 | inline char * | |
728 | xstrdup (s) | |
729 | register char *s; | |
730 | { | |
731 | register char *p = (char *) xmalloc (strlen (s) + 1); | |
732 | ||
733 | strcpy (p, s); | |
734 | return p; | |
735 | } | |
736 | ||
737 | static char * | |
9a631e8e | 738 | dwarf_tag_name (tag) |
340ccaab TW |
739 | register unsigned tag; |
740 | { | |
741 | switch (tag) | |
742 | { | |
9a631e8e RS |
743 | case TAG_padding: return "TAG_padding"; |
744 | case TAG_array_type: return "TAG_array_type"; | |
745 | case TAG_class_type: return "TAG_class_type"; | |
746 | case TAG_entry_point: return "TAG_entry_point"; | |
747 | case TAG_enumeration_type: return "TAG_enumeration_type"; | |
748 | case TAG_formal_parameter: return "TAG_formal_parameter"; | |
749 | case TAG_global_subroutine: return "TAG_global_subroutine"; | |
750 | case TAG_global_variable: return "TAG_global_variable"; | |
751 | case TAG_label: return "TAG_label"; | |
752 | case TAG_lexical_block: return "TAG_lexical_block"; | |
753 | case TAG_local_variable: return "TAG_local_variable"; | |
754 | case TAG_member: return "TAG_member"; | |
755 | case TAG_pointer_type: return "TAG_pointer_type"; | |
756 | case TAG_reference_type: return "TAG_reference_type"; | |
757 | case TAG_compile_unit: return "TAG_compile_unit"; | |
758 | case TAG_string_type: return "TAG_string_type"; | |
759 | case TAG_structure_type: return "TAG_structure_type"; | |
760 | case TAG_subroutine: return "TAG_subroutine"; | |
761 | case TAG_subroutine_type: return "TAG_subroutine_type"; | |
762 | case TAG_typedef: return "TAG_typedef"; | |
763 | case TAG_union_type: return "TAG_union_type"; | |
340ccaab | 764 | case TAG_unspecified_parameters: return "TAG_unspecified_parameters"; |
9a631e8e RS |
765 | case TAG_variant: return "TAG_variant"; |
766 | case TAG_common_block: return "TAG_common_block"; | |
767 | case TAG_common_inclusion: return "TAG_common_inclusion"; | |
768 | case TAG_inheritance: return "TAG_inheritance"; | |
769 | case TAG_inlined_subroutine: return "TAG_inlined_subroutine"; | |
770 | case TAG_module: return "TAG_module"; | |
771 | case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type"; | |
772 | case TAG_set_type: return "TAG_set_type"; | |
773 | case TAG_subrange_type: return "TAG_subrange_type"; | |
774 | case TAG_with_stmt: return "TAG_with_stmt"; | |
775 | ||
776 | /* GNU extensions. */ | |
777 | ||
778 | case TAG_format_label: return "TAG_format_label"; | |
779 | case TAG_namelist: return "TAG_namelist"; | |
780 | case TAG_function_template: return "TAG_function_template"; | |
781 | case TAG_class_template: return "TAG_class_template"; | |
782 | ||
783 | default: return "<unknown tag>"; | |
340ccaab TW |
784 | } |
785 | } | |
786 | ||
787 | static char * | |
9a631e8e | 788 | dwarf_attr_name (attr) |
340ccaab TW |
789 | register unsigned attr; |
790 | { | |
791 | switch (attr) | |
792 | { | |
9a631e8e RS |
793 | case AT_sibling: return "AT_sibling"; |
794 | case AT_location: return "AT_location"; | |
795 | case AT_name: return "AT_name"; | |
796 | case AT_fund_type: return "AT_fund_type"; | |
797 | case AT_mod_fund_type: return "AT_mod_fund_type"; | |
798 | case AT_user_def_type: return "AT_user_def_type"; | |
799 | case AT_mod_u_d_type: return "AT_mod_u_d_type"; | |
800 | case AT_ordering: return "AT_ordering"; | |
801 | case AT_subscr_data: return "AT_subscr_data"; | |
802 | case AT_byte_size: return "AT_byte_size"; | |
803 | case AT_bit_offset: return "AT_bit_offset"; | |
804 | case AT_bit_size: return "AT_bit_size"; | |
805 | case AT_element_list: return "AT_element_list"; | |
806 | case AT_stmt_list: return "AT_stmt_list"; | |
807 | case AT_low_pc: return "AT_low_pc"; | |
808 | case AT_high_pc: return "AT_high_pc"; | |
809 | case AT_language: return "AT_language"; | |
810 | case AT_member: return "AT_member"; | |
811 | case AT_discr: return "AT_discr"; | |
812 | case AT_discr_value: return "AT_discr_value"; | |
813 | case AT_string_length: return "AT_string_length"; | |
814 | case AT_common_reference: return "AT_common_reference"; | |
815 | case AT_comp_dir: return "AT_comp_dir"; | |
816 | case AT_const_value_string: return "AT_const_value_string"; | |
817 | case AT_const_value_data2: return "AT_const_value_data2"; | |
818 | case AT_const_value_data4: return "AT_const_value_data4"; | |
819 | case AT_const_value_data8: return "AT_const_value_data8"; | |
820 | case AT_const_value_block2: return "AT_const_value_block2"; | |
340ccaab | 821 | case AT_const_value_block4: return "AT_const_value_block4"; |
9a631e8e RS |
822 | case AT_containing_type: return "AT_containing_type"; |
823 | case AT_default_value_addr: return "AT_default_value_addr"; | |
824 | case AT_default_value_data2: return "AT_default_value_data2"; | |
825 | case AT_default_value_data4: return "AT_default_value_data4"; | |
826 | case AT_default_value_data8: return "AT_default_value_data8"; | |
827 | case AT_default_value_string: return "AT_default_value_string"; | |
828 | case AT_friends: return "AT_friends"; | |
829 | case AT_inline: return "AT_inline"; | |
830 | case AT_is_optional: return "AT_is_optional"; | |
831 | case AT_lower_bound_ref: return "AT_lower_bound_ref"; | |
832 | case AT_lower_bound_data2: return "AT_lower_bound_data2"; | |
833 | case AT_lower_bound_data4: return "AT_lower_bound_data4"; | |
834 | case AT_lower_bound_data8: return "AT_lower_bound_data8"; | |
835 | case AT_private: return "AT_private"; | |
836 | case AT_producer: return "AT_producer"; | |
837 | case AT_program: return "AT_program"; | |
838 | case AT_protected: return "AT_protected"; | |
839 | case AT_prototyped: return "AT_prototyped"; | |
840 | case AT_public: return "AT_public"; | |
841 | case AT_pure_virtual: return "AT_pure_virtual"; | |
842 | case AT_return_addr: return "AT_return_addr"; | |
843 | case AT_specification: return "AT_specification"; | |
844 | case AT_start_scope: return "AT_start_scope"; | |
845 | case AT_stride_size: return "AT_stride_size"; | |
846 | case AT_upper_bound_ref: return "AT_upper_bound_ref"; | |
847 | case AT_upper_bound_data2: return "AT_upper_bound_data2"; | |
848 | case AT_upper_bound_data4: return "AT_upper_bound_data4"; | |
849 | case AT_upper_bound_data8: return "AT_upper_bound_data8"; | |
850 | case AT_virtual: return "AT_virtual"; | |
851 | ||
852 | /* GNU extensions */ | |
853 | ||
854 | case AT_sf_names: return "AT_sf_names"; | |
855 | case AT_src_info: return "AT_src_info"; | |
856 | case AT_mac_info: return "AT_mac_info"; | |
857 | case AT_src_coords: return "AT_src_coords"; | |
858 | ||
859 | default: return "<unknown attribute>"; | |
340ccaab TW |
860 | } |
861 | } | |
862 | ||
863 | static char * | |
9a631e8e | 864 | dwarf_stack_op_name (op) |
340ccaab TW |
865 | register unsigned op; |
866 | { | |
867 | switch (op) | |
868 | { | |
869 | case OP_REG: return "OP_REG"; | |
870 | case OP_BASEREG: return "OP_BASEREG"; | |
871 | case OP_ADDR: return "OP_ADDR"; | |
872 | case OP_CONST: return "OP_CONST"; | |
873 | case OP_DEREF2: return "OP_DEREF2"; | |
874 | case OP_DEREF4: return "OP_DEREF4"; | |
875 | case OP_ADD: return "OP_ADD"; | |
876 | default: return "<unknown stack operator>"; | |
877 | } | |
878 | } | |
879 | ||
880 | static char * | |
9a631e8e | 881 | dwarf_typemod_name (mod) |
340ccaab TW |
882 | register unsigned mod; |
883 | { | |
884 | switch (mod) | |
885 | { | |
886 | case MOD_pointer_to: return "MOD_pointer_to"; | |
887 | case MOD_reference_to: return "MOD_reference_to"; | |
888 | case MOD_const: return "MOD_const"; | |
889 | case MOD_volatile: return "MOD_volatile"; | |
890 | default: return "<unknown modifier>"; | |
891 | } | |
892 | } | |
893 | ||
894 | static char * | |
9a631e8e | 895 | dwarf_fmt_byte_name (fmt) |
340ccaab TW |
896 | register unsigned fmt; |
897 | { | |
898 | switch (fmt) | |
899 | { | |
900 | case FMT_FT_C_C: return "FMT_FT_C_C"; | |
901 | case FMT_FT_C_X: return "FMT_FT_C_X"; | |
902 | case FMT_FT_X_C: return "FMT_FT_X_C"; | |
903 | case FMT_FT_X_X: return "FMT_FT_X_X"; | |
904 | case FMT_UT_C_C: return "FMT_UT_C_C"; | |
905 | case FMT_UT_C_X: return "FMT_UT_C_X"; | |
906 | case FMT_UT_X_C: return "FMT_UT_X_C"; | |
907 | case FMT_UT_X_X: return "FMT_UT_X_X"; | |
908 | case FMT_ET: return "FMT_ET"; | |
909 | default: return "<unknown array bound format byte>"; | |
910 | } | |
911 | } | |
912 | static char * | |
9a631e8e | 913 | dwarf_fund_type_name (ft) |
340ccaab TW |
914 | register unsigned ft; |
915 | { | |
916 | switch (ft) | |
917 | { | |
918 | case FT_char: return "FT_char"; | |
919 | case FT_signed_char: return "FT_signed_char"; | |
920 | case FT_unsigned_char: return "FT_unsigned_char"; | |
921 | case FT_short: return "FT_short"; | |
922 | case FT_signed_short: return "FT_signed_short"; | |
923 | case FT_unsigned_short: return "FT_unsigned_short"; | |
924 | case FT_integer: return "FT_integer"; | |
925 | case FT_signed_integer: return "FT_signed_integer"; | |
926 | case FT_unsigned_integer: return "FT_unsigned_integer"; | |
927 | case FT_long: return "FT_long"; | |
928 | case FT_signed_long: return "FT_signed_long"; | |
929 | case FT_unsigned_long: return "FT_unsigned_long"; | |
930 | case FT_pointer: return "FT_pointer"; | |
931 | case FT_float: return "FT_float"; | |
932 | case FT_dbl_prec_float: return "FT_dbl_prec_float"; | |
933 | case FT_ext_prec_float: return "FT_ext_prec_float"; | |
934 | case FT_complex: return "FT_complex"; | |
935 | case FT_dbl_prec_complex: return "FT_dbl_prec_complex"; | |
936 | case FT_void: return "FT_void"; | |
937 | case FT_boolean: return "FT_boolean"; | |
9a631e8e RS |
938 | case FT_ext_prec_complex: return "FT_ext_prec_complex"; |
939 | case FT_label: return "FT_label"; | |
940 | ||
941 | /* GNU extensions. */ | |
942 | ||
340ccaab TW |
943 | case FT_long_long: return "FT_long_long"; |
944 | case FT_signed_long_long: return "FT_signed_long_long"; | |
945 | case FT_unsigned_long_long: return "FT_unsigned_long_long"; | |
9a631e8e RS |
946 | |
947 | case FT_int8: return "FT_int8"; | |
948 | case FT_signed_int8: return "FT_signed_int8"; | |
949 | case FT_unsigned_int8: return "FT_unsigned_int8"; | |
950 | case FT_int16: return "FT_int16"; | |
951 | case FT_signed_int16: return "FT_signed_int16"; | |
952 | case FT_unsigned_int16: return "FT_unsigned_int16"; | |
953 | case FT_int32: return "FT_int32"; | |
954 | case FT_signed_int32: return "FT_signed_int32"; | |
955 | case FT_unsigned_int32: return "FT_unsigned_int32"; | |
956 | case FT_int64: return "FT_int64"; | |
957 | case FT_signed_int64: return "FT_signed_int64"; | |
958 | case FT_unsigned_int64: return "FT_signed_int64"; | |
959 | ||
960 | case FT_real32: return "FT_real32"; | |
961 | case FT_real64: return "FT_real64"; | |
962 | case FT_real96: return "FT_real96"; | |
963 | case FT_real128: return "FT_real128"; | |
964 | ||
340ccaab TW |
965 | default: return "<unknown fundamental type>"; |
966 | } | |
967 | } | |
968 | \f | |
969 | /**************** utility functions for attribute functions ******************/ | |
970 | ||
971 | /* Given a pointer to a tree node for some type, return a Dwarf fundamental | |
972 | type code for the given type. | |
973 | ||
974 | This routine must only be called for GCC type nodes that correspond to | |
975 | Dwarf fundamental types. | |
976 | ||
977 | The current Dwarf draft specification calls for Dwarf fundamental types | |
978 | to accurately reflect the fact that a given type was either a "plain" | |
979 | integral type or an explicitly "signed" integral type. Unfortuantely, | |
980 | we can't always do this, because GCC may already have thrown away the | |
981 | information about the precise way in which the type was originally | |
982 | specified, as in: | |
983 | ||
984 | typedef signed int field_type; | |
985 | ||
986 | struct s { field_type f; }; | |
987 | ||
988 | Since we may be stuck here without enought information to do exactly | |
989 | what is called for in the Dwarf draft specification, we do the best | |
990 | that we can under the circumstances and always use the "plain" integral | |
991 | fundamental type codes for int, short, and long types. That's probably | |
992 | good enough. The additional accuracy called for in the current DWARF | |
993 | draft specification is probably never even useful in practice. */ | |
994 | ||
995 | static int | |
996 | fundamental_type_code (type) | |
997 | register tree type; | |
998 | { | |
999 | if (TREE_CODE (type) == ERROR_MARK) | |
1000 | return 0; | |
1001 | ||
1002 | switch (TREE_CODE (type)) | |
1003 | { | |
1004 | case ERROR_MARK: | |
1005 | return FT_void; | |
1006 | ||
1007 | case VOID_TYPE: | |
1008 | return FT_void; | |
1009 | ||
1010 | case INTEGER_TYPE: | |
1011 | /* Carefully distinguish all the standard types of C, | |
1012 | without messing up if the language is not C. | |
1013 | Note that we check only for the names that contain spaces; | |
1014 | other names might occur by coincidence in other languages. */ | |
1015 | if (TYPE_NAME (type) != 0 | |
1016 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1017 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
1018 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
1019 | { | |
1020 | char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); | |
1021 | ||
1022 | if (!strcmp (name, "unsigned char")) | |
1023 | return FT_unsigned_char; | |
1024 | if (!strcmp (name, "signed char")) | |
1025 | return FT_signed_char; | |
1026 | if (!strcmp (name, "unsigned int")) | |
1027 | return FT_unsigned_integer; | |
1028 | if (!strcmp (name, "short int")) | |
1029 | return FT_short; | |
1030 | if (!strcmp (name, "short unsigned int")) | |
1031 | return FT_unsigned_short; | |
1032 | if (!strcmp (name, "long int")) | |
1033 | return FT_long; | |
1034 | if (!strcmp (name, "long unsigned int")) | |
1035 | return FT_unsigned_long; | |
1036 | if (!strcmp (name, "long long int")) | |
1037 | return FT_long_long; /* Not grok'ed by svr4 SDB */ | |
1038 | if (!strcmp (name, "long long unsigned int")) | |
1039 | return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */ | |
1040 | } | |
1041 | ||
1042 | /* Most integer types will be sorted out above, however, for the | |
1043 | sake of special `array index' integer types, the following code | |
1044 | is also provided. */ | |
1045 | ||
1046 | if (TYPE_PRECISION (type) == INT_TYPE_SIZE) | |
1047 | return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer); | |
1048 | ||
1049 | if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) | |
1050 | return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long); | |
1051 | ||
1052 | if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) | |
1053 | return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long); | |
1054 | ||
1055 | if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) | |
1056 | return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short); | |
1057 | ||
1058 | if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) | |
1059 | return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char); | |
1060 | ||
1061 | abort (); | |
1062 | ||
1063 | case REAL_TYPE: | |
1064 | /* Carefully distinguish all the standard types of C, | |
1065 | without messing up if the language is not C. */ | |
1066 | if (TYPE_NAME (type) != 0 | |
1067 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1068 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
1069 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
1070 | { | |
1071 | char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); | |
1072 | ||
1073 | /* Note that here we can run afowl of a serious bug in "classic" | |
1074 | svr4 SDB debuggers. They don't seem to understand the | |
1075 | FT_ext_prec_float type (even though they should). */ | |
1076 | ||
1077 | if (!strcmp (name, "long double")) | |
1078 | return FT_ext_prec_float; | |
1079 | } | |
1080 | ||
1081 | if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) | |
1082 | return FT_dbl_prec_float; | |
1083 | if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) | |
1084 | return FT_float; | |
1085 | ||
1086 | /* Note that here we can run afowl of a serious bug in "classic" | |
1087 | svr4 SDB debuggers. They don't seem to understand the | |
1088 | FT_ext_prec_float type (even though they should). */ | |
1089 | ||
1090 | if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) | |
1091 | return FT_ext_prec_float; | |
1092 | abort (); | |
1093 | ||
1094 | case COMPLEX_TYPE: | |
1095 | return FT_complex; /* GNU FORTRAN COMPLEX type. */ | |
1096 | ||
1097 | case CHAR_TYPE: | |
1098 | return FT_char; /* GNU Pascal CHAR type. Not used in C. */ | |
1099 | ||
1100 | case BOOLEAN_TYPE: | |
1101 | return FT_boolean; /* GNU FORTRAN BOOLEAN type. */ | |
1102 | ||
1103 | default: | |
1104 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ | |
1105 | } | |
1106 | return 0; | |
1107 | } | |
1108 | \f | |
1109 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
1110 | the Dwarf "root" type for the given input type. The Dwarf "root" type | |
1111 | of a given type is generally the same as the given type, except that if | |
1112 | the given type is a pointer or reference type, then the root type of | |
1113 | the given type is the root type of the "basis" type for the pointer or | |
1114 | reference type. (This definition of the "root" type is recursive.) | |
1115 | Also, the root type of a `const' qualified type or a `volatile' | |
1116 | qualified type is the root type of the given type without the | |
1117 | qualifiers. */ | |
1118 | ||
1119 | static tree | |
1120 | root_type (type) | |
1121 | register tree type; | |
1122 | { | |
1123 | if (TREE_CODE (type) == ERROR_MARK) | |
1124 | return error_mark_node; | |
1125 | ||
1126 | switch (TREE_CODE (type)) | |
1127 | { | |
1128 | case ERROR_MARK: | |
1129 | return error_mark_node; | |
1130 | ||
1131 | case POINTER_TYPE: | |
1132 | case REFERENCE_TYPE: | |
1133 | return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type))); | |
1134 | ||
1135 | default: | |
1136 | return TYPE_MAIN_VARIANT (type); | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence | |
1141 | of zero or more Dwarf "type-modifier" bytes applicable to the type. */ | |
1142 | ||
1143 | static void | |
1144 | write_modifier_bytes (type, decl_const, decl_volatile) | |
1145 | register tree type; | |
1146 | register int decl_const; | |
1147 | register int decl_volatile; | |
1148 | { | |
1149 | if (TREE_CODE (type) == ERROR_MARK) | |
1150 | return; | |
1151 | ||
1152 | if (TYPE_READONLY (type) || decl_const) | |
1153 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const); | |
1154 | if (TYPE_VOLATILE (type) || decl_volatile) | |
1155 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile); | |
1156 | switch (TREE_CODE (type)) | |
1157 | { | |
1158 | case POINTER_TYPE: | |
1159 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to); | |
1160 | write_modifier_bytes (TREE_TYPE (type), 0, 0); | |
1161 | return; | |
1162 | ||
1163 | case REFERENCE_TYPE: | |
1164 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to); | |
1165 | write_modifier_bytes (TREE_TYPE (type), 0, 0); | |
1166 | return; | |
1167 | ||
1168 | case ERROR_MARK: | |
1169 | default: | |
1170 | return; | |
1171 | } | |
1172 | } | |
1173 | \f | |
1174 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
1175 | given input type is a Dwarf "fundamental" type. Otherwise return zero. */ | |
1176 | ||
1177 | inline int | |
1178 | type_is_fundamental (type) | |
1179 | register tree type; | |
1180 | { | |
1181 | switch (TREE_CODE (type)) | |
1182 | { | |
1183 | case ERROR_MARK: | |
1184 | case VOID_TYPE: | |
1185 | case INTEGER_TYPE: | |
1186 | case REAL_TYPE: | |
1187 | case COMPLEX_TYPE: | |
1188 | case BOOLEAN_TYPE: | |
1189 | case CHAR_TYPE: | |
1190 | return 1; | |
1191 | ||
1192 | case SET_TYPE: | |
1193 | case ARRAY_TYPE: | |
1194 | case RECORD_TYPE: | |
1195 | case UNION_TYPE: | |
1196 | case ENUMERAL_TYPE: | |
1197 | case FUNCTION_TYPE: | |
1198 | case METHOD_TYPE: | |
1199 | case POINTER_TYPE: | |
1200 | case REFERENCE_TYPE: | |
1201 | case STRING_TYPE: | |
1202 | case FILE_TYPE: | |
1203 | case OFFSET_TYPE: | |
1204 | case LANG_TYPE: | |
1205 | return 0; | |
1206 | ||
1207 | default: | |
1208 | abort (); | |
1209 | } | |
1210 | return 0; | |
1211 | } | |
1212 | ||
1213 | /* Given a pointer to some ..._TYPE tree node, generate an assembly language | |
1214 | equate directive which will associate an easily remembered symbolic name | |
1215 | with the current DIE. | |
1216 | ||
1217 | The name used is an artificial label generated from the TYPE_UID number | |
1218 | associated with the given type node. The name it gets equated to is the | |
1219 | symbolic label that we (previously) output at the start of the DIE that | |
1220 | we are currently generating. | |
1221 | ||
1222 | Calling this function while generating some "type related" form of DIE | |
1223 | makes it easy to later refer to the DIE which represents the given type | |
1224 | simply by re-generating the alternative name from the ..._TYPE node's | |
1225 | UID number. */ | |
1226 | ||
1227 | inline void | |
1228 | equate_type_number_to_die_number (type) | |
1229 | register tree type; | |
1230 | { | |
1231 | char type_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1232 | char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1233 | ||
1234 | /* We are generating a DIE to represent the main variant of this type | |
1235 | (i.e the type without any const or volatile qualifiers) so in order | |
1236 | to get the equate to come out right, we need to get the main variant | |
1237 | itself here. */ | |
1238 | ||
1239 | type = TYPE_MAIN_VARIANT (type); | |
1240 | ||
1241 | sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type)); | |
1242 | sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
1243 | ASM_OUTPUT_DEF (asm_out_file, type_label, die_label); | |
1244 | } | |
1245 | ||
1246 | /* The following routine is a nice and simple transducer. It converts the | |
1247 | RTL for a variable or parameter (resident in memory) into an equivalent | |
1248 | Dwarf representation of a mechanism for getting the address of that same | |
1249 | variable onto the top of a hypothetical "address evaluation" stack. | |
1250 | ||
1251 | When creating memory location descriptors, we are effectively trans- | |
1252 | forming the RTL for a memory-resident object into its Dwarf postfix | |
1253 | expression equivalent. This routine just recursively descends an | |
1254 | RTL tree, turning it into Dwarf postfix code as it goes. */ | |
1255 | ||
1256 | static void | |
1257 | output_mem_loc_descriptor (rtl) | |
1258 | register rtx rtl; | |
1259 | { | |
1260 | /* Note that for a dynamically sized array, the location we will | |
1261 | generate a description of here will be the lowest numbered location | |
1262 | which is actually within the array. That's *not* necessarily the | |
1263 | same as the zeroth element of the array. */ | |
1264 | ||
1265 | switch (GET_CODE (rtl)) | |
1266 | { | |
1267 | case SUBREG: | |
1268 | ||
1269 | /* The case of a subreg may arise when we have a local (register) | |
1270 | variable or a formal (register) parameter which doesn't quite | |
1271 | fill up an entire register. For now, just assume that it is | |
1272 | legitimate to make the Dwarf info refer to the whole register | |
1273 | which contains the given subreg. */ | |
1274 | ||
1275 | rtl = XEXP (rtl, 0); | |
1276 | /* Drop thru. */ | |
1277 | ||
1278 | case REG: | |
1279 | ||
1280 | /* Whenever a register number forms a part of the description of | |
1281 | the method for calculating the (dynamic) address of a memory | |
1282 | resident object, Dwarf rules require the register number to | |
1283 | be referred to as a "base register". This distinction is not | |
1284 | based in any way upon what category of register the hardware | |
1285 | believes the given register belongs to. This is strictly | |
1286 | Dwarf terminology we're dealing with here. */ | |
1287 | ||
1288 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG); | |
1289 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
1290 | DBX_REGISTER_NUMBER (REGNO (rtl))); | |
1291 | break; | |
1292 | ||
1293 | case MEM: | |
1294 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
1295 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4); | |
1296 | break; | |
1297 | ||
1298 | case CONST: | |
1299 | case SYMBOL_REF: | |
1300 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR); | |
1301 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); | |
1302 | break; | |
1303 | ||
1304 | case PLUS: | |
1305 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
1306 | output_mem_loc_descriptor (XEXP (rtl, 1)); | |
1307 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); | |
1308 | break; | |
1309 | ||
1310 | case CONST_INT: | |
1311 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); | |
1312 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl)); | |
1313 | break; | |
1314 | ||
1315 | default: | |
1316 | abort (); | |
1317 | } | |
1318 | } | |
1319 | ||
1320 | /* Output a proper Dwarf location descriptor for a variable or parameter | |
1321 | which is either allocated in a register or in a memory location. For | |
1322 | a register, we just generate an OP_REG and the register number. For a | |
1323 | memory location we provide a Dwarf postfix expression describing how to | |
1324 | generate the (dynamic) address of the object onto the address stack. */ | |
1325 | ||
1326 | static void | |
1327 | output_loc_descriptor (rtl) | |
1328 | register rtx rtl; | |
1329 | { | |
1330 | switch (GET_CODE (rtl)) | |
1331 | { | |
1332 | case SUBREG: | |
1333 | ||
1334 | /* The case of a subreg may arise when we have a local (register) | |
1335 | variable or a formal (register) parameter which doesn't quite | |
1336 | fill up an entire register. For now, just assume that it is | |
1337 | legitimate to make the Dwarf info refer to the whole register | |
1338 | which contains the given subreg. */ | |
1339 | ||
1340 | rtl = XEXP (rtl, 0); | |
1341 | /* Drop thru. */ | |
1342 | ||
1343 | case REG: | |
1344 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG); | |
1345 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
1346 | DBX_REGISTER_NUMBER (REGNO (rtl))); | |
1347 | break; | |
1348 | ||
1349 | case MEM: | |
1350 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
1351 | break; | |
1352 | ||
1353 | default: | |
1354 | abort (); /* Should never happen */ | |
1355 | } | |
1356 | } | |
1357 | ||
1358 | /* Given a tree node describing an array bound (either lower or upper) | |
1359 | output a representation for that bound. */ | |
1360 | ||
1361 | static void | |
1362 | output_bound_representation (bound, dim_num, u_or_l) | |
1363 | register tree bound; | |
1364 | register unsigned dim_num; /* For multi-dimensional arrays. */ | |
1365 | register char u_or_l; /* Designates upper or lower bound. */ | |
1366 | { | |
1367 | switch (TREE_CODE (bound)) | |
1368 | { | |
1369 | ||
1370 | case ERROR_MARK: | |
1371 | return; | |
1372 | ||
1373 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
1374 | ||
1375 | case INTEGER_CST: | |
1376 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
1377 | (unsigned) TREE_INT_CST_LOW (bound)); | |
1378 | break; | |
1379 | ||
1380 | /* Dynamic bounds may be represented by NOP_EXPR nodes containing | |
1381 | SAVE_EXPR nodes. */ | |
1382 | ||
1383 | case NOP_EXPR: | |
1384 | bound = TREE_OPERAND (bound, 0); | |
1385 | /* ... fall thru... */ | |
1386 | ||
1387 | case SAVE_EXPR: | |
1388 | { | |
1389 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1390 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1391 | ||
1392 | sprintf (begin_label, BOUND_BEGIN_LABEL_FMT, | |
1393 | current_dienum, dim_num, u_or_l); | |
1394 | ||
1395 | sprintf (end_label, BOUND_END_LABEL_FMT, | |
1396 | current_dienum, dim_num, u_or_l); | |
1397 | ||
1398 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1399 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1400 | ||
1401 | /* If we are working on a bound for a dynamic dimension in C, | |
1402 | the dynamic dimension in question had better have a static | |
1403 | (zero) lower bound and a dynamic *upper* bound. */ | |
1404 | ||
1405 | if (u_or_l != 'u') | |
1406 | abort (); | |
1407 | ||
1408 | /* If optimization is turned on, the SAVE_EXPRs that describe | |
1409 | how to access the upper bound values are essentially bogus. | |
1410 | They only describe (at best) how to get at these values at | |
1411 | the points in the generated code right after they have just | |
1412 | been computed. Worse yet, in the typical case, the upper | |
1413 | bound values will not even *be* computed in the optimized | |
1414 | code, so these SAVE_EXPRs are entirely bogus. | |
1415 | ||
1416 | In order to compensate for this fact, we check here to see | |
1417 | if optimization is enabled, and if so, we effectively create | |
1418 | an empty location description for the (unknown and unknowable) | |
1419 | upper bound. | |
1420 | ||
1421 | This should not cause too much trouble for existing (stupid?) | |
1422 | debuggers because they have to deal with empty upper bounds | |
1423 | location descriptions anyway in order to be able to deal with | |
1424 | incomplete array types. | |
1425 | ||
1426 | Of course an intelligent debugger (GDB?) should be able to | |
1427 | comprehend that a missing upper bound specification in a | |
1428 | array type used for a storage class `auto' local array variable | |
1429 | indicates that the upper bound is both unknown (at compile- | |
1430 | time) and unknowable (at run-time) due to optimization. | |
1431 | */ | |
1432 | ||
1433 | if (! optimize) | |
1434 | output_loc_descriptor | |
1435 | (eliminate_regs (SAVE_EXPR_RTL (bound), 0, 0)); | |
1436 | ||
1437 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1438 | } | |
1439 | break; | |
1440 | ||
1441 | default: | |
1442 | abort (); | |
1443 | } | |
1444 | } | |
1445 | ||
1446 | /* Recursive function to output a sequence of value/name pairs for | |
1447 | enumeration constants in reversed order. This is called from | |
1448 | enumeration_type_die. */ | |
1449 | ||
1450 | static void | |
1451 | output_enumeral_list (link) | |
1452 | register tree link; | |
1453 | { | |
1454 | if (link) | |
1455 | { | |
1456 | output_enumeral_list (TREE_CHAIN (link)); | |
1457 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
1458 | (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); | |
1459 | ASM_OUTPUT_DWARF_STRING (asm_out_file, | |
1460 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | /****************************** attributes *********************************/ | |
1465 | ||
1466 | /* The following routines are responsible for writing out the various types | |
1467 | of Dwarf attributes (and any following data bytes associated with them). | |
1468 | These routines are listed in order based on the numerical codes of their | |
1469 | associated attributes. */ | |
1470 | ||
1471 | /* Generate an AT_sibling attribute. */ | |
1472 | ||
1473 | inline void | |
1474 | sibling_attribute () | |
1475 | { | |
1476 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1477 | ||
1478 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling); | |
1479 | sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); | |
1480 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
1481 | } | |
1482 | ||
1483 | /* Output the form of location attributes suitable for whole variables and | |
1484 | whole parameters. Note that the location attributes for struct fields | |
1485 | are generated by the routine `data_member_location_attribute' below. */ | |
1486 | ||
1487 | static void | |
1488 | location_attribute (rtl) | |
1489 | register rtx rtl; | |
1490 | { | |
1491 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1492 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1493 | ||
1494 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); | |
1495 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
1496 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
1497 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1498 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1499 | ||
1500 | /* Handle a special case. If we are about to output a location descriptor | |
2e494f70 | 1501 | for a variable or parameter which has been optimized out of existence, |
340ccaab TW |
1502 | don't do that. Instead we output a zero-length location descriptor |
1503 | value as part of the location attribute. Note that we cannot simply | |
1504 | suppress the entire location attribute, because the absence of a | |
1505 | location attribute in certain kinds of DIEs is used to indicate some- | |
1506 | thing entirely different... i.e. that the DIE represents an object | |
1507 | declaration, but not a definition. So sayeth the PLSIG. */ | |
1508 | ||
1509 | if (((GET_CODE (rtl) != REG) || (REGNO (rtl) < FIRST_PSEUDO_REGISTER)) | |
1510 | && ((GET_CODE (rtl) != SUBREG) | |
1511 | || (REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER))) | |
1512 | output_loc_descriptor (eliminate_regs (rtl, 0, 0)); | |
1513 | ||
1514 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1515 | } | |
1516 | ||
1517 | /* Output the specialized form of location attribute used for data members | |
9a631e8e RS |
1518 | of struct types. |
1519 | ||
1520 | In the special case of a FIELD_DECL node which represents a bit-field, | |
1521 | the "offset" part of this special location descriptor must indicate the | |
1522 | distance in bytes from the lowest-addressed byte of the containing | |
1523 | struct or union type to the lowest-addressed byte of the "containing | |
1524 | object" for the bit-field. | |
1525 | ||
1526 | For any given bit-field, the "containing object" is a hypothetical | |
1527 | object (of some integral or enum type) within which the given bit-field | |
1528 | lives. The type of this hypothetical "containing object" is always the | |
1529 | same as the declared type of the individual bit-field itself. | |
1530 | ||
1531 | Note that it is the size (in bytes) of the hypothetical "containing | |
1532 | object" which will be given in the AT_byte_size attribute for this | |
1533 | bit-field. (See the `byte_size_attribute' function below.) | |
1534 | */ | |
1535 | ||
340ccaab TW |
1536 | |
1537 | static void | |
1538 | data_member_location_attribute (decl) | |
1539 | register tree decl; | |
1540 | { | |
1541 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1542 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9a631e8e RS |
1543 | register unsigned containing_object_size_in_bytes; |
1544 | register unsigned containing_object_size_in_bits; | |
1545 | register unsigned member_offset_in_objects; | |
1546 | register unsigned member_offset_in_bytes; | |
1547 | register tree type; | |
1548 | register tree bitpos = DECL_FIELD_BITPOS (decl); | |
340ccaab TW |
1549 | |
1550 | if (TREE_CODE (decl) == ERROR_MARK) | |
1551 | return; | |
1552 | ||
1553 | if (TREE_CODE (decl) != FIELD_DECL) | |
1554 | abort (); | |
1555 | ||
9a631e8e RS |
1556 | /* The bit position given by DECL_FIELD_BITPOS could be non-constant |
1557 | in the case where one or more variable sized members preceeded this | |
1558 | member in the containing struct type. We could probably correctly | |
1559 | handle this case someday, by it's too complicated to deal with at | |
1560 | the moment (and probably too rare to worry about), so just punt on | |
1561 | the whole AT_location attribute for now. Eventually, we'll have | |
1562 | to analyze the expression given as the DECL_FIELD_BITPOS and turn | |
1563 | it into a member-style AT_location descriptor, but that'll be | |
1564 | tough to do. -- rfg */ | |
1565 | ||
75791cee | 1566 | if (TREE_CODE (bitpos) != INTEGER_CST) |
9a631e8e RS |
1567 | return; |
1568 | ||
340ccaab TW |
1569 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); |
1570 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
1571 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
1572 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1573 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1574 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); | |
1575 | ||
9a631e8e RS |
1576 | type = DECL_BIT_FIELD_TYPE (decl); |
1577 | if (type == NULL) | |
1578 | type = TREE_TYPE (decl); | |
340ccaab | 1579 | |
9a631e8e RS |
1580 | containing_object_size_in_bytes = int_size_in_bytes (type); |
1581 | containing_object_size_in_bits | |
1582 | = containing_object_size_in_bytes * BITS_PER_UNIT; | |
1583 | ||
1584 | /* WARNING! Note that the GCC front-end doesn't make any attempt to | |
1585 | keep track of the starting bit offset (relative to the start of | |
1586 | the containing structure type) of the hypothetical "containing | |
1587 | object" for a bit-field. (See the comments at the start of this | |
1588 | function.) Thus, when computing the byte offset value for a | |
1589 | bit-field, all we can do is to divide the starting bit offset of | |
1590 | the bit-field by the size of the hypothetical "containing object" | |
1591 | (which we can easily find). | |
1592 | ||
1593 | This solution only works right as long as the alignment used by the | |
1594 | compiler for the declared type of the bit-field is the same as the | |
1595 | size of that type. | |
1596 | ||
1597 | Since GCC allows type `long long' to be the declared type for a | |
1598 | bit-field, and since some target configurations only align | |
1599 | `long longs' to 4-byte boundaries, we have to check here to see | |
1600 | that the alignment of the containing object is the same as the | |
1601 | size of that object. If it isn't, and if the field in question | |
1602 | is a bit-field, then we may be about to generate bogus Dwarf | |
1603 | output, so we need to warn the user about that. | |
1604 | ||
1605 | Of course it would be nice to actually solve this problem, but | |
1606 | that would require a lot of changes elsewhere in the compiler | |
1607 | which could be quite painful, so for now we'll just live with | |
1608 | this minor annoyance. | |
1609 | */ | |
1610 | ||
75791cee | 1611 | if ((GET_MODE_ALIGNMENT (TYPE_MODE (type)) != containing_object_size_in_bits) |
9a631e8e RS |
1612 | && (DECL_BIT_FIELD_TYPE (type) != NULL)) |
1613 | warning_with_decl (decl, "debugging info won't necessarily be reliable"); | |
1614 | ||
1615 | member_offset_in_objects | |
1616 | = (unsigned) TREE_INT_CST_LOW (bitpos) / containing_object_size_in_bits; | |
1617 | member_offset_in_bytes | |
1618 | = member_offset_in_objects * containing_object_size_in_bytes; | |
1619 | ||
1620 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, member_offset_in_bytes); | |
340ccaab TW |
1621 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); |
1622 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1623 | } | |
1624 | ||
1625 | /* Output an AT_const_value attribute for a variable or a parameter which | |
1626 | does not have a "location" either in memory or in a register. These | |
1627 | things can arise in GNU C when a constant is passed as an actual | |
1628 | parameter to an inlined function. They can also arise in C++ where | |
1629 | declared constants do not necessarily get memory "homes". */ | |
1630 | ||
1631 | static void | |
1632 | const_value_attribute (rtl) | |
1633 | register rtx rtl; | |
1634 | { | |
1635 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1636 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1637 | ||
1638 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4); | |
1639 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
1640 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
1641 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
1642 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1643 | ||
1644 | switch (GET_CODE (rtl)) | |
1645 | { | |
1646 | case CONST_INT: | |
1647 | /* Note that a CONST_INT rtx could represent either an integer or | |
1648 | a floating-point constant. A CONST_INT is used whenever the | |
1649 | constant will fit into a single word. In all such cases, the | |
1650 | original mode of the constant value is wiped out, and the | |
1651 | CONST_INT rtx is assigned VOIDmode. Since we no longer have | |
1652 | precise mode information for these constants, we always just | |
1653 | output them using 4 bytes. */ | |
1654 | ||
1655 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl)); | |
1656 | break; | |
1657 | ||
1658 | case CONST_DOUBLE: | |
1659 | /* Note that a CONST_DOUBLE rtx could represent either an integer | |
1660 | or a floating-point constant. A CONST_DOUBLE is used whenever | |
1661 | the constant requires more than one word in order to be adequately | |
1662 | represented. In all such cases, the original mode of the constant | |
1663 | value is preserved as the mode of the CONST_DOUBLE rtx, but for | |
1664 | simplicity we always just output CONST_DOUBLEs using 8 bytes. */ | |
1665 | ||
1666 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
1667 | (unsigned) CONST_DOUBLE_HIGH (rtl), | |
1668 | (unsigned) CONST_DOUBLE_LOW (rtl)); | |
1669 | break; | |
1670 | ||
1671 | case CONST_STRING: | |
1672 | ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0)); | |
1673 | break; | |
1674 | ||
1675 | case SYMBOL_REF: | |
1676 | case LABEL_REF: | |
1677 | case CONST: | |
1678 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); | |
1679 | break; | |
1680 | ||
1681 | case PLUS: | |
1682 | /* In cases where an inlined instance of an inline function is passed | |
1683 | the address of an `auto' variable (which is local to the caller) | |
1684 | we can get a situation where the DECL_RTL of the artificial | |
1685 | local variable (for the inlining) which acts as a stand-in for | |
1686 | the corresponding formal parameter (of the inline function) | |
1687 | will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). | |
1688 | This is not exactly a compile-time constant expression, but it | |
1689 | isn't the address of the (artificial) local variable either. | |
1690 | Rather, it represents the *value* which the artificial local | |
1691 | variable always has during its lifetime. We currently have no | |
1692 | way to represent such quasi-constant values in Dwarf, so for now | |
1693 | we just punt and generate an AT_const_value attribute with form | |
1694 | FORM_BLOCK4 and a length of zero. */ | |
1695 | break; | |
1696 | } | |
1697 | ||
1698 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1699 | } | |
1700 | ||
1701 | /* Generate *either* an AT_location attribute or else an AT_const_value | |
1702 | data attribute for a variable or a parameter. We generate the | |
1703 | AT_const_value attribute only in those cases where the given | |
1704 | variable or parameter does not have a true "location" either in | |
1705 | memory or in a register. This can happen (for example) when a | |
1706 | constant is passed as an actual argument in a call to an inline | |
1707 | function. (It's possible that these things can crop up in other | |
1708 | ways also.) Note that one type of constant value which can be | |
1709 | passed into an inlined function is a constant pointer. This can | |
1710 | happen for example if an actual argument in an inlined function | |
1711 | call evaluates to a compile-time constant address. */ | |
1712 | ||
1713 | static void | |
1714 | location_or_const_value_attribute (decl) | |
1715 | register tree decl; | |
1716 | { | |
1717 | register rtx rtl; | |
1718 | ||
1719 | if (TREE_CODE (decl) == ERROR_MARK) | |
1720 | return; | |
1721 | ||
1722 | if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL)) | |
1723 | abort (); | |
1724 | ||
9a631e8e RS |
1725 | /* Existing Dwarf debuggers need and expect the location descriptors for |
1726 | formal parameters to reflect the place where the parameter are passed, | |
1727 | as opposed to the places where they might reside during the execution | |
1728 | of the function. This isn't clearly spelled out in the current Dwarf | |
1729 | version 1 specification, but it's obvious if you look at the output of | |
1730 | the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully, | |
1731 | a later version of the Dwarf specification will clarify this. For now, | |
1732 | we just need to generate the right thing. Note that Dwarf version 2 | |
1733 | will provide us with a means to describe *all* of the locations in which | |
1734 | a given variable or parameter resides (and the PC ranges over which it | |
1735 | occupies each one), but for now we can only describe the "passing" | |
1736 | location. */ | |
1737 | ||
340ccaab TW |
1738 | rtl = (TREE_CODE (decl) == PARM_DECL) |
1739 | ? DECL_INCOMING_RTL (decl) | |
1740 | : DECL_RTL (decl); | |
340ccaab TW |
1741 | |
1742 | if (rtl == NULL) | |
1743 | return; | |
1744 | ||
1745 | switch (GET_CODE (rtl)) | |
1746 | { | |
1747 | case CONST_INT: | |
1748 | case CONST_DOUBLE: | |
1749 | case CONST_STRING: | |
1750 | case SYMBOL_REF: | |
1751 | case LABEL_REF: | |
1752 | case CONST: | |
1753 | case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
1754 | const_value_attribute (rtl); | |
1755 | break; | |
1756 | ||
1757 | case MEM: | |
1758 | case REG: | |
1759 | case SUBREG: | |
1760 | location_attribute (rtl); | |
1761 | break; | |
1762 | ||
1763 | default: | |
1764 | abort (); /* Should never happen. */ | |
1765 | } | |
1766 | } | |
1767 | ||
1768 | /* Generate an AT_name attribute given some string value to be included as | |
9a631e8e | 1769 | the value of the attribute. */ |
340ccaab TW |
1770 | |
1771 | inline void | |
1772 | name_attribute (name_string) | |
1773 | register char *name_string; | |
1774 | { | |
75791cee TW |
1775 | if (name_string && *name_string) |
1776 | { | |
1777 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name); | |
1778 | ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string); | |
1779 | } | |
340ccaab TW |
1780 | } |
1781 | ||
1782 | inline void | |
1783 | fund_type_attribute (ft_code) | |
1784 | register unsigned ft_code; | |
1785 | { | |
1786 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type); | |
1787 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code); | |
1788 | } | |
1789 | ||
1790 | static void | |
1791 | mod_fund_type_attribute (type, decl_const, decl_volatile) | |
1792 | register tree type; | |
1793 | register int decl_const; | |
1794 | register int decl_volatile; | |
1795 | { | |
1796 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1797 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1798 | ||
1799 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type); | |
1800 | sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); | |
1801 | sprintf (end_label, MT_END_LABEL_FMT, current_dienum); | |
1802 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1803 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1804 | write_modifier_bytes (type, decl_const, decl_volatile); | |
1805 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, | |
1806 | fundamental_type_code (root_type (type))); | |
1807 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1808 | } | |
1809 | ||
1810 | inline void | |
1811 | user_def_type_attribute (type) | |
1812 | register tree type; | |
1813 | { | |
1814 | char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1815 | ||
1816 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type); | |
1817 | sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type)); | |
1818 | ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); | |
1819 | } | |
1820 | ||
1821 | static void | |
1822 | mod_u_d_type_attribute (type, decl_const, decl_volatile) | |
1823 | register tree type; | |
1824 | register int decl_const; | |
1825 | register int decl_volatile; | |
1826 | { | |
1827 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1828 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1829 | char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1830 | ||
1831 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type); | |
1832 | sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); | |
1833 | sprintf (end_label, MT_END_LABEL_FMT, current_dienum); | |
1834 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1835 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1836 | write_modifier_bytes (type, decl_const, decl_volatile); | |
1837 | sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type))); | |
1838 | ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); | |
1839 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1840 | } | |
1841 | ||
1842 | inline void | |
1843 | ordering_attribute (ordering) | |
1844 | register unsigned ordering; | |
1845 | { | |
1846 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering); | |
1847 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering); | |
1848 | } | |
1849 | ||
1850 | /* Note that the block of subscript information for an array type also | |
1851 | includes information about the element type of type given array type. */ | |
1852 | ||
1853 | static void | |
1854 | subscript_data_attribute (type) | |
1855 | register tree type; | |
1856 | { | |
1857 | register unsigned dimension_number; | |
1858 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1859 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1860 | ||
1861 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data); | |
1862 | sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum); | |
1863 | sprintf (end_label, SS_END_LABEL_FMT, current_dienum); | |
1864 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
1865 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
1866 | ||
1867 | /* The GNU compilers represent multidimensional array types as sequences | |
1868 | of one dimensional array types whose element types are themselves array | |
1869 | types. Here we squish that down, so that each multidimensional array | |
1870 | type gets only one array_type DIE in the Dwarf debugging info. The | |
1871 | draft Dwarf specification say that we are allowed to do this kind | |
1872 | of compression in C (because there is no difference between an | |
1873 | array or arrays and a multidimensional array in C) but for other | |
1874 | source languages (e.g. Ada) we probably shouldn't do this. */ | |
1875 | ||
1876 | for (dimension_number = 0; | |
1877 | TREE_CODE (type) == ARRAY_TYPE; | |
1878 | type = TREE_TYPE (type), dimension_number++) | |
1879 | { | |
1880 | register tree domain = TYPE_DOMAIN (type); | |
1881 | ||
1882 | /* Arrays come in three flavors. Unspecified bounds, fixed | |
1883 | bounds, and (in GNU C only) variable bounds. Handle all | |
1884 | three forms here. */ | |
1885 | ||
1886 | if (domain) | |
1887 | { | |
1888 | /* We have an array type with specified bounds. */ | |
1889 | ||
1890 | register tree lower = TYPE_MIN_VALUE (domain); | |
1891 | register tree upper = TYPE_MAX_VALUE (domain); | |
1892 | ||
1893 | /* Handle only fundamental types as index types for now. */ | |
1894 | ||
1895 | if (! type_is_fundamental (domain)) | |
1896 | abort (); | |
1897 | ||
1898 | /* Output the representation format byte for this dimension. */ | |
1899 | ||
1900 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, | |
1901 | FMT_CODE (1, | |
1902 | TREE_CODE (lower) == INTEGER_CST, | |
1903 | TREE_CODE (upper) == INTEGER_CST)); | |
1904 | ||
1905 | /* Output the index type for this dimension. */ | |
1906 | ||
1907 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, | |
1908 | fundamental_type_code (domain)); | |
1909 | ||
1910 | /* Output the representation for the lower bound. */ | |
1911 | ||
1912 | output_bound_representation (lower, dimension_number, 'l'); | |
1913 | ||
1914 | /* Output the representation for the upper bound. */ | |
1915 | ||
1916 | output_bound_representation (upper, dimension_number, 'u'); | |
1917 | } | |
1918 | else | |
1919 | { | |
1920 | /* We have an array type with an unspecified length. For C and | |
1921 | C++ we can assume that this really means that (a) the index | |
1922 | type is an integral type, and (b) the lower bound is zero. | |
1923 | Note that Dwarf defines the representation of an unspecified | |
1924 | (upper) bound as being a zero-length location description. */ | |
1925 | ||
1926 | /* Output the array-bounds format byte. */ | |
1927 | ||
1928 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X); | |
1929 | ||
1930 | /* Output the (assumed) index type. */ | |
1931 | ||
1932 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer); | |
1933 | ||
1934 | /* Output the (assumed) lower bound (constant) value. */ | |
1935 | ||
1936 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
1937 | ||
1938 | /* Output the (empty) location description for the upper bound. */ | |
1939 | ||
1940 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | /* Output the prefix byte that says that the element type is comming up. */ | |
1945 | ||
1946 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET); | |
1947 | ||
1948 | /* Output a representation of the type of the elements of this array type. */ | |
1949 | ||
1950 | type_attribute (type, 0, 0); | |
1951 | ||
1952 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
1953 | } | |
1954 | ||
1955 | static void | |
1956 | byte_size_attribute (tree_node) | |
1957 | register tree tree_node; | |
1958 | { | |
1959 | register unsigned size; | |
1960 | ||
1961 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size); | |
1962 | switch (TREE_CODE (tree_node)) | |
1963 | { | |
1964 | case ERROR_MARK: | |
1965 | size = 0; | |
1966 | break; | |
1967 | ||
1968 | case ENUMERAL_TYPE: | |
1969 | case RECORD_TYPE: | |
1970 | case UNION_TYPE: | |
1971 | size = int_size_in_bytes (tree_node); | |
1972 | break; | |
1973 | ||
1974 | case FIELD_DECL: | |
9a631e8e RS |
1975 | /* For a data member of a struct or union, the AT_byte_size is |
1976 | always given as the number of bytes normally allocated for | |
1977 | an object of the *declared* type of the member itself. This | |
1978 | is true even for bit-fields. */ | |
1979 | size = int_size_in_bytes (DECL_BIT_FIELD_TYPE (tree_node) | |
1980 | ? DECL_BIT_FIELD_TYPE (tree_node) | |
1981 | : TREE_TYPE (tree_node)); | |
340ccaab TW |
1982 | break; |
1983 | ||
1984 | default: | |
1985 | abort (); | |
1986 | } | |
9a631e8e RS |
1987 | |
1988 | /* Note that `size' might be -1 when we get to this point. If it | |
1989 | is, that indicates that the byte size of the entity in question | |
1990 | is variable. We have no good way of expressing this fact in Dwarf | |
1991 | at the present time, so just let the -1 pass on through. */ | |
1992 | ||
340ccaab TW |
1993 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size); |
1994 | } | |
1995 | ||
9a631e8e RS |
1996 | /* For a FIELD_DECL node which represents a bit-field, output an attribute |
1997 | which specifies the distance in bits from the highest order bit of the | |
1998 | "containing object" for the bit-field to the highest order bit of the | |
1999 | bit-field itself. | |
2000 | ||
2001 | For any given bit-field, the "containing object" is a hypothetical | |
2002 | object (of some integral or enum type) within which the given bit-field | |
2003 | lives. The type of this hypothetical "containing object" is always the | |
2004 | same as the declared type of the individual bit-field itself. | |
2005 | ||
2006 | Note that it is the size (in bytes) of the hypothetical "containing | |
2007 | object" which will be given in the AT_byte_size attribute for this | |
2008 | bit-field. (See `byte_size_attribute' above.) | |
2009 | */ | |
340ccaab TW |
2010 | |
2011 | inline void | |
2012 | bit_offset_attribute (decl) | |
2013 | register tree decl; | |
2014 | { | |
9a631e8e RS |
2015 | register tree type = DECL_BIT_FIELD_TYPE (decl); |
2016 | register unsigned containing_object_size_in_bits; | |
2017 | register unsigned dwarf_bit_offset; | |
2018 | register tree bitpos_tree = DECL_FIELD_BITPOS (decl); | |
2019 | register unsigned bitpos; | |
2020 | ||
340ccaab | 2021 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ |
9a631e8e RS |
2022 | assert (type); /* Must be a bit field. */ |
2023 | ||
2024 | /* The bit position given by DECL_FIELD_BITPOS could be non-constant | |
2025 | in the case where one or more variable sized members preceeded this | |
2026 | member in the containing struct type. We could probably correctly | |
2027 | handle this case someday, by it's too complicated to deal with at | |
2028 | the moment, so just punt on the whole AT_bit_offset attribute for | |
2029 | now. Eventually, we'll have to analyze the (variable) expression | |
2030 | given as the DECL_FIELD_BITPOS and see if we can factor out just | |
2031 | the (constant) bit offset part of that expression. -- rfg */ | |
2032 | ||
2033 | if (TREE_CODE (bitpos_tree) != CONST_INT) | |
2034 | return; | |
2035 | ||
2036 | containing_object_size_in_bits = int_size_in_bytes (type) * BITS_PER_UNIT; | |
2037 | ||
2038 | /* WARNING! Note that the GCC front-end doesn't make any attempt to | |
2039 | keep track of the starting bit offset (relative to the start of | |
2040 | the containing structure type) of the hypothetical "containing | |
2041 | object" for a bit-field. (See the comments at the start of this | |
2042 | function.) Thus, when computing the AT_bit_offset value for a | |
2043 | bit-field, all we can do is to divide the starting bit offset of | |
2044 | the bit-field by the size of the hypothetical "containing object" | |
2045 | (which we can easily find) and then get the remainder. | |
2046 | ||
2047 | This solution only works right as long as the alignment used by the | |
2048 | compiler for the declared type of the bit-field is the same as the | |
2049 | size of that type. | |
2050 | ||
2051 | Since GCC allows type `long long' to be the declared type for a | |
2052 | bit-field, and since some target configurations only align | |
2053 | `long longs' to 4-byte boundaries, we really should check here | |
2054 | to see that the alignment of the containing object is the same | |
2055 | as the size of that object and issue a warning if it isn't but | |
2056 | since we will also be generating an AT_location attribute for | |
2057 | the bit-field, and sinec it will generat a warning for this | |
2058 | condition we do not need to do it again here. That would just | |
2059 | cause the user to see two redundant warnings for the same single | |
2060 | bit-field declaration. | |
2061 | ||
2062 | Of course it would be nice to actually solve this problem, but | |
2063 | that would require a lot of changes elsewhere in the compiler | |
2064 | which could be quite painful, so for now we'll just live with | |
2065 | this minor annoyance. | |
2066 | */ | |
2067 | ||
2068 | #if 0 | |
75791cee | 2069 | if (GET_MODE_ALIGNMENT (TYPE_MODE (type)) != containing_object_size_in_bits) |
9a631e8e RS |
2070 | warning_with_decl (decl, "debugging info won't necessarily be reliable"); |
2071 | #endif | |
2072 | ||
2073 | bitpos = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
2074 | ||
2075 | #if (BYTES_BIG_ENDIAN == 1) | |
2076 | { | |
2077 | register unsigned high_order_bitpos = bitpos; | |
2078 | ||
2079 | dwarf_bit_offset = high_order_bitpos % containing_object_size_in_bits; | |
2080 | } | |
2081 | #else | |
2082 | { | |
2083 | register unsigned low_order_bitpos = bitpos; | |
2084 | register unsigned field_width | |
2085 | = (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); | |
2086 | register unsigned high_order_bitpos = low_order_bitpos + field_width; | |
2087 | ||
2088 | dwarf_bit_offset = containing_object_size_in_bits | |
2089 | - (high_order_bitpos % containing_object_size_in_bits); | |
2090 | } | |
2091 | #endif | |
340ccaab TW |
2092 | |
2093 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset); | |
9a631e8e | 2094 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, dwarf_bit_offset); |
340ccaab TW |
2095 | } |
2096 | ||
2097 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
2098 | which specifies the length in bits of the given field. */ | |
2099 | ||
2100 | inline void | |
2101 | bit_size_attribute (decl) | |
2102 | register tree decl; | |
2103 | { | |
2104 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ | |
2105 | assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ | |
2106 | ||
2107 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size); | |
2108 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
2109 | (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); | |
2110 | } | |
2111 | ||
2112 | /* The following routine outputs the `element_list' attribute for enumeration | |
2113 | type DIEs. The element_lits attribute includes the names and values of | |
2114 | all of the enumeration constants associated with the given enumeration | |
2115 | type. */ | |
2116 | ||
2117 | inline void | |
2118 | element_list_attribute (element) | |
2119 | register tree element; | |
2120 | { | |
2121 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2122 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2123 | ||
2124 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list); | |
2125 | sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum); | |
2126 | sprintf (end_label, EE_END_LABEL_FMT, current_dienum); | |
2127 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
2128 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2129 | ||
2130 | /* Here we output a list of value/name pairs for each enumeration constant | |
2131 | defined for this enumeration type (as required), but we do it in REVERSE | |
2132 | order. The order is the one required by the draft #5 Dwarf specification | |
2133 | published by the UI/PLSIG. */ | |
2134 | ||
2135 | output_enumeral_list (element); /* Recursively output the whole list. */ | |
2136 | ||
2137 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2138 | } | |
2139 | ||
2140 | /* Generate an AT_stmt_list attribute. These are normally present only in | |
2141 | DIEs with a TAG_compile_unit tag. */ | |
2142 | ||
2143 | inline void | |
2144 | stmt_list_attribute (label) | |
2145 | register char *label; | |
2146 | { | |
2147 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list); | |
2148 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
2149 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
2150 | } | |
2151 | ||
2152 | /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or | |
2153 | for a subroutine DIE. */ | |
2154 | ||
2155 | inline void | |
2156 | low_pc_attribute (asm_low_label) | |
2157 | register char *asm_low_label; | |
2158 | { | |
2159 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc); | |
2160 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label); | |
2161 | } | |
2162 | ||
2163 | /* Generate an AT_high_pc attribute for a lexical_block DIE or for a | |
2164 | subroutine DIE. */ | |
2165 | ||
2166 | inline void | |
2167 | high_pc_attribute (asm_high_label) | |
2168 | register char *asm_high_label; | |
2169 | { | |
2170 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc); | |
2171 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label); | |
2172 | } | |
2173 | ||
2174 | /* Generate an AT_language attribute given a LANG value. These attributes | |
2175 | are used only within TAG_compile_unit DIEs. */ | |
2176 | ||
2177 | inline void | |
2178 | language_attribute (language_code) | |
2179 | register unsigned language_code; | |
2180 | { | |
2181 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language); | |
2182 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code); | |
2183 | } | |
2184 | ||
2185 | inline void | |
2186 | member_attribute (context) | |
2187 | register tree context; | |
2188 | { | |
2189 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2190 | ||
2191 | /* Generate this attribute only for members in C++. */ | |
2192 | ||
2193 | if (context != NULL | |
2194 | && (TREE_CODE (context) == RECORD_TYPE | |
2195 | || TREE_CODE (context) == UNION_TYPE)) | |
2196 | { | |
2197 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member); | |
2198 | sprintf (label, TYPE_NAME_FMT, TYPE_UID (context)); | |
2199 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
2200 | } | |
2201 | } | |
2202 | ||
2203 | inline void | |
2204 | string_length_attribute (upper_bound) | |
2205 | register tree upper_bound; | |
2206 | { | |
2207 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2208 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2209 | ||
2210 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length); | |
2211 | sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum); | |
2212 | sprintf (end_label, SL_END_LABEL_FMT, current_dienum); | |
2213 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2214 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2215 | output_bound_representation (upper_bound, 0, 'u'); | |
2216 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2217 | } | |
2218 | ||
2219 | inline void | |
2220 | comp_dir_attribute (dirname) | |
2221 | register char *dirname; | |
2222 | { | |
2223 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir); | |
2224 | ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); | |
2225 | } | |
2226 | ||
2227 | inline void | |
2228 | sf_names_attribute (sf_names_start_label) | |
2229 | register char *sf_names_start_label; | |
2230 | { | |
2231 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names); | |
2232 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
2233 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label); | |
2234 | } | |
2235 | ||
2236 | inline void | |
2237 | src_info_attribute (src_info_start_label) | |
2238 | register char *src_info_start_label; | |
2239 | { | |
2240 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info); | |
2241 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
2242 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label); | |
2243 | } | |
2244 | ||
2245 | inline void | |
2246 | mac_info_attribute (mac_info_start_label) | |
2247 | register char *mac_info_start_label; | |
2248 | { | |
2249 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info); | |
2250 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
2251 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label); | |
2252 | } | |
2253 | ||
2254 | inline void | |
2255 | prototyped_attribute (func_type) | |
2256 | register tree func_type; | |
2257 | { | |
2258 | if ((strcmp (language_string, "GNU C") == 0) | |
2259 | && (TYPE_ARG_TYPES (func_type) != NULL)) | |
2260 | { | |
2261 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped); | |
2262 | ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | inline void | |
2267 | producer_attribute (producer) | |
2268 | register char *producer; | |
2269 | { | |
2270 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer); | |
2271 | ASM_OUTPUT_DWARF_STRING (asm_out_file, producer); | |
2272 | } | |
2273 | ||
2274 | inline void | |
2275 | inline_attribute (decl) | |
2276 | register tree decl; | |
2277 | { | |
2278 | if (TREE_INLINE (decl)) | |
2279 | { | |
2280 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline); | |
2281 | ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | inline void | |
2286 | containing_type_attribute (containing_type) | |
2287 | register tree containing_type; | |
2288 | { | |
2289 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2290 | ||
2291 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type); | |
2292 | sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type)); | |
2293 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
2294 | } | |
2295 | ||
9a631e8e RS |
2296 | inline void |
2297 | src_coords_attribute (src_fileno, src_lineno) | |
2298 | register unsigned src_fileno; | |
2299 | register unsigned src_lineno; | |
2300 | { | |
9a631e8e RS |
2301 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords); |
2302 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno); | |
2303 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno); | |
9a631e8e RS |
2304 | } |
2305 | ||
340ccaab TW |
2306 | /************************* end of attributes *****************************/ |
2307 | ||
2308 | /********************* utility routines for DIEs *************************/ | |
2309 | ||
9a631e8e RS |
2310 | /* Output an AT_name attribute and an AT_src_coords attribute for the |
2311 | given decl, but only if it actually has a name. */ | |
2312 | ||
2313 | inline void | |
2314 | name_and_src_coords_attributes (decl) | |
2315 | register tree decl; | |
2316 | { | |
2317 | register tree decl_name = DECL_NAME (decl); | |
2318 | ||
2319 | if (decl_name && IDENTIFIER_POINTER (decl_name)) | |
2320 | { | |
2321 | name_attribute (IDENTIFIER_POINTER (decl_name)); | |
75791cee TW |
2322 | #ifdef DWARF_DECL_COORDINATES |
2323 | { | |
2324 | register unsigned file_index; | |
2325 | ||
2326 | /* This is annoying, but we have to pop out of the .debug section | |
2327 | for a moment while we call `lookup_filename' because calling it | |
2328 | may cause a temporary switch into the .debug_sfnames section and | |
2329 | most svr4 assemblers are not smart enough be be able to nest | |
2330 | section switches to any depth greater than one. Note that we | |
2331 | also can't skirt this issue by delaying all output to the | |
2332 | .debug_sfnames section unit the end of compilation because that | |
2333 | would cause us to have inter-section forward references and | |
2334 | Fred Fish sez that m68k/svr4 assemblers botch those. */ | |
2335 | ||
2336 | ASM_OUTPUT_POP_SECTION (asm_out_file); | |
2337 | file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
2338 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); | |
2339 | ||
2340 | src_coords_attribute (file_index, DECL_SOURCE_LINE (decl)); | |
2341 | } | |
2342 | #endif | |
9a631e8e RS |
2343 | } |
2344 | } | |
2345 | ||
340ccaab TW |
2346 | /* Many forms of DIEs contain a "type description" part. The following |
2347 | routine writes out these "type descriptor" parts. */ | |
2348 | ||
2349 | static void | |
2350 | type_attribute (type, decl_const, decl_volatile) | |
2351 | register tree type; | |
2352 | register int decl_const; | |
2353 | register int decl_volatile; | |
2354 | { | |
2355 | register enum tree_code code = TREE_CODE (type); | |
2356 | register int root_type_modified; | |
2357 | ||
2358 | if (TREE_CODE (type) == ERROR_MARK) | |
2359 | return; | |
2360 | ||
2361 | /* Handle a special case. For functions whose return type is void, | |
2362 | we generate *no* type attribute. (Note that no object may have | |
2363 | type `void', so this only applies to function return types. */ | |
2364 | ||
2365 | if (TREE_CODE (type) == VOID_TYPE) | |
2366 | return; | |
2367 | ||
2368 | root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE | |
2369 | || decl_const || decl_volatile | |
2370 | || TYPE_READONLY (type) || TYPE_VOLATILE (type)); | |
2371 | ||
2372 | if (type_is_fundamental (root_type (type))) | |
2373 | if (root_type_modified) | |
2374 | mod_fund_type_attribute (type, decl_const, decl_volatile); | |
2375 | else | |
2376 | fund_type_attribute (fundamental_type_code (type)); | |
2377 | else | |
2378 | if (root_type_modified) | |
2379 | mod_u_d_type_attribute (type, decl_const, decl_volatile); | |
2380 | else | |
2381 | user_def_type_attribute (type); | |
2382 | } | |
2383 | ||
2384 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
2385 | a pointer to the (string) tag name for the given type, or zero if the | |
2386 | type was declared without a tag. */ | |
2387 | ||
2388 | static char * | |
2389 | type_tag (type) | |
2390 | register tree type; | |
2391 | { | |
2392 | register char *name = 0; | |
2393 | ||
2394 | if (TYPE_NAME (type) != 0) | |
2395 | { | |
2396 | register tree t = 0; | |
2397 | ||
2398 | /* Find the IDENTIFIER_NODE for the type name. */ | |
2399 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
2400 | t = TYPE_NAME (type); | |
2401 | #if 0 | |
2402 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point | |
2403 | to a TYPE_DECL node, regardless of whether or not a `typedef' was | |
2404 | involved. This is distinctly different from what the gcc front-end | |
2405 | does. It always makes the TYPE_NAME for each tagged type be either | |
2406 | NULL (signifying an anonymous tagged type) or else a pointer to an | |
2407 | IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf | |
2408 | for both C and C++, but given this inconsistancy in the TREE | |
2409 | representation of tagged types for C and C++ in the GNU front-ends, | |
2410 | we cannot support both languages correctly unless we introduce some | |
2411 | front-end specific code here, and rms objects to that, so we can | |
2412 | only generate correct Dwarf for one of these two languages. C is | |
2413 | more important, so for now we'll do the right thing for C and let | |
2414 | g++ go fish. */ | |
2415 | ||
2416 | else | |
2417 | if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) | |
2418 | t = DECL_NAME (TYPE_NAME (type)); | |
2419 | #endif | |
2420 | /* Now get the name as a string, or invent one. */ | |
2421 | if (t != 0) | |
2422 | name = IDENTIFIER_POINTER (t); | |
2423 | } | |
2424 | ||
2425 | return (name == 0 || *name == '\0') ? 0 : name; | |
2426 | } | |
2427 | ||
2428 | inline void | |
2429 | dienum_push () | |
2430 | { | |
2431 | /* Start by checking if the pending_sibling_stack needs to be expanded. | |
2432 | If necessary, expand it. */ | |
2433 | ||
2434 | if (pending_siblings == pending_siblings_allocated) | |
2435 | { | |
2436 | pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT; | |
2437 | pending_sibling_stack | |
2438 | = (unsigned *) xrealloc (pending_sibling_stack, | |
2439 | pending_siblings_allocated * sizeof(unsigned)); | |
2440 | } | |
2441 | ||
2442 | pending_siblings++; | |
2443 | NEXT_DIE_NUM = next_unused_dienum++; | |
2444 | } | |
2445 | ||
2446 | /* Pop the sibling stack so that the most recently pushed DIEnum becomes the | |
2447 | NEXT_DIE_NUM. */ | |
2448 | ||
2449 | inline void | |
2450 | dienum_pop () | |
2451 | { | |
2452 | pending_siblings--; | |
2453 | } | |
2454 | ||
2455 | inline tree | |
2456 | member_declared_type (member) | |
2457 | register tree member; | |
2458 | { | |
2459 | return (DECL_BIT_FIELD_TYPE (member)) | |
2460 | ? DECL_BIT_FIELD_TYPE (member) | |
2461 | : TREE_TYPE (member); | |
2462 | } | |
2463 | ||
2464 | /******************************* DIEs ************************************/ | |
2465 | ||
2466 | /* Output routines for individual types of DIEs. */ | |
2467 | ||
2468 | /* Note that every type of DIE (except a null DIE) gets a sibling. */ | |
2469 | ||
2470 | static void | |
2471 | output_array_type_die (arg) | |
2472 | register void *arg; | |
2473 | { | |
2474 | register tree type = arg; | |
2475 | ||
2476 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type); | |
2477 | sibling_attribute (); | |
2478 | equate_type_number_to_die_number (type); | |
2479 | member_attribute (TYPE_CONTEXT (type)); | |
2480 | ||
2481 | /* I believe that we can default the array ordering. SDB will probably | |
2482 | do the right things even if AT_ordering is not present. It's not | |
2483 | even an issue until we start to get into multidimensional arrays | |
9a631e8e RS |
2484 | anyway. If SDB is ever caught doing the Wrong Thing for multi- |
2485 | dimensional arrays, then we'll have to put the AT_ordering attribute | |
2486 | back in. (But if and when we find out that we need to put these in, | |
2487 | we will only do so for multidimensional arrays. After all, we don't | |
2488 | want to waste space in the .debug section now do we?) */ | |
340ccaab TW |
2489 | |
2490 | #if 0 | |
2491 | ordering_attribute (ORD_row_major); | |
2492 | #endif | |
2493 | ||
2494 | subscript_data_attribute (type); | |
2495 | } | |
2496 | ||
2497 | static void | |
2498 | output_set_type_die (arg) | |
2499 | register void *arg; | |
2500 | { | |
2501 | register tree type = arg; | |
2502 | ||
2503 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type); | |
2504 | sibling_attribute (); | |
2505 | equate_type_number_to_die_number (type); | |
2506 | member_attribute (TYPE_CONTEXT (type)); | |
2507 | type_attribute (TREE_TYPE (type), 0, 0); | |
2508 | } | |
2509 | ||
2510 | #if 0 | |
2511 | /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */ | |
2512 | static void | |
2513 | output_entry_point_die (arg) | |
2514 | register void *arg; | |
2515 | { | |
2516 | register tree decl = arg; | |
2517 | register tree type = TREE_TYPE (decl); | |
2518 | register tree return_type = TREE_TYPE (type); | |
2519 | ||
2520 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point); | |
2521 | sibling_attribute (); | |
2522 | dienum_push (); | |
9a631e8e | 2523 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2524 | member_attribute (DECL_CONTEXT (decl)); |
2525 | type_attribute (return_type, 0, 0); | |
2526 | } | |
2527 | #endif | |
2528 | ||
2529 | /* Output a DIE to represent an enumeration type. Note that these DIEs | |
2530 | include all of the information about the enumeration values also. | |
2531 | This information is encoded into the element_list attribute. */ | |
2532 | ||
2533 | static void | |
2534 | output_enumeration_type_die (arg) | |
2535 | register void *arg; | |
2536 | { | |
2537 | register tree type = arg; | |
2538 | ||
2539 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); | |
2540 | sibling_attribute (); | |
2541 | equate_type_number_to_die_number (type); | |
2542 | name_attribute (type_tag (type)); | |
2543 | member_attribute (TYPE_CONTEXT (type)); | |
2544 | ||
2545 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
2546 | given enum type is incomplete, do not generate the AT_byte_size | |
2547 | attribute or the AT_element_list attribute. */ | |
2548 | ||
2549 | if (TYPE_SIZE (type)) | |
2550 | { | |
2551 | byte_size_attribute (type); | |
2552 | element_list_attribute (TYPE_FIELDS (type)); | |
2553 | } | |
2554 | } | |
2555 | ||
2556 | /* Output a DIE to represent either a real live formal parameter decl or | |
2557 | to represent just the type of some formal parameter position in some | |
2558 | function type. | |
2559 | ||
2560 | Note that this routine is a bit unusual because its argument may be | |
2561 | either a PARM_DECL node or else some sort of a ..._TYPE node. If it's | |
2562 | the formar then this function is being called to output a real live | |
2563 | formal parameter declaration. If it's the latter, then this function | |
2564 | is only being called to output a TAG_formal_parameter DIE to stand as | |
2565 | a placeholder for some formal argument type of some subprogram type. */ | |
2566 | ||
2567 | static void | |
2568 | output_formal_parameter_die (arg) | |
2569 | register void *arg; | |
2570 | { | |
2571 | register tree decl = arg; | |
2572 | register tree type; | |
2573 | ||
2574 | if (TREE_CODE (decl) == PARM_DECL) | |
2575 | type = TREE_TYPE (decl); | |
2576 | else | |
2577 | { | |
2578 | type = decl; /* we were called with a type, not a decl */ | |
2579 | decl = NULL; | |
2580 | } | |
2581 | ||
2582 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter); | |
2583 | sibling_attribute (); | |
2584 | if (decl) | |
2585 | { | |
9a631e8e | 2586 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2587 | type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); |
2588 | location_or_const_value_attribute (decl); | |
2589 | } | |
2590 | else | |
2591 | type_attribute (type, 0, 0); | |
2592 | } | |
2593 | ||
2594 | /* Output a DIE to represent a declared function (either file-scope | |
2595 | or block-local) which has "external linkage" (according to ANSI-C). */ | |
2596 | ||
2597 | static void | |
2598 | output_global_subroutine_die (arg) | |
2599 | register void *arg; | |
2600 | { | |
2601 | register tree decl = arg; | |
2602 | register tree type = TREE_TYPE (decl); | |
2603 | register tree return_type = TREE_TYPE (type); | |
2604 | ||
2605 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine); | |
2606 | sibling_attribute (); | |
2607 | dienum_push (); | |
9a631e8e | 2608 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2609 | inline_attribute (decl); |
2610 | prototyped_attribute (type); | |
2611 | member_attribute (DECL_CONTEXT (decl)); | |
2612 | type_attribute (return_type, 0, 0); | |
2613 | if (!TREE_EXTERNAL (decl)) | |
2614 | { | |
2615 | char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2616 | ||
9a631e8e | 2617 | low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
340ccaab TW |
2618 | sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); |
2619 | high_pc_attribute (func_end_label); | |
2620 | } | |
2621 | } | |
2622 | ||
2623 | /* Output a DIE to represent a declared data object (either file-scope | |
2624 | or block-local) which has "external linkage" (according to ANSI-C). */ | |
2625 | ||
2626 | static void | |
2627 | output_global_variable_die (arg) | |
2628 | register void *arg; | |
2629 | { | |
2630 | register tree decl = arg; | |
2631 | register tree type = TREE_TYPE (decl); | |
2632 | ||
2633 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable); | |
2634 | sibling_attribute (); | |
9a631e8e | 2635 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2636 | member_attribute (DECL_CONTEXT (decl)); |
2637 | type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
2638 | if (!TREE_EXTERNAL (decl)) | |
2639 | location_or_const_value_attribute (decl); | |
2640 | } | |
2641 | ||
2642 | #if 0 | |
2643 | /* TAG_inline_subroutine has been retired by the UI/PLSIG. We're | |
2644 | now supposed to use either TAG_subroutine or TAG_global_subroutine | |
2645 | (depending on whether or not the function in question has internal | |
2646 | or external linkage) and we're supposed to just put in an AT_inline | |
2647 | attribute. */ | |
2648 | static void | |
2649 | output_inline_subroutine_die (arg) | |
2650 | register void *arg; | |
2651 | { | |
2652 | register tree decl = arg; | |
2653 | register tree type = TREE_TYPE (decl); | |
2654 | register tree return_type = TREE_TYPE (type); | |
2655 | ||
2656 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine); | |
2657 | sibling_attribute (); | |
2658 | dienum_push (); | |
9a631e8e | 2659 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2660 | prototyped_attribute (type); |
2661 | member_attribute (DECL_CONTEXT (decl)); | |
2662 | type_attribute (return_type, 0, 0); | |
2663 | ||
2664 | /* Note: For each inline function which gets an out-of-line body | |
2665 | generated for it, we want to generate AT_low_pc and AT_high_pc | |
2666 | attributes here for the function's out-of-line body. | |
2667 | ||
2668 | Unfortunately, the decision as to whether or not to generate an | |
2669 | out-of-line body for any given inline function may not be made | |
2670 | until we reach the end of the containing scope for the given | |
2671 | inline function (because only then will it be known if the | |
2672 | function was ever even called). | |
2673 | ||
2674 | For this reason, the output of DIEs representing file-scope inline | |
2675 | functions gets delayed until a special post-pass which happens only | |
2676 | after we have reached the end of the compilation unit. Because of | |
2677 | this mechanism, we can always be sure (by the time we reach here) | |
2678 | that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not | |
2679 | there was an out-of-line body generated for this inline function. | |
2680 | */ | |
2681 | ||
2682 | if (!TREE_EXTERNAL (decl)) | |
2683 | { | |
2684 | if (TREE_ASM_WRITTEN (decl)) | |
2685 | { | |
2686 | char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2687 | ||
9a631e8e | 2688 | low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
340ccaab TW |
2689 | sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); |
2690 | high_pc_attribute (func_end_label); | |
2691 | } | |
2692 | } | |
2693 | } | |
2694 | #endif | |
2695 | ||
2696 | static void | |
2697 | output_label_die (arg) | |
2698 | register void *arg; | |
2699 | { | |
2700 | register tree decl = arg; | |
2701 | register rtx insn = DECL_RTL (decl); | |
2702 | ||
2703 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label); | |
2704 | sibling_attribute (); | |
9a631e8e | 2705 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2706 | |
2707 | /* When optimization is enabled (with -O) the code in jump.c and in flow.c | |
2708 | may cause insns representing one of more of the user's own labels to | |
2709 | be deleted. This happens whenever it is determined that a given label | |
2710 | is unreachable. | |
2711 | ||
2712 | In such cases, we here generate an abbreviated form of a label DIE. | |
2713 | This abbreviated version does *not* have a low_pc attribute. This | |
2714 | should signify to the debugger that the label has been optimized away. | |
2715 | ||
2716 | Note that a CODE_LABEL can get deleted either by begin converted into | |
2717 | a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag | |
2718 | set to true. We handle both cases here. | |
2719 | */ | |
2720 | ||
2721 | if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn)) | |
2722 | { | |
2723 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2724 | ||
2725 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number, | |
2726 | (unsigned) INSN_UID (insn)); | |
2727 | low_pc_attribute (label); | |
2728 | } | |
2729 | } | |
2730 | ||
2731 | static void | |
2732 | output_lexical_block_die (arg) | |
2733 | register void *arg; | |
2734 | { | |
2735 | register tree stmt = arg; | |
2736 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2737 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2738 | ||
2739 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block); | |
2740 | sibling_attribute (); | |
2741 | dienum_push (); | |
2742 | sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); | |
2743 | low_pc_attribute (begin_label); | |
2744 | sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); | |
2745 | high_pc_attribute (end_label); | |
2746 | } | |
2747 | ||
2748 | static void | |
2749 | output_inlined_subroutine_die (arg) | |
2750 | register void *arg; | |
2751 | { | |
2752 | register tree stmt = arg; | |
2753 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2754 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2755 | ||
2756 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine); | |
2757 | sibling_attribute (); | |
2758 | dienum_push (); | |
2759 | sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); | |
2760 | low_pc_attribute (begin_label); | |
2761 | sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); | |
2762 | high_pc_attribute (end_label); | |
2763 | } | |
2764 | ||
2765 | /* Output a DIE to represent a declared data object (either file-scope | |
2766 | or block-local) which has "internal linkage" (according to ANSI-C). */ | |
2767 | ||
2768 | static void | |
2769 | output_local_variable_die (arg) | |
2770 | register void *arg; | |
2771 | { | |
2772 | register tree decl = arg; | |
2773 | register tree type = TREE_TYPE (decl); | |
2774 | ||
2775 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable); | |
2776 | sibling_attribute (); | |
9a631e8e | 2777 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2778 | member_attribute (DECL_CONTEXT (decl)); |
2779 | type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
2780 | location_or_const_value_attribute (decl); | |
2781 | } | |
2782 | ||
2783 | static void | |
2784 | output_member_die (arg) | |
2785 | register void *arg; | |
2786 | { | |
2787 | register tree decl = arg; | |
2788 | ||
2789 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member); | |
2790 | sibling_attribute (); | |
9a631e8e | 2791 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2792 | member_attribute (DECL_CONTEXT (decl)); |
2793 | type_attribute (member_declared_type (decl), | |
2794 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
2795 | if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */ | |
2796 | { | |
2797 | byte_size_attribute (decl); | |
2798 | bit_size_attribute (decl); | |
2799 | bit_offset_attribute (decl); | |
2800 | } | |
2801 | data_member_location_attribute (decl); | |
2802 | } | |
2803 | ||
2804 | #if 0 | |
2805 | /* Don't generate either pointer_type DIEs or reference_type DIEs. According | |
2806 | to the 4-4-90 Dwarf draft spec (just after requirement #47): | |
2807 | ||
2808 | These two type entries are not currently generated by any compiler. | |
2809 | Since the only way to name a pointer (or reference) type is C or C++ | |
2810 | is via a "typedef", an entry with the "typedef" tag is generated | |
2811 | instead. | |
2812 | ||
2813 | We keep this code here just in case these types of DIEs may be needed | |
2814 | to represent certain things in other languages (e.g. Pascal) someday. | |
2815 | */ | |
2816 | ||
2817 | static void | |
2818 | output_pointer_type_die (arg) | |
2819 | register void *arg; | |
2820 | { | |
2821 | register tree type = arg; | |
2822 | ||
2823 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type); | |
2824 | sibling_attribute (); | |
2825 | equate_type_number_to_die_number (type); | |
2826 | member_attribute (TYPE_CONTEXT (type)); | |
2827 | type_attribute (TREE_TYPE (type), 0, 0); | |
2828 | } | |
2829 | ||
2830 | static void | |
2831 | output_reference_type_die (arg) | |
2832 | register void *arg; | |
2833 | { | |
2834 | register tree type = arg; | |
2835 | ||
2836 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type); | |
2837 | sibling_attribute (); | |
2838 | equate_type_number_to_die_number (type); | |
2839 | member_attribute (TYPE_CONTEXT (type)); | |
2840 | type_attribute (TREE_TYPE (type), 0, 0); | |
2841 | } | |
2842 | #endif | |
2843 | ||
2844 | output_ptr_to_mbr_type_die (arg) | |
2845 | register void *arg; | |
2846 | { | |
2847 | register tree type = arg; | |
2848 | ||
2849 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type); | |
2850 | sibling_attribute (); | |
2851 | equate_type_number_to_die_number (type); | |
2852 | member_attribute (TYPE_CONTEXT (type)); | |
2853 | containing_type_attribute (TYPE_OFFSET_BASETYPE (type)); | |
2854 | type_attribute (TREE_TYPE (type), 0, 0); | |
2855 | } | |
2856 | ||
2857 | static void | |
2858 | output_compile_unit_die (arg) | |
2859 | register void *arg; | |
2860 | { | |
2861 | register char *main_input_filename = arg; | |
2862 | ||
2863 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit); | |
2864 | sibling_attribute (); | |
2865 | dienum_push (); | |
2866 | name_attribute (main_input_filename); | |
2867 | ||
2868 | { | |
2869 | char producer[250]; | |
2870 | ||
2871 | sprintf (producer, "%s %s", language_string, version_string); | |
2872 | producer_attribute (producer); | |
2873 | } | |
2874 | ||
2875 | if (strcmp (language_string, "GNU C++") == 0) | |
2876 | language_attribute (LANG_C_PLUS_PLUS); | |
2877 | else if (flag_traditional) | |
2878 | language_attribute (LANG_C); | |
2879 | else | |
2880 | language_attribute (LANG_C89); | |
2881 | low_pc_attribute (TEXT_BEGIN_LABEL); | |
2882 | high_pc_attribute (TEXT_END_LABEL); | |
2883 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
2884 | stmt_list_attribute (LINE_BEGIN_LABEL); | |
2885 | last_filename = xstrdup (main_input_filename); | |
2886 | ||
2887 | { | |
2e494f70 RS |
2888 | char *wd = getpwd (); |
2889 | if (wd) | |
2890 | comp_dir_attribute (wd); | |
340ccaab TW |
2891 | } |
2892 | ||
2893 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
2894 | { | |
2895 | sf_names_attribute (SFNAMES_BEGIN_LABEL); | |
2896 | src_info_attribute (SRCINFO_BEGIN_LABEL); | |
2897 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
2898 | mac_info_attribute (MACINFO_BEGIN_LABEL); | |
2899 | } | |
2900 | } | |
2901 | ||
2902 | static void | |
2903 | output_string_type_die (arg) | |
2904 | register void *arg; | |
2905 | { | |
2906 | register tree type = arg; | |
2907 | ||
2908 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type); | |
2909 | sibling_attribute (); | |
2910 | member_attribute (TYPE_CONTEXT (type)); | |
2911 | ||
2912 | /* Fudge the string length attribute for now. */ | |
2913 | ||
2914 | string_length_attribute ( | |
2915 | TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
2916 | } | |
2917 | ||
2918 | static void | |
2919 | output_structure_type_die (arg) | |
2920 | register void *arg; | |
2921 | { | |
2922 | register tree type = arg; | |
2923 | ||
2924 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); | |
2925 | sibling_attribute (); | |
2926 | equate_type_number_to_die_number (type); | |
2927 | name_attribute (type_tag (type)); | |
2928 | member_attribute (TYPE_CONTEXT (type)); | |
2929 | ||
2930 | /* If this type has been completed, then give it a byte_size attribute | |
2931 | and prepare to give a list of members. Otherwise, don't do either of | |
2932 | these things. In the latter case, we will not be generating a list | |
2933 | of members (since we don't have any idea what they might be for an | |
2934 | incomplete type). */ | |
2935 | ||
2936 | if (TYPE_SIZE (type)) | |
2937 | { | |
2938 | dienum_push (); | |
2939 | byte_size_attribute (type); | |
2940 | } | |
2941 | } | |
2942 | ||
2943 | /* Output a DIE to represent a declared function (either file-scope | |
2944 | or block-local) which has "internal linkage" (according to ANSI-C). */ | |
2945 | ||
2946 | static void | |
2947 | output_local_subroutine_die (arg) | |
2948 | register void *arg; | |
2949 | { | |
2950 | register tree decl = arg; | |
2951 | register tree type = TREE_TYPE (decl); | |
2952 | register tree return_type = TREE_TYPE (type); | |
2953 | char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2954 | ||
2955 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine); | |
2956 | sibling_attribute (); | |
2957 | dienum_push (); | |
9a631e8e | 2958 | name_and_src_coords_attributes (decl); |
340ccaab TW |
2959 | inline_attribute (decl); |
2960 | prototyped_attribute (type); | |
2961 | member_attribute (DECL_CONTEXT (decl)); | |
2962 | type_attribute (return_type, 0, 0); | |
2963 | ||
2964 | /* Avoid getting screwed up in cases where a function was declared static | |
2965 | but where no definition was ever given for it. */ | |
2966 | ||
2967 | if (TREE_ASM_WRITTEN (decl)) | |
2968 | { | |
9a631e8e | 2969 | low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
340ccaab TW |
2970 | sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); |
2971 | high_pc_attribute (func_end_label); | |
2972 | } | |
2973 | } | |
2974 | ||
2975 | static void | |
2976 | output_subroutine_type_die (arg) | |
2977 | register void *arg; | |
2978 | { | |
2979 | register tree type = arg; | |
2980 | register tree return_type = TREE_TYPE (type); | |
2981 | ||
2982 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type); | |
2983 | sibling_attribute (); | |
2984 | dienum_push (); | |
2985 | equate_type_number_to_die_number (type); | |
2986 | prototyped_attribute (type); | |
2987 | member_attribute (TYPE_CONTEXT (type)); | |
2988 | type_attribute (return_type, 0, 0); | |
2989 | } | |
2990 | ||
2991 | static void | |
2992 | output_typedef_die (arg) | |
2993 | register void *arg; | |
2994 | { | |
2995 | register tree decl = arg; | |
2996 | register tree type = TREE_TYPE (decl); | |
2997 | ||
2998 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef); | |
2999 | sibling_attribute (); | |
9a631e8e | 3000 | name_and_src_coords_attributes (decl); |
340ccaab TW |
3001 | member_attribute (DECL_CONTEXT (decl)); |
3002 | type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
3003 | } | |
3004 | ||
3005 | static void | |
3006 | output_union_type_die (arg) | |
3007 | register void *arg; | |
3008 | { | |
3009 | register tree type = arg; | |
3010 | ||
3011 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); | |
3012 | sibling_attribute (); | |
3013 | equate_type_number_to_die_number (type); | |
3014 | name_attribute (type_tag (type)); | |
3015 | member_attribute (TYPE_CONTEXT (type)); | |
3016 | ||
3017 | /* If this type has been completed, then give it a byte_size attribute | |
3018 | and prepare to give a list of members. Otherwise, don't do either of | |
3019 | these things. In the latter case, we will not be generating a list | |
3020 | of members (since we don't have any idea what they might be for an | |
3021 | incomplete type). */ | |
3022 | ||
3023 | if (TYPE_SIZE (type)) | |
3024 | { | |
3025 | dienum_push (); | |
3026 | byte_size_attribute (type); | |
3027 | } | |
3028 | } | |
3029 | ||
3030 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
3031 | at the end of an (ANSI prototyped) formal parameters list. */ | |
3032 | ||
3033 | static void | |
3034 | output_unspecified_parameters_die (arg) | |
3035 | register void *arg; | |
3036 | { | |
3037 | register tree decl_or_type = arg; | |
3038 | ||
3039 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters); | |
3040 | sibling_attribute (); | |
3041 | ||
3042 | /* This kludge is here only for the sake of being compatible with what | |
3043 | the USL CI5 C compiler does. The specification of Dwarf Version 1 | |
3044 | doesn't say that TAG_unspecified_parameters DIEs should contain any | |
3045 | attributes other than the AT_sibling attribute, but they are certainly | |
3046 | allowed to contain additional attributes, and the CI5 compiler | |
3047 | generates AT_name, AT_fund_type, and AT_location attributes within | |
3048 | TAG_unspecified_parameters DIEs which appear in the child lists for | |
3049 | DIEs representing function definitions, so we do likewise here. */ | |
3050 | ||
3051 | if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type)) | |
3052 | { | |
3053 | name_attribute ("..."); | |
3054 | fund_type_attribute (FT_pointer); | |
3055 | /* location_attribute (?); */ | |
3056 | } | |
3057 | } | |
3058 | ||
3059 | static void | |
3060 | output_padded_null_die (arg) | |
3061 | register void *arg; | |
3062 | { | |
3063 | ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */ | |
3064 | } | |
3065 | ||
3066 | /*************************** end of DIEs *********************************/ | |
3067 | ||
3068 | /* Generate some type of DIE. This routine generates the generic outer | |
3069 | wrapper stuff which goes around all types of DIE's (regardless of their | |
3070 | TAGs. All forms of DIEs start with a DIE-specific label, followed by a | |
3071 | DIE-length word, followed by the guts of the DIE itself. After the guts | |
3072 | of the DIE, there must always be a terminator label for the DIE. */ | |
3073 | ||
3074 | static void | |
3075 | output_die (die_specific_output_function, param) | |
3076 | register void (*die_specific_output_function)(); | |
3077 | register void *param; | |
3078 | { | |
3079 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3080 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3081 | ||
3082 | current_dienum = NEXT_DIE_NUM; | |
3083 | NEXT_DIE_NUM = next_unused_dienum; | |
3084 | ||
3085 | sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
3086 | sprintf (end_label, DIE_END_LABEL_FMT, current_dienum); | |
3087 | ||
3088 | /* Write a label which will act as the name for the start of this DIE. */ | |
3089 | ||
3090 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
3091 | ||
3092 | /* Write the DIE-length word. */ | |
3093 | ||
3094 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
3095 | ||
3096 | /* Fill in the guts of the DIE. */ | |
3097 | ||
3098 | next_unused_dienum++; | |
3099 | die_specific_output_function (param); | |
3100 | ||
3101 | /* Write a label which will act as the name for the end of this DIE. */ | |
3102 | ||
3103 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
3104 | } | |
3105 | ||
3106 | static void | |
3107 | end_sibling_chain () | |
3108 | { | |
3109 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3110 | ||
3111 | current_dienum = NEXT_DIE_NUM; | |
3112 | NEXT_DIE_NUM = next_unused_dienum; | |
3113 | ||
3114 | sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
3115 | ||
3116 | /* Write a label which will act as the name for the start of this DIE. */ | |
3117 | ||
3118 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
3119 | ||
3120 | /* Write the DIE-length word. */ | |
3121 | ||
3122 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
3123 | ||
3124 | dienum_pop (); | |
3125 | } | |
3126 | \f | |
3127 | /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a | |
3128 | TAG_unspecified_parameters DIE) to represent the types of the formal | |
3129 | parameters as specified in some function type specification (except | |
3130 | for those which appear as part of a function *definition*). | |
3131 | ||
3132 | Note that we must be careful here to output all of the parameter DIEs | |
3133 | *before* we output any DIEs needed to represent the types of the formal | |
3134 | parameters. This keeps svr4 SDB happy because it (incorrectly) thinks | |
3135 | that the first non-parameter DIE it sees ends the formal parameter list. | |
3136 | */ | |
3137 | ||
3138 | static void | |
3139 | output_formal_types (function_or_method_type) | |
3140 | register tree function_or_method_type; | |
3141 | { | |
3142 | register tree link; | |
3143 | register tree formal_type; | |
3144 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
3145 | ||
3146 | /* In the case where we are generating a formal types list for a C++ | |
3147 | non-static member function type, skip over the first thing on the | |
3148 | TYPE_ARG_TYPES list because it only represents the type of the | |
3149 | hidden `this pointer'. The debugger should be able to figure | |
3150 | out (without being explicitly told) that this non-static member | |
3151 | function type takes a `this pointer' and should be able to figure | |
3152 | what the type of that hidden parameter is from the AT_member | |
3153 | attribute of the parent TAG_subroutine_type DIE. */ | |
3154 | ||
3155 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
3156 | first_parm_type = TREE_CHAIN (first_parm_type); | |
3157 | ||
3158 | /* Make our first pass over the list of formal parameter types and output | |
3159 | a TAG_formal_parameter DIE for each one. */ | |
3160 | ||
3161 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
3162 | { | |
3163 | formal_type = TREE_VALUE (link); | |
3164 | if (formal_type == void_type_node) | |
3165 | break; | |
3166 | ||
3167 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
3168 | ||
3169 | output_die (output_formal_parameter_die, formal_type); | |
3170 | } | |
3171 | ||
3172 | /* If this function type has an ellipsis, add a TAG_unspecified_parameters | |
3173 | DIE to the end of the parameter list. */ | |
3174 | ||
3175 | if (formal_type != void_type_node) | |
3176 | output_die (output_unspecified_parameters_die, function_or_method_type); | |
3177 | ||
3178 | /* Make our second (and final) pass over the list of formal parameter types | |
3179 | and output DIEs to represent those types (as necessary). */ | |
3180 | ||
3181 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
3182 | link; | |
3183 | link = TREE_CHAIN (link)) | |
3184 | { | |
3185 | formal_type = TREE_VALUE (link); | |
3186 | if (formal_type == void_type_node) | |
3187 | break; | |
3188 | ||
3189 | output_type (formal_type, function_or_method_type); | |
3190 | } | |
3191 | } | |
3192 | \f | |
3193 | /* Remember a type in the pending_types_list. */ | |
3194 | ||
3195 | static void | |
3196 | pend_type (type) | |
3197 | register tree type; | |
3198 | { | |
3199 | if (pending_types == pending_types_allocated) | |
3200 | { | |
3201 | pending_types_allocated += PENDING_TYPES_INCREMENT; | |
3202 | pending_types_list | |
3203 | = (tree *) xrealloc (pending_types_list, | |
3204 | sizeof (tree) * pending_types_allocated); | |
3205 | } | |
3206 | pending_types_list[pending_types++] = type; | |
3207 | ||
3208 | /* Mark the pending type as having been output already (even though | |
3209 | it hasn't been). This prevents the type from being added to the | |
3210 | pending_types_list more than once. */ | |
3211 | ||
3212 | TREE_ASM_WRITTEN (type) = 1; | |
3213 | } | |
3214 | ||
3215 | /* Return non-zero if it is legitimate to output DIEs to represent a | |
3216 | given type while we are generating the list of child DIEs for some | |
3217 | DIE associated with a given scope. | |
3218 | ||
3219 | This function returns non-zero if *either* of the following two conditions | |
3220 | is satisfied: | |
3221 | ||
3222 | o the type actually belongs to the given scope (as evidenced | |
3223 | by its TYPE_CONTEXT value), or | |
3224 | ||
3225 | o the type is anonymous, and the `scope' in question is *not* | |
3226 | a RECORD_TYPE or UNION_TYPE. | |
3227 | ||
3228 | In theory, we should be able to generate DIEs for anonymous types | |
3229 | *anywhere* (since the scope of an anonymous type is irrelevant) | |
3230 | however svr4 SDB doesn't want to see other type DIEs within the | |
3231 | lists of child DIEs for a TAG_structure_type or TAG_union_type DIE. | |
3232 | ||
3233 | Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope) | |
3234 | or it may point to a BLOCK node (for types local to a block), or to a | |
3235 | FUNCTION_DECL node (for types local to the heading of some function | |
3236 | definition), or to a FUNCTION_TYPE node (for types local to the | |
3237 | prototyped parameter list of a function type specification), or to a | |
3238 | RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types). | |
3239 | ||
3240 | The `scope' parameter should likewise be NULL or should point to a | |
3241 | BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE | |
3242 | node, or a UNION_TYPE node. | |
3243 | ||
3244 | This function is used only for deciding when to "pend" and when to | |
3245 | "un-pend" types to/from the pending_types_list. | |
3246 | ||
3247 | Note that we sometimes make use of this "type pending" feature in a | |
3248 | rather twisted way to temporarily delay the production of DIEs for the | |
3249 | types of formal parameters. (We do this just to make svr4 SDB happy.) | |
3250 | It order to delay the production of DIEs representing types of formal | |
3251 | parameters, callers of this function supply `fake_containing_scope' as | |
3252 | the `scope' parameter to this function. Given that fake_containing_scope | |
3253 | is *not* the containing scope for *any* other type, the desired effect | |
3254 | is achieved, i.e. output of DIEs representing types is temporarily | |
3255 | suspended, and any type DIEs which would have been output otherwise | |
3256 | are instead placed onto the pending_types_list. Later on, we can force | |
3257 | these (temporarily pended) types to be output simply by calling | |
3258 | `output_pending_types_for_scope' with an actual argument equal to the | |
3259 | true scope of the types we temporarily pended. | |
3260 | */ | |
3261 | ||
3262 | static int | |
3263 | type_ok_for_scope (type, scope) | |
3264 | register tree type; | |
3265 | register tree scope; | |
3266 | { | |
3267 | return (TYPE_CONTEXT (type) == scope | |
3268 | || (TYPE_NAME (type) == NULL | |
3269 | && TREE_CODE (scope) != RECORD_TYPE | |
3270 | && TREE_CODE (scope) != UNION_TYPE)); | |
3271 | } | |
3272 | ||
3273 | /* Output any pending types (from the pending_types list) which we can output | |
3274 | now (given the limitations of the scope that we are working on now). | |
3275 | ||
3276 | For each type output, remove the given type from the pending_types_list | |
3277 | *before* we try to output it. | |
3278 | ||
3279 | Note that we have to process the list in beginning-to-end order, | |
3280 | because the call made here to output_type may cause yet more types | |
3281 | to be added to the end of the list, and we may have to output some | |
3282 | of them too. | |
3283 | */ | |
3284 | ||
3285 | static void | |
3286 | output_pending_types_for_scope (containing_scope) | |
3287 | register tree containing_scope; | |
3288 | { | |
3289 | register unsigned i; | |
3290 | ||
3291 | for (i = 0; i < pending_types; ) | |
3292 | { | |
3293 | register tree type = pending_types_list[i]; | |
3294 | ||
3295 | if (type_ok_for_scope (type, containing_scope)) | |
3296 | { | |
3297 | register tree *mover; | |
3298 | register tree *limit; | |
3299 | ||
3300 | pending_types--; | |
3301 | limit = &pending_types_list[pending_types]; | |
3302 | for (mover = &pending_types_list[i]; mover < limit; mover++) | |
3303 | *mover = *(mover+1); | |
3304 | ||
3305 | /* Un-mark the type as having been output already (because it | |
3306 | hasn't been, really). Then call output_type to generate a | |
3307 | Dwarf representation of it. */ | |
3308 | ||
3309 | TREE_ASM_WRITTEN (type) = 0; | |
3310 | output_type (type, containing_scope); | |
3311 | ||
3312 | /* Don't increment the loop counter in this case because we | |
3313 | have shifted all of the subsequent pending types down one | |
3314 | element in the pending_types_list array. */ | |
3315 | } | |
3316 | else | |
3317 | i++; | |
3318 | } | |
3319 | } | |
3320 | ||
3321 | static void | |
3322 | output_type (type, containing_scope) | |
3323 | register tree type; | |
3324 | register tree containing_scope; | |
3325 | { | |
3326 | if (type == 0 || type == error_mark_node) | |
3327 | return; | |
3328 | ||
3329 | /* We are going to output a DIE to represent the unqualified version of | |
3330 | of this type (i.e. without any const or volatile qualifiers) so get | |
3331 | the main variant (i.e. the unqualified version) of this type now. */ | |
3332 | ||
3333 | type = TYPE_MAIN_VARIANT (type); | |
3334 | ||
3335 | if (TREE_ASM_WRITTEN (type)) | |
3336 | return; | |
3337 | ||
3338 | /* Don't generate any DIEs for this type now unless it is OK to do so | |
3339 | (based upon what `type_ok_for_scope' tells us). */ | |
3340 | ||
3341 | if (! type_ok_for_scope (type, containing_scope)) | |
3342 | { | |
3343 | pend_type (type); | |
3344 | return; | |
3345 | } | |
3346 | ||
3347 | switch (TREE_CODE (type)) | |
3348 | { | |
3349 | case ERROR_MARK: | |
3350 | break; | |
3351 | ||
3352 | case POINTER_TYPE: | |
3353 | case REFERENCE_TYPE: | |
3354 | /* For these types, all that is required is that we output a DIE | |
3355 | (or a set of DIEs) to represent that "basis" type. */ | |
3356 | output_type (TREE_TYPE (type), containing_scope); | |
3357 | break; | |
3358 | ||
3359 | case OFFSET_TYPE: | |
3360 | /* This code is used for C++ pointer-to-data-member types. */ | |
3361 | /* Output a description of the relevant class type. */ | |
3362 | output_type (TYPE_OFFSET_BASETYPE (type), containing_scope); | |
3363 | /* Output a description of the type of the object pointed to. */ | |
3364 | output_type (TREE_TYPE (type), containing_scope); | |
3365 | /* Now output a DIE to represent this pointer-to-data-member type | |
3366 | itself. */ | |
3367 | output_die (output_ptr_to_mbr_type_die, type); | |
3368 | break; | |
3369 | ||
3370 | case SET_TYPE: | |
3371 | output_type (TREE_TYPE (type), containing_scope); | |
3372 | output_die (output_set_type_die, type); | |
3373 | break; | |
3374 | ||
3375 | case FILE_TYPE: | |
3376 | output_type (TREE_TYPE (type), containing_scope); | |
3377 | abort (); /* No way to reprsent these in Dwarf yet! */ | |
3378 | break; | |
3379 | ||
3380 | case STRING_TYPE: | |
3381 | output_type (TREE_TYPE (type), containing_scope); | |
3382 | output_die (output_string_type_die, type); | |
3383 | break; | |
3384 | ||
3385 | case FUNCTION_TYPE: | |
3386 | /* Force out return type (in case it wasn't forced out already). */ | |
3387 | output_type (TREE_TYPE (type), containing_scope); | |
3388 | output_die (output_subroutine_type_die, type); | |
3389 | output_formal_types (type); | |
3390 | end_sibling_chain (); | |
3391 | break; | |
3392 | ||
3393 | case METHOD_TYPE: | |
3394 | /* Force out return type (in case it wasn't forced out already). */ | |
3395 | output_type (TREE_TYPE (type), containing_scope); | |
3396 | output_die (output_subroutine_type_die, type); | |
3397 | output_formal_types (type); | |
3398 | end_sibling_chain (); | |
3399 | break; | |
3400 | ||
3401 | case ARRAY_TYPE: | |
3402 | { | |
3403 | register tree element_type; | |
3404 | ||
3405 | element_type = TREE_TYPE (type); | |
3406 | while (TREE_CODE (element_type) == ARRAY_TYPE) | |
3407 | element_type = TREE_TYPE (element_type); | |
3408 | ||
3409 | output_type (element_type, containing_scope); | |
3410 | output_die (output_array_type_die, type); | |
3411 | } | |
3412 | break; | |
3413 | ||
3414 | case ENUMERAL_TYPE: | |
3415 | case RECORD_TYPE: | |
3416 | case UNION_TYPE: | |
3417 | ||
3418 | /* For a non-file-scope tagged type, we can always go ahead and | |
3419 | output a Dwarf description of this type right now, even if | |
3420 | the type in question is still incomplete, because if this | |
3421 | local type *was* ever completed anywhere within its scope, | |
3422 | that complete definition would already have been attached to | |
3423 | this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the | |
3424 | time we reach this point. That's true because of the way the | |
3425 | front-end does its processing of file-scope declarations (of | |
3426 | functions and class types) within which other types might be | |
3427 | nested. The C and C++ front-ends always gobble up such "local | |
3428 | scope" things en-mass before they try to output *any* debugging | |
3429 | information for any of the stuff contained inside them and thus, | |
3430 | we get the benefit here of what is (in effect) a pre-resolution | |
3431 | of forward references to tagged types in local scopes. | |
3432 | ||
3433 | Note however that for file-scope tagged types we cannot assume | |
3434 | that such pre-resolution of forward references has taken place. | |
3435 | A given file-scope tagged type may appear to be incomplete when | |
3436 | we reach this point, but it may yet be given a full definition | |
3437 | (at file-scope) later on during compilation. In order to avoid | |
3438 | generating a premature (and possibly incorrect) set of Dwarf | |
3439 | DIEs for such (as yet incomplete) file-scope tagged types, we | |
3440 | generate nothing at all for as-yet incomplete file-scope tagged | |
3441 | types here unless we are making our special "finalization" pass | |
3442 | for file-scope things at the very end of compilation. At that | |
3443 | time, we will certainly know as much about each file-scope tagged | |
3444 | type as we are ever going to know, so at that point in time, we | |
3445 | can safely generate correct Dwarf descriptions for these file- | |
3446 | scope tagged types. | |
3447 | */ | |
3448 | ||
3449 | if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing) | |
3450 | return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */ | |
3451 | ||
3452 | /* Prevent infinite recursion in cases where the type of some | |
3453 | member of this type is expressed in terms of this type itself. */ | |
3454 | ||
3455 | TREE_ASM_WRITTEN (type) = 1; | |
3456 | ||
3457 | /* Output a DIE to represent the tagged type itself. */ | |
3458 | ||
3459 | switch (TREE_CODE (type)) | |
3460 | { | |
3461 | case ENUMERAL_TYPE: | |
3462 | output_die (output_enumeration_type_die, type); | |
3463 | return; /* a special case -- nothing left to do so just return */ | |
3464 | ||
3465 | case RECORD_TYPE: | |
3466 | output_die (output_structure_type_die, type); | |
3467 | break; | |
3468 | ||
3469 | case UNION_TYPE: | |
3470 | output_die (output_union_type_die, type); | |
3471 | break; | |
3472 | } | |
3473 | ||
3474 | /* If this is not an incomplete type, output descriptions of | |
3475 | each of its members. | |
3476 | ||
3477 | Note that as we output the DIEs necessary to represent the | |
3478 | members of this record or union type, we will also be trying | |
3479 | to output DIEs to represent the *types* of those members. | |
3480 | However the `output_type' function (above) will specifically | |
3481 | avoid generating type DIEs for member types *within* the list | |
3482 | of member DIEs for this (containing) type execpt for those | |
3483 | types (of members) which are explicitly marked as also being | |
3484 | members of this (containing) type themselves. The g++ front- | |
3485 | end can force any given type to be treated as a member of some | |
3486 | other (containing) type by setting the TYPE_CONTEXT of the | |
3487 | given (member) type to point to the TREE node representing the | |
3488 | appropriate (containing) type. | |
3489 | */ | |
3490 | ||
3491 | if (TYPE_SIZE (type)) | |
3492 | { | |
9a631e8e RS |
3493 | { |
3494 | register tree normal_member; | |
340ccaab | 3495 | |
9a631e8e | 3496 | /* First output info about the data members and type members. */ |
340ccaab | 3497 | |
9a631e8e RS |
3498 | for (normal_member = TYPE_FIELDS (type); |
3499 | normal_member; | |
3500 | normal_member = TREE_CHAIN (normal_member)) | |
3501 | output_decl (normal_member, type); | |
3502 | } | |
340ccaab | 3503 | |
9a631e8e RS |
3504 | { |
3505 | register tree vec_base; | |
3506 | ||
3507 | /* Now output info about the function members (if any). */ | |
3508 | ||
3509 | vec_base = TYPE_METHODS (type); | |
3510 | if (vec_base) | |
3511 | { | |
3512 | register tree first_func_member = TREE_VEC_ELT (vec_base, 0); | |
3513 | register tree func_member; | |
3514 | ||
3515 | /* This isn't documented, but the first element of the | |
3516 | vector of member functions can be NULL in cases where | |
3517 | the class type in question didn't have either a | |
3518 | constructor or a destructor declared for it. We have | |
3519 | to make allowances for that here. */ | |
3520 | ||
3521 | if (first_func_member == NULL) | |
3522 | first_func_member = TREE_VEC_ELT (vec_base, 1); | |
3523 | ||
3524 | for (func_member = first_func_member; | |
3525 | func_member; | |
3526 | func_member = TREE_CHAIN (func_member)) | |
3527 | output_decl (func_member, type); | |
3528 | } | |
3529 | } | |
340ccaab TW |
3530 | |
3531 | end_sibling_chain (); /* Terminate member chain. */ | |
3532 | } | |
3533 | ||
3534 | break; | |
3535 | ||
3536 | case VOID_TYPE: | |
3537 | case INTEGER_TYPE: | |
3538 | case REAL_TYPE: | |
3539 | case COMPLEX_TYPE: | |
3540 | case BOOLEAN_TYPE: | |
3541 | case CHAR_TYPE: | |
3542 | break; /* No DIEs needed for fundamental types. */ | |
3543 | ||
3544 | case LANG_TYPE: /* No Dwarf representation currently defined. */ | |
3545 | break; | |
3546 | ||
3547 | default: | |
3548 | abort (); | |
3549 | } | |
3550 | ||
3551 | TREE_ASM_WRITTEN (type) = 1; | |
3552 | } | |
3553 | \f | |
3554 | /* Output a TAG_lexical_block DIE followed by DIEs to represent all of | |
3555 | the things which are local to the given block. */ | |
3556 | ||
3557 | static void | |
3558 | output_block (stmt) | |
3559 | register tree stmt; | |
3560 | { | |
3561 | register int have_significant_locals = 0; | |
3562 | ||
3563 | /* Ignore blocks never really used to make RTL. */ | |
3564 | ||
3565 | if (! stmt || ! TREE_USED (stmt)) | |
3566 | return; | |
3567 | ||
3568 | /* Determine if this block contains any "significant" local declarations | |
3569 | which we need to output DIEs for. */ | |
3570 | ||
3571 | if (BLOCK_INLINE_FUNCTION (stmt)) | |
3572 | /* The outer scopes for inlinings *must* always be represented. */ | |
3573 | have_significant_locals = 1; | |
3574 | else | |
3575 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
3576 | have_significant_locals = (BLOCK_VARS (stmt) != NULL); | |
3577 | else | |
3578 | { | |
3579 | register tree decl; | |
3580 | ||
3581 | for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) | |
3582 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) | |
3583 | { | |
3584 | have_significant_locals = 1; | |
3585 | break; | |
3586 | } | |
3587 | } | |
3588 | ||
3589 | /* It would be a waste of space to generate a Dwarf TAG_lexical_block | |
3590 | DIE for any block which contains no significant local declarations | |
3591 | at all. Rather, in such cases we just call `output_decls_for_scope' | |
3592 | so that any needed Dwarf info for any sub-blocks will get properly | |
3593 | generated. Note that in terse mode, our definition of what constitutes | |
3594 | a "significant" local declaration gets restricted to include only | |
3595 | inlined function instances and local (nested) function definitions. */ | |
3596 | ||
3597 | if (have_significant_locals) | |
3598 | { | |
3599 | output_die (BLOCK_INLINE_FUNCTION (stmt) | |
3600 | ? output_inlined_subroutine_die | |
3601 | : output_lexical_block_die, | |
3602 | stmt); | |
3603 | output_decls_for_scope (stmt); | |
3604 | end_sibling_chain (); | |
3605 | } | |
3606 | else | |
3607 | output_decls_for_scope (stmt); | |
3608 | } | |
3609 | ||
3610 | /* Output all of the decls declared within a given scope (also called | |
3611 | a `binding contour') and (recursively) all of it's sub-blocks. */ | |
3612 | ||
3613 | static void | |
3614 | output_decls_for_scope (stmt) | |
3615 | register tree stmt; | |
3616 | { | |
3617 | /* Ignore blocks never really used to make RTL. */ | |
3618 | ||
3619 | if (! stmt || ! TREE_USED (stmt)) | |
3620 | return; | |
3621 | ||
3622 | next_block_number++; | |
3623 | ||
3624 | /* Output the DIEs to represent all of the data objects, functions, | |
3625 | typedefs, and tagged types declared directly within this block | |
3626 | but not within any nested sub-blocks. */ | |
3627 | ||
3628 | { | |
3629 | register tree decl; | |
3630 | ||
3631 | for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) | |
3632 | output_decl (decl, stmt); | |
3633 | } | |
3634 | ||
3635 | output_pending_types_for_scope (stmt); | |
3636 | ||
3637 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
3638 | therein) of this block. */ | |
3639 | ||
3640 | { | |
3641 | register tree subblocks; | |
3642 | ||
3643 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
3644 | subblocks; | |
3645 | subblocks = BLOCK_CHAIN (subblocks)) | |
3646 | output_block (subblocks); | |
3647 | } | |
3648 | } | |
3649 | ||
3650 | /* Output Dwarf .debug information for a decl described by DECL. */ | |
3651 | ||
3652 | static void | |
3653 | output_decl (decl, containing_scope) | |
3654 | register tree decl; | |
3655 | register tree containing_scope; | |
3656 | { | |
3657 | switch (TREE_CODE (decl)) | |
3658 | { | |
3659 | case ERROR_MARK: | |
3660 | break; | |
3661 | ||
3662 | case CONST_DECL: | |
3663 | /* The individual enumerators of an enum type get output when we | |
3664 | output the Dwarf representation of the relevant enum type itself. */ | |
3665 | break; | |
3666 | ||
3667 | case FUNCTION_DECL: | |
3668 | /* If we are in terse mode, don't output any DIEs to represent | |
3669 | mere external function declarations. */ | |
3670 | ||
3671 | if (TREE_EXTERNAL (decl) && debug_info_level <= DINFO_LEVEL_TERSE) | |
3672 | break; | |
3673 | ||
3674 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
3675 | have described its return type. */ | |
3676 | ||
3677 | output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope); | |
3678 | ||
3679 | /* If the following DIE will represent a function definition for a | |
3680 | function with "extern" linkage, output a special "pubnames" DIE | |
3681 | label just ahead of the actual DIE. A reference to this label | |
3682 | was already generated in the .debug_pubnames section sub-entry | |
3683 | for this function definition. */ | |
3684 | ||
3685 | if (TREE_PUBLIC (decl)) | |
3686 | { | |
3687 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3688 | ||
3689 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); | |
3690 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3691 | } | |
3692 | ||
3693 | /* Now output a DIE to represent the function itself. */ | |
3694 | ||
3695 | output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl) | |
3696 | ? output_global_subroutine_die | |
3697 | : output_local_subroutine_die, | |
3698 | decl); | |
3699 | ||
3700 | /* Now output descriptions of the arguments for this function. | |
3701 | This gets (unnecessarily?) complex because of the fact that | |
3702 | the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate | |
3703 | cases where there was a trailing `...' at the end of the formal | |
3704 | parameter list. In order to find out if there was a trailing | |
3705 | ellipsis or not, we must instead look at the type associated | |
3706 | with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE. | |
3707 | If the chain of type nodes hanging off of this FUNCTION_TYPE node | |
3708 | ends with a void_type_node then there should *not* be an ellipsis | |
3709 | at the end. */ | |
3710 | ||
3711 | /* In the case where we are describing an external function, all | |
3712 | we need to do here (and all we *can* do here) is to describe | |
3713 | the *types* of its formal parameters. */ | |
3714 | ||
3715 | if (TREE_EXTERNAL (decl)) | |
3716 | output_formal_types (TREE_TYPE (decl)); | |
3717 | else | |
3718 | { | |
3719 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
3720 | ||
3721 | /* In the case where the FUNCTION_DECL represents a C++ non-static | |
3722 | member function, skip over the first thing on the DECL_ARGUMENTS | |
3723 | chain. It only represents the hidden `this pointer' parameter | |
3724 | and the debugger should know implicitly that non-static member | |
3725 | functions have such a thing, and should be able to figure out | |
3726 | exactly what the type of each `this pointer' is (from the | |
3727 | AT_member attribute of the parent TAG_subroutine DIE) without | |
3728 | being explicitly told. */ | |
3729 | ||
3730 | if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
3731 | arg_decls = TREE_CHAIN (arg_decls); | |
3732 | ||
3733 | { | |
3734 | register tree last_arg; | |
3735 | ||
3736 | last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK) | |
3737 | ? tree_last (arg_decls) | |
3738 | : NULL; | |
3739 | ||
3740 | /* Generate DIEs to represent all known formal parameters, but | |
3741 | don't do it if this looks like a varargs function. A given | |
3742 | function is considered to be a varargs function if (and only | |
3743 | if) its last named argument is named `__builtin_va_alist'. */ | |
3744 | ||
3745 | if (! last_arg | |
3746 | || ! DECL_NAME (last_arg) | |
3747 | || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)), | |
3748 | "__builtin_va_alist")) | |
3749 | { | |
3750 | register tree parm; | |
3751 | ||
3752 | /* WARNING! Kludge zone ahead! Here we have a special | |
2e494f70 | 3753 | hack for svr4 SDB compatibility. Instead of passing the |
340ccaab TW |
3754 | current FUNCTION_DECL node as the second parameter (i.e. |
3755 | the `containing_scope' parameter) to `output_decl' (as | |
3756 | we ought to) we instead pass a pointer to our own private | |
3757 | fake_containing_scope node. That node is a RECORD_TYPE | |
3758 | node which NO OTHER TYPE may ever actually be a member of. | |
3759 | ||
3760 | This pointer will ultimately get passed into `output_type' | |
3761 | as its `containing_scope' parameter. `Output_type' will | |
3762 | then perform its part in the hack... i.e. it will pend | |
3763 | the type of the formal parameter onto the pending_types | |
3764 | list. Later on, when we are done generating the whole | |
3765 | sequence of formal parameter DIEs for this function | |
3766 | definition, we will un-pend all previously pended types | |
3767 | of formal parameters for this function definition. | |
3768 | ||
3769 | This whole kludge prevents any type DIEs from being | |
3770 | mixed in with the formal parameter DIEs. That's good | |
3771 | because svr4 SDB believes that the list of formal | |
3772 | parameter DIEs for a function ends wherever the first | |
3773 | non-formal-parameter DIE appears. Thus, we have to | |
3774 | keep the formal parameter DIEs segregated. They must | |
3775 | all appear (consecutively) at the start of the list of | |
3776 | children for the DIE representing the function definition. | |
3777 | Then (and only then) may we output any additional DIEs | |
3778 | needed to represent the types of these formal parameters. | |
3779 | */ | |
3780 | ||
3781 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
3782 | if (TREE_CODE (parm) == PARM_DECL) | |
3783 | output_decl (parm, fake_containing_scope); | |
3784 | ||
3785 | /* Now that we have finished generating all of the DIEs to | |
3786 | represent the formal parameters themselves, force out | |
3787 | any DIEs needed to represent their types. We do this | |
3788 | simply by un-pending all previously pended types which | |
3789 | can legitimately go into the chain of children DIEs for | |
3790 | the current FUNCTION_DECL. */ | |
3791 | ||
3792 | output_pending_types_for_scope (decl); | |
3793 | } | |
3794 | } | |
3795 | ||
3796 | /* Now try to decide if we should put an ellipsis at the end. */ | |
3797 | ||
3798 | { | |
3799 | register int has_ellipsis = TRUE; /* default assumption */ | |
3800 | register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
3801 | ||
3802 | if (fn_arg_types) | |
3803 | { | |
3804 | /* This function declaration/definition was prototyped. */ | |
3805 | ||
3806 | /* If the list of formal argument types ends with a | |
3807 | void_type_node, then the formals list did *not* end | |
3808 | with an ellipsis. */ | |
3809 | ||
3810 | if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node) | |
3811 | has_ellipsis = FALSE; | |
3812 | } | |
3813 | else | |
3814 | { | |
3815 | /* This function declaration/definition was not prototyped. */ | |
3816 | ||
3817 | /* Note that all non-prototyped function *declarations* are | |
3818 | assumed to represent varargs functions (until proven | |
3819 | otherwise). */ | |
3820 | ||
3821 | if (DECL_INITIAL (decl)) /* if this is a func definition */ | |
3822 | { | |
3823 | if (!arg_decls) | |
3824 | has_ellipsis = FALSE; /* no args == (void) */ | |
3825 | else | |
3826 | { | |
3827 | /* For a non-prototyped function definition which | |
3828 | declares one or more formal parameters, if the name | |
3829 | of the first formal parameter is *not* | |
3830 | __builtin_va_alist then we must assume that this | |
3831 | is *not* a varargs function. */ | |
3832 | ||
3833 | if (DECL_NAME (arg_decls) | |
3834 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)), | |
3835 | "__builtin_va_alist")) | |
3836 | has_ellipsis = FALSE; | |
3837 | } | |
3838 | } | |
3839 | } | |
3840 | ||
3841 | if (has_ellipsis) | |
3842 | output_die (output_unspecified_parameters_die, decl); | |
3843 | } | |
3844 | } | |
3845 | ||
3846 | /* Output Dwarf info for all of the stuff within the body of the | |
3847 | function (if it has one - it may be just a declaration). */ | |
3848 | ||
3849 | { | |
3850 | register tree outer_scope = DECL_INITIAL (decl); | |
3851 | ||
3852 | if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) | |
3853 | { | |
3854 | /* Note that here, `outer_scope' is a pointer to the outermost | |
3855 | BLOCK node created to represent the body of a function. | |
3856 | This outermost BLOCK actually represents the outermost | |
3857 | binding contour for the function, i.e. the contour in which | |
3858 | the function's formal parameters get declared. Just within | |
3859 | this contour, there will be another (nested) BLOCK which | |
3860 | represents the function's outermost block. We don't want | |
3861 | to generate a lexical_block DIE to represent the outermost | |
3862 | block of a function body, because that is not really an | |
3863 | independent scope according to ANSI C rules. Rather, it is | |
3864 | the same scope in which the parameters were declared and | |
3865 | for Dwarf, we do not generate a TAG_lexical_block DIE for | |
3866 | that scope. We must however see to it that the LABEL_DECLs | |
3867 | associated with `outer_scope' get DIEs generated for them. */ | |
3868 | ||
3869 | { | |
3870 | register tree label; | |
3871 | ||
3872 | for (label = BLOCK_VARS (outer_scope); | |
3873 | label; | |
3874 | label = TREE_CHAIN (label)) | |
3875 | output_decl (label, outer_scope); | |
3876 | } | |
3877 | ||
3878 | output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope)); | |
3879 | ||
3880 | /* Finally, force out any pending types which are local to the | |
3881 | outermost block of this function definition. These will | |
3882 | all have a TYPE_CONTEXT which points to the FUNCTION_DECL | |
3883 | node itself. */ | |
3884 | ||
3885 | output_pending_types_for_scope (decl); | |
3886 | } | |
3887 | } | |
3888 | ||
3889 | /* Generate a terminator for the list of stuff `owned' by this | |
3890 | function. */ | |
3891 | ||
3892 | end_sibling_chain (); | |
3893 | ||
3894 | break; | |
3895 | ||
3896 | case TYPE_DECL: | |
3897 | /* If we are in terse mode, don't generate any DIEs to represent | |
3898 | any actual typedefs. Note that even when we are in terse mode, | |
3899 | we must still output DIEs to represent those tagged types which | |
3900 | are used (directly or indirectly) in the specification of either | |
3901 | a return type or a formal parameter type of some function. */ | |
3902 | ||
3903 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
3904 | if (DECL_NAME (decl) != NULL | |
3905 | || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) | |
3906 | return; | |
3907 | ||
3908 | output_type (TREE_TYPE (decl), containing_scope); | |
3909 | ||
3910 | /* Note that unlike the gcc front end (which generates a NULL named | |
3911 | TYPE_DECL node for each complete tagged type, each array type, | |
3912 | and each function type node created) the g++ front end generates | |
3913 | a *named* TYPE_DECL node for each tagged type node created. | |
3914 | Unfortunately, these g++ TYPE_DECL nodes cause us to output many | |
3915 | superfluous and unnecessary TAG_typedef DIEs here. When g++ is | |
3916 | fixed to stop generating these superfluous named TYPE_DECL nodes, | |
3917 | the superfluous TAG_typedef DIEs will likewise cease. */ | |
3918 | ||
3919 | if (DECL_NAME (decl)) | |
3920 | /* Output a DIE to represent the typedef itself. */ | |
3921 | output_die (output_typedef_die, decl); | |
3922 | break; | |
3923 | ||
3924 | case LABEL_DECL: | |
3925 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
3926 | output_die (output_label_die, decl); | |
3927 | break; | |
3928 | ||
3929 | case VAR_DECL: | |
3930 | /* If we are in terse mode, don't generate any DIEs to represent | |
3931 | any variable declarations or definitions. */ | |
3932 | ||
3933 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
3934 | break; | |
3935 | ||
3936 | /* Output any DIEs that are needed to specify the type of this data | |
3937 | object. */ | |
3938 | ||
3939 | output_type (TREE_TYPE (decl), containing_scope); | |
3940 | ||
3941 | /* If the following DIE will represent a data object definition for a | |
3942 | data object with "extern" linkage, output a special "pubnames" DIE | |
3943 | label just ahead of the actual DIE. A reference to this label | |
3944 | was already generated in the .debug_pubnames section sub-entry | |
3945 | for this data object definition. */ | |
3946 | ||
3947 | if (TREE_PUBLIC (decl)) | |
3948 | { | |
3949 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3950 | ||
3951 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); | |
3952 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3953 | } | |
3954 | ||
3955 | /* Now output the DIE to represent the data object itself. */ | |
3956 | ||
3957 | output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl) | |
3958 | ? output_global_variable_die : output_local_variable_die, | |
3959 | decl); | |
3960 | break; | |
3961 | ||
3962 | case FIELD_DECL: | |
3963 | /* Ignore the nameless fields that are used to skip bits. */ | |
3964 | if (DECL_NAME (decl) != 0) | |
3965 | { | |
3966 | output_type (member_declared_type (decl), containing_scope); | |
3967 | output_die (output_member_die, decl); | |
3968 | } | |
3969 | break; | |
3970 | ||
3971 | case PARM_DECL: | |
3972 | /* Force out the type of this formal, if it was not forced out yet. | |
3973 | Note that here we can run afowl of a bug in "classic" svr4 SDB. | |
3974 | It should be able to grok the presence of type DIEs within a list | |
3975 | of TAG_formal_parameter DIEs, but it doesn't. */ | |
3976 | ||
3977 | output_type (TREE_TYPE (decl), containing_scope); | |
3978 | output_die (output_formal_parameter_die, decl); | |
3979 | break; | |
3980 | ||
3981 | default: | |
3982 | abort (); | |
3983 | } | |
3984 | } | |
3985 | \f | |
3986 | void | |
3987 | dwarfout_file_scope_decl (decl, set_finalizing) | |
3988 | register tree decl; | |
3989 | register int set_finalizing; | |
3990 | { | |
3991 | switch (TREE_CODE (decl)) | |
3992 | { | |
3993 | case FUNCTION_DECL: | |
3994 | ||
3995 | /* Ignore this FUNCTION_DECL if it refers to a builtin function. */ | |
3996 | ||
3997 | if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) | |
3998 | return; | |
3999 | ||
4000 | /* Ignore this FUNCTION_DECL if it refers to a file-scope extern | |
4001 | function declaration and if the declaration was never even | |
4002 | referenced from within this entire compilation unit. We | |
4003 | suppress these DIEs in order to save space in the .debug section | |
4004 | (by eliminating entries which are probably useless). Note that | |
4005 | we must not suppress block-local extern declarations (whether | |
4006 | used or not) because that would screw-up the debugger's name | |
4007 | lookup mechanism and cause it to miss things which really ought | |
4008 | to be in scope at a given point. */ | |
4009 | ||
4010 | if (TREE_EXTERNAL (decl) && !TREE_USED (decl)) | |
4011 | return; | |
4012 | ||
4013 | if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl)) | |
4014 | { | |
4015 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4016 | ||
4017 | /* Output a .debug_pubnames entry for a public function | |
4018 | defined in this compilation unit. */ | |
4019 | ||
4020 | fputc ('\n', asm_out_file); | |
85595d1a | 4021 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); |
340ccaab TW |
4022 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); |
4023 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
4024 | ASM_OUTPUT_DWARF_STRING (asm_out_file, | |
4025 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
85595d1a | 4026 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4027 | } |
4028 | ||
4029 | break; | |
4030 | ||
4031 | case VAR_DECL: | |
4032 | ||
4033 | /* Ignore this VAR_DECL if it refers to a file-scope extern data | |
4034 | object declaration and if the declaration was never even | |
4035 | referenced from within this entire compilation unit. We | |
4036 | suppress these DIEs in order to save space in the .debug section | |
4037 | (by eliminating entries which are probably useless). Note that | |
4038 | we must not suppress block-local extern declarations (whether | |
4039 | used or not) because that would screw-up the debugger's name | |
4040 | lookup mechanism and cause it to miss things which really ought | |
4041 | to be in scope at a given point. */ | |
4042 | ||
4043 | if (TREE_EXTERNAL (decl) && !TREE_USED (decl)) | |
4044 | return; | |
4045 | ||
4046 | if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl)) | |
4047 | { | |
4048 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4049 | ||
4050 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4051 | { | |
4052 | /* Output a .debug_pubnames entry for a public variable | |
4053 | defined in this compilation unit. */ | |
4054 | ||
4055 | fputc ('\n', asm_out_file); | |
85595d1a | 4056 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); |
340ccaab TW |
4057 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); |
4058 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
4059 | ASM_OUTPUT_DWARF_STRING (asm_out_file, | |
4060 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
85595d1a | 4061 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4062 | } |
4063 | ||
4064 | if (DECL_INITIAL (decl) == NULL) | |
4065 | { | |
4066 | /* Output a .debug_aranges entry for a public variable | |
4067 | which is tenatively defined in this compilation unit. */ | |
4068 | ||
4069 | fputc ('\n', asm_out_file); | |
85595d1a | 4070 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); |
340ccaab | 4071 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, |
9a631e8e | 4072 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
340ccaab TW |
4073 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, |
4074 | (unsigned) int_size_in_bytes (TREE_TYPE (decl))); | |
85595d1a | 4075 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4076 | } |
4077 | } | |
4078 | ||
4079 | /* If we are in terse mode, don't generate any DIEs to represent | |
4080 | any variable declarations or definitions. */ | |
4081 | ||
4082 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
4083 | return; | |
4084 | ||
4085 | break; | |
4086 | ||
4087 | case TYPE_DECL: | |
4088 | /* Don't generate any DIEs to represent the standard built-in types. */ | |
4089 | ||
4090 | if (DECL_SOURCE_LINE (decl) == 0) | |
4091 | return; | |
4092 | ||
4093 | /* If we are in terse mode, don't generate any DIEs to represent | |
4094 | any actual typedefs. Note that even when we are in terse mode, | |
4095 | we must still output DIEs to represent those tagged types which | |
4096 | are used (directly or indirectly) in the specification of either | |
4097 | a return type or a formal parameter type of some function. */ | |
4098 | ||
4099 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
4100 | if (DECL_NAME (decl) != NULL | |
4101 | || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) | |
4102 | return; | |
4103 | ||
4104 | break; | |
4105 | ||
4106 | default: | |
4107 | return; | |
4108 | } | |
4109 | ||
4110 | fputc ('\n', asm_out_file); | |
85595d1a | 4111 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
340ccaab TW |
4112 | finalizing = set_finalizing; |
4113 | output_decl (decl, NULL); | |
4114 | ||
4115 | /* NOTE: The call above to `output_decl' may have caused one or more | |
4116 | file-scope named types (i.e. tagged types) to be placed onto the | |
4117 | pending_types_list. We have to get those types off of that list | |
4118 | at some point, and this is the perfect time to do it. If we didn't | |
4119 | take them off now, they might still be on the list when cc1 finally | |
4120 | exits. That might be OK if it weren't for the fact that when we put | |
4121 | types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag | |
4122 | for these types, and that causes them never to be output unless | |
4123 | `output_pending_types_for_scope' takes them off of the list and un-sets | |
4124 | their TREE_ASM_WRITTEN flags. */ | |
4125 | ||
4126 | output_pending_types_for_scope (NULL); | |
4127 | ||
4128 | /* The above call should have totally emptied the pending_types_list. */ | |
4129 | ||
4130 | assert (pending_types == 0); | |
4131 | ||
85595d1a | 4132 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4133 | |
4134 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL) | |
4135 | current_funcdef_number++; | |
4136 | } | |
4137 | \f | |
4138 | /* Output a marker (i.e. a label) for the beginning of the generated code | |
4139 | for a lexical block. */ | |
4140 | ||
4141 | void | |
4142 | dwarfout_begin_block (blocknum) | |
4143 | register unsigned blocknum; | |
4144 | { | |
4145 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4146 | ||
4147 | text_section (); | |
4148 | sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); | |
4149 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4150 | } | |
4151 | ||
4152 | /* Output a marker (i.e. a label) for the end of the generated code | |
4153 | for a lexical block. */ | |
4154 | ||
4155 | void | |
4156 | dwarfout_end_block (blocknum) | |
4157 | register unsigned blocknum; | |
4158 | { | |
4159 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4160 | ||
4161 | text_section (); | |
4162 | sprintf (label, BLOCK_END_LABEL_FMT, blocknum); | |
4163 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4164 | } | |
4165 | ||
4166 | /* Output a marker (i.e. a label) at a point in the assembly code which | |
4167 | corresponds to a given source level label. */ | |
4168 | ||
4169 | void | |
4170 | dwarfout_label (insn) | |
4171 | register rtx insn; | |
4172 | { | |
4173 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4174 | { | |
4175 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4176 | ||
4177 | text_section (); | |
4178 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number, | |
4179 | (unsigned) INSN_UID (insn)); | |
4180 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4181 | } | |
4182 | } | |
4183 | ||
4184 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
4185 | for a function definition. This gets called *after* the epilogue code | |
4186 | has been generated. */ | |
4187 | ||
4188 | void | |
4189 | dwarfout_end_epilogue () | |
4190 | { | |
4191 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4192 | ||
4193 | /* Output a label to mark the endpoint of the code generated for this | |
4194 | function. */ | |
4195 | ||
4196 | sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); | |
4197 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4198 | } | |
4199 | ||
4200 | static void | |
4201 | shuffle_filename_entry (new_zeroth) | |
4202 | register filename_entry *new_zeroth; | |
4203 | { | |
4204 | filename_entry temp_entry; | |
4205 | register filename_entry *limit_p; | |
4206 | register filename_entry *move_p; | |
4207 | ||
4208 | if (new_zeroth == &filename_table[0]) | |
4209 | return; | |
4210 | ||
4211 | temp_entry = *new_zeroth; | |
4212 | ||
4213 | /* Shift entries up in the table to make room at [0]. */ | |
4214 | ||
4215 | limit_p = &filename_table[0]; | |
4216 | for (move_p = new_zeroth; move_p > limit_p; move_p--) | |
4217 | *move_p = *(move_p-1); | |
4218 | ||
4219 | /* Install the found entry at [0]. */ | |
4220 | ||
4221 | filename_table[0] = temp_entry; | |
4222 | } | |
4223 | ||
4224 | /* Create a new (string) entry for the .debug_sfnames section. */ | |
4225 | ||
4226 | static void | |
4227 | generate_new_sfname_entry () | |
4228 | { | |
4229 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4230 | ||
4231 | fputc ('\n', asm_out_file); | |
85595d1a | 4232 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION); |
340ccaab TW |
4233 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number); |
4234 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4235 | ASM_OUTPUT_DWARF_STRING (asm_out_file, | |
4236 | filename_table[0].name | |
4237 | ? filename_table[0].name | |
4238 | : ""); | |
85595d1a | 4239 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4240 | } |
4241 | ||
4242 | /* Lookup a filename (in the list of filenames that we know about here in | |
4243 | dwarfout.c) and return its "index". The index of each (known) filename | |
4244 | is just a unique number which is associated with only that one filename. | |
4245 | We need such numbers for the sake of generating labels (in the | |
4246 | .debug_sfnames section) and references to those unique labels (in the | |
4247 | .debug_srcinfo and .debug_macinfo sections). | |
4248 | ||
4249 | If the filename given as an argument is not found in our current list, | |
4250 | add it to the list and assign it the next available unique index number. | |
4251 | ||
4252 | Whatever we do (i.e. whether we find a pre-existing filename or add a new | |
4253 | one), we shuffle the filename found (or added) up to the zeroth entry of | |
4254 | our list of filenames (which is always searched linearly). We do this so | |
4255 | as to optimize the most common case for these filename lookups within | |
4256 | dwarfout.c. The most common case by far is the case where we call | |
4257 | lookup_filename to lookup the very same filename that we did a lookup | |
4258 | on the last time we called lookup_filename. We make sure that this | |
4259 | common case is fast because such cases will constitute 99.9% of the | |
4260 | lookups we ever do (in practice). | |
4261 | ||
4262 | If we add a new filename entry to our table, we go ahead and generate | |
4263 | the corresponding entry in the .debug_sfnames section right away. | |
4264 | Doing so allows us to avoid tickling an assembler bug (present in some | |
4265 | m68k assemblers) which yields assembly-time errors in cases where the | |
4266 | difference of two label addresses is taken and where the two labels | |
4267 | are in a section *other* than the one where the difference is being | |
4268 | calculated, and where at least one of the two symbol references is a | |
4269 | forward reference. (This bug could be tickled by our .debug_srcinfo | |
4270 | entries if we don't output their corresponding .debug_sfnames entries | |
4271 | before them.) | |
4272 | */ | |
4273 | ||
4274 | static unsigned | |
4275 | lookup_filename (file_name) | |
4276 | char *file_name; | |
4277 | { | |
4278 | register filename_entry *search_p; | |
4279 | register filename_entry *limit_p = &filename_table[ft_entries]; | |
4280 | ||
4281 | for (search_p = filename_table; search_p < limit_p; search_p++) | |
4282 | if (!strcmp (file_name, search_p->name)) | |
4283 | { | |
4284 | /* When we get here, we have found the filename that we were | |
4285 | looking for in the filename_table. Now we want to make sure | |
4286 | that it gets moved to the zero'th entry in the table (if it | |
4287 | is not already there) so that subsequent attempts to find the | |
4288 | same filename will find it as quickly as possible. */ | |
4289 | ||
4290 | shuffle_filename_entry (search_p); | |
4291 | return filename_table[0].number; | |
4292 | } | |
4293 | ||
4294 | /* We come here whenever we have a new filename which is not registered | |
4295 | in the current table. Here we add it to the table. */ | |
4296 | ||
4297 | /* Prepare to add a new table entry by making sure there is enough space | |
4298 | in the table to do so. If not, expand the current table. */ | |
4299 | ||
4300 | if (ft_entries == ft_entries_allocated) | |
4301 | { | |
4302 | ft_entries_allocated += FT_ENTRIES_INCREMENT; | |
4303 | filename_table | |
4304 | = (filename_entry *) | |
4305 | xrealloc (filename_table, | |
4306 | ft_entries_allocated * sizeof (filename_entry)); | |
4307 | } | |
4308 | ||
4309 | /* Initially, add the new entry at the end of the filename table. */ | |
4310 | ||
4311 | filename_table[ft_entries].number = ft_entries; | |
4312 | filename_table[ft_entries].name = xstrdup (file_name); | |
4313 | ||
4314 | /* Shuffle the new entry into filename_table[0]. */ | |
4315 | ||
4316 | shuffle_filename_entry (&filename_table[ft_entries]); | |
4317 | ||
4318 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4319 | generate_new_sfname_entry (); | |
4320 | ||
4321 | ft_entries++; | |
4322 | return filename_table[0].number; | |
4323 | } | |
4324 | ||
4325 | static void | |
4326 | generate_srcinfo_entry (line_entry_num, files_entry_num) | |
4327 | unsigned line_entry_num; | |
4328 | unsigned files_entry_num; | |
4329 | { | |
4330 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4331 | ||
4332 | fputc ('\n', asm_out_file); | |
85595d1a | 4333 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); |
340ccaab TW |
4334 | sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num); |
4335 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL); | |
4336 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num); | |
4337 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL); | |
85595d1a | 4338 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4339 | } |
4340 | ||
4341 | void | |
4342 | dwarfout_line (filename, line) | |
4343 | register char *filename; | |
4344 | register unsigned line; | |
4345 | { | |
4346 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4347 | { | |
4348 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4349 | static unsigned last_line_entry_num = 0; | |
4350 | static unsigned prev_file_entry_num = (unsigned) -1; | |
4351 | register unsigned this_file_entry_num = lookup_filename (filename); | |
4352 | ||
4353 | text_section (); | |
4354 | sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num); | |
4355 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
4356 | ||
4357 | fputc ('\n', asm_out_file); | |
85595d1a | 4358 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
340ccaab TW |
4359 | |
4360 | if (this_file_entry_num != prev_file_entry_num) | |
4361 | { | |
4362 | char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4363 | ||
4364 | sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num); | |
4365 | ASM_OUTPUT_LABEL (asm_out_file, line_entry_label); | |
4366 | } | |
4367 | ||
4368 | { | |
4369 | register char *tail = strrchr (filename, '/'); | |
4370 | ||
4371 | if (tail != NULL) | |
4372 | filename = tail; | |
4373 | } | |
4374 | ||
2e494f70 | 4375 | fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n", |
340ccaab TW |
4376 | UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START, |
4377 | filename, line); | |
4378 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); | |
4379 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL); | |
85595d1a | 4380 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4381 | |
4382 | if (this_file_entry_num != prev_file_entry_num) | |
4383 | generate_srcinfo_entry (last_line_entry_num, this_file_entry_num); | |
4384 | prev_file_entry_num = this_file_entry_num; | |
4385 | } | |
4386 | } | |
4387 | ||
4388 | /* Generate an entry in the .debug_macinfo section. */ | |
4389 | ||
4390 | static void | |
4391 | generate_macinfo_entry (type_and_offset, string) | |
4392 | register char *type_and_offset; | |
4393 | register char *string; | |
4394 | { | |
4395 | fputc ('\n', asm_out_file); | |
85595d1a | 4396 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); |
2e494f70 | 4397 | fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset); |
340ccaab | 4398 | ASM_OUTPUT_DWARF_STRING (asm_out_file, string); |
85595d1a | 4399 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4400 | } |
4401 | ||
4402 | void | |
4403 | dwarfout_start_new_source_file (filename) | |
4404 | register char *filename; | |
4405 | { | |
4406 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4407 | char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3]; | |
4408 | ||
4409 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename)); | |
4410 | sprintf (type_and_offset, "0x%08x+%s-%s", | |
4411 | ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL); | |
4412 | generate_macinfo_entry (type_and_offset, ""); | |
4413 | } | |
4414 | ||
4415 | void | |
4416 | dwarfout_resume_previous_source_file (lineno) | |
4417 | register unsigned lineno; | |
4418 | { | |
4419 | char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; | |
4420 | ||
4421 | sprintf (type_and_offset, "0x%08x+%u", | |
4422 | ((unsigned) MACINFO_resume << 24), lineno); | |
4423 | generate_macinfo_entry (type_and_offset, ""); | |
4424 | } | |
4425 | ||
4426 | /* Called from check_newline in c-parse.y. The `buffer' parameter | |
4427 | contains the tail part of the directive line, i.e. the part which | |
4428 | is past the initial whitespace, #, whitespace, directive-name, | |
4429 | whitespace part. */ | |
4430 | ||
4431 | void | |
4432 | dwarfout_define (lineno, buffer) | |
4433 | register unsigned lineno; | |
4434 | register char *buffer; | |
4435 | { | |
4436 | static int initialized = 0; | |
4437 | char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; | |
4438 | ||
4439 | if (!initialized) | |
4440 | { | |
4441 | dwarfout_start_new_source_file (primary_filename); | |
4442 | initialized = 1; | |
4443 | } | |
4444 | sprintf (type_and_offset, "0x%08x+%u", | |
4445 | ((unsigned) MACINFO_define << 24), lineno); | |
4446 | generate_macinfo_entry (type_and_offset, buffer); | |
4447 | } | |
4448 | ||
4449 | /* Called from check_newline in c-parse.y. The `buffer' parameter | |
4450 | contains the tail part of the directive line, i.e. the part which | |
4451 | is past the initial whitespace, #, whitespace, directive-name, | |
4452 | whitespace part. */ | |
4453 | ||
4454 | void | |
4455 | dwarfout_undef (lineno, buffer) | |
4456 | register unsigned lineno; | |
4457 | register char *buffer; | |
4458 | { | |
4459 | char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; | |
4460 | ||
4461 | sprintf (type_and_offset, "0x%08x+%u", | |
4462 | ((unsigned) MACINFO_undef << 24), lineno); | |
4463 | generate_macinfo_entry (type_and_offset, buffer); | |
4464 | } | |
4465 | ||
4466 | /* Set up for Dwarf output at the start of compilation. */ | |
4467 | ||
4468 | void | |
4469 | dwarfout_init (asm_out_file, main_input_filename) | |
4470 | register FILE *asm_out_file; | |
4471 | register char *main_input_filename; | |
4472 | { | |
4473 | /* Remember the name of the primary input file. */ | |
4474 | ||
4475 | primary_filename = main_input_filename; | |
4476 | ||
4477 | /* Allocate the initial hunk of the pending_sibling_stack. */ | |
4478 | ||
4479 | pending_sibling_stack | |
4480 | = (unsigned *) | |
4481 | xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned)); | |
4482 | pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT; | |
4483 | pending_siblings = 1; | |
4484 | ||
4485 | /* Allocate the initial hunk of the filename_table. */ | |
4486 | ||
4487 | filename_table | |
4488 | = (filename_entry *) | |
4489 | xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry)); | |
4490 | ft_entries_allocated = FT_ENTRIES_INCREMENT; | |
4491 | ft_entries = 0; | |
4492 | ||
4493 | /* Allocate the initial hunk of the pending_types_list. */ | |
4494 | ||
4495 | pending_types_list | |
4496 | = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree)); | |
4497 | pending_types_allocated = PENDING_TYPES_INCREMENT; | |
4498 | pending_types = 0; | |
4499 | ||
4500 | /* Create an artificial RECORD_TYPE node which we can use in our hack | |
4501 | to get the DIEs representing types of formal parameters to come out | |
4502 | only *after* the DIEs for the formal parameters themselves. */ | |
4503 | ||
4504 | fake_containing_scope = make_node (RECORD_TYPE); | |
4505 | ||
4506 | /* Output a starting label for the .text section. */ | |
4507 | ||
4508 | fputc ('\n', asm_out_file); | |
85595d1a | 4509 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION); |
340ccaab | 4510 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); |
85595d1a | 4511 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4512 | |
4513 | /* Output a starting label for the .data section. */ | |
4514 | ||
4515 | fputc ('\n', asm_out_file); | |
85595d1a | 4516 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION); |
340ccaab | 4517 | ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); |
85595d1a | 4518 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4519 | |
4520 | /* Output a starting label for the .data1 section. */ | |
4521 | ||
4522 | fputc ('\n', asm_out_file); | |
85595d1a | 4523 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION); |
340ccaab | 4524 | ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL); |
85595d1a | 4525 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4526 | |
4527 | /* Output a starting label for the .rodata section. */ | |
4528 | ||
4529 | fputc ('\n', asm_out_file); | |
85595d1a | 4530 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION); |
340ccaab | 4531 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); |
85595d1a | 4532 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4533 | |
4534 | /* Output a starting label for the .rodata1 section. */ | |
4535 | ||
4536 | fputc ('\n', asm_out_file); | |
85595d1a | 4537 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION); |
340ccaab | 4538 | ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL); |
85595d1a | 4539 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4540 | |
4541 | /* Output a starting label for the .bss section. */ | |
4542 | ||
4543 | fputc ('\n', asm_out_file); | |
85595d1a | 4544 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION); |
340ccaab | 4545 | ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); |
85595d1a | 4546 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4547 | |
4548 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4549 | { | |
4550 | /* Output a starting label and an initial (compilation directory) | |
4551 | entry for the .debug_sfnames section. The starting label will be | |
4552 | referenced by the initial entry in the .debug_srcinfo section. */ | |
4553 | ||
4554 | fputc ('\n', asm_out_file); | |
85595d1a | 4555 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION); |
340ccaab TW |
4556 | ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL); |
4557 | { | |
2e494f70 RS |
4558 | register char *pwd = getpwd (); |
4559 | register unsigned len = strlen (pwd); | |
4560 | register char *dirname = (char *) xmalloc (len + 2); | |
340ccaab | 4561 | |
2e494f70 RS |
4562 | strcpy (dirname, pwd); |
4563 | strcpy (dirname + len, "/"); | |
340ccaab TW |
4564 | ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); |
4565 | free (dirname); | |
4566 | } | |
85595d1a | 4567 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4568 | |
4569 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
4570 | { | |
4571 | /* Output a starting label for the .debug_macinfo section. This | |
4572 | label will be referenced by the AT_mac_info attribute in the | |
4573 | TAG_compile_unit DIE. */ | |
4574 | ||
4575 | fputc ('\n', asm_out_file); | |
85595d1a | 4576 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); |
340ccaab | 4577 | ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL); |
85595d1a | 4578 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4579 | } |
4580 | ||
4581 | /* Generate the initial entry for the .line section. */ | |
4582 | ||
4583 | fputc ('\n', asm_out_file); | |
85595d1a | 4584 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
340ccaab TW |
4585 | ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL); |
4586 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL); | |
4587 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
85595d1a | 4588 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4589 | |
4590 | /* Generate the initial entry for the .debug_srcinfo section. */ | |
4591 | ||
4592 | fputc ('\n', asm_out_file); | |
85595d1a | 4593 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); |
340ccaab TW |
4594 | ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL); |
4595 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL); | |
4596 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL); | |
4597 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
4598 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL); | |
4599 | #ifdef DWARF_TIMESTAMPS | |
4600 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL)); | |
4601 | #else | |
4602 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); | |
4603 | #endif | |
85595d1a | 4604 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4605 | |
4606 | /* Generate the initial entry for the .debug_pubnames section. */ | |
4607 | ||
4608 | fputc ('\n', asm_out_file); | |
85595d1a | 4609 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); |
340ccaab | 4610 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); |
85595d1a | 4611 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4612 | |
4613 | /* Generate the initial entry for the .debug_aranges section. */ | |
4614 | ||
4615 | fputc ('\n', asm_out_file); | |
85595d1a | 4616 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); |
340ccaab | 4617 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); |
85595d1a | 4618 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4619 | } |
4620 | ||
4621 | /* Setup first DIE number == 1. */ | |
4622 | NEXT_DIE_NUM = next_unused_dienum++; | |
4623 | ||
4624 | /* Generate the initial DIE for the .debug section. Note that the | |
4625 | (string) value given in the AT_name attribute of the TAG_compile_unit | |
4626 | DIE will (typically) be a relative pathname and that this pathname | |
4627 | should be taken as being relative to the directory from which the | |
4628 | compiler was invoked when the given (base) source file was compiled. */ | |
4629 | ||
4630 | fputc ('\n', asm_out_file); | |
85595d1a | 4631 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
340ccaab TW |
4632 | ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL); |
4633 | output_die (output_compile_unit_die, main_input_filename); | |
85595d1a | 4634 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4635 | |
4636 | fputc ('\n', asm_out_file); | |
4637 | } | |
4638 | ||
4639 | /* Output stuff that dwarf requires at the end of every file. */ | |
4640 | ||
4641 | void | |
4642 | dwarfout_finish () | |
4643 | { | |
4644 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4645 | ||
4646 | fputc ('\n', asm_out_file); | |
85595d1a | 4647 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
340ccaab TW |
4648 | |
4649 | /* Mark the end of the chain of siblings which represent all file-scope | |
4650 | declarations in this compilation unit. */ | |
4651 | ||
4652 | /* The (null) DIE which represents the terminator for the (sibling linked) | |
4653 | list of file-scope items is *special*. Normally, we would just call | |
4654 | end_sibling_chain at this point in order to output a word with the | |
4655 | value `4' and that word would act as the terminator for the list of | |
4656 | DIEs describing file-scope items. Unfortunately, if we were to simply | |
4657 | do that, the label that would follow this DIE in the .debug section | |
4658 | (i.e. `..D2') would *not* be properly aligned (as it must be on some | |
4659 | machines) to a 4 byte boundary. | |
4660 | ||
4661 | In order to force the label `..D2' to get aligned to a 4 byte boundary, | |
4662 | the trick used is to insert extra (otherwise useless) padding bytes | |
4663 | into the (null) DIE that we know must preceed the ..D2 label in the | |
4664 | .debug section. The amount of padding required can be anywhere between | |
4665 | 0 and 3 bytes. The length word at the start of this DIE (i.e. the one | |
4666 | with the padding) would normally contain the value 4, but now it will | |
4667 | also have to include the padding bytes, so it will instead have some | |
4668 | value in the range 4..7. | |
4669 | ||
4670 | Fortunately, the rules of Dwarf say that any DIE whose length word | |
4671 | contains *any* value less than 8 should be treated as a null DIE, so | |
4672 | this trick works out nicely. Clever, eh? Don't give me any credit | |
4673 | (or blame). I didn't think of this scheme. I just conformed to it. | |
4674 | */ | |
4675 | ||
4676 | output_die (output_padded_null_die, (void *)0); | |
4677 | dienum_pop (); | |
4678 | ||
4679 | sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); | |
4680 | ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */ | |
85595d1a | 4681 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4682 | |
4683 | /* Output a terminator label for the .text section. */ | |
4684 | ||
4685 | fputc ('\n', asm_out_file); | |
85595d1a | 4686 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION); |
340ccaab | 4687 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); |
85595d1a | 4688 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4689 | |
4690 | /* Output a terminator label for the .data section. */ | |
4691 | ||
4692 | fputc ('\n', asm_out_file); | |
85595d1a | 4693 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION); |
340ccaab | 4694 | ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); |
85595d1a | 4695 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4696 | |
4697 | /* Output a terminator label for the .data1 section. */ | |
4698 | ||
4699 | fputc ('\n', asm_out_file); | |
85595d1a | 4700 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION); |
340ccaab | 4701 | ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL); |
85595d1a | 4702 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4703 | |
4704 | /* Output a terminator label for the .rodata section. */ | |
4705 | ||
4706 | fputc ('\n', asm_out_file); | |
85595d1a | 4707 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION); |
340ccaab | 4708 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); |
85595d1a | 4709 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4710 | |
4711 | /* Output a terminator label for the .rodata1 section. */ | |
4712 | ||
4713 | fputc ('\n', asm_out_file); | |
85595d1a | 4714 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION); |
340ccaab | 4715 | ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL); |
85595d1a | 4716 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4717 | |
4718 | /* Output a terminator label for the .bss section. */ | |
4719 | ||
4720 | fputc ('\n', asm_out_file); | |
85595d1a | 4721 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION); |
340ccaab | 4722 | ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); |
85595d1a | 4723 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4724 | |
4725 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4726 | { | |
4727 | /* Output a terminating entry for the .line section. */ | |
4728 | ||
4729 | fputc ('\n', asm_out_file); | |
85595d1a | 4730 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
340ccaab TW |
4731 | ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL); |
4732 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4733 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); | |
4734 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); | |
4735 | ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL); | |
85595d1a | 4736 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4737 | |
4738 | /* Output a terminating entry for the .debug_srcinfo section. */ | |
4739 | ||
4740 | fputc ('\n', asm_out_file); | |
85595d1a | 4741 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); |
340ccaab TW |
4742 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, |
4743 | LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL); | |
4744 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); | |
85595d1a | 4745 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4746 | |
4747 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
4748 | { | |
4749 | /* Output terminating entries for the .debug_macinfo section. */ | |
4750 | ||
4751 | dwarfout_resume_previous_source_file (0); | |
4752 | ||
4753 | fputc ('\n', asm_out_file); | |
85595d1a | 4754 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); |
340ccaab TW |
4755 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
4756 | ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); | |
85595d1a | 4757 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4758 | } |
4759 | ||
4760 | /* Generate the terminating entry for the .debug_pubnames section. */ | |
4761 | ||
4762 | fputc ('\n', asm_out_file); | |
85595d1a | 4763 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); |
340ccaab TW |
4764 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
4765 | ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); | |
85595d1a | 4766 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4767 | |
4768 | /* Generate the terminating entries for the .debug_aranges section. | |
4769 | ||
4770 | Note that we want to do this only *after* we have output the end | |
4771 | labels (for the various program sections) which we are going to | |
4772 | refer to here. This allows us to work around a bug in the m68k | |
4773 | svr4 assembler. That assembler gives bogus assembly-time errors | |
4774 | if (within any given section) you try to take the difference of | |
4775 | two relocatable symbols, both of which are located within some | |
4776 | other section, and if one (or both?) of the symbols involved is | |
4777 | being forward-referenced. By generating the .debug_aranges | |
4778 | entries at this late point in the assembly output, we skirt the | |
4779 | issue simply by avoiding forward-references. | |
4780 | */ | |
4781 | ||
4782 | fputc ('\n', asm_out_file); | |
85595d1a | 4783 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); |
340ccaab TW |
4784 | |
4785 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
4786 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); | |
4787 | ||
4788 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL); | |
4789 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL); | |
4790 | ||
4791 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL); | |
4792 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL, | |
4793 | DATA1_BEGIN_LABEL); | |
4794 | ||
4795 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL); | |
4796 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL, | |
4797 | RODATA_BEGIN_LABEL); | |
4798 | ||
4799 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL); | |
4800 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL, | |
4801 | RODATA1_BEGIN_LABEL); | |
4802 | ||
4803 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL); | |
4804 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL); | |
4805 | ||
4806 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4807 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4808 | ||
85595d1a | 4809 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
340ccaab TW |
4810 | } |
4811 | } | |
4812 | ||
4813 | #endif /* DWARF_DEBUGGING_INFO */ |