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