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