]>
Commit | Line | Data |
---|---|---|
a3f97cbb JW |
1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
2 | Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc. | |
3 | Contributed by Gary Funck (gary@intrepid.com). Derived from the | |
4 | DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com). | |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
20 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
22 | #include "config.h" | |
23 | ||
6ba95bc9 RK |
24 | #ifndef DWARF_VERSION |
25 | #define DWARF_VERSION 1 | |
26 | #endif | |
27 | #if defined (DWARF_DEBUGGING_INFO) && (DWARF_VERSION == 2) | |
a3f97cbb JW |
28 | #include <stdio.h> |
29 | #include "dwarf2.h" | |
30 | #include "tree.h" | |
31 | #include "flags.h" | |
32 | #include "rtl.h" | |
33 | #include "hard-reg-set.h" | |
34 | #include "regs.h" | |
35 | #include "insn-config.h" | |
36 | #include "reload.h" | |
37 | #include "output.h" | |
38 | #include "defaults.h" | |
39 | ||
40 | /* #define NDEBUG 1 */ | |
41 | #include "assert.h" | |
42 | #if defined(DWARF_TIMESTAMPS) | |
43 | #if defined(POSIX) | |
44 | #include <time.h> | |
45 | #else /* !defined(POSIX) */ | |
46 | #include <sys/types.h> | |
47 | #if defined(__STDC__) | |
48 | extern time_t time (time_t *); | |
49 | #else /* !defined(__STDC__) */ | |
50 | extern time_t time (); | |
51 | #endif /* !defined(__STDC__) */ | |
52 | #endif /* !defined(POSIX) */ | |
53 | #endif /* defined(DWARF_TIMESTAMPS) */ | |
54 | ||
55 | extern char *getpwd (); | |
56 | extern char *index (); | |
57 | extern char *rindex (); | |
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 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
64 | throughout the remainder of this file. */ | |
65 | ||
66 | /* NOTE: The implementation of C++ support is unfinished. */ | |
67 | ||
68 | #if defined(__GNUC__) && (NDEBUG == 1) | |
69 | #define inline static inline | |
70 | #else | |
71 | #define inline static | |
72 | #endif | |
73 | ||
74 | ||
75 | /* An internal representation of the DWARF output is built, and then | |
76 | walked to generate the DWARF debugging info. The walk of the internal | |
77 | representation is done after the entire program has been compiled. | |
78 | The types below are used to describe the internal representation. */ | |
79 | ||
80 | /* Each DIE may have a series of attribute/value pairs. Values | |
81 | can take on several forms. The forms that are used in this | |
82 | impelementation are listed below. */ | |
83 | typedef enum | |
84 | { | |
85 | dw_val_class_addr, | |
86 | dw_val_class_loc, | |
87 | dw_val_class_const, | |
88 | dw_val_class_unsigned_const, | |
89 | dw_val_class_double_const, | |
90 | dw_val_class_flag, | |
91 | dw_val_class_die_ref, | |
92 | dw_val_class_fde_ref, | |
93 | dw_val_class_lbl_id, | |
94 | dw_val_class_section_offset, | |
95 | dw_val_class_str | |
96 | } | |
97 | dw_val_class; | |
98 | ||
99 | /* Various DIE's use offsets relative to the beginning of the | |
100 | .debug_info section to refer to each other. */ | |
101 | typedef long int dw_offset; | |
102 | ||
103 | /* Define typedefs here to avoid circular dependencies. */ | |
104 | typedef struct die_struct *dw_die_ref; | |
105 | typedef struct dw_attr_struct *dw_attr_ref; | |
106 | typedef struct dw_val_struct *dw_val_ref; | |
107 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
e90b62db | 108 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; |
a3f97cbb JW |
109 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; |
110 | typedef struct dw_cfi_struct *dw_cfi_ref; | |
111 | typedef struct dw_fde_struct *dw_fde_ref; | |
112 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
d291dd49 JM |
113 | typedef struct pubname_struct *pubname_ref; |
114 | typedef dw_die_ref *arange_ref; | |
a3f97cbb JW |
115 | |
116 | /* Describe a double word constant value. */ | |
117 | typedef struct dw_double_const_struct | |
118 | { | |
119 | unsigned long dw_dbl_hi; | |
120 | unsigned long dw_dbl_low; | |
121 | } | |
122 | dw_dbl_const; | |
123 | ||
124 | /* Each entry in the line_info_table maintains the file and | |
125 | line nuber associated with the label generated for that | |
126 | entry. The label gives the PC value associated with | |
127 | the line number entry. */ | |
128 | typedef struct dw_line_info_struct | |
129 | { | |
130 | unsigned long dw_file_num; | |
131 | unsigned long dw_line_num; | |
132 | } | |
133 | dw_line_info_entry; | |
134 | ||
e90b62db JM |
135 | /* Line information for functions in separate sections; each one gets its |
136 | own sequence. */ | |
137 | typedef struct dw_separate_line_info_struct | |
138 | { | |
139 | unsigned long dw_file_num; | |
140 | unsigned long dw_line_num; | |
141 | unsigned long function; | |
142 | } | |
143 | dw_separate_line_info_entry; | |
144 | ||
a3f97cbb JW |
145 | /* The dw_val_node describes an attibute's value, as it is |
146 | represnted internally. */ | |
147 | typedef struct dw_val_struct | |
148 | { | |
149 | dw_val_class val_class; | |
150 | union | |
151 | { | |
152 | char *val_addr; | |
153 | dw_loc_descr_ref val_loc; | |
154 | long int val_int; | |
155 | long unsigned val_unsigned; | |
156 | dw_dbl_const val_dbl_const; | |
157 | dw_die_ref val_die_ref; | |
158 | unsigned val_fde_index; | |
159 | char *val_str; | |
160 | char *val_lbl_id; | |
161 | char *val_section; | |
162 | unsigned char val_flag; | |
163 | } | |
164 | v; | |
165 | } | |
166 | dw_val_node; | |
167 | ||
168 | /* Locations in memory are described using a sequence of stack machine | |
169 | operations. */ | |
170 | typedef struct dw_loc_descr_struct | |
171 | { | |
172 | dw_loc_descr_ref dw_loc_next; | |
173 | enum dwarf_location_atom dw_loc_opc; | |
174 | dw_val_node dw_loc_oprnd1; | |
175 | dw_val_node dw_loc_oprnd2; | |
176 | } | |
177 | dw_loc_descr_node; | |
178 | ||
179 | /* Each DIE attribute has a field specifying the attribute kind, | |
180 | a link to the next attribute in the chain, and an attribute value. | |
181 | Attributes are typically linked below the DIE they modify. */ | |
182 | typedef struct dw_attr_struct | |
183 | { | |
184 | enum dwarf_attribute dw_attr; | |
185 | dw_attr_ref dw_attr_next; | |
186 | dw_val_node dw_attr_val; | |
187 | } | |
188 | dw_attr_node; | |
189 | ||
190 | /* Call frames are described using a sequence of Call Frame | |
191 | Information instructions. The register number, offset | |
192 | and address fields are provided as possible operands; | |
193 | their use is selected by the opcode field. */ | |
194 | typedef union dw_cfi_oprnd_struct | |
195 | { | |
196 | unsigned long dw_cfi_reg_num; | |
197 | long int dw_cfi_offset; | |
198 | char *dw_cfi_addr; | |
199 | } | |
200 | dw_cfi_oprnd; | |
201 | ||
202 | typedef struct dw_cfi_struct | |
203 | { | |
204 | dw_cfi_ref dw_cfi_next; | |
205 | enum dwarf_call_frame_info dw_cfi_opc; | |
206 | dw_cfi_oprnd dw_cfi_oprnd1; | |
207 | dw_cfi_oprnd dw_cfi_oprnd2; | |
208 | } | |
209 | dw_cfi_node; | |
210 | ||
211 | /* All call frame descriptions (FDE's) in the GCC generated DWARF | |
4b674448 | 212 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
213 | the beginning of the .debug_frame section. This used of a single |
214 | CIE obviates the need to keep track of multiple CIE's | |
215 | in the DWARF generation routines below. */ | |
216 | typedef struct dw_fde_struct | |
217 | { | |
218 | unsigned long dw_fde_offset; | |
219 | char *dw_fde_begin; | |
220 | char *dw_fde_end_prolog; | |
221 | char *dw_fde_begin_epilogue; | |
222 | char *dw_fde_end; | |
223 | dw_cfi_ref dw_fde_cfi; | |
224 | } | |
225 | dw_fde_node; | |
226 | ||
227 | /* The Debugging Information Entry (DIE) structure */ | |
228 | typedef struct die_struct | |
229 | { | |
230 | enum dwarf_tag die_tag; | |
231 | dw_attr_ref die_attr; | |
232 | dw_attr_ref die_attr_last; | |
233 | dw_die_ref die_parent; | |
234 | dw_die_ref die_child; | |
235 | dw_die_ref die_child_last; | |
236 | dw_die_ref die_sib; | |
237 | dw_offset die_offset; | |
238 | unsigned long die_abbrev; | |
239 | } | |
240 | die_node; | |
241 | ||
d291dd49 JM |
242 | /* The pubname structure */ |
243 | typedef struct pubname_struct | |
244 | { | |
245 | dw_die_ref die; | |
246 | char * name; | |
247 | } | |
248 | pubname_entry; | |
249 | ||
a3f97cbb JW |
250 | /* How to start an assembler comment. */ |
251 | #ifndef ASM_COMMENT_START | |
252 | #define ASM_COMMENT_START ";#" | |
253 | #endif | |
254 | ||
255 | /* Define a macro which returns non-zero for any tagged type which is used | |
256 | (directly or indirectly) in the specification of either some function's | |
257 | return type or some formal parameter of some function. We use this macro | |
258 | when we are operating in "terse" mode to help us know what tagged types | |
259 | have to be represented in Dwarf (even in terse mode) and which ones don't. | |
260 | A flag bit with this meaning really should be a part of the normal GCC | |
261 | ..._TYPE nodes, but at the moment, there is no such bit defined for these | |
262 | nodes. For now, we have to just fake it. It it safe for us to simply | |
263 | return zero for all complete tagged types (which will get forced out | |
264 | anyway if they were used in the specification of some formal or return | |
265 | type) and non-zero for all incomplete tagged types. */ | |
266 | #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) | |
267 | ||
268 | /* Information concerning the compilation unit's programming | |
269 | language, and compiler version. */ | |
270 | extern int flag_traditional; | |
271 | extern char *version_string; | |
272 | extern char *language_string; | |
273 | ||
274 | /* Maximum size (in bytes) of an artificially generated label. */ | |
275 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
276 | ||
277 | /* Make sure we know the sizes of the various types dwarf can describe. These | |
278 | are only defaults. If the sizes are different for your target, you should | |
279 | override these values by defining the appropriate symbols in your tm.h | |
280 | file. */ | |
281 | #ifndef CHAR_TYPE_SIZE | |
282 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
283 | #endif | |
284 | #ifndef SHORT_TYPE_SIZE | |
285 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) | |
286 | #endif | |
287 | #ifndef INT_TYPE_SIZE | |
288 | #define INT_TYPE_SIZE BITS_PER_WORD | |
289 | #endif | |
290 | #ifndef LONG_TYPE_SIZE | |
291 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
292 | #endif | |
293 | #ifndef LONG_LONG_TYPE_SIZE | |
294 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
295 | #endif | |
296 | #ifndef WCHAR_TYPE_SIZE | |
297 | #define WCHAR_TYPE_SIZE INT_TYPE_SIZE | |
298 | #endif | |
299 | #ifndef WCHAR_UNSIGNED | |
300 | #define WCHAR_UNSIGNED 0 | |
301 | #endif | |
302 | #ifndef FLOAT_TYPE_SIZE | |
303 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
304 | #endif | |
305 | #ifndef DOUBLE_TYPE_SIZE | |
306 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
307 | #endif | |
308 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
309 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
310 | #endif | |
311 | #ifndef PTR_SIZE | |
312 | #define PTR_SIZE (POINTER_SIZE / 8) | |
313 | #endif | |
314 | ||
315 | /* Fixed size portion of the DWARF compilation unit header. */ | |
316 | #define DWARF_COMPILE_UNIT_HEADER_SIZE 11 | |
317 | ||
318 | /* Fixed size portion of debugging line information prolog. */ | |
319 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
320 | ||
321 | /* Fixed size portion of public names info. */ | |
322 | #define DWARF_PUBNAMES_HEADER_SIZE 10 | |
323 | ||
324 | /* Fixed size portion of the address range info. */ | |
325 | #define DWARF_ARANGES_HEADER_SIZE 12 | |
326 | ||
327 | /* Fixed size portion of the Common Information Entry (including | |
328 | the length field). */ | |
329 | #define DWARF_CIE_HEADER_SIZE 16 | |
330 | ||
331 | /* Fixed size of the Common Information Entry in the call frame | |
332 | information (.debug_frame) section rounded up to an 8 byte boundary. */ | |
333 | #define DWARF_CIE_SIZE ((DWARF_CIE_HEADER_SIZE + 7) & ~7) | |
334 | ||
335 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ | |
336 | #define DWARF_CIE_DATA_ALIGNMENT -4 | |
337 | ||
338 | /* Fixed size portion of the FDE. */ | |
339 | #define DWARF_FDE_HEADER_SIZE (4 + 4 + (2 * PTR_SIZE)) | |
340 | ||
341 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
342 | In this implementation of DWARF, this field is used for information | |
343 | purposes only. Since GCC generates assembly language, we have | |
344 | no a priori knowledge of how many instruction bytes are generated | |
345 | for each source line, and therefore can use only the DW_LNE_set_address | |
346 | and DW_LNS_fixed_advance_pc line information commands. */ | |
347 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
348 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
349 | #endif | |
350 | ||
351 | /* Minimum line offset in a special line info. opcode. | |
352 | This value was chosen to give a reasonable range of values. */ | |
353 | #define DWARF_LINE_BASE -10 | |
354 | ||
355 | /* First special line opcde - leave room for the standard opcodes. */ | |
356 | #define DWARF_LINE_OPCODE_BASE 10 | |
357 | ||
358 | /* Range of line offsets in a special line info. opcode. */ | |
359 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
360 | ||
361 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
362 | In the present implementation, we do not mark any lines as | |
363 | the beginning of a source statement, because that information | |
364 | is not made available by the GCC front-end. */ | |
365 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
366 | ||
367 | /* This location is used by calc_die_sizes() to keep track | |
368 | the offset of each DIE within the .debug_info section. */ | |
369 | static unsigned long next_die_offset; | |
370 | ||
371 | /* This location is used by calc_fde_sizes() to keep track | |
372 | the offset of each FDE within the .debug_frame section. */ | |
373 | static unsigned long next_fde_offset; | |
374 | ||
375 | /* Record the root of the DIE's built for the current compilation unit. */ | |
376 | dw_die_ref comp_unit_die; | |
377 | ||
378 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
379 | static char **file_table; | |
380 | ||
381 | /* Total number of entries in the table (i.e. array) pointed to by | |
382 | `file_table'. This is the *total* and includes both used and unused | |
383 | slots. */ | |
384 | static unsigned file_table_allocated; | |
385 | ||
386 | /* Number of entries in the file_table which are actually in use. */ | |
387 | static unsigned file_table_in_use; | |
388 | ||
389 | /* Size (in elements) of increments by which we may expand the filename | |
390 | table. */ | |
391 | #define FILE_TABLE_INCREMENT 64 | |
392 | ||
393 | /* Local pointer to the name of the main input file. Initialized in | |
394 | dwarfout_init. */ | |
395 | static char *primary_filename; | |
396 | ||
397 | /* For Dwarf output, we must assign lexical-blocks id numbers in the order in | |
398 | which their beginnings are encountered. We output Dwarf debugging info | |
399 | that refers to the beginnings and ends of the ranges of code for each | |
400 | lexical block. The labels themselves are generated in final.c, which | |
401 | assigns numbers to the blocks in the same way. */ | |
402 | static unsigned next_block_number = 2; | |
403 | ||
404 | /* Non-zero if we are performing the file-scope finalization pass and if we | |
405 | should force out Dwarf descriptions of any and all file-scope tagged types | |
406 | which are still incomplete types. */ | |
407 | static int finalizing = 0; | |
408 | ||
409 | /* A pointer to the base of a list of references to DIE's that describe | |
410 | types. The table is indexed by TYPE_UID() which is a unique number, | |
411 | indentifying each type. */ | |
412 | static dw_die_ref *type_die_table; | |
413 | ||
414 | /* Number of elements currently allocated for type_die_table. */ | |
415 | static unsigned type_die_table_allocated; | |
416 | ||
417 | /* Number of elements in type_die_table currently in use. */ | |
418 | static unsigned type_die_table_in_use; | |
419 | ||
420 | /* Size (in elements) of increments by which we may expand the | |
421 | type_die_table. */ | |
422 | #define TYPE_DIE_TABLE_INCREMENT 4096 | |
423 | ||
424 | /* A pointer to the base of a table of references to DIE's that describe | |
425 | declarations. The table is indexed by DECL_UID() which is a unique | |
426 | number, indentifying each decl. */ | |
427 | static dw_die_ref *decl_die_table; | |
428 | ||
429 | /* Number of elements currently allocated for the decl_die_table. */ | |
430 | static unsigned decl_die_table_allocated; | |
431 | ||
432 | /* Number of elements in decl_die_table currently in use. */ | |
433 | static unsigned decl_die_table_in_use; | |
434 | ||
435 | /* Size (in elements) of increments by which we may expand the | |
436 | decl_die_table. */ | |
437 | #define DECL_DIE_TABLE_INCREMENT 256 | |
438 | ||
439 | /* A pointer to the base of a table of references to declaration | |
440 | scopes. This table is a display which tracks the nesting | |
441 | of declaration scopes at the current scope and containing | |
442 | scopes. This table is used to find the proper place to | |
443 | define type declaration DIE's. */ | |
444 | static tree *decl_scope_table; | |
445 | ||
446 | /* Number of elements currently allocated for the decl_scope_table. */ | |
447 | static unsigned decl_scope_table_allocated; | |
448 | ||
449 | /* Current level of nesting of declataion scopes. */ | |
450 | static unsigned decl_scope_depth; | |
451 | ||
452 | /* Size (in elements) of increments by which we may expand the | |
453 | decl_scope_table. */ | |
454 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
455 | ||
456 | /* A pointer to the base of a list of references to DIE's that | |
457 | are uniquely identified by their tag, presence/absence of | |
458 | children DIE's, and list of attribute/value pairs. */ | |
459 | static dw_die_ref *abbrev_die_table; | |
460 | ||
461 | /* Number of elements currently allocated for abbrev_die_table. */ | |
462 | static unsigned abbrev_die_table_allocated; | |
463 | ||
464 | /* Number of elements in type_die_table currently in use. */ | |
465 | static unsigned abbrev_die_table_in_use; | |
466 | ||
467 | /* Size (in elements) of increments by which we may expand the | |
468 | abbrev_die_table. */ | |
469 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
470 | ||
471 | /* A pointer to the base of a table that contains line information | |
e90b62db | 472 | for each source code line in .text in the compilation unit. */ |
a3f97cbb JW |
473 | static dw_line_info_ref line_info_table; |
474 | ||
475 | /* Number of elements currently allocated for line_info_table. */ | |
476 | static unsigned line_info_table_allocated; | |
477 | ||
e90b62db JM |
478 | /* Number of elements in separate_line_info_table currently in use. */ |
479 | static unsigned separate_line_info_table_in_use; | |
480 | ||
481 | /* A pointer to the base of a table that contains line information | |
482 | for each source code line outside of .text in the compilation unit. */ | |
483 | static dw_separate_line_info_ref separate_line_info_table; | |
484 | ||
485 | /* Number of elements currently allocated for separate_line_info_table. */ | |
486 | static unsigned separate_line_info_table_allocated; | |
487 | ||
a3f97cbb JW |
488 | /* Number of elements in line_info_table currently in use. */ |
489 | static unsigned line_info_table_in_use; | |
490 | ||
491 | /* Size (in elements) of increments by which we may expand the | |
492 | line_info_table. */ | |
493 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
494 | ||
495 | /* Keep track of the last line_info_table entry number, returned | |
496 | by the prior call to lookup_filename(). This serves as a | |
497 | cache used to speed up file name look ups. */ | |
498 | static unsigned prev_file_entry_num = (unsigned) -1; | |
499 | ||
500 | /* A pointer to the base of a table that contains frame description | |
501 | information for each routine. */ | |
502 | static dw_fde_ref fde_table; | |
503 | ||
504 | /* Number of elements currently allocated for fde_table. */ | |
505 | static unsigned fde_table_allocated; | |
506 | ||
507 | /* Number of elements in fde_table currently in use. */ | |
508 | static unsigned fde_table_in_use; | |
509 | ||
510 | /* Size (in elements) of increments by which we may expand the | |
511 | fde_table. */ | |
512 | #define FDE_TABLE_INCREMENT 256 | |
513 | ||
d291dd49 JM |
514 | /* A pointer to the base of a table that contains a list of publicly |
515 | accessible names. */ | |
516 | static pubname_ref pubname_table; | |
517 | ||
518 | /* Number of elements currently allocated for pubname_table. */ | |
519 | static unsigned pubname_table_allocated; | |
520 | ||
521 | /* Number of elements in pubname_table currently in use. */ | |
522 | static unsigned pubname_table_in_use; | |
523 | ||
524 | /* Size (in elements) of increments by which we may expand the | |
525 | pubname_table. */ | |
526 | #define PUBNAME_TABLE_INCREMENT 64 | |
527 | ||
528 | /* A pointer to the base of a table that contains a list of publicly | |
529 | accessible names. */ | |
530 | static arange_ref arange_table; | |
531 | ||
532 | /* Number of elements currently allocated for arange_table. */ | |
533 | static unsigned arange_table_allocated; | |
534 | ||
535 | /* Number of elements in arange_table currently in use. */ | |
536 | static unsigned arange_table_in_use; | |
537 | ||
538 | /* Size (in elements) of increments by which we may expand the | |
539 | arange_table. */ | |
540 | #define ARANGE_TABLE_INCREMENT 64 | |
541 | ||
a3f97cbb JW |
542 | /* The number of the current function definition for which debugging |
543 | information is being generated. These numbers range from 1 up to the | |
544 | maximum number of function definitions contained within the current | |
545 | compilation unit. These numbers are used to create unique label id's | |
546 | unique to each function definition. */ | |
547 | static unsigned current_funcdef_number = 1; | |
548 | ||
549 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
550 | attribute that accelerates the lookup of the FDE associated | |
551 | with the subprogram. This variable holds the table index of the FDE | |
552 | associated with the current function (body) definition. */ | |
553 | static unsigned current_funcdef_fde; | |
554 | ||
555 | /* Record the size of the frame, so that the DW_AT_frame_base | |
556 | attribute can be set properly in gen_subprogram_die. */ | |
557 | static long int current_funcdef_frame_size = 0; | |
558 | ||
559 | /* DWARF requires that the compiler's primary datatypes | |
560 | are mapped into a reference to a DIE that defines that | |
561 | primary (base) type. The base_type_info structure is used | |
562 | to track the correspondence between the name of a | |
563 | base type used by GCC, and its corresponding type | |
564 | characteristics. Note, that the bt_size field below | |
565 | is the size in bits. */ | |
566 | typedef struct base_type_struct *base_type_ref; | |
567 | typedef struct base_type_struct | |
568 | { | |
569 | char *bt_name; | |
570 | enum dwarf_type bt_type; | |
571 | int bt_is_signed; | |
572 | int bt_size; | |
573 | } | |
574 | base_type_info; | |
575 | ||
576 | /* Characteristics of base types used by the compiler. */ | |
577 | static base_type_info base_type_table[] = | |
578 | { | |
579 | {"void", DW_ATE_unsigned, 0, 0}, | |
580 | /* TODO: on some architectures, "char" may be signed. */ | |
581 | {"char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE}, | |
582 | {"unsigned char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE}, | |
583 | {"signed char", DW_ATE_signed_char, 1, CHAR_TYPE_SIZE}, | |
584 | {"int", DW_ATE_signed, 1, /* INT_TYPE_SIZE */ 4*8}, | |
585 | {"unsigned int", DW_ATE_unsigned, 0, /* INT_TYPE_SIZE */ 4*8}, | |
586 | {"short", DW_ATE_signed, 1, SHORT_TYPE_SIZE}, | |
587 | {"short int", DW_ATE_signed, 1, SHORT_TYPE_SIZE}, | |
588 | {"short unsigned int", DW_ATE_unsigned, 0, SHORT_TYPE_SIZE}, | |
589 | {"long", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8}, | |
590 | {"long int", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8}, | |
591 | {"long unsigned int", DW_ATE_unsigned, 0, /* LONG_TYPE_SIZE */ 4*8}, | |
592 | {"long long int", DW_ATE_signed, 1, LONG_LONG_TYPE_SIZE}, | |
593 | {"long long unsigned int", DW_ATE_unsigned, 0, LONG_LONG_TYPE_SIZE}, | |
594 | {"float", DW_ATE_float, 1, /* FLOAT_TYPE_SIZE */ 4*8}, | |
595 | {"double", DW_ATE_float, 1, DOUBLE_TYPE_SIZE}, | |
596 | {"long double", DW_ATE_float, 1, LONG_DOUBLE_TYPE_SIZE}, | |
597 | {"complex", DW_ATE_complex_float, 1, 2 * /* FLOAT_TYPE_SIZE */ 4*8}, | |
598 | {"double complex", DW_ATE_complex_float, 1, 2 * DOUBLE_TYPE_SIZE}, | |
599 | {"long double complex", DW_ATE_complex_float, 1, 2 * LONG_DOUBLE_TYPE_SIZE} | |
600 | }; | |
601 | #define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info)) | |
602 | ||
603 | /* Record the DIE associated with a given base type This table is | |
604 | parallel to the base_type_table, and records the DIE genereated | |
605 | to describe base type that has been previously referenced. */ | |
606 | static dw_die_ref base_type_die_table[NUM_BASE_TYPES]; | |
607 | ||
608 | /* This predefined base type is used to create certain anonymous types */ | |
609 | static dw_die_ref int_base_type_die; | |
610 | ||
611 | /* A pointer to the ..._DECL node which we have most recently been working | |
612 | on. We keep this around just in case something about it looks screwy and | |
613 | we want to tell the user what the source coordinates for the actual | |
614 | declaration are. */ | |
615 | static tree dwarf_last_decl; | |
616 | ||
a3f97cbb JW |
617 | /* Forward declarations for functions defined in this file. */ |
618 | static void gen_type_die (); | |
619 | static void add_type_attribute (); | |
620 | static void decls_for_scope (); | |
621 | static void gen_decl_die (); | |
622 | static unsigned lookup_filename (); | |
623 | ||
624 | ||
625 | /* Definitions of defaults for assembler-dependent names of various | |
626 | pseudo-ops and section names. | |
627 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
628 | assembler. */ | |
629 | #ifndef UNALIGNED_SHORT_ASM_OP | |
630 | #define UNALIGNED_SHORT_ASM_OP ".2byte" | |
631 | #endif | |
632 | #ifndef UNALIGNED_INT_ASM_OP | |
633 | #define UNALIGNED_INT_ASM_OP ".4byte" | |
634 | #endif | |
635 | #ifndef ASM_BYTE_OP | |
636 | #define ASM_BYTE_OP ".byte" | |
637 | #endif | |
638 | ||
639 | /* Pseudo-op for defining a new section. */ | |
640 | #ifndef SECTION_ASM_OP | |
641 | #define SECTION_ASM_OP ".section" | |
642 | #endif | |
643 | ||
644 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
645 | print the SECTION_ASM_OP and the section name. The default here works for | |
646 | almost all svr4 assemblers, except for the sparc, where the section name | |
647 | must be enclosed in double quotes. (See sparcv4.h). */ | |
648 | #ifndef SECTION_FORMAT | |
649 | #define SECTION_FORMAT "\t%s\t%s\n" | |
650 | #endif | |
651 | ||
652 | /* Section names used to hold DWARF debugging information. */ | |
653 | #ifndef DEBUG_SECTION | |
654 | #define DEBUG_SECTION ".debug_info" | |
655 | #endif | |
656 | #ifndef ABBREV_SECTION | |
657 | #define ABBREV_SECTION ".debug_abbrev" | |
658 | #endif | |
659 | #ifndef ARANGES_SECTION | |
660 | #define ARANGES_SECTION ".debug_aranges" | |
661 | #endif | |
662 | #ifndef DW_MACINFO_SECTION | |
663 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
664 | #endif | |
665 | #ifndef FRAME_SECTION | |
666 | #define FRAME_SECTION ".debug_frame" | |
667 | #endif | |
668 | #ifndef LINE_SECTION | |
669 | #define LINE_SECTION ".debug_line" | |
670 | #endif | |
671 | #ifndef LOC_SECTION | |
672 | #define LOC_SECTION ".debug_loc" | |
673 | #endif | |
674 | #ifndef PUBNAMES_SECTION | |
675 | #define PUBNAMES_SECTION ".debug_pubnames" | |
676 | #endif | |
677 | #ifndef STR_SECTION | |
678 | #define STR_SECTION ".debug_str" | |
679 | #endif | |
680 | ||
681 | /* Standerd ELF section names for compiled code and data. */ | |
682 | #ifndef TEXT_SECTION | |
683 | #define TEXT_SECTION ".text" | |
684 | #endif | |
685 | #ifndef DATA_SECTION | |
686 | #define DATA_SECTION ".data" | |
687 | #endif | |
688 | #ifndef DATA1_SECTION | |
689 | #define DATA1_SECTION ".data1" | |
690 | #endif | |
691 | #ifndef RODATA_SECTION | |
692 | #define RODATA_SECTION ".rodata" | |
693 | #endif | |
694 | #ifndef RODATA1_SECTION | |
695 | #define RODATA1_SECTION ".rodata1" | |
696 | #endif | |
697 | #ifndef BSS_SECTION | |
698 | #define BSS_SECTION ".bss" | |
699 | #endif | |
700 | ||
701 | ||
702 | /* Definitions of defaults for formats and names of various special | |
703 | (artificial) labels which may be generated within this file (when the -g | |
704 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
705 | If necessary, these may be overridden from within the tm.h file, but | |
706 | typically, overriding these defaults is unnecessary. | |
707 | These labels have been hacked so that they all begin with a | |
708 | `.L' sequence to appease the stock sparc/svr4 assembler and the | |
709 | stock m88k/svr4 assembler, both of which need to see .L at the start of a | |
710 | label in order to prevent that label from going into the linker symbol | |
711 | table). Eventually, the ASM_GENERATE_INTERNAL_LABEL and | |
712 | ASM_OUTPUT_INTERNAL_LABEL should be used, but that will require | |
713 | a major rework. */ | |
714 | #ifndef TEXT_BEGIN_LABEL | |
715 | #define TEXT_BEGIN_LABEL ".L_text_b" | |
716 | #endif | |
717 | #ifndef TEXT_END_LABEL | |
718 | #define TEXT_END_LABEL ".L_text_e" | |
719 | #endif | |
720 | #ifndef DATA_BEGIN_LABEL | |
721 | #define DATA_BEGIN_LABEL ".L_data_b" | |
722 | #endif | |
723 | #ifndef DATA_END_LABEL | |
724 | #define DATA_END_LABEL ".L_data_e" | |
725 | #endif | |
726 | #ifndef RODATA_BEGIN_LABEL | |
727 | #define RODATA_BEGIN_LABEL ".L_rodata_b" | |
728 | #endif | |
729 | #ifndef RODATA_END_LABEL | |
730 | #define RODATA_END_LABEL ".L_rodata_e" | |
731 | #endif | |
732 | #ifndef BSS_BEGIN_LABEL | |
733 | #define BSS_BEGIN_LABEL ".L_bss_b" | |
734 | #endif | |
735 | #ifndef BSS_END_LABEL | |
736 | #define BSS_END_LABEL ".L_bss_e" | |
737 | #endif | |
738 | #ifndef LINE_BEGIN_LABEL | |
739 | #define LINE_BEGIN_LABEL ".L_line_b" | |
740 | #endif | |
741 | #ifndef LINE_END_LABEL | |
742 | #define LINE_END_LABEL ".L_line_e" | |
743 | #endif | |
744 | #ifndef INSN_LABEL_FMT | |
745 | #define INSN_LABEL_FMT ".L_I%u_%u" | |
746 | #endif | |
747 | #ifndef BLOCK_BEGIN_LABEL_FMT | |
748 | #define BLOCK_BEGIN_LABEL_FMT ".L_B%u" | |
749 | #endif | |
750 | #ifndef BLOCK_END_LABEL_FMT | |
751 | #define BLOCK_END_LABEL_FMT ".L_B%u_e" | |
752 | #endif | |
753 | #ifndef BODY_BEGIN_LABEL_FMT | |
754 | #define BODY_BEGIN_LABEL_FMT ".L_b%u" | |
755 | #endif | |
756 | #ifndef BODY_END_LABEL_FMT | |
757 | #define BODY_END_LABEL_FMT ".L_b%u_e" | |
758 | #endif | |
d291dd49 JM |
759 | #ifndef FUNC_BEGIN_LABEL_FMT |
760 | #define FUNC_BEGIN_LABEL_FMT ".L_f%u" | |
761 | #endif | |
a3f97cbb JW |
762 | #ifndef FUNC_END_LABEL_FMT |
763 | #define FUNC_END_LABEL_FMT ".L_f%u_e" | |
764 | #endif | |
765 | #ifndef LINE_CODE_LABEL_FMT | |
766 | #define LINE_CODE_LABEL_FMT ".L_LC%u" | |
767 | #endif | |
e90b62db JM |
768 | #ifndef SEPARATE_LINE_CODE_LABEL_FMT |
769 | #define SEPARATE_LINE_CODE_LABEL_FMT ".L_SLC%u" | |
770 | #endif | |
a3f97cbb JW |
771 | #ifndef SFNAMES_ENTRY_LABEL_FMT |
772 | #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u" | |
773 | #endif | |
774 | ||
a3f97cbb JW |
775 | /* Definitions of defaults for various types of primitive assembly language |
776 | output operations. These may be overridden from within the tm.h file, | |
777 | but typically, that is unecessary. */ | |
778 | #ifndef ASM_OUTPUT_SECTION | |
779 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
780 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
781 | #endif | |
782 | ||
783 | #ifndef ASM_OUTPUT_DWARF_DELTA2 | |
784 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
785 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ | |
786 | assemble_name (FILE, LABEL1); \ | |
787 | fprintf (FILE, "-"); \ | |
788 | assemble_name (FILE, LABEL2); \ | |
789 | } while (0) | |
790 | #endif | |
791 | ||
792 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
793 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
794 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
795 | assemble_name (FILE, LABEL1); \ | |
796 | fprintf (FILE, "-"); \ | |
797 | assemble_name (FILE, LABEL2); \ | |
798 | } while (0) | |
799 | #endif | |
800 | ||
801 | #ifndef ASM_OUTPUT_DWARF_ADDR | |
802 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
803 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
804 | assemble_name (FILE, LABEL); \ | |
805 | } while (0) | |
806 | #endif | |
807 | ||
808 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
809 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \ | |
810 | fprintf ((FILE), "\t%s\t%s", UNALIGNED_INT_ASM_OP, (ADDR)) | |
811 | #endif | |
812 | ||
813 | #ifndef ASM_OUTPUT_DWARF_DATA1 | |
814 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
815 | fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE) | |
816 | #endif | |
817 | ||
818 | #ifndef ASM_OUTPUT_DWARF_DATA2 | |
819 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
820 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) | |
821 | #endif | |
822 | ||
823 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
824 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
825 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) | |
826 | #endif | |
827 | ||
828 | #ifndef ASM_OUTPUT_DWARF_DATA8 | |
829 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
830 | do { \ | |
831 | if (WORDS_BIG_ENDIAN) \ | |
832 | { \ | |
833 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
834 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
835 | } \ | |
836 | else \ | |
837 | { \ | |
838 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
839 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
840 | } \ | |
841 | } while (0) | |
842 | #endif | |
843 | ||
844 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing | |
845 | newline is produced. When flag_verbose_asm is asserted, we add commnetary | |
846 | at the end of the line, so we must avoid output of a newline here. */ | |
847 | #ifndef ASM_OUTPUT_DWARF_STRING | |
848 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
849 | do { \ | |
850 | register int slen = strlen(P); \ | |
851 | register char *p = (P); \ | |
852 | register int i; \ | |
853 | fprintf (FILE, "\t.ascii \""); \ | |
854 | for (i = 0; i < slen; i++) \ | |
855 | { \ | |
856 | register int c = p[i]; \ | |
857 | if (c == '\"' || c == '\\') \ | |
858 | putc ('\\', FILE); \ | |
859 | if (c >= ' ' && c < 0177) \ | |
860 | putc (c, FILE); \ | |
861 | else \ | |
862 | { \ | |
863 | fprintf (FILE, "\\%o", c); \ | |
864 | } \ | |
865 | } \ | |
866 | fprintf (FILE, "\\0\""); \ | |
867 | } \ | |
868 | while (0) | |
869 | #endif | |
870 | ||
871 | /* Convert a reference to the assembler name of a C-level name. This | |
872 | macro has the same effect as ASM_OUTPUT_LABELREF, but copies to | |
873 | a string rather than writing to a file. */ | |
874 | #ifndef ASM_NAME_TO_STRING | |
875 | #define ASM_NAME_TO_STRING(STR, NAME) \ | |
876 | do { \ | |
877 | if ((NAME)[0] == '*') \ | |
878 | strcpy (STR, NAME+1); \ | |
879 | else \ | |
880 | strcpy (STR, NAME); \ | |
881 | } \ | |
882 | while (0) | |
883 | #endif | |
884 | ||
885 | \f | |
886 | /************************ general utility functions **************************/ | |
887 | ||
888 | /* Return a pointer to a copy of the section string name 's' with all | |
889 | attributes stripped off. */ | |
890 | inline char * | |
891 | stripattributes (s) | |
892 | register char *s; | |
893 | { | |
894 | register char *stripped, *p; | |
895 | stripped = xstrdup (s); | |
896 | p = stripped; | |
897 | while (*p && *p != ',') | |
898 | p++; | |
899 | *p = '\0'; | |
900 | return stripped; | |
901 | } | |
902 | ||
903 | /* Convert an integer constant expression into assembler syntax. | |
904 | Addition and subtraction are the only arithmetic | |
905 | that may appear in these expressions. This is an adaptation | |
906 | of output_addr_const() in final.c. Here, the target of the | |
907 | conversion is a string buffer. We can't use output_addr_const | |
908 | directly, because it writes to a file. */ | |
909 | static void | |
910 | addr_const_to_string (str, x) | |
911 | char *str; | |
912 | rtx x; | |
913 | { | |
914 | char buf1[256]; | |
915 | char buf2[256]; | |
916 | ||
917 | restart: | |
918 | str[0] = '\0'; | |
919 | switch (GET_CODE (x)) | |
920 | { | |
921 | case PC: | |
922 | if (flag_pic) | |
923 | strcat (str, ","); | |
924 | else | |
925 | abort (); | |
926 | break; | |
927 | ||
928 | case SYMBOL_REF: | |
929 | ASM_NAME_TO_STRING (buf1, XSTR (x, 0)); | |
930 | strcat (str, buf1); | |
931 | break; | |
932 | ||
933 | case LABEL_REF: | |
934 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); | |
935 | ASM_NAME_TO_STRING (buf2, buf1); | |
936 | strcat (str, buf2); | |
937 | break; | |
938 | ||
939 | case CODE_LABEL: | |
940 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); | |
941 | ASM_NAME_TO_STRING (buf2, buf1); | |
942 | strcat (str, buf2); | |
943 | break; | |
944 | ||
945 | case CONST_INT: | |
946 | sprintf (buf1, | |
947 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
948 | "%d", | |
949 | #else | |
950 | "%ld", | |
951 | #endif | |
952 | INTVAL (x)); | |
953 | strcat (str, buf1); | |
954 | break; | |
955 | ||
956 | case CONST: | |
957 | /* This used to output parentheses around the expression, but that does | |
958 | not work on the 386 (either ATT or BSD assembler). */ | |
959 | addr_const_to_string (buf1, XEXP (x, 0)); | |
960 | strcat (str, buf1); | |
961 | break; | |
962 | ||
963 | case CONST_DOUBLE: | |
964 | if (GET_MODE (x) == VOIDmode) | |
965 | { | |
966 | /* We can use %d if the number is one word and positive. */ | |
967 | if (CONST_DOUBLE_HIGH (x)) | |
968 | sprintf (buf1, | |
969 | #if HOST_BITS_PER_WIDE_INT == 64 | |
970 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
971 | "0x%lx%016lx", | |
972 | #else | |
973 | "0x%x%016x", | |
974 | #endif | |
975 | #else | |
976 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
977 | "0x%lx%08lx", | |
978 | #else | |
979 | "0x%x%08x", | |
980 | #endif | |
981 | #endif | |
982 | CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); | |
983 | else if (CONST_DOUBLE_LOW (x) < 0) | |
984 | sprintf (buf1, | |
985 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
986 | "0x%x", | |
987 | #else | |
988 | "0x%lx", | |
989 | #endif | |
990 | CONST_DOUBLE_LOW (x)); | |
991 | else | |
992 | sprintf (buf1, | |
993 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
994 | "%d", | |
995 | #else | |
996 | "%ld", | |
997 | #endif | |
998 | CONST_DOUBLE_LOW (x)); | |
999 | strcat (str, buf1); | |
1000 | } | |
1001 | else | |
1002 | /* We can't handle floating point constants; PRINT_OPERAND must | |
1003 | handle them. */ | |
1004 | output_operand_lossage ("floating constant misused"); | |
1005 | break; | |
1006 | ||
1007 | case PLUS: | |
1008 | /* Some assemblers need integer constants to appear last (eg masm). */ | |
1009 | if (GET_CODE (XEXP (x, 0)) == CONST_INT) | |
1010 | { | |
1011 | addr_const_to_string (buf1, XEXP (x, 1)); | |
1012 | strcat (str, buf1); | |
1013 | if (INTVAL (XEXP (x, 0)) >= 0) | |
1014 | strcat (str, "+"); | |
1015 | addr_const_to_string (buf1, XEXP (x, 0)); | |
1016 | strcat (str, buf1); | |
1017 | } | |
1018 | else | |
1019 | { | |
1020 | addr_const_to_string (buf1, XEXP (x, 0)); | |
1021 | strcat (str, buf1); | |
bdb669cb | 1022 | if (INTVAL (XEXP (x, 1)) >= 0) |
a3f97cbb JW |
1023 | strcat (str, "+"); |
1024 | addr_const_to_string (buf1, XEXP (x, 1)); | |
bdb669cb | 1025 | strcat (str, buf1); |
a3f97cbb JW |
1026 | } |
1027 | break; | |
1028 | ||
1029 | case MINUS: | |
1030 | /* Avoid outputting things like x-x or x+5-x, since some assemblers | |
1031 | can't handle that. */ | |
1032 | x = simplify_subtraction (x); | |
1033 | if (GET_CODE (x) != MINUS) | |
1034 | goto restart; | |
1035 | ||
1036 | addr_const_to_string (buf1, XEXP (x, 0)); | |
1037 | strcat (str, buf1); | |
1038 | strcat (str, "-"); | |
1039 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
1040 | && INTVAL (XEXP (x, 1)) < 0) | |
1041 | { | |
1042 | strcat (str, ASM_OPEN_PAREN); | |
1043 | addr_const_to_string (buf1, XEXP (x, 1)); | |
1044 | strcat (str, buf1); | |
1045 | strcat (str, ASM_CLOSE_PAREN); | |
1046 | } | |
1047 | else | |
1048 | { | |
1049 | addr_const_to_string (buf1, XEXP (x, 1)); | |
1050 | strcat (str, buf1); | |
1051 | } | |
1052 | break; | |
1053 | ||
1054 | case ZERO_EXTEND: | |
1055 | case SIGN_EXTEND: | |
1056 | addr_const_to_string (buf1, XEXP (x, 0)); | |
1057 | strcat (str, buf1); | |
1058 | break; | |
1059 | ||
1060 | default: | |
1061 | output_operand_lossage ("invalid expression as operand"); | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | /* Convert an address constant to a string, and return a pointer to | |
1066 | a copy of the result, located on the heap. */ | |
1067 | static char * | |
1068 | addr_to_string (x) | |
1069 | rtx x; | |
1070 | { | |
1071 | char buf[1024]; | |
1072 | addr_const_to_string (buf, x); | |
1073 | return xstrdup (buf); | |
1074 | } | |
1075 | ||
1076 | /* Test if rtl node points to a psuedo register. */ | |
1077 | inline int | |
1078 | is_pseudo_reg (rtl) | |
1079 | register rtx rtl; | |
1080 | { | |
1081 | return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) | |
1082 | || ((GET_CODE (rtl) == SUBREG) | |
1083 | && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER))); | |
1084 | } | |
1085 | ||
1086 | ||
1087 | /* Return a reference to a type, with its const and volatile qualifiers | |
1088 | removed. */ | |
1089 | inline tree | |
1090 | type_main_variant (type) | |
1091 | register tree type; | |
1092 | { | |
1093 | type = TYPE_MAIN_VARIANT (type); | |
1094 | ||
1095 | /* There really should be only one main variant among any group of variants | |
1096 | of a given type (and all of the MAIN_VARIANT values for all members of | |
1097 | the group should point to that one type) but sometimes the C front-end | |
1098 | messes this up for array types, so we work around that bug here. */ | |
1099 | if (TREE_CODE (type) == ARRAY_TYPE) | |
1100 | { | |
1101 | while (type != TYPE_MAIN_VARIANT (type)) | |
1102 | type = TYPE_MAIN_VARIANT (type); | |
1103 | } | |
1104 | return type; | |
1105 | } | |
1106 | ||
1107 | /* Return non-zero if the given type node represents a tagged type. */ | |
1108 | inline int | |
1109 | is_tagged_type (type) | |
1110 | register tree type; | |
1111 | { | |
1112 | register enum tree_code code = TREE_CODE (type); | |
1113 | ||
1114 | return (code == RECORD_TYPE || code == UNION_TYPE | |
1115 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
1116 | } | |
1117 | ||
1118 | /* Convert a DIE tag into its string name. */ | |
1119 | static char * | |
1120 | dwarf_tag_name (tag) | |
1121 | register unsigned tag; | |
1122 | { | |
1123 | switch (tag) | |
1124 | { | |
1125 | case DW_TAG_padding: | |
1126 | return "DW_TAG_padding"; | |
1127 | case DW_TAG_array_type: | |
1128 | return "DW_TAG_array_type"; | |
1129 | case DW_TAG_class_type: | |
1130 | return "DW_TAG_class_type"; | |
1131 | case DW_TAG_entry_point: | |
1132 | return "DW_TAG_entry_point"; | |
1133 | case DW_TAG_enumeration_type: | |
1134 | return "DW_TAG_enumeration_type"; | |
1135 | case DW_TAG_formal_parameter: | |
1136 | return "DW_TAG_formal_parameter"; | |
1137 | case DW_TAG_imported_declaration: | |
1138 | return "DW_TAG_imported_declaration"; | |
1139 | case DW_TAG_label: | |
1140 | return "DW_TAG_label"; | |
1141 | case DW_TAG_lexical_block: | |
1142 | return "DW_TAG_lexical_block"; | |
1143 | case DW_TAG_member: | |
1144 | return "DW_TAG_member"; | |
1145 | case DW_TAG_pointer_type: | |
1146 | return "DW_TAG_pointer_type"; | |
1147 | case DW_TAG_reference_type: | |
1148 | return "DW_TAG_reference_type"; | |
1149 | case DW_TAG_compile_unit: | |
1150 | return "DW_TAG_compile_unit"; | |
1151 | case DW_TAG_string_type: | |
1152 | return "DW_TAG_string_type"; | |
1153 | case DW_TAG_structure_type: | |
1154 | return "DW_TAG_structure_type"; | |
1155 | case DW_TAG_subroutine_type: | |
1156 | return "DW_TAG_subroutine_type"; | |
1157 | case DW_TAG_typedef: | |
1158 | return "DW_TAG_typedef"; | |
1159 | case DW_TAG_union_type: | |
1160 | return "DW_TAG_union_type"; | |
1161 | case DW_TAG_unspecified_parameters: | |
1162 | return "DW_TAG_unspecified_parameters"; | |
1163 | case DW_TAG_variant: | |
1164 | return "DW_TAG_variant"; | |
1165 | case DW_TAG_common_block: | |
1166 | return "DW_TAG_common_block"; | |
1167 | case DW_TAG_common_inclusion: | |
1168 | return "DW_TAG_common_inclusion"; | |
1169 | case DW_TAG_inheritance: | |
1170 | return "DW_TAG_inheritance"; | |
1171 | case DW_TAG_inlined_subroutine: | |
1172 | return "DW_TAG_inlined_subroutine"; | |
1173 | case DW_TAG_module: | |
1174 | return "DW_TAG_module"; | |
1175 | case DW_TAG_ptr_to_member_type: | |
1176 | return "DW_TAG_ptr_to_member_type"; | |
1177 | case DW_TAG_set_type: | |
1178 | return "DW_TAG_set_type"; | |
1179 | case DW_TAG_subrange_type: | |
1180 | return "DW_TAG_subrange_type"; | |
1181 | case DW_TAG_with_stmt: | |
1182 | return "DW_TAG_with_stmt"; | |
1183 | case DW_TAG_access_declaration: | |
1184 | return "DW_TAG_access_declaration"; | |
1185 | case DW_TAG_base_type: | |
1186 | return "DW_TAG_base_type"; | |
1187 | case DW_TAG_catch_block: | |
1188 | return "DW_TAG_catch_block"; | |
1189 | case DW_TAG_const_type: | |
1190 | return "DW_TAG_const_type"; | |
1191 | case DW_TAG_constant: | |
1192 | return "DW_TAG_constant"; | |
1193 | case DW_TAG_enumerator: | |
1194 | return "DW_TAG_enumerator"; | |
1195 | case DW_TAG_file_type: | |
1196 | return "DW_TAG_file_type"; | |
1197 | case DW_TAG_friend: | |
1198 | return "DW_TAG_friend"; | |
1199 | case DW_TAG_namelist: | |
1200 | return "DW_TAG_namelist"; | |
1201 | case DW_TAG_namelist_item: | |
1202 | return "DW_TAG_namelist_item"; | |
1203 | case DW_TAG_packed_type: | |
1204 | return "DW_TAG_packed_type"; | |
1205 | case DW_TAG_subprogram: | |
1206 | return "DW_TAG_subprogram"; | |
1207 | case DW_TAG_template_type_param: | |
1208 | return "DW_TAG_template_type_param"; | |
1209 | case DW_TAG_template_value_param: | |
1210 | return "DW_TAG_template_value_param"; | |
1211 | case DW_TAG_thrown_type: | |
1212 | return "DW_TAG_thrown_type"; | |
1213 | case DW_TAG_try_block: | |
1214 | return "DW_TAG_try_block"; | |
1215 | case DW_TAG_variant_part: | |
1216 | return "DW_TAG_variant_part"; | |
1217 | case DW_TAG_variable: | |
1218 | return "DW_TAG_variable"; | |
1219 | case DW_TAG_volatile_type: | |
1220 | return "DW_TAG_volatile_type"; | |
1221 | case DW_TAG_MIPS_loop: | |
1222 | return "DW_TAG_MIPS_loop"; | |
1223 | case DW_TAG_format_label: | |
1224 | return "DW_TAG_format_label"; | |
1225 | case DW_TAG_function_template: | |
1226 | return "DW_TAG_function_template"; | |
1227 | case DW_TAG_class_template: | |
1228 | return "DW_TAG_class_template"; | |
1229 | default: | |
1230 | return "DW_TAG_<unknown>"; | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | /* Convert a DWARF attribute code into its string name. */ | |
1235 | static char * | |
1236 | dwarf_attr_name (attr) | |
1237 | register unsigned attr; | |
1238 | { | |
1239 | switch (attr) | |
1240 | { | |
1241 | case DW_AT_sibling: | |
1242 | return "DW_AT_sibling"; | |
1243 | case DW_AT_location: | |
1244 | return "DW_AT_location"; | |
1245 | case DW_AT_name: | |
1246 | return "DW_AT_name"; | |
1247 | case DW_AT_ordering: | |
1248 | return "DW_AT_ordering"; | |
1249 | case DW_AT_subscr_data: | |
1250 | return "DW_AT_subscr_data"; | |
1251 | case DW_AT_byte_size: | |
1252 | return "DW_AT_byte_size"; | |
1253 | case DW_AT_bit_offset: | |
1254 | return "DW_AT_bit_offset"; | |
1255 | case DW_AT_bit_size: | |
1256 | return "DW_AT_bit_size"; | |
1257 | case DW_AT_element_list: | |
1258 | return "DW_AT_element_list"; | |
1259 | case DW_AT_stmt_list: | |
1260 | return "DW_AT_stmt_list"; | |
1261 | case DW_AT_low_pc: | |
1262 | return "DW_AT_low_pc"; | |
1263 | case DW_AT_high_pc: | |
1264 | return "DW_AT_high_pc"; | |
1265 | case DW_AT_language: | |
1266 | return "DW_AT_language"; | |
1267 | case DW_AT_member: | |
1268 | return "DW_AT_member"; | |
1269 | case DW_AT_discr: | |
1270 | return "DW_AT_discr"; | |
1271 | case DW_AT_discr_value: | |
1272 | return "DW_AT_discr_value"; | |
1273 | case DW_AT_visibility: | |
1274 | return "DW_AT_visibility"; | |
1275 | case DW_AT_import: | |
1276 | return "DW_AT_import"; | |
1277 | case DW_AT_string_length: | |
1278 | return "DW_AT_string_length"; | |
1279 | case DW_AT_common_reference: | |
1280 | return "DW_AT_common_reference"; | |
1281 | case DW_AT_comp_dir: | |
1282 | return "DW_AT_comp_dir"; | |
1283 | case DW_AT_const_value: | |
1284 | return "DW_AT_const_value"; | |
1285 | case DW_AT_containing_type: | |
1286 | return "DW_AT_containing_type"; | |
1287 | case DW_AT_default_value: | |
1288 | return "DW_AT_default_value"; | |
1289 | case DW_AT_inline: | |
1290 | return "DW_AT_inline"; | |
1291 | case DW_AT_is_optional: | |
1292 | return "DW_AT_is_optional"; | |
1293 | case DW_AT_lower_bound: | |
1294 | return "DW_AT_lower_bound"; | |
1295 | case DW_AT_producer: | |
1296 | return "DW_AT_producer"; | |
1297 | case DW_AT_prototyped: | |
1298 | return "DW_AT_prototyped"; | |
1299 | case DW_AT_return_addr: | |
1300 | return "DW_AT_return_addr"; | |
1301 | case DW_AT_start_scope: | |
1302 | return "DW_AT_start_scope"; | |
1303 | case DW_AT_stride_size: | |
1304 | return "DW_AT_stride_size"; | |
1305 | case DW_AT_upper_bound: | |
1306 | return "DW_AT_upper_bound"; | |
1307 | case DW_AT_abstract_origin: | |
1308 | return "DW_AT_abstract_origin"; | |
1309 | case DW_AT_accessibility: | |
1310 | return "DW_AT_accessibility"; | |
1311 | case DW_AT_address_class: | |
1312 | return "DW_AT_address_class"; | |
1313 | case DW_AT_artificial: | |
1314 | return "DW_AT_artificial"; | |
1315 | case DW_AT_base_types: | |
1316 | return "DW_AT_base_types"; | |
1317 | case DW_AT_calling_convention: | |
1318 | return "DW_AT_calling_convention"; | |
1319 | case DW_AT_count: | |
1320 | return "DW_AT_count"; | |
1321 | case DW_AT_data_member_location: | |
1322 | return "DW_AT_data_member_location"; | |
1323 | case DW_AT_decl_column: | |
1324 | return "DW_AT_decl_column"; | |
1325 | case DW_AT_decl_file: | |
1326 | return "DW_AT_decl_file"; | |
1327 | case DW_AT_decl_line: | |
1328 | return "DW_AT_decl_line"; | |
1329 | case DW_AT_declaration: | |
1330 | return "DW_AT_declaration"; | |
1331 | case DW_AT_discr_list: | |
1332 | return "DW_AT_discr_list"; | |
1333 | case DW_AT_encoding: | |
1334 | return "DW_AT_encoding"; | |
1335 | case DW_AT_external: | |
1336 | return "DW_AT_external"; | |
1337 | case DW_AT_frame_base: | |
1338 | return "DW_AT_frame_base"; | |
1339 | case DW_AT_friend: | |
1340 | return "DW_AT_friend"; | |
1341 | case DW_AT_identifier_case: | |
1342 | return "DW_AT_identifier_case"; | |
1343 | case DW_AT_macro_info: | |
1344 | return "DW_AT_macro_info"; | |
1345 | case DW_AT_namelist_items: | |
1346 | return "DW_AT_namelist_items"; | |
1347 | case DW_AT_priority: | |
1348 | return "DW_AT_priority"; | |
1349 | case DW_AT_segment: | |
1350 | return "DW_AT_segment"; | |
1351 | case DW_AT_specification: | |
1352 | return "DW_AT_specification"; | |
1353 | case DW_AT_static_link: | |
1354 | return "DW_AT_static_link"; | |
1355 | case DW_AT_type: | |
1356 | return "DW_AT_type"; | |
1357 | case DW_AT_use_location: | |
1358 | return "DW_AT_use_location"; | |
1359 | case DW_AT_variable_parameter: | |
1360 | return "DW_AT_variable_parameter"; | |
1361 | case DW_AT_virtuality: | |
1362 | return "DW_AT_virtuality"; | |
1363 | case DW_AT_vtable_elem_location: | |
1364 | return "DW_AT_vtable_elem_location"; | |
1365 | ||
1366 | #ifdef MIPS_DEBUGGING_INFO | |
1367 | case DW_AT_MIPS_fde: | |
1368 | return "DW_AT_MIPS_fde"; | |
1369 | case DW_AT_MIPS_loop_begin: | |
1370 | return "DW_AT_MIPS_loop_begin"; | |
1371 | case DW_AT_MIPS_tail_loop_begin: | |
1372 | return "DW_AT_MIPS_tail_loop_begin"; | |
1373 | case DW_AT_MIPS_epilog_begin: | |
1374 | return "DW_AT_MIPS_epilog_begin"; | |
1375 | case DW_AT_MIPS_loop_unroll_factor: | |
1376 | return "DW_AT_MIPS_loop_unroll_factor"; | |
1377 | case DW_AT_MIPS_software_pipeline_depth: | |
1378 | return "DW_AT_MIPS_software_pipeline_depth"; | |
1379 | case DW_AT_MIPS_linkage_name: | |
1380 | return "DW_AT_MIPS_linkage_name"; | |
1381 | #endif | |
1382 | ||
1383 | case DW_AT_sf_names: | |
1384 | return "DW_AT_sf_names"; | |
1385 | case DW_AT_src_info: | |
1386 | return "DW_AT_src_info"; | |
1387 | case DW_AT_mac_info: | |
1388 | return "DW_AT_mac_info"; | |
1389 | case DW_AT_src_coords: | |
1390 | return "DW_AT_src_coords"; | |
1391 | case DW_AT_body_begin: | |
1392 | return "DW_AT_body_begin"; | |
1393 | case DW_AT_body_end: | |
1394 | return "DW_AT_body_end"; | |
1395 | default: | |
1396 | return "DW_AT_<unknown>"; | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | /* Convert a DWARF value form code into its string name. */ | |
1401 | static char * | |
1402 | dwarf_form_name (form) | |
1403 | register unsigned form; | |
1404 | { | |
1405 | switch (form) | |
1406 | { | |
1407 | case DW_FORM_addr: | |
1408 | return "DW_FORM_addr"; | |
1409 | case DW_FORM_block2: | |
1410 | return "DW_FORM_block2"; | |
1411 | case DW_FORM_block4: | |
1412 | return "DW_FORM_block4"; | |
1413 | case DW_FORM_data2: | |
1414 | return "DW_FORM_data2"; | |
1415 | case DW_FORM_data4: | |
1416 | return "DW_FORM_data4"; | |
1417 | case DW_FORM_data8: | |
1418 | return "DW_FORM_data8"; | |
1419 | case DW_FORM_string: | |
1420 | return "DW_FORM_string"; | |
1421 | case DW_FORM_block: | |
1422 | return "DW_FORM_block"; | |
1423 | case DW_FORM_block1: | |
1424 | return "DW_FORM_block1"; | |
1425 | case DW_FORM_data1: | |
1426 | return "DW_FORM_data1"; | |
1427 | case DW_FORM_flag: | |
1428 | return "DW_FORM_flag"; | |
1429 | case DW_FORM_sdata: | |
1430 | return "DW_FORM_sdata"; | |
1431 | case DW_FORM_strp: | |
1432 | return "DW_FORM_strp"; | |
1433 | case DW_FORM_udata: | |
1434 | return "DW_FORM_udata"; | |
1435 | case DW_FORM_ref_addr: | |
1436 | return "DW_FORM_ref_addr"; | |
1437 | case DW_FORM_ref1: | |
1438 | return "DW_FORM_ref1"; | |
1439 | case DW_FORM_ref2: | |
1440 | return "DW_FORM_ref2"; | |
1441 | case DW_FORM_ref4: | |
1442 | return "DW_FORM_ref4"; | |
1443 | case DW_FORM_ref8: | |
1444 | return "DW_FORM_ref8"; | |
1445 | case DW_FORM_ref_udata: | |
1446 | return "DW_FORM_ref_udata"; | |
1447 | case DW_FORM_indirect: | |
1448 | return "DW_FORM_indirect"; | |
1449 | default: | |
1450 | return "DW_FORM_<unknown>"; | |
1451 | } | |
1452 | } | |
1453 | ||
1454 | /* Convert a DWARF stack opcode into its string name. */ | |
1455 | static char * | |
1456 | dwarf_stack_op_name (op) | |
1457 | register unsigned op; | |
1458 | { | |
1459 | switch (op) | |
1460 | { | |
1461 | case DW_OP_addr: | |
1462 | return "DW_OP_addr"; | |
1463 | case DW_OP_deref: | |
1464 | return "DW_OP_deref"; | |
1465 | case DW_OP_const1u: | |
1466 | return "DW_OP_const1u"; | |
1467 | case DW_OP_const1s: | |
1468 | return "DW_OP_const1s"; | |
1469 | case DW_OP_const2u: | |
1470 | return "DW_OP_const2u"; | |
1471 | case DW_OP_const2s: | |
1472 | return "DW_OP_const2s"; | |
1473 | case DW_OP_const4u: | |
1474 | return "DW_OP_const4u"; | |
1475 | case DW_OP_const4s: | |
1476 | return "DW_OP_const4s"; | |
1477 | case DW_OP_const8u: | |
1478 | return "DW_OP_const8u"; | |
1479 | case DW_OP_const8s: | |
1480 | return "DW_OP_const8s"; | |
1481 | case DW_OP_constu: | |
1482 | return "DW_OP_constu"; | |
1483 | case DW_OP_consts: | |
1484 | return "DW_OP_consts"; | |
1485 | case DW_OP_dup: | |
1486 | return "DW_OP_dup"; | |
1487 | case DW_OP_drop: | |
1488 | return "DW_OP_drop"; | |
1489 | case DW_OP_over: | |
1490 | return "DW_OP_over"; | |
1491 | case DW_OP_pick: | |
1492 | return "DW_OP_pick"; | |
1493 | case DW_OP_swap: | |
1494 | return "DW_OP_swap"; | |
1495 | case DW_OP_rot: | |
1496 | return "DW_OP_rot"; | |
1497 | case DW_OP_xderef: | |
1498 | return "DW_OP_xderef"; | |
1499 | case DW_OP_abs: | |
1500 | return "DW_OP_abs"; | |
1501 | case DW_OP_and: | |
1502 | return "DW_OP_and"; | |
1503 | case DW_OP_div: | |
1504 | return "DW_OP_div"; | |
1505 | case DW_OP_minus: | |
1506 | return "DW_OP_minus"; | |
1507 | case DW_OP_mod: | |
1508 | return "DW_OP_mod"; | |
1509 | case DW_OP_mul: | |
1510 | return "DW_OP_mul"; | |
1511 | case DW_OP_neg: | |
1512 | return "DW_OP_neg"; | |
1513 | case DW_OP_not: | |
1514 | return "DW_OP_not"; | |
1515 | case DW_OP_or: | |
1516 | return "DW_OP_or"; | |
1517 | case DW_OP_plus: | |
1518 | return "DW_OP_plus"; | |
1519 | case DW_OP_plus_uconst: | |
1520 | return "DW_OP_plus_uconst"; | |
1521 | case DW_OP_shl: | |
1522 | return "DW_OP_shl"; | |
1523 | case DW_OP_shr: | |
1524 | return "DW_OP_shr"; | |
1525 | case DW_OP_shra: | |
1526 | return "DW_OP_shra"; | |
1527 | case DW_OP_xor: | |
1528 | return "DW_OP_xor"; | |
1529 | case DW_OP_bra: | |
1530 | return "DW_OP_bra"; | |
1531 | case DW_OP_eq: | |
1532 | return "DW_OP_eq"; | |
1533 | case DW_OP_ge: | |
1534 | return "DW_OP_ge"; | |
1535 | case DW_OP_gt: | |
1536 | return "DW_OP_gt"; | |
1537 | case DW_OP_le: | |
1538 | return "DW_OP_le"; | |
1539 | case DW_OP_lt: | |
1540 | return "DW_OP_lt"; | |
1541 | case DW_OP_ne: | |
1542 | return "DW_OP_ne"; | |
1543 | case DW_OP_skip: | |
1544 | return "DW_OP_skip"; | |
1545 | case DW_OP_lit0: | |
1546 | return "DW_OP_lit0"; | |
1547 | case DW_OP_lit1: | |
1548 | return "DW_OP_lit1"; | |
1549 | case DW_OP_lit2: | |
1550 | return "DW_OP_lit2"; | |
1551 | case DW_OP_lit3: | |
1552 | return "DW_OP_lit3"; | |
1553 | case DW_OP_lit4: | |
1554 | return "DW_OP_lit4"; | |
1555 | case DW_OP_lit5: | |
1556 | return "DW_OP_lit5"; | |
1557 | case DW_OP_lit6: | |
1558 | return "DW_OP_lit6"; | |
1559 | case DW_OP_lit7: | |
1560 | return "DW_OP_lit7"; | |
1561 | case DW_OP_lit8: | |
1562 | return "DW_OP_lit8"; | |
1563 | case DW_OP_lit9: | |
1564 | return "DW_OP_lit9"; | |
1565 | case DW_OP_lit10: | |
1566 | return "DW_OP_lit10"; | |
1567 | case DW_OP_lit11: | |
1568 | return "DW_OP_lit11"; | |
1569 | case DW_OP_lit12: | |
1570 | return "DW_OP_lit12"; | |
1571 | case DW_OP_lit13: | |
1572 | return "DW_OP_lit13"; | |
1573 | case DW_OP_lit14: | |
1574 | return "DW_OP_lit14"; | |
1575 | case DW_OP_lit15: | |
1576 | return "DW_OP_lit15"; | |
1577 | case DW_OP_lit16: | |
1578 | return "DW_OP_lit16"; | |
1579 | case DW_OP_lit17: | |
1580 | return "DW_OP_lit17"; | |
1581 | case DW_OP_lit18: | |
1582 | return "DW_OP_lit18"; | |
1583 | case DW_OP_lit19: | |
1584 | return "DW_OP_lit19"; | |
1585 | case DW_OP_lit20: | |
1586 | return "DW_OP_lit20"; | |
1587 | case DW_OP_lit21: | |
1588 | return "DW_OP_lit21"; | |
1589 | case DW_OP_lit22: | |
1590 | return "DW_OP_lit22"; | |
1591 | case DW_OP_lit23: | |
1592 | return "DW_OP_lit23"; | |
1593 | case DW_OP_lit24: | |
1594 | return "DW_OP_lit24"; | |
1595 | case DW_OP_lit25: | |
1596 | return "DW_OP_lit25"; | |
1597 | case DW_OP_lit26: | |
1598 | return "DW_OP_lit26"; | |
1599 | case DW_OP_lit27: | |
1600 | return "DW_OP_lit27"; | |
1601 | case DW_OP_lit28: | |
1602 | return "DW_OP_lit28"; | |
1603 | case DW_OP_lit29: | |
1604 | return "DW_OP_lit29"; | |
1605 | case DW_OP_lit30: | |
1606 | return "DW_OP_lit30"; | |
1607 | case DW_OP_lit31: | |
1608 | return "DW_OP_lit31"; | |
1609 | case DW_OP_reg0: | |
1610 | return "DW_OP_reg0"; | |
1611 | case DW_OP_reg1: | |
1612 | return "DW_OP_reg1"; | |
1613 | case DW_OP_reg2: | |
1614 | return "DW_OP_reg2"; | |
1615 | case DW_OP_reg3: | |
1616 | return "DW_OP_reg3"; | |
1617 | case DW_OP_reg4: | |
1618 | return "DW_OP_reg4"; | |
1619 | case DW_OP_reg5: | |
1620 | return "DW_OP_reg5"; | |
1621 | case DW_OP_reg6: | |
1622 | return "DW_OP_reg6"; | |
1623 | case DW_OP_reg7: | |
1624 | return "DW_OP_reg7"; | |
1625 | case DW_OP_reg8: | |
1626 | return "DW_OP_reg8"; | |
1627 | case DW_OP_reg9: | |
1628 | return "DW_OP_reg9"; | |
1629 | case DW_OP_reg10: | |
1630 | return "DW_OP_reg10"; | |
1631 | case DW_OP_reg11: | |
1632 | return "DW_OP_reg11"; | |
1633 | case DW_OP_reg12: | |
1634 | return "DW_OP_reg12"; | |
1635 | case DW_OP_reg13: | |
1636 | return "DW_OP_reg13"; | |
1637 | case DW_OP_reg14: | |
1638 | return "DW_OP_reg14"; | |
1639 | case DW_OP_reg15: | |
1640 | return "DW_OP_reg15"; | |
1641 | case DW_OP_reg16: | |
1642 | return "DW_OP_reg16"; | |
1643 | case DW_OP_reg17: | |
1644 | return "DW_OP_reg17"; | |
1645 | case DW_OP_reg18: | |
1646 | return "DW_OP_reg18"; | |
1647 | case DW_OP_reg19: | |
1648 | return "DW_OP_reg19"; | |
1649 | case DW_OP_reg20: | |
1650 | return "DW_OP_reg20"; | |
1651 | case DW_OP_reg21: | |
1652 | return "DW_OP_reg21"; | |
1653 | case DW_OP_reg22: | |
1654 | return "DW_OP_reg22"; | |
1655 | case DW_OP_reg23: | |
1656 | return "DW_OP_reg23"; | |
1657 | case DW_OP_reg24: | |
1658 | return "DW_OP_reg24"; | |
1659 | case DW_OP_reg25: | |
1660 | return "DW_OP_reg25"; | |
1661 | case DW_OP_reg26: | |
1662 | return "DW_OP_reg26"; | |
1663 | case DW_OP_reg27: | |
1664 | return "DW_OP_reg27"; | |
1665 | case DW_OP_reg28: | |
1666 | return "DW_OP_reg28"; | |
1667 | case DW_OP_reg29: | |
1668 | return "DW_OP_reg29"; | |
1669 | case DW_OP_reg30: | |
1670 | return "DW_OP_reg30"; | |
1671 | case DW_OP_reg31: | |
1672 | return "DW_OP_reg31"; | |
1673 | case DW_OP_breg0: | |
1674 | return "DW_OP_breg0"; | |
1675 | case DW_OP_breg1: | |
1676 | return "DW_OP_breg1"; | |
1677 | case DW_OP_breg2: | |
1678 | return "DW_OP_breg2"; | |
1679 | case DW_OP_breg3: | |
1680 | return "DW_OP_breg3"; | |
1681 | case DW_OP_breg4: | |
1682 | return "DW_OP_breg4"; | |
1683 | case DW_OP_breg5: | |
1684 | return "DW_OP_breg5"; | |
1685 | case DW_OP_breg6: | |
1686 | return "DW_OP_breg6"; | |
1687 | case DW_OP_breg7: | |
1688 | return "DW_OP_breg7"; | |
1689 | case DW_OP_breg8: | |
1690 | return "DW_OP_breg8"; | |
1691 | case DW_OP_breg9: | |
1692 | return "DW_OP_breg9"; | |
1693 | case DW_OP_breg10: | |
1694 | return "DW_OP_breg10"; | |
1695 | case DW_OP_breg11: | |
1696 | return "DW_OP_breg11"; | |
1697 | case DW_OP_breg12: | |
1698 | return "DW_OP_breg12"; | |
1699 | case DW_OP_breg13: | |
1700 | return "DW_OP_breg13"; | |
1701 | case DW_OP_breg14: | |
1702 | return "DW_OP_breg14"; | |
1703 | case DW_OP_breg15: | |
1704 | return "DW_OP_breg15"; | |
1705 | case DW_OP_breg16: | |
1706 | return "DW_OP_breg16"; | |
1707 | case DW_OP_breg17: | |
1708 | return "DW_OP_breg17"; | |
1709 | case DW_OP_breg18: | |
1710 | return "DW_OP_breg18"; | |
1711 | case DW_OP_breg19: | |
1712 | return "DW_OP_breg19"; | |
1713 | case DW_OP_breg20: | |
1714 | return "DW_OP_breg20"; | |
1715 | case DW_OP_breg21: | |
1716 | return "DW_OP_breg21"; | |
1717 | case DW_OP_breg22: | |
1718 | return "DW_OP_breg22"; | |
1719 | case DW_OP_breg23: | |
1720 | return "DW_OP_breg23"; | |
1721 | case DW_OP_breg24: | |
1722 | return "DW_OP_breg24"; | |
1723 | case DW_OP_breg25: | |
1724 | return "DW_OP_breg25"; | |
1725 | case DW_OP_breg26: | |
1726 | return "DW_OP_breg26"; | |
1727 | case DW_OP_breg27: | |
1728 | return "DW_OP_breg27"; | |
1729 | case DW_OP_breg28: | |
1730 | return "DW_OP_breg28"; | |
1731 | case DW_OP_breg29: | |
1732 | return "DW_OP_breg29"; | |
1733 | case DW_OP_breg30: | |
1734 | return "DW_OP_breg30"; | |
1735 | case DW_OP_breg31: | |
1736 | return "DW_OP_breg31"; | |
1737 | case DW_OP_regx: | |
1738 | return "DW_OP_regx"; | |
1739 | case DW_OP_fbreg: | |
1740 | return "DW_OP_fbreg"; | |
1741 | case DW_OP_bregx: | |
1742 | return "DW_OP_bregx"; | |
1743 | case DW_OP_piece: | |
1744 | return "DW_OP_piece"; | |
1745 | case DW_OP_deref_size: | |
1746 | return "DW_OP_deref_size"; | |
1747 | case DW_OP_xderef_size: | |
1748 | return "DW_OP_xderef_size"; | |
1749 | case DW_OP_nop: | |
1750 | return "DW_OP_nop"; | |
1751 | default: | |
1752 | return "OP_<unknown>"; | |
1753 | } | |
1754 | } | |
1755 | ||
1756 | /* Convert a DWARF type code into its string name. */ | |
1757 | static char * | |
1758 | dwarf_type_encoding_name (enc) | |
1759 | register unsigned enc; | |
1760 | { | |
1761 | switch (enc) | |
1762 | { | |
1763 | case DW_ATE_address: | |
1764 | return "DW_ATE_address"; | |
1765 | case DW_ATE_boolean: | |
1766 | return "DW_ATE_boolean"; | |
1767 | case DW_ATE_complex_float: | |
1768 | return "DW_ATE_complex_float"; | |
1769 | case DW_ATE_float: | |
1770 | return "DW_ATE_float"; | |
1771 | case DW_ATE_signed: | |
1772 | return "DW_ATE_signed"; | |
1773 | case DW_ATE_signed_char: | |
1774 | return "DW_ATE_signed_char"; | |
1775 | case DW_ATE_unsigned: | |
1776 | return "DW_ATE_unsigned"; | |
1777 | case DW_ATE_unsigned_char: | |
1778 | return "DW_ATE_unsigned_char"; | |
1779 | default: | |
1780 | return "DW_ATE_<unknown>"; | |
1781 | } | |
1782 | } | |
1783 | ||
1784 | /* Convert a DWARF call frame info. operation to its string name */ | |
1785 | static char * | |
1786 | dwarf_cfi_name (cfi_opc) | |
1787 | register unsigned cfi_opc; | |
1788 | { | |
1789 | switch (cfi_opc) | |
1790 | { | |
1791 | case DW_CFA_advance_loc: | |
1792 | return "DW_CFA_advance_loc"; | |
1793 | case DW_CFA_offset: | |
1794 | return "DW_CFA_offset"; | |
1795 | case DW_CFA_restore: | |
1796 | return "DW_CFA_restore"; | |
1797 | case DW_CFA_nop: | |
1798 | return "DW_CFA_nop"; | |
1799 | case DW_CFA_set_loc: | |
1800 | return "DW_CFA_set_loc"; | |
1801 | case DW_CFA_advance_loc1: | |
1802 | return "DW_CFA_advance_loc1"; | |
1803 | case DW_CFA_advance_loc2: | |
1804 | return "DW_CFA_advance_loc2"; | |
1805 | case DW_CFA_advance_loc4: | |
1806 | return "DW_CFA_advance_loc4"; | |
1807 | case DW_CFA_offset_extended: | |
1808 | return "DW_CFA_offset_extended"; | |
1809 | case DW_CFA_restore_extended: | |
1810 | return "DW_CFA_restore_extended"; | |
1811 | case DW_CFA_undefined: | |
1812 | return "DW_CFA_undefined"; | |
1813 | case DW_CFA_same_value: | |
1814 | return "DW_CFA_same_value"; | |
1815 | case DW_CFA_register: | |
1816 | return "DW_CFA_register"; | |
1817 | case DW_CFA_remember_state: | |
1818 | return "DW_CFA_remember_state"; | |
1819 | case DW_CFA_restore_state: | |
1820 | return "DW_CFA_restore_state"; | |
1821 | case DW_CFA_def_cfa: | |
1822 | return "DW_CFA_def_cfa"; | |
1823 | case DW_CFA_def_cfa_register: | |
1824 | return "DW_CFA_def_cfa_register"; | |
1825 | case DW_CFA_def_cfa_offset: | |
1826 | return "DW_CFA_def_cfa_offset"; | |
1827 | /* SGI/MIPS specific */ | |
1828 | case DW_CFA_MIPS_advance_loc8: | |
1829 | return "DW_CFA_MIPS_advance_loc8"; | |
1830 | default: | |
1831 | return "DW_CFA_<unknown>"; | |
1832 | } | |
1833 | } | |
1834 | \f | |
1835 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
1836 | instance of an inlined instance of a decl which is local to an inline | |
1837 | function, so we have to trace all of the way back through the origin chain | |
1838 | to find out what sort of node actually served as the original seed for the | |
1839 | given block. */ | |
1840 | static tree | |
1841 | decl_ultimate_origin (decl) | |
1842 | register tree decl; | |
1843 | { | |
1844 | register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl); | |
1845 | ||
1846 | if (immediate_origin == NULL) | |
1847 | return NULL; | |
1848 | else | |
1849 | { | |
1850 | register tree ret_val; | |
1851 | register tree lookahead = immediate_origin; | |
1852 | ||
1853 | do | |
1854 | { | |
1855 | ret_val = lookahead; | |
1856 | lookahead = DECL_ABSTRACT_ORIGIN (ret_val); | |
1857 | } | |
1858 | while (lookahead != NULL && lookahead != ret_val); | |
1859 | return ret_val; | |
1860 | } | |
1861 | } | |
1862 | ||
1863 | /* Determine the "ultimate origin" of a block. The block may be an inlined | |
1864 | instance of an inlined instance of a block which is local to an inline | |
1865 | function, so we have to trace all of the way back through the origin chain | |
1866 | to find out what sort of node actually served as the original seed for the | |
1867 | given block. */ | |
1868 | static tree | |
1869 | block_ultimate_origin (block) | |
1870 | register tree block; | |
1871 | { | |
1872 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); | |
1873 | ||
1874 | if (immediate_origin == NULL) | |
1875 | return NULL; | |
1876 | else | |
1877 | { | |
1878 | register tree ret_val; | |
1879 | register tree lookahead = immediate_origin; | |
1880 | ||
1881 | do | |
1882 | { | |
1883 | ret_val = lookahead; | |
1884 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
1885 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
1886 | : NULL; | |
1887 | } | |
1888 | while (lookahead != NULL && lookahead != ret_val); | |
1889 | return ret_val; | |
1890 | } | |
1891 | } | |
bdb669cb JM |
1892 | |
1893 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT | |
1894 | of a virtual function may refer to a base class, so we check the 'this' | |
1895 | parameter. */ | |
1896 | ||
1897 | tree | |
1898 | decl_class_context (decl) | |
1899 | tree decl; | |
1900 | { | |
1901 | tree context = NULL_TREE; | |
1902 | if (TREE_CODE (decl) != FUNCTION_DECL | |
1903 | || ! DECL_VIRTUAL_P (decl)) | |
1904 | context = DECL_CONTEXT (decl); | |
1905 | else | |
1906 | context = TYPE_MAIN_VARIANT | |
1907 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
1908 | ||
1909 | if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't') | |
1910 | context = NULL_TREE; | |
1911 | ||
1912 | return context; | |
1913 | } | |
a3f97cbb JW |
1914 | \f |
1915 | /**************** DIE internal representation constturction *******************/ | |
1916 | ||
1917 | /* Add an attribute/value pair to a DIE */ | |
1918 | inline void | |
1919 | add_dwarf_attr (die, attr) | |
1920 | register dw_die_ref die; | |
1921 | register dw_attr_ref attr; | |
1922 | { | |
1923 | if (die != NULL && attr != NULL) | |
1924 | { | |
1925 | if (die->die_attr == NULL) | |
1926 | { | |
1927 | die->die_attr = attr; | |
1928 | die->die_attr_last = attr; | |
1929 | } | |
1930 | else | |
1931 | { | |
1932 | die->die_attr_last->dw_attr_next = attr; | |
1933 | die->die_attr_last = attr; | |
1934 | } | |
1935 | } | |
1936 | } | |
1937 | ||
1938 | /* Add a flag value attribute to a DIE. */ | |
1939 | inline void | |
1940 | add_AT_flag (die, attr_kind, flag) | |
1941 | register dw_die_ref die; | |
1942 | register enum dwarf_attribute attr_kind; | |
1943 | register unsigned flag; | |
1944 | { | |
1945 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
1946 | if (attr != NULL) | |
1947 | { | |
1948 | attr->dw_attr_next = NULL; | |
1949 | attr->dw_attr = attr_kind; | |
1950 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
1951 | attr->dw_attr_val.v.val_flag = flag; | |
1952 | add_dwarf_attr (die, attr); | |
1953 | } | |
1954 | } | |
1955 | ||
1956 | /* Add a signed integer attribute value to a DIE. */ | |
1957 | inline void | |
1958 | add_AT_int (die, attr_kind, int_val) | |
1959 | register dw_die_ref die; | |
1960 | register enum dwarf_attribute attr_kind; | |
1961 | register long int int_val; | |
1962 | { | |
1963 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
1964 | if (attr != NULL) | |
1965 | { | |
1966 | attr->dw_attr_next = NULL; | |
1967 | attr->dw_attr = attr_kind; | |
1968 | attr->dw_attr_val.val_class = dw_val_class_const; | |
1969 | attr->dw_attr_val.v.val_int = int_val; | |
1970 | add_dwarf_attr (die, attr); | |
1971 | } | |
1972 | } | |
1973 | ||
1974 | /* Add an unsigned integer attribute value to a DIE. */ | |
1975 | inline void | |
1976 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
1977 | register dw_die_ref die; | |
1978 | register enum dwarf_attribute attr_kind; | |
1979 | register unsigned long unsigned_val; | |
1980 | { | |
1981 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
1982 | if (attr != NULL) | |
1983 | { | |
1984 | attr->dw_attr_next = NULL; | |
1985 | attr->dw_attr = attr_kind; | |
1986 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
1987 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
1988 | add_dwarf_attr (die, attr); | |
1989 | } | |
1990 | } | |
1991 | ||
1992 | /* Add an unsigned double integer attribute value to a DIE. */ | |
1993 | inline void | |
1994 | add_AT_double (die, attr_kind, val_hi, val_low) | |
1995 | register dw_die_ref die; | |
1996 | register enum dwarf_attribute attr_kind; | |
1997 | register unsigned long val_hi; | |
1998 | register unsigned long val_low; | |
1999 | { | |
2000 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2001 | if (attr != NULL) | |
2002 | { | |
2003 | attr->dw_attr_next = NULL; | |
2004 | attr->dw_attr = attr_kind; | |
2005 | attr->dw_attr_val.val_class = dw_val_class_double_const; | |
2006 | attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi; | |
2007 | attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low; | |
2008 | add_dwarf_attr (die, attr); | |
2009 | } | |
2010 | } | |
2011 | ||
2012 | /* Add a string attribute value to a DIE. */ | |
2013 | inline void | |
2014 | add_AT_string (die, attr_kind, str) | |
2015 | register dw_die_ref die; | |
2016 | register enum dwarf_attribute attr_kind; | |
2017 | register char *str; | |
2018 | { | |
2019 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2020 | if (attr != NULL) | |
2021 | { | |
2022 | attr->dw_attr_next = NULL; | |
2023 | attr->dw_attr = attr_kind; | |
2024 | attr->dw_attr_val.val_class = dw_val_class_str; | |
2025 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
2026 | add_dwarf_attr (die, attr); | |
2027 | } | |
2028 | } | |
2029 | ||
2030 | /* Add a DIE reference attribute value to a DIE. */ | |
2031 | inline void | |
2032 | add_AT_die_ref (die, attr_kind, targ_die) | |
2033 | register dw_die_ref die; | |
2034 | register enum dwarf_attribute attr_kind; | |
2035 | register dw_die_ref targ_die; | |
2036 | { | |
2037 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2038 | if (attr != NULL) | |
2039 | { | |
2040 | attr->dw_attr_next = NULL; | |
2041 | attr->dw_attr = attr_kind; | |
2042 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
2043 | attr->dw_attr_val.v.val_die_ref = targ_die; | |
2044 | add_dwarf_attr (die, attr); | |
2045 | } | |
2046 | } | |
2047 | ||
2048 | /* Add an FDE reference attribute value to a DIE. */ | |
2049 | inline void | |
2050 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
2051 | register dw_die_ref die; | |
2052 | register enum dwarf_attribute attr_kind; | |
2053 | register unsigned targ_fde; | |
2054 | { | |
2055 | register dw_attr_ref attr; | |
2056 | ||
2057 | attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2058 | if (attr != NULL) | |
2059 | { | |
2060 | attr->dw_attr_next = NULL; | |
2061 | attr->dw_attr = attr_kind; | |
2062 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
2063 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
2064 | add_dwarf_attr (die, attr); | |
2065 | } | |
2066 | } | |
2067 | ||
2068 | /* Add a location description attribute value to a DIE. */ | |
2069 | inline void | |
2070 | add_AT_loc (die, attr_kind, loc) | |
2071 | register dw_die_ref die; | |
2072 | register enum dwarf_attribute attr_kind; | |
2073 | register dw_loc_descr_ref loc; | |
2074 | { | |
2075 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2076 | if (attr != NULL) | |
2077 | { | |
2078 | attr->dw_attr_next = NULL; | |
2079 | attr->dw_attr = attr_kind; | |
2080 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
2081 | attr->dw_attr_val.v.val_loc = loc; | |
2082 | add_dwarf_attr (die, attr); | |
2083 | } | |
2084 | } | |
2085 | ||
2086 | /* Add an address constant attribute value to a DIE. */ | |
2087 | inline void | |
2088 | add_AT_addr (die, attr_kind, addr) | |
2089 | register dw_die_ref die; | |
2090 | register enum dwarf_attribute attr_kind; | |
2091 | char *addr; | |
2092 | { | |
2093 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2094 | if (attr != NULL) | |
2095 | { | |
2096 | attr->dw_attr_next = NULL; | |
2097 | attr->dw_attr = attr_kind; | |
2098 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
2099 | attr->dw_attr_val.v.val_addr = addr; | |
2100 | add_dwarf_attr (die, attr); | |
2101 | } | |
2102 | } | |
2103 | ||
2104 | /* Add a label identifier attribute value to a DIE. */ | |
2105 | inline void | |
2106 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
2107 | register dw_die_ref die; | |
2108 | register enum dwarf_attribute attr_kind; | |
2109 | register char *lbl_id; | |
2110 | { | |
2111 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2112 | if (attr != NULL) | |
2113 | { | |
2114 | attr->dw_attr_next = NULL; | |
2115 | attr->dw_attr = attr_kind; | |
2116 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
2117 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
2118 | add_dwarf_attr (die, attr); | |
2119 | } | |
2120 | } | |
2121 | ||
2122 | /* Add a section offset attribute value to a DIE. */ | |
2123 | inline void | |
2124 | add_AT_section_offset (die, attr_kind, section) | |
2125 | register dw_die_ref die; | |
2126 | register enum dwarf_attribute attr_kind; | |
2127 | register char *section; | |
2128 | { | |
2129 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2130 | if (attr != NULL) | |
2131 | { | |
2132 | attr->dw_attr_next = NULL; | |
2133 | attr->dw_attr = attr_kind; | |
2134 | attr->dw_attr_val.val_class = dw_val_class_section_offset; | |
2135 | attr->dw_attr_val.v.val_section = section; | |
2136 | add_dwarf_attr (die, attr); | |
2137 | } | |
2138 | } | |
2139 | ||
a3f97cbb JW |
2140 | /* Test if die refers to an external subroutine. */ |
2141 | inline int | |
2142 | is_extern_subr_die (die) | |
2143 | register dw_die_ref die; | |
2144 | { | |
2145 | register dw_attr_ref a; | |
2146 | register int is_subr = FALSE; | |
2147 | register int is_extern = FALSE; | |
2148 | if (die != NULL && die->die_tag == DW_TAG_subprogram) | |
2149 | { | |
2150 | is_subr = TRUE; | |
2151 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2152 | { | |
2153 | if (a->dw_attr == DW_AT_external | |
2154 | && a->dw_attr_val.val_class == dw_val_class_flag | |
2155 | && a->dw_attr_val.v.val_flag != 0) | |
2156 | { | |
2157 | is_extern = TRUE; | |
2158 | break; | |
2159 | } | |
2160 | } | |
2161 | } | |
2162 | return is_subr && is_extern; | |
2163 | } | |
2164 | ||
d291dd49 JM |
2165 | /* Get the attribute of type attr_kind. */ |
2166 | inline dw_attr_ref | |
2167 | get_AT (die, attr_kind) | |
a3f97cbb | 2168 | register dw_die_ref die; |
d291dd49 | 2169 | register enum dwarf_attribute attr_kind; |
a3f97cbb JW |
2170 | { |
2171 | register dw_attr_ref a; | |
d291dd49 JM |
2172 | register dw_die_ref spec; |
2173 | ||
a3f97cbb JW |
2174 | if (die != NULL) |
2175 | { | |
2176 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2177 | { | |
d291dd49 JM |
2178 | if (a->dw_attr == attr_kind) |
2179 | return a; | |
2180 | if (a->dw_attr == DW_AT_specification | |
2181 | || a->dw_attr == DW_AT_abstract_origin) | |
2182 | spec = a->dw_attr_val.v.val_die_ref; | |
a3f97cbb | 2183 | } |
d291dd49 JM |
2184 | if (spec) |
2185 | return get_AT (spec, attr_kind); | |
a3f97cbb | 2186 | } |
d291dd49 JM |
2187 | return NULL; |
2188 | } | |
2189 | ||
2190 | /* Return the "low pc" attribute value, typically associated with | |
2191 | a subprogram DIE. Return null if the "low pc" attribute is | |
2192 | either not prsent, or if it cannot be represented as an | |
2193 | assembler label identifier. */ | |
2194 | inline char * | |
2195 | get_AT_low_pc (die) | |
2196 | register dw_die_ref die; | |
2197 | { | |
2198 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); | |
2199 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) | |
2200 | return a->dw_attr_val.v.val_lbl_id; | |
2201 | return NULL; | |
2202 | } | |
2203 | ||
2204 | /* Return the "high pc" attribute value, typically associated with | |
2205 | a subprogram DIE. Return null if the "high pc" attribute is | |
2206 | either not prsent, or if it cannot be represented as an | |
2207 | assembler label identifier. */ | |
2208 | inline char * | |
2209 | get_AT_hi_pc (die) | |
2210 | register dw_die_ref die; | |
2211 | { | |
2212 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); | |
2213 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) | |
2214 | return a->dw_attr_val.v.val_lbl_id; | |
2215 | return NULL; | |
2216 | } | |
2217 | ||
2218 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
2219 | NULL if it is not present. */ | |
2220 | inline char * | |
2221 | get_AT_string (die, attr_kind) | |
2222 | register dw_die_ref die; | |
2223 | register enum dwarf_attribute attr_kind; | |
2224 | { | |
2225 | register dw_attr_ref a = get_AT (die, attr_kind); | |
2226 | if (a && a->dw_attr_val.val_class == dw_val_class_str) | |
2227 | return a->dw_attr_val.v.val_str; | |
2228 | return NULL; | |
a3f97cbb JW |
2229 | } |
2230 | ||
bdb669cb JM |
2231 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
2232 | if it is not present. */ | |
2233 | inline int | |
2234 | get_AT_flag (die, attr_kind) | |
2235 | register dw_die_ref die; | |
2236 | register enum dwarf_attribute attr_kind; | |
2237 | { | |
d291dd49 JM |
2238 | register dw_attr_ref a = get_AT (die, attr_kind); |
2239 | if (a && a->dw_attr_val.val_class == dw_val_class_flag) | |
2240 | return a->dw_attr_val.v.val_flag; | |
bdb669cb JM |
2241 | return -1; |
2242 | } | |
2243 | ||
2244 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 | |
2245 | if it is not present. */ | |
2246 | inline unsigned | |
2247 | get_AT_unsigned (die, attr_kind) | |
2248 | register dw_die_ref die; | |
2249 | register enum dwarf_attribute attr_kind; | |
2250 | { | |
d291dd49 JM |
2251 | register dw_attr_ref a = get_AT (die, attr_kind); |
2252 | if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const) | |
2253 | return a->dw_attr_val.v.val_unsigned; | |
bdb669cb JM |
2254 | return 0; |
2255 | } | |
a3f97cbb | 2256 | |
4b674448 JM |
2257 | /* Remove the specified attribute if present. */ |
2258 | inline void | |
2259 | remove_AT (die, attr_kind) | |
2260 | register dw_die_ref die; | |
2261 | register enum dwarf_attribute attr_kind; | |
2262 | { | |
2263 | register dw_attr_ref a; | |
2264 | register dw_attr_ref removed = NULL;; | |
2265 | if (die != NULL) | |
2266 | { | |
2267 | if (die->die_attr->dw_attr == attr_kind) | |
2268 | { | |
2269 | removed = die->die_attr; | |
2270 | if (die->die_attr_last == die->die_attr) | |
2271 | die->die_attr_last = NULL; | |
2272 | die->die_attr = die->die_attr->dw_attr_next; | |
2273 | } | |
2274 | else for (a = die->die_attr; a->dw_attr_next != NULL; | |
2275 | a = a->dw_attr_next) | |
2276 | if (a->dw_attr_next->dw_attr == attr_kind) | |
2277 | { | |
2278 | removed = a->dw_attr_next; | |
2279 | if (die->die_attr_last == a->dw_attr_next) | |
2280 | die->die_attr_last = a; | |
2281 | a->dw_attr_next = a->dw_attr_next->dw_attr_next; | |
e90b62db | 2282 | break; |
4b674448 JM |
2283 | } |
2284 | if (removed) | |
2285 | free (removed); | |
2286 | } | |
2287 | } | |
2288 | ||
2289 | /* Discard the children of this DIE. */ | |
2290 | inline void | |
2291 | remove_children (die) | |
2292 | register dw_die_ref die; | |
2293 | { | |
2294 | register dw_die_ref child_die = die->die_child; | |
2295 | die->die_child = NULL; | |
2296 | die->die_child_last = NULL; | |
2297 | while (child_die != NULL) | |
2298 | { | |
2299 | register dw_die_ref tmp_die = child_die; | |
2300 | register dw_attr_ref a; | |
2301 | child_die = child_die->die_sib; | |
2302 | ||
2303 | for (a = tmp_die->die_attr; a != NULL; ) | |
2304 | { | |
2305 | register dw_attr_ref tmp_a = a; | |
2306 | a = a->dw_attr_next; | |
2307 | free (tmp_a); | |
2308 | } | |
2309 | free (tmp_die); | |
2310 | } | |
2311 | } | |
2312 | ||
a3f97cbb JW |
2313 | /* Add a child DIE below its parent. */ |
2314 | inline void | |
2315 | add_child_die (die, child_die) | |
2316 | register dw_die_ref die; | |
2317 | register dw_die_ref child_die; | |
2318 | { | |
2319 | if (die != NULL && child_die != NULL) | |
2320 | { | |
2321 | assert (die != child_die); | |
2322 | child_die->die_parent = die; | |
2323 | child_die->die_sib = NULL; | |
2324 | if (die->die_child == NULL) | |
2325 | { | |
2326 | die->die_child = child_die; | |
2327 | die->die_child_last = child_die; | |
2328 | } | |
2329 | else | |
2330 | { | |
2331 | die->die_child_last->die_sib = child_die; | |
2332 | die->die_child_last = child_die; | |
2333 | } | |
2334 | } | |
2335 | } | |
2336 | ||
2337 | /* Return a pointer to a newly created DIE node. */ | |
2338 | inline dw_die_ref | |
2339 | new_die (tag_value, parent_die) | |
2340 | register enum dwarf_tag tag_value; | |
2341 | register dw_die_ref parent_die; | |
2342 | { | |
2343 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
2344 | if (die != NULL) | |
2345 | { | |
2346 | die->die_tag = tag_value; | |
2347 | die->die_abbrev = 0; | |
2348 | die->die_offset = 0; | |
2349 | die->die_child = NULL; | |
2350 | die->die_parent = NULL; | |
2351 | die->die_sib = NULL; | |
2352 | die->die_child_last = NULL; | |
2353 | die->die_attr = NULL; | |
2354 | die->die_attr_last = NULL; | |
2355 | if (parent_die != NULL) | |
2356 | { | |
2357 | add_child_die (parent_die, die); | |
2358 | } | |
2359 | } | |
2360 | return die; | |
2361 | } | |
2362 | ||
2363 | /* Return the DIE associated with the given type specifier. */ | |
2364 | inline dw_die_ref | |
2365 | lookup_type_die (type) | |
2366 | register tree type; | |
2367 | { | |
2368 | register unsigned type_id = TYPE_UID (type); | |
2369 | return (type_id < type_die_table_in_use) | |
2370 | ? type_die_table[type_id] : NULL; | |
2371 | } | |
2372 | ||
2373 | /* Equate a DIE to a given type specifier. */ | |
2374 | static void | |
2375 | equate_type_number_to_die (type, type_die) | |
2376 | register tree type; | |
2377 | register dw_die_ref type_die; | |
2378 | { | |
2379 | register unsigned type_id = TYPE_UID (type); | |
2380 | register unsigned i; | |
2381 | register unsigned num_allocated; | |
2382 | if (type_id >= type_die_table_allocated) | |
2383 | { | |
2384 | num_allocated = (((type_id + 1) | |
2385 | + TYPE_DIE_TABLE_INCREMENT - 1) | |
2386 | / TYPE_DIE_TABLE_INCREMENT) | |
2387 | * TYPE_DIE_TABLE_INCREMENT; | |
2388 | type_die_table = (dw_die_ref *) xrealloc (type_die_table, | |
2389 | sizeof (dw_die_ref) * num_allocated); | |
2390 | bzero (&type_die_table[type_die_table_allocated], | |
2391 | (num_allocated - type_die_table_allocated) * sizeof (dw_die_ref)); | |
2392 | type_die_table_allocated = num_allocated; | |
2393 | } | |
2394 | if (type_id >= type_die_table_in_use) | |
2395 | { | |
2396 | type_die_table_in_use = (type_id + 1); | |
2397 | } | |
2398 | type_die_table[type_id] = type_die; | |
2399 | } | |
2400 | ||
2401 | /* Return the DIE associated with a given declaration. */ | |
2402 | inline dw_die_ref | |
2403 | lookup_decl_die (decl) | |
2404 | register tree decl; | |
2405 | { | |
2406 | register unsigned decl_id = DECL_UID (decl); | |
2407 | return (decl_id < decl_die_table_in_use) | |
2408 | ? decl_die_table[decl_id] : NULL; | |
2409 | } | |
2410 | ||
2411 | /* Equate a DIE to a particular declaration. */ | |
2412 | static void | |
2413 | equate_decl_number_to_die (decl, decl_die) | |
2414 | register tree decl; | |
2415 | register dw_die_ref decl_die; | |
2416 | { | |
2417 | register unsigned decl_id = DECL_UID (decl); | |
2418 | register unsigned i; | |
2419 | register unsigned num_allocated; | |
2420 | if (decl_id >= decl_die_table_allocated) | |
2421 | { | |
2422 | num_allocated = (((decl_id + 1) | |
2423 | + DECL_DIE_TABLE_INCREMENT - 1) | |
2424 | / DECL_DIE_TABLE_INCREMENT) | |
2425 | * DECL_DIE_TABLE_INCREMENT; | |
2426 | decl_die_table = (dw_die_ref *) xrealloc (decl_die_table, | |
2427 | sizeof (dw_die_ref) * num_allocated); | |
2428 | bzero (&decl_die_table[decl_die_table_allocated], | |
2429 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); | |
2430 | decl_die_table_allocated = num_allocated; | |
2431 | } | |
2432 | if (decl_id >= decl_die_table_in_use) | |
2433 | { | |
2434 | decl_die_table_in_use = (decl_id + 1); | |
2435 | } | |
2436 | decl_die_table[decl_id] = decl_die; | |
2437 | } | |
2438 | ||
2439 | /* Return a pointer to a newly allocated location description. Location | |
2440 | descriptions are simple expression terms that can be strung | |
2441 | together to form more complicated location (address) descriptions. */ | |
2442 | inline dw_loc_descr_ref | |
2443 | new_loc_descr (op, oprnd1, oprnd2) | |
2444 | register enum dwarf_location_atom op; | |
2445 | register unsigned long oprnd1; | |
2446 | register unsigned long oprnd2; | |
2447 | { | |
2448 | register dw_loc_descr_ref descr = | |
2449 | (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node)); | |
2450 | if (descr != NULL) | |
2451 | { | |
2452 | descr->dw_loc_next = NULL; | |
2453 | descr->dw_loc_opc = op; | |
2454 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2455 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2456 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2457 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
2458 | } | |
2459 | return descr; | |
2460 | } | |
2461 | ||
2462 | /* Add a location description term to a location description expression. */ | |
2463 | inline void | |
2464 | add_loc_descr (list_head, descr) | |
2465 | register dw_loc_descr_ref *list_head; | |
2466 | register dw_loc_descr_ref descr; | |
2467 | { | |
2468 | register dw_loc_descr_ref *d; | |
2469 | /* find the end of the chain. */ | |
2470 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2471 | { | |
2472 | /* nothing */ ; | |
2473 | } | |
2474 | *d = descr; | |
2475 | } | |
2476 | ||
2477 | /* Return a pointer to a newly allocated Call Frame Instruction. */ | |
2478 | inline dw_cfi_ref | |
2479 | new_cfi () | |
2480 | { | |
2481 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
2482 | if (cfi != NULL) | |
2483 | { | |
2484 | cfi->dw_cfi_next = NULL; | |
2485 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
2486 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
2487 | } | |
2488 | return cfi; | |
2489 | } | |
2490 | ||
2491 | /* Add a Call Frame Instruction to list of instructions. */ | |
2492 | inline void | |
2493 | add_cfi (list_head, cfi) | |
2494 | register dw_cfi_ref *list_head; | |
2495 | register dw_cfi_ref cfi; | |
2496 | { | |
2497 | register dw_cfi_ref *p; | |
2498 | /* find the end of the chain. */ | |
2499 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
2500 | { | |
2501 | /* nothing */ ; | |
2502 | } | |
2503 | *p = cfi; | |
2504 | } | |
2505 | \f | |
2506 | /********* Print DWARF Internal Representation (debugging aids) ***************/ | |
2507 | ||
2508 | /* Keep track of the number of spaces used to indent the | |
2509 | output of the debugging routines that print the structure of | |
2510 | the DIE internal representation. */ | |
2511 | static int print_indent; | |
2512 | ||
2513 | /* Indent the line the number of spaces given by print_indent. */ | |
2514 | inline void | |
2515 | print_spaces (outfile) | |
2516 | FILE *outfile; | |
2517 | { | |
2518 | fprintf (outfile, "%*s", print_indent, ""); | |
2519 | } | |
2520 | ||
2521 | /* Print the information assoaciated with a given DIE, and its children. | |
2522 | This routine is a debugging aid only. */ | |
2523 | static void | |
2524 | print_die (die, outfile) | |
2525 | dw_die_ref die; | |
2526 | FILE *outfile; | |
2527 | { | |
2528 | register dw_attr_ref a; | |
2529 | register dw_die_ref c; | |
2530 | print_spaces (outfile); | |
2531 | fprintf (outfile, "DIE %4u: %s\n", | |
2532 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
2533 | print_spaces (outfile); | |
2534 | fprintf (outfile, " abbrev id: %u", die->die_abbrev); | |
2535 | fprintf (outfile, " offset: %u\n", die->die_offset); | |
2536 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2537 | { | |
2538 | print_spaces (outfile); | |
2539 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
2540 | switch (a->dw_attr_val.val_class) | |
2541 | { | |
2542 | case dw_val_class_addr: | |
2543 | fprintf (outfile, "address"); | |
2544 | break; | |
2545 | case dw_val_class_loc: | |
2546 | fprintf (outfile, "location descriptor"); | |
2547 | break; | |
2548 | case dw_val_class_const: | |
2549 | fprintf (outfile, "%d", a->dw_attr_val.v.val_int); | |
2550 | break; | |
2551 | case dw_val_class_unsigned_const: | |
2552 | fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned); | |
2553 | break; | |
2554 | case dw_val_class_double_const: | |
2555 | fprintf (outfile, "constant (%u,%u)", | |
2556 | a->dw_attr_val.v.val_dbl_const.dw_dbl_hi, | |
2557 | a->dw_attr_val.v.val_dbl_const.dw_dbl_low); | |
2558 | break; | |
2559 | case dw_val_class_flag: | |
2560 | fprintf (outfile, "%u", a->dw_attr_val.v.val_flag); | |
2561 | break; | |
2562 | case dw_val_class_die_ref: | |
2563 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
2564 | { | |
2565 | fprintf (outfile, "die -> %u", | |
2566 | a->dw_attr_val.v.val_die_ref->die_offset); | |
2567 | } | |
2568 | else | |
2569 | { | |
2570 | fprintf (outfile, "die -> <null>"); | |
2571 | } | |
2572 | break; | |
2573 | case dw_val_class_lbl_id: | |
2574 | fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id); | |
2575 | break; | |
2576 | case dw_val_class_section_offset: | |
2577 | fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section); | |
2578 | break; | |
2579 | case dw_val_class_str: | |
2580 | if (a->dw_attr_val.v.val_str != NULL) | |
2581 | { | |
2582 | fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str); | |
2583 | } | |
2584 | else | |
2585 | { | |
2586 | fprintf (outfile, "<null>"); | |
2587 | } | |
2588 | break; | |
2589 | } | |
2590 | fprintf (outfile, "\n"); | |
2591 | } | |
2592 | if (die->die_child != NULL) | |
2593 | { | |
2594 | print_indent += 4; | |
2595 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
2596 | { | |
2597 | print_die (c, outfile); | |
2598 | } | |
2599 | print_indent -= 4; | |
2600 | } | |
2601 | } | |
2602 | ||
2603 | /* Print the contents of the source code line number correspondence table. | |
2604 | This routine is a debugging aid only. */ | |
2605 | static void | |
2606 | print_dwarf_line_table (outfile) | |
2607 | FILE *outfile; | |
2608 | { | |
2609 | register unsigned i; | |
2610 | register dw_line_info_ref line_info; | |
2611 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2612 | for (i = 1; i < line_info_table_in_use; ++i) | |
2613 | { | |
2614 | line_info = &line_info_table[i]; | |
2615 | fprintf (outfile, "%5d: ", i); | |
2616 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
2617 | fprintf (outfile, "%6d", line_info->dw_line_num); | |
2618 | fprintf (outfile, "\n"); | |
2619 | } | |
2620 | fprintf (outfile, "\n\n"); | |
2621 | } | |
2622 | ||
2623 | /* Print the information collected for a given DIE. */ | |
2624 | void | |
2625 | debug_dwarf_die (die) | |
2626 | dw_die_ref die; | |
2627 | { | |
2628 | print_die (die, stderr); | |
2629 | } | |
2630 | ||
2631 | /* Print all DWARF informaiton collected for the compilation unit. | |
2632 | This routine is a debugging aid only. */ | |
2633 | void | |
2634 | debug_dwarf () | |
2635 | { | |
2636 | print_indent = 0; | |
2637 | print_die (comp_unit_die, stderr); | |
2638 | print_dwarf_line_table (stderr); | |
2639 | } | |
2640 | ||
2641 | \f | |
2642 | /***************** DWARF Information Construction Support *********************/ | |
2643 | ||
2644 | /* Traverse the DIE, and add a sibling attribute if it may have the | |
2645 | effect of speeding up access to siblings. To save some space, | |
2646 | avoid generating sibling attributes for DIE's without children. */ | |
2647 | static void | |
2648 | add_sibling_attributes(die) | |
2649 | register dw_die_ref die; | |
2650 | { | |
2651 | register dw_die_ref c; | |
2652 | register dw_attr_ref attr; | |
2653 | if (die != comp_unit_die && die->die_child != NULL) | |
2654 | { | |
2655 | attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
2656 | if (attr != NULL) | |
2657 | { | |
2658 | attr->dw_attr_next = NULL; | |
2659 | attr->dw_attr = DW_AT_sibling; | |
2660 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
2661 | attr->dw_attr_val.v.val_die_ref = die->die_sib; | |
2662 | } | |
2663 | /* add the sibling link to the front of the attribute list. */ | |
2664 | attr->dw_attr_next = die->die_attr; | |
2665 | if (die->die_attr == NULL) | |
2666 | { | |
2667 | die->die_attr_last = attr; | |
2668 | } | |
2669 | die->die_attr = attr; | |
2670 | } | |
2671 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
2672 | { | |
2673 | add_sibling_attributes (c); | |
2674 | } | |
2675 | } | |
2676 | ||
2677 | /* The format of each DIE (and its attribute value pairs) | |
2678 | is encoded in an abbreviation table. This routine builds the | |
2679 | abbreviation table and assigns a unique abbreviation id for | |
2680 | each abbreviation entry. The children of each die are visited | |
2681 | recursively. */ | |
2682 | static void | |
2683 | build_abbrev_table (die) | |
2684 | register dw_die_ref die; | |
2685 | { | |
2686 | register unsigned long abbrev_id; | |
2687 | register unsigned long n_alloc; | |
2688 | register dw_die_ref c; | |
2689 | register dw_attr_ref d_attr, a_attr; | |
2690 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
2691 | { | |
2692 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
2693 | if (abbrev->die_tag == die->die_tag) | |
2694 | { | |
2695 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
2696 | { | |
2697 | a_attr = abbrev->die_attr; | |
2698 | d_attr = die->die_attr; | |
2699 | while (a_attr != NULL && d_attr != NULL) | |
2700 | { | |
2701 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
2702 | || (a_attr->dw_attr_val.val_class | |
2703 | != d_attr->dw_attr_val.val_class)) | |
2704 | { | |
2705 | break; | |
2706 | } | |
2707 | a_attr = a_attr->dw_attr_next; | |
2708 | d_attr = d_attr->dw_attr_next; | |
2709 | } | |
2710 | if (a_attr == NULL && d_attr == NULL) | |
2711 | { | |
2712 | break; | |
2713 | } | |
2714 | } | |
2715 | } | |
2716 | } | |
2717 | if (abbrev_id >= abbrev_die_table_in_use) | |
2718 | { | |
2719 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
2720 | { | |
2721 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
2722 | abbrev_die_table = (dw_die_ref *) | |
2723 | xmalloc (abbrev_die_table, | |
2724 | sizeof (dw_die_ref) * n_alloc); | |
2725 | bzero (&abbrev_die_table[abbrev_die_table_allocated], | |
2726 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); | |
2727 | abbrev_die_table_allocated = n_alloc; | |
2728 | } | |
2729 | ++abbrev_die_table_in_use; | |
2730 | abbrev_die_table[abbrev_id] = die; | |
2731 | } | |
2732 | die->die_abbrev = abbrev_id; | |
2733 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
2734 | { | |
2735 | build_abbrev_table (c); | |
2736 | } | |
2737 | } | |
2738 | ||
2739 | \f | |
2740 | /********************** DWARF Information Sizing *****************************/ | |
2741 | ||
2742 | /* Return the size of an unsigned LEB128 quantity. */ | |
2743 | inline unsigned long | |
2744 | size_of_uleb128 (value) | |
2745 | register unsigned long value; | |
2746 | { | |
2747 | register unsigned long size = 0; | |
2748 | register unsigned byte; | |
2749 | do | |
2750 | { | |
2751 | byte = (value & 0x7f); | |
2752 | value >>= 7; | |
2753 | size += 1; | |
2754 | } | |
2755 | while (value != 0); | |
2756 | return size; | |
2757 | } | |
2758 | ||
2759 | /* Return the size of a signed LEB128 quantity. */ | |
2760 | inline unsigned long | |
2761 | size_of_sleb128 (value) | |
2762 | register long value; | |
2763 | { | |
2764 | register unsigned long size = 0; | |
2765 | register unsigned byte; | |
2766 | do | |
2767 | { | |
2768 | byte = (value & 0x7f); | |
2769 | value >>= 7; | |
2770 | size += 1; | |
2771 | } | |
2772 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
2773 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
2774 | return size; | |
2775 | } | |
2776 | ||
2777 | /* Return the size of a string, including the null byte. */ | |
2778 | static unsigned long | |
2779 | size_of_string (str) | |
2780 | register char *str; | |
2781 | { | |
2782 | register unsigned long size = 0; | |
2783 | register unsigned long slen = strlen (str); | |
2784 | register unsigned long i; | |
2785 | register unsigned c; | |
2786 | for (i = 0; i < slen; ++i) | |
2787 | { | |
2788 | c = str[i]; | |
2789 | if (c == '\\') | |
2790 | { | |
2791 | ++i; | |
2792 | } | |
2793 | size += 1; | |
2794 | } | |
2795 | /* Null terminator. */ | |
2796 | size += 1; | |
2797 | return size; | |
2798 | } | |
2799 | ||
2800 | /* Return the size of a location descriptor. */ | |
2801 | static unsigned long | |
2802 | size_of_loc_descr (loc) | |
2803 | register dw_loc_descr_ref loc; | |
2804 | { | |
2805 | register unsigned long size = 1; | |
2806 | switch (loc->dw_loc_opc) | |
2807 | { | |
2808 | case DW_OP_addr: | |
2809 | size += PTR_SIZE; | |
2810 | break; | |
2811 | case DW_OP_const1u: | |
2812 | case DW_OP_const1s: | |
2813 | size += 1; | |
2814 | break; | |
2815 | case DW_OP_const2u: | |
2816 | case DW_OP_const2s: | |
2817 | size += 2; | |
2818 | break; | |
2819 | case DW_OP_const4u: | |
2820 | case DW_OP_const4s: | |
2821 | size += 4; | |
2822 | break; | |
2823 | case DW_OP_const8u: | |
2824 | case DW_OP_const8s: | |
2825 | size += 8; | |
2826 | break; | |
2827 | case DW_OP_constu: | |
2828 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2829 | break; | |
2830 | case DW_OP_consts: | |
2831 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2832 | break; | |
2833 | case DW_OP_pick: | |
2834 | size += 1; | |
2835 | break; | |
2836 | case DW_OP_plus_uconst: | |
2837 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2838 | break; | |
2839 | case DW_OP_skip: | |
2840 | case DW_OP_bra: | |
2841 | size += 2; | |
2842 | break; | |
2843 | case DW_OP_breg0: | |
2844 | case DW_OP_breg1: | |
2845 | case DW_OP_breg2: | |
2846 | case DW_OP_breg3: | |
2847 | case DW_OP_breg4: | |
2848 | case DW_OP_breg5: | |
2849 | case DW_OP_breg6: | |
2850 | case DW_OP_breg7: | |
2851 | case DW_OP_breg8: | |
2852 | case DW_OP_breg9: | |
2853 | case DW_OP_breg10: | |
2854 | case DW_OP_breg11: | |
2855 | case DW_OP_breg12: | |
2856 | case DW_OP_breg13: | |
2857 | case DW_OP_breg14: | |
2858 | case DW_OP_breg15: | |
2859 | case DW_OP_breg16: | |
2860 | case DW_OP_breg17: | |
2861 | case DW_OP_breg18: | |
2862 | case DW_OP_breg19: | |
2863 | case DW_OP_breg20: | |
2864 | case DW_OP_breg21: | |
2865 | case DW_OP_breg22: | |
2866 | case DW_OP_breg23: | |
2867 | case DW_OP_breg24: | |
2868 | case DW_OP_breg25: | |
2869 | case DW_OP_breg26: | |
2870 | case DW_OP_breg27: | |
2871 | case DW_OP_breg28: | |
2872 | case DW_OP_breg29: | |
2873 | case DW_OP_breg30: | |
2874 | case DW_OP_breg31: | |
2875 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2876 | break; | |
2877 | case DW_OP_regx: | |
2878 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2879 | break; | |
2880 | case DW_OP_fbreg: | |
2881 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2882 | break; | |
2883 | case DW_OP_bregx: | |
2884 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2885 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2886 | break; | |
2887 | case DW_OP_piece: | |
2888 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2889 | break; | |
2890 | case DW_OP_deref_size: | |
2891 | case DW_OP_xderef_size: | |
2892 | size += 1; | |
2893 | break; | |
2894 | default: | |
2895 | break; | |
2896 | } | |
2897 | return size; | |
2898 | } | |
2899 | ||
2900 | /* Return the size of a DIE, as it is represented in the | |
2901 | .debug_info section. */ | |
2902 | static unsigned long | |
2903 | size_of_die (die) | |
2904 | register dw_die_ref die; | |
2905 | { | |
2906 | register unsigned long size = 0; | |
2907 | register dw_attr_ref a; | |
2908 | register dw_loc_descr_ref loc; | |
2909 | size += size_of_uleb128 (die->die_abbrev); | |
2910 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2911 | { | |
2912 | switch (a->dw_attr_val.val_class) | |
2913 | { | |
2914 | case dw_val_class_addr: | |
2915 | size += 4; | |
2916 | break; | |
2917 | case dw_val_class_loc: | |
2918 | /* Block length. */ | |
2919 | size += 2; | |
2920 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
2921 | loc = loc->dw_loc_next) | |
2922 | { | |
2923 | size += size_of_loc_descr (loc); | |
2924 | } | |
2925 | break; | |
2926 | case dw_val_class_const: | |
2927 | size += 4; | |
2928 | break; | |
2929 | case dw_val_class_unsigned_const: | |
2930 | size += 4; | |
2931 | break; | |
2932 | case dw_val_class_double_const: | |
2933 | size += 8; | |
2934 | break; | |
2935 | case dw_val_class_flag: | |
2936 | size += 1; | |
2937 | break; | |
2938 | case dw_val_class_die_ref: | |
2939 | size += 4; | |
2940 | break; | |
2941 | case dw_val_class_fde_ref: | |
2942 | size += 4; | |
2943 | break; | |
2944 | case dw_val_class_lbl_id: | |
2945 | size += 4; | |
2946 | break; | |
2947 | case dw_val_class_section_offset: | |
2948 | size += 4; | |
2949 | break; | |
2950 | case dw_val_class_str: | |
2951 | size += size_of_string (a->dw_attr_val.v.val_str); | |
2952 | break; | |
2953 | default: | |
2954 | abort (); | |
2955 | } | |
2956 | } | |
2957 | return size; | |
2958 | } | |
2959 | ||
2960 | /* Size the debgging information associted with a given DIE. | |
2961 | Visits the DIE's children recursively. Updates the global | |
2962 | variable next_die_offset, on each time through. Uses the | |
2963 | current value of next_die_offset to updete the die_offset | |
2964 | field in each DIE. */ | |
2965 | static void | |
2966 | calc_die_sizes (die) | |
2967 | dw_die_ref die; | |
2968 | { | |
2969 | register dw_die_ref c; | |
2970 | register unsigned long die_size; | |
2971 | die->die_offset = next_die_offset; | |
2972 | next_die_offset += size_of_die (die); | |
2973 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
2974 | { | |
2975 | calc_die_sizes (c); | |
2976 | } | |
2977 | if (die->die_child != NULL) | |
2978 | { | |
2979 | /* Count the null byte used to terminate sibling lists. */ | |
2980 | next_die_offset += 1; | |
2981 | } | |
2982 | } | |
2983 | ||
2984 | /* Return the size of the line information prolog generated for the | |
2985 | compilation unit. */ | |
2986 | static unsigned long | |
2987 | size_of_line_prolog () | |
2988 | { | |
2989 | register unsigned long size; | |
2990 | register unsigned opc; | |
2991 | register unsigned n_op_args; | |
2992 | register unsigned long ft_index; | |
2993 | size = DWARF_LINE_PROLOG_HEADER_SIZE; | |
2994 | /* Count the size of the table giving number of args for each | |
2995 | standard opcode. */ | |
2996 | size += DWARF_LINE_OPCODE_BASE - 1; | |
2997 | /* Include directory table is empty (at present). Count only the | |
2998 | the null byte used to terminate the table. */ | |
2999 | size += 1; | |
3000 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) | |
3001 | { | |
3002 | /* File name entry. */ | |
3003 | size += size_of_string (file_table[ft_index]); | |
3004 | /* Include directory index. */ | |
3005 | size += size_of_uleb128 (0); | |
3006 | /* Modification time. */ | |
3007 | size += size_of_uleb128 (0); | |
3008 | /* File length in bytes. */ | |
3009 | size += size_of_uleb128 (0); | |
3010 | } | |
3011 | /* Count the file table terminator. */ | |
3012 | size += 1; | |
3013 | return size; | |
3014 | } | |
3015 | ||
3016 | /* Return the size of the line information generated for this | |
3017 | compilation unit. */ | |
3018 | static unsigned long | |
3019 | size_of_line_info () | |
3020 | { | |
3021 | register unsigned long size; | |
a3f97cbb JW |
3022 | register unsigned long lt_index; |
3023 | register unsigned long current_line; | |
3024 | register long line_offset; | |
3025 | register long line_delta; | |
3026 | register unsigned long current_file; | |
e90b62db | 3027 | register unsigned long function; |
a3f97cbb JW |
3028 | /* Version number. */ |
3029 | size = 2; | |
3030 | /* Prolog length specifier. */ | |
3031 | size += 4; | |
3032 | /* Prolog. */ | |
3033 | size += size_of_line_prolog (); | |
3034 | /* Set address register instruction. */ | |
3035 | size += 1 + size_of_uleb128 (1 + PTR_SIZE) | |
3036 | + 1 + PTR_SIZE; | |
3037 | current_file = 1; | |
3038 | current_line = 1; | |
3039 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) | |
3040 | { | |
e90b62db | 3041 | register dw_line_info_ref line_info; |
a3f97cbb JW |
3042 | /* Advance pc instruction. */ |
3043 | size += 1 + 2; | |
3044 | line_info = &line_info_table[lt_index]; | |
3045 | if (line_info->dw_file_num != current_file) | |
3046 | { | |
3047 | /* Set file number instruction. */ | |
3048 | size += 1; | |
3049 | current_file = line_info->dw_file_num; | |
3050 | size += size_of_uleb128 (current_file); | |
3051 | } | |
3052 | if (line_info->dw_line_num != current_line) | |
3053 | { | |
3054 | line_offset = line_info->dw_line_num - current_line; | |
3055 | line_delta = line_offset - DWARF_LINE_BASE; | |
3056 | current_line = line_info->dw_line_num; | |
3057 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
3058 | { | |
3059 | /* 1-byte special line number instruction. */ | |
3060 | size += 1; | |
3061 | } | |
3062 | else | |
3063 | { | |
3064 | /* Advance line instruction. */ | |
3065 | size += 1; | |
3066 | size += size_of_sleb128 (line_offset); | |
3067 | /* Generate line entry instruction. */ | |
3068 | size += 1; | |
3069 | } | |
3070 | } | |
3071 | } | |
bdb669cb JM |
3072 | /* Advance pc instruction. */ |
3073 | size += 1 + 2; | |
a3f97cbb JW |
3074 | /* End of line number info. marker. */ |
3075 | size += 1 + size_of_uleb128 (1) + 1; | |
e90b62db JM |
3076 | function = 0; |
3077 | current_file = 1; | |
3078 | current_line = 1; | |
3079 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
3080 | { | |
3081 | register dw_separate_line_info_ref line_info | |
3082 | = &separate_line_info_table[lt_index]; | |
3083 | if (function != line_info->function) | |
3084 | { | |
3085 | function = line_info->function; | |
3086 | /* Set address register instruction. */ | |
3087 | size += 1 + size_of_uleb128 (1 + PTR_SIZE) | |
3088 | + 1 + PTR_SIZE; | |
3089 | } | |
3090 | else | |
3091 | { | |
3092 | /* Advance pc instruction. */ | |
3093 | size += 1 + 2; | |
3094 | } | |
3095 | if (line_info->dw_file_num != current_file) | |
3096 | { | |
3097 | /* Set file number instruction. */ | |
3098 | size += 1; | |
3099 | current_file = line_info->dw_file_num; | |
3100 | size += size_of_uleb128 (current_file); | |
3101 | } | |
3102 | if (line_info->dw_line_num != current_line) | |
3103 | { | |
3104 | line_offset = line_info->dw_line_num - current_line; | |
3105 | line_delta = line_offset - DWARF_LINE_BASE; | |
3106 | current_line = line_info->dw_line_num; | |
3107 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
3108 | { | |
3109 | /* 1-byte special line number instruction. */ | |
3110 | size += 1; | |
3111 | } | |
3112 | else | |
3113 | { | |
3114 | /* Advance line instruction. */ | |
3115 | size += 1; | |
3116 | size += size_of_sleb128 (line_offset); | |
3117 | /* Generate line entry instruction. */ | |
3118 | size += 1; | |
3119 | } | |
3120 | } | |
3121 | ++lt_index; | |
3122 | ||
3123 | /* If we're done with a function, end its sequence. */ | |
3124 | if (lt_index == separate_line_info_table_in_use | |
3125 | || separate_line_info_table[lt_index].function != function) | |
3126 | { | |
3127 | current_file = 1; | |
3128 | current_line = 1; | |
3129 | /* Advance pc instruction. */ | |
3130 | size += 1 + 2; | |
3131 | /* End of line number info. marker. */ | |
3132 | size += 1 + size_of_uleb128 (1) + 1; | |
3133 | } | |
3134 | } | |
a3f97cbb JW |
3135 | return size; |
3136 | } | |
3137 | ||
3138 | /* Return the size of the .debug_pubnames table generated for the | |
3139 | compilation unit. */ | |
3140 | static unsigned long | |
3141 | size_of_pubnames () | |
3142 | { | |
a3f97cbb | 3143 | register unsigned long size; |
d291dd49 JM |
3144 | register unsigned i; |
3145 | ||
a3f97cbb | 3146 | size = DWARF_PUBNAMES_HEADER_SIZE; |
d291dd49 | 3147 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 3148 | { |
d291dd49 JM |
3149 | register pubname_ref p = &pubname_table[i]; |
3150 | size += 4 + size_of_string (p->name); | |
a3f97cbb JW |
3151 | } |
3152 | size += 4; | |
3153 | return size; | |
3154 | } | |
3155 | ||
3156 | /* Return the size of the information in the .debug_aranges seciton. */ | |
3157 | static unsigned long | |
3158 | size_of_aranges () | |
3159 | { | |
3160 | register unsigned long size; | |
3161 | size = DWARF_ARANGES_HEADER_SIZE; | |
3162 | /* Count the address/length pair for this compilation unit. */ | |
3163 | size += 8; | |
d291dd49 | 3164 | size += 8 * arange_table_in_use; |
a3f97cbb JW |
3165 | /* Count the two zero words used to terminated the address range table. */ |
3166 | size += 8; | |
3167 | return size; | |
3168 | } | |
3169 | \f | |
3170 | /**************** DWARF Debug Information Output *****************************/ | |
3171 | ||
3172 | /* Output an unsigned LEB128 quantity. */ | |
3173 | static void | |
3174 | output_uleb128 (value) | |
3175 | register unsigned long value; | |
3176 | { | |
3177 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
3178 | do | |
3179 | { | |
3180 | register unsigned byte = (value & 0x7f); | |
3181 | value >>= 7; | |
3182 | if (value != 0) | |
3183 | { | |
3184 | /* More bytes to follow. */ | |
3185 | byte |= 0x80; | |
3186 | } | |
3187 | fprintf (asm_out_file, "0x%x", byte); | |
3188 | if (value != 0) | |
3189 | { | |
3190 | fprintf (asm_out_file, ","); | |
3191 | } | |
3192 | } | |
3193 | while (value != 0); | |
3194 | } | |
3195 | ||
3196 | /* Output an signed LEB128 quantity. */ | |
3197 | static void | |
3198 | output_sleb128 (value) | |
3199 | register long value; | |
3200 | { | |
3201 | register int more; | |
3202 | register unsigned byte; | |
3203 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
3204 | do | |
3205 | { | |
3206 | byte = (value & 0x7f); | |
3207 | /* arithmetic shift */ | |
3208 | value >>= 7; | |
3209 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
3210 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
3211 | if (more) | |
3212 | { | |
3213 | byte |= 0x80; | |
3214 | } | |
3215 | fprintf (asm_out_file, "0x%x", byte); | |
3216 | if (more) | |
3217 | { | |
3218 | fprintf (asm_out_file, ","); | |
3219 | } | |
3220 | } | |
3221 | while (more); | |
3222 | } | |
3223 | ||
3224 | /* Output the encoding of an attribute value. */ | |
3225 | static void | |
3226 | output_value_format (v) | |
3227 | dw_val_ref v; | |
3228 | { | |
3229 | enum dwarf_form form; | |
3230 | switch (v->val_class) | |
3231 | { | |
3232 | case dw_val_class_addr: | |
3233 | form = DW_FORM_addr; | |
3234 | break; | |
3235 | case dw_val_class_loc: | |
3236 | form = DW_FORM_block2; | |
3237 | break; | |
3238 | case dw_val_class_const: | |
3239 | form = DW_FORM_data4; | |
3240 | break; | |
3241 | case dw_val_class_unsigned_const: | |
3242 | form = DW_FORM_data4; | |
3243 | break; | |
3244 | case dw_val_class_double_const: | |
3245 | form = DW_FORM_data8; | |
3246 | break; | |
3247 | case dw_val_class_flag: | |
3248 | form = DW_FORM_flag; | |
3249 | break; | |
3250 | case dw_val_class_die_ref: | |
3251 | form = DW_FORM_ref4; | |
3252 | break; | |
3253 | case dw_val_class_fde_ref: | |
3254 | form = DW_FORM_data4; | |
3255 | break; | |
3256 | case dw_val_class_lbl_id: | |
3257 | form = DW_FORM_addr; | |
3258 | break; | |
3259 | case dw_val_class_section_offset: | |
3260 | form = DW_FORM_data4; | |
3261 | break; | |
3262 | case dw_val_class_str: | |
3263 | form = DW_FORM_string; | |
3264 | break; | |
3265 | default: | |
3266 | abort (); | |
3267 | } | |
3268 | output_uleb128 (form); | |
3269 | if (flag_verbose_asm) | |
3270 | { | |
3271 | fprintf (asm_out_file, "\t%s %s", | |
3272 | ASM_COMMENT_START, dwarf_form_name (form)); | |
3273 | } | |
3274 | fputc ('\n', asm_out_file); | |
3275 | } | |
3276 | ||
3277 | /* Output the .debug_abbrev section which defines the DIE abbreviation | |
3278 | table. */ | |
3279 | static void | |
3280 | output_abbrev_section () | |
3281 | { | |
3282 | unsigned long abbrev_id; | |
3283 | dw_attr_ref a_attr; | |
3284 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
3285 | { | |
3286 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
3287 | output_uleb128 (abbrev_id); | |
3288 | if (flag_verbose_asm) | |
3289 | { | |
3290 | fprintf (asm_out_file, "\t%s abbrev code = %u", | |
3291 | ASM_COMMENT_START, abbrev_id); | |
3292 | } | |
3293 | fputc ('\n', asm_out_file); | |
3294 | output_uleb128 (abbrev->die_tag); | |
3295 | if (flag_verbose_asm) | |
3296 | { | |
3297 | fprintf (asm_out_file, "\t%s TAG: %s", | |
3298 | ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag)); | |
3299 | } | |
3300 | fputc ('\n', asm_out_file); | |
3301 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, | |
3302 | (abbrev->die_child != NULL) | |
3303 | ? DW_children_yes : DW_children_no); | |
3304 | if (flag_verbose_asm) | |
3305 | { | |
3306 | fprintf (asm_out_file, "\t%s %s", | |
3307 | ASM_COMMENT_START, | |
3308 | (abbrev->die_child != NULL) | |
3309 | ? "DW_children_yes" : "DW_children_no"); | |
3310 | } | |
3311 | fputc ('\n', asm_out_file); | |
3312 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
3313 | a_attr = a_attr->dw_attr_next) | |
3314 | { | |
3315 | output_uleb128 (a_attr->dw_attr); | |
3316 | if (flag_verbose_asm) | |
3317 | { | |
3318 | fprintf (asm_out_file, "\t%s %s", | |
3319 | ASM_COMMENT_START, | |
3320 | dwarf_attr_name (a_attr->dw_attr)); | |
3321 | } | |
3322 | fputc ('\n', asm_out_file); | |
3323 | output_value_format (&a_attr->dw_attr_val); | |
3324 | } | |
3325 | fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); | |
3326 | } | |
3327 | } | |
3328 | ||
3329 | /* Output location description stack opcode's operands (if any). */ | |
3330 | static void | |
3331 | output_loc_operands (loc) | |
3332 | register dw_loc_descr_ref loc; | |
3333 | { | |
3334 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; | |
3335 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
3336 | switch (loc->dw_loc_opc) | |
3337 | { | |
3338 | case DW_OP_addr: | |
3339 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); | |
3340 | fputc ('\n', asm_out_file); | |
3341 | break; | |
3342 | case DW_OP_const1u: | |
3343 | case DW_OP_const1s: | |
3344 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
3345 | fputc ('\n', asm_out_file); | |
3346 | break; | |
3347 | case DW_OP_const2u: | |
3348 | case DW_OP_const2s: | |
3349 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
3350 | fputc ('\n', asm_out_file); | |
3351 | break; | |
3352 | case DW_OP_const4u: | |
3353 | case DW_OP_const4s: | |
3354 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); | |
3355 | fputc ('\n', asm_out_file); | |
3356 | break; | |
3357 | case DW_OP_const8u: | |
3358 | case DW_OP_const8s: | |
3359 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
3360 | val1->v.val_dbl_const.dw_dbl_hi, | |
3361 | val2->v.val_dbl_const.dw_dbl_low); | |
3362 | fputc ('\n', asm_out_file); | |
3363 | break; | |
3364 | case DW_OP_constu: | |
3365 | output_uleb128 (val1->v.val_unsigned); | |
3366 | fputc ('\n', asm_out_file); | |
3367 | break; | |
3368 | case DW_OP_consts: | |
3369 | output_sleb128 (val1->v.val_unsigned); | |
3370 | fputc ('\n', asm_out_file); | |
3371 | break; | |
3372 | case DW_OP_pick: | |
3373 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
3374 | fputc ('\n', asm_out_file); | |
3375 | break; | |
3376 | case DW_OP_plus_uconst: | |
3377 | output_uleb128 (val1->v.val_unsigned); | |
3378 | fputc ('\n', asm_out_file); | |
3379 | break; | |
3380 | case DW_OP_skip: | |
3381 | case DW_OP_bra: | |
3382 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
3383 | fputc ('\n', asm_out_file); | |
3384 | break; | |
3385 | case DW_OP_breg0: | |
3386 | case DW_OP_breg1: | |
3387 | case DW_OP_breg2: | |
3388 | case DW_OP_breg3: | |
3389 | case DW_OP_breg4: | |
3390 | case DW_OP_breg5: | |
3391 | case DW_OP_breg6: | |
3392 | case DW_OP_breg7: | |
3393 | case DW_OP_breg8: | |
3394 | case DW_OP_breg9: | |
3395 | case DW_OP_breg10: | |
3396 | case DW_OP_breg11: | |
3397 | case DW_OP_breg12: | |
3398 | case DW_OP_breg13: | |
3399 | case DW_OP_breg14: | |
3400 | case DW_OP_breg15: | |
3401 | case DW_OP_breg16: | |
3402 | case DW_OP_breg17: | |
3403 | case DW_OP_breg18: | |
3404 | case DW_OP_breg19: | |
3405 | case DW_OP_breg20: | |
3406 | case DW_OP_breg21: | |
3407 | case DW_OP_breg22: | |
3408 | case DW_OP_breg23: | |
3409 | case DW_OP_breg24: | |
3410 | case DW_OP_breg25: | |
3411 | case DW_OP_breg26: | |
3412 | case DW_OP_breg27: | |
3413 | case DW_OP_breg28: | |
3414 | case DW_OP_breg29: | |
3415 | case DW_OP_breg30: | |
3416 | case DW_OP_breg31: | |
3417 | output_sleb128 (val1->v.val_int); | |
3418 | fputc ('\n', asm_out_file); | |
3419 | break; | |
3420 | case DW_OP_regx: | |
3421 | output_uleb128 (val1->v.val_unsigned); | |
3422 | fputc ('\n', asm_out_file); | |
3423 | break; | |
3424 | case DW_OP_fbreg: | |
3425 | output_sleb128 (val1->v.val_unsigned); | |
3426 | fputc ('\n', asm_out_file); | |
3427 | break; | |
3428 | case DW_OP_bregx: | |
3429 | output_uleb128 (val1->v.val_unsigned); | |
3430 | fputc ('\n', asm_out_file); | |
3431 | output_sleb128 (val2->v.val_unsigned); | |
3432 | fputc ('\n', asm_out_file); | |
3433 | break; | |
3434 | case DW_OP_piece: | |
3435 | output_uleb128 (val1->v.val_unsigned); | |
3436 | fputc ('\n', asm_out_file); | |
3437 | break; | |
3438 | case DW_OP_deref_size: | |
3439 | case DW_OP_xderef_size: | |
3440 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
3441 | fputc ('\n', asm_out_file); | |
3442 | break; | |
3443 | default: | |
3444 | break; | |
3445 | } | |
3446 | } | |
3447 | ||
3448 | /* Compute the offset of a sibling. */ | |
3449 | static unsigned long | |
3450 | sibling_offset (die) | |
3451 | dw_die_ref die; | |
3452 | { | |
3453 | unsigned long offset; | |
3454 | if (die->die_child_last == NULL) | |
3455 | { | |
3456 | offset = die->die_offset + size_of_die (die); | |
3457 | } | |
3458 | else | |
3459 | { | |
3460 | offset = sibling_offset (die->die_child_last) + 1; | |
3461 | } | |
3462 | return offset; | |
3463 | } | |
3464 | ||
3465 | /* Output the DIE and its attributes. Called recursively to generate | |
3466 | the definitions of each child DIE. */ | |
3467 | static void | |
3468 | output_die (die) | |
3469 | register dw_die_ref die; | |
3470 | { | |
3471 | register dw_attr_ref a; | |
3472 | register dw_die_ref c; | |
3473 | register unsigned long ref_offset; | |
3474 | register unsigned long size; | |
3475 | register dw_loc_descr_ref loc; | |
3476 | output_uleb128 (die->die_abbrev); | |
3477 | if (flag_verbose_asm) | |
3478 | { | |
3479 | fprintf (asm_out_file, "\t%s DIE (0x%x) %s", | |
3480 | ASM_COMMENT_START, | |
3481 | die->die_offset, | |
3482 | dwarf_tag_name (die->die_tag)); | |
3483 | } | |
3484 | fputc ('\n', asm_out_file); | |
3485 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3486 | { | |
3487 | switch (a->dw_attr_val.val_class) | |
3488 | { | |
3489 | case dw_val_class_addr: | |
3490 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, | |
3491 | a->dw_attr_val.v.val_addr); | |
3492 | break; | |
3493 | case dw_val_class_loc: | |
3494 | size = 0; | |
3495 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
3496 | loc = loc->dw_loc_next) | |
3497 | { | |
3498 | size += size_of_loc_descr (loc); | |
3499 | } | |
3500 | /* Output the block length for this list of location operations. */ | |
3501 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
3502 | if (flag_verbose_asm) | |
3503 | { | |
3504 | fprintf (asm_out_file, "\t%s %s", | |
3505 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
3506 | } | |
3507 | fputc ('\n', asm_out_file); | |
3508 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
3509 | loc = loc->dw_loc_next) | |
3510 | { | |
3511 | /* Output the opcode. */ | |
3512 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
3513 | if (flag_verbose_asm) | |
3514 | { | |
3515 | fprintf (asm_out_file, "\t%s %s", | |
3516 | ASM_COMMENT_START, | |
3517 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
3518 | } | |
3519 | fputc ('\n', asm_out_file); | |
3520 | /* Output the operand(s) (if any). */ | |
3521 | output_loc_operands (loc); | |
3522 | } | |
3523 | break; | |
3524 | case dw_val_class_const: | |
3525 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int); | |
3526 | break; | |
3527 | case dw_val_class_unsigned_const: | |
3528 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_unsigned); | |
3529 | break; | |
3530 | case dw_val_class_double_const: | |
3531 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
3532 | a->dw_attr_val.v.val_dbl_const.dw_dbl_hi, | |
3533 | a->dw_attr_val.v.val_dbl_const.dw_dbl_low); | |
3534 | break; | |
3535 | case dw_val_class_flag: | |
3536 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag); | |
3537 | break; | |
3538 | case dw_val_class_die_ref: | |
3539 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
3540 | { | |
3541 | ref_offset = a->dw_attr_val.v.val_die_ref->die_offset; | |
3542 | } | |
3543 | else if (a->dw_attr == DW_AT_sibling) | |
3544 | { | |
3545 | ref_offset = sibling_offset(die); | |
3546 | } | |
3547 | else | |
3548 | { | |
3549 | abort (); | |
3550 | } | |
3551 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, ref_offset); | |
3552 | break; | |
3553 | case dw_val_class_fde_ref: | |
3554 | ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset; | |
3555 | fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_INT_ASM_OP, | |
3556 | stripattributes (FRAME_SECTION), ref_offset); | |
3557 | break; | |
3558 | case dw_val_class_lbl_id: | |
3559 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id); | |
3560 | break; | |
3561 | case dw_val_class_section_offset: | |
3562 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, | |
3563 | stripattributes (a->dw_attr_val.v.val_section)); | |
3564 | break; | |
3565 | case dw_val_class_str: | |
3566 | ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str); | |
3567 | break; | |
3568 | default: | |
3569 | abort (); | |
3570 | } | |
3571 | if (a->dw_attr_val.val_class != dw_val_class_loc) | |
3572 | { | |
3573 | if (flag_verbose_asm) | |
3574 | { | |
3575 | fprintf (asm_out_file, "\t%s %s", | |
3576 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
3577 | } | |
3578 | fputc ('\n', asm_out_file); | |
3579 | } | |
3580 | } | |
3581 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
3582 | { | |
3583 | output_die (c); | |
3584 | } | |
3585 | if (die->die_child != NULL) | |
3586 | { | |
3587 | /* Add null byte to terminate sibling list. */ | |
3588 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
3589 | fputc ('\n', asm_out_file); | |
3590 | } | |
3591 | } | |
3592 | ||
3593 | /* Output the compilation unit that appears at the beginning of the | |
3594 | .debug_info section, and precedes the DIE descriptions. */ | |
3595 | static void | |
3596 | output_compilation_unit_header () | |
3597 | { | |
3598 | /* ??? The dwarf standard says this must be a 4 byte integer, but the | |
3599 | SGI dwarf reader assumes this is the same size as a pointer. */ | |
3600 | fprintf (asm_out_file, "\t%s\t0x%x", | |
3601 | UNALIGNED_INT_ASM_OP, next_die_offset - 4); | |
3602 | if (flag_verbose_asm) | |
3603 | { | |
3604 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", | |
3605 | ASM_COMMENT_START); | |
3606 | } | |
3607 | fputc ('\n', asm_out_file); | |
3608 | fprintf (asm_out_file, "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, DWARF_VERSION); | |
3609 | if (flag_verbose_asm) | |
3610 | { | |
3611 | fprintf (asm_out_file, "\t%s DWARF version number", | |
3612 | ASM_COMMENT_START); | |
3613 | } | |
3614 | fputc ('\n', asm_out_file); | |
3615 | fprintf (asm_out_file, "\t%s\t%s", UNALIGNED_INT_ASM_OP, | |
3616 | stripattributes (ABBREV_SECTION)); | |
3617 | if (flag_verbose_asm) | |
3618 | { | |
3619 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", | |
3620 | ASM_COMMENT_START); | |
3621 | } | |
3622 | fputc ('\n', asm_out_file); | |
3623 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, PTR_SIZE); | |
3624 | if (flag_verbose_asm) | |
3625 | { | |
3626 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", | |
3627 | ASM_COMMENT_START); | |
3628 | } | |
3629 | fputc ('\n', asm_out_file); | |
3630 | } | |
3631 | ||
3632 | /* Return the size of a Call Frame Instruction. */ | |
3633 | static unsigned long | |
3634 | size_of_cfi (cfi) | |
3635 | dw_cfi_ref cfi; | |
3636 | { | |
3637 | register unsigned long size; | |
3638 | /* count the 1-byte opcode */ | |
3639 | size = 1; | |
3640 | switch (cfi->dw_cfi_opc) | |
3641 | { | |
3642 | case DW_CFA_offset: | |
3643 | size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
3644 | break; | |
3645 | case DW_CFA_set_loc: | |
3646 | size += PTR_SIZE; | |
3647 | break; | |
3648 | case DW_CFA_advance_loc1: | |
3649 | size += 1; | |
3650 | break; | |
3651 | case DW_CFA_advance_loc2: | |
3652 | size += 2; | |
3653 | break; | |
3654 | case DW_CFA_advance_loc4: | |
3655 | size += 4; | |
3656 | break; | |
3657 | #ifdef MIPS_DEBUGGING_INFO | |
3658 | case DW_CFA_MIPS_advance_loc8: | |
3659 | size += 8; | |
3660 | break; | |
3661 | #endif | |
3662 | case DW_CFA_offset_extended: | |
3663 | case DW_CFA_def_cfa: | |
3664 | size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3665 | size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
3666 | break; | |
3667 | case DW_CFA_restore_extended: | |
3668 | case DW_CFA_undefined: | |
3669 | size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3670 | break; | |
3671 | case DW_CFA_same_value: | |
3672 | case DW_CFA_def_cfa_register: | |
3673 | size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3674 | break; | |
3675 | case DW_CFA_register: | |
3676 | size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3677 | size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
3678 | break; | |
3679 | case DW_CFA_def_cfa_offset: | |
3680 | size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3681 | break; | |
3682 | default: | |
3683 | break; | |
3684 | } | |
3685 | return size; | |
3686 | } | |
3687 | ||
3688 | /* Return the size of an FDE sans the length word. */ | |
3689 | inline unsigned long | |
3690 | size_of_fde (fde, npad) | |
3691 | dw_fde_ref fde; | |
3692 | unsigned long *npad; | |
3693 | { | |
3694 | register dw_cfi_ref cfi; | |
3695 | register unsigned long aligned_size; | |
3696 | register unsigned long size; | |
3697 | size = DWARF_FDE_HEADER_SIZE; | |
3698 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
3699 | { | |
3700 | size += size_of_cfi(cfi); | |
3701 | } | |
3702 | /* Round the size up to an 8 byte boundary. */ | |
3703 | aligned_size = (size + 7) & ~7; | |
3704 | *npad = aligned_size - size; | |
3705 | return aligned_size; | |
3706 | } | |
3707 | ||
3708 | /* Calculate the size of the FDE table, and establish the offset | |
3709 | of each FDE in the .debug_frame section. */ | |
3710 | static void | |
3711 | calc_fde_sizes () | |
3712 | { | |
3713 | register unsigned long i; | |
3714 | register dw_fde_ref fde; | |
3715 | register unsigned long fde_size; | |
3716 | unsigned long fde_pad; | |
3717 | for (i = 0; i < fde_table_in_use; ++i) | |
3718 | { | |
3719 | fde = &fde_table[i]; | |
3720 | fde->dw_fde_offset = next_fde_offset; | |
3721 | fde_size = size_of_fde (fde, &fde_pad); | |
3722 | next_fde_offset += fde_size; | |
3723 | } | |
3724 | } | |
3725 | ||
3726 | /* Output a Call Frame Information opcode and its operand(s). */ | |
3727 | static void | |
3728 | output_cfi (cfi, fde) | |
3729 | register dw_cfi_ref cfi; | |
3730 | register dw_fde_ref fde; | |
3731 | { | |
3732 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
3733 | { | |
3734 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
3735 | cfi->dw_cfi_opc | |
3736 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
3737 | if (flag_verbose_asm) | |
3738 | { | |
3739 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START); | |
3740 | } | |
3741 | fputc ('\n', asm_out_file); | |
3742 | } | |
3743 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
3744 | { | |
3745 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
3746 | cfi->dw_cfi_opc | |
3747 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
3748 | if (flag_verbose_asm) | |
3749 | { | |
3750 | fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START); | |
3751 | } | |
3752 | fputc ('\n', asm_out_file); | |
3753 | output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
3754 | fputc ('\n', asm_out_file); | |
3755 | } | |
3756 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
3757 | { | |
3758 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
3759 | cfi->dw_cfi_opc | |
3760 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
3761 | if (flag_verbose_asm) | |
3762 | { | |
3763 | fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START); | |
3764 | } | |
3765 | fputc ('\n', asm_out_file); | |
3766 | } | |
3767 | else | |
3768 | { | |
3769 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
3770 | if (flag_verbose_asm) | |
3771 | { | |
3772 | fprintf (asm_out_file, "\t%s %s", | |
3773 | ASM_COMMENT_START, | |
3774 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3775 | } | |
3776 | fputc ('\n', asm_out_file); | |
3777 | switch (cfi->dw_cfi_opc) | |
3778 | { | |
3779 | case DW_CFA_set_loc: | |
3780 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, | |
3781 | cfi->dw_cfi_oprnd1.dw_cfi_addr); | |
3782 | fputc ('\n', asm_out_file); | |
3783 | break; | |
3784 | case DW_CFA_advance_loc1: | |
3785 | /* TODO: not currently implemented. */ | |
3786 | abort (); | |
3787 | break; | |
3788 | case DW_CFA_advance_loc2: | |
3789 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, | |
3790 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
3791 | fde->dw_fde_begin); | |
3792 | fputc ('\n', asm_out_file); | |
3793 | break; | |
3794 | case DW_CFA_advance_loc4: | |
3795 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
3796 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
3797 | fde->dw_fde_begin); | |
3798 | fputc ('\n', asm_out_file); | |
3799 | break; | |
3800 | #ifdef MIPS_DEBUGGING_INFO | |
3801 | case DW_CFA_MIPS_advance_loc8: | |
3802 | /* TODO: not currently implemented. */ | |
3803 | abort (); | |
3804 | break; | |
3805 | #endif | |
3806 | case DW_CFA_offset_extended: | |
3807 | case DW_CFA_def_cfa: | |
3808 | output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3809 | fputc ('\n', asm_out_file); | |
3810 | output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
3811 | fputc ('\n', asm_out_file); | |
3812 | break; | |
3813 | case DW_CFA_restore_extended: | |
3814 | case DW_CFA_undefined: | |
3815 | output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3816 | fputc ('\n', asm_out_file); | |
3817 | break; | |
3818 | case DW_CFA_same_value: | |
3819 | case DW_CFA_def_cfa_register: | |
3820 | output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3821 | fputc ('\n', asm_out_file); | |
3822 | break; | |
3823 | case DW_CFA_register: | |
3824 | output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3825 | fputc ('\n', asm_out_file); | |
3826 | output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
3827 | fputc ('\n', asm_out_file); | |
3828 | break; | |
3829 | case DW_CFA_def_cfa_offset: | |
3830 | output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3831 | fputc ('\n', asm_out_file); | |
3832 | break; | |
3833 | default: | |
3834 | break; | |
3835 | } | |
3836 | } | |
3837 | } | |
3838 | ||
3839 | /* Output the call frame information used to used to record information | |
3840 | that relates to calculating the frame pointer, and records the | |
3841 | location of saved registers. */ | |
3842 | static void | |
3843 | output_call_frame_info () | |
3844 | { | |
3845 | register unsigned long i, j; | |
3846 | register dw_fde_ref fde; | |
3847 | register unsigned long fde_size; | |
3848 | dw_cfi_node cfi_node; | |
3849 | register dw_cfi_ref cfi; | |
3850 | unsigned long fde_pad; | |
3851 | ||
3852 | /* Output the CIE. */ | |
3853 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DWARF_CIE_SIZE - 4); | |
3854 | if (flag_verbose_asm) | |
3855 | { | |
3856 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", | |
3857 | ASM_COMMENT_START); | |
3858 | } | |
3859 | fputc ('\n', asm_out_file); | |
3860 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
3861 | if (flag_verbose_asm) | |
3862 | { | |
3863 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", | |
3864 | ASM_COMMENT_START); | |
3865 | } | |
3866 | fputc ('\n', asm_out_file); | |
3867 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
3868 | if (flag_verbose_asm) | |
3869 | { | |
3870 | fprintf (asm_out_file, "\t%s CIE Version", | |
3871 | ASM_COMMENT_START); | |
3872 | } | |
3873 | fputc ('\n', asm_out_file); | |
3874 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
3875 | if (flag_verbose_asm) | |
3876 | { | |
3877 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", | |
3878 | ASM_COMMENT_START); | |
3879 | } | |
3880 | fputc ('\n', asm_out_file); | |
3881 | output_uleb128 (1); | |
3882 | if (flag_verbose_asm) | |
3883 | { | |
3884 | fprintf (asm_out_file, "\t%s CIE Code Alignment Factor", | |
3885 | ASM_COMMENT_START); | |
3886 | } | |
3887 | fputc ('\n', asm_out_file); | |
3888 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
3889 | if (flag_verbose_asm) | |
3890 | { | |
3891 | fprintf (asm_out_file, "\t%s CIE Data Alignment Factor", | |
3892 | ASM_COMMENT_START); | |
3893 | } | |
3894 | fputc ('\n', asm_out_file); | |
3895 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_FRAME_RA_COL); | |
3896 | if (flag_verbose_asm) | |
3897 | { | |
3898 | fprintf (asm_out_file, "\t%s CIE RA Column", | |
3899 | ASM_COMMENT_START); | |
3900 | } | |
3901 | fputc ('\n', asm_out_file); | |
3902 | ||
3903 | /* Output the CFA instructions common to all FDE's. */ | |
3904 | ||
3905 | #ifdef MIPS_DEBUGGING_INFO | |
3906 | ||
3907 | /* Set the RA on entry to be the contents of r31. */ | |
3908 | bzero (&cfi_node, sizeof (dw_cfi_node)); | |
3909 | cfi = &cfi_node; | |
3910 | cfi->dw_cfi_opc = DW_CFA_register; | |
3911 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL; | |
3912 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = DW_FRAME_REG31; | |
3913 | output_cfi (cfi); | |
3914 | ||
3915 | #endif | |
3916 | ||
3917 | /* Pad the CIE out to an address sized boundary. */ | |
3918 | for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i) | |
3919 | { | |
3920 | /* Pad out to a pointer size boundary */ | |
3921 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop); | |
3922 | if (flag_verbose_asm) | |
3923 | { | |
3924 | fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)", | |
3925 | ASM_COMMENT_START); | |
3926 | } | |
3927 | fputc ('\n', asm_out_file); | |
3928 | } | |
3929 | ||
3930 | /* Loop through all of the FDE's. */ | |
3931 | for (i = 0; i < fde_table_in_use; ++i) | |
3932 | { | |
3933 | fde = &fde_table[i]; | |
3934 | fde_size = size_of_fde (fde, &fde_pad); | |
3935 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, fde_size - 4); | |
3936 | if (flag_verbose_asm) | |
3937 | { | |
3938 | fprintf (asm_out_file, "\t%s FDE Length", | |
3939 | ASM_COMMENT_START); | |
3940 | } | |
3941 | fputc ('\n', asm_out_file); | |
ba7b35df | 3942 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (FRAME_SECTION)); |
a3f97cbb JW |
3943 | if (flag_verbose_asm) |
3944 | { | |
3945 | fprintf (asm_out_file, "\t%s FDE CIE offset", | |
3946 | ASM_COMMENT_START); | |
3947 | } | |
3948 | fputc ('\n', asm_out_file); | |
3949 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
3950 | if (flag_verbose_asm) | |
3951 | { | |
3952 | fprintf (asm_out_file, "\t%s FDE initial location", | |
3953 | ASM_COMMENT_START); | |
3954 | } | |
3955 | fputc ('\n', asm_out_file); | |
3956 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
3957 | fde->dw_fde_end, fde->dw_fde_begin); | |
3958 | if (flag_verbose_asm) | |
3959 | { | |
3960 | fprintf (asm_out_file, "\t%s FDE address range", | |
3961 | ASM_COMMENT_START); | |
3962 | } | |
3963 | fputc ('\n', asm_out_file); | |
3964 | ||
3965 | /* Loop through the Call Frame Instructions associated with | |
3966 | this FDE. */ | |
3967 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
3968 | { | |
3969 | output_cfi (cfi, fde); | |
3970 | } | |
3971 | ||
3972 | /* Pad to a double word boundary. */ | |
3973 | for (j = 0; j < fde_pad; ++j) | |
3974 | { | |
3975 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop); | |
3976 | if (flag_verbose_asm) | |
3977 | { | |
3978 | fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)", | |
3979 | ASM_COMMENT_START); | |
3980 | } | |
3981 | fputc ('\n', asm_out_file); | |
3982 | } | |
3983 | } | |
3984 | } | |
3985 | ||
d291dd49 JM |
3986 | /* Add a new entry to .debug_pubnames if appropriate. */ |
3987 | static void | |
3988 | add_pubname (decl, die) | |
3989 | tree decl; | |
3990 | dw_die_ref die; | |
3991 | { | |
3992 | pubname_ref p; | |
3993 | ||
3994 | if (! TREE_PUBLIC (decl)) | |
3995 | return; | |
3996 | ||
3997 | if (pubname_table_in_use == pubname_table_allocated) | |
3998 | { | |
3999 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
4000 | pubname_table = (pubname_ref) xrealloc | |
4001 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
4002 | } | |
4003 | p = &pubname_table[pubname_table_in_use++]; | |
4004 | p->die = die; | |
4005 | p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
4006 | } | |
4007 | ||
a3f97cbb JW |
4008 | /* Output the public names table used to speed up access to externally |
4009 | visible names. For now, only generate entries for externally | |
4010 | visible procedures. */ | |
4011 | static void | |
4012 | output_pubnames () | |
4013 | { | |
d291dd49 JM |
4014 | register unsigned i; |
4015 | { | |
4016 | register unsigned long pubnames_length = size_of_pubnames (); | |
4017 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, pubnames_length); | |
4018 | } | |
a3f97cbb JW |
4019 | if (flag_verbose_asm) |
4020 | { | |
4021 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", | |
4022 | ASM_COMMENT_START); | |
4023 | } | |
4024 | fputc ('\n', asm_out_file); | |
4025 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
4026 | if (flag_verbose_asm) | |
4027 | { | |
4028 | fprintf (asm_out_file, "\t%s DWARF Version", | |
4029 | ASM_COMMENT_START); | |
4030 | } | |
4031 | fputc ('\n', asm_out_file); | |
4032 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (DEBUG_SECTION)); | |
4033 | if (flag_verbose_asm) | |
4034 | { | |
4035 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", | |
4036 | ASM_COMMENT_START); | |
4037 | } | |
4038 | fputc ('\n', asm_out_file); | |
4039 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, next_die_offset); | |
4040 | if (flag_verbose_asm) | |
4041 | { | |
4042 | fprintf (asm_out_file, "\t%s Compilation Unit Length", | |
4043 | ASM_COMMENT_START); | |
4044 | } | |
4045 | fputc ('\n', asm_out_file); | |
d291dd49 | 4046 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 4047 | { |
d291dd49 JM |
4048 | register pubname_ref pub = &pubname_table[i]; |
4049 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, pub->die->die_offset); | |
4050 | if (flag_verbose_asm) | |
a3f97cbb | 4051 | { |
d291dd49 JM |
4052 | fprintf (asm_out_file, "\t%s DIE offset", |
4053 | ASM_COMMENT_START); | |
a3f97cbb | 4054 | } |
d291dd49 JM |
4055 | fputc ('\n', asm_out_file); |
4056 | ||
4057 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
4058 | if (flag_verbose_asm) | |
4059 | { | |
4060 | fprintf (asm_out_file, "%s external name", | |
4061 | ASM_COMMENT_START); | |
4062 | } | |
4063 | fputc ('\n', asm_out_file); | |
a3f97cbb JW |
4064 | } |
4065 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4066 | fputc ('\n', asm_out_file); | |
4067 | } | |
4068 | ||
d291dd49 JM |
4069 | /* Add a new entry to .debug_aranges if appropriate. */ |
4070 | static void | |
4071 | add_arange (decl, die) | |
4072 | tree decl; | |
4073 | dw_die_ref die; | |
4074 | { | |
4075 | if (! DECL_SECTION_NAME (decl)) | |
4076 | return; | |
4077 | ||
4078 | if (arange_table_in_use == arange_table_allocated) | |
4079 | { | |
4080 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
4081 | arange_table = (arange_ref) xrealloc | |
4082 | (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
4083 | } | |
4084 | arange_table[arange_table_in_use++] = die; | |
4085 | } | |
4086 | ||
a3f97cbb JW |
4087 | /* Output the information that goes into the .debug_aranges table. |
4088 | Namely, define the beginning and ending address range of the | |
4089 | text section generated for this compilation unit. */ | |
4090 | static void | |
4091 | output_aranges () | |
4092 | { | |
d291dd49 JM |
4093 | register unsigned i; |
4094 | { | |
4095 | register unsigned long aranges_length = size_of_aranges (); | |
4096 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, aranges_length); | |
4097 | } | |
a3f97cbb JW |
4098 | if (flag_verbose_asm) |
4099 | { | |
4100 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", | |
4101 | ASM_COMMENT_START); | |
4102 | } | |
4103 | fputc ('\n', asm_out_file); | |
4104 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
4105 | if (flag_verbose_asm) | |
4106 | { | |
4107 | fprintf (asm_out_file, "\t%s DWARF Version", | |
4108 | ASM_COMMENT_START); | |
4109 | } | |
4110 | fputc ('\n', asm_out_file); | |
4111 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (DEBUG_SECTION)); | |
4112 | if (flag_verbose_asm) | |
4113 | { | |
4114 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", | |
4115 | ASM_COMMENT_START); | |
4116 | } | |
4117 | fputc ('\n', asm_out_file); | |
4118 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); | |
4119 | if (flag_verbose_asm) | |
4120 | { | |
4121 | fprintf (asm_out_file, "\t%s Size of Address", | |
4122 | ASM_COMMENT_START); | |
4123 | } | |
4124 | fputc ('\n', asm_out_file); | |
4125 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4126 | if (flag_verbose_asm) | |
4127 | { | |
4128 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", | |
4129 | ASM_COMMENT_START); | |
4130 | } | |
4131 | fputc ('\n', asm_out_file); | |
4132 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
4133 | if (flag_verbose_asm) | |
4134 | { | |
4135 | fprintf (asm_out_file, "\t%s Pad to 8 byte boundary", | |
4136 | ASM_COMMENT_START); | |
4137 | } | |
4138 | fputc ('\n', asm_out_file); | |
bdb669cb | 4139 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
a3f97cbb JW |
4140 | if (flag_verbose_asm) |
4141 | { | |
4142 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); | |
4143 | } | |
4144 | fputc ('\n', asm_out_file); | |
bdb669cb | 4145 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_SECTION); |
a3f97cbb JW |
4146 | if (flag_verbose_asm) |
4147 | { | |
4148 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); | |
4149 | } | |
4150 | fputc ('\n', asm_out_file); | |
d291dd49 JM |
4151 | for (i = 0; i < arange_table_in_use; ++i) |
4152 | { | |
4153 | dw_die_ref a = arange_table[i]; | |
4154 | if (a->die_tag == DW_TAG_subprogram) | |
4155 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a)); | |
4156 | else | |
4157 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_string (a, DW_AT_name)); | |
4158 | if (flag_verbose_asm) | |
4159 | { | |
4160 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); | |
4161 | } | |
4162 | fputc ('\n', asm_out_file); | |
4163 | if (a->die_tag == DW_TAG_subprogram) | |
4164 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, get_AT_hi_pc (a), | |
4165 | get_AT_low_pc (a)); | |
4166 | else | |
4167 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
4168 | get_AT_unsigned (a, DW_AT_byte_size)); | |
4169 | if (flag_verbose_asm) | |
4170 | { | |
4171 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); | |
4172 | } | |
4173 | fputc ('\n', asm_out_file); | |
4174 | } | |
a3f97cbb JW |
4175 | /* Output the terminator words. */ |
4176 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4177 | fputc ('\n', asm_out_file); | |
4178 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
4179 | fputc ('\n', asm_out_file); | |
4180 | } | |
4181 | ||
4182 | /* Output the source line number correspondence information. This | |
4183 | information goes into the .debug_line section. */ | |
4184 | static void | |
4185 | output_line_info () | |
4186 | { | |
a3f97cbb JW |
4187 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
4188 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4189 | register unsigned opc; | |
4190 | register unsigned n_op_args; | |
a3f97cbb JW |
4191 | register unsigned long ft_index; |
4192 | register unsigned long lt_index; | |
4193 | register unsigned long current_line; | |
4194 | register long line_offset; | |
4195 | register long line_delta; | |
4196 | register unsigned long current_file; | |
e90b62db JM |
4197 | register unsigned long function; |
4198 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size_of_line_info ()); | |
a3f97cbb JW |
4199 | if (flag_verbose_asm) |
4200 | { | |
4201 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", | |
4202 | ASM_COMMENT_START); | |
4203 | } | |
4204 | fputc ('\n', asm_out_file); | |
4205 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
4206 | if (flag_verbose_asm) | |
4207 | { | |
4208 | fprintf (asm_out_file, "\t%s DWARF Version", | |
4209 | ASM_COMMENT_START); | |
4210 | } | |
4211 | fputc ('\n', asm_out_file); | |
e90b62db | 4212 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size_of_line_prolog ()); |
a3f97cbb JW |
4213 | if (flag_verbose_asm) |
4214 | { | |
4215 | fprintf (asm_out_file, "\t%s Prolog Length", | |
4216 | ASM_COMMENT_START); | |
4217 | } | |
4218 | fputc ('\n', asm_out_file); | |
4219 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
4220 | if (flag_verbose_asm) | |
4221 | { | |
4222 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", | |
4223 | ASM_COMMENT_START); | |
4224 | } | |
4225 | fputc ('\n', asm_out_file); | |
4226 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
4227 | if (flag_verbose_asm) | |
4228 | { | |
4229 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", | |
4230 | ASM_COMMENT_START); | |
4231 | } | |
4232 | fputc ('\n', asm_out_file); | |
4233 | fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE); | |
4234 | if (flag_verbose_asm) | |
4235 | { | |
4236 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", | |
4237 | ASM_COMMENT_START); | |
4238 | } | |
4239 | fputc ('\n', asm_out_file); | |
4240 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE); | |
4241 | if (flag_verbose_asm) | |
4242 | { | |
4243 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", | |
4244 | ASM_COMMENT_START); | |
4245 | } | |
4246 | fputc ('\n', asm_out_file); | |
4247 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); | |
4248 | if (flag_verbose_asm) | |
4249 | { | |
4250 | fprintf (asm_out_file, "\t%s Special Opcode Base", | |
4251 | ASM_COMMENT_START); | |
4252 | } | |
4253 | fputc ('\n', asm_out_file); | |
4254 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
4255 | { | |
4256 | switch (opc) | |
4257 | { | |
4258 | case DW_LNS_advance_pc: | |
4259 | case DW_LNS_advance_line: | |
4260 | case DW_LNS_set_file: | |
4261 | case DW_LNS_set_column: | |
4262 | case DW_LNS_fixed_advance_pc: | |
4263 | n_op_args = 1; | |
4264 | break; | |
4265 | default: | |
4266 | n_op_args = 0; | |
4267 | break; | |
4268 | } | |
4269 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
4270 | if (flag_verbose_asm) | |
4271 | { | |
4272 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", | |
4273 | ASM_COMMENT_START, opc, n_op_args); | |
4274 | } | |
4275 | fputc ('\n', asm_out_file); | |
4276 | } | |
4277 | if (flag_verbose_asm) | |
4278 | { | |
4279 | fprintf (asm_out_file, "%s Include Directory Table\n", | |
4280 | ASM_COMMENT_START); | |
4281 | } | |
4282 | /* Include directory table is empty, at present */ | |
4283 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4284 | fputc ('\n', asm_out_file); | |
4285 | if (flag_verbose_asm) | |
4286 | { | |
4287 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); | |
4288 | } | |
4289 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) | |
4290 | { | |
4291 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
4292 | if (flag_verbose_asm) | |
4293 | { | |
4294 | fprintf (asm_out_file, "%s File Entry: 0x%x", | |
4295 | ASM_COMMENT_START, ft_index); | |
4296 | } | |
4297 | fputc ('\n', asm_out_file); | |
4298 | /* Include directory index */ | |
4299 | output_uleb128 (0); | |
4300 | fputc ('\n', asm_out_file); | |
4301 | /* Modification time */ | |
4302 | output_uleb128 (0); | |
4303 | fputc ('\n', asm_out_file); | |
4304 | /* File length in bytes */ | |
4305 | output_uleb128 (0); | |
4306 | fputc ('\n', asm_out_file); | |
4307 | } | |
4308 | /* Terminate the file name table */ | |
4309 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4310 | fputc ('\n', asm_out_file); | |
4311 | ||
4312 | /* Set the address register to the first location in the text section */ | |
4313 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4314 | if (flag_verbose_asm) | |
4315 | { | |
4316 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); | |
4317 | } | |
4318 | fputc ('\n', asm_out_file); | |
4319 | output_uleb128 (1 + PTR_SIZE); | |
4320 | fputc ('\n', asm_out_file); | |
4321 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
4322 | fputc ('\n', asm_out_file); | |
bdb669cb | 4323 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
a3f97cbb JW |
4324 | fputc ('\n', asm_out_file); |
4325 | ||
4326 | /* Generate the line number to PC correspondence table, encoded as | |
4327 | a series of state machine operations. */ | |
4328 | current_file = 1; | |
4329 | current_line = 1; | |
bdb669cb | 4330 | strcpy (prev_line_label, TEXT_SECTION); |
a3f97cbb JW |
4331 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
4332 | { | |
e90b62db | 4333 | register dw_line_info_ref line_info; |
a3f97cbb JW |
4334 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); |
4335 | if (flag_verbose_asm) | |
4336 | { | |
4337 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
4338 | ASM_COMMENT_START); | |
4339 | } | |
4340 | fputc ('\n', asm_out_file); | |
4341 | sprintf (line_label, LINE_CODE_LABEL_FMT, lt_index); | |
4342 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
4343 | fputc ('\n', asm_out_file); | |
4344 | line_info = &line_info_table[lt_index]; | |
4345 | if (line_info->dw_file_num != current_file) | |
4346 | { | |
4347 | current_file = line_info->dw_file_num; | |
4348 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
4349 | if (flag_verbose_asm) | |
4350 | { | |
4351 | fprintf (asm_out_file, | |
4352 | "\t%s DW_LNS_set_file", ASM_COMMENT_START); | |
4353 | } | |
4354 | fputc ('\n', asm_out_file); | |
4355 | output_uleb128 (current_file); | |
4356 | if (flag_verbose_asm) | |
4357 | { | |
4358 | fprintf (asm_out_file, "\t%s \"%s\"", | |
4359 | ASM_COMMENT_START, file_table[current_file]); | |
4360 | } | |
4361 | fputc ('\n', asm_out_file); | |
4362 | } | |
4363 | if (line_info->dw_line_num != current_line) | |
4364 | { | |
4365 | line_offset = line_info->dw_line_num - current_line; | |
4366 | line_delta = line_offset - DWARF_LINE_BASE; | |
4367 | current_line = line_info->dw_line_num; | |
4368 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4369 | { | |
4370 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
4371 | DWARF_LINE_OPCODE_BASE + line_delta); | |
4372 | if (flag_verbose_asm) | |
4373 | { | |
4374 | fprintf (asm_out_file, | |
4375 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
4376 | } | |
4377 | fputc ('\n', asm_out_file); | |
4378 | } | |
4379 | else | |
4380 | { | |
4381 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
4382 | if (flag_verbose_asm) | |
4383 | { | |
4384 | fprintf (asm_out_file, | |
4385 | "\t%s advance to line %d", | |
4386 | ASM_COMMENT_START, current_line); | |
4387 | } | |
4388 | fputc ('\n', asm_out_file); | |
4389 | output_sleb128 (line_offset); | |
4390 | fputc ('\n', asm_out_file); | |
4391 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
4392 | fputc ('\n', asm_out_file); | |
4393 | } | |
4394 | } | |
4395 | strcpy (prev_line_label, line_label); | |
4396 | } | |
4397 | ||
bdb669cb | 4398 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); |
a3f97cbb JW |
4399 | if (flag_verbose_asm) |
4400 | { | |
bdb669cb JM |
4401 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
4402 | ASM_COMMENT_START); | |
a3f97cbb JW |
4403 | } |
4404 | fputc ('\n', asm_out_file); | |
bdb669cb | 4405 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, TEXT_END_LABEL, prev_line_label); |
a3f97cbb | 4406 | fputc ('\n', asm_out_file); |
bdb669cb | 4407 | |
a3f97cbb JW |
4408 | /* Output the marker for the end of the line number info. */ |
4409 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4410 | if (flag_verbose_asm) | |
4411 | { | |
4412 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); | |
4413 | } | |
4414 | fputc ('\n', asm_out_file); | |
4415 | output_uleb128 (1); | |
4416 | fputc ('\n', asm_out_file); | |
4417 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
4418 | fputc ('\n', asm_out_file); | |
e90b62db JM |
4419 | |
4420 | function = 0; | |
4421 | current_file = 1; | |
4422 | current_line = 1; | |
4423 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
4424 | { | |
4425 | register dw_separate_line_info_ref line_info | |
4426 | = &separate_line_info_table[lt_index]; | |
4427 | sprintf (line_label, SEPARATE_LINE_CODE_LABEL_FMT, lt_index); | |
4428 | if (function != line_info->function) | |
4429 | { | |
4430 | function = line_info->function; | |
4431 | /* Set the address register to the first line in the function */ | |
4432 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4433 | if (flag_verbose_asm) | |
4434 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", | |
4435 | ASM_COMMENT_START); | |
4436 | fputc ('\n', asm_out_file); | |
4437 | output_uleb128 (1 + PTR_SIZE); | |
4438 | fputc ('\n', asm_out_file); | |
4439 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
4440 | fputc ('\n', asm_out_file); | |
4441 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
4442 | fputc ('\n', asm_out_file); | |
4443 | } | |
4444 | else | |
4445 | { | |
4446 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
4447 | if (flag_verbose_asm) | |
4448 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
4449 | ASM_COMMENT_START); | |
4450 | fputc ('\n', asm_out_file); | |
4451 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
4452 | fputc ('\n', asm_out_file); | |
4453 | } | |
4454 | if (line_info->dw_file_num != current_file) | |
4455 | { | |
4456 | current_file = line_info->dw_file_num; | |
4457 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
4458 | if (flag_verbose_asm) | |
4459 | { | |
4460 | fprintf (asm_out_file, | |
4461 | "\t%s DW_LNS_set_file", ASM_COMMENT_START); | |
4462 | } | |
4463 | fputc ('\n', asm_out_file); | |
4464 | output_uleb128 (current_file); | |
4465 | if (flag_verbose_asm) | |
4466 | { | |
4467 | fprintf (asm_out_file, "\t%s \"%s\"", | |
4468 | ASM_COMMENT_START, file_table[current_file]); | |
4469 | } | |
4470 | fputc ('\n', asm_out_file); | |
4471 | } | |
4472 | if (line_info->dw_line_num != current_line) | |
4473 | { | |
4474 | line_offset = line_info->dw_line_num - current_line; | |
4475 | line_delta = line_offset - DWARF_LINE_BASE; | |
4476 | current_line = line_info->dw_line_num; | |
4477 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4478 | { | |
4479 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
4480 | DWARF_LINE_OPCODE_BASE + line_delta); | |
4481 | if (flag_verbose_asm) | |
4482 | { | |
4483 | fprintf (asm_out_file, | |
4484 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
4485 | } | |
4486 | fputc ('\n', asm_out_file); | |
4487 | } | |
4488 | else | |
4489 | { | |
4490 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
4491 | if (flag_verbose_asm) | |
4492 | { | |
4493 | fprintf (asm_out_file, | |
4494 | "\t%s advance to line %d", | |
4495 | ASM_COMMENT_START, current_line); | |
4496 | } | |
4497 | fputc ('\n', asm_out_file); | |
4498 | output_sleb128 (line_offset); | |
4499 | fputc ('\n', asm_out_file); | |
4500 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
4501 | fputc ('\n', asm_out_file); | |
4502 | } | |
4503 | } | |
4504 | ++lt_index; | |
4505 | strcpy (prev_line_label, line_label); | |
4506 | ||
4507 | /* If we're done with a function, end its sequence. */ | |
4508 | if (lt_index == separate_line_info_table_in_use | |
4509 | || separate_line_info_table[lt_index].function != function) | |
4510 | { | |
4511 | current_file = 1; | |
4512 | current_line = 1; | |
4513 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
4514 | if (flag_verbose_asm) | |
4515 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
4516 | ASM_COMMENT_START); | |
4517 | fputc ('\n', asm_out_file); | |
4518 | sprintf (line_label, FUNC_END_LABEL_FMT, function); | |
4519 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
4520 | fputc ('\n', asm_out_file); | |
4521 | ||
4522 | /* Output the marker for the end of this sequence. */ | |
4523 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4524 | if (flag_verbose_asm) | |
4525 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", | |
4526 | ASM_COMMENT_START); | |
4527 | fputc ('\n', asm_out_file); | |
4528 | output_uleb128 (1); | |
4529 | fputc ('\n', asm_out_file); | |
4530 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
4531 | fputc ('\n', asm_out_file); | |
4532 | } | |
4533 | } | |
a3f97cbb JW |
4534 | } |
4535 | \f | |
4536 | /**************** attribute support utilities ********************************/ | |
4537 | ||
4538 | /* | |
4539 | * Given a pointer to a BLOCK node return non-zero if (and only if) the node | |
4540 | * in question represents the outermost pair of curly braces (i.e. the "body | |
4541 | * block") of a function or method. | |
4542 | * | |
4543 | * For any BLOCK node representing a "body block" of a function or method, the | |
4544 | * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which | |
4545 | * represents the outermost (function) scope for the function or method (i.e. | |
4546 | * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of | |
4547 | * *that* node in turn will point to the relevant FUNCTION_DECL node. | |
4548 | */ | |
4549 | inline int | |
4550 | is_body_block (stmt) | |
4551 | register tree stmt; | |
4552 | { | |
4553 | if (TREE_CODE (stmt) == BLOCK) | |
4554 | { | |
4555 | register tree parent = BLOCK_SUPERCONTEXT (stmt); | |
4556 | ||
4557 | if (TREE_CODE (parent) == BLOCK) | |
4558 | { | |
4559 | register tree grandparent = BLOCK_SUPERCONTEXT (parent); | |
4560 | ||
4561 | if (TREE_CODE (grandparent) == FUNCTION_DECL) | |
4562 | return 1; | |
4563 | } | |
4564 | } | |
4565 | return 0; | |
4566 | } | |
4567 | ||
4568 | /* Reset the base type to DIE table, and build a special predefined | |
4569 | base type entry for the "int" signed integer base type. The | |
4570 | "int" base type is used to construct subscript index range | |
4571 | definitions, in situations where an anonymous integer type | |
4572 | is required. */ | |
4573 | inline void | |
4574 | init_base_type_table () | |
4575 | { | |
4576 | register int i; | |
4577 | register base_type_ref bt; | |
4578 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4579 | { | |
4580 | base_type_die_table[i] = NULL; | |
4581 | } | |
4582 | assert (comp_unit_die != 0); | |
4583 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4584 | { | |
4585 | bt = &base_type_table[i]; | |
4586 | if (strcmp (bt->bt_name, "int") == 0) | |
4587 | { | |
4588 | int_base_type_die = new_die (DW_TAG_base_type, comp_unit_die); | |
4589 | base_type_die_table[i] = int_base_type_die; | |
4590 | add_AT_string (int_base_type_die, DW_AT_name, bt->bt_name); | |
4591 | add_AT_unsigned (int_base_type_die, | |
4592 | DW_AT_byte_size, bt->bt_size / 8); | |
4593 | add_AT_unsigned (int_base_type_die, DW_AT_encoding, bt->bt_type); | |
4594 | break; | |
4595 | } | |
4596 | } | |
4597 | } | |
4598 | ||
4599 | /* Given a pointer to a tree node for some base type, return a pointer to | |
4600 | a DIE that describes the given type. | |
4601 | ||
4602 | This routine must only be called for GCC type nodes that correspond to | |
4603 | Dwarf base (fundamental) types. */ | |
4604 | static dw_die_ref | |
4605 | base_type_die (type) | |
4606 | register tree type; | |
4607 | { | |
4608 | register dw_die_ref base_type_result = NULL; | |
4609 | register char *type_name = NULL; | |
4610 | register int type_index = 0; | |
4611 | register base_type_ref bt; | |
4612 | register int i; | |
4613 | ||
4614 | if (TREE_CODE (type) == ERROR_MARK) | |
4615 | return 0; | |
4616 | ||
4617 | switch (TREE_CODE (type)) | |
4618 | { | |
4619 | case VOID_TYPE: | |
4620 | case ERROR_MARK: | |
4621 | break; | |
4622 | ||
4623 | case INTEGER_TYPE: | |
4624 | /* Carefully distinguish all the standard types of C, without messing | |
4625 | up if the language is not C. Note that we check only for the names | |
4626 | that contain spaces; other names might occur by coincidence in other | |
4627 | languages. */ | |
4628 | if (TYPE_NAME (type) != 0 | |
4629 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
4630 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
4631 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
4632 | { | |
4633 | type_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); | |
4634 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4635 | { | |
4636 | bt = &base_type_table[i]; | |
4637 | if (strcmp (type_name, bt->bt_name) == 0) | |
4638 | { | |
4639 | type_index = i; | |
4640 | break; | |
4641 | } | |
4642 | } | |
4643 | } | |
4644 | ||
4645 | /* Most integer types will be sorted out above, however, for the sake | |
4646 | of special `array index' integer types, the following code is also | |
4647 | provided. */ | |
4648 | if (type_index == 0) | |
4649 | { | |
4650 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4651 | { | |
4652 | bt = &base_type_table[i]; | |
4653 | if (bt->bt_size == TYPE_PRECISION (type) | |
4654 | && (TREE_UNSIGNED (type) == 0) == bt->bt_is_signed) | |
4655 | { | |
4656 | type_index = i; | |
4657 | break; | |
4658 | } | |
4659 | } | |
4660 | } | |
4661 | break; | |
4662 | ||
4663 | case REAL_TYPE: | |
4664 | /* Carefully distinguish all the standard types of C, without messing | |
4665 | up if the language is not C. */ | |
4666 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4667 | { | |
4668 | bt = &base_type_table[i]; | |
4669 | if ((bt->bt_type == DW_ATE_float) | |
4670 | && (bt->bt_size == TYPE_PRECISION (type))) | |
4671 | { | |
4672 | type_index = i; | |
4673 | break; | |
4674 | } | |
4675 | } | |
4676 | break; | |
4677 | ||
4678 | case COMPLEX_TYPE: | |
4679 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4680 | { | |
4681 | bt = &base_type_table[i]; | |
4682 | if ((bt->bt_type == DW_ATE_complex_float) | |
4683 | && (bt->bt_size == TYPE_PRECISION (type))) | |
4684 | { | |
4685 | type_index = i; | |
4686 | break; | |
4687 | } | |
4688 | } | |
4689 | break; | |
4690 | ||
4691 | case CHAR_TYPE: | |
4692 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
4693 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4694 | { | |
4695 | bt = &base_type_table[i]; | |
4696 | if (bt->bt_type == DW_ATE_signed_char | |
4697 | || bt->bt_type == DW_ATE_unsigned_char) | |
4698 | { | |
4699 | if (bt->bt_size == TYPE_PRECISION (type) | |
4700 | && ((TREE_UNSIGNED (type) == 0) == bt->bt_is_signed)) | |
4701 | { | |
4702 | type_index = i; | |
4703 | break; | |
4704 | } | |
4705 | } | |
4706 | } | |
4707 | break; | |
4708 | ||
4709 | case BOOLEAN_TYPE: | |
4710 | /* GNU FORTRAN/Ada BOOLEAN type. */ | |
4711 | for (i = 0; i < NUM_BASE_TYPES; ++i) | |
4712 | { | |
4713 | bt = &base_type_table[i]; | |
4714 | if (bt->bt_type == DW_ATE_boolean | |
4715 | && bt->bt_size == TYPE_PRECISION (type)) | |
4716 | { | |
4717 | type_index = i; | |
4718 | break; | |
4719 | } | |
4720 | } | |
4721 | break; | |
4722 | ||
4723 | default: | |
4724 | abort (); /* No other TREE_CODEs are Dwarf fundamental | |
4725 | types. */ | |
4726 | } | |
4727 | ||
4728 | if (type_index == 0) | |
4729 | { | |
4730 | base_type_result = NULL; | |
4731 | } | |
4732 | else | |
4733 | { | |
4734 | base_type_result = base_type_die_table[type_index]; | |
4735 | if (base_type_result == NULL) | |
4736 | { | |
4737 | bt = &base_type_table[type_index]; | |
4738 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); | |
4739 | base_type_die_table[type_index] = base_type_result; | |
4740 | add_AT_string (base_type_result, DW_AT_name, bt->bt_name); | |
4741 | add_AT_unsigned (base_type_result, DW_AT_byte_size, bt->bt_size / 8); | |
4742 | add_AT_unsigned (base_type_result, DW_AT_encoding, bt->bt_type); | |
4743 | } | |
4744 | ||
4745 | } | |
4746 | ||
4747 | return base_type_result; | |
4748 | } | |
4749 | ||
4750 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
4751 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
4752 | a given type is generally the same as the given type, except that if the | |
4753 | given type is a pointer or reference type, then the root type of the given | |
4754 | type is the root type of the "basis" type for the pointer or reference | |
4755 | type. (This definition of the "root" type is recursive.) Also, the root | |
4756 | type of a `const' qualified type or a `volatile' qualified type is the | |
4757 | root type of the given type without the qualifiers. */ | |
4758 | static tree | |
4759 | root_type (type) | |
4760 | register tree type; | |
4761 | { | |
4762 | if (TREE_CODE (type) == ERROR_MARK) | |
4763 | return error_mark_node; | |
4764 | ||
4765 | switch (TREE_CODE (type)) | |
4766 | { | |
4767 | case ERROR_MARK: | |
4768 | return error_mark_node; | |
4769 | ||
4770 | case POINTER_TYPE: | |
4771 | case REFERENCE_TYPE: | |
4772 | return type_main_variant (root_type (TREE_TYPE (type))); | |
4773 | ||
4774 | default: | |
4775 | return type_main_variant (type); | |
4776 | } | |
4777 | } | |
4778 | ||
4779 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
4780 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
4781 | inline int | |
4782 | is_base_type (type) | |
4783 | register tree type; | |
4784 | { | |
4785 | switch (TREE_CODE (type)) | |
4786 | { | |
4787 | case ERROR_MARK: | |
4788 | case VOID_TYPE: | |
4789 | case INTEGER_TYPE: | |
4790 | case REAL_TYPE: | |
4791 | case COMPLEX_TYPE: | |
4792 | case BOOLEAN_TYPE: | |
4793 | case CHAR_TYPE: | |
4794 | return 1; | |
4795 | ||
4796 | case SET_TYPE: | |
4797 | case ARRAY_TYPE: | |
4798 | case RECORD_TYPE: | |
4799 | case UNION_TYPE: | |
4800 | case QUAL_UNION_TYPE: | |
4801 | case ENUMERAL_TYPE: | |
4802 | case FUNCTION_TYPE: | |
4803 | case METHOD_TYPE: | |
4804 | case POINTER_TYPE: | |
4805 | case REFERENCE_TYPE: | |
4806 | case FILE_TYPE: | |
4807 | case OFFSET_TYPE: | |
4808 | case LANG_TYPE: | |
4809 | return 0; | |
4810 | ||
4811 | default: | |
4812 | abort (); | |
4813 | } | |
4814 | return 0; | |
4815 | } | |
4816 | ||
4817 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
4818 | entry that chains various modifiers in front of the given type. */ | |
4819 | static dw_die_ref | |
4820 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
4821 | register tree type; | |
4822 | register int is_const_type; | |
4823 | register int is_volatile_type; | |
4824 | register dw_die_ref context_die; | |
4825 | { | |
4826 | register enum tree_code code = TREE_CODE (type); | |
4827 | register dw_die_ref mod_type_die = NULL; | |
4828 | register dw_die_ref sub_die = NULL; | |
4829 | register tree item_type; | |
4830 | ||
4831 | if (code != ERROR_MARK) | |
4832 | { | |
bdb669cb JM |
4833 | type = build_type_variant (type, is_const_type, is_volatile_type); |
4834 | ||
4835 | mod_type_die = lookup_type_die (type); | |
4836 | if (mod_type_die) | |
4837 | return mod_type_die; | |
4838 | ||
a3f97cbb JW |
4839 | if (is_const_type) |
4840 | { | |
4841 | mod_type_die = new_die (DW_TAG_const_type, context_die); | |
bdb669cb JM |
4842 | sub_die = modified_type_die |
4843 | (build_type_variant (type, 0, is_volatile_type), | |
4844 | 0, is_volatile_type, context_die); | |
a3f97cbb JW |
4845 | } |
4846 | else if (is_volatile_type) | |
4847 | { | |
4848 | mod_type_die = new_die (DW_TAG_volatile_type, context_die); | |
bdb669cb JM |
4849 | sub_die = modified_type_die |
4850 | (TYPE_MAIN_VARIANT (type), 0, 0, context_die); | |
a3f97cbb JW |
4851 | } |
4852 | else if (code == POINTER_TYPE) | |
4853 | { | |
4854 | mod_type_die = new_die (DW_TAG_pointer_type, context_die); | |
4855 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); | |
4856 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); | |
4857 | item_type = TREE_TYPE (type); | |
4858 | sub_die = modified_type_die (item_type, | |
4859 | TYPE_READONLY (item_type), | |
4860 | TYPE_VOLATILE (item_type), | |
4861 | context_die); | |
4862 | } | |
4863 | else if (code == REFERENCE_TYPE) | |
4864 | { | |
4865 | mod_type_die = new_die (DW_TAG_reference_type, context_die); | |
4866 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); | |
4867 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); | |
4868 | item_type = TREE_TYPE (type); | |
4869 | sub_die = modified_type_die (item_type, | |
4870 | TYPE_READONLY (item_type), | |
4871 | TYPE_VOLATILE (item_type), | |
4872 | context_die); | |
4873 | } | |
4874 | else if (is_base_type (type)) | |
4875 | { | |
4876 | mod_type_die = base_type_die (type); | |
4877 | } | |
4878 | else | |
4879 | { | |
4b674448 JM |
4880 | gen_type_die (type, context_die); |
4881 | ||
a3f97cbb JW |
4882 | /* We have to get the type_main_variant here (and pass that to the |
4883 | `lookup_type_die' routine) because the ..._TYPE node we have | |
4884 | might simply be a *copy* of some original type node (where the | |
4885 | copy was created to help us keep track of typedef names) and | |
4886 | that copy might have a different TYPE_UID from the original | |
4887 | ..._TYPE node. (Note that when `equate_type_number_to_die' is | |
4888 | labeling a given type DIE for future reference, it always only | |
4889 | handles DIEs representing *main variants*, and it never even | |
4890 | knows about non-main-variants.). */ | |
4891 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
a3f97cbb | 4892 | if (mod_type_die == NULL) |
4b674448 | 4893 | abort (); |
a3f97cbb JW |
4894 | } |
4895 | } | |
4896 | if (sub_die != NULL) | |
4897 | { | |
4898 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); | |
4899 | } | |
bdb669cb | 4900 | equate_type_number_to_die (type, mod_type_die); |
a3f97cbb JW |
4901 | return mod_type_die; |
4902 | } | |
4903 | ||
a3f97cbb JW |
4904 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
4905 | an enumerated type. */ | |
4906 | inline int | |
4907 | type_is_enum (type) | |
4908 | register tree type; | |
4909 | { | |
4910 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
4911 | } | |
4912 | ||
4913 | /* Return the register number described by a given RTL node. */ | |
4914 | static unsigned | |
4915 | reg_number (rtl) | |
4916 | register rtx rtl; | |
4917 | { | |
4918 | register unsigned regno = REGNO (rtl); | |
4919 | ||
4920 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4921 | { | |
4922 | warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n", | |
4923 | regno); | |
4924 | regno = 0; | |
4925 | } | |
4926 | regno = DBX_REGISTER_NUMBER (regno); | |
4927 | return regno; | |
4928 | } | |
4929 | ||
4930 | /* Return a location descriptor that designates a machine register. */ | |
4931 | static dw_loc_descr_ref | |
4932 | reg_loc_descriptor (rtl) | |
4933 | register rtx rtl; | |
4934 | { | |
4935 | register dw_loc_descr_ref loc_result = NULL; | |
4936 | register unsigned reg = reg_number (rtl); | |
4937 | if (reg >= 0 && reg <= 31) | |
4938 | { | |
4939 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0); | |
4940 | } | |
4941 | else | |
4942 | { | |
4943 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); | |
4944 | } | |
4945 | return loc_result; | |
4946 | } | |
4947 | ||
4948 | /* Return a location descriptor that designates a base+offset location. */ | |
4949 | static dw_loc_descr_ref | |
4950 | based_loc_descr (reg, offset) | |
4951 | unsigned reg; | |
4952 | long int offset; | |
4953 | { | |
4954 | register dw_loc_descr_ref loc_result; | |
4955 | register unsigned fp_reg = (frame_pointer_needed) | |
4956 | ? FRAME_POINTER_REGNUM | |
4957 | : STACK_POINTER_REGNUM; | |
4958 | if (reg == fp_reg) | |
4959 | { | |
4960 | loc_result = new_loc_descr (DW_OP_fbreg, | |
4961 | offset - current_funcdef_frame_size, 0); | |
4962 | } | |
4963 | else if (reg >= 0 && reg <= 31) | |
4964 | { | |
4965 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset); | |
4966 | } | |
4967 | else | |
4968 | { | |
4969 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); | |
4970 | } | |
4971 | return loc_result; | |
4972 | } | |
4973 | ||
4974 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
4975 | inline int | |
4976 | is_based_loc (rtl) | |
4977 | register rtx rtl; | |
4978 | { | |
4979 | return GET_CODE (rtl) == PLUS | |
4980 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
4981 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT)); | |
4982 | } | |
4983 | ||
4984 | /* The following routine converts the RTL for a variable or parameter | |
4985 | (resident in memory) into an equivalent Dwarf representation of a | |
4986 | mechanism for getting the address of that same variable onto the top of a | |
4987 | hypothetical "address evaluation" stack. | |
4988 | When creating memory location descriptors, we are effectively transforming | |
4989 | the RTL for a memory-resident object into its Dwarf postfix expression | |
4990 | equivalent. This routine recursively descends an RTL tree, turning | |
4991 | it into Dwarf postfix code as it goes. */ | |
4992 | static dw_loc_descr_ref | |
4993 | mem_loc_descriptor (rtl) | |
4994 | register rtx rtl; | |
4995 | { | |
4996 | dw_loc_descr_ref mem_loc_result = NULL; | |
4997 | /* Note that for a dynamically sized array, the location we will generate a | |
4998 | description of here will be the lowest numbered location which is | |
4999 | actually within the array. That's *not* necessarily the same as the | |
5000 | zeroth element of the array. */ | |
5001 | switch (GET_CODE (rtl)) | |
5002 | { | |
5003 | case SUBREG: | |
5004 | /* The case of a subreg may arise when we have a local (register) | |
5005 | variable or a formal (register) parameter which doesn't quite fill | |
5006 | up an entire register. For now, just assume that it is | |
5007 | legitimate to make the Dwarf info refer to the whole register which | |
5008 | contains the given subreg. */ | |
5009 | rtl = XEXP (rtl, 0); | |
5010 | /* Drop thru. */ | |
5011 | ||
5012 | case REG: | |
5013 | /* Whenever a register number forms a part of the description of the | |
5014 | method for calculating the (dynamic) address of a memory resident | |
5015 | object, DWARF rules require the register number be referred to as | |
5016 | a "base register". This distinction is not based in any way upon | |
5017 | what category of register the hardware believes the given register | |
5018 | belongs to. This is strictly DWARF terminology we're dealing with | |
5019 | here. Note that in cases where the location of a memory-resident | |
5020 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
5021 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
5022 | may just be OP_BASEREG (basereg). This may look deceptively like | |
5023 | the object in question was allocated to a register (rather than in | |
5024 | memory) so DWARF consumers need to be aware of the subtle | |
5025 | distinction between OP_REG and OP_BASEREG. */ | |
5026 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
5027 | break; | |
5028 | ||
5029 | case MEM: | |
5030 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
5031 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
5032 | break; | |
5033 | ||
5034 | case CONST: | |
5035 | case SYMBOL_REF: | |
5036 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
5037 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
5038 | mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl); | |
5039 | break; | |
5040 | ||
5041 | case PLUS: | |
5042 | if (is_based_loc (rtl)) | |
5043 | { | |
5044 | mem_loc_result = based_loc_descr ( | |
5045 | reg_number (XEXP (rtl, 0)), | |
5046 | INTVAL (XEXP (rtl, 1))); | |
5047 | } | |
5048 | else | |
5049 | { | |
5050 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
5051 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
5052 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0)); | |
5053 | } | |
5054 | break; | |
5055 | ||
5056 | case CONST_INT: | |
5057 | mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0); | |
5058 | break; | |
5059 | ||
5060 | default: | |
5061 | abort (); | |
5062 | } | |
5063 | return mem_loc_result; | |
5064 | } | |
5065 | ||
5066 | /* Output a proper Dwarf location descriptor for a variable or parameter | |
5067 | which is either allocated in a register or in a memory location. For a | |
5068 | register, we just generate an OP_REG and the register number. For a | |
5069 | memory location we provide a Dwarf postfix expression describing how to | |
5070 | generate the (dynamic) address of the object onto the address stack. */ | |
5071 | static dw_loc_descr_ref | |
5072 | loc_descriptor (rtl) | |
5073 | register rtx rtl; | |
5074 | { | |
5075 | dw_loc_descr_ref loc_result = NULL; | |
5076 | switch (GET_CODE (rtl)) | |
5077 | { | |
5078 | case SUBREG: | |
5079 | ||
5080 | /* The case of a subreg may arise when we have a local (register) | |
5081 | variable or a formal (register) parameter which doesn't quite fill | |
5082 | up an entire register. For now, just assume that it is | |
5083 | legitimate to make the Dwarf info refer to the whole register which | |
5084 | contains the given subreg. */ | |
5085 | ||
5086 | rtl = XEXP (rtl, 0); | |
5087 | loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0); | |
5088 | break; | |
5089 | ||
5090 | case REG: | |
5091 | loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0); | |
5092 | break; | |
5093 | ||
5094 | case MEM: | |
5095 | loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
5096 | break; | |
5097 | ||
5098 | default: | |
5099 | abort (); /* Should never happen */ | |
5100 | } | |
5101 | return loc_result; | |
5102 | } | |
5103 | ||
5104 | /* Given an unsigned value, round it up to the lowest multiple of `boundary' | |
5105 | which is not less than the value itself. */ | |
5106 | inline unsigned | |
5107 | ceiling (value, boundary) | |
5108 | register unsigned value; | |
5109 | register unsigned boundary; | |
5110 | { | |
5111 | return (((value + boundary - 1) / boundary) * boundary); | |
5112 | } | |
5113 | ||
5114 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
5115 | pointer to the declared type for the relevant field variable, or return | |
5116 | `integer_type_node' if the given node turns out to be an | |
5117 | ERROR_MARK node. */ | |
5118 | inline tree | |
5119 | field_type (decl) | |
5120 | register tree decl; | |
5121 | { | |
5122 | register tree type; | |
5123 | ||
5124 | if (TREE_CODE (decl) == ERROR_MARK) | |
5125 | return integer_type_node; | |
5126 | ||
5127 | type = DECL_BIT_FIELD_TYPE (decl); | |
5128 | if (type == NULL) | |
5129 | type = TREE_TYPE (decl); | |
5130 | ||
5131 | return type; | |
5132 | } | |
5133 | ||
5134 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
5135 | node, return the alignment in bits for the type, or else return | |
5136 | BITS_PER_WORD if the node actually turns out to be an | |
5137 | ERROR_MARK node. */ | |
5138 | inline unsigned | |
5139 | simple_type_align_in_bits (type) | |
5140 | register tree type; | |
5141 | { | |
5142 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
5143 | } | |
5144 | ||
5145 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
5146 | node, return the size in bits for the type if it is a constant, or else | |
5147 | return the alignment for the type if the type's size is not constant, or | |
5148 | else return BITS_PER_WORD if the type actually turns out to be an | |
5149 | ERROR_MARK node. */ | |
5150 | inline unsigned | |
5151 | simple_type_size_in_bits (type) | |
5152 | register tree type; | |
5153 | { | |
5154 | if (TREE_CODE (type) == ERROR_MARK) | |
5155 | return BITS_PER_WORD; | |
5156 | else | |
5157 | { | |
5158 | register tree type_size_tree = TYPE_SIZE (type); | |
5159 | ||
5160 | if (TREE_CODE (type_size_tree) != INTEGER_CST) | |
5161 | return TYPE_ALIGN (type); | |
5162 | ||
5163 | return (unsigned) TREE_INT_CST_LOW (type_size_tree); | |
5164 | } | |
5165 | } | |
5166 | ||
5167 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
5168 | return the byte offset of the lowest addressed byte of the "containing | |
5169 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
5170 | determine what that offset is, either because the argument turns out to | |
5171 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
5172 | variable. (We can't handle the latter case just yet). */ | |
5173 | static unsigned | |
5174 | field_byte_offset (decl) | |
5175 | register tree decl; | |
5176 | { | |
5177 | register unsigned type_align_in_bytes; | |
5178 | register unsigned type_align_in_bits; | |
5179 | register unsigned type_size_in_bits; | |
5180 | register unsigned object_offset_in_align_units; | |
5181 | register unsigned object_offset_in_bits; | |
5182 | register unsigned object_offset_in_bytes; | |
5183 | register tree type; | |
5184 | register tree bitpos_tree; | |
5185 | register tree field_size_tree; | |
5186 | register unsigned bitpos_int; | |
5187 | register unsigned deepest_bitpos; | |
5188 | register unsigned field_size_in_bits; | |
5189 | ||
5190 | if (TREE_CODE (decl) == ERROR_MARK) | |
5191 | return 0; | |
5192 | ||
5193 | if (TREE_CODE (decl) != FIELD_DECL) | |
5194 | abort (); | |
5195 | ||
5196 | type = field_type (decl); | |
5197 | ||
5198 | bitpos_tree = DECL_FIELD_BITPOS (decl); | |
5199 | field_size_tree = DECL_SIZE (decl); | |
5200 | ||
5201 | /* We cannot yet cope with fields whose positions or sizes are variable, so | |
5202 | for now, when we see such things, we simply return 0. Someday, we may | |
5203 | be able to handle such cases, but it will be damn difficult. */ | |
5204 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
5205 | return 0; | |
5206 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
5207 | ||
5208 | if (TREE_CODE (field_size_tree) != INTEGER_CST) | |
5209 | return 0; | |
5210 | field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree); | |
5211 | ||
5212 | type_size_in_bits = simple_type_size_in_bits (type); | |
5213 | ||
5214 | type_align_in_bits = simple_type_align_in_bits (type); | |
5215 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
5216 | ||
5217 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
5218 | the starting bit offset (relative to the start of the containing | |
5219 | structure type) of the hypothetical "containing object" for a bit- | |
5220 | field. Thus, when computing the byte offset value for the start of the | |
5221 | "containing object" of a bit-field, we must deduce this information on | |
5222 | our own. This can be rather tricky to do in some cases. For example, | |
5223 | handling the following structure type definition when compiling for an | |
5224 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
5225 | can be very tricky: | |
5226 | ||
5227 | struct S { int field1; long long field2:31; }; | |
5228 | ||
5229 | Fortunately, there is a simple rule-of-thumb which can be | |
5230 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
5231 | 8 bytes for the structure shown above. It decides to do this based upon | |
5232 | one simple rule for bit-field allocation. Quite simply, GCC allocates | |
5233 | each "containing object" for each bit-field at the first (i.e. lowest | |
5234 | addressed) legitimate alignment boundary (based upon the required | |
5235 | minimum alignment for the declared type of the field) which it can | |
5236 | possibly use, subject to the condition that there is still enough | |
5237 | available space remaining in the containing object (when allocated at | |
5238 | the selected point) to fully accommodate all of the bits of the | |
5239 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
5240 | 8 bytes for each object of the structure type shown above. When looking | |
5241 | for a place to allocate the "containing object" for `field2', the | |
5242 | compiler simply tries to allocate a 64-bit "containing object" at each | |
5243 | successive 32-bit boundary (starting at zero) until it finds a place to | |
5244 | allocate that 64- bit field such that at least 31 contiguous (and | |
5245 | previously unallocated) bits remain within that selected 64 bit field. | |
5246 | (As it turns out, for the example above, the compiler finds that it is | |
5247 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
5248 | within the structure type.) Here we attempt to work backwards from the | |
5249 | limited set of facts we're given, and we try to deduce from those facts, | |
5250 | where GCC must have believed that the containing object started (within | |
5251 | the structure type). The value we deduce is then used (by the callers of | |
5252 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
5253 | for fields (both bit-fields and, in the case of DW_AT_location, regular | |
5254 | fields as well). */ | |
5255 | ||
5256 | /* Figure out the bit-distance from the start of the structure to the | |
5257 | "deepest" bit of the bit-field. */ | |
5258 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
5259 | ||
5260 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
5261 | lowest addressed bit of the containing object must be. */ | |
5262 | object_offset_in_bits | |
5263 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
5264 | ||
5265 | /* Compute the offset of the containing object in "alignment units". */ | |
5266 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
5267 | ||
5268 | /* Compute the offset of the containing object in bytes. */ | |
5269 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
5270 | ||
5271 | return object_offset_in_bytes; | |
5272 | } | |
5273 | ||
5274 | ||
5275 | \f | |
5276 | /****************************** attributes *********************************/ | |
5277 | ||
5278 | /* The following routines define various Dwarf attributes | |
5279 | (and any data associated with them). */ | |
5280 | ||
5281 | ||
5282 | /* Output the form of location attributes suitable for whole variables and | |
5283 | whole parameters. Note that the location attributes for struct fields are | |
5284 | generated by the routine `data_member_location_attribute' below. */ | |
5285 | static void | |
5286 | add_location_attribute (die, rtl) | |
5287 | dw_die_ref die; | |
5288 | register rtx rtl; | |
5289 | { | |
5290 | dw_loc_descr_ref loc_descr = NULL; | |
5291 | ||
5292 | /* Handle a special case. If we are about to output a location descriptor | |
5293 | for a variable or parameter which has been optimized out of existence, | |
5294 | don't do that. Instead we output a null location descriptor value as | |
5295 | part of the location attribute. A variable which has been optimized out | |
5296 | of existence will have a DECL_RTL value which denotes a pseudo-reg. | |
5297 | Currently, in some rare cases, variables can have DECL_RTL values which | |
5298 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
5299 | elsewhere in the compiler. We treat such cases as if the variable(s) in | |
5300 | question had been optimized out of existence. Note that in all cases | |
5301 | where we wish to express the fact that a variable has been optimized out | |
5302 | of existence, we do not simply suppress the generation of the entire | |
5303 | location attribute because the absence of a location attribute in | |
5304 | certain kinds of DIEs is used to indicate something else entirely... | |
5305 | i.e. that the DIE represents an object declaration, but not a | |
5306 | definition. So sayeth the PLSIG. */ | |
5307 | if (!is_pseudo_reg (rtl) | |
5308 | && (GET_CODE (rtl) != MEM | |
5309 | || !is_pseudo_reg (XEXP (rtl, 0)))) | |
5310 | { | |
5311 | loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX)); | |
5312 | } | |
5313 | ||
5314 | #ifdef MIPS_DEBUGGING_INFO | |
5315 | /* ??? SGI's dwarf reader is buggy, and will not accept a zero size | |
5316 | location descriptor. Lets just use r0 for now to represent a | |
5317 | variable that has been optimized away. */ | |
5318 | if (loc_descr == NULL) | |
5319 | { | |
5320 | loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0)); | |
5321 | } | |
5322 | #endif | |
5323 | ||
5324 | add_AT_loc (die, DW_AT_location, loc_descr); | |
5325 | } | |
5326 | ||
5327 | /* Attach the specialized form of location attribute used for data | |
5328 | members of struct and union types. In the special case of a | |
5329 | FIELD_DECL node which represents a bit-field, the "offset" part | |
5330 | of this special location descriptor must indicate the distance | |
5331 | in bytes from the lowest-addressed byte of the containing struct | |
5332 | or union type to the lowest-addressed byte of the "containing | |
5333 | object" for the bit-field. (See the `field_byte_offset' function | |
5334 | above).. For any given bit-field, the "containing object" is a | |
5335 | hypothetical object (of some integral or enum type) within which | |
5336 | the given bit-field lives. The type of this hypothetical | |
5337 | "containing object" is always the same as the declared type of | |
5338 | the individual bit-field itself (for GCC anyway... the DWARF | |
5339 | spec doesn't actually mandate this). Note that it is the size | |
5340 | (in bytes) of the hypothetical "containing object" which will | |
5341 | be given in the DW_AT_byte_size attribute for this bit-field. | |
5342 | (See the `byte_size_attribute' function below.) It is also used | |
5343 | when calculating the value of the DW_AT_bit_offset attribute. | |
5344 | (See the `bit_offset_attribute' function below). */ | |
5345 | static void | |
5346 | add_data_member_location_attribute (die, decl) | |
5347 | register dw_die_ref die; | |
5348 | register tree decl; | |
5349 | { | |
5350 | register unsigned long offset = field_byte_offset (decl); | |
5351 | register dw_loc_descr_ref loc_descr; | |
5352 | register enum dwarf_location_atom op; | |
5353 | ||
5354 | /* The DWARF2 standard says that we should assume that the structure address | |
5355 | is already on the stack, so we can specify a structure field address | |
5356 | by using DW_OP_plus_uconst. */ | |
5357 | #ifdef MIPS_DEBUGGING_INFO | |
5358 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
5359 | correctly. It works only if we leave the offset on the stack. */ | |
5360 | op = DW_OP_constu; | |
5361 | #else | |
5362 | op = DW_OP_plus_uconst; | |
5363 | #endif | |
5364 | loc_descr = new_loc_descr (op, offset, 0); | |
5365 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
5366 | } | |
5367 | ||
5368 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
5369 | does not have a "location" either in memory or in a register. These | |
5370 | things can arise in GNU C when a constant is passed as an actual parameter | |
5371 | to an inlined function. They can also arise in C++ where declared | |
5372 | constants do not necessarily get memory "homes". */ | |
5373 | static void | |
5374 | add_const_value_attribute (die, rtl) | |
5375 | register dw_die_ref die; | |
5376 | register rtx rtl; | |
5377 | { | |
5378 | switch (GET_CODE (rtl)) | |
5379 | { | |
5380 | case CONST_INT: | |
5381 | /* Note that a CONST_INT rtx could represent either an integer or a | |
5382 | floating-point constant. A CONST_INT is used whenever the constant | |
5383 | will fit into a single word. In all such cases, the original mode | |
5384 | of the constant value is wiped out, and the CONST_INT rtx is | |
5385 | assigned VOIDmode. */ | |
5386 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
5387 | break; | |
5388 | ||
5389 | case CONST_DOUBLE: | |
5390 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
5391 | floating-point constant. A CONST_DOUBLE is used whenever the | |
5392 | constant requires more than one word in order to be adequately | |
5393 | represented. In all such cases, the original mode of the constant | |
5394 | value is preserved as the mode of the CONST_DOUBLE rtx, but for | |
5395 | simplicity we always just output CONST_DOUBLEs using 8 bytes. */ | |
5396 | add_AT_double (die, DW_AT_const_value, | |
5397 | (unsigned) CONST_DOUBLE_HIGH (rtl), | |
5398 | (unsigned) CONST_DOUBLE_LOW (rtl)); | |
5399 | break; | |
5400 | ||
5401 | case CONST_STRING: | |
5402 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
5403 | break; | |
5404 | ||
5405 | case SYMBOL_REF: | |
5406 | case LABEL_REF: | |
5407 | case CONST: | |
5408 | add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl)); | |
5409 | break; | |
5410 | ||
5411 | case PLUS: | |
5412 | /* In cases where an inlined instance of an inline function is passed | |
5413 | the address of an `auto' variable (which is local to the caller) we | |
5414 | can get a situation where the DECL_RTL of the artificial local | |
5415 | variable (for the inlining) which acts as a stand-in for the | |
5416 | corresponding formal parameter (of the inline function) will look | |
5417 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
5418 | exactly a compile-time constant expression, but it isn't the address | |
5419 | of the (artificial) local variable either. Rather, it represents the | |
5420 | *value* which the artificial local variable always has during its | |
5421 | lifetime. We currently have no way to represent such quasi-constant | |
5422 | values in Dwarf, so for now we just punt and generate an | |
5423 | DW_AT_const_value attribute with null address. */ | |
5424 | add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx)); | |
5425 | break; | |
5426 | ||
5427 | default: | |
5428 | /* No other kinds of rtx should be possible here. */ | |
5429 | abort (); | |
5430 | } | |
5431 | ||
5432 | } | |
5433 | ||
5434 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
5435 | data attribute for a variable or a parameter. We generate the | |
5436 | DW_AT_const_value attribute only in those cases where the given variable | |
5437 | or parameter does not have a true "location" either in memory or in a | |
5438 | register. This can happen (for example) when a constant is passed as an | |
5439 | actual argument in a call to an inline function. (It's possible that | |
5440 | these things can crop up in other ways also.) Note that one type of | |
5441 | constant value which can be passed into an inlined function is a constant | |
5442 | pointer. This can happen for example if an actual argument in an inlined | |
5443 | function call evaluates to a compile-time constant address. */ | |
5444 | static void | |
5445 | add_location_or_const_value_attribute (die, decl) | |
5446 | register dw_die_ref die; | |
5447 | register tree decl; | |
5448 | { | |
5449 | register rtx rtl; | |
5450 | register tree declared_type; | |
5451 | register tree passed_type; | |
5452 | ||
5453 | if (TREE_CODE (decl) == ERROR_MARK) | |
5454 | { | |
5455 | return; | |
5456 | } | |
5457 | if ((TREE_CODE (decl) != VAR_DECL) | |
5458 | && (TREE_CODE (decl) != PARM_DECL)) | |
5459 | { | |
5460 | /* Should never happen. */ | |
5461 | abort (); | |
5462 | return; | |
5463 | } | |
5464 | /* Here we have to decide where we are going to say the parameter "lives" | |
5465 | (as far as the debugger is concerned). We only have a couple of | |
5466 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
5467 | DECL_RTL normally indicates where the parameter lives during most of the | |
5468 | activa- tion of the function. If optimization is enabled however, this | |
5469 | could be either NULL or else a pseudo-reg. Both of those cases indicate | |
5470 | that the parameter doesn't really live anywhere (as far as the code | |
5471 | generation parts of GCC are concerned) during most of the function's | |
5472 | activation. That will happen (for example) if the parameter is never | |
5473 | referenced within the function. We could just generate a location | |
5474 | descriptor here for all non-NULL non-pseudo values of DECL_RTL and | |
5475 | ignore all of the rest, but we can be a little nicer than that if we | |
5476 | also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a | |
5477 | pseudo-reg. Note however that we can only get away with using | |
5478 | DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited | |
5479 | cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as | |
5480 | TREE_TYPE(decl) we can be sure that the parameter was passed using the | |
5481 | same type as it is declared to have within the function, and that its | |
5482 | DECL_INCOMING_RTL points us to a place where a value of that type is | |
5483 | passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are | |
5484 | different types however, we cannot (in general) use DECL_INCOMING_RTL as | |
5485 | a backup substitute for DECL_RTL because in these cases, | |
5486 | DECL_INCOMING_RTL points us to a value of some type which is *different* | |
5487 | from the type of the parameter itself. Thus, if we tried to use | |
5488 | DECL_INCOMING_RTL to generate a location attribute in such cases, the | |
5489 | debugger would end up (for example) trying to fetch a `float' from a | |
5490 | place which actually contains the first part of a `double'. That would | |
5491 | lead to really incorrect and confusing output at debug-time, and we | |
5492 | don't want that now do we? So in general, we DO NOT use | |
5493 | DECL_INCOMING_RTL as a backup for DECL_RTL in cases where | |
5494 | DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute | |
5495 | exceptions however. On little-endian machines we can get away with | |
5496 | using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as | |
5497 | TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type | |
5498 | which is smaller than TREE_TYPE(decl). These cases arise when (on a | |
5499 | little-endian machine) a non-prototyped function has a parameter | |
5500 | declared to be of type `short' or `char'. In such cases, | |
5501 | TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be | |
5502 | `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
5503 | passed `int' value. If the debugger then uses that address to fetch a | |
5504 | `short' or a `char' (on a little-endian machine) the result will be the | |
5505 | correct data, so we allow for such exceptional cases below. Note that | |
5506 | our goal here is to describe the place where the given formal parameter | |
5507 | lives during most of the function's activation (i.e. between the end of | |
5508 | the prologue and the start of the epilogue). We'll do that as best as | |
5509 | we can. Note however that if the given formal parameter is modified | |
5510 | sometime during the execution of the function, then a stack backtrace | |
5511 | (at debug-time) will show the function as having been called with the | |
5512 | *new* value rather than the value which was originally passed in. This | |
5513 | happens rarely enough that it is not a major problem, but it *is* a | |
5514 | problem, and I'd like to fix it. A future version of dwarfout.c may | |
5515 | generate two additional attributes for any given DW_TAG_formal_parameter | |
5516 | DIE which will describe the "passed type" and the "passed location" for | |
5517 | the given formal parameter in addition to the attributes we now generate | |
5518 | to indicate the "declared type" and the "active location" for each | |
5519 | parameter. This additional set of attributes could be used by debuggers | |
5520 | for stack backtraces. Separately, note that sometimes DECL_RTL can be | |
5521 | NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example) | |
5522 | for inlined-instances of inline function formal parameters which are | |
5523 | never referenced. This really shouldn't be happening. All PARM_DECL | |
5524 | nodes should get valid non-NULL DECL_INCOMING_RTL values, but | |
5525 | integrate.c doesn't currently generate these values for inlined | |
5526 | instances of inline function parameters, so when we see such cases, we | |
5527 | are just SOL (shit-out-of-luck) for the time being (until integrate.c | |
5528 | gets fixed). */ | |
5529 | ||
5530 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
5531 | rtl = DECL_RTL (decl); | |
5532 | ||
5533 | if (TREE_CODE (decl) == PARM_DECL) | |
5534 | { | |
5535 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
5536 | { | |
5537 | declared_type = type_main_variant (TREE_TYPE (decl)); | |
5538 | passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
5539 | /* This decl represents a formal parameter which was | |
5540 | optimized out. | |
5541 | ||
5542 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle | |
5543 | all* cases where (rtl == NULL_RTX) just below. */ | |
5544 | if (declared_type == passed_type) | |
5545 | { | |
5546 | rtl = DECL_INCOMING_RTL (decl); | |
5547 | } | |
5548 | else if (!BYTES_BIG_ENDIAN) | |
5549 | { | |
5550 | if (TREE_CODE (declared_type) == INTEGER_TYPE) | |
5551 | { | |
5552 | if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) | |
5553 | { | |
5554 | rtl = DECL_INCOMING_RTL (decl); | |
5555 | } | |
5556 | } | |
5557 | } | |
5558 | if (rtl == NULL_RTX) | |
5559 | { | |
5560 | return; | |
5561 | } | |
5562 | } | |
5563 | } | |
5564 | switch (GET_CODE (rtl)) | |
5565 | { | |
5566 | case CONST_INT: | |
5567 | case CONST_DOUBLE: | |
5568 | case CONST_STRING: | |
5569 | case SYMBOL_REF: | |
5570 | case LABEL_REF: | |
5571 | case CONST: | |
5572 | case PLUS: | |
5573 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
5574 | add_const_value_attribute (die, rtl); | |
5575 | break; | |
5576 | ||
5577 | case MEM: | |
5578 | case REG: | |
5579 | case SUBREG: | |
5580 | add_location_attribute (die, rtl); | |
5581 | break; | |
5582 | ||
5583 | default: | |
5584 | abort (); /* Should never happen. */ | |
5585 | } | |
5586 | } | |
5587 | ||
5588 | /* Generate an DW_AT_name attribute given some string value to be included as | |
5589 | the value of the attribute. */ | |
5590 | inline void | |
5591 | add_name_attribute (die, name_string) | |
5592 | register dw_die_ref die; | |
5593 | register char *name_string; | |
5594 | { | |
5595 | if (name_string && *name_string) | |
5596 | { | |
5597 | add_AT_string (die, DW_AT_name, name_string); | |
5598 | } | |
5599 | } | |
5600 | ||
5601 | /* Given a tree node describing an array bound (either lower or upper) output | |
5602 | a representation for that bound. */ | |
5603 | static void | |
5604 | add_bound_info (subrange_die, bound_attr, bound) | |
5605 | register dw_die_ref subrange_die; | |
5606 | register enum dwarf_attribute bound_attr; | |
5607 | register tree bound; | |
5608 | { | |
5609 | register dw_loc_descr_ref bound_loc = NULL; | |
5610 | register unsigned bound_value = 0; | |
5611 | switch (TREE_CODE (bound)) | |
5612 | { | |
5613 | case ERROR_MARK: | |
5614 | return; | |
5615 | ||
5616 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
5617 | case INTEGER_CST: | |
5618 | bound_value = TREE_INT_CST_LOW (bound); | |
5619 | /* TODO: we need to check for C language below, or some flag | |
5620 | derived from the language. C implies a lower bound of 0. */ | |
5621 | if (!(bound_attr == DW_AT_lower_bound && bound_value == 0)) | |
5622 | { | |
5623 | add_AT_unsigned (subrange_die, bound_attr, bound_value); | |
5624 | } | |
5625 | break; | |
5626 | ||
5627 | /* Dynamic bounds may be represented by NOP_EXPR nodes containing | |
5628 | SAVE_EXPR nodes. */ | |
5629 | case NOP_EXPR: | |
5630 | bound = TREE_OPERAND (bound, 0); | |
5631 | /* ... fall thru... */ | |
5632 | ||
5633 | case SAVE_EXPR: | |
5634 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
5635 | access the upper bound values are essentially bogus. They only | |
5636 | describe (at best) how to get at these values at the points in the | |
5637 | generated code right after they have just been computed. Worse yet, | |
5638 | in the typical case, the upper bound values will not even *be* | |
5639 | computed in the optimized code, so these SAVE_EXPRs are entirely | |
5640 | bogus. In order to compensate for this fact, we check here to see if | |
5641 | optimization is enabled, and if so, we effectively create an empty | |
5642 | location description for the (unknown and unknowable) upper bound. | |
5643 | This should not cause too much trouble for existing (stupid?) | |
5644 | debuggers because they have to deal with empty upper bounds location | |
5645 | descriptions anyway in order to be able to deal with incomplete array | |
5646 | types. Of course an intelligent debugger (GDB?) should be able to | |
5647 | comprehend that a missing upper bound specification in a array type | |
5648 | used for a storage class `auto' local array variable indicates that | |
5649 | the upper bound is both unknown (at compile- time) and unknowable (at | |
5650 | run-time) due to optimization. */ | |
5651 | if (!optimize) | |
5652 | { | |
5653 | bound_loc = mem_loc_descriptor ( | |
5654 | eliminate_regs (SAVE_EXPR_RTL (bound), | |
5655 | 0, NULL_RTX)); | |
5656 | } | |
5657 | else | |
5658 | { | |
5659 | bound_loc = NULL; | |
5660 | } | |
5661 | add_AT_loc (subrange_die, bound_attr, bound_loc); | |
5662 | break; | |
5663 | ||
5664 | default: | |
5665 | abort (); | |
5666 | } | |
5667 | } | |
5668 | ||
5669 | /* Note that the block of subscript information for an array type also | |
5670 | includes information about the element type of type given array type. */ | |
5671 | static void | |
5672 | add_subscript_info (type_die, type) | |
5673 | register dw_die_ref type_die; | |
5674 | register tree type; | |
5675 | { | |
5676 | register unsigned dimension_number; | |
5677 | register tree lower, upper; | |
5678 | register dw_die_ref subrange_die; | |
5679 | ||
5680 | /* The GNU compilers represent multidimensional array types as sequences of | |
5681 | one dimensional array types whose element types are themselves array | |
5682 | types. Here we squish that down, so that each multidimensional array | |
5683 | type gets only one array_type DIE in the Dwarf debugging info. The draft | |
5684 | Dwarf specification say that we are allowed to do this kind of | |
5685 | compression in C (because there is no difference between an array or | |
5686 | arrays and a multidimensional array in C) but for other source languages | |
5687 | (e.g. Ada) we probably shouldn't do this. */ | |
5688 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a | |
5689 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
5690 | We work around this by disabling this feature. See also | |
5691 | gen_array_type_die. */ | |
5692 | #ifndef MIPS_DEBUGGING_INFO | |
5693 | for (dimension_number = 0; | |
5694 | TREE_CODE (type) == ARRAY_TYPE; | |
5695 | type = TREE_TYPE (type), dimension_number++) | |
5696 | { | |
5697 | #endif | |
5698 | register tree domain = TYPE_DOMAIN (type); | |
5699 | ||
5700 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
5701 | and (in GNU C only) variable bounds. Handle all three forms | |
5702 | here. */ | |
5703 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
5704 | if (domain) | |
5705 | { | |
5706 | /* We have an array type with specified bounds. */ | |
5707 | lower = TYPE_MIN_VALUE (domain); | |
5708 | upper = TYPE_MAX_VALUE (domain); | |
5709 | ||
5710 | /* TODO: establish DW_AT_type for the basis type a byte_size | |
5711 | attribute if the byte size is non-standard */ | |
5712 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); | |
5713 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
5714 | } | |
5715 | else | |
5716 | { | |
5717 | /* We have an array type with an unspecified length. For C and C++ | |
5718 | we can assume that this really means that (a) the index type is | |
5719 | an integral type, and (b) the lower bound is zero. Note that | |
5720 | Dwarf defines the representation of an unspecified (upper) bound | |
5721 | as being a zero-length location description. */ | |
5722 | ||
5723 | /* define the (assumed) index type. */ | |
5724 | add_AT_die_ref (subrange_die, DW_AT_type, int_base_type_die); | |
5725 | ||
5726 | /* Add the (assumed) lower bound (constant) value. */ | |
5727 | add_AT_unsigned (subrange_die, DW_AT_lower_bound, 0); | |
5728 | ||
5729 | /* Add the (empty) location description for the upper bound. */ | |
5730 | add_AT_loc (subrange_die, DW_AT_upper_bound, NULL); | |
5731 | } | |
5732 | #ifndef MIPS_DEBUGGING_INFO | |
5733 | } | |
5734 | #endif | |
5735 | } | |
5736 | ||
5737 | static void | |
5738 | add_byte_size_attribute (die, tree_node) | |
5739 | dw_die_ref die; | |
5740 | register tree tree_node; | |
5741 | { | |
5742 | register unsigned size; | |
5743 | ||
5744 | switch (TREE_CODE (tree_node)) | |
5745 | { | |
5746 | case ERROR_MARK: | |
5747 | size = 0; | |
5748 | break; | |
5749 | case ENUMERAL_TYPE: | |
5750 | case RECORD_TYPE: | |
5751 | case UNION_TYPE: | |
5752 | case QUAL_UNION_TYPE: | |
5753 | size = int_size_in_bytes (tree_node); | |
5754 | break; | |
5755 | case FIELD_DECL: | |
5756 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
5757 | generally given as the number of bytes normally allocated for an | |
5758 | object of the *declared* type of the member itself. This is true | |
5759 | even for bit-fields. */ | |
5760 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
5761 | break; | |
5762 | default: | |
5763 | abort (); | |
5764 | } | |
5765 | ||
5766 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
5767 | indicates that the byte size of the entity in question is variable. We | |
5768 | have no good way of expressing this fact in Dwarf at the present time, | |
5769 | so just let the -1 pass on through. */ | |
5770 | ||
5771 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
5772 | } | |
5773 | ||
5774 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
5775 | which specifies the distance in bits from the highest order bit of the | |
5776 | "containing object" for the bit-field to the highest order bit of the | |
5777 | bit-field itself. | |
5778 | ||
5779 | For any given bit-field, the "containing object" is a hypothetical object (of | |
5780 | some integral or enum type) within which the given bit-field lives. The | |
5781 | type of this hypothetical "containing object" is always the same as the | |
5782 | declared type of the individual bit-field itself. | |
5783 | The determination of the exact location of the "containing object" for a | |
5784 | bit-field is rather complicated. It's handled by the `field_byte_offset' | |
5785 | function (above). | |
5786 | ||
5787 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
5788 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
5789 | (See `byte_size_attribute' above). */ | |
5790 | inline void | |
5791 | add_bit_offset_attribute (die, decl) | |
5792 | register dw_die_ref die; | |
5793 | register tree decl; | |
5794 | { | |
5795 | register unsigned object_offset_in_bytes = field_byte_offset (decl); | |
5796 | register tree type = DECL_BIT_FIELD_TYPE (decl); | |
5797 | register tree bitpos_tree = DECL_FIELD_BITPOS (decl); | |
5798 | register unsigned bitpos_int; | |
5799 | register unsigned highest_order_object_bit_offset; | |
5800 | register unsigned highest_order_field_bit_offset; | |
5801 | register unsigned bit_offset; | |
5802 | ||
5803 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ | |
5804 | assert (type); /* Must be a bit field. */ | |
5805 | ||
5806 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
5807 | encounter such things, just return without generating any attribute | |
5808 | whatsoever. */ | |
5809 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
5810 | { | |
5811 | return; | |
5812 | } | |
5813 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
5814 | ||
5815 | /* Note that the bit offset is always the distance (in bits) from the | |
5816 | highest-order bit of the "containing object" to the highest-order bit of | |
5817 | the bit-field itself. Since the "high-order end" of any object or field | |
5818 | is different on big-endian and little-endian machines, the computation | |
5819 | below must take account of these differences. */ | |
5820 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
5821 | highest_order_field_bit_offset = bitpos_int; | |
5822 | ||
5823 | if (!BYTES_BIG_ENDIAN) | |
5824 | { | |
5825 | highest_order_field_bit_offset | |
5826 | += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); | |
5827 | ||
5828 | highest_order_object_bit_offset += simple_type_size_in_bits (type); | |
5829 | } | |
5830 | bit_offset = | |
5831 | (!BYTES_BIG_ENDIAN | |
5832 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
5833 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
5834 | ||
5835 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
5836 | } | |
5837 | ||
5838 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
5839 | which specifies the length in bits of the given field. */ | |
5840 | inline void | |
5841 | add_bit_size_attribute (die, decl) | |
5842 | register dw_die_ref die; | |
5843 | register tree decl; | |
5844 | { | |
5845 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ | |
5846 | assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ | |
5847 | add_AT_unsigned (die, DW_AT_bit_size, | |
5848 | (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); | |
5849 | } | |
5850 | ||
a3f97cbb JW |
5851 | /* If the compiled language is GNU C, then add a 'prototyped' |
5852 | attribute, if arg types are given for the parameters of a function. */ | |
5853 | inline void | |
5854 | add_prototyped_attribute (die, func_type) | |
5855 | register dw_die_ref die; | |
5856 | register tree func_type; | |
5857 | { | |
5858 | if ((strcmp (language_string, "GNU C") == 0) | |
5859 | && (TYPE_ARG_TYPES (func_type) != NULL)) | |
5860 | { | |
5861 | add_AT_flag (die, DW_AT_prototyped, 0); | |
5862 | } | |
5863 | } | |
5864 | ||
5865 | ||
5866 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found | |
5867 | by looking in either the type declaration or object declaration | |
5868 | equate table. */ | |
5869 | inline void | |
5870 | add_abstract_origin_attribute (die, origin) | |
5871 | register dw_die_ref die; | |
5872 | register tree origin; | |
5873 | { | |
5874 | dw_die_ref origin_die = NULL; | |
5875 | if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd') | |
5876 | { | |
5877 | origin_die = lookup_decl_die (origin); | |
5878 | } | |
5879 | else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't') | |
5880 | { | |
5881 | origin_die = lookup_type_die (origin); | |
5882 | } | |
5883 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); | |
5884 | } | |
5885 | ||
bdb669cb JM |
5886 | /* We do not currently support the pure_virtual attribute. */ |
5887 | ||
a3f97cbb JW |
5888 | inline void |
5889 | add_pure_or_virtual_attribute (die, func_decl) | |
5890 | register dw_die_ref die; | |
5891 | register tree func_decl; | |
5892 | { | |
5893 | if (DECL_VIRTUAL_P (func_decl)) | |
5894 | { | |
bdb669cb | 5895 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
a3f97cbb JW |
5896 | } |
5897 | } | |
5898 | \f | |
5899 | /********************* utility routines for DIEs *************************/ | |
5900 | ||
5901 | /* Add an DW_AT_name attribute and source coordinate attribute for the | |
5902 | given decl, but only if it actually has a name. */ | |
5903 | static void | |
5904 | add_name_and_src_coords_attributes (die, decl) | |
5905 | register dw_die_ref die; | |
5906 | register tree decl; | |
5907 | { | |
d291dd49 | 5908 | register tree decl_name = DECL_ASSEMBLER_NAME (decl); |
a3f97cbb JW |
5909 | register unsigned file_index; |
5910 | if (decl_name && IDENTIFIER_POINTER (decl_name)) | |
5911 | { | |
5912 | add_name_attribute (die, IDENTIFIER_POINTER (decl_name)); | |
5913 | file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
5914 | add_AT_unsigned (die, DW_AT_decl_file, file_index); | |
5915 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
5916 | } | |
5917 | } | |
5918 | ||
5919 | /* Push a new declaration scope. */ | |
5920 | static void | |
5921 | push_decl_scope (scope) | |
5922 | tree scope; | |
5923 | { | |
5924 | /* Make room in the decl_scope_table, if necessary. */ | |
5925 | if (decl_scope_table_allocated == decl_scope_depth) | |
5926 | { | |
5927 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
5928 | decl_scope_table = (tree *) xrealloc (decl_scope_table, | |
5929 | decl_scope_table_allocated * sizeof (tree)); | |
5930 | } | |
5931 | decl_scope_table[decl_scope_depth++] = scope; | |
5932 | } | |
5933 | ||
5934 | /* Return the DIE for the scope the immediately contains this declaration. */ | |
5935 | static dw_die_ref | |
5936 | scope_die_for_type (type, context_die) | |
5937 | register tree type; | |
5938 | register dw_die_ref context_die; | |
5939 | { | |
5940 | register dw_die_ref scope_die = NULL; | |
5941 | register tree containing_scope; | |
5942 | register unsigned long i; | |
5943 | ||
5944 | /* Walk back up the declaration tree looking for a place to define | |
5945 | this type. */ | |
5946 | containing_scope = TYPE_CONTEXT (type); | |
5947 | if (containing_scope == NULL) | |
5948 | { | |
5949 | scope_die = comp_unit_die; | |
5950 | } | |
5951 | else | |
5952 | { | |
5953 | for (i = decl_scope_depth - 1, scope_die = context_die; | |
5954 | i >= 0 | |
5955 | && scope_die != NULL | |
5956 | && decl_scope_table[i] != containing_scope; | |
5957 | --i, scope_die = scope_die->die_parent) | |
5958 | { | |
5959 | /* nothing */ ; | |
5960 | } | |
5961 | if (scope_die == NULL) | |
5962 | { | |
5963 | scope_die = context_die; | |
5964 | } | |
5965 | } | |
5966 | return scope_die; | |
5967 | } | |
5968 | ||
5969 | /* Pop a declaration scope. */ | |
5970 | inline void | |
5971 | pop_decl_scope () | |
5972 | { | |
5973 | assert (decl_scope_depth > 0); | |
5974 | --decl_scope_depth; | |
5975 | } | |
5976 | ||
5977 | /* Many forms of DIEs require a "type description" attribute. This | |
5978 | routine locates the proper "type descriptor" die for the type given | |
5979 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
5980 | static void | |
5981 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
5982 | register dw_die_ref object_die; | |
5983 | register tree type; | |
5984 | register int decl_const; | |
5985 | register int decl_volatile; | |
5986 | register dw_die_ref context_die; | |
5987 | { | |
5988 | register enum tree_code code = TREE_CODE (type); | |
5989 | register dw_die_ref scope_die = NULL; | |
5990 | register dw_die_ref type_die = NULL; | |
5991 | ||
5992 | if (code == ERROR_MARK) | |
5993 | { | |
5994 | return; | |
5995 | } | |
5996 | ||
5997 | /* Handle a special case. For functions whose return type is void, we | |
5998 | generate *no* type attribute. (Note that no object may have type | |
5999 | `void', so this only applies to function return types). */ | |
6000 | if (code == VOID_TYPE) | |
6001 | { | |
6002 | return; | |
6003 | } | |
6004 | ||
6005 | scope_die = scope_die_for_type (type, context_die); | |
6006 | type_die = modified_type_die (type, | |
6007 | decl_const || TYPE_READONLY (type), | |
6008 | decl_volatile || TYPE_VOLATILE (type), | |
6009 | scope_die); | |
6010 | if (type_die != NULL) | |
6011 | { | |
6012 | add_AT_die_ref (object_die, DW_AT_type, type_die); | |
6013 | } | |
6014 | } | |
6015 | ||
6016 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
6017 | a pointer to the (string) tag name for the given type, or zero if the type | |
6018 | was declared without a tag. */ | |
6019 | static char * | |
6020 | type_tag (type) | |
6021 | register tree type; | |
6022 | { | |
6023 | register char *name = 0; | |
6024 | ||
6025 | if (TYPE_NAME (type) != 0) | |
6026 | { | |
6027 | register tree t = 0; | |
6028 | ||
6029 | /* Find the IDENTIFIER_NODE for the type name. */ | |
6030 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
6031 | t = TYPE_NAME (type); | |
bdb669cb | 6032 | |
a3f97cbb JW |
6033 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
6034 | a TYPE_DECL node, regardless of whether or not a `typedef' was | |
bdb669cb | 6035 | involved. */ |
a3f97cbb JW |
6036 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) |
6037 | t = DECL_NAME (TYPE_NAME (type)); | |
bdb669cb | 6038 | |
a3f97cbb JW |
6039 | /* Now get the name as a string, or invent one. */ |
6040 | if (t != 0) | |
6041 | { | |
6042 | name = IDENTIFIER_POINTER (t); | |
6043 | } | |
6044 | } | |
6045 | return (name == 0 || *name == '\0') ? 0 : name; | |
6046 | } | |
6047 | ||
6048 | /* Return the type associated with a data member, make a special check | |
6049 | for bit field types. */ | |
6050 | inline tree | |
6051 | member_declared_type (member) | |
6052 | register tree member; | |
6053 | { | |
6054 | return (DECL_BIT_FIELD_TYPE (member)) | |
6055 | ? DECL_BIT_FIELD_TYPE (member) | |
6056 | : TREE_TYPE (member); | |
6057 | } | |
6058 | ||
d291dd49 | 6059 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb JW |
6060 | from the DECL_NAME name used in the source file. */ |
6061 | static char * | |
d291dd49 | 6062 | decl_start_label (decl) |
a3f97cbb JW |
6063 | register tree decl; |
6064 | { | |
6065 | rtx x; | |
6066 | char *fnname; | |
6067 | x = DECL_RTL (decl); | |
6068 | if (GET_CODE (x) != MEM) | |
6069 | { | |
6070 | abort (); | |
6071 | } | |
6072 | x = XEXP (x, 0); | |
6073 | if (GET_CODE (x) != SYMBOL_REF) | |
6074 | { | |
6075 | abort (); | |
6076 | } | |
6077 | fnname = XSTR (x, 0); | |
6078 | return fnname; | |
6079 | } | |
6080 | \f | |
6081 | /******************************* DIE Generation *************************/ | |
6082 | ||
6083 | /* These routines generate the internnal representation of the DIE's for | |
6084 | the compilation unit. Debugging information is collected by walking | |
6085 | the declaration trees passed in from dwarfout_file_scope_decl(). */ | |
6086 | ||
6087 | static void | |
6088 | gen_array_type_die (type, context_die) | |
6089 | register tree type; | |
6090 | register dw_die_ref context_die; | |
6091 | { | |
6092 | register dw_die_ref scope_die = scope_die_for_type (type, context_die); | |
bdb669cb | 6093 | register dw_die_ref array_die = lookup_type_die (type); |
a3f97cbb | 6094 | register tree element_type; |
bdb669cb JM |
6095 | |
6096 | if (array_die) | |
6097 | return; | |
6098 | ||
6099 | array_die = new_die (DW_TAG_array_type, scope_die); | |
a3f97cbb JW |
6100 | #if 0 |
6101 | /* We default the array ordering. SDB will probably do | |
6102 | the right things even if DW_AT_ordering is not present. It's not even | |
6103 | an issue until we start to get into multidimensional arrays anyway. If | |
6104 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
6105 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
6106 | and when we find out that we need to put these in, we will only do so | |
6107 | for multidimensional arrays. */ | |
6108 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
6109 | #endif | |
6110 | ||
6111 | add_subscript_info (array_die, type); | |
6112 | ||
6113 | equate_type_number_to_die (type, array_die); | |
6114 | ||
6115 | /* Add representation of the type of the elements of this array type. */ | |
6116 | element_type = TREE_TYPE (type); | |
6117 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a | |
6118 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
6119 | We work around this by disabling this feature. See also | |
6120 | add_subscript_info. */ | |
6121 | #ifndef MIPS_DEBUGGING_INFO | |
6122 | while (TREE_CODE (element_type) == ARRAY_TYPE) | |
6123 | { | |
6124 | element_type = TREE_TYPE (element_type); | |
6125 | } | |
6126 | #endif | |
6127 | gen_type_die (element_type, context_die); | |
6128 | ||
6129 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
6130 | } | |
6131 | ||
6132 | static void | |
6133 | gen_set_type_die (type, context_die) | |
6134 | register tree type; | |
6135 | register dw_die_ref context_die; | |
6136 | { | |
bdb669cb JM |
6137 | register dw_die_ref type_die = lookup_type_die (type); |
6138 | if (type_die) | |
6139 | return; | |
a3f97cbb JW |
6140 | type_die = new_die (DW_TAG_set_type, scope_die_for_type (type, context_die)); |
6141 | equate_type_number_to_die (type, type_die); | |
a3f97cbb JW |
6142 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
6143 | } | |
6144 | ||
6145 | static void | |
6146 | gen_entry_point_die (decl, context_die) | |
6147 | register tree decl; | |
6148 | register dw_die_ref context_die; | |
6149 | { | |
6150 | register tree origin = decl_ultimate_origin (decl); | |
6151 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
6152 | if (origin != NULL) | |
6153 | { | |
6154 | add_abstract_origin_attribute (decl_die, origin); | |
6155 | } | |
6156 | else | |
6157 | { | |
6158 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
6159 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
6160 | 0, 0, context_die); | |
6161 | } | |
6162 | if (DECL_ABSTRACT (decl)) | |
6163 | { | |
6164 | equate_decl_number_to_die (decl, decl_die); | |
6165 | } | |
6166 | else | |
6167 | { | |
d291dd49 | 6168 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb JW |
6169 | } |
6170 | } | |
6171 | ||
6172 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ | |
6173 | static void | |
6174 | gen_inlined_enumeration_type_die (type, context_die) | |
6175 | register tree type; | |
6176 | register dw_die_ref context_die; | |
6177 | { | |
6178 | register dw_die_ref type_die; | |
6179 | type_die = new_die (DW_TAG_enumeration_type, | |
6180 | scope_die_for_type (type, context_die)); | |
6181 | assert (TREE_ASM_WRITTEN (type)); | |
6182 | add_abstract_origin_attribute (type_die, type); | |
6183 | } | |
6184 | ||
6185 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
6186 | static void | |
6187 | gen_inlined_structure_type_die (type, context_die) | |
6188 | register tree type; | |
6189 | register dw_die_ref context_die; | |
6190 | { | |
6191 | register dw_die_ref type_die; | |
6192 | type_die = new_die (DW_TAG_structure_type, | |
6193 | scope_die_for_type (type, context_die)); | |
6194 | assert (TREE_ASM_WRITTEN (type)); | |
6195 | add_abstract_origin_attribute (type_die, type); | |
6196 | } | |
6197 | ||
6198 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
6199 | static void | |
6200 | gen_inlined_union_type_die (type, context_die) | |
6201 | register tree type; | |
6202 | register dw_die_ref context_die; | |
6203 | { | |
6204 | register dw_die_ref type_die; | |
6205 | type_die = new_die (DW_TAG_union_type, | |
6206 | scope_die_for_type (type, context_die)); | |
6207 | assert (TREE_ASM_WRITTEN (type)); | |
6208 | add_abstract_origin_attribute (type_die, type); | |
6209 | } | |
6210 | ||
6211 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
6212 | include all of the information about the enumeration values also. Each | |
6213 | enumerated type name/value is listed as a child of the enumerated type DIE */ | |
6214 | static void | |
6215 | gen_enumeration_type_die (type, is_complete, context_die) | |
6216 | register tree type; | |
6217 | register unsigned is_complete; | |
6218 | register dw_die_ref context_die; | |
6219 | { | |
6220 | register dw_die_ref type_die; | |
6221 | register dw_die_ref enum_die; | |
6222 | register tree link; | |
6223 | type_die = lookup_type_die (type); | |
6224 | if (type_die == NULL) | |
6225 | { | |
6226 | type_die = new_die (DW_TAG_enumeration_type, | |
6227 | scope_die_for_type (type, context_die)); | |
6228 | equate_type_number_to_die (type, type_die); | |
6229 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb JW |
6230 | } |
6231 | if (is_complete) | |
6232 | { | |
6233 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
6234 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
6235 | attribute or the DW_AT_element_list attribute. */ | |
6236 | if (TYPE_SIZE (type)) | |
6237 | { | |
6238 | add_byte_size_attribute (type_die, type); | |
6239 | for (link = TYPE_FIELDS (type); | |
6240 | link != NULL; link = TREE_CHAIN (link)) | |
6241 | { | |
6242 | enum_die = new_die (DW_TAG_enumerator, type_die); | |
6243 | add_name_attribute (enum_die, | |
6244 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
6245 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
6246 | (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); | |
6247 | } | |
6248 | } | |
6249 | } | |
6250 | } | |
6251 | ||
6252 | ||
6253 | /* Generate a DIE to represent either a real live formal parameter decl or to | |
6254 | represent just the type of some formal parameter position in some function | |
6255 | type. | |
6256 | Note that this routine is a bit unusual because its argument may be a | |
6257 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
6258 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
6259 | node. If it's the former then this function is being called to output a | |
6260 | DIE to represent a formal parameter object (or some inlining thereof). If | |
6261 | it's the latter, then this function is only being called to output a | |
6262 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
6263 | argument type of some subprogram type. */ | |
6264 | static void | |
6265 | gen_formal_parameter_die (node, context_die) | |
6266 | register tree node; | |
6267 | register dw_die_ref context_die; | |
6268 | { | |
6269 | register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter, | |
6270 | context_die); | |
6271 | register tree origin; | |
6272 | switch (TREE_CODE_CLASS (TREE_CODE (node))) | |
6273 | { | |
6274 | /* We were called with some kind of a ..._DECL node. */ | |
6275 | case 'd': | |
6276 | origin = decl_ultimate_origin (node); | |
6277 | if (origin != NULL) | |
6278 | { | |
6279 | add_abstract_origin_attribute (parm_die, origin); | |
6280 | } | |
6281 | else | |
6282 | { | |
6283 | add_name_and_src_coords_attributes (parm_die, node); | |
6284 | add_type_attribute (parm_die, TREE_TYPE (node), | |
6285 | TREE_READONLY (node), | |
6286 | TREE_THIS_VOLATILE (node), | |
6287 | context_die); | |
bdb669cb JM |
6288 | if (DECL_ARTIFICIAL (node)) |
6289 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
6290 | } |
6291 | if (DECL_ABSTRACT (node)) | |
6292 | { | |
6293 | equate_decl_number_to_die (node, parm_die); | |
6294 | } | |
6295 | else | |
6296 | { | |
6297 | add_location_or_const_value_attribute (parm_die, node); | |
6298 | } | |
6299 | break; | |
6300 | ||
6301 | /* We were called with some kind of a ..._TYPE node. */ | |
6302 | case 't': | |
6303 | add_type_attribute (parm_die, node, 0, 0, context_die); | |
6304 | break; | |
6305 | ||
6306 | /* Should never happen. */ | |
6307 | default: | |
6308 | abort (); | |
6309 | } | |
6310 | } | |
6311 | ||
6312 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
6313 | at the end of an (ANSI prototyped) formal parameters list. */ | |
6314 | static void | |
6315 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
6316 | register tree decl_or_type; | |
6317 | register dw_die_ref context_die; | |
6318 | { | |
6319 | register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters, | |
6320 | context_die); | |
6321 | /* This kludge is here only for the sake of being compatible with what the | |
6322 | USL CI5 C compiler does. The specification of Dwarf Version 1 doesn't | |
6323 | say that DW_TAG_unspecified_parameters DIEs should contain any | |
6324 | attributes other than the DW_AT_sibling attribute, but they are | |
6325 | certainly allowed to contain additional attributes, and the CI5 compiler | |
6326 | generates DW_AT_name, DW_AT_base_type, and DW_AT_location attributes | |
6327 | within DW_TAG_unspecified_parameters DIEs which appear in the child | |
6328 | lists for DIEs representing function definitions, so we do likewise | |
6329 | here. */ | |
6330 | if (TREE_CODE (decl_or_type) == FUNCTION_DECL | |
6331 | && DECL_INITIAL (decl_or_type)) | |
6332 | { | |
6333 | add_name_attribute (parm_die, "..."); | |
6334 | add_AT_die_ref (parm_die, DW_AT_type, int_base_type_die); | |
6335 | } | |
6336 | } | |
6337 | ||
6338 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
6339 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
6340 | parameters as specified in some function type specification (except for | |
6341 | those which appear as part of a function *definition*). | |
6342 | Note that we must be careful here to output all of the parameter DIEs before* | |
6343 | we output any DIEs needed to represent the types of the formal parameters. | |
6344 | This keeps svr4 SDB happy because it (incorrectly) thinks that the first | |
6345 | non-parameter DIE it sees ends the formal parameter list. */ | |
6346 | static void | |
6347 | gen_formal_types_die (function_or_method_type, context_die) | |
6348 | register tree function_or_method_type; | |
6349 | register dw_die_ref context_die; | |
6350 | { | |
6351 | register tree link; | |
6352 | register tree formal_type = NULL; | |
6353 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
6354 | ||
bdb669cb | 6355 | #if 0 |
a3f97cbb JW |
6356 | /* In the case where we are generating a formal types list for a C++ |
6357 | non-static member function type, skip over the first thing on the | |
6358 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
6359 | `this pointer'. The debugger should be able to figure out (without | |
6360 | being explicitly told) that this non-static member function type takes a | |
6361 | `this pointer' and should be able to figure what the type of that hidden | |
6362 | parameter is from the DW_AT_member attribute of the parent | |
6363 | DW_TAG_subroutine_type DIE. */ | |
6364 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
6365 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 6366 | #endif |
a3f97cbb JW |
6367 | |
6368 | /* Make our first pass over the list of formal parameter types and output a | |
6369 | DW_TAG_formal_parameter DIE for each one. */ | |
6370 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
6371 | { | |
6372 | formal_type = TREE_VALUE (link); | |
6373 | if (formal_type == void_type_node) | |
6374 | break; | |
6375 | ||
6376 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
6377 | gen_formal_parameter_die (formal_type, context_die); | |
6378 | } | |
6379 | ||
6380 | /* If this function type has an ellipsis, add a | |
6381 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
6382 | if (formal_type != void_type_node) | |
6383 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
6384 | ||
6385 | /* Make our second (and final) pass over the list of formal parameter types | |
6386 | and output DIEs to represent those types (as necessary). */ | |
6387 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
6388 | link; | |
6389 | link = TREE_CHAIN (link)) | |
6390 | { | |
6391 | formal_type = TREE_VALUE (link); | |
6392 | if (formal_type == void_type_node) | |
6393 | break; | |
6394 | ||
b50c02f9 | 6395 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
6396 | } |
6397 | } | |
6398 | ||
6399 | /* Generate a DIE to represent a declared function (either file-scope or | |
6400 | block-local). */ | |
6401 | static void | |
6402 | gen_subprogram_die (decl, context_die) | |
6403 | register tree decl; | |
6404 | register dw_die_ref context_die; | |
6405 | { | |
6406 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6407 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 6408 | register dw_die_ref subr_die; |
a3f97cbb JW |
6409 | register dw_loc_descr_ref fp_loc = NULL; |
6410 | register unsigned fp_reg; | |
6411 | register tree type; | |
6412 | register tree fn_arg_types; | |
6413 | register tree outer_scope; | |
6414 | register tree label; | |
bdb669cb | 6415 | dw_die_ref old_die = lookup_decl_die (decl); |
a3f97cbb | 6416 | |
a3f97cbb JW |
6417 | if (origin != NULL) |
6418 | { | |
4b674448 | 6419 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
6420 | add_abstract_origin_attribute (subr_die, origin); |
6421 | } | |
bdb669cb JM |
6422 | else if (old_die) |
6423 | { | |
4b674448 JM |
6424 | register unsigned file_index |
6425 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
bdb669cb JM |
6426 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) |
6427 | abort (); | |
4b674448 JM |
6428 | |
6429 | /* If the definition comes from the same place as the declaration, | |
6430 | use the old DIE. */ | |
6431 | if (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
6432 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
6433 | == DECL_SOURCE_LINE (decl))) | |
bdb669cb | 6434 | { |
4b674448 JM |
6435 | subr_die = old_die; |
6436 | ||
6437 | /* Clear out the declaration attribute and the parm types. */ | |
6438 | remove_AT (subr_die, DW_AT_declaration); | |
6439 | remove_children (subr_die); | |
6440 | } | |
6441 | else | |
6442 | { | |
6443 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
6444 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
6445 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
6446 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
6447 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
6448 | != DECL_SOURCE_LINE (decl)) | |
6449 | add_AT_unsigned | |
6450 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
6451 | } | |
6452 | } | |
a3f97cbb JW |
6453 | else |
6454 | { | |
4b674448 | 6455 | subr_die = new_die (DW_TAG_subprogram, context_die); |
ba7b35df JW |
6456 | if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) |
6457 | { | |
6458 | add_AT_flag (subr_die, DW_AT_external, 1); | |
6459 | } | |
a3f97cbb JW |
6460 | add_name_and_src_coords_attributes (subr_die, decl); |
6461 | if (DECL_INLINE (decl)) | |
6462 | { | |
6463 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); | |
6464 | } | |
ba7b35df | 6465 | type = TREE_TYPE (decl); |
a3f97cbb | 6466 | add_prototyped_attribute (subr_die, type); |
a3f97cbb JW |
6467 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); |
6468 | add_pure_or_virtual_attribute (subr_die, decl); | |
bdb669cb JM |
6469 | |
6470 | /* The first time we see a member function, it is in the context of | |
6471 | the class to which it belongs. We make sure of this by emitting | |
6472 | the class first. The next time is the definition, which is | |
6473 | handled above. The two may come from the same source text. */ | |
6474 | if (! DECL_INITIAL (decl)) | |
6475 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
a3f97cbb | 6476 | } |
bdb669cb | 6477 | if (DECL_ABSTRACT (decl) || ! DECL_INITIAL (decl)) |
a3f97cbb JW |
6478 | { |
6479 | equate_decl_number_to_die (decl, subr_die); | |
6480 | } | |
6481 | else if (!DECL_EXTERNAL (decl)) | |
6482 | { | |
ba7b35df JW |
6483 | if (origin == NULL) |
6484 | equate_decl_number_to_die (decl, subr_die); | |
d291dd49 JM |
6485 | if (DECL_WEAK (current_function_decl) |
6486 | || DECL_ONE_ONLY (current_function_decl)) | |
6487 | { | |
6488 | sprintf (label_id, FUNC_BEGIN_LABEL_FMT, current_funcdef_number); | |
6489 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); | |
6490 | } | |
6491 | else | |
6492 | add_AT_lbl_id (subr_die, DW_AT_low_pc, decl_start_label (decl)); | |
a3f97cbb JW |
6493 | sprintf (label_id, FUNC_END_LABEL_FMT, current_funcdef_number); |
6494 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); | |
6495 | ||
d291dd49 JM |
6496 | add_pubname (decl, subr_die); |
6497 | add_arange (decl, subr_die); | |
6498 | ||
a3f97cbb JW |
6499 | #ifdef MIPS_DEBUGGING_INFO |
6500 | ||
6501 | /* Add a reference to the FDE for this routine. */ | |
6502 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
6503 | #endif | |
6504 | ||
6505 | /* Define the frame pointer location for this routine. */ | |
6506 | fp_reg = (frame_pointer_needed) ? FRAME_POINTER_REGNUM | |
6507 | : STACK_POINTER_REGNUM; | |
6508 | assert (fp_reg >= 0 && fp_reg <= 31); | |
6509 | fp_loc = new_loc_descr (DW_OP_breg0 + fp_reg, current_funcdef_frame_size); | |
6510 | add_AT_loc (subr_die, DW_AT_frame_base, fp_loc); | |
6511 | ||
6512 | #ifdef DWARF_GNU_EXTENSIONS | |
6513 | sprintf (label_id, BODY_BEGIN_LABEL_FMT, current_funcdef_number); | |
6514 | add_AT_lbl_id (subr_die, DW_AT_body_begin, label_id); | |
6515 | sprintf (label_id, BODY_END_LABEL_FMT, current_funcdef_number); | |
6516 | add_AT_lbl_id (subr_die, DW_AT_body_end, label_id); | |
6517 | #endif | |
6518 | ||
6519 | } | |
6520 | ||
6521 | /* Now output descriptions of the arguments for this function. This gets | |
6522 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list | |
6523 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing | |
6524 | `...' at the end of the formal parameter list. In order to find out if | |
6525 | there was a trailing ellipsis or not, we must instead look at the type | |
6526 | associated with the FUNCTION_DECL. This will be a node of type | |
6527 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
6528 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be | |
6529 | an ellipsis at the end. */ | |
6530 | ||
6531 | /* In the case where we are describing a mere function declaration, all we | |
6532 | need to do here (and all we *can* do here) is to describe the *types* of | |
6533 | its formal parameters. */ | |
6534 | if (DECL_INITIAL (decl) == NULL_TREE) | |
6535 | { | |
6536 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
6537 | } | |
6538 | else | |
6539 | { | |
6540 | /* Generate DIEs to represent all known formal parameters */ | |
6541 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
6542 | register tree parm; | |
6543 | ||
6544 | /* When generating DIEs, generate the unspecified_parameters DIE | |
6545 | instead if we come across the arg "__builtin_va_alist" */ | |
6546 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
6547 | { | |
6548 | if (TREE_CODE (parm) == PARM_DECL) | |
6549 | { | |
6550 | if (DECL_NAME (parm) && | |
6551 | !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
6552 | "__builtin_va_alist")) | |
6553 | { | |
6554 | gen_unspecified_parameters_die (parm, subr_die); | |
6555 | } | |
6556 | else | |
6557 | { | |
6558 | gen_decl_die (parm, subr_die); | |
6559 | } | |
6560 | } | |
6561 | } | |
6562 | ||
6563 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
6564 | There are 2 more cases to do this for: 1) the ansi ... declaration - | |
6565 | this is detectable when the end of the arg list is not a | |
6566 | void_type_node 2) an unprototyped function declaration (not a | |
6567 | definition). This just means that we have no info about the | |
6568 | parameters at all. */ | |
6569 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
6570 | if (fn_arg_types) | |
6571 | { | |
6572 | /* this is the prototyped case, check for ... */ | |
6573 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
6574 | { | |
6575 | gen_unspecified_parameters_die (decl, subr_die); | |
6576 | } | |
6577 | } | |
6578 | else | |
6579 | { | |
6580 | /* this is unprotoyped, check for undefined (just declaration) */ | |
6581 | if (!DECL_INITIAL (decl)) | |
6582 | { | |
6583 | gen_unspecified_parameters_die (decl, subr_die); | |
6584 | } | |
6585 | } | |
6586 | } | |
6587 | ||
6588 | /* Output Dwarf info for all of the stuff within the body of the function | |
6589 | (if it has one - it may be just a declaration). */ | |
6590 | outer_scope = DECL_INITIAL (decl); | |
6591 | ||
d7248bff JM |
6592 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
6593 | node created to represent a function. This outermost BLOCK actually | |
6594 | represents the outermost binding contour for the function, i.e. the | |
6595 | contour in which the function's formal parameters and labels get | |
6596 | declared. Curiously, it appears that the front end doesn't actually | |
6597 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
6598 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
6599 | list for the function instead.) The BLOCK_VARS list for the | |
6600 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
6601 | the function however, and we output DWARF info for those in | |
6602 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
6603 | node representing the function's outermost pair of curly braces, and | |
6604 | any blocks used for the base and member initializers of a C++ | |
6605 | constructor function. */ | |
a3f97cbb | 6606 | if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) |
d7248bff | 6607 | decls_for_scope (outer_scope, subr_die, 0); |
a3f97cbb JW |
6608 | } |
6609 | ||
6610 | /* Generate a DIE to represent a declared data object. */ | |
6611 | static void | |
6612 | gen_variable_die (decl, context_die) | |
6613 | register tree decl; | |
6614 | register dw_die_ref context_die; | |
6615 | { | |
6616 | register tree origin = decl_ultimate_origin (decl); | |
6617 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
bdb669cb JM |
6618 | dw_die_ref old_die = lookup_decl_die (decl); |
6619 | ||
a3f97cbb JW |
6620 | if (origin != NULL) |
6621 | { | |
6622 | add_abstract_origin_attribute (var_die, origin); | |
6623 | } | |
bdb669cb JM |
6624 | else if (old_die) |
6625 | { | |
6626 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) | |
6627 | abort (); | |
6628 | add_AT_die_ref (var_die, DW_AT_specification, old_die); | |
6629 | if (DECL_NAME (decl)) | |
6630 | { | |
6631 | register unsigned file_index | |
6632 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
6633 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) | |
6634 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
6635 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
6636 | != DECL_SOURCE_LINE (decl)) | |
6637 | add_AT_unsigned | |
6638 | (var_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
6639 | } | |
6640 | } | |
a3f97cbb JW |
6641 | else |
6642 | { | |
6643 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
6644 | add_type_attribute (var_die, TREE_TYPE (decl), |
6645 | TREE_READONLY (decl), | |
6646 | TREE_THIS_VOLATILE (decl), context_die); | |
bdb669cb JM |
6647 | if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) |
6648 | { | |
6649 | add_AT_flag (var_die, DW_AT_external, 1); | |
6650 | } | |
a3f97cbb JW |
6651 | } |
6652 | if (DECL_ABSTRACT (decl)) | |
6653 | { | |
6654 | equate_decl_number_to_die (decl, var_die); | |
6655 | } | |
6656 | else if (!DECL_EXTERNAL (decl)) | |
6657 | { | |
bdb669cb | 6658 | equate_decl_number_to_die (decl, var_die); |
a3f97cbb | 6659 | add_location_or_const_value_attribute (var_die, decl); |
d291dd49 | 6660 | add_pubname (decl, var_die); |
a3f97cbb | 6661 | } |
bdb669cb JM |
6662 | else if (decl_class_context (decl)) |
6663 | { | |
6664 | equate_decl_number_to_die (decl, var_die); | |
6665 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
6666 | } | |
a3f97cbb JW |
6667 | } |
6668 | ||
6669 | /* Generate a DIE to represent a label identifier. */ | |
6670 | static void | |
6671 | gen_label_die (decl, context_die) | |
6672 | register tree decl; | |
6673 | register dw_die_ref context_die; | |
6674 | { | |
6675 | register tree origin = decl_ultimate_origin (decl); | |
6676 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
6677 | register rtx insn; | |
6678 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6679 | if (origin != NULL) | |
6680 | { | |
6681 | add_abstract_origin_attribute (lbl_die, origin); | |
6682 | } | |
6683 | else | |
6684 | { | |
6685 | add_name_and_src_coords_attributes (lbl_die, decl); | |
6686 | } | |
6687 | if (DECL_ABSTRACT (decl)) | |
6688 | { | |
6689 | equate_decl_number_to_die (decl, lbl_die); | |
6690 | } | |
6691 | else | |
6692 | { | |
6693 | insn = DECL_RTL (decl); | |
6694 | if (GET_CODE (insn) == CODE_LABEL) | |
6695 | { | |
6696 | /* When optimization is enabled (via -O) some parts of the compiler | |
6697 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
6698 | represent source-level labels which were explicitly declared by | |
6699 | the user. This really shouldn't be happening though, so catch | |
6700 | it if it ever does happen. */ | |
6701 | if (INSN_DELETED_P (insn)) | |
6702 | { | |
6703 | abort (); /* Should never happen. */ | |
6704 | } | |
6705 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number, | |
6706 | (unsigned) INSN_UID (insn)); | |
6707 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); | |
6708 | } | |
6709 | } | |
6710 | } | |
6711 | ||
6712 | /* Generate a DIE for a lexical block. */ | |
6713 | static void | |
d7248bff | 6714 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
6715 | register tree stmt; |
6716 | register dw_die_ref context_die; | |
d7248bff | 6717 | int depth; |
a3f97cbb JW |
6718 | { |
6719 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
6720 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6721 | if (!BLOCK_ABSTRACT (stmt)) | |
6722 | { | |
6723 | sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number); | |
6724 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
6725 | sprintf (label, BLOCK_END_LABEL_FMT, next_block_number); | |
6726 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
6727 | } | |
d7248bff | 6728 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
6729 | } |
6730 | ||
6731 | /* Generate a DIE for an inlined subprogram. */ | |
6732 | static void | |
d7248bff | 6733 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
6734 | register tree stmt; |
6735 | register dw_die_ref context_die; | |
d7248bff | 6736 | int depth; |
a3f97cbb | 6737 | { |
a3f97cbb JW |
6738 | if (!BLOCK_ABSTRACT (stmt)) |
6739 | { | |
d7248bff JM |
6740 | register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, |
6741 | context_die); | |
6742 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6743 | add_abstract_origin_attribute (subr_die, block_ultimate_origin (stmt)); | |
a3f97cbb JW |
6744 | sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number); |
6745 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); | |
6746 | sprintf (label, BLOCK_END_LABEL_FMT, next_block_number); | |
6747 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); | |
d7248bff | 6748 | decls_for_scope (stmt, subr_die, depth); |
a3f97cbb | 6749 | } |
a3f97cbb JW |
6750 | } |
6751 | ||
6752 | /* Generate a DIE for a field in a record, or structure. */ | |
6753 | static void | |
6754 | gen_field_die (decl, context_die) | |
6755 | register tree decl; | |
6756 | register dw_die_ref context_die; | |
6757 | { | |
6758 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
6759 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
6760 | add_type_attribute (decl_die, member_declared_type (decl), |
6761 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
6762 | context_die); | |
6763 | /* If this is a bit field... */ | |
6764 | if (DECL_BIT_FIELD_TYPE (decl)) | |
6765 | { | |
6766 | add_byte_size_attribute (decl_die, decl); | |
6767 | add_bit_size_attribute (decl_die, decl); | |
6768 | add_bit_offset_attribute (decl_die, decl); | |
6769 | } | |
6770 | add_data_member_location_attribute (decl_die, decl); | |
6771 | } | |
6772 | ||
6773 | /* Don't generate either pointer_type DIEs or reference_type DIEs. | |
6774 | Use modified type DIE's instead. | |
6775 | We keep this code here just in case these types of DIEs may be needed to | |
6776 | represent certain things in other languages (e.g. Pascal) someday. */ | |
6777 | static void | |
6778 | gen_pointer_type_die (type, context_die) | |
6779 | register tree type; | |
6780 | register dw_die_ref context_die; | |
6781 | { | |
bdb669cb JM |
6782 | register dw_die_ref ptr_die = lookup_type_die (type); |
6783 | if (ptr_die) | |
6784 | return; | |
6785 | ptr_die = new_die (DW_TAG_pointer_type, context_die); | |
a3f97cbb | 6786 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb JW |
6787 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
6788 | } | |
6789 | ||
6790 | /* Don't generate either pointer_type DIEs or reference_type DIEs. | |
6791 | Use modified type DIE's instead. | |
6792 | We keep this code here just in case these types of DIEs may be needed to | |
6793 | represent certain things in other languages (e.g. Pascal) someday. */ | |
6794 | static void | |
6795 | gen_reference_type_die (type, context_die) | |
6796 | register tree type; | |
6797 | register dw_die_ref context_die; | |
6798 | { | |
bdb669cb JM |
6799 | register dw_die_ref ref_die = lookup_type_die (type); |
6800 | if (ref_die) | |
6801 | return; | |
6802 | ref_die = new_die (DW_TAG_reference_type, context_die); | |
a3f97cbb | 6803 | equate_type_number_to_die (type, ref_die); |
a3f97cbb JW |
6804 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
6805 | } | |
6806 | ||
6807 | /* Generate a DIE for a pointer to a member type. */ | |
6808 | static void | |
6809 | gen_ptr_to_mbr_type_die (type, context_die) | |
6810 | register tree type; | |
6811 | register dw_die_ref context_die; | |
6812 | { | |
bdb669cb JM |
6813 | register dw_die_ref ptr_die = lookup_type_die (type); |
6814 | if (ptr_die) | |
6815 | return; | |
6816 | ptr_die = new_die (DW_TAG_ptr_to_member_type, context_die); | |
a3f97cbb | 6817 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 6818 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 6819 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
6820 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
6821 | } | |
6822 | ||
6823 | /* Generate the DIE for the compilation unit. */ | |
6824 | static void | |
6825 | gen_compile_unit_die (main_input_filename) | |
6826 | register char *main_input_filename; | |
6827 | { | |
6828 | char producer[250]; | |
a3f97cbb JW |
6829 | char *wd = getpwd (); |
6830 | ||
6831 | comp_unit_die = new_die (DW_TAG_compile_unit, NULL); | |
6832 | ||
bdb669cb JM |
6833 | add_name_attribute (comp_unit_die, main_input_filename); |
6834 | ||
6835 | if (wd) | |
a3f97cbb | 6836 | { |
bdb669cb | 6837 | add_AT_string (comp_unit_die, DW_AT_comp_dir, wd); |
a3f97cbb JW |
6838 | } |
6839 | ||
6840 | sprintf (producer, "%s %s", language_string, version_string); | |
6841 | ||
6842 | #ifdef MIPS_DEBUGGING_INFO | |
6843 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
6844 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
6845 | not appear in the producer string, the debugger reaches the conclusion | |
6846 | that the object file is stripped and has no debugging information. | |
6847 | To get the MIPS/SGI debugger to believe that there is debugging | |
6848 | information in the object file, we add a -g to the producer string. */ | |
6849 | if (write_symbols != NO_DEBUG) | |
6850 | { | |
bdb669cb | 6851 | strcat (producer, " -g"); |
a3f97cbb JW |
6852 | } |
6853 | ||
6854 | #endif | |
6855 | ||
6856 | add_AT_string (comp_unit_die, DW_AT_producer, producer); | |
6857 | if (strcmp (language_string, "GNU C++") == 0) | |
6858 | { | |
6859 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus); | |
6860 | } | |
6861 | else if (strcmp (language_string, "GNU Ada") == 0) | |
6862 | { | |
6863 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83); | |
6864 | } | |
6865 | else if (flag_traditional) | |
6866 | { | |
6867 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C); | |
6868 | } | |
6869 | else | |
6870 | { | |
6871 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89); | |
6872 | } | |
e90b62db | 6873 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
a3f97cbb | 6874 | { |
e90b62db | 6875 | add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0); |
a3f97cbb JW |
6876 | } |
6877 | } | |
6878 | ||
6879 | /* Generate a DIE for a string type. */ | |
6880 | static void | |
6881 | gen_string_type_die (type, context_die) | |
6882 | register tree type; | |
6883 | register dw_die_ref context_die; | |
6884 | { | |
bdb669cb JM |
6885 | register dw_die_ref type_die = lookup_type_die (type); |
6886 | if (type_die) | |
6887 | return; | |
a3f97cbb JW |
6888 | type_die = new_die (DW_TAG_string_type, |
6889 | scope_die_for_type (type, context_die)); | |
bdb669cb | 6890 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
6891 | |
6892 | /* Fudge the string length attribute for now. */ | |
6893 | ||
6894 | /* TODO: add string length info. | |
6895 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
6896 | bound_representation (upper_bound, 0, 'u'); */ | |
6897 | } | |
6898 | ||
6899 | /* Genearate a DIE for a class member. */ | |
6900 | static void | |
6901 | gen_member_die (type, context_die) | |
6902 | register tree type; | |
6903 | register dw_die_ref context_die; | |
6904 | { | |
6905 | register tree normal_member; | |
a3f97cbb JW |
6906 | register tree first_func_member; |
6907 | register tree func_member; | |
6908 | /* If this is not an incomplete type, output descriptions of each of its | |
6909 | members. Note that as we output the DIEs necessary to represent the | |
6910 | members of this record or union type, we will also be trying to output | |
6911 | DIEs to represent the *types* of those members. However the `type' | |
6912 | function (above) will specifically avoid generating type DIEs for member | |
6913 | types *within* the list of member DIEs for this (containing) type execpt | |
6914 | for those types (of members) which are explicitly marked as also being | |
6915 | members of this (containing) type themselves. The g++ front- end can | |
6916 | force any given type to be treated as a member of some other | |
6917 | (containing) type by setting the TYPE_CONTEXT of the given (member) type | |
6918 | to point to the TREE node representing the appropriate (containing) | |
6919 | type. */ | |
6920 | ||
6921 | /* First output info about the data members and type members. */ | |
6922 | for (normal_member = TYPE_FIELDS (type); | |
6923 | normal_member; | |
6924 | normal_member = TREE_CHAIN (normal_member)) | |
6925 | { | |
6926 | gen_decl_die (normal_member, context_die); | |
6927 | } | |
6928 | ||
6929 | /* Now output info about the function members (if any). */ | |
bdb669cb JM |
6930 | for (func_member = TYPE_METHODS (type); |
6931 | func_member; | |
6932 | func_member = TREE_CHAIN (func_member)) | |
a3f97cbb | 6933 | { |
bdb669cb | 6934 | gen_decl_die (func_member, context_die); |
a3f97cbb JW |
6935 | } |
6936 | } | |
6937 | ||
6938 | /* Generate a DIE for a structure or union type. */ | |
6939 | static void | |
6940 | gen_struct_or_union_type_die (type, is_complete, context_die) | |
6941 | register tree type; | |
6942 | register unsigned is_complete; | |
6943 | register dw_die_ref context_die; | |
6944 | { | |
6945 | register dw_die_ref type_die; | |
6946 | type_die = lookup_type_die (type); | |
6947 | if (type_die == NULL) | |
6948 | { | |
6949 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE | |
6950 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
6951 | scope_die_for_type (type, context_die)); | |
6952 | equate_type_number_to_die (type, type_die); | |
6953 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 6954 | } |
4b674448 JM |
6955 | else if (is_complete) |
6956 | remove_AT (type_die, DW_AT_declaration); | |
6957 | else | |
6958 | return; | |
a3f97cbb JW |
6959 | |
6960 | /* If this type has been completed, then give it a byte_size attribute and | |
6961 | then give a list of members. */ | |
6962 | if (is_complete) | |
6963 | { | |
6964 | /* Prevent infinite recursion in cases where the type of some member of | |
6965 | this type is expressed in terms of this type itself. */ | |
6966 | TREE_ASM_WRITTEN (type) = 1; | |
6967 | if (TYPE_SIZE (type)) | |
6968 | { | |
6969 | add_byte_size_attribute (type_die, type); | |
6970 | gen_member_die (type, type_die); | |
6971 | } | |
6972 | } | |
4b674448 JM |
6973 | else |
6974 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
6975 | } |
6976 | ||
6977 | /* Generate a DIE for a subroutine _type_. */ | |
6978 | static void | |
6979 | gen_subroutine_type_die (type, context_die) | |
6980 | register tree type; | |
6981 | register dw_die_ref context_die; | |
6982 | { | |
6983 | register tree return_type = TREE_TYPE (type); | |
bdb669cb JM |
6984 | register dw_die_ref subr_die = lookup_type_die (type); |
6985 | if (subr_die) | |
6986 | return; | |
6987 | subr_die = new_die (DW_TAG_subroutine_type, context_die); | |
a3f97cbb JW |
6988 | equate_type_number_to_die (type, subr_die); |
6989 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb JW |
6990 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
6991 | gen_formal_types_die (type, context_die); | |
6992 | } | |
6993 | ||
6994 | /* Generate a DIE for a type definition */ | |
6995 | static void | |
6996 | gen_typedef_die (decl, context_die) | |
6997 | register tree decl; | |
6998 | register dw_die_ref context_die; | |
6999 | { | |
7000 | register tree origin = decl_ultimate_origin (decl); | |
7001 | register dw_die_ref type_die; | |
7002 | type_die = new_die (DW_TAG_typedef, | |
7003 | scope_die_for_type (decl, context_die)); | |
7004 | if (origin != NULL) | |
7005 | { | |
7006 | add_abstract_origin_attribute (type_die, origin); | |
7007 | } | |
7008 | else | |
7009 | { | |
7010 | add_name_and_src_coords_attributes (type_die, decl); | |
a3f97cbb JW |
7011 | add_type_attribute (type_die, TREE_TYPE (decl), |
7012 | TREE_READONLY (decl), | |
7013 | TREE_THIS_VOLATILE (decl), | |
7014 | context_die); | |
7015 | } | |
7016 | if (DECL_ABSTRACT (decl)) | |
7017 | { | |
7018 | equate_decl_number_to_die (decl, type_die); | |
7019 | } | |
7020 | } | |
7021 | ||
7022 | /* Generate a type description DIE. */ | |
7023 | static void | |
7024 | gen_type_die (type, context_die) | |
7025 | register tree type; | |
7026 | register dw_die_ref context_die; | |
7027 | { | |
7028 | register unsigned is_complete; | |
7029 | if (type == 0 || type == error_mark_node) | |
7030 | { | |
7031 | return; | |
7032 | } | |
7033 | ||
7034 | /* We are going to output a DIE to represent the unqualified version of of | |
7035 | this type (i.e. without any const or volatile qualifiers) so get the | |
7036 | main variant (i.e. the unqualified version) of this type now. */ | |
7037 | type = type_main_variant (type); | |
7038 | ||
7039 | if (TREE_ASM_WRITTEN (type)) | |
7040 | { | |
7041 | return; | |
7042 | } | |
7043 | ||
7044 | switch (TREE_CODE (type)) | |
7045 | { | |
7046 | case ERROR_MARK: | |
7047 | break; | |
7048 | ||
7049 | case POINTER_TYPE: | |
7050 | case REFERENCE_TYPE: | |
7051 | /* For these types, all that is required is that we output a DIE (or a | |
7052 | set of DIEs) to represent the "basis" type. */ | |
7053 | gen_type_die (TREE_TYPE (type), context_die); | |
7054 | break; | |
7055 | ||
7056 | case OFFSET_TYPE: | |
7057 | /* This code is used for C++ pointer-to-data-member types. */ | |
7058 | /* Output a description of the relevant class type. */ | |
7059 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); | |
7060 | /* Output a description of the type of the object pointed to. */ | |
7061 | gen_type_die (TREE_TYPE (type), context_die); | |
7062 | /* Now output a DIE to represent this pointer-to-data-member type | |
7063 | itself. */ | |
7064 | gen_ptr_to_mbr_type_die (type, context_die); | |
7065 | break; | |
7066 | ||
7067 | case SET_TYPE: | |
7068 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
7069 | gen_set_type_die (type, context_die); | |
7070 | break; | |
7071 | ||
7072 | case FILE_TYPE: | |
7073 | gen_type_die (TREE_TYPE (type), context_die); | |
7074 | abort (); /* No way to represent these in Dwarf yet! */ | |
7075 | break; | |
7076 | ||
7077 | case FUNCTION_TYPE: | |
7078 | /* Force out return type (in case it wasn't forced out already). */ | |
7079 | gen_type_die (TREE_TYPE (type), context_die); | |
7080 | gen_subroutine_type_die (type, context_die); | |
7081 | break; | |
7082 | ||
7083 | case METHOD_TYPE: | |
7084 | /* Force out return type (in case it wasn't forced out already). */ | |
7085 | gen_type_die (TREE_TYPE (type), context_die); | |
7086 | gen_subroutine_type_die (type, context_die); | |
7087 | break; | |
7088 | ||
7089 | case ARRAY_TYPE: | |
7090 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
7091 | { | |
7092 | gen_type_die (TREE_TYPE (type), context_die); | |
7093 | gen_string_type_die (type, context_die); | |
7094 | } | |
7095 | else | |
7096 | { | |
7097 | gen_array_type_die (type, context_die); | |
7098 | } | |
7099 | break; | |
7100 | ||
7101 | case ENUMERAL_TYPE: | |
7102 | case RECORD_TYPE: | |
7103 | case UNION_TYPE: | |
7104 | case QUAL_UNION_TYPE: | |
e90b62db | 7105 | /* For a function-scope tagged type, we can always go ahead and output |
a3f97cbb JW |
7106 | a Dwarf description of this type right now, even if the type in |
7107 | question is still incomplete, because if this local type *was* ever | |
7108 | completed anywhere within its scope, that complete definition would | |
7109 | already have been attached to this RECORD_TYPE, UNION_TYPE, | |
7110 | QUAL_UNION_TYPE or ENUMERAL_TYPE node by the time we reach this | |
7111 | point. That's true because of the way the front-end does its | |
7112 | processing of file-scope declarations (of functions and class types) | |
7113 | within which other types might be nested. The C and C++ front-ends | |
7114 | always gobble up such "local scope" things en-mass before they try | |
7115 | to output *any* debugging information for any of the stuff contained | |
7116 | inside them and thus, we get the benefit here of what is (in effect) | |
7117 | a pre-resolution of forward references to tagged types in local | |
7118 | scopes. Note however that for file-scope tagged types we cannot | |
7119 | assume that such pre-resolution of forward references has taken | |
7120 | place. A given file-scope tagged type may appear to be incomplete | |
7121 | when we reach this point, but it may yet be given a full definition | |
7122 | (at file-scope) later on during compilation. In order to avoid | |
7123 | generating a premature (and possibly incorrect) set of Dwarf DIEs | |
7124 | for such (as yet incomplete) file-scope tagged types, we generate | |
7125 | nothing at all for as-yet incomplete file-scope tagged types here | |
7126 | unless we are making our special "finalization" pass for file-scope | |
7127 | things at the very end of compilation. At that time, we will | |
7128 | certainly know as much about each file-scope tagged type as we are | |
7129 | ever going to know, so at that point in time, we can safely generate | |
7130 | correct Dwarf descriptions for these file-scope tagged types. */ | |
7131 | is_complete = TYPE_SIZE (type) != 0 | |
e90b62db JM |
7132 | || (TYPE_CONTEXT (type) != NULL |
7133 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) != 't') | |
a3f97cbb JW |
7134 | || finalizing; |
7135 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
7136 | { | |
7137 | gen_enumeration_type_die (type, is_complete, context_die); | |
7138 | } | |
7139 | else | |
7140 | { | |
7141 | gen_struct_or_union_type_die (type, is_complete, context_die); | |
7142 | } | |
4b674448 JM |
7143 | |
7144 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix | |
7145 | it up if it is ever completed. */ | |
7146 | if (! is_complete) | |
7147 | return; | |
a3f97cbb JW |
7148 | break; |
7149 | ||
7150 | case VOID_TYPE: | |
7151 | case INTEGER_TYPE: | |
7152 | case REAL_TYPE: | |
7153 | case COMPLEX_TYPE: | |
7154 | case BOOLEAN_TYPE: | |
7155 | case CHAR_TYPE: | |
7156 | /* No DIEs needed for fundamental types. */ | |
7157 | break; | |
7158 | ||
7159 | case LANG_TYPE: | |
7160 | /* No Dwarf representation currently defined. */ | |
7161 | break; | |
7162 | ||
7163 | default: | |
7164 | abort (); | |
7165 | } | |
7166 | ||
7167 | TREE_ASM_WRITTEN (type) = 1; | |
7168 | } | |
7169 | ||
7170 | /* Generate a DIE for a tagged type instantiation. */ | |
7171 | static void | |
7172 | gen_tagged_type_instantiation_die (type, context_die) | |
7173 | register tree type; | |
7174 | register dw_die_ref context_die; | |
7175 | { | |
7176 | if (type == 0 || type == error_mark_node) | |
7177 | { | |
7178 | return; | |
7179 | } | |
7180 | ||
7181 | /* We are going to output a DIE to represent the unqualified version of of | |
7182 | this type (i.e. without any const or volatile qualifiers) so make sure | |
7183 | that we have the main variant (i.e. the unqualified version) of this | |
7184 | type now. */ | |
7185 | assert (type == type_main_variant (type)); | |
7186 | assert (TREE_ASM_WRITTEN (type)); | |
7187 | ||
7188 | switch (TREE_CODE (type)) | |
7189 | { | |
7190 | case ERROR_MARK: | |
7191 | break; | |
7192 | ||
7193 | case ENUMERAL_TYPE: | |
7194 | gen_inlined_enumeration_type_die (type, context_die); | |
7195 | break; | |
7196 | ||
7197 | case RECORD_TYPE: | |
7198 | gen_inlined_structure_type_die (type, context_die); | |
7199 | break; | |
7200 | ||
7201 | case UNION_TYPE: | |
7202 | case QUAL_UNION_TYPE: | |
7203 | gen_inlined_union_type_die (type, context_die); | |
7204 | break; | |
7205 | ||
7206 | default: | |
7207 | abort (); /* Should never happen. */ | |
7208 | } | |
7209 | } | |
7210 | ||
7211 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
7212 | things which are local to the given block. */ | |
7213 | static void | |
d7248bff | 7214 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
7215 | register tree stmt; |
7216 | register dw_die_ref context_die; | |
d7248bff | 7217 | int depth; |
a3f97cbb JW |
7218 | { |
7219 | register int must_output_die = 0; | |
7220 | register tree origin; | |
7221 | register tree decl; | |
7222 | register enum tree_code origin_code; | |
7223 | ||
7224 | /* Ignore blocks never really used to make RTL. */ | |
7225 | ||
7226 | if (!stmt || !TREE_USED (stmt)) | |
7227 | { | |
7228 | return; | |
7229 | } | |
7230 | ||
7231 | /* Determine the "ultimate origin" of this block. This block may be an | |
7232 | inlined instance of an inlined instance of inline function, so we have | |
7233 | to trace all of the way back through the origin chain to find out what | |
7234 | sort of node actually served as the original seed for the creation of | |
7235 | the current block. */ | |
7236 | origin = block_ultimate_origin (stmt); | |
7237 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
7238 | ||
7239 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
7240 | block. */ | |
7241 | if (origin_code == FUNCTION_DECL) | |
7242 | { | |
7243 | /* The outer scopes for inlinings *must* always be represented. We | |
7244 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
7245 | must_output_die = 1; | |
7246 | } | |
7247 | else | |
7248 | { | |
7249 | /* In the case where the current block represents an inlining of the | |
7250 | "body block" of an inline function, we must *NOT* output any DIE for | |
7251 | this block because we have already output a DIE to represent the | |
7252 | whole inlined function scope and the "body block" of any function | |
7253 | doesn't really represent a different scope according to ANSI C | |
7254 | rules. So we check here to make sure that this block does not | |
7255 | represent a "body block inlining" before trying to set the | |
7256 | `must_output_die' flag. */ | |
d7248bff | 7257 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
7258 | { |
7259 | /* Determine if this block directly contains any "significant" | |
7260 | local declarations which we will need to output DIEs for. */ | |
7261 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
7262 | { | |
7263 | /* We are not in terse mode so *any* local declaration counts | |
7264 | as being a "significant" one. */ | |
7265 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
7266 | } | |
7267 | else | |
7268 | { | |
7269 | /* We are in terse mode, so only local (nested) function | |
7270 | definitions count as "significant" local declarations. */ | |
7271 | for (decl = BLOCK_VARS (stmt); | |
7272 | decl != NULL; decl = TREE_CHAIN (decl)) | |
7273 | { | |
7274 | if (TREE_CODE (decl) == FUNCTION_DECL | |
7275 | && DECL_INITIAL (decl)) | |
7276 | { | |
7277 | must_output_die = 1; | |
7278 | break; | |
7279 | } | |
7280 | } | |
7281 | } | |
7282 | } | |
7283 | } | |
7284 | ||
7285 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
7286 | DIE for any block which contains no significant local declarations at | |
7287 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
7288 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
7289 | that in terse mode, our definition of what constitutes a "significant" | |
7290 | local declaration gets restricted to include only inlined function | |
7291 | instances and local (nested) function definitions. */ | |
7292 | if (must_output_die) | |
7293 | { | |
7294 | if (origin_code == FUNCTION_DECL) | |
7295 | { | |
d7248bff | 7296 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb JW |
7297 | } |
7298 | else | |
7299 | { | |
d7248bff | 7300 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
7301 | } |
7302 | } | |
7303 | else | |
d7248bff | 7304 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
7305 | } |
7306 | ||
7307 | /* Generate all of the decls declared within a given scope and (recursively) | |
7308 | all of it's sub-blocks. */ | |
7309 | static void | |
d7248bff | 7310 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
7311 | register tree stmt; |
7312 | register dw_die_ref context_die; | |
d7248bff | 7313 | int depth; |
a3f97cbb JW |
7314 | { |
7315 | register tree decl; | |
7316 | register tree subblocks; | |
7317 | /* Ignore blocks never really used to make RTL. */ | |
7318 | if (!stmt || !TREE_USED (stmt)) | |
7319 | { | |
7320 | return; | |
7321 | } | |
d7248bff | 7322 | if (!BLOCK_ABSTRACT (stmt) && depth > 0) |
a3f97cbb JW |
7323 | { |
7324 | next_block_number++; | |
7325 | } | |
7326 | ||
7327 | /* Output the DIEs to represent all of the data objects, functions, | |
7328 | typedefs, and tagged types declared directly within this block but not | |
7329 | within any nested sub-blocks. */ | |
7330 | for (decl = BLOCK_VARS (stmt); | |
7331 | decl != NULL; decl = TREE_CHAIN (decl)) | |
7332 | { | |
7333 | gen_decl_die (decl, context_die); | |
7334 | } | |
7335 | ||
7336 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
7337 | therein) of this block. */ | |
7338 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
7339 | subblocks != NULL; | |
7340 | subblocks = BLOCK_CHAIN (subblocks)) | |
7341 | { | |
d7248bff | 7342 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
7343 | } |
7344 | } | |
7345 | ||
7346 | /* Generate Dwarf debug information for a decl described by DECL. */ | |
7347 | static void | |
7348 | gen_decl_die (decl, context_die) | |
7349 | register tree decl; | |
7350 | register dw_die_ref context_die; | |
7351 | { | |
7352 | register tree origin; | |
7353 | /* Make a note of the decl node we are going to be working on. We may need | |
7354 | to give the user the source coordinates of where it appeared in case we | |
7355 | notice (later on) that something about it looks screwy. */ | |
7356 | dwarf_last_decl = decl; | |
7357 | ||
7358 | if (TREE_CODE (decl) == ERROR_MARK) | |
7359 | { | |
7360 | return; | |
7361 | } | |
7362 | ||
7363 | /* If this ..._DECL node is marked to be ignored, then ignore it. But don't | |
7364 | ignore a function definition, since that would screw up our count of | |
7365 | blocks, and that it turn will completely screw up the the labels we will | |
7366 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
7367 | subsequent blocks). */ | |
7368 | if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL) | |
7369 | { | |
7370 | return; | |
7371 | } | |
7372 | ||
7373 | push_decl_scope (DECL_CONTEXT (decl)); | |
7374 | switch (TREE_CODE (decl)) | |
7375 | { | |
7376 | case CONST_DECL: | |
7377 | /* The individual enumerators of an enum type get output when we output | |
7378 | the Dwarf representation of the relevant enum type itself. */ | |
7379 | break; | |
7380 | ||
7381 | case FUNCTION_DECL: | |
7382 | /* If we are in terse mode, don't output any DIEs to represent mere | |
bdb669cb JM |
7383 | function declarations, unless they are class members. */ |
7384 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE) | |
a3f97cbb JW |
7385 | { |
7386 | break; | |
7387 | } | |
bdb669cb | 7388 | |
a3f97cbb JW |
7389 | /* Before we describe the FUNCTION_DECL itself, make sure that we have |
7390 | described its return type. */ | |
7391 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
7392 | ||
7393 | /* Now output a DIE to represent the function itself. */ | |
7394 | gen_subprogram_die (decl, context_die); | |
7395 | break; | |
7396 | ||
7397 | case TYPE_DECL: | |
7398 | /* If we are in terse mode, don't generate any DIEs to represent any | |
7399 | actual typedefs. Note that even when we are in terse mode, we must | |
7400 | still output DIEs to represent those tagged types which are used | |
7401 | (directly or indirectly) in the specification of either a return | |
7402 | type or a formal parameter type of some function. */ | |
7403 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
7404 | { | |
7405 | if (DECL_NAME (decl) != NULL | |
7406 | || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) | |
7407 | { | |
7408 | break; | |
7409 | } | |
7410 | } | |
7411 | ||
7412 | /* In the special case of a null-named TYPE_DECL node (representing the | |
7413 | declaration of some type tag), if the given TYPE_DECL is marked as | |
7414 | having been instantiated from some other (original) TYPE_DECL node | |
7415 | (e.g. one which was generated within the original definition of an | |
7416 | inline function) we have to generate a special (abbreviated) | |
7417 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type | |
7418 | DIE here. */ | |
7419 | if (!DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl)) | |
7420 | { | |
7421 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
7422 | break; | |
7423 | } | |
7424 | gen_type_die (TREE_TYPE (decl), context_die); | |
7425 | ||
7426 | /* Note that unlike the gcc front end (which generates a NULL named | |
7427 | TYPE_DECL node for each complete tagged type, each array type, and | |
7428 | each function type node created) the g++ front end generates a | |
7429 | _named_ TYPE_DECL node for each tagged type node created. | |
bdb669cb JM |
7430 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to |
7431 | generate a DW_TAG_typedef DIE for them. */ | |
7432 | if (DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) | |
a3f97cbb JW |
7433 | { |
7434 | /* Output a DIE to represent the typedef itself. */ | |
7435 | gen_typedef_die (decl, context_die); | |
7436 | } | |
7437 | break; | |
7438 | ||
7439 | case LABEL_DECL: | |
7440 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
7441 | { | |
7442 | gen_label_die (decl, context_die); | |
7443 | } | |
7444 | break; | |
7445 | ||
7446 | case VAR_DECL: | |
7447 | /* If we are in terse mode, don't generate any DIEs to represent any | |
7448 | variable declarations or definitions. */ | |
7449 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
7450 | { | |
7451 | break; | |
7452 | } | |
7453 | ||
7454 | /* Output any DIEs that are needed to specify the type of this data | |
7455 | object. */ | |
7456 | gen_type_die (TREE_TYPE (decl), context_die); | |
7457 | ||
7458 | /* Now output the DIE to represent the data object itself. This gets | |
7459 | complicated because of the possibility that the VAR_DECL really | |
7460 | represents an inlined instance of a formal parameter for an inline | |
7461 | function. */ | |
7462 | origin = decl_ultimate_origin (decl); | |
7463 | if (origin != NULL && TREE_CODE (origin) == PARM_DECL) | |
7464 | { | |
7465 | gen_formal_parameter_die (decl, context_die); | |
7466 | } | |
7467 | else | |
7468 | { | |
7469 | gen_variable_die (decl, context_die); | |
7470 | } | |
7471 | break; | |
7472 | ||
7473 | case FIELD_DECL: | |
7474 | /* Ignore the nameless fields that are used to skip bits. */ | |
7475 | if (DECL_NAME (decl) != 0) | |
7476 | { | |
7477 | gen_type_die (member_declared_type (decl), context_die); | |
7478 | gen_field_die (decl, context_die); | |
7479 | } | |
7480 | break; | |
7481 | ||
7482 | case PARM_DECL: | |
7483 | gen_type_die (TREE_TYPE (decl), context_die); | |
7484 | gen_formal_parameter_die (decl, context_die); | |
7485 | break; | |
7486 | ||
7487 | default: | |
7488 | abort (); | |
7489 | } | |
7490 | pop_decl_scope (); | |
7491 | } | |
7492 | \f | |
7493 | /***************** Debug Information Generation Hooks ***********************/ | |
7494 | void | |
7495 | dwarfout_file_scope_decl (decl, set_finalizing) | |
7496 | register tree decl; | |
7497 | register int set_finalizing; | |
7498 | { | |
7499 | if (TREE_CODE (decl) == ERROR_MARK) | |
7500 | { | |
7501 | return; | |
7502 | } | |
7503 | ||
7504 | /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta | |
7505 | hope that the node in question doesn't represent a function definition. | |
7506 | If it does, then totally ignoring it is bound to screw up our count of | |
7507 | blocks, and that it turn will completely screw up the the labels we will | |
7508 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
7509 | subsequent blocks). (It's too bad that BLOCK nodes don't carry their | |
7510 | own sequence numbers with them!) */ | |
7511 | if (DECL_IGNORED_P (decl)) | |
7512 | { | |
7513 | if (TREE_CODE (decl) == FUNCTION_DECL | |
7514 | && DECL_INITIAL (decl) != NULL) | |
7515 | { | |
7516 | abort (); | |
7517 | } | |
7518 | return; | |
7519 | } | |
7520 | ||
7521 | switch (TREE_CODE (decl)) | |
7522 | { | |
7523 | case FUNCTION_DECL: | |
7524 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a | |
7525 | builtin function. Explicit programmer-supplied declarations of | |
7526 | these same functions should NOT be ignored however. */ | |
7527 | if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) | |
7528 | { | |
7529 | return; | |
7530 | } | |
7531 | ||
7532 | /* What we would really like to do here is to filter out all mere | |
7533 | file-scope declarations of file-scope functions which are never | |
7534 | referenced later within this translation unit (and keep all of ones | |
7535 | that *are* referenced later on) but we aren't clarvoiant, so we have | |
7536 | no idea which functions will be referenced in the future (i.e. later | |
7537 | on within the current translation unit). So here we just ignore all | |
7538 | file-scope function declarations which are not also definitions. If | |
7539 | and when the debugger needs to know something about these funcstion, | |
7540 | it wil have to hunt around and find the DWARF information associated | |
7541 | with the definition of the function. Note that we can't just check | |
7542 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent | |
7543 | definitions and which ones represent mere declarations. We have to | |
7544 | check `DECL_INITIAL' instead. That's because the C front-end | |
7545 | supports some weird semantics for "extern inline" function | |
7546 | definitions. These can get inlined within the current translation | |
7547 | unit (an thus, we need to generate DWARF info for their abstract | |
7548 | instances so that the DWARF info for the concrete inlined instances | |
7549 | can have something to refer to) but the compiler never generates any | |
7550 | out-of-lines instances of such things (despite the fact that they | |
7551 | *are* definitions). The important point is that the C front-end | |
7552 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
7553 | to generate DWARf for them anyway. Note that the C++ front-end also | |
7554 | plays some similar games for inline function definitions appearing | |
7555 | within include files which also contain | |
7556 | `#pragma interface' pragmas. */ | |
7557 | if (DECL_INITIAL (decl) == NULL_TREE) | |
7558 | { | |
7559 | return; | |
7560 | } | |
7561 | break; | |
7562 | ||
7563 | case VAR_DECL: | |
7564 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object | |
7565 | declaration and if the declaration was never even referenced from | |
7566 | within this entire compilation unit. We suppress these DIEs in | |
7567 | order to save space in the .debug section (by eliminating entries | |
7568 | which are probably useless). Note that we must not suppress | |
7569 | block-local extern declarations (whether used or not) because that | |
7570 | would screw-up the debugger's name lookup mechanism and cause it to | |
7571 | miss things which really ought to be in scope at a given point. */ | |
7572 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
7573 | { | |
7574 | return; | |
7575 | } | |
7576 | ||
7577 | /* If we are in terse mode, don't generate any DIEs to represent any | |
7578 | variable declarations or definitions. */ | |
7579 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
7580 | { | |
7581 | return; | |
7582 | } | |
7583 | break; | |
7584 | ||
7585 | case TYPE_DECL: | |
7586 | /* Don't bother trying to generate any DIEs to represent any of the | |
7587 | normal built-in types for the language we are compiling, except in | |
7588 | cases where the types in question are *not* DWARF fundamental types. | |
7589 | We make an exception in the case of non-fundamental types for the | |
7590 | sake of objective C (and perhaps C++) because the GNU front-ends for | |
7591 | these languages may in fact create certain "built-in" types which | |
7592 | are (for example) RECORD_TYPEs. In such cases, we really need to | |
7593 | output these (non-fundamental) types because other DIEs may contain | |
7594 | references to them. */ | |
7595 | if (DECL_SOURCE_LINE (decl) == 0 | |
7596 | && is_base_type (TREE_TYPE (decl))) | |
7597 | { | |
7598 | return; | |
7599 | } | |
7600 | ||
7601 | /* If we are in terse mode, don't generate any DIEs to represent any | |
7602 | actual typedefs. Note that even when we are in terse mode, we must | |
7603 | still output DIEs to represent those tagged types which are used | |
7604 | (directly or indirectly) in the specification of either a return | |
7605 | type or a formal parameter type of some function. */ | |
7606 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
7607 | { | |
7608 | if (DECL_NAME (decl) != NULL | |
7609 | || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) | |
7610 | { | |
7611 | return; | |
7612 | } | |
7613 | } | |
7614 | break; | |
7615 | ||
7616 | default: | |
7617 | return; | |
7618 | } | |
7619 | ||
7620 | finalizing = set_finalizing; | |
7621 | gen_decl_die (decl, comp_unit_die); | |
7622 | ||
7623 | if (TREE_CODE (decl) == FUNCTION_DECL | |
7624 | && DECL_INITIAL (decl) != NULL) | |
7625 | { | |
7626 | current_funcdef_number++; | |
7627 | } | |
7628 | ||
7629 | } | |
7630 | ||
7631 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
7632 | a lexical block. */ | |
7633 | void | |
7634 | dwarfout_begin_block (blocknum) | |
7635 | register unsigned blocknum; | |
7636 | { | |
7637 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7638 | ||
7639 | function_section (current_function_decl); | |
7640 | sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); | |
7641 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7642 | } | |
7643 | ||
7644 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
7645 | lexical block. */ | |
7646 | void | |
7647 | dwarfout_end_block (blocknum) | |
7648 | register unsigned blocknum; | |
7649 | { | |
7650 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7651 | ||
7652 | function_section (current_function_decl); | |
7653 | sprintf (label, BLOCK_END_LABEL_FMT, blocknum); | |
7654 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7655 | } | |
7656 | ||
7657 | /* Output a marker (i.e. a label) at a point in the assembly code which | |
7658 | corresponds to a given source level label. */ | |
7659 | void | |
7660 | dwarfout_label (insn) | |
7661 | register rtx insn; | |
7662 | { | |
7663 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7664 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
7665 | { | |
7666 | function_section (current_function_decl); | |
7667 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number, | |
7668 | (unsigned) INSN_UID (insn)); | |
7669 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7670 | } | |
7671 | } | |
7672 | ||
d291dd49 JM |
7673 | /* Output a marker (i.e. a label) for the beginning of a function, before |
7674 | the prologue. */ | |
a3f97cbb | 7675 | void |
d291dd49 | 7676 | dwarfout_begin_prologue () |
a3f97cbb JW |
7677 | { |
7678 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
a3f97cbb JW |
7679 | register dw_fde_ref fde; |
7680 | register dw_cfi_ref cfi; | |
7681 | ||
7682 | function_section (current_function_decl); | |
d291dd49 | 7683 | sprintf (label, FUNC_BEGIN_LABEL_FMT, current_funcdef_number); |
a3f97cbb JW |
7684 | ASM_OUTPUT_LABEL (asm_out_file, label); |
7685 | ||
7686 | /* Expand the fde table if necessary. */ | |
7687 | if (fde_table_in_use == fde_table_allocated) | |
7688 | { | |
7689 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
7690 | fde_table = (dw_fde_ref) xrealloc (fde_table, | |
7691 | fde_table_allocated * sizeof (dw_fde_node)); | |
7692 | } | |
7693 | ||
7694 | /* Record the FDE associated with this function. */ | |
7695 | current_funcdef_fde = fde_table_in_use; | |
7696 | ||
7697 | /* Add the new FDE at the end of the fde_table. */ | |
7698 | fde = &fde_table[fde_table_in_use++]; | |
d291dd49 JM |
7699 | if (DECL_WEAK (current_function_decl) |
7700 | || DECL_ONE_ONLY (current_function_decl)) | |
7701 | fde->dw_fde_begin = xstrdup (label); | |
7702 | else | |
7703 | fde->dw_fde_begin = xstrdup (decl_start_label (current_function_decl)); | |
7704 | fde->dw_fde_end_prolog = NULL; | |
a3f97cbb JW |
7705 | fde->dw_fde_begin_epilogue = NULL; |
7706 | fde->dw_fde_end = NULL; | |
7707 | fde->dw_fde_cfi = NULL; | |
d291dd49 JM |
7708 | } |
7709 | ||
7710 | /* Output a marker (i.e. a label) for the point in the generated code where | |
7711 | the real body of the function begins (after parameters have been moved to | |
7712 | their home locations). */ | |
7713 | void | |
7714 | dwarfout_begin_function () | |
7715 | { | |
7716 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7717 | register long int offset; | |
7718 | register dw_fde_ref fde; | |
7719 | register dw_cfi_ref cfi; | |
7720 | ||
7721 | function_section (current_function_decl); | |
7722 | sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number); | |
7723 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7724 | ||
7725 | /* Record the end-of-prolog location in the FDE. */ | |
7726 | fde = &fde_table[fde_table_in_use - 1]; | |
7727 | fde->dw_fde_end_prolog = xstrdup (label); | |
a3f97cbb JW |
7728 | |
7729 | #ifdef MIPS_DEBUGGING_INFO | |
7730 | ||
7731 | /* On entry, the Call Frame Address is in the stack pointer register. */ | |
7732 | cfi = new_cfi (); | |
7733 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
7734 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM; | |
7735 | cfi->dw_cfi_oprnd2.dw_cfi_offset = 0; | |
7736 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7737 | ||
7738 | /* Set the location counter to the end of the function prolog. */ | |
7739 | cfi = new_cfi (); | |
7740 | cfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
7741 | cfi->dw_cfi_oprnd1.dw_cfi_addr = xstrdup (label); | |
7742 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7743 | ||
7744 | /* Define the CFA as either an explicit frame pointer register, | |
7745 | or an offset from the stack pointer. */ | |
7746 | cfi = new_cfi (); | |
7747 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
7748 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = (frame_pointer_needed) | |
7749 | ? FRAME_POINTER_REGNUM | |
7750 | : STACK_POINTER_REGNUM; | |
7751 | offset = current_frame_info.total_size; | |
7752 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
7753 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7754 | ||
7755 | /* record the frame size for later definition of the DW_AT_frame_base | |
7756 | attribute. */ | |
7757 | current_funcdef_frame_size = offset; | |
7758 | ||
7759 | /* Define the rule for restoring the stack pointer. */ | |
7760 | if (frame_pointer_needed) | |
7761 | { | |
7762 | /* Restore the stack register from the frame pointer. */ | |
7763 | cfi = new_cfi (); | |
7764 | cfi->dw_cfi_opc = DW_CFA_register; | |
7765 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM; | |
7766 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = FRAME_POINTER_REGNUM; | |
7767 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7768 | } | |
7769 | ||
7770 | /* If RA is saved on the stack, define it here. */ | |
7771 | if (regs_ever_live[31]) | |
7772 | { | |
7773 | offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT; | |
7774 | assert (offset >= 0); | |
7775 | cfi = new_cfi (); | |
7776 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
7777 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL; | |
7778 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
7779 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7780 | } | |
7781 | ||
7782 | /* If FP is saved on the stack, define it here. */ | |
7783 | if (current_frame_info.mask & (1 << 30)) | |
7784 | { | |
7785 | offset = (current_frame_info.gp_save_offset | |
ba7b35df | 7786 | - (((current_frame_info.mask >> 31) & 1) * UNITS_PER_WORD)) |
a3f97cbb JW |
7787 | / DWARF_CIE_DATA_ALIGNMENT; |
7788 | assert (offset >= 0); | |
7789 | cfi = new_cfi (); | |
7790 | cfi->dw_cfi_opc = DW_CFA_offset; | |
7791 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = FRAME_POINTER_REGNUM; | |
7792 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
7793 | add_cfi (&fde->dw_fde_cfi, cfi); | |
7794 | } | |
7795 | ||
7796 | #endif | |
7797 | ||
7798 | } | |
7799 | ||
7800 | /* Output a marker (i.e. a label) for the point in the generated code where | |
7801 | the real body of the function ends (just before the epilogue code). */ | |
7802 | void | |
7803 | dwarfout_end_function () | |
7804 | { | |
7805 | dw_fde_ref fde; | |
7806 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7807 | function_section (current_function_decl); | |
7808 | sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number); | |
7809 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7810 | /* Record the ending code location in the FDE. */ | |
7811 | fde = &fde_table[fde_table_in_use - 1]; | |
7812 | fde->dw_fde_begin_epilogue = xstrdup(label); | |
7813 | } | |
7814 | ||
7815 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
7816 | for a function definition. This gets called *after* the epilogue code has | |
7817 | been generated. */ | |
7818 | void | |
7819 | dwarfout_end_epilogue () | |
7820 | { | |
7821 | dw_fde_ref fde; | |
7822 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7823 | /* Output a label to mark the endpoint of the code generated for this | |
7824 | function. */ | |
7825 | sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); | |
7826 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7827 | fde = &fde_table[fde_table_in_use - 1]; | |
7828 | fde->dw_fde_end = xstrdup (label); | |
7829 | } | |
7830 | ||
7831 | /* Lookup a filename (in the list of filenames that we know about here in | |
7832 | dwarfout.c) and return its "index". The index of each (known) filename is | |
7833 | just a unique number which is associated with only that one filename. | |
7834 | We need such numbers for the sake of generating labels | |
7835 | (in the .debug_sfnames section) and references to those | |
7836 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
7837 | If the filename given as an argument is not found in our current list, | |
7838 | add it to the list and assign it the next available unique index number. | |
7839 | In order to speed up searches, we remember the index of the filename | |
7840 | was looked up last. This handles the majority of all searches. */ | |
7841 | static unsigned | |
7842 | lookup_filename (file_name) | |
7843 | char *file_name; | |
7844 | { | |
7845 | static unsigned last_file_lookup_index = 0; | |
7846 | register char *fn; | |
7847 | register unsigned i; | |
7848 | ||
7849 | /* Check to see if the file name that was searched on the previous call | |
7850 | matches this file name. If so, return the index. */ | |
7851 | if (last_file_lookup_index != 0) | |
7852 | { | |
7853 | fn = file_table[last_file_lookup_index]; | |
7854 | if (strcmp (file_name, fn) == 0) | |
7855 | { | |
7856 | return last_file_lookup_index; | |
7857 | } | |
7858 | } | |
7859 | ||
7860 | /* Didn't match the previous lookup, search the table */ | |
7861 | for (i = 1; i < file_table_in_use; ++i) | |
7862 | { | |
7863 | fn = file_table[i]; | |
7864 | if (strcmp (file_name, fn) == 0) | |
7865 | { | |
7866 | last_file_lookup_index = i; | |
7867 | return i; | |
7868 | } | |
7869 | } | |
7870 | ||
7871 | /* Prepare to add a new table entry by making sure there is enough space in | |
7872 | the table to do so. If not, expand the current table. */ | |
7873 | if (file_table_in_use == file_table_allocated) | |
7874 | { | |
7875 | file_table_allocated += FILE_TABLE_INCREMENT; | |
7876 | file_table | |
7877 | = (char **) | |
7878 | xrealloc (file_table, file_table_allocated * sizeof (char *)); | |
7879 | } | |
7880 | ||
7881 | /* add the new entry to the end of the filename table. */ | |
7882 | file_table[file_table_in_use] = xstrdup (file_name); | |
7883 | last_file_lookup_index = file_table_in_use++; | |
7884 | return last_file_lookup_index; | |
7885 | } | |
7886 | ||
7887 | /* Output a label to mark the beginning of a source code line entry | |
7888 | and record information relating to this source line, in | |
7889 | 'line_info_table' for later output of the .debug_line section. */ | |
7890 | void | |
7891 | dwarfout_line (filename, line) | |
7892 | register char *filename; | |
7893 | register unsigned line; | |
7894 | { | |
7895 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7896 | register unsigned this_file_entry_num = lookup_filename (filename); | |
a3f97cbb JW |
7897 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
7898 | { | |
7899 | function_section (current_function_decl); | |
a3f97cbb | 7900 | |
e90b62db | 7901 | if (DECL_SECTION_NAME (current_function_decl)) |
a3f97cbb | 7902 | { |
e90b62db JM |
7903 | register dw_separate_line_info_ref line_info; |
7904 | sprintf (label, SEPARATE_LINE_CODE_LABEL_FMT, | |
7905 | separate_line_info_table_in_use); | |
7906 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7907 | fputc ('\n', asm_out_file); | |
7908 | ||
7909 | /* expand the line info table if necessary */ | |
7910 | if (separate_line_info_table_in_use | |
7911 | == separate_line_info_table_allocated) | |
7912 | { | |
7913 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
7914 | separate_line_info_table | |
7915 | = (dw_separate_line_info_ref) xrealloc | |
7916 | (separate_line_info_table, | |
7917 | separate_line_info_table_allocated | |
7918 | * sizeof (dw_separate_line_info_entry)); | |
7919 | } | |
7920 | /* add the new entry at the end of the line_info_table. */ | |
7921 | line_info | |
7922 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
7923 | line_info->dw_file_num = lookup_filename (filename); | |
7924 | line_info->dw_line_num = line; | |
7925 | line_info->function = current_funcdef_number; | |
7926 | } | |
7927 | else | |
7928 | { | |
7929 | register dw_line_info_ref line_info; | |
7930 | sprintf (label, LINE_CODE_LABEL_FMT, line_info_table_in_use); | |
7931 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
7932 | fputc ('\n', asm_out_file); | |
7933 | ||
7934 | /* expand the line info table if necessary */ | |
7935 | if (line_info_table_in_use == line_info_table_allocated) | |
7936 | { | |
7937 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
7938 | line_info_table | |
7939 | = (dw_line_info_ref) xrealloc | |
7940 | (line_info_table, | |
7941 | line_info_table_allocated * sizeof (dw_line_info_entry)); | |
7942 | } | |
7943 | /* add the new entry at the end of the line_info_table. */ | |
7944 | line_info = &line_info_table[line_info_table_in_use++]; | |
7945 | line_info->dw_file_num = lookup_filename (filename); | |
7946 | line_info->dw_line_num = line; | |
a3f97cbb | 7947 | } |
a3f97cbb JW |
7948 | } |
7949 | } | |
7950 | ||
7951 | /* Record the beginning of a new source file, for later output | |
7952 | of the .debug_macinfo section. At present, unimplemented. */ | |
7953 | void | |
7954 | dwarfout_start_new_source_file (filename) | |
7955 | register char *filename; | |
7956 | { | |
7957 | } | |
7958 | ||
7959 | /* Record the resumption of a source file, for later output | |
7960 | of the .debug_macinfo section. At present, unimplemented. */ | |
7961 | void | |
7962 | dwarfout_resume_previous_source_file (lineno) | |
7963 | register unsigned lineno; | |
7964 | { | |
7965 | } | |
7966 | ||
7967 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
7968 | the tail part of the directive line, i.e. the part which is past the | |
7969 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
7970 | void | |
7971 | dwarfout_define (lineno, buffer) | |
7972 | register unsigned lineno; | |
7973 | register char *buffer; | |
7974 | { | |
7975 | static int initialized = 0; | |
7976 | if (!initialized) | |
7977 | { | |
7978 | dwarfout_start_new_source_file (primary_filename); | |
7979 | initialized = 1; | |
7980 | } | |
7981 | } | |
7982 | ||
7983 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
7984 | the tail part of the directive line, i.e. the part which is past the | |
7985 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
7986 | void | |
7987 | dwarfout_undef (lineno, buffer) | |
7988 | register unsigned lineno; | |
7989 | register char *buffer; | |
7990 | { | |
7991 | } | |
7992 | ||
7993 | /* Set up for Dwarf output at the start of compilation. */ | |
7994 | void | |
7995 | dwarfout_init (asm_out_file, main_input_filename) | |
7996 | register FILE *asm_out_file; | |
7997 | register char *main_input_filename; | |
7998 | { | |
7999 | ||
8000 | /* Remember the name of the primary input file. */ | |
8001 | primary_filename = main_input_filename; | |
8002 | ||
8003 | /* Allocate the initial hunk of the file_table. */ | |
8004 | file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *)); | |
8005 | bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *)); | |
8006 | file_table_allocated = FILE_TABLE_INCREMENT; | |
8007 | /* skip the first entry - file numbers begin at 1 */ | |
8008 | file_table_in_use = 1; | |
8009 | ||
8010 | /* Allocate the initial hunk of the type_die_table. */ | |
8011 | type_die_table | |
8012 | = (dw_die_ref *) xmalloc (TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
8013 | bzero (type_die_table, TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
8014 | type_die_table_allocated = TYPE_DIE_TABLE_INCREMENT; | |
8015 | type_die_table_in_use = 0; | |
8016 | ||
8017 | /* Allocate the initial hunk of the decl_die_table. */ | |
8018 | decl_die_table | |
8019 | = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
8020 | bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
8021 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; | |
8022 | decl_die_table_in_use = 0; | |
8023 | ||
8024 | /* Allocate the initial hunk of the decl_scope_table. */ | |
8025 | decl_scope_table | |
8026 | = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
8027 | bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
8028 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; | |
8029 | decl_scope_depth = 0; | |
8030 | ||
8031 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
8032 | abbrev_die_table | |
8033 | = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT | |
8034 | * sizeof (dw_die_ref)); | |
8035 | bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
8036 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; | |
8037 | /* zero-th entry is allocated, but unused */ | |
8038 | abbrev_die_table_in_use = 1; | |
8039 | ||
8040 | /* Allocate the initial hunk of the line_info_table. */ | |
8041 | line_info_table | |
8042 | = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT | |
8043 | * sizeof (dw_line_info_entry)); | |
8044 | bzero (line_info_table, LINE_INFO_TABLE_INCREMENT | |
8045 | * sizeof (dw_line_info_entry)); | |
8046 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; | |
8047 | /* zero-th entry is allocated, but unused */ | |
8048 | line_info_table_in_use = 1; | |
8049 | ||
8050 | /* Allocate the initial hunk of the fde_table. */ | |
8051 | fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
8052 | bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
8053 | fde_table_allocated = FDE_TABLE_INCREMENT; | |
8054 | fde_table_in_use = 0; | |
8055 | ||
bdb669cb | 8056 | #if 0 |
a3f97cbb JW |
8057 | /* Output a starting label for the .text section. */ |
8058 | fputc ('\n', asm_out_file); | |
8059 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
8060 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); | |
8061 | ||
8062 | /* Output a starting label for the .data section. */ | |
8063 | fputc ('\n', asm_out_file); | |
8064 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
8065 | ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); | |
8066 | ||
8067 | /* Output a starting label for the .rodata section. */ | |
8068 | fputc ('\n', asm_out_file); | |
8069 | ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION); | |
8070 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); | |
8071 | ||
8072 | /* Output a starting label for the .bss section. */ | |
8073 | fputc ('\n', asm_out_file); | |
8074 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
8075 | ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); | |
bdb669cb | 8076 | #endif |
a3f97cbb JW |
8077 | |
8078 | /* Generate the initial DIE for the .debug section. Note that the (string) | |
8079 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE | |
8080 | will (typically) be a relative pathname and that this pathname should be | |
8081 | taken as being relative to the directory from which the compiler was | |
8082 | invoked when the given (base) source file was compiled. */ | |
8083 | gen_compile_unit_die (main_input_filename); | |
8084 | ||
8085 | /* clear the association between base types and their DIE's */ | |
8086 | init_base_type_table (); | |
a3f97cbb JW |
8087 | } |
8088 | ||
8089 | /* Output stuff that dwarf requires at the end of every file, | |
8090 | and generate the DWARF-2 debugging info. */ | |
8091 | void | |
8092 | dwarfout_finish () | |
8093 | { | |
a3f97cbb JW |
8094 | /* Traverse the DIE tree and add sibling attributes to those DIE's |
8095 | that have children. */ | |
8096 | add_sibling_attributes (comp_unit_die); | |
8097 | ||
8098 | /* Output a terminator label for the .text section. */ | |
8099 | fputc ('\n', asm_out_file); | |
8100 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
8101 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); | |
8102 | ||
bdb669cb | 8103 | #if 0 |
a3f97cbb JW |
8104 | /* Output a terminator label for the .data section. */ |
8105 | fputc ('\n', asm_out_file); | |
8106 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
8107 | ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); | |
8108 | ||
8109 | /* Output a terminator label for the .rodata section. */ | |
8110 | fputc ('\n', asm_out_file); | |
8111 | ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION); | |
8112 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); | |
8113 | ||
8114 | /* Output a terminator label for the .bss section. */ | |
8115 | fputc ('\n', asm_out_file); | |
8116 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
8117 | ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); | |
bdb669cb | 8118 | #endif |
a3f97cbb | 8119 | |
e90b62db JM |
8120 | /* Output the source line correspondence table. */ |
8121 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
8122 | { | |
8123 | fputc ('\n', asm_out_file); | |
8124 | ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION); | |
8125 | output_line_info (); | |
8126 | ||
8127 | /* We can only use the low/high_pc attributes if all of the code | |
8128 | was in .text. */ | |
8129 | if (separate_line_info_table_in_use == 0) | |
8130 | { | |
8131 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION); | |
8132 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, TEXT_END_LABEL); | |
8133 | } | |
8134 | add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION); | |
8135 | } | |
8136 | ||
a3f97cbb JW |
8137 | /* Output the abbreviation table. */ |
8138 | fputc ('\n', asm_out_file); | |
8139 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
8140 | build_abbrev_table (comp_unit_die); | |
8141 | output_abbrev_section (); | |
8142 | ||
a3f97cbb JW |
8143 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
8144 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
8145 | calc_die_sizes (comp_unit_die); | |
8146 | ||
8147 | /* Initialize the beginning FDE offset - and calculate sizes/offsets. */ | |
8148 | next_fde_offset = DWARF_CIE_SIZE; | |
8149 | calc_fde_sizes (); | |
8150 | ||
8151 | /* Output debugging information. */ | |
8152 | fputc ('\n', asm_out_file); | |
8153 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION); | |
8154 | output_compilation_unit_header (); | |
8155 | output_die (comp_unit_die); | |
8156 | ||
d291dd49 JM |
8157 | if (pubname_table_in_use) |
8158 | { | |
8159 | /* Output public names table. */ | |
8160 | fputc ('\n', asm_out_file); | |
8161 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
8162 | output_pubnames (); | |
8163 | } | |
8164 | ||
a3f97cbb JW |
8165 | if (fde_table_in_use) |
8166 | { | |
8167 | /* Output call frame information. */ | |
8168 | fputc ('\n', asm_out_file); | |
8169 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
8170 | output_call_frame_info (); | |
8171 | ||
a3f97cbb JW |
8172 | /* Output the address range information. */ |
8173 | fputc ('\n', asm_out_file); | |
8174 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
8175 | output_aranges (); | |
8176 | } | |
8177 | } | |
8178 | #endif /* DWARF_DEBUGGING_INFO && DWARF_VERSION == 2 */ |