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