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