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