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