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