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