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