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