]>
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. |
e9a25f70 JL |
3 | Contributed by Gary Funck (gary@intrepid.com). |
4 | Derived from DWARF 1 implementation of 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 | 31 | #include <stdio.h> |
a3f97cbb JW |
32 | #include "tree.h" |
33 | #include "flags.h" | |
34 | #include "rtl.h" | |
35 | #include "hard-reg-set.h" | |
36 | #include "regs.h" | |
37 | #include "insn-config.h" | |
38 | #include "reload.h" | |
39 | #include "output.h" | |
71dfc51f | 40 | #include "expr.h" |
3f76745e | 41 | #include "except.h" |
a7cc7f29 | 42 | #include "dwarf2.h" |
a3f97cbb | 43 | |
c85f7c16 JL |
44 | /* We cannot use <assert.h> in GCC source, since that would include |
45 | GCC's assert.h, which may not be compatible with the host compiler. */ | |
46 | #undef assert | |
47 | #ifdef NDEBUG | |
48 | # define assert(e) | |
49 | #else | |
50 | # define assert(e) do { if (! (e)) abort (); } while (0) | |
51 | #endif | |
52 | ||
0021b564 JM |
53 | /* Decide whether we want to emit frame unwind information for the current |
54 | translation unit. */ | |
55 | ||
56 | int | |
57 | dwarf2out_do_frame () | |
58 | { | |
59 | return (write_symbols == DWARF2_DEBUG | |
60 | #ifdef DWARF2_UNWIND_INFO | |
61 | || (flag_exceptions && ! exceptions_via_longjmp) | |
62 | #endif | |
63 | ); | |
64 | } | |
65 | ||
66 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
67 | ||
71dfc51f RK |
68 | #ifndef __GNUC__ |
69 | #define inline | |
a3f97cbb JW |
70 | #endif |
71 | ||
eaf95893 RK |
72 | /* How to start an assembler comment. */ |
73 | #ifndef ASM_COMMENT_START | |
74 | #define ASM_COMMENT_START ";#" | |
75 | #endif | |
76 | ||
a3f97cbb JW |
77 | typedef struct dw_cfi_struct *dw_cfi_ref; |
78 | typedef struct dw_fde_struct *dw_fde_ref; | |
79 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
80 | |
81 | /* Call frames are described using a sequence of Call Frame | |
82 | Information instructions. The register number, offset | |
83 | and address fields are provided as possible operands; | |
84 | their use is selected by the opcode field. */ | |
71dfc51f | 85 | |
a3f97cbb | 86 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
87 | { |
88 | unsigned long dw_cfi_reg_num; | |
89 | long int dw_cfi_offset; | |
90 | char *dw_cfi_addr; | |
91 | } | |
a3f97cbb JW |
92 | dw_cfi_oprnd; |
93 | ||
94 | typedef struct dw_cfi_struct | |
71dfc51f RK |
95 | { |
96 | dw_cfi_ref dw_cfi_next; | |
97 | enum dwarf_call_frame_info dw_cfi_opc; | |
98 | dw_cfi_oprnd dw_cfi_oprnd1; | |
99 | dw_cfi_oprnd dw_cfi_oprnd2; | |
100 | } | |
a3f97cbb JW |
101 | dw_cfi_node; |
102 | ||
103 | /* All call frame descriptions (FDE's) in the GCC generated DWARF | |
4b674448 | 104 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
105 | the beginning of the .debug_frame section. This used of a single |
106 | CIE obviates the need to keep track of multiple CIE's | |
107 | in the DWARF generation routines below. */ | |
71dfc51f | 108 | |
a3f97cbb | 109 | typedef struct dw_fde_struct |
71dfc51f | 110 | { |
71dfc51f RK |
111 | char *dw_fde_begin; |
112 | char *dw_fde_current_label; | |
113 | char *dw_fde_end; | |
114 | dw_cfi_ref dw_fde_cfi; | |
115 | } | |
a3f97cbb JW |
116 | dw_fde_node; |
117 | ||
a3f97cbb JW |
118 | /* Maximum size (in bytes) of an artificially generated label. */ |
119 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
120 | ||
121 | /* Make sure we know the sizes of the various types dwarf can describe. These | |
122 | are only defaults. If the sizes are different for your target, you should | |
123 | override these values by defining the appropriate symbols in your tm.h | |
124 | file. */ | |
71dfc51f | 125 | |
a3f97cbb JW |
126 | #ifndef CHAR_TYPE_SIZE |
127 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
128 | #endif | |
a3f97cbb | 129 | #ifndef PTR_SIZE |
a9d38797 | 130 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
131 | #endif |
132 | ||
7e23cb16 JM |
133 | /* The size in bytes of a DWARF field indicating an offset or length |
134 | relative to a debug info section, specified to be 4 bytes in the DWARF-2 | |
135 | specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */ | |
71dfc51f | 136 | |
7e23cb16 JM |
137 | #ifndef DWARF_OFFSET_SIZE |
138 | #define DWARF_OFFSET_SIZE 4 | |
139 | #endif | |
140 | ||
9a666dda JM |
141 | #define DWARF_VERSION 2 |
142 | ||
7e23cb16 JM |
143 | /* Round SIZE up to the nearest BOUNDARY. */ |
144 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
145 | (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1)) | |
a3f97cbb | 146 | |
a3f97cbb | 147 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
469ac993 JM |
148 | #ifdef STACK_GROWS_DOWNWARD |
149 | #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD) | |
150 | #else | |
151 | #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD | |
152 | #endif | |
a3f97cbb | 153 | |
3f76745e JM |
154 | /* A pointer to the base of a table that contains frame description |
155 | information for each routine. */ | |
156 | static dw_fde_ref fde_table; | |
a3f97cbb | 157 | |
3f76745e JM |
158 | /* Number of elements currently allocated for fde_table. */ |
159 | static unsigned fde_table_allocated; | |
a94dbf2c | 160 | |
3f76745e JM |
161 | /* Number of elements in fde_table currently in use. */ |
162 | static unsigned fde_table_in_use; | |
a3f97cbb | 163 | |
3f76745e JM |
164 | /* Size (in elements) of increments by which we may expand the |
165 | fde_table. */ | |
166 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 167 | |
a94dbf2c JM |
168 | /* A list of call frame insns for the CIE. */ |
169 | static dw_cfi_ref cie_cfi_head; | |
170 | ||
a3f97cbb JW |
171 | /* The number of the current function definition for which debugging |
172 | information is being generated. These numbers range from 1 up to the | |
173 | maximum number of function definitions contained within the current | |
174 | compilation unit. These numbers are used to create unique label id's | |
175 | unique to each function definition. */ | |
4f988ea2 | 176 | static unsigned current_funcdef_number = 0; |
a3f97cbb JW |
177 | |
178 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
179 | attribute that accelerates the lookup of the FDE associated | |
180 | with the subprogram. This variable holds the table index of the FDE | |
181 | associated with the current function (body) definition. */ | |
182 | static unsigned current_funcdef_fde; | |
183 | ||
a3f97cbb | 184 | /* Forward declarations for functions defined in this file. */ |
71dfc51f RK |
185 | |
186 | static char *stripattributes PROTO((char *)); | |
3f76745e JM |
187 | static char *dwarf_cfi_name PROTO((unsigned)); |
188 | static dw_cfi_ref new_cfi PROTO((void)); | |
189 | static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref)); | |
71dfc51f RK |
190 | static unsigned long size_of_uleb128 PROTO((unsigned long)); |
191 | static unsigned long size_of_sleb128 PROTO((long)); | |
71dfc51f RK |
192 | static void output_uleb128 PROTO((unsigned long)); |
193 | static void output_sleb128 PROTO((long)); | |
71dfc51f RK |
194 | static void add_fde_cfi PROTO((char *, dw_cfi_ref)); |
195 | static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *, | |
196 | long *)); | |
197 | static void lookup_cfa PROTO((unsigned long *, long *)); | |
198 | static void reg_save PROTO((char *, unsigned, unsigned, | |
199 | long)); | |
200 | static void initial_return_save PROTO((rtx)); | |
71dfc51f | 201 | static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref)); |
3f76745e | 202 | static void output_call_frame_info PROTO((int)); |
71dfc51f | 203 | static unsigned reg_number PROTO((rtx)); |
a3f97cbb JW |
204 | |
205 | /* Definitions of defaults for assembler-dependent names of various | |
206 | pseudo-ops and section names. | |
207 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
208 | assembler. */ | |
71dfc51f | 209 | |
0021b564 | 210 | #ifdef OBJECT_FORMAT_ELF |
a3f97cbb JW |
211 | #ifndef UNALIGNED_SHORT_ASM_OP |
212 | #define UNALIGNED_SHORT_ASM_OP ".2byte" | |
213 | #endif | |
214 | #ifndef UNALIGNED_INT_ASM_OP | |
215 | #define UNALIGNED_INT_ASM_OP ".4byte" | |
216 | #endif | |
7e23cb16 JM |
217 | #ifndef UNALIGNED_DOUBLE_INT_ASM_OP |
218 | #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte" | |
219 | #endif | |
0021b564 JM |
220 | #endif /* OBJECT_FORMAT_ELF */ |
221 | ||
a3f97cbb JW |
222 | #ifndef ASM_BYTE_OP |
223 | #define ASM_BYTE_OP ".byte" | |
224 | #endif | |
225 | ||
7e23cb16 JM |
226 | /* Data and reference forms for relocatable data. */ |
227 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
228 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
229 | ||
a3f97cbb JW |
230 | /* Pseudo-op for defining a new section. */ |
231 | #ifndef SECTION_ASM_OP | |
232 | #define SECTION_ASM_OP ".section" | |
233 | #endif | |
234 | ||
235 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
236 | print the SECTION_ASM_OP and the section name. The default here works for | |
237 | almost all svr4 assemblers, except for the sparc, where the section name | |
238 | must be enclosed in double quotes. (See sparcv4.h). */ | |
239 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
240 | #ifdef PUSHSECTION_FORMAT |
241 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
242 | #else | |
243 | #define SECTION_FORMAT "\t%s\t%s\n" | |
244 | #endif | |
a3f97cbb JW |
245 | #endif |
246 | ||
a3f97cbb JW |
247 | #ifndef FRAME_SECTION |
248 | #define FRAME_SECTION ".debug_frame" | |
249 | #endif | |
a3f97cbb | 250 | |
5c90448c JM |
251 | #ifndef FUNC_BEGIN_LABEL |
252 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 253 | #endif |
5c90448c JM |
254 | #ifndef FUNC_END_LABEL |
255 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 256 | #endif |
a6ab3aad JM |
257 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
258 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 259 | #define CIE_LENGTH_LABEL "LLCIE" |
a6ab3aad JM |
260 | #define FDE_AFTER_SIZE_LABEL "LSFDE" |
261 | #define FDE_END_LABEL "LEFDE" | |
2ed2af28 | 262 | #define FDE_LENGTH_LABEL "LLFDE" |
a3f97cbb | 263 | |
a3f97cbb JW |
264 | /* Definitions of defaults for various types of primitive assembly language |
265 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 266 | but typically, that is unnecessary. */ |
71dfc51f | 267 | |
a3f97cbb JW |
268 | #ifndef ASM_OUTPUT_SECTION |
269 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
270 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
271 | #endif | |
272 | ||
0021b564 JM |
273 | #ifndef ASM_OUTPUT_DWARF_DATA1 |
274 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
275 | fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE) | |
276 | #endif | |
277 | ||
bb727b5a JM |
278 | #ifndef ASM_OUTPUT_DWARF_DELTA1 |
279 | #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \ | |
280 | do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \ | |
281 | assemble_name (FILE, LABEL1); \ | |
282 | fprintf (FILE, "-"); \ | |
283 | assemble_name (FILE, LABEL2); \ | |
284 | } while (0) | |
285 | #endif | |
286 | ||
0021b564 JM |
287 | #ifdef UNALIGNED_INT_ASM_OP |
288 | ||
289 | #ifndef UNALIGNED_OFFSET_ASM_OP | |
290 | #define UNALIGNED_OFFSET_ASM_OP \ | |
291 | (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
292 | #endif | |
293 | ||
294 | #ifndef UNALIGNED_WORD_ASM_OP | |
295 | #define UNALIGNED_WORD_ASM_OP \ | |
296 | (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
297 | #endif | |
298 | ||
a3f97cbb JW |
299 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
300 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
301 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ | |
302 | assemble_name (FILE, LABEL1); \ | |
303 | fprintf (FILE, "-"); \ | |
304 | assemble_name (FILE, LABEL2); \ | |
305 | } while (0) | |
306 | #endif | |
307 | ||
308 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
309 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
310 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
311 | assemble_name (FILE, LABEL1); \ | |
312 | fprintf (FILE, "-"); \ | |
313 | assemble_name (FILE, LABEL2); \ | |
314 | } while (0) | |
315 | #endif | |
316 | ||
7e23cb16 JM |
317 | #ifndef ASM_OUTPUT_DWARF_DELTA |
318 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
319 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
320 | assemble_name (FILE, LABEL1); \ | |
321 | fprintf (FILE, "-"); \ | |
322 | assemble_name (FILE, LABEL2); \ | |
323 | } while (0) | |
324 | #endif | |
325 | ||
326 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA | |
327 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
328 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ | |
329 | assemble_name (FILE, LABEL1); \ | |
330 | fprintf (FILE, "-"); \ | |
331 | assemble_name (FILE, LABEL2); \ | |
332 | } while (0) | |
333 | #endif | |
334 | ||
a3f97cbb JW |
335 | #ifndef ASM_OUTPUT_DWARF_ADDR |
336 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
7e23cb16 | 337 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ |
a3f97cbb JW |
338 | assemble_name (FILE, LABEL); \ |
339 | } while (0) | |
340 | #endif | |
341 | ||
342 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
343 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \ | |
7e23cb16 JM |
344 | fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR)) |
345 | #endif | |
346 | ||
7bb9fb0e JM |
347 | #ifndef ASM_OUTPUT_DWARF_OFFSET4 |
348 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ | |
349 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
350 | assemble_name (FILE, LABEL); \ | |
351 | } while (0) | |
352 | #endif | |
353 | ||
7e23cb16 JM |
354 | #ifndef ASM_OUTPUT_DWARF_OFFSET |
355 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ | |
356 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
357 | assemble_name (FILE, LABEL); \ | |
358 | } while (0) | |
a3f97cbb JW |
359 | #endif |
360 | ||
a3f97cbb JW |
361 | #ifndef ASM_OUTPUT_DWARF_DATA2 |
362 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
363 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) | |
364 | #endif | |
365 | ||
366 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
367 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
368 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) | |
369 | #endif | |
370 | ||
7e23cb16 JM |
371 | #ifndef ASM_OUTPUT_DWARF_DATA |
372 | #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \ | |
373 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \ | |
374 | (unsigned long) VALUE) | |
375 | #endif | |
376 | ||
377 | #ifndef ASM_OUTPUT_DWARF_ADDR_DATA | |
378 | #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \ | |
379 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \ | |
380 | (unsigned long) VALUE) | |
381 | #endif | |
382 | ||
a3f97cbb JW |
383 | #ifndef ASM_OUTPUT_DWARF_DATA8 |
384 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
385 | do { \ | |
386 | if (WORDS_BIG_ENDIAN) \ | |
387 | { \ | |
388 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
389 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
390 | } \ | |
391 | else \ | |
392 | { \ | |
393 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
394 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
395 | } \ | |
396 | } while (0) | |
397 | #endif | |
398 | ||
0021b564 JM |
399 | #else /* UNALIGNED_INT_ASM_OP */ |
400 | ||
401 | /* We don't have unaligned support, let's hope the normal output works for | |
402 | .debug_frame. */ | |
403 | ||
404 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
38a448ca | 405 | assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1) |
0021b564 | 406 | |
7bb9fb0e | 407 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ |
38a448ca | 408 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
7bb9fb0e | 409 | |
0021b564 | 410 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ |
38a448ca | 411 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
0021b564 JM |
412 | |
413 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
414 | assemble_integer (gen_rtx_MINUS (HImode, \ |
415 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
416 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
417 | 2, 1) |
418 | ||
419 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
420 | assemble_integer (gen_rtx_MINUS (SImode, \ |
421 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
422 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
423 | 4, 1) |
424 | ||
425 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
426 | assemble_integer (gen_rtx_MINUS (Pmode, \ |
427 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
428 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
429 | PTR_SIZE, 1) |
430 | ||
431 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
432 | ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2) | |
433 | ||
434 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
435 | assemble_integer (GEN_INT (VALUE), 4, 1) | |
436 | ||
437 | #endif /* UNALIGNED_INT_ASM_OP */ | |
438 | ||
2ed2af28 PDM |
439 | #ifdef SET_ASM_OP |
440 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
441 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
442 | do { \ | |
443 | fprintf (FILE, "\t%s\t", SET_ASM_OP); \ | |
444 | assemble_name (FILE, SY); \ | |
445 | fputc (',', FILE); \ | |
446 | assemble_name (FILE, HI); \ | |
447 | fputc ('-', FILE); \ | |
448 | assemble_name (FILE, LO); \ | |
449 | } while (0) | |
2ed2af28 PDM |
450 | #endif |
451 | #endif /* SET_ASM_OP */ | |
452 | ||
a6ab3aad | 453 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing |
2ed2af28 | 454 | newline is produced. When flag_debug_asm is asserted, we add commentary |
a6ab3aad JM |
455 | at the end of the line, so we must avoid output of a newline here. */ |
456 | #ifndef ASM_OUTPUT_DWARF_STRING | |
457 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
458 | do { \ | |
459 | register int slen = strlen(P); \ | |
460 | register char *p = (P); \ | |
461 | register int i; \ | |
462 | fprintf (FILE, "\t.ascii \""); \ | |
463 | for (i = 0; i < slen; i++) \ | |
464 | { \ | |
465 | register int c = p[i]; \ | |
466 | if (c == '\"' || c == '\\') \ | |
467 | putc ('\\', FILE); \ | |
468 | if (c >= ' ' && c < 0177) \ | |
469 | putc (c, FILE); \ | |
470 | else \ | |
471 | { \ | |
472 | fprintf (FILE, "\\%o", c); \ | |
473 | } \ | |
474 | } \ | |
475 | fprintf (FILE, "\\0\""); \ | |
476 | } \ | |
477 | while (0) | |
478 | #endif | |
479 | ||
c8cc5c4a | 480 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
481 | is the column for PC, or the first column after all of the hard |
482 | registers. */ | |
c8cc5c4a | 483 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
484 | #ifdef PC_REGNUM |
485 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
486 | #else | |
466446b0 | 487 | #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER |
a94dbf2c | 488 | #endif |
c8cc5c4a JM |
489 | #endif |
490 | ||
491 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 492 | default, we just provide columns for all registers. */ |
c8cc5c4a | 493 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 494 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 495 | #endif |
3f76745e | 496 | |
0021b564 JM |
497 | /* Hook used by __throw. */ |
498 | ||
499 | rtx | |
500 | expand_builtin_dwarf_fp_regnum () | |
501 | { | |
502 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
503 | } | |
504 | ||
a6ab3aad JM |
505 | /* The offset from the incoming value of %sp to the top of the stack frame |
506 | for the current function. */ | |
507 | #ifndef INCOMING_FRAME_SP_OFFSET | |
508 | #define INCOMING_FRAME_SP_OFFSET 0 | |
509 | #endif | |
510 | ||
71dfc51f | 511 | /* Return a pointer to a copy of the section string name S with all |
a3f97cbb | 512 | attributes stripped off. */ |
71dfc51f RK |
513 | |
514 | static inline char * | |
a3f97cbb | 515 | stripattributes (s) |
71dfc51f | 516 | char *s; |
a3f97cbb | 517 | { |
71dfc51f RK |
518 | char *stripped = xstrdup (s); |
519 | char *p = stripped; | |
520 | ||
a3f97cbb JW |
521 | while (*p && *p != ',') |
522 | p++; | |
71dfc51f | 523 | |
a3f97cbb JW |
524 | *p = '\0'; |
525 | return stripped; | |
526 | } | |
527 | ||
3f76745e | 528 | /* Return the register number described by a given RTL node. */ |
71dfc51f | 529 | |
3f76745e JM |
530 | static unsigned |
531 | reg_number (rtl) | |
532 | register rtx rtl; | |
a3f97cbb | 533 | { |
3f76745e | 534 | register unsigned regno = REGNO (rtl); |
a3f97cbb | 535 | |
3f76745e | 536 | if (regno >= FIRST_PSEUDO_REGISTER) |
a3f97cbb | 537 | { |
3f76745e JM |
538 | warning ("internal regno botch: regno = %d\n", regno); |
539 | regno = 0; | |
540 | } | |
a3f97cbb | 541 | |
3f76745e JM |
542 | regno = DBX_REGISTER_NUMBER (regno); |
543 | return regno; | |
544 | } | |
a3f97cbb | 545 | |
2f3ca9e7 JM |
546 | struct reg_size_range |
547 | { | |
548 | int beg; | |
549 | int end; | |
550 | int size; | |
551 | }; | |
552 | ||
553 | /* Given a register number in REG_TREE, return an rtx for its size in bytes. | |
554 | We do this in kind of a roundabout way, by building up a list of | |
555 | register size ranges and seeing where our register falls in one of those | |
556 | ranges. We need to do it this way because REG_TREE is not a constant, | |
557 | and the target macros were not designed to make this task easy. */ | |
558 | ||
559 | rtx | |
560 | expand_builtin_dwarf_reg_size (reg_tree, target) | |
561 | tree reg_tree; | |
562 | rtx target; | |
563 | { | |
31c8581d | 564 | enum machine_mode mode; |
d1485032 | 565 | int size; |
2f3ca9e7 JM |
566 | struct reg_size_range ranges[5]; |
567 | tree t, t2; | |
568 | ||
d1485032 JM |
569 | int i = 0; |
570 | int n_ranges = 0; | |
571 | int last_size = -1; | |
2f3ca9e7 | 572 | |
d1485032 | 573 | for (; i < FIRST_PSEUDO_REGISTER; ++i) |
2f3ca9e7 | 574 | { |
d1485032 JM |
575 | /* The return address is out of order on the MIPS, and we don't use |
576 | copy_reg for it anyway, so we don't care here how large it is. */ | |
577 | if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN) | |
578 | continue; | |
579 | ||
31c8581d JW |
580 | mode = reg_raw_mode[i]; |
581 | /* CCmode is arbitrarily given a size of 4 bytes. It is more useful | |
582 | to use the same size as word_mode, since that reduces the number | |
583 | of ranges we need. It should not matter, since the result should | |
584 | never be used for a condition code register anyways. */ | |
585 | if (mode == CCmode) | |
586 | mode = word_mode; | |
587 | size = GET_MODE_SIZE (mode); | |
588 | ||
d1485032 | 589 | if (size != last_size) |
2f3ca9e7 | 590 | { |
2f3ca9e7 | 591 | ranges[n_ranges].beg = i; |
d1485032 | 592 | ranges[n_ranges].size = last_size = GET_MODE_SIZE (reg_raw_mode[i]); |
2f3ca9e7 | 593 | ++n_ranges; |
3a88cbd1 JL |
594 | if (n_ranges >= 5) |
595 | abort (); | |
2f3ca9e7 | 596 | } |
d1485032 | 597 | ranges[n_ranges-1].end = i; |
2f3ca9e7 | 598 | } |
2f3ca9e7 JM |
599 | |
600 | /* The usual case: fp regs surrounded by general regs. */ | |
601 | if (n_ranges == 3 && ranges[0].size == ranges[2].size) | |
602 | { | |
3a88cbd1 JL |
603 | if ((DWARF_FRAME_REGNUM (ranges[1].end) |
604 | - DWARF_FRAME_REGNUM (ranges[1].beg)) | |
605 | != ranges[1].end - ranges[1].beg) | |
606 | abort (); | |
2f3ca9e7 JM |
607 | t = fold (build (GE_EXPR, integer_type_node, reg_tree, |
608 | build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0))); | |
609 | t2 = fold (build (LE_EXPR, integer_type_node, reg_tree, | |
610 | build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0))); | |
611 | t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2)); | |
612 | t = fold (build (COND_EXPR, integer_type_node, t, | |
613 | build_int_2 (ranges[1].size, 0), | |
614 | build_int_2 (ranges[0].size, 0))); | |
615 | } | |
616 | else | |
617 | { | |
618 | --n_ranges; | |
619 | t = build_int_2 (ranges[n_ranges].size, 0); | |
620 | size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg); | |
621 | for (; n_ranges--; ) | |
622 | { | |
3a88cbd1 JL |
623 | if ((DWARF_FRAME_REGNUM (ranges[n_ranges].end) |
624 | - DWARF_FRAME_REGNUM (ranges[n_ranges].beg)) | |
625 | != ranges[n_ranges].end - ranges[n_ranges].beg) | |
626 | abort (); | |
627 | if (DWARF_FRAME_REGNUM (ranges[n_ranges].beg) >= size) | |
628 | abort (); | |
2f3ca9e7 JM |
629 | size = DWARF_FRAME_REGNUM (ranges[n_ranges].beg); |
630 | t2 = fold (build (LE_EXPR, integer_type_node, reg_tree, | |
631 | build_int_2 (DWARF_FRAME_REGNUM | |
632 | (ranges[n_ranges].end), 0))); | |
633 | t = fold (build (COND_EXPR, integer_type_node, t2, | |
634 | build_int_2 (ranges[n_ranges].size, 0), t)); | |
635 | } | |
636 | } | |
637 | return expand_expr (t, target, Pmode, 0); | |
638 | } | |
639 | ||
3f76745e | 640 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 641 | |
3f76745e JM |
642 | static char * |
643 | dwarf_cfi_name (cfi_opc) | |
644 | register unsigned cfi_opc; | |
645 | { | |
646 | switch (cfi_opc) | |
647 | { | |
648 | case DW_CFA_advance_loc: | |
649 | return "DW_CFA_advance_loc"; | |
650 | case DW_CFA_offset: | |
651 | return "DW_CFA_offset"; | |
652 | case DW_CFA_restore: | |
653 | return "DW_CFA_restore"; | |
654 | case DW_CFA_nop: | |
655 | return "DW_CFA_nop"; | |
656 | case DW_CFA_set_loc: | |
657 | return "DW_CFA_set_loc"; | |
658 | case DW_CFA_advance_loc1: | |
659 | return "DW_CFA_advance_loc1"; | |
660 | case DW_CFA_advance_loc2: | |
661 | return "DW_CFA_advance_loc2"; | |
662 | case DW_CFA_advance_loc4: | |
663 | return "DW_CFA_advance_loc4"; | |
664 | case DW_CFA_offset_extended: | |
665 | return "DW_CFA_offset_extended"; | |
666 | case DW_CFA_restore_extended: | |
667 | return "DW_CFA_restore_extended"; | |
668 | case DW_CFA_undefined: | |
669 | return "DW_CFA_undefined"; | |
670 | case DW_CFA_same_value: | |
671 | return "DW_CFA_same_value"; | |
672 | case DW_CFA_register: | |
673 | return "DW_CFA_register"; | |
674 | case DW_CFA_remember_state: | |
675 | return "DW_CFA_remember_state"; | |
676 | case DW_CFA_restore_state: | |
677 | return "DW_CFA_restore_state"; | |
678 | case DW_CFA_def_cfa: | |
679 | return "DW_CFA_def_cfa"; | |
680 | case DW_CFA_def_cfa_register: | |
681 | return "DW_CFA_def_cfa_register"; | |
682 | case DW_CFA_def_cfa_offset: | |
683 | return "DW_CFA_def_cfa_offset"; | |
c53aa195 | 684 | |
3f76745e JM |
685 | /* SGI/MIPS specific */ |
686 | case DW_CFA_MIPS_advance_loc8: | |
687 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
688 | |
689 | /* GNU extensions */ | |
690 | case DW_CFA_GNU_window_save: | |
691 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
692 | case DW_CFA_GNU_args_size: |
693 | return "DW_CFA_GNU_args_size"; | |
c53aa195 | 694 | |
3f76745e JM |
695 | default: |
696 | return "DW_CFA_<unknown>"; | |
697 | } | |
698 | } | |
a3f97cbb | 699 | |
3f76745e | 700 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 701 | |
3f76745e JM |
702 | static inline dw_cfi_ref |
703 | new_cfi () | |
704 | { | |
705 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 706 | |
3f76745e JM |
707 | cfi->dw_cfi_next = NULL; |
708 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
709 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 710 | |
3f76745e JM |
711 | return cfi; |
712 | } | |
a3f97cbb | 713 | |
3f76745e | 714 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 715 | |
3f76745e JM |
716 | static inline void |
717 | add_cfi (list_head, cfi) | |
718 | register dw_cfi_ref *list_head; | |
719 | register dw_cfi_ref cfi; | |
720 | { | |
721 | register dw_cfi_ref *p; | |
a3f97cbb | 722 | |
3f76745e JM |
723 | /* Find the end of the chain. */ |
724 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
725 | ; | |
726 | ||
727 | *p = cfi; | |
a3f97cbb JW |
728 | } |
729 | ||
3f76745e | 730 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 731 | |
c53aa195 | 732 | char * |
3f76745e | 733 | dwarf2out_cfi_label () |
a3f97cbb | 734 | { |
3f76745e JM |
735 | static char label[20]; |
736 | static unsigned long label_num = 0; | |
737 | ||
738 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); | |
739 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
740 | ||
741 | return label; | |
a3f97cbb JW |
742 | } |
743 | ||
3f76745e JM |
744 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
745 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 746 | |
3f76745e JM |
747 | static void |
748 | add_fde_cfi (label, cfi) | |
749 | register char *label; | |
750 | register dw_cfi_ref cfi; | |
a3f97cbb | 751 | { |
3f76745e JM |
752 | if (label) |
753 | { | |
754 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 755 | |
3f76745e JM |
756 | if (*label == 0) |
757 | label = dwarf2out_cfi_label (); | |
71dfc51f | 758 | |
3f76745e JM |
759 | if (fde->dw_fde_current_label == NULL |
760 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
761 | { | |
762 | register dw_cfi_ref xcfi; | |
a3f97cbb | 763 | |
3f76745e | 764 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 765 | |
3f76745e JM |
766 | /* Set the location counter to the new label. */ |
767 | xcfi = new_cfi (); | |
768 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
769 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
770 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
771 | } | |
71dfc51f | 772 | |
3f76745e JM |
773 | add_cfi (&fde->dw_fde_cfi, cfi); |
774 | } | |
775 | ||
776 | else | |
777 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
778 | } |
779 | ||
3f76745e | 780 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 781 | |
3f76745e JM |
782 | static inline void |
783 | lookup_cfa_1 (cfi, regp, offsetp) | |
784 | register dw_cfi_ref cfi; | |
785 | register unsigned long *regp; | |
786 | register long *offsetp; | |
a3f97cbb | 787 | { |
3f76745e JM |
788 | switch (cfi->dw_cfi_opc) |
789 | { | |
790 | case DW_CFA_def_cfa_offset: | |
791 | *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset; | |
792 | break; | |
793 | case DW_CFA_def_cfa_register: | |
794 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
795 | break; | |
796 | case DW_CFA_def_cfa: | |
797 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
798 | *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
799 | break; | |
e9a25f70 JL |
800 | default: |
801 | break; | |
3f76745e | 802 | } |
a3f97cbb JW |
803 | } |
804 | ||
3f76745e | 805 | /* Find the previous value for the CFA. */ |
71dfc51f | 806 | |
3f76745e JM |
807 | static void |
808 | lookup_cfa (regp, offsetp) | |
809 | register unsigned long *regp; | |
810 | register long *offsetp; | |
a3f97cbb | 811 | { |
3f76745e JM |
812 | register dw_cfi_ref cfi; |
813 | ||
814 | *regp = (unsigned long) -1; | |
815 | *offsetp = 0; | |
816 | ||
817 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
818 | lookup_cfa_1 (cfi, regp, offsetp); | |
819 | ||
820 | if (fde_table_in_use) | |
a3f97cbb | 821 | { |
3f76745e JM |
822 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
823 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
824 | lookup_cfa_1 (cfi, regp, offsetp); | |
a3f97cbb JW |
825 | } |
826 | } | |
827 | ||
3f76745e | 828 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
a6ab3aad | 829 | static unsigned long cfa_reg; |
3f76745e | 830 | static long cfa_offset; |
71dfc51f | 831 | |
3f76745e JM |
832 | /* The register used for saving registers to the stack, and its offset |
833 | from the CFA. */ | |
834 | static unsigned cfa_store_reg; | |
835 | static long cfa_store_offset; | |
836 | ||
0021b564 JM |
837 | /* The running total of the size of arguments pushed onto the stack. */ |
838 | static long args_size; | |
839 | ||
3f76745e JM |
840 | /* Entry point to update the canonical frame address (CFA). |
841 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
842 | calculated from REG+OFFSET. */ | |
843 | ||
844 | void | |
845 | dwarf2out_def_cfa (label, reg, offset) | |
846 | register char *label; | |
847 | register unsigned reg; | |
848 | register long offset; | |
a3f97cbb | 849 | { |
3f76745e JM |
850 | register dw_cfi_ref cfi; |
851 | unsigned long old_reg; | |
852 | long old_offset; | |
853 | ||
5bef9b1f JM |
854 | cfa_reg = reg; |
855 | cfa_offset = offset; | |
856 | if (cfa_store_reg == reg) | |
857 | cfa_store_offset = offset; | |
858 | ||
3f76745e JM |
859 | reg = DWARF_FRAME_REGNUM (reg); |
860 | lookup_cfa (&old_reg, &old_offset); | |
861 | ||
862 | if (reg == old_reg && offset == old_offset) | |
863 | return; | |
864 | ||
865 | cfi = new_cfi (); | |
866 | ||
867 | if (reg == old_reg) | |
a3f97cbb | 868 | { |
3f76745e JM |
869 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
870 | cfi->dw_cfi_oprnd1.dw_cfi_offset = offset; | |
871 | } | |
a3f97cbb | 872 | |
3f76745e JM |
873 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
874 | else if (offset == old_offset && old_reg != (unsigned long) -1) | |
875 | { | |
876 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; | |
877 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
878 | } | |
879 | #endif | |
a3f97cbb | 880 | |
3f76745e JM |
881 | else |
882 | { | |
883 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
884 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
885 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
a3f97cbb | 886 | } |
3f76745e JM |
887 | |
888 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
889 | } |
890 | ||
3f76745e JM |
891 | /* Add the CFI for saving a register. REG is the CFA column number. |
892 | LABEL is passed to add_fde_cfi. | |
893 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
894 | otherwise it is saved in SREG. */ | |
71dfc51f | 895 | |
3f76745e JM |
896 | static void |
897 | reg_save (label, reg, sreg, offset) | |
898 | register char * label; | |
899 | register unsigned reg; | |
900 | register unsigned sreg; | |
901 | register long offset; | |
a3f97cbb | 902 | { |
3f76745e JM |
903 | register dw_cfi_ref cfi = new_cfi (); |
904 | ||
905 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
906 | ||
907 | if (sreg == -1) | |
a3f97cbb | 908 | { |
3f76745e JM |
909 | if (reg & ~0x3f) |
910 | /* The register number won't fit in 6 bits, so we have to use | |
911 | the long form. */ | |
912 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
913 | else | |
914 | cfi->dw_cfi_opc = DW_CFA_offset; | |
915 | ||
916 | offset /= DWARF_CIE_DATA_ALIGNMENT; | |
3a88cbd1 JL |
917 | if (offset < 0) |
918 | abort (); | |
3f76745e JM |
919 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
920 | } | |
921 | else | |
922 | { | |
923 | cfi->dw_cfi_opc = DW_CFA_register; | |
924 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
925 | } | |
926 | ||
927 | add_fde_cfi (label, cfi); | |
928 | } | |
929 | ||
c53aa195 JM |
930 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
931 | This CFI tells the unwinder that it needs to restore the window registers | |
932 | from the previous frame's window save area. | |
933 | ||
934 | ??? Perhaps we should note in the CIE where windows are saved (instead of | |
935 | assuming 0(cfa)) and what registers are in the window. */ | |
936 | ||
937 | void | |
938 | dwarf2out_window_save (label) | |
939 | register char * label; | |
940 | { | |
941 | register dw_cfi_ref cfi = new_cfi (); | |
942 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
943 | add_fde_cfi (label, cfi); | |
944 | } | |
945 | ||
0021b564 JM |
946 | /* Add a CFI to update the running total of the size of arguments |
947 | pushed onto the stack. */ | |
948 | ||
949 | void | |
950 | dwarf2out_args_size (label, size) | |
951 | char *label; | |
952 | long size; | |
953 | { | |
954 | register dw_cfi_ref cfi = new_cfi (); | |
955 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; | |
956 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
957 | add_fde_cfi (label, cfi); | |
958 | } | |
959 | ||
c53aa195 JM |
960 | /* Entry point for saving a register to the stack. REG is the GCC register |
961 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
962 | |
963 | void | |
964 | dwarf2out_reg_save (label, reg, offset) | |
965 | register char * label; | |
966 | register unsigned reg; | |
967 | register long offset; | |
968 | { | |
969 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
970 | } | |
971 | ||
c53aa195 JM |
972 | /* Entry point for saving the return address in the stack. |
973 | LABEL and OFFSET are passed to reg_save. */ | |
974 | ||
975 | void | |
976 | dwarf2out_return_save (label, offset) | |
977 | register char * label; | |
978 | register long offset; | |
979 | { | |
980 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
981 | } | |
982 | ||
983 | /* Entry point for saving the return address in a register. | |
984 | LABEL and SREG are passed to reg_save. */ | |
985 | ||
986 | void | |
987 | dwarf2out_return_reg (label, sreg) | |
988 | register char * label; | |
989 | register unsigned sreg; | |
990 | { | |
991 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
992 | } | |
993 | ||
3f76745e JM |
994 | /* Record the initial position of the return address. RTL is |
995 | INCOMING_RETURN_ADDR_RTX. */ | |
996 | ||
997 | static void | |
998 | initial_return_save (rtl) | |
999 | register rtx rtl; | |
1000 | { | |
1001 | unsigned reg = -1; | |
1002 | long offset = 0; | |
1003 | ||
1004 | switch (GET_CODE (rtl)) | |
1005 | { | |
1006 | case REG: | |
1007 | /* RA is in a register. */ | |
1008 | reg = reg_number (rtl); | |
1009 | break; | |
1010 | case MEM: | |
1011 | /* RA is on the stack. */ | |
1012 | rtl = XEXP (rtl, 0); | |
1013 | switch (GET_CODE (rtl)) | |
1014 | { | |
1015 | case REG: | |
3a88cbd1 JL |
1016 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
1017 | abort (); | |
3f76745e JM |
1018 | offset = 0; |
1019 | break; | |
1020 | case PLUS: | |
3a88cbd1 JL |
1021 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1022 | abort (); | |
3f76745e JM |
1023 | offset = INTVAL (XEXP (rtl, 1)); |
1024 | break; | |
1025 | case MINUS: | |
3a88cbd1 JL |
1026 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1027 | abort (); | |
3f76745e JM |
1028 | offset = -INTVAL (XEXP (rtl, 1)); |
1029 | break; | |
1030 | default: | |
1031 | abort (); | |
1032 | } | |
1033 | break; | |
c53aa195 JM |
1034 | case PLUS: |
1035 | /* The return address is at some offset from any value we can | |
1036 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
1037 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
1038 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
1039 | abort (); | |
c53aa195 JM |
1040 | initial_return_save (XEXP (rtl, 0)); |
1041 | return; | |
a3f97cbb | 1042 | default: |
3f76745e | 1043 | abort (); |
a3f97cbb | 1044 | } |
3f76745e | 1045 | |
a6ab3aad | 1046 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset); |
a3f97cbb JW |
1047 | } |
1048 | ||
0021b564 JM |
1049 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1050 | make a note of it if it does. EH uses this information to find out how | |
1051 | much extra space it needs to pop off the stack. */ | |
1052 | ||
1053 | static void | |
1054 | dwarf2out_stack_adjust (insn) | |
1055 | rtx insn; | |
1056 | { | |
0021b564 JM |
1057 | long offset; |
1058 | char *label; | |
1059 | ||
6020d360 | 1060 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1061 | { |
6020d360 JM |
1062 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1063 | the compiler will have already emitted a stack adjustment, but | |
1064 | doesn't bother for calls to noreturn functions. */ | |
1065 | #ifdef STACK_GROWS_DOWNWARD | |
1066 | offset = -args_size; | |
1067 | #else | |
1068 | offset = args_size; | |
1069 | #endif | |
0021b564 | 1070 | } |
6020d360 | 1071 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 1072 | { |
6020d360 JM |
1073 | rtx src, dest; |
1074 | enum rtx_code code; | |
1075 | ||
1076 | insn = PATTERN (insn); | |
1077 | src = SET_SRC (insn); | |
1078 | dest = SET_DEST (insn); | |
0021b564 | 1079 | |
6020d360 JM |
1080 | if (dest == stack_pointer_rtx) |
1081 | { | |
1082 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
1083 | code = GET_CODE (src); | |
1084 | if (! (code == PLUS || code == MINUS) | |
1085 | || XEXP (src, 0) != stack_pointer_rtx | |
1086 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1087 | return; | |
1088 | ||
1089 | offset = INTVAL (XEXP (src, 1)); | |
1090 | } | |
1091 | else if (GET_CODE (dest) == MEM) | |
1092 | { | |
1093 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1094 | src = XEXP (dest, 0); | |
1095 | code = GET_CODE (src); | |
1096 | ||
1097 | if (! (code == PRE_DEC || code == PRE_INC) | |
1098 | || XEXP (src, 0) != stack_pointer_rtx) | |
1099 | return; | |
1100 | ||
1101 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1102 | } | |
1103 | else | |
0021b564 JM |
1104 | return; |
1105 | ||
6020d360 JM |
1106 | if (code == PLUS || code == PRE_INC) |
1107 | offset = -offset; | |
0021b564 JM |
1108 | } |
1109 | else | |
1110 | return; | |
1111 | ||
6020d360 JM |
1112 | if (offset == 0) |
1113 | return; | |
1114 | ||
0021b564 JM |
1115 | if (cfa_reg == STACK_POINTER_REGNUM) |
1116 | cfa_offset += offset; | |
1117 | ||
1118 | #ifndef STACK_GROWS_DOWNWARD | |
1119 | offset = -offset; | |
1120 | #endif | |
1121 | args_size += offset; | |
1122 | if (args_size < 0) | |
1123 | args_size = 0; | |
1124 | ||
1125 | label = dwarf2out_cfi_label (); | |
1126 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1127 | dwarf2out_args_size (label, args_size); | |
1128 | } | |
1129 | ||
3f76745e JM |
1130 | /* Record call frame debugging information for INSN, which either |
1131 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1132 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1133 | |
3f76745e JM |
1134 | void |
1135 | dwarf2out_frame_debug (insn) | |
1136 | rtx insn; | |
a3f97cbb | 1137 | { |
3f76745e JM |
1138 | char *label; |
1139 | rtx src, dest; | |
1140 | long offset; | |
1141 | ||
1142 | /* A temporary register used in adjusting SP or setting up the store_reg. */ | |
1143 | static unsigned cfa_temp_reg; | |
1144 | static long cfa_temp_value; | |
1145 | ||
1146 | if (insn == NULL_RTX) | |
a3f97cbb | 1147 | { |
3f76745e | 1148 | /* Set up state for generating call frame debug info. */ |
a6ab3aad | 1149 | lookup_cfa (&cfa_reg, &cfa_offset); |
3a88cbd1 JL |
1150 | if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) |
1151 | abort (); | |
3f76745e | 1152 | cfa_reg = STACK_POINTER_REGNUM; |
a6ab3aad JM |
1153 | cfa_store_reg = cfa_reg; |
1154 | cfa_store_offset = cfa_offset; | |
3f76745e JM |
1155 | cfa_temp_reg = -1; |
1156 | cfa_temp_value = 0; | |
1157 | return; | |
1158 | } | |
1159 | ||
0021b564 JM |
1160 | if (! RTX_FRAME_RELATED_P (insn)) |
1161 | { | |
6020d360 | 1162 | dwarf2out_stack_adjust (insn); |
0021b564 JM |
1163 | return; |
1164 | } | |
1165 | ||
3f76745e JM |
1166 | label = dwarf2out_cfi_label (); |
1167 | ||
1168 | insn = PATTERN (insn); | |
267c09ab JM |
1169 | /* Assume that in a PARALLEL prologue insn, only the first elt is |
1170 | significant. Currently this is true. */ | |
1171 | if (GET_CODE (insn) == PARALLEL) | |
1172 | insn = XVECEXP (insn, 0, 0); | |
3a88cbd1 JL |
1173 | if (GET_CODE (insn) != SET) |
1174 | abort (); | |
3f76745e JM |
1175 | |
1176 | src = SET_SRC (insn); | |
1177 | dest = SET_DEST (insn); | |
1178 | ||
1179 | switch (GET_CODE (dest)) | |
1180 | { | |
1181 | case REG: | |
1182 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
1183 | relative to the current CFA register. */ | |
1184 | switch (GET_CODE (src)) | |
1185 | { | |
1186 | /* Setting FP from SP. */ | |
1187 | case REG: | |
3a88cbd1 JL |
1188 | if (cfa_reg != REGNO (src)) |
1189 | abort (); | |
1190 | if (REGNO (dest) != STACK_POINTER_REGNUM | |
1191 | && !(frame_pointer_needed | |
1192 | && REGNO (dest) == HARD_FRAME_POINTER_REGNUM)) | |
1193 | abort (); | |
3f76745e JM |
1194 | cfa_reg = REGNO (dest); |
1195 | break; | |
1196 | ||
1197 | case PLUS: | |
1198 | case MINUS: | |
1199 | if (dest == stack_pointer_rtx) | |
1200 | { | |
1201 | /* Adjusting SP. */ | |
1202 | switch (GET_CODE (XEXP (src, 1))) | |
1203 | { | |
1204 | case CONST_INT: | |
1205 | offset = INTVAL (XEXP (src, 1)); | |
1206 | break; | |
1207 | case REG: | |
3a88cbd1 JL |
1208 | if (REGNO (XEXP (src, 1)) != cfa_temp_reg) |
1209 | abort (); | |
3f76745e JM |
1210 | offset = cfa_temp_value; |
1211 | break; | |
1212 | default: | |
1213 | abort (); | |
1214 | } | |
1215 | ||
0021b564 JM |
1216 | if (XEXP (src, 0) == hard_frame_pointer_rtx) |
1217 | { | |
1218 | /* Restoring SP from FP in the epilogue. */ | |
3a88cbd1 JL |
1219 | if (cfa_reg != HARD_FRAME_POINTER_REGNUM) |
1220 | abort (); | |
0021b564 JM |
1221 | cfa_reg = STACK_POINTER_REGNUM; |
1222 | } | |
3a88cbd1 JL |
1223 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1224 | abort (); | |
0021b564 | 1225 | |
3f76745e JM |
1226 | if (GET_CODE (src) == PLUS) |
1227 | offset = -offset; | |
1228 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1229 | cfa_offset += offset; | |
1230 | if (cfa_store_reg == STACK_POINTER_REGNUM) | |
1231 | cfa_store_offset += offset; | |
3f76745e | 1232 | } |
63d96a95 GK |
1233 | else if (dest == hard_frame_pointer_rtx) |
1234 | { | |
1235 | /* Either setting the FP from an offset of the SP, | |
1236 | or adjusting the FP */ | |
1237 | if (! frame_pointer_needed | |
1238 | || REGNO (dest) != HARD_FRAME_POINTER_REGNUM) | |
1239 | abort (); | |
1240 | ||
1241 | if (XEXP (src, 0) == stack_pointer_rtx | |
1242 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1243 | { | |
1244 | if (cfa_reg != STACK_POINTER_REGNUM) | |
1245 | abort (); | |
1246 | offset = INTVAL (XEXP (src, 1)); | |
1247 | if (GET_CODE (src) == PLUS) | |
1248 | offset = -offset; | |
1249 | cfa_offset += offset; | |
1250 | cfa_reg = HARD_FRAME_POINTER_REGNUM; | |
1251 | } | |
1252 | else if (XEXP (src, 0) == hard_frame_pointer_rtx | |
1253 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1254 | { | |
1255 | if (cfa_reg != HARD_FRAME_POINTER_REGNUM) | |
1256 | abort (); | |
1257 | offset = INTVAL (XEXP (src, 1)); | |
1258 | if (GET_CODE (src) == PLUS) | |
1259 | offset = -offset; | |
1260 | cfa_offset += offset; | |
1261 | } | |
1262 | ||
1263 | else | |
1264 | abort(); | |
1265 | } | |
3f76745e JM |
1266 | else |
1267 | { | |
3a88cbd1 | 1268 | if (GET_CODE (src) != PLUS |
31d52528 | 1269 | || XEXP (src, 1) != stack_pointer_rtx) |
3a88cbd1 JL |
1270 | abort (); |
1271 | if (GET_CODE (XEXP (src, 0)) != REG | |
1272 | || REGNO (XEXP (src, 0)) != cfa_temp_reg) | |
1273 | abort (); | |
218c2cdb JW |
1274 | if (cfa_reg != STACK_POINTER_REGNUM) |
1275 | abort (); | |
3f76745e | 1276 | cfa_store_reg = REGNO (dest); |
218c2cdb | 1277 | cfa_store_offset = cfa_offset - cfa_temp_value; |
3f76745e JM |
1278 | } |
1279 | break; | |
1280 | ||
1281 | case CONST_INT: | |
1282 | cfa_temp_reg = REGNO (dest); | |
1283 | cfa_temp_value = INTVAL (src); | |
1284 | break; | |
1285 | ||
ef76d03b | 1286 | case IOR: |
3a88cbd1 JL |
1287 | if (GET_CODE (XEXP (src, 0)) != REG |
1288 | || REGNO (XEXP (src, 0)) != cfa_temp_reg | |
1289 | || REGNO (dest) != cfa_temp_reg | |
1290 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1291 | abort (); | |
ef76d03b JW |
1292 | cfa_temp_value |= INTVAL (XEXP (src, 1)); |
1293 | break; | |
1294 | ||
3f76745e JM |
1295 | default: |
1296 | abort (); | |
1297 | } | |
1298 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1299 | break; | |
1300 | ||
1301 | case MEM: | |
1302 | /* Saving a register to the stack. Make sure dest is relative to the | |
1303 | CFA register. */ | |
3a88cbd1 JL |
1304 | if (GET_CODE (src) != REG) |
1305 | abort (); | |
3f76745e JM |
1306 | switch (GET_CODE (XEXP (dest, 0))) |
1307 | { | |
1308 | /* With a push. */ | |
1309 | case PRE_INC: | |
1310 | case PRE_DEC: | |
1311 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
0021b564 | 1312 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) |
3f76745e JM |
1313 | offset = -offset; |
1314 | ||
3a88cbd1 JL |
1315 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
1316 | || cfa_store_reg != STACK_POINTER_REGNUM) | |
1317 | abort (); | |
3f76745e JM |
1318 | cfa_store_offset += offset; |
1319 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1320 | cfa_offset = cfa_store_offset; | |
1321 | ||
1322 | offset = -cfa_store_offset; | |
1323 | break; | |
1324 | ||
1325 | /* With an offset. */ | |
1326 | case PLUS: | |
1327 | case MINUS: | |
1328 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); | |
1329 | if (GET_CODE (src) == MINUS) | |
1330 | offset = -offset; | |
1331 | ||
3a88cbd1 JL |
1332 | if (cfa_store_reg != REGNO (XEXP (XEXP (dest, 0), 0))) |
1333 | abort (); | |
3f76745e JM |
1334 | offset -= cfa_store_offset; |
1335 | break; | |
1336 | ||
1337 | default: | |
1338 | abort (); | |
1339 | } | |
1340 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1341 | dwarf2out_reg_save (label, REGNO (src), offset); | |
1342 | break; | |
1343 | ||
1344 | default: | |
1345 | abort (); | |
1346 | } | |
1347 | } | |
1348 | ||
1349 | /* Return the size of an unsigned LEB128 quantity. */ | |
1350 | ||
1351 | static inline unsigned long | |
1352 | size_of_uleb128 (value) | |
1353 | register unsigned long value; | |
1354 | { | |
1355 | register unsigned long size = 0; | |
1356 | register unsigned byte; | |
1357 | ||
1358 | do | |
1359 | { | |
1360 | byte = (value & 0x7f); | |
1361 | value >>= 7; | |
1362 | size += 1; | |
1363 | } | |
1364 | while (value != 0); | |
1365 | ||
1366 | return size; | |
1367 | } | |
1368 | ||
1369 | /* Return the size of a signed LEB128 quantity. */ | |
1370 | ||
1371 | static inline unsigned long | |
1372 | size_of_sleb128 (value) | |
1373 | register long value; | |
1374 | { | |
1375 | register unsigned long size = 0; | |
1376 | register unsigned byte; | |
1377 | ||
1378 | do | |
1379 | { | |
1380 | byte = (value & 0x7f); | |
1381 | value >>= 7; | |
1382 | size += 1; | |
1383 | } | |
1384 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
1385 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1386 | ||
1387 | return size; | |
1388 | } | |
1389 | ||
3f76745e JM |
1390 | /* Output an unsigned LEB128 quantity. */ |
1391 | ||
1392 | static void | |
1393 | output_uleb128 (value) | |
1394 | register unsigned long value; | |
1395 | { | |
1396 | unsigned long save_value = value; | |
1397 | ||
1398 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1399 | do | |
1400 | { | |
1401 | register unsigned byte = (value & 0x7f); | |
1402 | value >>= 7; | |
1403 | if (value != 0) | |
1404 | /* More bytes to follow. */ | |
1405 | byte |= 0x80; | |
1406 | ||
1407 | fprintf (asm_out_file, "0x%x", byte); | |
1408 | if (value != 0) | |
1409 | fprintf (asm_out_file, ","); | |
1410 | } | |
1411 | while (value != 0); | |
1412 | ||
c5cec899 | 1413 | if (flag_debug_asm) |
3f76745e JM |
1414 | fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value); |
1415 | } | |
1416 | ||
1417 | /* Output an signed LEB128 quantity. */ | |
1418 | ||
1419 | static void | |
1420 | output_sleb128 (value) | |
1421 | register long value; | |
1422 | { | |
1423 | register int more; | |
1424 | register unsigned byte; | |
1425 | long save_value = value; | |
1426 | ||
1427 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1428 | do | |
1429 | { | |
1430 | byte = (value & 0x7f); | |
1431 | /* arithmetic shift */ | |
1432 | value >>= 7; | |
1433 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
1434 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1435 | if (more) | |
1436 | byte |= 0x80; | |
1437 | ||
1438 | fprintf (asm_out_file, "0x%x", byte); | |
1439 | if (more) | |
1440 | fprintf (asm_out_file, ","); | |
1441 | } | |
1442 | ||
1443 | while (more); | |
c5cec899 | 1444 | if (flag_debug_asm) |
3f76745e JM |
1445 | fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value); |
1446 | } | |
1447 | ||
1448 | /* Output a Call Frame Information opcode and its operand(s). */ | |
1449 | ||
1450 | static void | |
1451 | output_cfi (cfi, fde) | |
1452 | register dw_cfi_ref cfi; | |
1453 | register dw_fde_ref fde; | |
1454 | { | |
1455 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1456 | { | |
1457 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1458 | cfi->dw_cfi_opc | |
1459 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
c5cec899 | 1460 | if (flag_debug_asm) |
3f76745e JM |
1461 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x", |
1462 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1463 | fputc ('\n', asm_out_file); | |
1464 | } | |
1465 | ||
1466 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
1467 | { | |
1468 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1469 | cfi->dw_cfi_opc | |
1470 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1471 | if (flag_debug_asm) |
3f76745e JM |
1472 | fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x", |
1473 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1474 | ||
1475 | fputc ('\n', asm_out_file); | |
1476 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1477 | fputc ('\n', asm_out_file); | |
1478 | } | |
1479 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1480 | { | |
1481 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1482 | cfi->dw_cfi_opc | |
1483 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1484 | if (flag_debug_asm) |
3f76745e JM |
1485 | fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x", |
1486 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1487 | ||
1488 | fputc ('\n', asm_out_file); | |
1489 | } | |
1490 | else | |
1491 | { | |
1492 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
c5cec899 | 1493 | if (flag_debug_asm) |
3f76745e JM |
1494 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
1495 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
1496 | ||
1497 | fputc ('\n', asm_out_file); | |
1498 | switch (cfi->dw_cfi_opc) | |
1499 | { | |
1500 | case DW_CFA_set_loc: | |
1501 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr); | |
1502 | fputc ('\n', asm_out_file); | |
1503 | break; | |
1504 | case DW_CFA_advance_loc1: | |
bb727b5a JM |
1505 | ASM_OUTPUT_DWARF_DELTA1 (asm_out_file, |
1506 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1507 | fde->dw_fde_current_label); | |
1508 | fputc ('\n', asm_out_file); | |
1509 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e JM |
1510 | break; |
1511 | case DW_CFA_advance_loc2: | |
1512 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, | |
1513 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1514 | fde->dw_fde_current_label); | |
1515 | fputc ('\n', asm_out_file); | |
1516 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1517 | break; | |
1518 | case DW_CFA_advance_loc4: | |
1519 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
1520 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1521 | fde->dw_fde_current_label); | |
1522 | fputc ('\n', asm_out_file); | |
1523 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1524 | break; | |
1525 | #ifdef MIPS_DEBUGGING_INFO | |
1526 | case DW_CFA_MIPS_advance_loc8: | |
1527 | /* TODO: not currently implemented. */ | |
1528 | abort (); | |
1529 | break; | |
1530 | #endif | |
1531 | case DW_CFA_offset_extended: | |
1532 | case DW_CFA_def_cfa: | |
1533 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1534 | fputc ('\n', asm_out_file); | |
1535 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1536 | fputc ('\n', asm_out_file); | |
1537 | break; | |
1538 | case DW_CFA_restore_extended: | |
1539 | case DW_CFA_undefined: | |
1540 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1541 | fputc ('\n', asm_out_file); | |
1542 | break; | |
1543 | case DW_CFA_same_value: | |
1544 | case DW_CFA_def_cfa_register: | |
1545 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1546 | fputc ('\n', asm_out_file); | |
1547 | break; | |
1548 | case DW_CFA_register: | |
1549 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1550 | fputc ('\n', asm_out_file); | |
1551 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
1552 | fputc ('\n', asm_out_file); | |
1553 | break; | |
1554 | case DW_CFA_def_cfa_offset: | |
1555 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1556 | fputc ('\n', asm_out_file); | |
1557 | break; | |
c53aa195 JM |
1558 | case DW_CFA_GNU_window_save: |
1559 | break; | |
0021b564 JM |
1560 | case DW_CFA_GNU_args_size: |
1561 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1562 | fputc ('\n', asm_out_file); | |
1563 | break; | |
3f76745e JM |
1564 | default: |
1565 | break; | |
1566 | } | |
1567 | } | |
1568 | } | |
1569 | ||
0021b564 JM |
1570 | #if !defined (EH_FRAME_SECTION) |
1571 | #if defined (EH_FRAME_SECTION_ASM_OP) | |
1572 | #define EH_FRAME_SECTION() eh_frame_section(); | |
1573 | #else | |
1574 | #if defined (ASM_OUTPUT_SECTION_NAME) | |
1575 | #define EH_FRAME_SECTION() \ | |
1576 | do { \ | |
1577 | named_section (NULL_TREE, ".eh_frame", 0); \ | |
1578 | } while (0) | |
1579 | #endif | |
1580 | #endif | |
1581 | #endif | |
1582 | ||
3f76745e JM |
1583 | /* Output the call frame information used to used to record information |
1584 | that relates to calculating the frame pointer, and records the | |
1585 | location of saved registers. */ | |
1586 | ||
1587 | static void | |
1588 | output_call_frame_info (for_eh) | |
1589 | int for_eh; | |
1590 | { | |
1591 | register unsigned long i, j; | |
1592 | register dw_fde_ref fde; | |
1593 | register unsigned long fde_size; | |
1594 | register dw_cfi_ref cfi; | |
1595 | unsigned long fde_pad; | |
a6ab3aad | 1596 | char l1[20], l2[20]; |
2ed2af28 PDM |
1597 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1598 | char ld[20]; | |
1599 | #endif | |
a6ab3aad JM |
1600 | |
1601 | /* Do we want to include a pointer to the exception table? */ | |
1602 | int eh_ptr = for_eh && exception_table_p (); | |
3f76745e | 1603 | |
3f76745e | 1604 | fputc ('\n', asm_out_file); |
e9e30253 | 1605 | |
aa0c1401 JL |
1606 | /* We're going to be generating comments, so turn on app. */ |
1607 | if (flag_debug_asm) | |
1608 | app_enable (); | |
956d6950 | 1609 | |
3f76745e JM |
1610 | if (for_eh) |
1611 | { | |
1612 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1613 | EH_FRAME_SECTION (); |
3f76745e | 1614 | #else |
496651db | 1615 | tree label = get_file_function_name ('F'); |
0021b564 | 1616 | |
3f76745e | 1617 | data_section (); |
f4744807 | 1618 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
0021b564 JM |
1619 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1620 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1621 | #endif |
1622 | assemble_label ("__FRAME_BEGIN__"); | |
1623 | } | |
1624 | else | |
1625 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
1626 | ||
1627 | /* Output the CIE. */ | |
a6ab3aad JM |
1628 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1629 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2ed2af28 PDM |
1630 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1631 | ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh); | |
1632 | if (for_eh) | |
7bb9fb0e | 1633 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1634 | else |
1635 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1636 | #else | |
267c09ab JM |
1637 | if (for_eh) |
1638 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1639 | else | |
1640 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1641 | #endif |
c5cec899 | 1642 | if (flag_debug_asm) |
3f76745e JM |
1643 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", |
1644 | ASM_COMMENT_START); | |
1645 | ||
1646 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1647 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1648 | ||
d84e64d4 JM |
1649 | if (for_eh) |
1650 | /* Now that the CIE pointer is PC-relative for EH, | |
1651 | use 0 to identify the CIE. */ | |
1652 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
1653 | else | |
1654 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1655 | ||
c5cec899 | 1656 | if (flag_debug_asm) |
3f76745e JM |
1657 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START); |
1658 | ||
1659 | fputc ('\n', asm_out_file); | |
d84e64d4 | 1660 | if (! for_eh && DWARF_OFFSET_SIZE == 8) |
3f76745e JM |
1661 | { |
1662 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1663 | fputc ('\n', asm_out_file); | |
1664 | } | |
1665 | ||
1666 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
c5cec899 | 1667 | if (flag_debug_asm) |
3f76745e JM |
1668 | fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START); |
1669 | ||
1670 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1671 | if (eh_ptr) |
1672 | { | |
d84e64d4 JM |
1673 | /* The CIE contains a pointer to the exception region info for the |
1674 | frame. Make the augmentation string three bytes (including the | |
1675 | trailing null) so the pointer is 4-byte aligned. The Solaris ld | |
1676 | can't handle unaligned relocs. */ | |
c5cec899 | 1677 | if (flag_debug_asm) |
8d4e65a6 JL |
1678 | { |
1679 | ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh"); | |
1680 | fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START); | |
1681 | } | |
1682 | else | |
1683 | { | |
c2c85462 | 1684 | ASM_OUTPUT_ASCII (asm_out_file, "eh", 3); |
8d4e65a6 | 1685 | } |
d84e64d4 JM |
1686 | fputc ('\n', asm_out_file); |
1687 | ||
1688 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__"); | |
1689 | if (flag_debug_asm) | |
1690 | fprintf (asm_out_file, "\t%s pointer to exception region info", | |
1691 | ASM_COMMENT_START); | |
a6ab3aad JM |
1692 | } |
1693 | else | |
1694 | { | |
1695 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 1696 | if (flag_debug_asm) |
a6ab3aad JM |
1697 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", |
1698 | ASM_COMMENT_START); | |
1699 | } | |
3f76745e JM |
1700 | |
1701 | fputc ('\n', asm_out_file); | |
1702 | output_uleb128 (1); | |
c5cec899 | 1703 | if (flag_debug_asm) |
3f76745e JM |
1704 | fprintf (asm_out_file, " (CIE Code Alignment Factor)"); |
1705 | ||
1706 | fputc ('\n', asm_out_file); | |
1707 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
c5cec899 | 1708 | if (flag_debug_asm) |
3f76745e JM |
1709 | fprintf (asm_out_file, " (CIE Data Alignment Factor)"); |
1710 | ||
1711 | fputc ('\n', asm_out_file); | |
1712 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN); | |
c5cec899 | 1713 | if (flag_debug_asm) |
3f76745e JM |
1714 | fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START); |
1715 | ||
1716 | fputc ('\n', asm_out_file); | |
1717 | ||
1718 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1719 | output_cfi (cfi, NULL); | |
1720 | ||
1721 | /* Pad the CIE out to an address sized boundary. */ | |
a6ab3aad JM |
1722 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
1723 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
2ed2af28 PDM |
1724 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1725 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1726 | if (flag_debug_asm) |
1727 | fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START); | |
1728 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1729 | #endif |
3f76745e JM |
1730 | |
1731 | /* Loop through all of the FDE's. */ | |
1732 | for (i = 0; i < fde_table_in_use; ++i) | |
1733 | { | |
1734 | fde = &fde_table[i]; | |
3f76745e | 1735 | |
a6ab3aad JM |
1736 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2); |
1737 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2); | |
2ed2af28 PDM |
1738 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1739 | ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2); | |
1740 | if (for_eh) | |
7bb9fb0e | 1741 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1742 | else |
1743 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1744 | #else | |
267c09ab JM |
1745 | if (for_eh) |
1746 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1747 | else | |
1748 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1749 | #endif |
c5cec899 | 1750 | if (flag_debug_asm) |
3f76745e | 1751 | fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START); |
3f76745e | 1752 | fputc ('\n', asm_out_file); |
a6ab3aad JM |
1753 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1754 | ||
3f76745e | 1755 | if (for_eh) |
ede19932 | 1756 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, "__FRAME_BEGIN__"); |
3f76745e JM |
1757 | else |
1758 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION)); | |
c5cec899 | 1759 | if (flag_debug_asm) |
3f76745e JM |
1760 | fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START); |
1761 | ||
1762 | fputc ('\n', asm_out_file); | |
1763 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
c5cec899 | 1764 | if (flag_debug_asm) |
3f76745e JM |
1765 | fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START); |
1766 | ||
1767 | fputc ('\n', asm_out_file); | |
1768 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, | |
1769 | fde->dw_fde_end, fde->dw_fde_begin); | |
c5cec899 | 1770 | if (flag_debug_asm) |
3f76745e JM |
1771 | fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START); |
1772 | ||
1773 | fputc ('\n', asm_out_file); | |
1774 | ||
1775 | /* Loop through the Call Frame Instructions associated with | |
1776 | this FDE. */ | |
1777 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1778 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1779 | output_cfi (cfi, fde); | |
1780 | ||
a6ab3aad JM |
1781 | /* Pad the FDE out to an address sized boundary. */ |
1782 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1783 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
2ed2af28 PDM |
1784 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1785 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1786 | if (flag_debug_asm) |
1787 | fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START); | |
1788 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1789 | #endif |
3f76745e JM |
1790 | } |
1791 | #ifndef EH_FRAME_SECTION | |
1792 | if (for_eh) | |
1793 | { | |
1794 | /* Emit terminating zero for table. */ | |
267c09ab | 1795 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
3f76745e JM |
1796 | fputc ('\n', asm_out_file); |
1797 | } | |
1798 | #endif | |
a6ab3aad JM |
1799 | #ifdef MIPS_DEBUGGING_INFO |
1800 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1801 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1802 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1803 | #endif | |
aa0c1401 JL |
1804 | |
1805 | /* Turn off app to make assembly quicker. */ | |
1806 | if (flag_debug_asm) | |
1807 | app_disable (); | |
a6ab3aad JM |
1808 | } |
1809 | ||
3f76745e JM |
1810 | /* Output a marker (i.e. a label) for the beginning of a function, before |
1811 | the prologue. */ | |
1812 | ||
1813 | void | |
1814 | dwarf2out_begin_prologue () | |
1815 | { | |
1816 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1817 | register dw_fde_ref fde; | |
1818 | ||
4f988ea2 JM |
1819 | ++current_funcdef_number; |
1820 | ||
3f76745e JM |
1821 | function_section (current_function_decl); |
1822 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
1823 | current_funcdef_number); | |
1824 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1825 | ||
1826 | /* Expand the fde table if necessary. */ | |
1827 | if (fde_table_in_use == fde_table_allocated) | |
1828 | { | |
1829 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
1830 | fde_table | |
1831 | = (dw_fde_ref) xrealloc (fde_table, | |
1832 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 1833 | } |
3f76745e JM |
1834 | |
1835 | /* Record the FDE associated with this function. */ | |
1836 | current_funcdef_fde = fde_table_in_use; | |
1837 | ||
1838 | /* Add the new FDE at the end of the fde_table. */ | |
1839 | fde = &fde_table[fde_table_in_use++]; | |
1840 | fde->dw_fde_begin = xstrdup (label); | |
1841 | fde->dw_fde_current_label = NULL; | |
1842 | fde->dw_fde_end = NULL; | |
1843 | fde->dw_fde_cfi = NULL; | |
0021b564 JM |
1844 | |
1845 | args_size = 0; | |
3f76745e JM |
1846 | } |
1847 | ||
1848 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
1849 | for a function definition. This gets called *after* the epilogue code has | |
1850 | been generated. */ | |
1851 | ||
1852 | void | |
1853 | dwarf2out_end_epilogue () | |
1854 | { | |
1855 | dw_fde_ref fde; | |
1856 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1857 | ||
1858 | /* Output a label to mark the endpoint of the code generated for this | |
1859 | function. */ | |
1860 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
1861 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1862 | fde = &fde_table[fde_table_in_use - 1]; | |
1863 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
1864 | } |
1865 | ||
1866 | void | |
1867 | dwarf2out_frame_init () | |
1868 | { | |
1869 | /* Allocate the initial hunk of the fde_table. */ | |
1870 | fde_table | |
1871 | = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1872 | bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1873 | fde_table_allocated = FDE_TABLE_INCREMENT; | |
1874 | fde_table_in_use = 0; | |
1875 | ||
1876 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
1877 | sake of lookup_cfa. */ | |
1878 | ||
a6ab3aad JM |
1879 | #ifdef DWARF2_UNWIND_INFO |
1880 | /* On entry, the Canonical Frame Address is at SP. */ | |
1881 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
3f76745e JM |
1882 | initial_return_save (INCOMING_RETURN_ADDR_RTX); |
1883 | #endif | |
1884 | } | |
1885 | ||
1886 | void | |
1887 | dwarf2out_frame_finish () | |
1888 | { | |
3f76745e | 1889 | /* Output call frame information. */ |
a6ab3aad | 1890 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
1891 | if (write_symbols == DWARF2_DEBUG) |
1892 | output_call_frame_info (0); | |
1893 | if (flag_exceptions && ! exceptions_via_longjmp) | |
1894 | output_call_frame_info (1); | |
a6ab3aad JM |
1895 | #else |
1896 | if (write_symbols == DWARF2_DEBUG | |
1897 | || (flag_exceptions && ! exceptions_via_longjmp)) | |
1898 | output_call_frame_info (1); | |
1899 | #endif | |
3f76745e JM |
1900 | } |
1901 | ||
1902 | #endif /* .debug_frame support */ | |
1903 | ||
1904 | /* And now, the support for symbolic debugging information. */ | |
1905 | #ifdef DWARF2_DEBUGGING_INFO | |
1906 | ||
1907 | extern char *getpwd (); | |
1908 | ||
1909 | /* NOTE: In the comments in this file, many references are made to | |
1910 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
1911 | throughout the remainder of this file. */ | |
1912 | ||
1913 | /* An internal representation of the DWARF output is built, and then | |
1914 | walked to generate the DWARF debugging info. The walk of the internal | |
1915 | representation is done after the entire program has been compiled. | |
1916 | The types below are used to describe the internal representation. */ | |
1917 | ||
1918 | /* Each DIE may have a series of attribute/value pairs. Values | |
1919 | can take on several forms. The forms that are used in this | |
1920 | implementation are listed below. */ | |
1921 | ||
1922 | typedef enum | |
1923 | { | |
1924 | dw_val_class_addr, | |
1925 | dw_val_class_loc, | |
1926 | dw_val_class_const, | |
1927 | dw_val_class_unsigned_const, | |
1928 | dw_val_class_long_long, | |
1929 | dw_val_class_float, | |
1930 | dw_val_class_flag, | |
1931 | dw_val_class_die_ref, | |
1932 | dw_val_class_fde_ref, | |
1933 | dw_val_class_lbl_id, | |
1934 | dw_val_class_section_offset, | |
1935 | dw_val_class_str | |
a3f97cbb | 1936 | } |
3f76745e | 1937 | dw_val_class; |
a3f97cbb | 1938 | |
3f76745e JM |
1939 | /* Various DIE's use offsets relative to the beginning of the |
1940 | .debug_info section to refer to each other. */ | |
71dfc51f | 1941 | |
3f76745e JM |
1942 | typedef long int dw_offset; |
1943 | ||
1944 | /* Define typedefs here to avoid circular dependencies. */ | |
1945 | ||
1946 | typedef struct die_struct *dw_die_ref; | |
1947 | typedef struct dw_attr_struct *dw_attr_ref; | |
1948 | typedef struct dw_val_struct *dw_val_ref; | |
1949 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
1950 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
1951 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
1952 | typedef struct pubname_struct *pubname_ref; | |
1953 | typedef dw_die_ref *arange_ref; | |
1954 | ||
1955 | /* Describe a double word constant value. */ | |
1956 | ||
1957 | typedef struct dw_long_long_struct | |
a3f97cbb | 1958 | { |
3f76745e JM |
1959 | unsigned long hi; |
1960 | unsigned long low; | |
1961 | } | |
1962 | dw_long_long_const; | |
1963 | ||
1964 | /* Describe a floating point constant value. */ | |
1965 | ||
1966 | typedef struct dw_fp_struct | |
1967 | { | |
1968 | long *array; | |
1969 | unsigned length; | |
1970 | } | |
1971 | dw_float_const; | |
1972 | ||
1973 | /* Each entry in the line_info_table maintains the file and | |
956d6950 | 1974 | line number associated with the label generated for that |
3f76745e JM |
1975 | entry. The label gives the PC value associated with |
1976 | the line number entry. */ | |
1977 | ||
1978 | typedef struct dw_line_info_struct | |
1979 | { | |
1980 | unsigned long dw_file_num; | |
1981 | unsigned long dw_line_num; | |
1982 | } | |
1983 | dw_line_info_entry; | |
1984 | ||
1985 | /* Line information for functions in separate sections; each one gets its | |
1986 | own sequence. */ | |
1987 | typedef struct dw_separate_line_info_struct | |
1988 | { | |
1989 | unsigned long dw_file_num; | |
1990 | unsigned long dw_line_num; | |
1991 | unsigned long function; | |
1992 | } | |
1993 | dw_separate_line_info_entry; | |
1994 | ||
956d6950 | 1995 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
1996 | represented internally. */ |
1997 | ||
1998 | typedef struct dw_val_struct | |
1999 | { | |
2000 | dw_val_class val_class; | |
2001 | union | |
a3f97cbb | 2002 | { |
3f76745e JM |
2003 | char *val_addr; |
2004 | dw_loc_descr_ref val_loc; | |
2005 | long int val_int; | |
2006 | long unsigned val_unsigned; | |
2007 | dw_long_long_const val_long_long; | |
2008 | dw_float_const val_float; | |
2009 | dw_die_ref val_die_ref; | |
2010 | unsigned val_fde_index; | |
2011 | char *val_str; | |
2012 | char *val_lbl_id; | |
2013 | char *val_section; | |
2014 | unsigned char val_flag; | |
a3f97cbb | 2015 | } |
3f76745e JM |
2016 | v; |
2017 | } | |
2018 | dw_val_node; | |
2019 | ||
2020 | /* Locations in memory are described using a sequence of stack machine | |
2021 | operations. */ | |
2022 | ||
2023 | typedef struct dw_loc_descr_struct | |
2024 | { | |
2025 | dw_loc_descr_ref dw_loc_next; | |
2026 | enum dwarf_location_atom dw_loc_opc; | |
2027 | dw_val_node dw_loc_oprnd1; | |
2028 | dw_val_node dw_loc_oprnd2; | |
2029 | } | |
2030 | dw_loc_descr_node; | |
2031 | ||
2032 | /* Each DIE attribute has a field specifying the attribute kind, | |
2033 | a link to the next attribute in the chain, and an attribute value. | |
2034 | Attributes are typically linked below the DIE they modify. */ | |
2035 | ||
2036 | typedef struct dw_attr_struct | |
2037 | { | |
2038 | enum dwarf_attribute dw_attr; | |
2039 | dw_attr_ref dw_attr_next; | |
2040 | dw_val_node dw_attr_val; | |
2041 | } | |
2042 | dw_attr_node; | |
2043 | ||
2044 | /* The Debugging Information Entry (DIE) structure */ | |
2045 | ||
2046 | typedef struct die_struct | |
2047 | { | |
2048 | enum dwarf_tag die_tag; | |
2049 | dw_attr_ref die_attr; | |
2050 | dw_attr_ref die_attr_last; | |
2051 | dw_die_ref die_parent; | |
2052 | dw_die_ref die_child; | |
2053 | dw_die_ref die_child_last; | |
2054 | dw_die_ref die_sib; | |
2055 | dw_offset die_offset; | |
2056 | unsigned long die_abbrev; | |
a3f97cbb | 2057 | } |
3f76745e JM |
2058 | die_node; |
2059 | ||
2060 | /* The pubname structure */ | |
2061 | ||
2062 | typedef struct pubname_struct | |
2063 | { | |
2064 | dw_die_ref die; | |
2065 | char * name; | |
2066 | } | |
2067 | pubname_entry; | |
2068 | ||
ef76d03b JW |
2069 | /* The limbo die list structure. */ |
2070 | typedef struct limbo_die_struct | |
2071 | { | |
2072 | dw_die_ref die; | |
2073 | struct limbo_die_struct *next; | |
2074 | } | |
2075 | limbo_die_node; | |
2076 | ||
3f76745e JM |
2077 | /* How to start an assembler comment. */ |
2078 | #ifndef ASM_COMMENT_START | |
2079 | #define ASM_COMMENT_START ";#" | |
2080 | #endif | |
2081 | ||
2082 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
2083 | implicitly generated for a tagged type. | |
2084 | ||
2085 | Note that unlike the gcc front end (which generates a NULL named | |
2086 | TYPE_DECL node for each complete tagged type, each array type, and | |
2087 | each function type node created) the g++ front end generates a | |
2088 | _named_ TYPE_DECL node for each tagged type node created. | |
2089 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
2090 | generate a DW_TAG_typedef DIE for them. */ | |
2091 | ||
2092 | #define TYPE_DECL_IS_STUB(decl) \ | |
2093 | (DECL_NAME (decl) == NULL_TREE \ | |
2094 | || (DECL_ARTIFICIAL (decl) \ | |
2095 | && is_tagged_type (TREE_TYPE (decl)) \ | |
ef76d03b JW |
2096 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ |
2097 | /* This is necessary for stub decls that \ | |
2098 | appear in nested inline functions. */ \ | |
2099 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
2100 | && (decl_ultimate_origin (decl) \ | |
2101 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3f76745e JM |
2102 | |
2103 | /* Information concerning the compilation unit's programming | |
2104 | language, and compiler version. */ | |
2105 | ||
2106 | extern int flag_traditional; | |
2107 | extern char *version_string; | |
2108 | extern char *language_string; | |
2109 | ||
2110 | /* Fixed size portion of the DWARF compilation unit header. */ | |
2111 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
2112 | ||
2113 | /* Fixed size portion of debugging line information prolog. */ | |
2114 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
2115 | ||
2116 | /* Fixed size portion of public names info. */ | |
2117 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
2118 | ||
2119 | /* Fixed size portion of the address range info. */ | |
2120 | #define DWARF_ARANGES_HEADER_SIZE \ | |
2121 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE) | |
2122 | ||
2123 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
2124 | In this implementation of DWARF, this field is used for information | |
2125 | purposes only. Since GCC generates assembly language, we have | |
2126 | no a priori knowledge of how many instruction bytes are generated | |
2127 | for each source line, and therefore can use only the DW_LNE_set_address | |
2128 | and DW_LNS_fixed_advance_pc line information commands. */ | |
2129 | ||
2130 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
2131 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
2132 | #endif | |
2133 | ||
2134 | /* Minimum line offset in a special line info. opcode. | |
2135 | This value was chosen to give a reasonable range of values. */ | |
2136 | #define DWARF_LINE_BASE -10 | |
2137 | ||
2138 | /* First special line opcde - leave room for the standard opcodes. */ | |
2139 | #define DWARF_LINE_OPCODE_BASE 10 | |
2140 | ||
2141 | /* Range of line offsets in a special line info. opcode. */ | |
2142 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
2143 | ||
2144 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
2145 | In the present implementation, we do not mark any lines as | |
2146 | the beginning of a source statement, because that information | |
2147 | is not made available by the GCC front-end. */ | |
2148 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
2149 | ||
2150 | /* This location is used by calc_die_sizes() to keep track | |
2151 | the offset of each DIE within the .debug_info section. */ | |
2152 | static unsigned long next_die_offset; | |
2153 | ||
2154 | /* Record the root of the DIE's built for the current compilation unit. */ | |
2155 | static dw_die_ref comp_unit_die; | |
2156 | ||
ef76d03b JW |
2157 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
2158 | static limbo_die_node *limbo_die_list = 0; | |
3f76745e JM |
2159 | |
2160 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
2161 | static char **file_table; | |
2162 | ||
2163 | /* Total number of entries in the table (i.e. array) pointed to by | |
2164 | `file_table'. This is the *total* and includes both used and unused | |
2165 | slots. */ | |
2166 | static unsigned file_table_allocated; | |
a3f97cbb | 2167 | |
3f76745e JM |
2168 | /* Number of entries in the file_table which are actually in use. */ |
2169 | static unsigned file_table_in_use; | |
71dfc51f | 2170 | |
3f76745e JM |
2171 | /* Size (in elements) of increments by which we may expand the filename |
2172 | table. */ | |
2173 | #define FILE_TABLE_INCREMENT 64 | |
71dfc51f | 2174 | |
3f76745e JM |
2175 | /* Local pointer to the name of the main input file. Initialized in |
2176 | dwarf2out_init. */ | |
2177 | static char *primary_filename; | |
a3f97cbb | 2178 | |
3f76745e JM |
2179 | /* For Dwarf output, we must assign lexical-blocks id numbers in the order in |
2180 | which their beginnings are encountered. We output Dwarf debugging info | |
2181 | that refers to the beginnings and ends of the ranges of code for each | |
2182 | lexical block. The labels themselves are generated in final.c, which | |
2183 | assigns numbers to the blocks in the same way. */ | |
2184 | static unsigned next_block_number = 2; | |
a3f97cbb | 2185 | |
3f76745e JM |
2186 | /* A pointer to the base of a table of references to DIE's that describe |
2187 | declarations. The table is indexed by DECL_UID() which is a unique | |
956d6950 | 2188 | number identifying each decl. */ |
3f76745e | 2189 | static dw_die_ref *decl_die_table; |
71dfc51f | 2190 | |
3f76745e JM |
2191 | /* Number of elements currently allocated for the decl_die_table. */ |
2192 | static unsigned decl_die_table_allocated; | |
a3f97cbb | 2193 | |
3f76745e JM |
2194 | /* Number of elements in decl_die_table currently in use. */ |
2195 | static unsigned decl_die_table_in_use; | |
71dfc51f | 2196 | |
3f76745e JM |
2197 | /* Size (in elements) of increments by which we may expand the |
2198 | decl_die_table. */ | |
2199 | #define DECL_DIE_TABLE_INCREMENT 256 | |
a3f97cbb | 2200 | |
3f76745e JM |
2201 | /* A pointer to the base of a table of references to declaration |
2202 | scopes. This table is a display which tracks the nesting | |
2203 | of declaration scopes at the current scope and containing | |
2204 | scopes. This table is used to find the proper place to | |
2205 | define type declaration DIE's. */ | |
2206 | static tree *decl_scope_table; | |
a3f97cbb | 2207 | |
3f76745e JM |
2208 | /* Number of elements currently allocated for the decl_scope_table. */ |
2209 | static unsigned decl_scope_table_allocated; | |
71dfc51f | 2210 | |
956d6950 | 2211 | /* Current level of nesting of declaration scopes. */ |
3f76745e | 2212 | static unsigned decl_scope_depth; |
bdb669cb | 2213 | |
3f76745e JM |
2214 | /* Size (in elements) of increments by which we may expand the |
2215 | decl_scope_table. */ | |
2216 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
bdb669cb | 2217 | |
3f76745e JM |
2218 | /* A pointer to the base of a list of references to DIE's that |
2219 | are uniquely identified by their tag, presence/absence of | |
2220 | children DIE's, and list of attribute/value pairs. */ | |
2221 | static dw_die_ref *abbrev_die_table; | |
71dfc51f | 2222 | |
3f76745e JM |
2223 | /* Number of elements currently allocated for abbrev_die_table. */ |
2224 | static unsigned abbrev_die_table_allocated; | |
bdb669cb | 2225 | |
3f76745e JM |
2226 | /* Number of elements in type_die_table currently in use. */ |
2227 | static unsigned abbrev_die_table_in_use; | |
bdb669cb | 2228 | |
3f76745e JM |
2229 | /* Size (in elements) of increments by which we may expand the |
2230 | abbrev_die_table. */ | |
2231 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
71dfc51f | 2232 | |
3f76745e JM |
2233 | /* A pointer to the base of a table that contains line information |
2234 | for each source code line in .text in the compilation unit. */ | |
2235 | static dw_line_info_ref line_info_table; | |
a3f97cbb | 2236 | |
3f76745e JM |
2237 | /* Number of elements currently allocated for line_info_table. */ |
2238 | static unsigned line_info_table_allocated; | |
71dfc51f | 2239 | |
3f76745e JM |
2240 | /* Number of elements in separate_line_info_table currently in use. */ |
2241 | static unsigned separate_line_info_table_in_use; | |
71dfc51f | 2242 | |
3f76745e JM |
2243 | /* A pointer to the base of a table that contains line information |
2244 | for each source code line outside of .text in the compilation unit. */ | |
2245 | static dw_separate_line_info_ref separate_line_info_table; | |
a3f97cbb | 2246 | |
3f76745e JM |
2247 | /* Number of elements currently allocated for separate_line_info_table. */ |
2248 | static unsigned separate_line_info_table_allocated; | |
71dfc51f | 2249 | |
3f76745e JM |
2250 | /* Number of elements in line_info_table currently in use. */ |
2251 | static unsigned line_info_table_in_use; | |
71dfc51f | 2252 | |
3f76745e JM |
2253 | /* Size (in elements) of increments by which we may expand the |
2254 | line_info_table. */ | |
2255 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
a3f97cbb | 2256 | |
3f76745e JM |
2257 | /* A pointer to the base of a table that contains a list of publicly |
2258 | accessible names. */ | |
2259 | static pubname_ref pubname_table; | |
71dfc51f | 2260 | |
3f76745e JM |
2261 | /* Number of elements currently allocated for pubname_table. */ |
2262 | static unsigned pubname_table_allocated; | |
2263 | ||
2264 | /* Number of elements in pubname_table currently in use. */ | |
2265 | static unsigned pubname_table_in_use; | |
2266 | ||
2267 | /* Size (in elements) of increments by which we may expand the | |
2268 | pubname_table. */ | |
2269 | #define PUBNAME_TABLE_INCREMENT 64 | |
2270 | ||
2271 | /* A pointer to the base of a table that contains a list of publicly | |
2272 | accessible names. */ | |
2273 | static arange_ref arange_table; | |
71dfc51f | 2274 | |
3f76745e JM |
2275 | /* Number of elements currently allocated for arange_table. */ |
2276 | static unsigned arange_table_allocated; | |
a3f97cbb | 2277 | |
3f76745e JM |
2278 | /* Number of elements in arange_table currently in use. */ |
2279 | static unsigned arange_table_in_use; | |
71dfc51f | 2280 | |
3f76745e JM |
2281 | /* Size (in elements) of increments by which we may expand the |
2282 | arange_table. */ | |
2283 | #define ARANGE_TABLE_INCREMENT 64 | |
71dfc51f | 2284 | |
3f76745e JM |
2285 | /* A pointer to the base of a list of pending types which we haven't |
2286 | generated DIEs for yet, but which we will have to come back to | |
2287 | later on. */ | |
469ac993 | 2288 | |
3f76745e | 2289 | static tree *pending_types_list; |
71dfc51f | 2290 | |
3f76745e JM |
2291 | /* Number of elements currently allocated for the pending_types_list. */ |
2292 | static unsigned pending_types_allocated; | |
71dfc51f | 2293 | |
3f76745e JM |
2294 | /* Number of elements of pending_types_list currently in use. */ |
2295 | static unsigned pending_types; | |
a3f97cbb | 2296 | |
3f76745e JM |
2297 | /* Size (in elements) of increments by which we may expand the pending |
2298 | types list. Actually, a single hunk of space of this size should | |
2299 | be enough for most typical programs. */ | |
2300 | #define PENDING_TYPES_INCREMENT 64 | |
71dfc51f | 2301 | |
3f76745e JM |
2302 | /* Record whether the function being analyzed contains inlined functions. */ |
2303 | static int current_function_has_inlines; | |
2304 | static int comp_unit_has_inlines; | |
71dfc51f | 2305 | |
3f76745e JM |
2306 | /* A pointer to the ..._DECL node which we have most recently been working |
2307 | on. We keep this around just in case something about it looks screwy and | |
2308 | we want to tell the user what the source coordinates for the actual | |
2309 | declaration are. */ | |
2310 | static tree dwarf_last_decl; | |
a3f97cbb | 2311 | |
3f76745e | 2312 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 2313 | |
3f76745e JM |
2314 | static void addr_const_to_string PROTO((char *, rtx)); |
2315 | static char *addr_to_string PROTO((rtx)); | |
2316 | static int is_pseudo_reg PROTO((rtx)); | |
2317 | static tree type_main_variant PROTO((tree)); | |
2318 | static int is_tagged_type PROTO((tree)); | |
2319 | static char *dwarf_tag_name PROTO((unsigned)); | |
2320 | static char *dwarf_attr_name PROTO((unsigned)); | |
2321 | static char *dwarf_form_name PROTO((unsigned)); | |
2322 | static char *dwarf_stack_op_name PROTO((unsigned)); | |
2323 | static char *dwarf_type_encoding_name PROTO((unsigned)); | |
2324 | static tree decl_ultimate_origin PROTO((tree)); | |
2325 | static tree block_ultimate_origin PROTO((tree)); | |
2326 | static tree decl_class_context PROTO((tree)); | |
2327 | static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref)); | |
2328 | static void add_AT_flag PROTO((dw_die_ref, | |
2329 | enum dwarf_attribute, | |
2330 | unsigned)); | |
2331 | static void add_AT_int PROTO((dw_die_ref, | |
2332 | enum dwarf_attribute, long)); | |
2333 | static void add_AT_unsigned PROTO((dw_die_ref, | |
2334 | enum dwarf_attribute, | |
2335 | unsigned long)); | |
2336 | static void add_AT_long_long PROTO((dw_die_ref, | |
2337 | enum dwarf_attribute, | |
2338 | unsigned long, unsigned long)); | |
2339 | static void add_AT_float PROTO((dw_die_ref, | |
2340 | enum dwarf_attribute, | |
2341 | unsigned, long *)); | |
2342 | static void add_AT_string PROTO((dw_die_ref, | |
2343 | enum dwarf_attribute, char *)); | |
2344 | static void add_AT_die_ref PROTO((dw_die_ref, | |
2345 | enum dwarf_attribute, | |
2346 | dw_die_ref)); | |
2347 | static void add_AT_fde_ref PROTO((dw_die_ref, | |
2348 | enum dwarf_attribute, | |
2349 | unsigned)); | |
2350 | static void add_AT_loc PROTO((dw_die_ref, | |
2351 | enum dwarf_attribute, | |
2352 | dw_loc_descr_ref)); | |
2353 | static void add_AT_addr PROTO((dw_die_ref, | |
2354 | enum dwarf_attribute, char *)); | |
2355 | static void add_AT_lbl_id PROTO((dw_die_ref, | |
2356 | enum dwarf_attribute, char *)); | |
956d6950 | 2357 | static void add_AT_section_offset PROTO((dw_die_ref, |
3f76745e JM |
2358 | enum dwarf_attribute, char *)); |
2359 | static int is_extern_subr_die PROTO((dw_die_ref)); | |
2360 | static dw_attr_ref get_AT PROTO((dw_die_ref, | |
2361 | enum dwarf_attribute)); | |
2362 | static char *get_AT_low_pc PROTO((dw_die_ref)); | |
2363 | static char *get_AT_hi_pc PROTO((dw_die_ref)); | |
2364 | static char *get_AT_string PROTO((dw_die_ref, | |
2365 | enum dwarf_attribute)); | |
2366 | static int get_AT_flag PROTO((dw_die_ref, | |
2367 | enum dwarf_attribute)); | |
2368 | static unsigned get_AT_unsigned PROTO((dw_die_ref, | |
2369 | enum dwarf_attribute)); | |
2370 | static int is_c_family PROTO((void)); | |
2371 | static int is_fortran PROTO((void)); | |
2372 | static void remove_AT PROTO((dw_die_ref, | |
2373 | enum dwarf_attribute)); | |
2374 | static void remove_children PROTO((dw_die_ref)); | |
2375 | static void add_child_die PROTO((dw_die_ref, dw_die_ref)); | |
2376 | static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref)); | |
2377 | static dw_die_ref lookup_type_die PROTO((tree)); | |
2378 | static void equate_type_number_to_die PROTO((tree, dw_die_ref)); | |
2379 | static dw_die_ref lookup_decl_die PROTO((tree)); | |
2380 | static void equate_decl_number_to_die PROTO((tree, dw_die_ref)); | |
2381 | static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom, | |
2382 | unsigned long, unsigned long)); | |
2383 | static void add_loc_descr PROTO((dw_loc_descr_ref *, | |
2384 | dw_loc_descr_ref)); | |
2385 | static void print_spaces PROTO((FILE *)); | |
2386 | static void print_die PROTO((dw_die_ref, FILE *)); | |
2387 | static void print_dwarf_line_table PROTO((FILE *)); | |
956d6950 | 2388 | static void add_sibling_attributes PROTO((dw_die_ref)); |
3f76745e JM |
2389 | static void build_abbrev_table PROTO((dw_die_ref)); |
2390 | static unsigned long size_of_string PROTO((char *)); | |
2391 | static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref)); | |
2392 | static unsigned long size_of_locs PROTO((dw_loc_descr_ref)); | |
2393 | static int constant_size PROTO((long unsigned)); | |
2394 | static unsigned long size_of_die PROTO((dw_die_ref)); | |
2395 | static void calc_die_sizes PROTO((dw_die_ref)); | |
2396 | static unsigned long size_of_prolog PROTO((void)); | |
2397 | static unsigned long size_of_line_info PROTO((void)); | |
2398 | static unsigned long size_of_pubnames PROTO((void)); | |
2399 | static unsigned long size_of_aranges PROTO((void)); | |
2400 | static enum dwarf_form value_format PROTO((dw_val_ref)); | |
2401 | static void output_value_format PROTO((dw_val_ref)); | |
2402 | static void output_abbrev_section PROTO((void)); | |
2403 | static void output_loc_operands PROTO((dw_loc_descr_ref)); | |
2404 | static unsigned long sibling_offset PROTO((dw_die_ref)); | |
2405 | static void output_die PROTO((dw_die_ref)); | |
2406 | static void output_compilation_unit_header PROTO((void)); | |
2407 | static char *dwarf2_name PROTO((tree, int)); | |
2408 | static void add_pubname PROTO((tree, dw_die_ref)); | |
2409 | static void output_pubnames PROTO((void)); | |
2410 | static void add_arrange PROTO((tree, dw_die_ref)); | |
2411 | static void output_arranges PROTO((void)); | |
2412 | static void output_line_info PROTO((void)); | |
2413 | static int is_body_block PROTO((tree)); | |
2414 | static dw_die_ref base_type_die PROTO((tree)); | |
2415 | static tree root_type PROTO((tree)); | |
2416 | static int is_base_type PROTO((tree)); | |
2417 | static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref)); | |
2418 | static int type_is_enum PROTO((tree)); | |
4401bf24 | 2419 | static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx)); |
3f76745e JM |
2420 | static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long)); |
2421 | static int is_based_loc PROTO((rtx)); | |
2422 | static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx)); | |
4401bf24 | 2423 | static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx)); |
3f76745e JM |
2424 | static dw_loc_descr_ref loc_descriptor PROTO((rtx)); |
2425 | static unsigned ceiling PROTO((unsigned, unsigned)); | |
2426 | static tree field_type PROTO((tree)); | |
2427 | static unsigned simple_type_align_in_bits PROTO((tree)); | |
2428 | static unsigned simple_type_size_in_bits PROTO((tree)); | |
2429 | static unsigned field_byte_offset PROTO((tree)); | |
ef76d03b JW |
2430 | static void add_AT_location_description PROTO((dw_die_ref, |
2431 | enum dwarf_attribute, rtx)); | |
3f76745e JM |
2432 | static void add_data_member_location_attribute PROTO((dw_die_ref, tree)); |
2433 | static void add_const_value_attribute PROTO((dw_die_ref, rtx)); | |
2434 | static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree)); | |
2435 | static void add_name_attribute PROTO((dw_die_ref, char *)); | |
2436 | static void add_bound_info PROTO((dw_die_ref, | |
2437 | enum dwarf_attribute, tree)); | |
2438 | static void add_subscript_info PROTO((dw_die_ref, tree)); | |
2439 | static void add_byte_size_attribute PROTO((dw_die_ref, tree)); | |
2440 | static void add_bit_offset_attribute PROTO((dw_die_ref, tree)); | |
2441 | static void add_bit_size_attribute PROTO((dw_die_ref, tree)); | |
2442 | static void add_prototyped_attribute PROTO((dw_die_ref, tree)); | |
2443 | static void add_abstract_origin_attribute PROTO((dw_die_ref, tree)); | |
2444 | static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree)); | |
2445 | static void add_src_coords_attributes PROTO((dw_die_ref, tree)); | |
2446 | static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree)); | |
2447 | static void push_decl_scope PROTO((tree)); | |
2448 | static dw_die_ref scope_die_for PROTO((tree, dw_die_ref)); | |
2449 | static void pop_decl_scope PROTO((void)); | |
2450 | static void add_type_attribute PROTO((dw_die_ref, tree, int, int, | |
2451 | dw_die_ref)); | |
2452 | static char *type_tag PROTO((tree)); | |
2453 | static tree member_declared_type PROTO((tree)); | |
2454 | static char *decl_start_label PROTO((tree)); | |
2455 | static void gen_arrqay_type_die PROTO((tree, dw_die_ref)); | |
2456 | static void gen_set_type_die PROTO((tree, dw_die_ref)); | |
2457 | static void gen_entry_point_die PROTO((tree, dw_die_ref)); | |
2458 | static void pend_type PROTO((tree)); | |
2459 | static void output_pending_types_for_scope PROTO((dw_die_ref)); | |
2460 | static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2461 | static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref)); | |
2462 | static void gen_inlined_union_type_die PROTO((tree, dw_die_ref)); | |
2463 | static void gen_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2464 | static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref)); | |
2465 | static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref)); | |
2466 | static void gen_formal_types_die PROTO((tree, dw_die_ref)); | |
2467 | static void gen_subprogram_die PROTO((tree, dw_die_ref)); | |
2468 | static void gen_variable_die PROTO((tree, dw_die_ref)); | |
2469 | static void gen_label_die PROTO((tree, dw_die_ref)); | |
2470 | static void gen_lexical_block_die PROTO((tree, dw_die_ref, int)); | |
2471 | static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int)); | |
2472 | static void gen_field_die PROTO((tree, dw_die_ref)); | |
2473 | static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref)); | |
2474 | static void gen_compile_unit_die PROTO((char *)); | |
2475 | static void gen_string_type_die PROTO((tree, dw_die_ref)); | |
2476 | static void gen_inheritance_die PROTO((tree, dw_die_ref)); | |
2477 | static void gen_member_die PROTO((tree, dw_die_ref)); | |
2478 | static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref)); | |
2479 | static void gen_subroutine_type_die PROTO((tree, dw_die_ref)); | |
2480 | static void gen_typedef_die PROTO((tree, dw_die_ref)); | |
2481 | static void gen_type_die PROTO((tree, dw_die_ref)); | |
2482 | static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref)); | |
2483 | static void gen_block_die PROTO((tree, dw_die_ref, int)); | |
2484 | static void decls_for_scope PROTO((tree, dw_die_ref, int)); | |
2485 | static int is_redundant_typedef PROTO((tree)); | |
2486 | static void gen_decl_die PROTO((tree, dw_die_ref)); | |
2487 | static unsigned lookup_filename PROTO((char *)); | |
71dfc51f | 2488 | |
3f76745e | 2489 | /* Section names used to hold DWARF debugging information. */ |
c53aa195 JM |
2490 | #ifndef DEBUG_INFO_SECTION |
2491 | #define DEBUG_INFO_SECTION ".debug_info" | |
3f76745e JM |
2492 | #endif |
2493 | #ifndef ABBREV_SECTION | |
2494 | #define ABBREV_SECTION ".debug_abbrev" | |
2495 | #endif | |
2496 | #ifndef ARANGES_SECTION | |
2497 | #define ARANGES_SECTION ".debug_aranges" | |
2498 | #endif | |
2499 | #ifndef DW_MACINFO_SECTION | |
2500 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
2501 | #endif | |
c53aa195 JM |
2502 | #ifndef DEBUG_LINE_SECTION |
2503 | #define DEBUG_LINE_SECTION ".debug_line" | |
3f76745e JM |
2504 | #endif |
2505 | #ifndef LOC_SECTION | |
2506 | #define LOC_SECTION ".debug_loc" | |
2507 | #endif | |
2508 | #ifndef PUBNAMES_SECTION | |
2509 | #define PUBNAMES_SECTION ".debug_pubnames" | |
2510 | #endif | |
2511 | #ifndef STR_SECTION | |
2512 | #define STR_SECTION ".debug_str" | |
2513 | #endif | |
a3f97cbb | 2514 | |
956d6950 | 2515 | /* Standard ELF section names for compiled code and data. */ |
3f76745e JM |
2516 | #ifndef TEXT_SECTION |
2517 | #define TEXT_SECTION ".text" | |
2518 | #endif | |
2519 | #ifndef DATA_SECTION | |
2520 | #define DATA_SECTION ".data" | |
2521 | #endif | |
2522 | #ifndef BSS_SECTION | |
2523 | #define BSS_SECTION ".bss" | |
2524 | #endif | |
71dfc51f | 2525 | |
a3f97cbb | 2526 | |
3f76745e JM |
2527 | /* Definitions of defaults for formats and names of various special |
2528 | (artificial) labels which may be generated within this file (when the -g | |
2529 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
2530 | If necessary, these may be overridden from within the tm.h file, but | |
2531 | typically, overriding these defaults is unnecessary. */ | |
a3f97cbb | 2532 | |
257ebd1f | 2533 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 2534 | |
3f76745e JM |
2535 | #ifndef TEXT_END_LABEL |
2536 | #define TEXT_END_LABEL "Letext" | |
2537 | #endif | |
2538 | #ifndef DATA_END_LABEL | |
2539 | #define DATA_END_LABEL "Ledata" | |
2540 | #endif | |
2541 | #ifndef BSS_END_LABEL | |
2542 | #define BSS_END_LABEL "Lebss" | |
2543 | #endif | |
2544 | #ifndef INSN_LABEL_FMT | |
2545 | #define INSN_LABEL_FMT "LI%u_" | |
2546 | #endif | |
2547 | #ifndef BLOCK_BEGIN_LABEL | |
2548 | #define BLOCK_BEGIN_LABEL "LBB" | |
2549 | #endif | |
2550 | #ifndef BLOCK_END_LABEL | |
2551 | #define BLOCK_END_LABEL "LBE" | |
2552 | #endif | |
2553 | #ifndef BODY_BEGIN_LABEL | |
2554 | #define BODY_BEGIN_LABEL "Lbb" | |
2555 | #endif | |
2556 | #ifndef BODY_END_LABEL | |
2557 | #define BODY_END_LABEL "Lbe" | |
2558 | #endif | |
2559 | #ifndef LINE_CODE_LABEL | |
2560 | #define LINE_CODE_LABEL "LM" | |
2561 | #endif | |
2562 | #ifndef SEPARATE_LINE_CODE_LABEL | |
2563 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
2564 | #endif | |
71dfc51f | 2565 | |
3f76745e JM |
2566 | /* Convert a reference to the assembler name of a C-level name. This |
2567 | macro has the same effect as ASM_OUTPUT_LABELREF, but copies to | |
2568 | a string rather than writing to a file. */ | |
2569 | #ifndef ASM_NAME_TO_STRING | |
2570 | #define ASM_NAME_TO_STRING(STR, NAME) \ | |
2571 | do { \ | |
2572 | if ((NAME)[0] == '*') \ | |
2573 | strcpy (STR, NAME+1); \ | |
2574 | else \ | |
2575 | strcpy (STR, NAME); \ | |
2576 | } \ | |
2577 | while (0) | |
2578 | #endif | |
2579 | \f | |
2580 | /* Convert an integer constant expression into assembler syntax. Addition | |
2581 | and subtraction are the only arithmetic that may appear in these | |
2582 | expressions. This is an adaptation of output_addr_const in final.c. | |
2583 | Here, the target of the conversion is a string buffer. We can't use | |
2584 | output_addr_const directly, because it writes to a file. */ | |
71dfc51f | 2585 | |
3f76745e JM |
2586 | static void |
2587 | addr_const_to_string (str, x) | |
2588 | char *str; | |
2589 | rtx x; | |
a3f97cbb | 2590 | { |
3f76745e JM |
2591 | char buf1[256]; |
2592 | char buf2[256]; | |
71dfc51f | 2593 | |
3f76745e JM |
2594 | restart: |
2595 | str[0] = '\0'; | |
2596 | switch (GET_CODE (x)) | |
2597 | { | |
2598 | case PC: | |
2599 | if (flag_pic) | |
2600 | strcat (str, ","); | |
2601 | else | |
2602 | abort (); | |
2603 | break; | |
71dfc51f | 2604 | |
3f76745e JM |
2605 | case SYMBOL_REF: |
2606 | ASM_NAME_TO_STRING (buf1, XSTR (x, 0)); | |
2607 | strcat (str, buf1); | |
2608 | break; | |
a3f97cbb | 2609 | |
3f76745e JM |
2610 | case LABEL_REF: |
2611 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); | |
2612 | ASM_NAME_TO_STRING (buf2, buf1); | |
2613 | strcat (str, buf2); | |
2614 | break; | |
71dfc51f | 2615 | |
3f76745e JM |
2616 | case CODE_LABEL: |
2617 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); | |
2618 | ASM_NAME_TO_STRING (buf2, buf1); | |
2619 | strcat (str, buf2); | |
2620 | break; | |
71dfc51f | 2621 | |
3f76745e JM |
2622 | case CONST_INT: |
2623 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
2624 | strcat (str, buf1); | |
2625 | break; | |
a3f97cbb | 2626 | |
3f76745e JM |
2627 | case CONST: |
2628 | /* This used to output parentheses around the expression, but that does | |
2629 | not work on the 386 (either ATT or BSD assembler). */ | |
2630 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2631 | strcat (str, buf1); | |
2632 | break; | |
71dfc51f | 2633 | |
3f76745e JM |
2634 | case CONST_DOUBLE: |
2635 | if (GET_MODE (x) == VOIDmode) | |
2636 | { | |
2637 | /* We can use %d if the number is one word and positive. */ | |
2638 | if (CONST_DOUBLE_HIGH (x)) | |
2639 | sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX, | |
2640 | CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); | |
2641 | else if (CONST_DOUBLE_LOW (x) < 0) | |
2642 | sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x)); | |
2643 | else | |
2644 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, | |
2645 | CONST_DOUBLE_LOW (x)); | |
2646 | strcat (str, buf1); | |
2647 | } | |
2648 | else | |
2649 | /* We can't handle floating point constants; PRINT_OPERAND must | |
2650 | handle them. */ | |
2651 | output_operand_lossage ("floating constant misused"); | |
2652 | break; | |
71dfc51f | 2653 | |
3f76745e JM |
2654 | case PLUS: |
2655 | /* Some assemblers need integer constants to appear last (eg masm). */ | |
2656 | if (GET_CODE (XEXP (x, 0)) == CONST_INT) | |
a3f97cbb | 2657 | { |
3f76745e JM |
2658 | addr_const_to_string (buf1, XEXP (x, 1)); |
2659 | strcat (str, buf1); | |
2660 | if (INTVAL (XEXP (x, 0)) >= 0) | |
2661 | strcat (str, "+"); | |
2662 | ||
2663 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2664 | strcat (str, buf1); | |
a3f97cbb | 2665 | } |
3f76745e JM |
2666 | else |
2667 | { | |
2668 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2669 | strcat (str, buf1); | |
2670 | if (INTVAL (XEXP (x, 1)) >= 0) | |
2671 | strcat (str, "+"); | |
71dfc51f | 2672 | |
3f76745e JM |
2673 | addr_const_to_string (buf1, XEXP (x, 1)); |
2674 | strcat (str, buf1); | |
2675 | } | |
2676 | break; | |
a3f97cbb | 2677 | |
3f76745e JM |
2678 | case MINUS: |
2679 | /* Avoid outputting things like x-x or x+5-x, since some assemblers | |
2680 | can't handle that. */ | |
2681 | x = simplify_subtraction (x); | |
2682 | if (GET_CODE (x) != MINUS) | |
2683 | goto restart; | |
71dfc51f | 2684 | |
3f76745e JM |
2685 | addr_const_to_string (buf1, XEXP (x, 0)); |
2686 | strcat (str, buf1); | |
2687 | strcat (str, "-"); | |
2688 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
2689 | && INTVAL (XEXP (x, 1)) < 0) | |
a3f97cbb | 2690 | { |
3f76745e JM |
2691 | strcat (str, ASM_OPEN_PAREN); |
2692 | addr_const_to_string (buf1, XEXP (x, 1)); | |
2693 | strcat (str, buf1); | |
2694 | strcat (str, ASM_CLOSE_PAREN); | |
2695 | } | |
2696 | else | |
2697 | { | |
2698 | addr_const_to_string (buf1, XEXP (x, 1)); | |
2699 | strcat (str, buf1); | |
a3f97cbb | 2700 | } |
3f76745e | 2701 | break; |
71dfc51f | 2702 | |
3f76745e JM |
2703 | case ZERO_EXTEND: |
2704 | case SIGN_EXTEND: | |
2705 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2706 | strcat (str, buf1); | |
2707 | break; | |
71dfc51f | 2708 | |
3f76745e JM |
2709 | default: |
2710 | output_operand_lossage ("invalid expression as operand"); | |
2711 | } | |
d291dd49 JM |
2712 | } |
2713 | ||
3f76745e JM |
2714 | /* Convert an address constant to a string, and return a pointer to |
2715 | a copy of the result, located on the heap. */ | |
71dfc51f | 2716 | |
3f76745e JM |
2717 | static char * |
2718 | addr_to_string (x) | |
2719 | rtx x; | |
d291dd49 | 2720 | { |
3f76745e JM |
2721 | char buf[1024]; |
2722 | addr_const_to_string (buf, x); | |
2723 | return xstrdup (buf); | |
d291dd49 JM |
2724 | } |
2725 | ||
956d6950 | 2726 | /* Test if rtl node points to a pseudo register. */ |
71dfc51f | 2727 | |
3f76745e JM |
2728 | static inline int |
2729 | is_pseudo_reg (rtl) | |
2730 | register rtx rtl; | |
d291dd49 | 2731 | { |
3f76745e JM |
2732 | return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) |
2733 | || ((GET_CODE (rtl) == SUBREG) | |
2734 | && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER))); | |
d291dd49 JM |
2735 | } |
2736 | ||
3f76745e JM |
2737 | /* Return a reference to a type, with its const and volatile qualifiers |
2738 | removed. */ | |
71dfc51f | 2739 | |
3f76745e JM |
2740 | static inline tree |
2741 | type_main_variant (type) | |
2742 | register tree type; | |
d291dd49 | 2743 | { |
3f76745e | 2744 | type = TYPE_MAIN_VARIANT (type); |
71dfc51f | 2745 | |
3f76745e JM |
2746 | /* There really should be only one main variant among any group of variants |
2747 | of a given type (and all of the MAIN_VARIANT values for all members of | |
2748 | the group should point to that one type) but sometimes the C front-end | |
2749 | messes this up for array types, so we work around that bug here. */ | |
71dfc51f | 2750 | |
3f76745e JM |
2751 | if (TREE_CODE (type) == ARRAY_TYPE) |
2752 | while (type != TYPE_MAIN_VARIANT (type)) | |
2753 | type = TYPE_MAIN_VARIANT (type); | |
2754 | ||
2755 | return type; | |
a3f97cbb JW |
2756 | } |
2757 | ||
3f76745e | 2758 | /* Return non-zero if the given type node represents a tagged type. */ |
71dfc51f RK |
2759 | |
2760 | static inline int | |
3f76745e JM |
2761 | is_tagged_type (type) |
2762 | register tree type; | |
bdb669cb | 2763 | { |
3f76745e | 2764 | register enum tree_code code = TREE_CODE (type); |
71dfc51f | 2765 | |
3f76745e JM |
2766 | return (code == RECORD_TYPE || code == UNION_TYPE |
2767 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
bdb669cb JM |
2768 | } |
2769 | ||
3f76745e | 2770 | /* Convert a DIE tag into its string name. */ |
71dfc51f | 2771 | |
3f76745e JM |
2772 | static char * |
2773 | dwarf_tag_name (tag) | |
2774 | register unsigned tag; | |
bdb669cb | 2775 | { |
3f76745e JM |
2776 | switch (tag) |
2777 | { | |
2778 | case DW_TAG_padding: | |
2779 | return "DW_TAG_padding"; | |
2780 | case DW_TAG_array_type: | |
2781 | return "DW_TAG_array_type"; | |
2782 | case DW_TAG_class_type: | |
2783 | return "DW_TAG_class_type"; | |
2784 | case DW_TAG_entry_point: | |
2785 | return "DW_TAG_entry_point"; | |
2786 | case DW_TAG_enumeration_type: | |
2787 | return "DW_TAG_enumeration_type"; | |
2788 | case DW_TAG_formal_parameter: | |
2789 | return "DW_TAG_formal_parameter"; | |
2790 | case DW_TAG_imported_declaration: | |
2791 | return "DW_TAG_imported_declaration"; | |
2792 | case DW_TAG_label: | |
2793 | return "DW_TAG_label"; | |
2794 | case DW_TAG_lexical_block: | |
2795 | return "DW_TAG_lexical_block"; | |
2796 | case DW_TAG_member: | |
2797 | return "DW_TAG_member"; | |
2798 | case DW_TAG_pointer_type: | |
2799 | return "DW_TAG_pointer_type"; | |
2800 | case DW_TAG_reference_type: | |
2801 | return "DW_TAG_reference_type"; | |
2802 | case DW_TAG_compile_unit: | |
2803 | return "DW_TAG_compile_unit"; | |
2804 | case DW_TAG_string_type: | |
2805 | return "DW_TAG_string_type"; | |
2806 | case DW_TAG_structure_type: | |
2807 | return "DW_TAG_structure_type"; | |
2808 | case DW_TAG_subroutine_type: | |
2809 | return "DW_TAG_subroutine_type"; | |
2810 | case DW_TAG_typedef: | |
2811 | return "DW_TAG_typedef"; | |
2812 | case DW_TAG_union_type: | |
2813 | return "DW_TAG_union_type"; | |
2814 | case DW_TAG_unspecified_parameters: | |
2815 | return "DW_TAG_unspecified_parameters"; | |
2816 | case DW_TAG_variant: | |
2817 | return "DW_TAG_variant"; | |
2818 | case DW_TAG_common_block: | |
2819 | return "DW_TAG_common_block"; | |
2820 | case DW_TAG_common_inclusion: | |
2821 | return "DW_TAG_common_inclusion"; | |
2822 | case DW_TAG_inheritance: | |
2823 | return "DW_TAG_inheritance"; | |
2824 | case DW_TAG_inlined_subroutine: | |
2825 | return "DW_TAG_inlined_subroutine"; | |
2826 | case DW_TAG_module: | |
2827 | return "DW_TAG_module"; | |
2828 | case DW_TAG_ptr_to_member_type: | |
2829 | return "DW_TAG_ptr_to_member_type"; | |
2830 | case DW_TAG_set_type: | |
2831 | return "DW_TAG_set_type"; | |
2832 | case DW_TAG_subrange_type: | |
2833 | return "DW_TAG_subrange_type"; | |
2834 | case DW_TAG_with_stmt: | |
2835 | return "DW_TAG_with_stmt"; | |
2836 | case DW_TAG_access_declaration: | |
2837 | return "DW_TAG_access_declaration"; | |
2838 | case DW_TAG_base_type: | |
2839 | return "DW_TAG_base_type"; | |
2840 | case DW_TAG_catch_block: | |
2841 | return "DW_TAG_catch_block"; | |
2842 | case DW_TAG_const_type: | |
2843 | return "DW_TAG_const_type"; | |
2844 | case DW_TAG_constant: | |
2845 | return "DW_TAG_constant"; | |
2846 | case DW_TAG_enumerator: | |
2847 | return "DW_TAG_enumerator"; | |
2848 | case DW_TAG_file_type: | |
2849 | return "DW_TAG_file_type"; | |
2850 | case DW_TAG_friend: | |
2851 | return "DW_TAG_friend"; | |
2852 | case DW_TAG_namelist: | |
2853 | return "DW_TAG_namelist"; | |
2854 | case DW_TAG_namelist_item: | |
2855 | return "DW_TAG_namelist_item"; | |
2856 | case DW_TAG_packed_type: | |
2857 | return "DW_TAG_packed_type"; | |
2858 | case DW_TAG_subprogram: | |
2859 | return "DW_TAG_subprogram"; | |
2860 | case DW_TAG_template_type_param: | |
2861 | return "DW_TAG_template_type_param"; | |
2862 | case DW_TAG_template_value_param: | |
2863 | return "DW_TAG_template_value_param"; | |
2864 | case DW_TAG_thrown_type: | |
2865 | return "DW_TAG_thrown_type"; | |
2866 | case DW_TAG_try_block: | |
2867 | return "DW_TAG_try_block"; | |
2868 | case DW_TAG_variant_part: | |
2869 | return "DW_TAG_variant_part"; | |
2870 | case DW_TAG_variable: | |
2871 | return "DW_TAG_variable"; | |
2872 | case DW_TAG_volatile_type: | |
2873 | return "DW_TAG_volatile_type"; | |
2874 | case DW_TAG_MIPS_loop: | |
2875 | return "DW_TAG_MIPS_loop"; | |
2876 | case DW_TAG_format_label: | |
2877 | return "DW_TAG_format_label"; | |
2878 | case DW_TAG_function_template: | |
2879 | return "DW_TAG_function_template"; | |
2880 | case DW_TAG_class_template: | |
2881 | return "DW_TAG_class_template"; | |
2882 | default: | |
2883 | return "DW_TAG_<unknown>"; | |
2884 | } | |
bdb669cb | 2885 | } |
a3f97cbb | 2886 | |
3f76745e | 2887 | /* Convert a DWARF attribute code into its string name. */ |
71dfc51f | 2888 | |
3f76745e JM |
2889 | static char * |
2890 | dwarf_attr_name (attr) | |
2891 | register unsigned attr; | |
4b674448 | 2892 | { |
3f76745e | 2893 | switch (attr) |
4b674448 | 2894 | { |
3f76745e JM |
2895 | case DW_AT_sibling: |
2896 | return "DW_AT_sibling"; | |
2897 | case DW_AT_location: | |
2898 | return "DW_AT_location"; | |
2899 | case DW_AT_name: | |
2900 | return "DW_AT_name"; | |
2901 | case DW_AT_ordering: | |
2902 | return "DW_AT_ordering"; | |
2903 | case DW_AT_subscr_data: | |
2904 | return "DW_AT_subscr_data"; | |
2905 | case DW_AT_byte_size: | |
2906 | return "DW_AT_byte_size"; | |
2907 | case DW_AT_bit_offset: | |
2908 | return "DW_AT_bit_offset"; | |
2909 | case DW_AT_bit_size: | |
2910 | return "DW_AT_bit_size"; | |
2911 | case DW_AT_element_list: | |
2912 | return "DW_AT_element_list"; | |
2913 | case DW_AT_stmt_list: | |
2914 | return "DW_AT_stmt_list"; | |
2915 | case DW_AT_low_pc: | |
2916 | return "DW_AT_low_pc"; | |
2917 | case DW_AT_high_pc: | |
2918 | return "DW_AT_high_pc"; | |
2919 | case DW_AT_language: | |
2920 | return "DW_AT_language"; | |
2921 | case DW_AT_member: | |
2922 | return "DW_AT_member"; | |
2923 | case DW_AT_discr: | |
2924 | return "DW_AT_discr"; | |
2925 | case DW_AT_discr_value: | |
2926 | return "DW_AT_discr_value"; | |
2927 | case DW_AT_visibility: | |
2928 | return "DW_AT_visibility"; | |
2929 | case DW_AT_import: | |
2930 | return "DW_AT_import"; | |
2931 | case DW_AT_string_length: | |
2932 | return "DW_AT_string_length"; | |
2933 | case DW_AT_common_reference: | |
2934 | return "DW_AT_common_reference"; | |
2935 | case DW_AT_comp_dir: | |
2936 | return "DW_AT_comp_dir"; | |
2937 | case DW_AT_const_value: | |
2938 | return "DW_AT_const_value"; | |
2939 | case DW_AT_containing_type: | |
2940 | return "DW_AT_containing_type"; | |
2941 | case DW_AT_default_value: | |
2942 | return "DW_AT_default_value"; | |
2943 | case DW_AT_inline: | |
2944 | return "DW_AT_inline"; | |
2945 | case DW_AT_is_optional: | |
2946 | return "DW_AT_is_optional"; | |
2947 | case DW_AT_lower_bound: | |
2948 | return "DW_AT_lower_bound"; | |
2949 | case DW_AT_producer: | |
2950 | return "DW_AT_producer"; | |
2951 | case DW_AT_prototyped: | |
2952 | return "DW_AT_prototyped"; | |
2953 | case DW_AT_return_addr: | |
2954 | return "DW_AT_return_addr"; | |
2955 | case DW_AT_start_scope: | |
2956 | return "DW_AT_start_scope"; | |
2957 | case DW_AT_stride_size: | |
2958 | return "DW_AT_stride_size"; | |
2959 | case DW_AT_upper_bound: | |
2960 | return "DW_AT_upper_bound"; | |
2961 | case DW_AT_abstract_origin: | |
2962 | return "DW_AT_abstract_origin"; | |
2963 | case DW_AT_accessibility: | |
2964 | return "DW_AT_accessibility"; | |
2965 | case DW_AT_address_class: | |
2966 | return "DW_AT_address_class"; | |
2967 | case DW_AT_artificial: | |
2968 | return "DW_AT_artificial"; | |
2969 | case DW_AT_base_types: | |
2970 | return "DW_AT_base_types"; | |
2971 | case DW_AT_calling_convention: | |
2972 | return "DW_AT_calling_convention"; | |
2973 | case DW_AT_count: | |
2974 | return "DW_AT_count"; | |
2975 | case DW_AT_data_member_location: | |
2976 | return "DW_AT_data_member_location"; | |
2977 | case DW_AT_decl_column: | |
2978 | return "DW_AT_decl_column"; | |
2979 | case DW_AT_decl_file: | |
2980 | return "DW_AT_decl_file"; | |
2981 | case DW_AT_decl_line: | |
2982 | return "DW_AT_decl_line"; | |
2983 | case DW_AT_declaration: | |
2984 | return "DW_AT_declaration"; | |
2985 | case DW_AT_discr_list: | |
2986 | return "DW_AT_discr_list"; | |
2987 | case DW_AT_encoding: | |
2988 | return "DW_AT_encoding"; | |
2989 | case DW_AT_external: | |
2990 | return "DW_AT_external"; | |
2991 | case DW_AT_frame_base: | |
2992 | return "DW_AT_frame_base"; | |
2993 | case DW_AT_friend: | |
2994 | return "DW_AT_friend"; | |
2995 | case DW_AT_identifier_case: | |
2996 | return "DW_AT_identifier_case"; | |
2997 | case DW_AT_macro_info: | |
2998 | return "DW_AT_macro_info"; | |
2999 | case DW_AT_namelist_items: | |
3000 | return "DW_AT_namelist_items"; | |
3001 | case DW_AT_priority: | |
3002 | return "DW_AT_priority"; | |
3003 | case DW_AT_segment: | |
3004 | return "DW_AT_segment"; | |
3005 | case DW_AT_specification: | |
3006 | return "DW_AT_specification"; | |
3007 | case DW_AT_static_link: | |
3008 | return "DW_AT_static_link"; | |
3009 | case DW_AT_type: | |
3010 | return "DW_AT_type"; | |
3011 | case DW_AT_use_location: | |
3012 | return "DW_AT_use_location"; | |
3013 | case DW_AT_variable_parameter: | |
3014 | return "DW_AT_variable_parameter"; | |
3015 | case DW_AT_virtuality: | |
3016 | return "DW_AT_virtuality"; | |
3017 | case DW_AT_vtable_elem_location: | |
3018 | return "DW_AT_vtable_elem_location"; | |
71dfc51f | 3019 | |
3f76745e JM |
3020 | case DW_AT_MIPS_fde: |
3021 | return "DW_AT_MIPS_fde"; | |
3022 | case DW_AT_MIPS_loop_begin: | |
3023 | return "DW_AT_MIPS_loop_begin"; | |
3024 | case DW_AT_MIPS_tail_loop_begin: | |
3025 | return "DW_AT_MIPS_tail_loop_begin"; | |
3026 | case DW_AT_MIPS_epilog_begin: | |
3027 | return "DW_AT_MIPS_epilog_begin"; | |
3028 | case DW_AT_MIPS_loop_unroll_factor: | |
3029 | return "DW_AT_MIPS_loop_unroll_factor"; | |
3030 | case DW_AT_MIPS_software_pipeline_depth: | |
3031 | return "DW_AT_MIPS_software_pipeline_depth"; | |
3032 | case DW_AT_MIPS_linkage_name: | |
3033 | return "DW_AT_MIPS_linkage_name"; | |
3034 | case DW_AT_MIPS_stride: | |
3035 | return "DW_AT_MIPS_stride"; | |
3036 | case DW_AT_MIPS_abstract_name: | |
3037 | return "DW_AT_MIPS_abstract_name"; | |
3038 | case DW_AT_MIPS_clone_origin: | |
3039 | return "DW_AT_MIPS_clone_origin"; | |
3040 | case DW_AT_MIPS_has_inlines: | |
3041 | return "DW_AT_MIPS_has_inlines"; | |
71dfc51f | 3042 | |
3f76745e JM |
3043 | case DW_AT_sf_names: |
3044 | return "DW_AT_sf_names"; | |
3045 | case DW_AT_src_info: | |
3046 | return "DW_AT_src_info"; | |
3047 | case DW_AT_mac_info: | |
3048 | return "DW_AT_mac_info"; | |
3049 | case DW_AT_src_coords: | |
3050 | return "DW_AT_src_coords"; | |
3051 | case DW_AT_body_begin: | |
3052 | return "DW_AT_body_begin"; | |
3053 | case DW_AT_body_end: | |
3054 | return "DW_AT_body_end"; | |
3055 | default: | |
3056 | return "DW_AT_<unknown>"; | |
4b674448 JM |
3057 | } |
3058 | } | |
3059 | ||
3f76745e | 3060 | /* Convert a DWARF value form code into its string name. */ |
71dfc51f | 3061 | |
3f76745e JM |
3062 | static char * |
3063 | dwarf_form_name (form) | |
3064 | register unsigned form; | |
4b674448 | 3065 | { |
3f76745e | 3066 | switch (form) |
4b674448 | 3067 | { |
3f76745e JM |
3068 | case DW_FORM_addr: |
3069 | return "DW_FORM_addr"; | |
3070 | case DW_FORM_block2: | |
3071 | return "DW_FORM_block2"; | |
3072 | case DW_FORM_block4: | |
3073 | return "DW_FORM_block4"; | |
3074 | case DW_FORM_data2: | |
3075 | return "DW_FORM_data2"; | |
3076 | case DW_FORM_data4: | |
3077 | return "DW_FORM_data4"; | |
3078 | case DW_FORM_data8: | |
3079 | return "DW_FORM_data8"; | |
3080 | case DW_FORM_string: | |
3081 | return "DW_FORM_string"; | |
3082 | case DW_FORM_block: | |
3083 | return "DW_FORM_block"; | |
3084 | case DW_FORM_block1: | |
3085 | return "DW_FORM_block1"; | |
3086 | case DW_FORM_data1: | |
3087 | return "DW_FORM_data1"; | |
3088 | case DW_FORM_flag: | |
3089 | return "DW_FORM_flag"; | |
3090 | case DW_FORM_sdata: | |
3091 | return "DW_FORM_sdata"; | |
3092 | case DW_FORM_strp: | |
3093 | return "DW_FORM_strp"; | |
3094 | case DW_FORM_udata: | |
3095 | return "DW_FORM_udata"; | |
3096 | case DW_FORM_ref_addr: | |
3097 | return "DW_FORM_ref_addr"; | |
3098 | case DW_FORM_ref1: | |
3099 | return "DW_FORM_ref1"; | |
3100 | case DW_FORM_ref2: | |
3101 | return "DW_FORM_ref2"; | |
3102 | case DW_FORM_ref4: | |
3103 | return "DW_FORM_ref4"; | |
3104 | case DW_FORM_ref8: | |
3105 | return "DW_FORM_ref8"; | |
3106 | case DW_FORM_ref_udata: | |
3107 | return "DW_FORM_ref_udata"; | |
3108 | case DW_FORM_indirect: | |
3109 | return "DW_FORM_indirect"; | |
3110 | default: | |
3111 | return "DW_FORM_<unknown>"; | |
4b674448 JM |
3112 | } |
3113 | } | |
3114 | ||
3f76745e | 3115 | /* Convert a DWARF stack opcode into its string name. */ |
71dfc51f | 3116 | |
3f76745e JM |
3117 | static char * |
3118 | dwarf_stack_op_name (op) | |
3119 | register unsigned op; | |
a3f97cbb | 3120 | { |
3f76745e | 3121 | switch (op) |
a3f97cbb | 3122 | { |
3f76745e JM |
3123 | case DW_OP_addr: |
3124 | return "DW_OP_addr"; | |
3125 | case DW_OP_deref: | |
3126 | return "DW_OP_deref"; | |
3127 | case DW_OP_const1u: | |
3128 | return "DW_OP_const1u"; | |
3129 | case DW_OP_const1s: | |
3130 | return "DW_OP_const1s"; | |
3131 | case DW_OP_const2u: | |
3132 | return "DW_OP_const2u"; | |
3133 | case DW_OP_const2s: | |
3134 | return "DW_OP_const2s"; | |
3135 | case DW_OP_const4u: | |
3136 | return "DW_OP_const4u"; | |
3137 | case DW_OP_const4s: | |
3138 | return "DW_OP_const4s"; | |
3139 | case DW_OP_const8u: | |
3140 | return "DW_OP_const8u"; | |
3141 | case DW_OP_const8s: | |
3142 | return "DW_OP_const8s"; | |
3143 | case DW_OP_constu: | |
3144 | return "DW_OP_constu"; | |
3145 | case DW_OP_consts: | |
3146 | return "DW_OP_consts"; | |
3147 | case DW_OP_dup: | |
3148 | return "DW_OP_dup"; | |
3149 | case DW_OP_drop: | |
3150 | return "DW_OP_drop"; | |
3151 | case DW_OP_over: | |
3152 | return "DW_OP_over"; | |
3153 | case DW_OP_pick: | |
3154 | return "DW_OP_pick"; | |
3155 | case DW_OP_swap: | |
3156 | return "DW_OP_swap"; | |
3157 | case DW_OP_rot: | |
3158 | return "DW_OP_rot"; | |
3159 | case DW_OP_xderef: | |
3160 | return "DW_OP_xderef"; | |
3161 | case DW_OP_abs: | |
3162 | return "DW_OP_abs"; | |
3163 | case DW_OP_and: | |
3164 | return "DW_OP_and"; | |
3165 | case DW_OP_div: | |
3166 | return "DW_OP_div"; | |
3167 | case DW_OP_minus: | |
3168 | return "DW_OP_minus"; | |
3169 | case DW_OP_mod: | |
3170 | return "DW_OP_mod"; | |
3171 | case DW_OP_mul: | |
3172 | return "DW_OP_mul"; | |
3173 | case DW_OP_neg: | |
3174 | return "DW_OP_neg"; | |
3175 | case DW_OP_not: | |
3176 | return "DW_OP_not"; | |
3177 | case DW_OP_or: | |
3178 | return "DW_OP_or"; | |
3179 | case DW_OP_plus: | |
3180 | return "DW_OP_plus"; | |
3181 | case DW_OP_plus_uconst: | |
3182 | return "DW_OP_plus_uconst"; | |
3183 | case DW_OP_shl: | |
3184 | return "DW_OP_shl"; | |
3185 | case DW_OP_shr: | |
3186 | return "DW_OP_shr"; | |
3187 | case DW_OP_shra: | |
3188 | return "DW_OP_shra"; | |
3189 | case DW_OP_xor: | |
3190 | return "DW_OP_xor"; | |
3191 | case DW_OP_bra: | |
3192 | return "DW_OP_bra"; | |
3193 | case DW_OP_eq: | |
3194 | return "DW_OP_eq"; | |
3195 | case DW_OP_ge: | |
3196 | return "DW_OP_ge"; | |
3197 | case DW_OP_gt: | |
3198 | return "DW_OP_gt"; | |
3199 | case DW_OP_le: | |
3200 | return "DW_OP_le"; | |
3201 | case DW_OP_lt: | |
3202 | return "DW_OP_lt"; | |
3203 | case DW_OP_ne: | |
3204 | return "DW_OP_ne"; | |
3205 | case DW_OP_skip: | |
3206 | return "DW_OP_skip"; | |
3207 | case DW_OP_lit0: | |
3208 | return "DW_OP_lit0"; | |
3209 | case DW_OP_lit1: | |
3210 | return "DW_OP_lit1"; | |
3211 | case DW_OP_lit2: | |
3212 | return "DW_OP_lit2"; | |
3213 | case DW_OP_lit3: | |
3214 | return "DW_OP_lit3"; | |
3215 | case DW_OP_lit4: | |
3216 | return "DW_OP_lit4"; | |
3217 | case DW_OP_lit5: | |
3218 | return "DW_OP_lit5"; | |
3219 | case DW_OP_lit6: | |
3220 | return "DW_OP_lit6"; | |
3221 | case DW_OP_lit7: | |
3222 | return "DW_OP_lit7"; | |
3223 | case DW_OP_lit8: | |
3224 | return "DW_OP_lit8"; | |
3225 | case DW_OP_lit9: | |
3226 | return "DW_OP_lit9"; | |
3227 | case DW_OP_lit10: | |
3228 | return "DW_OP_lit10"; | |
3229 | case DW_OP_lit11: | |
3230 | return "DW_OP_lit11"; | |
3231 | case DW_OP_lit12: | |
3232 | return "DW_OP_lit12"; | |
3233 | case DW_OP_lit13: | |
3234 | return "DW_OP_lit13"; | |
3235 | case DW_OP_lit14: | |
3236 | return "DW_OP_lit14"; | |
3237 | case DW_OP_lit15: | |
3238 | return "DW_OP_lit15"; | |
3239 | case DW_OP_lit16: | |
3240 | return "DW_OP_lit16"; | |
3241 | case DW_OP_lit17: | |
3242 | return "DW_OP_lit17"; | |
3243 | case DW_OP_lit18: | |
3244 | return "DW_OP_lit18"; | |
3245 | case DW_OP_lit19: | |
3246 | return "DW_OP_lit19"; | |
3247 | case DW_OP_lit20: | |
3248 | return "DW_OP_lit20"; | |
3249 | case DW_OP_lit21: | |
3250 | return "DW_OP_lit21"; | |
3251 | case DW_OP_lit22: | |
3252 | return "DW_OP_lit22"; | |
3253 | case DW_OP_lit23: | |
3254 | return "DW_OP_lit23"; | |
3255 | case DW_OP_lit24: | |
3256 | return "DW_OP_lit24"; | |
3257 | case DW_OP_lit25: | |
3258 | return "DW_OP_lit25"; | |
3259 | case DW_OP_lit26: | |
3260 | return "DW_OP_lit26"; | |
3261 | case DW_OP_lit27: | |
3262 | return "DW_OP_lit27"; | |
3263 | case DW_OP_lit28: | |
3264 | return "DW_OP_lit28"; | |
3265 | case DW_OP_lit29: | |
3266 | return "DW_OP_lit29"; | |
3267 | case DW_OP_lit30: | |
3268 | return "DW_OP_lit30"; | |
3269 | case DW_OP_lit31: | |
3270 | return "DW_OP_lit31"; | |
3271 | case DW_OP_reg0: | |
3272 | return "DW_OP_reg0"; | |
3273 | case DW_OP_reg1: | |
3274 | return "DW_OP_reg1"; | |
3275 | case DW_OP_reg2: | |
3276 | return "DW_OP_reg2"; | |
3277 | case DW_OP_reg3: | |
3278 | return "DW_OP_reg3"; | |
3279 | case DW_OP_reg4: | |
3280 | return "DW_OP_reg4"; | |
3281 | case DW_OP_reg5: | |
3282 | return "DW_OP_reg5"; | |
3283 | case DW_OP_reg6: | |
3284 | return "DW_OP_reg6"; | |
3285 | case DW_OP_reg7: | |
3286 | return "DW_OP_reg7"; | |
3287 | case DW_OP_reg8: | |
3288 | return "DW_OP_reg8"; | |
3289 | case DW_OP_reg9: | |
3290 | return "DW_OP_reg9"; | |
3291 | case DW_OP_reg10: | |
3292 | return "DW_OP_reg10"; | |
3293 | case DW_OP_reg11: | |
3294 | return "DW_OP_reg11"; | |
3295 | case DW_OP_reg12: | |
3296 | return "DW_OP_reg12"; | |
3297 | case DW_OP_reg13: | |
3298 | return "DW_OP_reg13"; | |
3299 | case DW_OP_reg14: | |
3300 | return "DW_OP_reg14"; | |
3301 | case DW_OP_reg15: | |
3302 | return "DW_OP_reg15"; | |
3303 | case DW_OP_reg16: | |
3304 | return "DW_OP_reg16"; | |
3305 | case DW_OP_reg17: | |
3306 | return "DW_OP_reg17"; | |
3307 | case DW_OP_reg18: | |
3308 | return "DW_OP_reg18"; | |
3309 | case DW_OP_reg19: | |
3310 | return "DW_OP_reg19"; | |
3311 | case DW_OP_reg20: | |
3312 | return "DW_OP_reg20"; | |
3313 | case DW_OP_reg21: | |
3314 | return "DW_OP_reg21"; | |
3315 | case DW_OP_reg22: | |
3316 | return "DW_OP_reg22"; | |
3317 | case DW_OP_reg23: | |
3318 | return "DW_OP_reg23"; | |
3319 | case DW_OP_reg24: | |
3320 | return "DW_OP_reg24"; | |
3321 | case DW_OP_reg25: | |
3322 | return "DW_OP_reg25"; | |
3323 | case DW_OP_reg26: | |
3324 | return "DW_OP_reg26"; | |
3325 | case DW_OP_reg27: | |
3326 | return "DW_OP_reg27"; | |
3327 | case DW_OP_reg28: | |
3328 | return "DW_OP_reg28"; | |
3329 | case DW_OP_reg29: | |
3330 | return "DW_OP_reg29"; | |
3331 | case DW_OP_reg30: | |
3332 | return "DW_OP_reg30"; | |
3333 | case DW_OP_reg31: | |
3334 | return "DW_OP_reg31"; | |
3335 | case DW_OP_breg0: | |
3336 | return "DW_OP_breg0"; | |
3337 | case DW_OP_breg1: | |
3338 | return "DW_OP_breg1"; | |
3339 | case DW_OP_breg2: | |
3340 | return "DW_OP_breg2"; | |
3341 | case DW_OP_breg3: | |
3342 | return "DW_OP_breg3"; | |
3343 | case DW_OP_breg4: | |
3344 | return "DW_OP_breg4"; | |
3345 | case DW_OP_breg5: | |
3346 | return "DW_OP_breg5"; | |
3347 | case DW_OP_breg6: | |
3348 | return "DW_OP_breg6"; | |
3349 | case DW_OP_breg7: | |
3350 | return "DW_OP_breg7"; | |
3351 | case DW_OP_breg8: | |
3352 | return "DW_OP_breg8"; | |
3353 | case DW_OP_breg9: | |
3354 | return "DW_OP_breg9"; | |
3355 | case DW_OP_breg10: | |
3356 | return "DW_OP_breg10"; | |
3357 | case DW_OP_breg11: | |
3358 | return "DW_OP_breg11"; | |
3359 | case DW_OP_breg12: | |
3360 | return "DW_OP_breg12"; | |
3361 | case DW_OP_breg13: | |
3362 | return "DW_OP_breg13"; | |
3363 | case DW_OP_breg14: | |
3364 | return "DW_OP_breg14"; | |
3365 | case DW_OP_breg15: | |
3366 | return "DW_OP_breg15"; | |
3367 | case DW_OP_breg16: | |
3368 | return "DW_OP_breg16"; | |
3369 | case DW_OP_breg17: | |
3370 | return "DW_OP_breg17"; | |
3371 | case DW_OP_breg18: | |
3372 | return "DW_OP_breg18"; | |
3373 | case DW_OP_breg19: | |
3374 | return "DW_OP_breg19"; | |
3375 | case DW_OP_breg20: | |
3376 | return "DW_OP_breg20"; | |
3377 | case DW_OP_breg21: | |
3378 | return "DW_OP_breg21"; | |
3379 | case DW_OP_breg22: | |
3380 | return "DW_OP_breg22"; | |
3381 | case DW_OP_breg23: | |
3382 | return "DW_OP_breg23"; | |
3383 | case DW_OP_breg24: | |
3384 | return "DW_OP_breg24"; | |
3385 | case DW_OP_breg25: | |
3386 | return "DW_OP_breg25"; | |
3387 | case DW_OP_breg26: | |
3388 | return "DW_OP_breg26"; | |
3389 | case DW_OP_breg27: | |
3390 | return "DW_OP_breg27"; | |
3391 | case DW_OP_breg28: | |
3392 | return "DW_OP_breg28"; | |
3393 | case DW_OP_breg29: | |
3394 | return "DW_OP_breg29"; | |
3395 | case DW_OP_breg30: | |
3396 | return "DW_OP_breg30"; | |
3397 | case DW_OP_breg31: | |
3398 | return "DW_OP_breg31"; | |
3399 | case DW_OP_regx: | |
3400 | return "DW_OP_regx"; | |
3401 | case DW_OP_fbreg: | |
3402 | return "DW_OP_fbreg"; | |
3403 | case DW_OP_bregx: | |
3404 | return "DW_OP_bregx"; | |
3405 | case DW_OP_piece: | |
3406 | return "DW_OP_piece"; | |
3407 | case DW_OP_deref_size: | |
3408 | return "DW_OP_deref_size"; | |
3409 | case DW_OP_xderef_size: | |
3410 | return "DW_OP_xderef_size"; | |
3411 | case DW_OP_nop: | |
3412 | return "DW_OP_nop"; | |
3413 | default: | |
3414 | return "OP_<unknown>"; | |
a3f97cbb JW |
3415 | } |
3416 | } | |
3417 | ||
3f76745e | 3418 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 3419 | |
3f76745e JM |
3420 | static char * |
3421 | dwarf_type_encoding_name (enc) | |
3422 | register unsigned enc; | |
a3f97cbb | 3423 | { |
3f76745e | 3424 | switch (enc) |
a3f97cbb | 3425 | { |
3f76745e JM |
3426 | case DW_ATE_address: |
3427 | return "DW_ATE_address"; | |
3428 | case DW_ATE_boolean: | |
3429 | return "DW_ATE_boolean"; | |
3430 | case DW_ATE_complex_float: | |
3431 | return "DW_ATE_complex_float"; | |
3432 | case DW_ATE_float: | |
3433 | return "DW_ATE_float"; | |
3434 | case DW_ATE_signed: | |
3435 | return "DW_ATE_signed"; | |
3436 | case DW_ATE_signed_char: | |
3437 | return "DW_ATE_signed_char"; | |
3438 | case DW_ATE_unsigned: | |
3439 | return "DW_ATE_unsigned"; | |
3440 | case DW_ATE_unsigned_char: | |
3441 | return "DW_ATE_unsigned_char"; | |
3442 | default: | |
3443 | return "DW_ATE_<unknown>"; | |
3444 | } | |
a3f97cbb | 3445 | } |
3f76745e JM |
3446 | \f |
3447 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
3448 | instance of an inlined instance of a decl which is local to an inline | |
3449 | function, so we have to trace all of the way back through the origin chain | |
3450 | to find out what sort of node actually served as the original seed for the | |
3451 | given block. */ | |
a3f97cbb | 3452 | |
3f76745e JM |
3453 | static tree |
3454 | decl_ultimate_origin (decl) | |
3455 | register tree decl; | |
a3f97cbb | 3456 | { |
3f76745e | 3457 | register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl); |
71dfc51f | 3458 | |
3f76745e JM |
3459 | if (immediate_origin == NULL_TREE) |
3460 | return NULL_TREE; | |
3461 | else | |
3462 | { | |
3463 | register tree ret_val; | |
3464 | register tree lookahead = immediate_origin; | |
71dfc51f | 3465 | |
3f76745e JM |
3466 | do |
3467 | { | |
3468 | ret_val = lookahead; | |
3469 | lookahead = DECL_ABSTRACT_ORIGIN (ret_val); | |
3470 | } | |
3471 | while (lookahead != NULL && lookahead != ret_val); | |
3472 | ||
3473 | return ret_val; | |
3474 | } | |
a3f97cbb JW |
3475 | } |
3476 | ||
3f76745e JM |
3477 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
3478 | instance of an inlined instance of a block which is local to an inline | |
3479 | function, so we have to trace all of the way back through the origin chain | |
3480 | to find out what sort of node actually served as the original seed for the | |
3481 | given block. */ | |
71dfc51f | 3482 | |
3f76745e JM |
3483 | static tree |
3484 | block_ultimate_origin (block) | |
3485 | register tree block; | |
a3f97cbb | 3486 | { |
3f76745e | 3487 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 3488 | |
3f76745e JM |
3489 | if (immediate_origin == NULL_TREE) |
3490 | return NULL_TREE; | |
3491 | else | |
3492 | { | |
3493 | register tree ret_val; | |
3494 | register tree lookahead = immediate_origin; | |
71dfc51f | 3495 | |
3f76745e JM |
3496 | do |
3497 | { | |
3498 | ret_val = lookahead; | |
3499 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
3500 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
3501 | : NULL; | |
3502 | } | |
3503 | while (lookahead != NULL && lookahead != ret_val); | |
3504 | ||
3505 | return ret_val; | |
3506 | } | |
a3f97cbb JW |
3507 | } |
3508 | ||
3f76745e JM |
3509 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
3510 | of a virtual function may refer to a base class, so we check the 'this' | |
3511 | parameter. */ | |
71dfc51f | 3512 | |
3f76745e JM |
3513 | static tree |
3514 | decl_class_context (decl) | |
3515 | tree decl; | |
a3f97cbb | 3516 | { |
3f76745e | 3517 | tree context = NULL_TREE; |
71dfc51f | 3518 | |
3f76745e JM |
3519 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
3520 | context = DECL_CONTEXT (decl); | |
3521 | else | |
3522 | context = TYPE_MAIN_VARIANT | |
3523 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 3524 | |
3f76745e JM |
3525 | if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't') |
3526 | context = NULL_TREE; | |
3527 | ||
3528 | return context; | |
a3f97cbb JW |
3529 | } |
3530 | \f | |
3f76745e | 3531 | /* Add an attribute/value pair to a DIE */ |
71dfc51f RK |
3532 | |
3533 | static inline void | |
3f76745e JM |
3534 | add_dwarf_attr (die, attr) |
3535 | register dw_die_ref die; | |
3536 | register dw_attr_ref attr; | |
a3f97cbb | 3537 | { |
3f76745e | 3538 | if (die != NULL && attr != NULL) |
a3f97cbb | 3539 | { |
3f76745e | 3540 | if (die->die_attr == NULL) |
a3f97cbb | 3541 | { |
3f76745e JM |
3542 | die->die_attr = attr; |
3543 | die->die_attr_last = attr; | |
3544 | } | |
3545 | else | |
3546 | { | |
3547 | die->die_attr_last->dw_attr_next = attr; | |
3548 | die->die_attr_last = attr; | |
a3f97cbb | 3549 | } |
a3f97cbb JW |
3550 | } |
3551 | } | |
3552 | ||
3f76745e | 3553 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 3554 | |
3f76745e JM |
3555 | static inline void |
3556 | add_AT_flag (die, attr_kind, flag) | |
3557 | register dw_die_ref die; | |
3558 | register enum dwarf_attribute attr_kind; | |
3559 | register unsigned flag; | |
a3f97cbb | 3560 | { |
3f76745e | 3561 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3562 | |
3f76745e JM |
3563 | attr->dw_attr_next = NULL; |
3564 | attr->dw_attr = attr_kind; | |
3565 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
3566 | attr->dw_attr_val.v.val_flag = flag; | |
3567 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3568 | } |
3569 | ||
3f76745e | 3570 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 3571 | |
3f76745e JM |
3572 | static inline void |
3573 | add_AT_int (die, attr_kind, int_val) | |
3574 | register dw_die_ref die; | |
3575 | register enum dwarf_attribute attr_kind; | |
3576 | register long int int_val; | |
a3f97cbb | 3577 | { |
3f76745e JM |
3578 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3579 | ||
3580 | attr->dw_attr_next = NULL; | |
3581 | attr->dw_attr = attr_kind; | |
3582 | attr->dw_attr_val.val_class = dw_val_class_const; | |
3583 | attr->dw_attr_val.v.val_int = int_val; | |
3584 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3585 | } |
3586 | ||
3f76745e | 3587 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 3588 | |
3f76745e JM |
3589 | static inline void |
3590 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
3591 | register dw_die_ref die; | |
3592 | register enum dwarf_attribute attr_kind; | |
3593 | register unsigned long unsigned_val; | |
a3f97cbb | 3594 | { |
3f76745e JM |
3595 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3596 | ||
3597 | attr->dw_attr_next = NULL; | |
3598 | attr->dw_attr = attr_kind; | |
3599 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
3600 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
3601 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3602 | } |
71dfc51f | 3603 | |
3f76745e JM |
3604 | /* Add an unsigned double integer attribute value to a DIE. */ |
3605 | ||
3606 | static inline void | |
3607 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 3608 | register dw_die_ref die; |
3f76745e JM |
3609 | register enum dwarf_attribute attr_kind; |
3610 | register unsigned long val_hi; | |
3611 | register unsigned long val_low; | |
a3f97cbb | 3612 | { |
3f76745e | 3613 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3614 | |
3f76745e JM |
3615 | attr->dw_attr_next = NULL; |
3616 | attr->dw_attr = attr_kind; | |
3617 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
3618 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
3619 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
3620 | add_dwarf_attr (die, attr); | |
3621 | } | |
71dfc51f | 3622 | |
3f76745e | 3623 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 3624 | |
3f76745e JM |
3625 | static inline void |
3626 | add_AT_float (die, attr_kind, length, array) | |
3627 | register dw_die_ref die; | |
3628 | register enum dwarf_attribute attr_kind; | |
3629 | register unsigned length; | |
3630 | register long *array; | |
3631 | { | |
3632 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
3633 | ||
3634 | attr->dw_attr_next = NULL; | |
3635 | attr->dw_attr = attr_kind; | |
3636 | attr->dw_attr_val.val_class = dw_val_class_float; | |
3637 | attr->dw_attr_val.v.val_float.length = length; | |
3638 | attr->dw_attr_val.v.val_float.array = array; | |
3639 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3640 | } |
3641 | ||
3f76745e | 3642 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 3643 | |
3f76745e JM |
3644 | static inline void |
3645 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 3646 | register dw_die_ref die; |
3f76745e JM |
3647 | register enum dwarf_attribute attr_kind; |
3648 | register char *str; | |
a3f97cbb | 3649 | { |
3f76745e | 3650 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3651 | |
3f76745e JM |
3652 | attr->dw_attr_next = NULL; |
3653 | attr->dw_attr = attr_kind; | |
3654 | attr->dw_attr_val.val_class = dw_val_class_str; | |
3655 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
3656 | add_dwarf_attr (die, attr); | |
3657 | } | |
71dfc51f | 3658 | |
3f76745e | 3659 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 3660 | |
3f76745e JM |
3661 | static inline void |
3662 | add_AT_die_ref (die, attr_kind, targ_die) | |
3663 | register dw_die_ref die; | |
3664 | register enum dwarf_attribute attr_kind; | |
3665 | register dw_die_ref targ_die; | |
3666 | { | |
3667 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3668 | |
3f76745e JM |
3669 | attr->dw_attr_next = NULL; |
3670 | attr->dw_attr = attr_kind; | |
3671 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
3672 | attr->dw_attr_val.v.val_die_ref = targ_die; | |
3673 | add_dwarf_attr (die, attr); | |
3674 | } | |
b1ccbc24 | 3675 | |
3f76745e | 3676 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 3677 | |
3f76745e JM |
3678 | static inline void |
3679 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
3680 | register dw_die_ref die; | |
3681 | register enum dwarf_attribute attr_kind; | |
3682 | register unsigned targ_fde; | |
3683 | { | |
3684 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 3685 | |
3f76745e JM |
3686 | attr->dw_attr_next = NULL; |
3687 | attr->dw_attr = attr_kind; | |
3688 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
3689 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
3690 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3691 | } |
71dfc51f | 3692 | |
3f76745e | 3693 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 3694 | |
3f76745e JM |
3695 | static inline void |
3696 | add_AT_loc (die, attr_kind, loc) | |
3697 | register dw_die_ref die; | |
3698 | register enum dwarf_attribute attr_kind; | |
3699 | register dw_loc_descr_ref loc; | |
3700 | { | |
3701 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3702 | |
3f76745e JM |
3703 | attr->dw_attr_next = NULL; |
3704 | attr->dw_attr = attr_kind; | |
3705 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
3706 | attr->dw_attr_val.v.val_loc = loc; | |
3707 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3708 | } |
3709 | ||
3f76745e | 3710 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 3711 | |
3f76745e JM |
3712 | static inline void |
3713 | add_AT_addr (die, attr_kind, addr) | |
3714 | register dw_die_ref die; | |
3715 | register enum dwarf_attribute attr_kind; | |
3716 | char *addr; | |
a3f97cbb | 3717 | { |
3f76745e | 3718 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3719 | |
3f76745e JM |
3720 | attr->dw_attr_next = NULL; |
3721 | attr->dw_attr = attr_kind; | |
3722 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
3723 | attr->dw_attr_val.v.val_addr = addr; | |
3724 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3725 | } |
3726 | ||
3f76745e | 3727 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 3728 | |
3f76745e JM |
3729 | static inline void |
3730 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
3731 | register dw_die_ref die; | |
3732 | register enum dwarf_attribute attr_kind; | |
3733 | register char *lbl_id; | |
a3f97cbb | 3734 | { |
3f76745e | 3735 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3736 | |
3f76745e JM |
3737 | attr->dw_attr_next = NULL; |
3738 | attr->dw_attr = attr_kind; | |
3739 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
3740 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
3741 | add_dwarf_attr (die, attr); | |
3742 | } | |
71dfc51f | 3743 | |
3f76745e JM |
3744 | /* Add a section offset attribute value to a DIE. */ |
3745 | ||
3746 | static inline void | |
3747 | add_AT_section_offset (die, attr_kind, section) | |
3748 | register dw_die_ref die; | |
3749 | register enum dwarf_attribute attr_kind; | |
3750 | register char *section; | |
3751 | { | |
3752 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3753 | |
3f76745e JM |
3754 | attr->dw_attr_next = NULL; |
3755 | attr->dw_attr = attr_kind; | |
3756 | attr->dw_attr_val.val_class = dw_val_class_section_offset; | |
3757 | attr->dw_attr_val.v.val_section = section; | |
3758 | add_dwarf_attr (die, attr); | |
3759 | ||
a3f97cbb JW |
3760 | } |
3761 | ||
3f76745e | 3762 | /* Test if die refers to an external subroutine. */ |
71dfc51f | 3763 | |
3f76745e JM |
3764 | static inline int |
3765 | is_extern_subr_die (die) | |
3766 | register dw_die_ref die; | |
a3f97cbb | 3767 | { |
3f76745e JM |
3768 | register dw_attr_ref a; |
3769 | register int is_subr = FALSE; | |
3770 | register int is_extern = FALSE; | |
71dfc51f | 3771 | |
3f76745e | 3772 | if (die != NULL && die->die_tag == DW_TAG_subprogram) |
a3f97cbb | 3773 | { |
3f76745e JM |
3774 | is_subr = TRUE; |
3775 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3776 | { | |
3777 | if (a->dw_attr == DW_AT_external | |
3778 | && a->dw_attr_val.val_class == dw_val_class_flag | |
3779 | && a->dw_attr_val.v.val_flag != 0) | |
3780 | { | |
3781 | is_extern = TRUE; | |
3782 | break; | |
3783 | } | |
3784 | } | |
a3f97cbb | 3785 | } |
71dfc51f | 3786 | |
3f76745e | 3787 | return is_subr && is_extern; |
a3f97cbb JW |
3788 | } |
3789 | ||
3f76745e | 3790 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 3791 | |
3f76745e JM |
3792 | static inline dw_attr_ref |
3793 | get_AT (die, attr_kind) | |
3794 | register dw_die_ref die; | |
3795 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 3796 | { |
3f76745e JM |
3797 | register dw_attr_ref a; |
3798 | register dw_die_ref spec = NULL; | |
3799 | ||
3800 | if (die != NULL) | |
3801 | { | |
3802 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3803 | { | |
3804 | if (a->dw_attr == attr_kind) | |
3805 | return a; | |
71dfc51f | 3806 | |
3f76745e JM |
3807 | if (a->dw_attr == DW_AT_specification |
3808 | || a->dw_attr == DW_AT_abstract_origin) | |
3809 | spec = a->dw_attr_val.v.val_die_ref; | |
3810 | } | |
71dfc51f | 3811 | |
3f76745e JM |
3812 | if (spec) |
3813 | return get_AT (spec, attr_kind); | |
3814 | } | |
3815 | ||
3816 | return NULL; | |
f37230f0 JM |
3817 | } |
3818 | ||
3f76745e JM |
3819 | /* Return the "low pc" attribute value, typically associated with |
3820 | a subprogram DIE. Return null if the "low pc" attribute is | |
3821 | either not prsent, or if it cannot be represented as an | |
3822 | assembler label identifier. */ | |
71dfc51f | 3823 | |
3f76745e JM |
3824 | static inline char * |
3825 | get_AT_low_pc (die) | |
3826 | register dw_die_ref die; | |
7e23cb16 | 3827 | { |
3f76745e | 3828 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
7e23cb16 | 3829 | |
3f76745e JM |
3830 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3831 | return a->dw_attr_val.v.val_lbl_id; | |
7e23cb16 | 3832 | |
3f76745e | 3833 | return NULL; |
7e23cb16 JM |
3834 | } |
3835 | ||
3f76745e JM |
3836 | /* Return the "high pc" attribute value, typically associated with |
3837 | a subprogram DIE. Return null if the "high pc" attribute is | |
3838 | either not prsent, or if it cannot be represented as an | |
3839 | assembler label identifier. */ | |
71dfc51f | 3840 | |
3f76745e JM |
3841 | static inline char * |
3842 | get_AT_hi_pc (die) | |
a3f97cbb JW |
3843 | register dw_die_ref die; |
3844 | { | |
3f76745e | 3845 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
71dfc51f | 3846 | |
3f76745e JM |
3847 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3848 | return a->dw_attr_val.v.val_lbl_id; | |
f37230f0 | 3849 | |
3f76745e JM |
3850 | return NULL; |
3851 | } | |
3852 | ||
3853 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
3854 | NULL if it is not present. */ | |
71dfc51f | 3855 | |
3f76745e JM |
3856 | static inline char * |
3857 | get_AT_string (die, attr_kind) | |
3858 | register dw_die_ref die; | |
3859 | register enum dwarf_attribute attr_kind; | |
3860 | { | |
3861 | register dw_attr_ref a = get_AT (die, attr_kind); | |
3862 | ||
3863 | if (a && a->dw_attr_val.val_class == dw_val_class_str) | |
3864 | return a->dw_attr_val.v.val_str; | |
3865 | ||
3866 | return NULL; | |
a3f97cbb JW |
3867 | } |
3868 | ||
3f76745e JM |
3869 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
3870 | if it is not present. */ | |
71dfc51f | 3871 | |
3f76745e JM |
3872 | static inline int |
3873 | get_AT_flag (die, attr_kind) | |
3874 | register dw_die_ref die; | |
3875 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3876 | { |
3f76745e | 3877 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3878 | |
3f76745e JM |
3879 | if (a && a->dw_attr_val.val_class == dw_val_class_flag) |
3880 | return a->dw_attr_val.v.val_flag; | |
71dfc51f | 3881 | |
3f76745e | 3882 | return -1; |
a3f97cbb JW |
3883 | } |
3884 | ||
3f76745e JM |
3885 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
3886 | if it is not present. */ | |
71dfc51f | 3887 | |
3f76745e JM |
3888 | static inline unsigned |
3889 | get_AT_unsigned (die, attr_kind) | |
3890 | register dw_die_ref die; | |
3891 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3892 | { |
3f76745e | 3893 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3894 | |
3f76745e JM |
3895 | if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const) |
3896 | return a->dw_attr_val.v.val_unsigned; | |
71dfc51f | 3897 | |
3f76745e JM |
3898 | return 0; |
3899 | } | |
71dfc51f | 3900 | |
3f76745e JM |
3901 | static inline int |
3902 | is_c_family () | |
3903 | { | |
3904 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3905 | |
3f76745e JM |
3906 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
3907 | || lang == DW_LANG_C_plus_plus); | |
3908 | } | |
71dfc51f | 3909 | |
3f76745e JM |
3910 | static inline int |
3911 | is_fortran () | |
3912 | { | |
3913 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3914 | |
3f76745e JM |
3915 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
3916 | } | |
71dfc51f | 3917 | |
3f76745e | 3918 | /* Remove the specified attribute if present. */ |
71dfc51f | 3919 | |
3f76745e JM |
3920 | static inline void |
3921 | remove_AT (die, attr_kind) | |
3922 | register dw_die_ref die; | |
3923 | register enum dwarf_attribute attr_kind; | |
3924 | { | |
3925 | register dw_attr_ref a; | |
3926 | register dw_attr_ref removed = NULL;; | |
a3f97cbb | 3927 | |
3f76745e JM |
3928 | if (die != NULL) |
3929 | { | |
3930 | if (die->die_attr->dw_attr == attr_kind) | |
3931 | { | |
3932 | removed = die->die_attr; | |
3933 | if (die->die_attr_last == die->die_attr) | |
3934 | die->die_attr_last = NULL; | |
71dfc51f | 3935 | |
3f76745e JM |
3936 | die->die_attr = die->die_attr->dw_attr_next; |
3937 | } | |
71dfc51f | 3938 | |
3f76745e JM |
3939 | else |
3940 | for (a = die->die_attr; a->dw_attr_next != NULL; | |
3941 | a = a->dw_attr_next) | |
3942 | if (a->dw_attr_next->dw_attr == attr_kind) | |
3943 | { | |
3944 | removed = a->dw_attr_next; | |
3945 | if (die->die_attr_last == a->dw_attr_next) | |
3946 | die->die_attr_last = a; | |
71dfc51f | 3947 | |
3f76745e JM |
3948 | a->dw_attr_next = a->dw_attr_next->dw_attr_next; |
3949 | break; | |
3950 | } | |
71dfc51f | 3951 | |
3f76745e JM |
3952 | if (removed != 0) |
3953 | free (removed); | |
3954 | } | |
3955 | } | |
71dfc51f | 3956 | |
3f76745e | 3957 | /* Discard the children of this DIE. */ |
71dfc51f | 3958 | |
3f76745e JM |
3959 | static inline void |
3960 | remove_children (die) | |
3961 | register dw_die_ref die; | |
3962 | { | |
3963 | register dw_die_ref child_die = die->die_child; | |
3964 | ||
3965 | die->die_child = NULL; | |
3966 | die->die_child_last = NULL; | |
3967 | ||
3968 | while (child_die != NULL) | |
a3f97cbb | 3969 | { |
3f76745e JM |
3970 | register dw_die_ref tmp_die = child_die; |
3971 | register dw_attr_ref a; | |
71dfc51f | 3972 | |
3f76745e JM |
3973 | child_die = child_die->die_sib; |
3974 | ||
3975 | for (a = tmp_die->die_attr; a != NULL; ) | |
a3f97cbb | 3976 | { |
3f76745e | 3977 | register dw_attr_ref tmp_a = a; |
71dfc51f | 3978 | |
3f76745e JM |
3979 | a = a->dw_attr_next; |
3980 | free (tmp_a); | |
a3f97cbb | 3981 | } |
71dfc51f | 3982 | |
3f76745e JM |
3983 | free (tmp_die); |
3984 | } | |
3985 | } | |
71dfc51f | 3986 | |
3f76745e | 3987 | /* Add a child DIE below its parent. */ |
71dfc51f | 3988 | |
3f76745e JM |
3989 | static inline void |
3990 | add_child_die (die, child_die) | |
3991 | register dw_die_ref die; | |
3992 | register dw_die_ref child_die; | |
3993 | { | |
3994 | if (die != NULL && child_die != NULL) | |
e90b62db | 3995 | { |
3a88cbd1 JL |
3996 | if (die == child_die) |
3997 | abort (); | |
3f76745e JM |
3998 | child_die->die_parent = die; |
3999 | child_die->die_sib = NULL; | |
4000 | ||
4001 | if (die->die_child == NULL) | |
e90b62db | 4002 | { |
3f76745e JM |
4003 | die->die_child = child_die; |
4004 | die->die_child_last = child_die; | |
e90b62db JM |
4005 | } |
4006 | else | |
e90b62db | 4007 | { |
3f76745e JM |
4008 | die->die_child_last->die_sib = child_die; |
4009 | die->die_child_last = child_die; | |
e90b62db | 4010 | } |
3f76745e JM |
4011 | } |
4012 | } | |
4013 | ||
4014 | /* Return a pointer to a newly created DIE node. */ | |
4015 | ||
4016 | static inline dw_die_ref | |
4017 | new_die (tag_value, parent_die) | |
4018 | register enum dwarf_tag tag_value; | |
4019 | register dw_die_ref parent_die; | |
4020 | { | |
4021 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
4022 | ||
4023 | die->die_tag = tag_value; | |
4024 | die->die_abbrev = 0; | |
4025 | die->die_offset = 0; | |
4026 | die->die_child = NULL; | |
4027 | die->die_parent = NULL; | |
4028 | die->die_sib = NULL; | |
4029 | die->die_child_last = NULL; | |
4030 | die->die_attr = NULL; | |
4031 | die->die_attr_last = NULL; | |
4032 | ||
4033 | if (parent_die != NULL) | |
4034 | add_child_die (parent_die, die); | |
4035 | else | |
ef76d03b JW |
4036 | { |
4037 | limbo_die_node *limbo_node; | |
4038 | ||
4039 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4040 | limbo_node->die = die; | |
4041 | limbo_node->next = limbo_die_list; | |
4042 | limbo_die_list = limbo_node; | |
4043 | } | |
71dfc51f | 4044 | |
3f76745e JM |
4045 | return die; |
4046 | } | |
71dfc51f | 4047 | |
3f76745e | 4048 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4049 | |
3f76745e JM |
4050 | static inline dw_die_ref |
4051 | lookup_type_die (type) | |
4052 | register tree type; | |
4053 | { | |
4054 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
4055 | } | |
e90b62db | 4056 | |
3f76745e | 4057 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4058 | |
3f76745e JM |
4059 | static void |
4060 | equate_type_number_to_die (type, type_die) | |
4061 | register tree type; | |
4062 | register dw_die_ref type_die; | |
4063 | { | |
4064 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4065 | } | |
71dfc51f | 4066 | |
3f76745e | 4067 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4068 | |
3f76745e JM |
4069 | static inline dw_die_ref |
4070 | lookup_decl_die (decl) | |
4071 | register tree decl; | |
4072 | { | |
4073 | register unsigned decl_id = DECL_UID (decl); | |
4074 | ||
4075 | return (decl_id < decl_die_table_in_use | |
4076 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4077 | } |
4078 | ||
3f76745e | 4079 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4080 | |
3f76745e JM |
4081 | static void |
4082 | equate_decl_number_to_die (decl, decl_die) | |
4083 | register tree decl; | |
4084 | register dw_die_ref decl_die; | |
a3f97cbb | 4085 | { |
3f76745e | 4086 | register unsigned decl_id = DECL_UID (decl); |
d291dd49 | 4087 | register unsigned i; |
3f76745e | 4088 | register unsigned num_allocated; |
d291dd49 | 4089 | |
3f76745e | 4090 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4091 | { |
3f76745e JM |
4092 | num_allocated |
4093 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4094 | / DECL_DIE_TABLE_INCREMENT) | |
4095 | * DECL_DIE_TABLE_INCREMENT; | |
4096 | ||
4097 | decl_die_table | |
4098 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4099 | sizeof (dw_die_ref) * num_allocated); | |
4100 | ||
4101 | bzero ((char *) &decl_die_table[decl_die_table_allocated], | |
4102 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); | |
4103 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4104 | } |
71dfc51f | 4105 | |
3f76745e JM |
4106 | if (decl_id >= decl_die_table_in_use) |
4107 | decl_die_table_in_use = (decl_id + 1); | |
4108 | ||
4109 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb JW |
4110 | } |
4111 | ||
3f76745e JM |
4112 | /* Return a pointer to a newly allocated location description. Location |
4113 | descriptions are simple expression terms that can be strung | |
4114 | together to form more complicated location (address) descriptions. */ | |
71dfc51f | 4115 | |
3f76745e JM |
4116 | static inline dw_loc_descr_ref |
4117 | new_loc_descr (op, oprnd1, oprnd2) | |
4118 | register enum dwarf_location_atom op; | |
4119 | register unsigned long oprnd1; | |
4120 | register unsigned long oprnd2; | |
a3f97cbb | 4121 | { |
3f76745e JM |
4122 | register dw_loc_descr_ref descr |
4123 | = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node)); | |
71dfc51f | 4124 | |
3f76745e JM |
4125 | descr->dw_loc_next = NULL; |
4126 | descr->dw_loc_opc = op; | |
4127 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
4128 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
4129 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
4130 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 4131 | |
3f76745e | 4132 | return descr; |
a3f97cbb | 4133 | } |
71dfc51f | 4134 | |
3f76745e JM |
4135 | /* Add a location description term to a location description expression. */ |
4136 | ||
4137 | static inline void | |
4138 | add_loc_descr (list_head, descr) | |
4139 | register dw_loc_descr_ref *list_head; | |
4140 | register dw_loc_descr_ref descr; | |
a3f97cbb | 4141 | { |
3f76745e | 4142 | register dw_loc_descr_ref *d; |
71dfc51f | 4143 | |
3f76745e JM |
4144 | /* Find the end of the chain. */ |
4145 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
4146 | ; | |
71dfc51f | 4147 | |
3f76745e JM |
4148 | *d = descr; |
4149 | } | |
4150 | \f | |
4151 | /* Keep track of the number of spaces used to indent the | |
4152 | output of the debugging routines that print the structure of | |
4153 | the DIE internal representation. */ | |
4154 | static int print_indent; | |
71dfc51f | 4155 | |
3f76745e JM |
4156 | /* Indent the line the number of spaces given by print_indent. */ |
4157 | ||
4158 | static inline void | |
4159 | print_spaces (outfile) | |
4160 | FILE *outfile; | |
4161 | { | |
4162 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4163 | } |
4164 | ||
956d6950 | 4165 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4166 | This routine is a debugging aid only. */ |
71dfc51f | 4167 | |
a3f97cbb | 4168 | static void |
3f76745e JM |
4169 | print_die (die, outfile) |
4170 | dw_die_ref die; | |
4171 | FILE *outfile; | |
a3f97cbb | 4172 | { |
3f76745e JM |
4173 | register dw_attr_ref a; |
4174 | register dw_die_ref c; | |
71dfc51f | 4175 | |
3f76745e JM |
4176 | print_spaces (outfile); |
4177 | fprintf (outfile, "DIE %4u: %s\n", | |
4178 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
4179 | print_spaces (outfile); | |
4180 | fprintf (outfile, " abbrev id: %u", die->die_abbrev); | |
4181 | fprintf (outfile, " offset: %u\n", die->die_offset); | |
4182 | ||
4183 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 4184 | { |
3f76745e JM |
4185 | print_spaces (outfile); |
4186 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
4187 | ||
4188 | switch (a->dw_attr_val.val_class) | |
4189 | { | |
4190 | case dw_val_class_addr: | |
4191 | fprintf (outfile, "address"); | |
4192 | break; | |
4193 | case dw_val_class_loc: | |
4194 | fprintf (outfile, "location descriptor"); | |
4195 | break; | |
4196 | case dw_val_class_const: | |
4197 | fprintf (outfile, "%d", a->dw_attr_val.v.val_int); | |
4198 | break; | |
4199 | case dw_val_class_unsigned_const: | |
4200 | fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned); | |
4201 | break; | |
4202 | case dw_val_class_long_long: | |
4203 | fprintf (outfile, "constant (%u,%u)", | |
4204 | a->dw_attr_val.v.val_long_long.hi, | |
4205 | a->dw_attr_val.v.val_long_long.low); | |
4206 | break; | |
4207 | case dw_val_class_float: | |
4208 | fprintf (outfile, "floating-point constant"); | |
4209 | break; | |
4210 | case dw_val_class_flag: | |
4211 | fprintf (outfile, "%u", a->dw_attr_val.v.val_flag); | |
4212 | break; | |
4213 | case dw_val_class_die_ref: | |
4214 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
4215 | fprintf (outfile, "die -> %u", | |
4216 | a->dw_attr_val.v.val_die_ref->die_offset); | |
4217 | else | |
4218 | fprintf (outfile, "die -> <null>"); | |
4219 | break; | |
4220 | case dw_val_class_lbl_id: | |
4221 | fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id); | |
4222 | break; | |
4223 | case dw_val_class_section_offset: | |
4224 | fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section); | |
4225 | break; | |
4226 | case dw_val_class_str: | |
4227 | if (a->dw_attr_val.v.val_str != NULL) | |
4228 | fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str); | |
4229 | else | |
4230 | fprintf (outfile, "<null>"); | |
4231 | break; | |
e9a25f70 JL |
4232 | default: |
4233 | break; | |
3f76745e JM |
4234 | } |
4235 | ||
4236 | fprintf (outfile, "\n"); | |
4237 | } | |
4238 | ||
4239 | if (die->die_child != NULL) | |
4240 | { | |
4241 | print_indent += 4; | |
4242 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4243 | print_die (c, outfile); | |
71dfc51f | 4244 | |
3f76745e | 4245 | print_indent -= 4; |
a3f97cbb | 4246 | } |
a3f97cbb JW |
4247 | } |
4248 | ||
3f76745e JM |
4249 | /* Print the contents of the source code line number correspondence table. |
4250 | This routine is a debugging aid only. */ | |
71dfc51f | 4251 | |
3f76745e JM |
4252 | static void |
4253 | print_dwarf_line_table (outfile) | |
4254 | FILE *outfile; | |
a3f97cbb | 4255 | { |
3f76745e JM |
4256 | register unsigned i; |
4257 | register dw_line_info_ref line_info; | |
4258 | ||
4259 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
4260 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 4261 | { |
3f76745e JM |
4262 | line_info = &line_info_table[i]; |
4263 | fprintf (outfile, "%5d: ", i); | |
4264 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
4265 | fprintf (outfile, "%6d", line_info->dw_line_num); | |
4266 | fprintf (outfile, "\n"); | |
a3f97cbb | 4267 | } |
3f76745e JM |
4268 | |
4269 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
4270 | } |
4271 | ||
3f76745e JM |
4272 | /* Print the information collected for a given DIE. */ |
4273 | ||
4274 | void | |
4275 | debug_dwarf_die (die) | |
4276 | dw_die_ref die; | |
4277 | { | |
4278 | print_die (die, stderr); | |
4279 | } | |
4280 | ||
4281 | /* Print all DWARF information collected for the compilation unit. | |
4282 | This routine is a debugging aid only. */ | |
4283 | ||
4284 | void | |
4285 | debug_dwarf () | |
4286 | { | |
4287 | print_indent = 0; | |
4288 | print_die (comp_unit_die, stderr); | |
4289 | print_dwarf_line_table (stderr); | |
4290 | } | |
4291 | \f | |
4292 | /* Traverse the DIE, and add a sibling attribute if it may have the | |
4293 | effect of speeding up access to siblings. To save some space, | |
4294 | avoid generating sibling attributes for DIE's without children. */ | |
71dfc51f | 4295 | |
f37230f0 | 4296 | static void |
3f76745e JM |
4297 | add_sibling_attributes(die) |
4298 | register dw_die_ref die; | |
f37230f0 | 4299 | { |
3f76745e JM |
4300 | register dw_die_ref c; |
4301 | register dw_attr_ref attr; | |
4302 | if (die != comp_unit_die && die->die_child != NULL) | |
4303 | { | |
4304 | attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4305 | attr->dw_attr_next = NULL; | |
4306 | attr->dw_attr = DW_AT_sibling; | |
4307 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
4308 | attr->dw_attr_val.v.val_die_ref = die->die_sib; | |
71dfc51f | 4309 | |
3f76745e JM |
4310 | /* Add the sibling link to the front of the attribute list. */ |
4311 | attr->dw_attr_next = die->die_attr; | |
4312 | if (die->die_attr == NULL) | |
4313 | die->die_attr_last = attr; | |
71dfc51f | 4314 | |
3f76745e JM |
4315 | die->die_attr = attr; |
4316 | } | |
4317 | ||
4318 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4319 | add_sibling_attributes (c); | |
a3f97cbb JW |
4320 | } |
4321 | ||
3f76745e JM |
4322 | /* The format of each DIE (and its attribute value pairs) |
4323 | is encoded in an abbreviation table. This routine builds the | |
4324 | abbreviation table and assigns a unique abbreviation id for | |
4325 | each abbreviation entry. The children of each die are visited | |
4326 | recursively. */ | |
71dfc51f | 4327 | |
a3f97cbb | 4328 | static void |
3f76745e JM |
4329 | build_abbrev_table (die) |
4330 | register dw_die_ref die; | |
a3f97cbb | 4331 | { |
3f76745e JM |
4332 | register unsigned long abbrev_id; |
4333 | register unsigned long n_alloc; | |
4334 | register dw_die_ref c; | |
4335 | register dw_attr_ref d_attr, a_attr; | |
a3f97cbb JW |
4336 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
4337 | { | |
4338 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4339 | |
3f76745e JM |
4340 | if (abbrev->die_tag == die->die_tag) |
4341 | { | |
4342 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
4343 | { | |
4344 | a_attr = abbrev->die_attr; | |
4345 | d_attr = die->die_attr; | |
71dfc51f | 4346 | |
3f76745e JM |
4347 | while (a_attr != NULL && d_attr != NULL) |
4348 | { | |
4349 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
4350 | || (value_format (&a_attr->dw_attr_val) | |
4351 | != value_format (&d_attr->dw_attr_val))) | |
4352 | break; | |
71dfc51f | 4353 | |
3f76745e JM |
4354 | a_attr = a_attr->dw_attr_next; |
4355 | d_attr = d_attr->dw_attr_next; | |
4356 | } | |
71dfc51f | 4357 | |
3f76745e JM |
4358 | if (a_attr == NULL && d_attr == NULL) |
4359 | break; | |
4360 | } | |
4361 | } | |
4362 | } | |
71dfc51f | 4363 | |
3f76745e JM |
4364 | if (abbrev_id >= abbrev_die_table_in_use) |
4365 | { | |
4366 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
a3f97cbb | 4367 | { |
3f76745e JM |
4368 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; |
4369 | abbrev_die_table | |
c760091a | 4370 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
966f5dff | 4371 | sizeof (dw_die_ref) * n_alloc); |
71dfc51f | 4372 | |
3f76745e JM |
4373 | bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated], |
4374 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); | |
4375 | abbrev_die_table_allocated = n_alloc; | |
a3f97cbb | 4376 | } |
71dfc51f | 4377 | |
3f76745e JM |
4378 | ++abbrev_die_table_in_use; |
4379 | abbrev_die_table[abbrev_id] = die; | |
a3f97cbb | 4380 | } |
3f76745e JM |
4381 | |
4382 | die->die_abbrev = abbrev_id; | |
4383 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4384 | build_abbrev_table (c); | |
a3f97cbb | 4385 | } |
3f76745e JM |
4386 | \f |
4387 | /* Return the size of a string, including the null byte. */ | |
a3f97cbb | 4388 | |
3f76745e JM |
4389 | static unsigned long |
4390 | size_of_string (str) | |
4391 | register char *str; | |
4392 | { | |
4393 | register unsigned long size = 0; | |
4394 | register unsigned long slen = strlen (str); | |
4395 | register unsigned long i; | |
4396 | register unsigned c; | |
71dfc51f | 4397 | |
3f76745e JM |
4398 | for (i = 0; i < slen; ++i) |
4399 | { | |
4400 | c = str[i]; | |
4401 | if (c == '\\') | |
4402 | ++i; | |
4403 | ||
4404 | size += 1; | |
4405 | } | |
4406 | ||
4407 | /* Null terminator. */ | |
4408 | size += 1; | |
4409 | return size; | |
4410 | } | |
4411 | ||
4412 | /* Return the size of a location descriptor. */ | |
4413 | ||
4414 | static unsigned long | |
4415 | size_of_loc_descr (loc) | |
a3f97cbb JW |
4416 | register dw_loc_descr_ref loc; |
4417 | { | |
3f76745e | 4418 | register unsigned long size = 1; |
71dfc51f | 4419 | |
a3f97cbb JW |
4420 | switch (loc->dw_loc_opc) |
4421 | { | |
4422 | case DW_OP_addr: | |
3f76745e | 4423 | size += PTR_SIZE; |
a3f97cbb JW |
4424 | break; |
4425 | case DW_OP_const1u: | |
4426 | case DW_OP_const1s: | |
3f76745e | 4427 | size += 1; |
a3f97cbb JW |
4428 | break; |
4429 | case DW_OP_const2u: | |
4430 | case DW_OP_const2s: | |
3f76745e | 4431 | size += 2; |
a3f97cbb JW |
4432 | break; |
4433 | case DW_OP_const4u: | |
4434 | case DW_OP_const4s: | |
3f76745e | 4435 | size += 4; |
a3f97cbb JW |
4436 | break; |
4437 | case DW_OP_const8u: | |
4438 | case DW_OP_const8s: | |
3f76745e | 4439 | size += 8; |
a3f97cbb JW |
4440 | break; |
4441 | case DW_OP_constu: | |
3f76745e | 4442 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4443 | break; |
4444 | case DW_OP_consts: | |
3f76745e | 4445 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4446 | break; |
4447 | case DW_OP_pick: | |
3f76745e | 4448 | size += 1; |
a3f97cbb JW |
4449 | break; |
4450 | case DW_OP_plus_uconst: | |
3f76745e | 4451 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4452 | break; |
4453 | case DW_OP_skip: | |
4454 | case DW_OP_bra: | |
3f76745e | 4455 | size += 2; |
a3f97cbb JW |
4456 | break; |
4457 | case DW_OP_breg0: | |
4458 | case DW_OP_breg1: | |
4459 | case DW_OP_breg2: | |
4460 | case DW_OP_breg3: | |
4461 | case DW_OP_breg4: | |
4462 | case DW_OP_breg5: | |
4463 | case DW_OP_breg6: | |
4464 | case DW_OP_breg7: | |
4465 | case DW_OP_breg8: | |
4466 | case DW_OP_breg9: | |
4467 | case DW_OP_breg10: | |
4468 | case DW_OP_breg11: | |
4469 | case DW_OP_breg12: | |
4470 | case DW_OP_breg13: | |
4471 | case DW_OP_breg14: | |
4472 | case DW_OP_breg15: | |
4473 | case DW_OP_breg16: | |
4474 | case DW_OP_breg17: | |
4475 | case DW_OP_breg18: | |
4476 | case DW_OP_breg19: | |
4477 | case DW_OP_breg20: | |
4478 | case DW_OP_breg21: | |
4479 | case DW_OP_breg22: | |
4480 | case DW_OP_breg23: | |
4481 | case DW_OP_breg24: | |
4482 | case DW_OP_breg25: | |
4483 | case DW_OP_breg26: | |
4484 | case DW_OP_breg27: | |
4485 | case DW_OP_breg28: | |
4486 | case DW_OP_breg29: | |
4487 | case DW_OP_breg30: | |
4488 | case DW_OP_breg31: | |
3f76745e | 4489 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4490 | break; |
4491 | case DW_OP_regx: | |
3f76745e | 4492 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4493 | break; |
4494 | case DW_OP_fbreg: | |
3f76745e | 4495 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4496 | break; |
4497 | case DW_OP_bregx: | |
3f76745e JM |
4498 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
4499 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
a3f97cbb JW |
4500 | break; |
4501 | case DW_OP_piece: | |
3f76745e | 4502 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4503 | break; |
4504 | case DW_OP_deref_size: | |
4505 | case DW_OP_xderef_size: | |
3f76745e | 4506 | size += 1; |
a3f97cbb JW |
4507 | break; |
4508 | default: | |
4509 | break; | |
4510 | } | |
3f76745e JM |
4511 | |
4512 | return size; | |
a3f97cbb JW |
4513 | } |
4514 | ||
3f76745e | 4515 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 4516 | |
a3f97cbb | 4517 | static unsigned long |
3f76745e JM |
4518 | size_of_locs (loc) |
4519 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4520 | { |
3f76745e | 4521 | register unsigned long size = 0; |
71dfc51f | 4522 | |
3f76745e JM |
4523 | for (; loc != NULL; loc = loc->dw_loc_next) |
4524 | size += size_of_loc_descr (loc); | |
4525 | ||
4526 | return size; | |
4527 | } | |
4528 | ||
4529 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
4530 | ||
4531 | static int | |
4532 | constant_size (value) | |
4533 | long unsigned value; | |
4534 | { | |
4535 | int log; | |
4536 | ||
4537 | if (value == 0) | |
4538 | log = 0; | |
a3f97cbb | 4539 | else |
3f76745e | 4540 | log = floor_log2 (value); |
71dfc51f | 4541 | |
3f76745e JM |
4542 | log = log / 8; |
4543 | log = 1 << (floor_log2 (log) + 1); | |
4544 | ||
4545 | return log; | |
a3f97cbb JW |
4546 | } |
4547 | ||
3f76745e JM |
4548 | /* Return the size of a DIE, as it is represented in the |
4549 | .debug_info section. */ | |
71dfc51f | 4550 | |
3f76745e JM |
4551 | static unsigned long |
4552 | size_of_die (die) | |
a3f97cbb JW |
4553 | register dw_die_ref die; |
4554 | { | |
3f76745e | 4555 | register unsigned long size = 0; |
a3f97cbb | 4556 | register dw_attr_ref a; |
71dfc51f | 4557 | |
3f76745e | 4558 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
4559 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
4560 | { | |
4561 | switch (a->dw_attr_val.val_class) | |
4562 | { | |
4563 | case dw_val_class_addr: | |
3f76745e | 4564 | size += PTR_SIZE; |
a3f97cbb JW |
4565 | break; |
4566 | case dw_val_class_loc: | |
3f76745e JM |
4567 | { |
4568 | register unsigned long lsize | |
4569 | = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 4570 | |
3f76745e JM |
4571 | /* Block length. */ |
4572 | size += constant_size (lsize); | |
4573 | size += lsize; | |
4574 | } | |
a3f97cbb JW |
4575 | break; |
4576 | case dw_val_class_const: | |
3f76745e | 4577 | size += 4; |
a3f97cbb JW |
4578 | break; |
4579 | case dw_val_class_unsigned_const: | |
3f76745e | 4580 | size += constant_size (a->dw_attr_val.v.val_unsigned); |
a3f97cbb | 4581 | break; |
469ac993 | 4582 | case dw_val_class_long_long: |
3f76745e | 4583 | size += 1 + 8; /* block */ |
469ac993 JM |
4584 | break; |
4585 | case dw_val_class_float: | |
3f76745e | 4586 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
4587 | break; |
4588 | case dw_val_class_flag: | |
3f76745e | 4589 | size += 1; |
a3f97cbb JW |
4590 | break; |
4591 | case dw_val_class_die_ref: | |
3f76745e | 4592 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4593 | break; |
4594 | case dw_val_class_fde_ref: | |
3f76745e | 4595 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4596 | break; |
4597 | case dw_val_class_lbl_id: | |
3f76745e JM |
4598 | size += PTR_SIZE; |
4599 | break; | |
4600 | case dw_val_class_section_offset: | |
4601 | size += DWARF_OFFSET_SIZE; | |
4602 | break; | |
4603 | case dw_val_class_str: | |
4604 | size += size_of_string (a->dw_attr_val.v.val_str); | |
4605 | break; | |
4606 | default: | |
4607 | abort (); | |
4608 | } | |
a3f97cbb | 4609 | } |
3f76745e JM |
4610 | |
4611 | return size; | |
a3f97cbb JW |
4612 | } |
4613 | ||
956d6950 | 4614 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
4615 | Visits the DIE's children recursively. Updates the global |
4616 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 4617 | current value of next_die_offset to update the die_offset |
3f76745e | 4618 | field in each DIE. */ |
71dfc51f | 4619 | |
a3f97cbb | 4620 | static void |
3f76745e JM |
4621 | calc_die_sizes (die) |
4622 | dw_die_ref die; | |
a3f97cbb | 4623 | { |
3f76745e JM |
4624 | register dw_die_ref c; |
4625 | die->die_offset = next_die_offset; | |
4626 | next_die_offset += size_of_die (die); | |
71dfc51f | 4627 | |
3f76745e JM |
4628 | for (c = die->die_child; c != NULL; c = c->die_sib) |
4629 | calc_die_sizes (c); | |
71dfc51f | 4630 | |
3f76745e JM |
4631 | if (die->die_child != NULL) |
4632 | /* Count the null byte used to terminate sibling lists. */ | |
4633 | next_die_offset += 1; | |
a3f97cbb JW |
4634 | } |
4635 | ||
3f76745e JM |
4636 | /* Return the size of the line information prolog generated for the |
4637 | compilation unit. */ | |
469ac993 | 4638 | |
3f76745e JM |
4639 | static unsigned long |
4640 | size_of_line_prolog () | |
a94dbf2c | 4641 | { |
3f76745e JM |
4642 | register unsigned long size; |
4643 | register unsigned long ft_index; | |
a94dbf2c | 4644 | |
3f76745e | 4645 | size = DWARF_LINE_PROLOG_HEADER_SIZE; |
469ac993 | 4646 | |
3f76745e JM |
4647 | /* Count the size of the table giving number of args for each |
4648 | standard opcode. */ | |
4649 | size += DWARF_LINE_OPCODE_BASE - 1; | |
71dfc51f | 4650 | |
3f76745e JM |
4651 | /* Include directory table is empty (at present). Count only the |
4652 | the null byte used to terminate the table. */ | |
4653 | size += 1; | |
71dfc51f | 4654 | |
3f76745e JM |
4655 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
4656 | { | |
4657 | /* File name entry. */ | |
4658 | size += size_of_string (file_table[ft_index]); | |
a94dbf2c | 4659 | |
3f76745e JM |
4660 | /* Include directory index. */ |
4661 | size += size_of_uleb128 (0); | |
a94dbf2c | 4662 | |
3f76745e JM |
4663 | /* Modification time. */ |
4664 | size += size_of_uleb128 (0); | |
71dfc51f | 4665 | |
3f76745e JM |
4666 | /* File length in bytes. */ |
4667 | size += size_of_uleb128 (0); | |
a94dbf2c | 4668 | } |
71dfc51f | 4669 | |
3f76745e JM |
4670 | /* Count the file table terminator. */ |
4671 | size += 1; | |
4672 | return size; | |
a94dbf2c JM |
4673 | } |
4674 | ||
3f76745e JM |
4675 | /* Return the size of the line information generated for this |
4676 | compilation unit. */ | |
71dfc51f | 4677 | |
3f76745e JM |
4678 | static unsigned long |
4679 | size_of_line_info () | |
a94dbf2c | 4680 | { |
3f76745e JM |
4681 | register unsigned long size; |
4682 | register unsigned long lt_index; | |
4683 | register unsigned long current_line; | |
4684 | register long line_offset; | |
4685 | register long line_delta; | |
4686 | register unsigned long current_file; | |
4687 | register unsigned long function; | |
f19a6894 JW |
4688 | unsigned long size_of_set_address; |
4689 | ||
4690 | /* Size of a DW_LNE_set_address instruction. */ | |
4691 | size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE; | |
a94dbf2c | 4692 | |
3f76745e JM |
4693 | /* Version number. */ |
4694 | size = 2; | |
71dfc51f | 4695 | |
3f76745e JM |
4696 | /* Prolog length specifier. */ |
4697 | size += DWARF_OFFSET_SIZE; | |
71dfc51f | 4698 | |
3f76745e JM |
4699 | /* Prolog. */ |
4700 | size += size_of_line_prolog (); | |
a94dbf2c | 4701 | |
3f76745e | 4702 | /* Set address register instruction. */ |
f19a6894 | 4703 | size += size_of_set_address; |
71dfc51f | 4704 | |
3f76745e JM |
4705 | current_file = 1; |
4706 | current_line = 1; | |
4707 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) | |
a94dbf2c | 4708 | { |
3f76745e JM |
4709 | register dw_line_info_ref line_info; |
4710 | ||
4711 | /* Advance pc instruction. */ | |
f19a6894 JW |
4712 | /* ??? See the DW_LNS_advance_pc comment in output_line_info. */ |
4713 | if (0) | |
4714 | size += 1 + 2; | |
4715 | else | |
4716 | size += size_of_set_address; | |
4717 | ||
3f76745e JM |
4718 | line_info = &line_info_table[lt_index]; |
4719 | if (line_info->dw_file_num != current_file) | |
4720 | { | |
4721 | /* Set file number instruction. */ | |
4722 | size += 1; | |
4723 | current_file = line_info->dw_file_num; | |
4724 | size += size_of_uleb128 (current_file); | |
4725 | } | |
4726 | ||
4727 | if (line_info->dw_line_num != current_line) | |
4728 | { | |
4729 | line_offset = line_info->dw_line_num - current_line; | |
4730 | line_delta = line_offset - DWARF_LINE_BASE; | |
4731 | current_line = line_info->dw_line_num; | |
4732 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4733 | /* 1-byte special line number instruction. */ | |
4734 | size += 1; | |
4735 | else | |
4736 | { | |
4737 | /* Advance line instruction. */ | |
4738 | size += 1; | |
4739 | size += size_of_sleb128 (line_offset); | |
4740 | /* Generate line entry instruction. */ | |
4741 | size += 1; | |
4742 | } | |
4743 | } | |
a94dbf2c | 4744 | } |
a94dbf2c | 4745 | |
3f76745e | 4746 | /* Advance pc instruction. */ |
f19a6894 JW |
4747 | if (0) |
4748 | size += 1 + 2; | |
4749 | else | |
4750 | size += size_of_set_address; | |
a94dbf2c | 4751 | |
3f76745e JM |
4752 | /* End of line number info. marker. */ |
4753 | size += 1 + size_of_uleb128 (1) + 1; | |
a94dbf2c | 4754 | |
3f76745e JM |
4755 | function = 0; |
4756 | current_file = 1; | |
4757 | current_line = 1; | |
4758 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
4759 | { | |
4760 | register dw_separate_line_info_ref line_info | |
4761 | = &separate_line_info_table[lt_index]; | |
4762 | if (function != line_info->function) | |
4763 | { | |
4764 | function = line_info->function; | |
4765 | /* Set address register instruction. */ | |
f19a6894 | 4766 | size += size_of_set_address; |
3f76745e JM |
4767 | } |
4768 | else | |
f19a6894 JW |
4769 | { |
4770 | /* Advance pc instruction. */ | |
4771 | if (0) | |
4772 | size += 1 + 2; | |
4773 | else | |
4774 | size += size_of_set_address; | |
4775 | } | |
3f76745e JM |
4776 | |
4777 | if (line_info->dw_file_num != current_file) | |
4778 | { | |
4779 | /* Set file number instruction. */ | |
4780 | size += 1; | |
4781 | current_file = line_info->dw_file_num; | |
4782 | size += size_of_uleb128 (current_file); | |
4783 | } | |
4784 | ||
4785 | if (line_info->dw_line_num != current_line) | |
4786 | { | |
4787 | line_offset = line_info->dw_line_num - current_line; | |
4788 | line_delta = line_offset - DWARF_LINE_BASE; | |
4789 | current_line = line_info->dw_line_num; | |
4790 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4791 | /* 1-byte special line number instruction. */ | |
4792 | size += 1; | |
4793 | else | |
4794 | { | |
4795 | /* Advance line instruction. */ | |
4796 | size += 1; | |
4797 | size += size_of_sleb128 (line_offset); | |
a94dbf2c | 4798 | |
3f76745e JM |
4799 | /* Generate line entry instruction. */ |
4800 | size += 1; | |
4801 | } | |
4802 | } | |
a94dbf2c | 4803 | |
3f76745e | 4804 | ++lt_index; |
a94dbf2c | 4805 | |
3f76745e JM |
4806 | /* If we're done with a function, end its sequence. */ |
4807 | if (lt_index == separate_line_info_table_in_use | |
4808 | || separate_line_info_table[lt_index].function != function) | |
4809 | { | |
4810 | current_file = 1; | |
4811 | current_line = 1; | |
71dfc51f | 4812 | |
3f76745e | 4813 | /* Advance pc instruction. */ |
f19a6894 JW |
4814 | if (0) |
4815 | size += 1 + 2; | |
4816 | else | |
4817 | size += size_of_set_address; | |
71dfc51f | 4818 | |
3f76745e JM |
4819 | /* End of line number info. marker. */ |
4820 | size += 1 + size_of_uleb128 (1) + 1; | |
4821 | } | |
a94dbf2c JM |
4822 | } |
4823 | ||
3f76745e | 4824 | return size; |
a94dbf2c JM |
4825 | } |
4826 | ||
3f76745e JM |
4827 | /* Return the size of the .debug_pubnames table generated for the |
4828 | compilation unit. */ | |
a94dbf2c | 4829 | |
3f76745e JM |
4830 | static unsigned long |
4831 | size_of_pubnames () | |
a94dbf2c | 4832 | { |
3f76745e JM |
4833 | register unsigned long size; |
4834 | register unsigned i; | |
469ac993 | 4835 | |
3f76745e JM |
4836 | size = DWARF_PUBNAMES_HEADER_SIZE; |
4837 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 4838 | { |
3f76745e JM |
4839 | register pubname_ref p = &pubname_table[i]; |
4840 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
4841 | } |
4842 | ||
3f76745e JM |
4843 | size += DWARF_OFFSET_SIZE; |
4844 | return size; | |
a94dbf2c JM |
4845 | } |
4846 | ||
956d6950 | 4847 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 4848 | |
3f76745e JM |
4849 | static unsigned long |
4850 | size_of_aranges () | |
469ac993 | 4851 | { |
3f76745e | 4852 | register unsigned long size; |
469ac993 | 4853 | |
3f76745e | 4854 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 4855 | |
3f76745e JM |
4856 | /* Count the address/length pair for this compilation unit. */ |
4857 | size += 2 * PTR_SIZE; | |
4858 | size += 2 * PTR_SIZE * arange_table_in_use; | |
469ac993 | 4859 | |
3f76745e JM |
4860 | /* Count the two zero words used to terminated the address range table. */ |
4861 | size += 2 * PTR_SIZE; | |
4862 | return size; | |
4863 | } | |
4864 | \f | |
4865 | /* Select the encoding of an attribute value. */ | |
4866 | ||
4867 | static enum dwarf_form | |
4868 | value_format (v) | |
4869 | dw_val_ref v; | |
4870 | { | |
4871 | switch (v->val_class) | |
469ac993 | 4872 | { |
3f76745e JM |
4873 | case dw_val_class_addr: |
4874 | return DW_FORM_addr; | |
4875 | case dw_val_class_loc: | |
4876 | switch (constant_size (size_of_locs (v->v.val_loc))) | |
469ac993 | 4877 | { |
3f76745e JM |
4878 | case 1: |
4879 | return DW_FORM_block1; | |
4880 | case 2: | |
4881 | return DW_FORM_block2; | |
469ac993 JM |
4882 | default: |
4883 | abort (); | |
4884 | } | |
3f76745e JM |
4885 | case dw_val_class_const: |
4886 | return DW_FORM_data4; | |
4887 | case dw_val_class_unsigned_const: | |
4888 | switch (constant_size (v->v.val_unsigned)) | |
4889 | { | |
4890 | case 1: | |
4891 | return DW_FORM_data1; | |
4892 | case 2: | |
4893 | return DW_FORM_data2; | |
4894 | case 4: | |
4895 | return DW_FORM_data4; | |
4896 | case 8: | |
4897 | return DW_FORM_data8; | |
4898 | default: | |
4899 | abort (); | |
4900 | } | |
4901 | case dw_val_class_long_long: | |
4902 | return DW_FORM_block1; | |
4903 | case dw_val_class_float: | |
4904 | return DW_FORM_block1; | |
4905 | case dw_val_class_flag: | |
4906 | return DW_FORM_flag; | |
4907 | case dw_val_class_die_ref: | |
4908 | return DW_FORM_ref; | |
4909 | case dw_val_class_fde_ref: | |
4910 | return DW_FORM_data; | |
4911 | case dw_val_class_lbl_id: | |
4912 | return DW_FORM_addr; | |
4913 | case dw_val_class_section_offset: | |
4914 | return DW_FORM_data; | |
4915 | case dw_val_class_str: | |
4916 | return DW_FORM_string; | |
469ac993 JM |
4917 | default: |
4918 | abort (); | |
4919 | } | |
a94dbf2c JM |
4920 | } |
4921 | ||
3f76745e | 4922 | /* Output the encoding of an attribute value. */ |
469ac993 | 4923 | |
3f76745e JM |
4924 | static void |
4925 | output_value_format (v) | |
4926 | dw_val_ref v; | |
a94dbf2c | 4927 | { |
3f76745e | 4928 | enum dwarf_form form = value_format (v); |
71dfc51f | 4929 | |
3f76745e | 4930 | output_uleb128 (form); |
c5cec899 | 4931 | if (flag_debug_asm) |
3f76745e | 4932 | fprintf (asm_out_file, " (%s)", dwarf_form_name (form)); |
141719a8 | 4933 | |
3f76745e JM |
4934 | fputc ('\n', asm_out_file); |
4935 | } | |
469ac993 | 4936 | |
3f76745e JM |
4937 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
4938 | table. */ | |
469ac993 | 4939 | |
3f76745e JM |
4940 | static void |
4941 | output_abbrev_section () | |
4942 | { | |
4943 | unsigned long abbrev_id; | |
71dfc51f | 4944 | |
3f76745e JM |
4945 | dw_attr_ref a_attr; |
4946 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
4947 | { | |
4948 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4949 | |
3f76745e | 4950 | output_uleb128 (abbrev_id); |
c5cec899 | 4951 | if (flag_debug_asm) |
3f76745e | 4952 | fprintf (asm_out_file, " (abbrev code)"); |
469ac993 | 4953 | |
3f76745e JM |
4954 | fputc ('\n', asm_out_file); |
4955 | output_uleb128 (abbrev->die_tag); | |
c5cec899 | 4956 | if (flag_debug_asm) |
3f76745e JM |
4957 | fprintf (asm_out_file, " (TAG: %s)", |
4958 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 4959 | |
3f76745e JM |
4960 | fputc ('\n', asm_out_file); |
4961 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, | |
4962 | abbrev->die_child != NULL ? DW_children_yes : DW_children_no); | |
469ac993 | 4963 | |
c5cec899 | 4964 | if (flag_debug_asm) |
3f76745e JM |
4965 | fprintf (asm_out_file, "\t%s %s", |
4966 | ASM_COMMENT_START, | |
4967 | (abbrev->die_child != NULL | |
4968 | ? "DW_children_yes" : "DW_children_no")); | |
4969 | ||
4970 | fputc ('\n', asm_out_file); | |
4971 | ||
4972 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
4973 | a_attr = a_attr->dw_attr_next) | |
4974 | { | |
4975 | output_uleb128 (a_attr->dw_attr); | |
c5cec899 | 4976 | if (flag_debug_asm) |
3f76745e JM |
4977 | fprintf (asm_out_file, " (%s)", |
4978 | dwarf_attr_name (a_attr->dw_attr)); | |
4979 | ||
4980 | fputc ('\n', asm_out_file); | |
4981 | output_value_format (&a_attr->dw_attr_val); | |
469ac993 | 4982 | } |
469ac993 | 4983 | |
3f76745e | 4984 | fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); |
469ac993 | 4985 | } |
a94dbf2c JM |
4986 | } |
4987 | ||
3f76745e | 4988 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 4989 | |
3f76745e JM |
4990 | static void |
4991 | output_loc_operands (loc) | |
4992 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4993 | { |
3f76745e JM |
4994 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
4995 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
71dfc51f | 4996 | |
3f76745e | 4997 | switch (loc->dw_loc_opc) |
a3f97cbb | 4998 | { |
3f76745e JM |
4999 | case DW_OP_addr: |
5000 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); | |
5001 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5002 | break; |
3f76745e JM |
5003 | case DW_OP_const1u: |
5004 | case DW_OP_const1s: | |
5005 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
5006 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5007 | break; |
3f76745e JM |
5008 | case DW_OP_const2u: |
5009 | case DW_OP_const2s: | |
5010 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
5011 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5012 | break; |
3f76745e JM |
5013 | case DW_OP_const4u: |
5014 | case DW_OP_const4s: | |
5015 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); | |
5016 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5017 | break; |
3f76745e JM |
5018 | case DW_OP_const8u: |
5019 | case DW_OP_const8s: | |
5020 | abort (); | |
5021 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5022 | break; |
3f76745e JM |
5023 | case DW_OP_constu: |
5024 | output_uleb128 (val1->v.val_unsigned); | |
5025 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5026 | break; |
3f76745e JM |
5027 | case DW_OP_consts: |
5028 | output_sleb128 (val1->v.val_int); | |
5029 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5030 | break; |
3f76745e JM |
5031 | case DW_OP_pick: |
5032 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
5033 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5034 | break; |
3f76745e JM |
5035 | case DW_OP_plus_uconst: |
5036 | output_uleb128 (val1->v.val_unsigned); | |
5037 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5038 | break; |
3f76745e JM |
5039 | case DW_OP_skip: |
5040 | case DW_OP_bra: | |
5041 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
5042 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5043 | break; |
3f76745e JM |
5044 | case DW_OP_breg0: |
5045 | case DW_OP_breg1: | |
5046 | case DW_OP_breg2: | |
5047 | case DW_OP_breg3: | |
5048 | case DW_OP_breg4: | |
5049 | case DW_OP_breg5: | |
5050 | case DW_OP_breg6: | |
5051 | case DW_OP_breg7: | |
5052 | case DW_OP_breg8: | |
5053 | case DW_OP_breg9: | |
5054 | case DW_OP_breg10: | |
5055 | case DW_OP_breg11: | |
5056 | case DW_OP_breg12: | |
5057 | case DW_OP_breg13: | |
5058 | case DW_OP_breg14: | |
5059 | case DW_OP_breg15: | |
5060 | case DW_OP_breg16: | |
5061 | case DW_OP_breg17: | |
5062 | case DW_OP_breg18: | |
5063 | case DW_OP_breg19: | |
5064 | case DW_OP_breg20: | |
5065 | case DW_OP_breg21: | |
5066 | case DW_OP_breg22: | |
5067 | case DW_OP_breg23: | |
5068 | case DW_OP_breg24: | |
5069 | case DW_OP_breg25: | |
5070 | case DW_OP_breg26: | |
5071 | case DW_OP_breg27: | |
5072 | case DW_OP_breg28: | |
5073 | case DW_OP_breg29: | |
5074 | case DW_OP_breg30: | |
5075 | case DW_OP_breg31: | |
5076 | output_sleb128 (val1->v.val_int); | |
5077 | fputc ('\n', asm_out_file); | |
5078 | break; | |
5079 | case DW_OP_regx: | |
5080 | output_uleb128 (val1->v.val_unsigned); | |
5081 | fputc ('\n', asm_out_file); | |
5082 | break; | |
5083 | case DW_OP_fbreg: | |
5084 | output_sleb128 (val1->v.val_int); | |
5085 | fputc ('\n', asm_out_file); | |
5086 | break; | |
5087 | case DW_OP_bregx: | |
5088 | output_uleb128 (val1->v.val_unsigned); | |
5089 | fputc ('\n', asm_out_file); | |
5090 | output_sleb128 (val2->v.val_int); | |
5091 | fputc ('\n', asm_out_file); | |
5092 | break; | |
5093 | case DW_OP_piece: | |
5094 | output_uleb128 (val1->v.val_unsigned); | |
5095 | fputc ('\n', asm_out_file); | |
5096 | break; | |
5097 | case DW_OP_deref_size: | |
5098 | case DW_OP_xderef_size: | |
5099 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
5100 | fputc ('\n', asm_out_file); | |
a3f97cbb JW |
5101 | break; |
5102 | default: | |
5103 | break; | |
5104 | } | |
a3f97cbb JW |
5105 | } |
5106 | ||
3f76745e | 5107 | /* Compute the offset of a sibling. */ |
71dfc51f | 5108 | |
3f76745e JM |
5109 | static unsigned long |
5110 | sibling_offset (die) | |
5111 | dw_die_ref die; | |
a3f97cbb | 5112 | { |
3f76745e | 5113 | unsigned long offset; |
71dfc51f | 5114 | |
3f76745e JM |
5115 | if (die->die_child_last == NULL) |
5116 | offset = die->die_offset + size_of_die (die); | |
5117 | else | |
5118 | offset = sibling_offset (die->die_child_last) + 1; | |
71dfc51f | 5119 | |
3f76745e | 5120 | return offset; |
a3f97cbb JW |
5121 | } |
5122 | ||
3f76745e JM |
5123 | /* Output the DIE and its attributes. Called recursively to generate |
5124 | the definitions of each child DIE. */ | |
71dfc51f | 5125 | |
a3f97cbb | 5126 | static void |
3f76745e JM |
5127 | output_die (die) |
5128 | register dw_die_ref die; | |
a3f97cbb | 5129 | { |
3f76745e JM |
5130 | register dw_attr_ref a; |
5131 | register dw_die_ref c; | |
5132 | register unsigned long ref_offset; | |
5133 | register unsigned long size; | |
5134 | register dw_loc_descr_ref loc; | |
5135 | register int i; | |
a94dbf2c | 5136 | |
3f76745e | 5137 | output_uleb128 (die->die_abbrev); |
c5cec899 | 5138 | if (flag_debug_asm) |
3f76745e JM |
5139 | fprintf (asm_out_file, " (DIE (0x%x) %s)", |
5140 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 5141 | |
3f76745e | 5142 | fputc ('\n', asm_out_file); |
a94dbf2c | 5143 | |
3f76745e | 5144 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 5145 | { |
3f76745e JM |
5146 | switch (a->dw_attr_val.val_class) |
5147 | { | |
5148 | case dw_val_class_addr: | |
5149 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, | |
5150 | a->dw_attr_val.v.val_addr); | |
5151 | break; | |
a3f97cbb | 5152 | |
3f76745e JM |
5153 | case dw_val_class_loc: |
5154 | size = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 5155 | |
3f76745e JM |
5156 | /* Output the block length for this list of location operations. */ |
5157 | switch (constant_size (size)) | |
5158 | { | |
5159 | case 1: | |
5160 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size); | |
5161 | break; | |
5162 | case 2: | |
5163 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
5164 | break; | |
5165 | default: | |
5166 | abort (); | |
5167 | } | |
71dfc51f | 5168 | |
c5cec899 | 5169 | if (flag_debug_asm) |
3f76745e JM |
5170 | fprintf (asm_out_file, "\t%s %s", |
5171 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
71dfc51f | 5172 | |
3f76745e JM |
5173 | fputc ('\n', asm_out_file); |
5174 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
5175 | loc = loc->dw_loc_next) | |
5176 | { | |
5177 | /* Output the opcode. */ | |
5178 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
c5cec899 | 5179 | if (flag_debug_asm) |
3f76745e JM |
5180 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
5181 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
71dfc51f | 5182 | |
3f76745e | 5183 | fputc ('\n', asm_out_file); |
71dfc51f | 5184 | |
3f76745e JM |
5185 | /* Output the operand(s) (if any). */ |
5186 | output_loc_operands (loc); | |
5187 | } | |
a3f97cbb | 5188 | break; |
3f76745e JM |
5189 | |
5190 | case dw_val_class_const: | |
5191 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int); | |
a3f97cbb | 5192 | break; |
3f76745e JM |
5193 | |
5194 | case dw_val_class_unsigned_const: | |
5195 | switch (constant_size (a->dw_attr_val.v.val_unsigned)) | |
5196 | { | |
5197 | case 1: | |
5198 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5199 | a->dw_attr_val.v.val_unsigned); | |
5200 | break; | |
5201 | case 2: | |
5202 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, | |
5203 | a->dw_attr_val.v.val_unsigned); | |
5204 | break; | |
5205 | case 4: | |
5206 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5207 | a->dw_attr_val.v.val_unsigned); | |
5208 | break; | |
5209 | case 8: | |
5210 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5211 | a->dw_attr_val.v.val_long_long.hi, | |
5212 | a->dw_attr_val.v.val_long_long.low); | |
5213 | break; | |
5214 | default: | |
5215 | abort (); | |
5216 | } | |
a3f97cbb | 5217 | break; |
3f76745e JM |
5218 | |
5219 | case dw_val_class_long_long: | |
5220 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8); | |
c5cec899 | 5221 | if (flag_debug_asm) |
3f76745e JM |
5222 | fprintf (asm_out_file, "\t%s %s", |
5223 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5224 | ||
5225 | fputc ('\n', asm_out_file); | |
5226 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5227 | a->dw_attr_val.v.val_long_long.hi, | |
5228 | a->dw_attr_val.v.val_long_long.low); | |
5229 | ||
c5cec899 | 5230 | if (flag_debug_asm) |
3f76745e JM |
5231 | fprintf (asm_out_file, |
5232 | "\t%s long long constant", ASM_COMMENT_START); | |
5233 | ||
5234 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5235 | break; |
3f76745e JM |
5236 | |
5237 | case dw_val_class_float: | |
5238 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5239 | a->dw_attr_val.v.val_float.length * 4); | |
c5cec899 | 5240 | if (flag_debug_asm) |
3f76745e JM |
5241 | fprintf (asm_out_file, "\t%s %s", |
5242 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5243 | ||
5244 | fputc ('\n', asm_out_file); | |
5245 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) | |
5246 | { | |
5247 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5248 | a->dw_attr_val.v.val_float.array[i]); | |
c5cec899 | 5249 | if (flag_debug_asm) |
3f76745e JM |
5250 | fprintf (asm_out_file, "\t%s fp constant word %d", |
5251 | ASM_COMMENT_START, i); | |
5252 | ||
5253 | fputc ('\n', asm_out_file); | |
5254 | } | |
a3f97cbb | 5255 | break; |
3f76745e JM |
5256 | |
5257 | case dw_val_class_flag: | |
5258 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag); | |
a3f97cbb | 5259 | break; |
3f76745e JM |
5260 | |
5261 | case dw_val_class_die_ref: | |
5262 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
5263 | ref_offset = a->dw_attr_val.v.val_die_ref->die_offset; | |
5264 | else if (a->dw_attr == DW_AT_sibling) | |
5265 | ref_offset = sibling_offset(die); | |
5266 | else | |
5267 | abort (); | |
5268 | ||
5269 | ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset); | |
a3f97cbb | 5270 | break; |
3f76745e JM |
5271 | |
5272 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
5273 | { |
5274 | char l1[20]; | |
5275 | ASM_GENERATE_INTERNAL_LABEL | |
5276 | (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2); | |
5277 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1); | |
5278 | fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE); | |
5279 | } | |
a3f97cbb | 5280 | break; |
a3f97cbb | 5281 | |
3f76745e JM |
5282 | case dw_val_class_lbl_id: |
5283 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id); | |
5284 | break; | |
71dfc51f | 5285 | |
3f76745e JM |
5286 | case dw_val_class_section_offset: |
5287 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, | |
5288 | stripattributes | |
5289 | (a->dw_attr_val.v.val_section)); | |
5290 | break; | |
a3f97cbb | 5291 | |
3f76745e | 5292 | case dw_val_class_str: |
8d4e65a6 JL |
5293 | if (flag_debug_asm) |
5294 | ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str); | |
5295 | else | |
5296 | ASM_OUTPUT_ASCII (asm_out_file, | |
5297 | a->dw_attr_val.v.val_str, | |
c2c85462 | 5298 | strlen (a->dw_attr_val.v.val_str) + 1); |
3f76745e | 5299 | break; |
b2932ae5 | 5300 | |
3f76745e JM |
5301 | default: |
5302 | abort (); | |
5303 | } | |
a94dbf2c | 5304 | |
3f76745e JM |
5305 | if (a->dw_attr_val.val_class != dw_val_class_loc |
5306 | && a->dw_attr_val.val_class != dw_val_class_long_long | |
5307 | && a->dw_attr_val.val_class != dw_val_class_float) | |
5308 | { | |
c5cec899 | 5309 | if (flag_debug_asm) |
3f76745e JM |
5310 | fprintf (asm_out_file, "\t%s %s", |
5311 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
b2932ae5 | 5312 | |
3f76745e JM |
5313 | fputc ('\n', asm_out_file); |
5314 | } | |
5315 | } | |
71dfc51f | 5316 | |
3f76745e JM |
5317 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5318 | output_die (c); | |
71dfc51f | 5319 | |
3f76745e | 5320 | if (die->die_child != NULL) |
7e23cb16 | 5321 | { |
3f76745e JM |
5322 | /* Add null byte to terminate sibling list. */ |
5323 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5324 | if (flag_debug_asm) |
3f76745e JM |
5325 | fprintf (asm_out_file, "\t%s end of children of DIE 0x%x", |
5326 | ASM_COMMENT_START, die->die_offset); | |
5327 | ||
7e23cb16 JM |
5328 | fputc ('\n', asm_out_file); |
5329 | } | |
3f76745e | 5330 | } |
71dfc51f | 5331 | |
3f76745e JM |
5332 | /* Output the compilation unit that appears at the beginning of the |
5333 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 5334 | |
3f76745e JM |
5335 | static void |
5336 | output_compilation_unit_header () | |
5337 | { | |
5338 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE); | |
c5cec899 | 5339 | if (flag_debug_asm) |
3f76745e JM |
5340 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", |
5341 | ASM_COMMENT_START); | |
71dfc51f | 5342 | |
a3f97cbb | 5343 | fputc ('\n', asm_out_file); |
3f76745e | 5344 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
c5cec899 | 5345 | if (flag_debug_asm) |
3f76745e | 5346 | fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START); |
71dfc51f | 5347 | |
a3f97cbb | 5348 | fputc ('\n', asm_out_file); |
3f76745e | 5349 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION)); |
c5cec899 | 5350 | if (flag_debug_asm) |
3f76745e JM |
5351 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", |
5352 | ASM_COMMENT_START); | |
71dfc51f | 5353 | |
a3f97cbb | 5354 | fputc ('\n', asm_out_file); |
3f76745e | 5355 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); |
c5cec899 | 5356 | if (flag_debug_asm) |
3f76745e | 5357 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START); |
71dfc51f | 5358 | |
a3f97cbb | 5359 | fputc ('\n', asm_out_file); |
a3f97cbb JW |
5360 | } |
5361 | ||
a1d7ffe3 JM |
5362 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
5363 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
5364 | argument list, and maybe the scope. */ | |
5365 | ||
71dfc51f | 5366 | static char * |
a1d7ffe3 JM |
5367 | dwarf2_name (decl, scope) |
5368 | tree decl; | |
5369 | int scope; | |
5370 | { | |
5371 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
5372 | } | |
5373 | ||
d291dd49 | 5374 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 5375 | |
d291dd49 JM |
5376 | static void |
5377 | add_pubname (decl, die) | |
5378 | tree decl; | |
5379 | dw_die_ref die; | |
5380 | { | |
5381 | pubname_ref p; | |
5382 | ||
5383 | if (! TREE_PUBLIC (decl)) | |
5384 | return; | |
5385 | ||
5386 | if (pubname_table_in_use == pubname_table_allocated) | |
5387 | { | |
5388 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
5389 | pubname_table = (pubname_ref) xrealloc | |
5390 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
5391 | } | |
71dfc51f | 5392 | |
d291dd49 JM |
5393 | p = &pubname_table[pubname_table_in_use++]; |
5394 | p->die = die; | |
a1d7ffe3 JM |
5395 | |
5396 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
5397 | } |
5398 | ||
a3f97cbb JW |
5399 | /* Output the public names table used to speed up access to externally |
5400 | visible names. For now, only generate entries for externally | |
5401 | visible procedures. */ | |
71dfc51f | 5402 | |
a3f97cbb JW |
5403 | static void |
5404 | output_pubnames () | |
5405 | { | |
d291dd49 | 5406 | register unsigned i; |
71dfc51f RK |
5407 | register unsigned long pubnames_length = size_of_pubnames (); |
5408 | ||
5409 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length); | |
5410 | ||
c5cec899 | 5411 | if (flag_debug_asm) |
71dfc51f RK |
5412 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", |
5413 | ASM_COMMENT_START); | |
5414 | ||
a3f97cbb JW |
5415 | fputc ('\n', asm_out_file); |
5416 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
71dfc51f | 5417 | |
c5cec899 | 5418 | if (flag_debug_asm) |
71dfc51f RK |
5419 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5420 | ||
a3f97cbb | 5421 | fputc ('\n', asm_out_file); |
c53aa195 | 5422 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
c5cec899 | 5423 | if (flag_debug_asm) |
71dfc51f RK |
5424 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5425 | ASM_COMMENT_START); | |
5426 | ||
a3f97cbb | 5427 | fputc ('\n', asm_out_file); |
7e23cb16 | 5428 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset); |
c5cec899 | 5429 | if (flag_debug_asm) |
71dfc51f RK |
5430 | fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START); |
5431 | ||
a3f97cbb | 5432 | fputc ('\n', asm_out_file); |
d291dd49 | 5433 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 5434 | { |
d291dd49 | 5435 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 5436 | |
7e23cb16 | 5437 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset); |
c5cec899 | 5438 | if (flag_debug_asm) |
71dfc51f RK |
5439 | fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START); |
5440 | ||
d291dd49 JM |
5441 | fputc ('\n', asm_out_file); |
5442 | ||
c5cec899 | 5443 | if (flag_debug_asm) |
8d4e65a6 JL |
5444 | { |
5445 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
5446 | fprintf (asm_out_file, "%s external name", ASM_COMMENT_START); | |
5447 | } | |
5448 | else | |
5449 | { | |
c2c85462 | 5450 | ASM_OUTPUT_ASCII (asm_out_file, pub->name, strlen (pub->name) + 1); |
8d4e65a6 | 5451 | } |
71dfc51f | 5452 | |
d291dd49 | 5453 | fputc ('\n', asm_out_file); |
a3f97cbb | 5454 | } |
71dfc51f | 5455 | |
7e23cb16 | 5456 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); |
a3f97cbb JW |
5457 | fputc ('\n', asm_out_file); |
5458 | } | |
5459 | ||
d291dd49 | 5460 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 5461 | |
d291dd49 JM |
5462 | static void |
5463 | add_arange (decl, die) | |
5464 | tree decl; | |
5465 | dw_die_ref die; | |
5466 | { | |
5467 | if (! DECL_SECTION_NAME (decl)) | |
5468 | return; | |
5469 | ||
5470 | if (arange_table_in_use == arange_table_allocated) | |
5471 | { | |
5472 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
5473 | arange_table |
5474 | = (arange_ref) xrealloc (arange_table, | |
5475 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 5476 | } |
71dfc51f | 5477 | |
d291dd49 JM |
5478 | arange_table[arange_table_in_use++] = die; |
5479 | } | |
5480 | ||
a3f97cbb JW |
5481 | /* Output the information that goes into the .debug_aranges table. |
5482 | Namely, define the beginning and ending address range of the | |
5483 | text section generated for this compilation unit. */ | |
71dfc51f | 5484 | |
a3f97cbb JW |
5485 | static void |
5486 | output_aranges () | |
5487 | { | |
d291dd49 | 5488 | register unsigned i; |
71dfc51f RK |
5489 | register unsigned long aranges_length = size_of_aranges (); |
5490 | ||
5491 | ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length); | |
c5cec899 | 5492 | if (flag_debug_asm) |
71dfc51f RK |
5493 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", |
5494 | ASM_COMMENT_START); | |
5495 | ||
a3f97cbb JW |
5496 | fputc ('\n', asm_out_file); |
5497 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 5498 | if (flag_debug_asm) |
71dfc51f RK |
5499 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5500 | ||
a3f97cbb | 5501 | fputc ('\n', asm_out_file); |
c53aa195 | 5502 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
c5cec899 | 5503 | if (flag_debug_asm) |
71dfc51f RK |
5504 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5505 | ASM_COMMENT_START); | |
5506 | ||
a3f97cbb JW |
5507 | fputc ('\n', asm_out_file); |
5508 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); | |
c5cec899 | 5509 | if (flag_debug_asm) |
71dfc51f RK |
5510 | fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START); |
5511 | ||
a3f97cbb JW |
5512 | fputc ('\n', asm_out_file); |
5513 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5514 | if (flag_debug_asm) |
71dfc51f RK |
5515 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", |
5516 | ASM_COMMENT_START); | |
5517 | ||
a3f97cbb JW |
5518 | fputc ('\n', asm_out_file); |
5519 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
7e23cb16 JM |
5520 | if (PTR_SIZE == 8) |
5521 | fprintf (asm_out_file, ",0,0"); | |
71dfc51f | 5522 | |
c5cec899 | 5523 | if (flag_debug_asm) |
71dfc51f RK |
5524 | fprintf (asm_out_file, "\t%s Pad to %d byte boundary", |
5525 | ASM_COMMENT_START, 2 * PTR_SIZE); | |
5526 | ||
a3f97cbb | 5527 | fputc ('\n', asm_out_file); |
bdb669cb | 5528 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
c5cec899 | 5529 | if (flag_debug_asm) |
71dfc51f RK |
5530 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5531 | ||
a3f97cbb | 5532 | fputc ('\n', asm_out_file); |
5c90448c | 5533 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION); |
c5cec899 | 5534 | if (flag_debug_asm) |
71dfc51f RK |
5535 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5536 | ||
a3f97cbb | 5537 | fputc ('\n', asm_out_file); |
d291dd49 JM |
5538 | for (i = 0; i < arange_table_in_use; ++i) |
5539 | { | |
5540 | dw_die_ref a = arange_table[i]; | |
71dfc51f | 5541 | |
d291dd49 JM |
5542 | if (a->die_tag == DW_TAG_subprogram) |
5543 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a)); | |
5544 | else | |
a1d7ffe3 JM |
5545 | { |
5546 | char *name = get_AT_string (a, DW_AT_MIPS_linkage_name); | |
5547 | if (! name) | |
5548 | name = get_AT_string (a, DW_AT_name); | |
71dfc51f | 5549 | |
a1d7ffe3 JM |
5550 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, name); |
5551 | } | |
71dfc51f | 5552 | |
c5cec899 | 5553 | if (flag_debug_asm) |
71dfc51f RK |
5554 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5555 | ||
d291dd49 JM |
5556 | fputc ('\n', asm_out_file); |
5557 | if (a->die_tag == DW_TAG_subprogram) | |
7e23cb16 JM |
5558 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a), |
5559 | get_AT_low_pc (a)); | |
d291dd49 | 5560 | else |
7e23cb16 JM |
5561 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, |
5562 | get_AT_unsigned (a, DW_AT_byte_size)); | |
71dfc51f | 5563 | |
c5cec899 | 5564 | if (flag_debug_asm) |
71dfc51f RK |
5565 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5566 | ||
d291dd49 JM |
5567 | fputc ('\n', asm_out_file); |
5568 | } | |
71dfc51f | 5569 | |
a3f97cbb | 5570 | /* Output the terminator words. */ |
7e23cb16 | 5571 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb | 5572 | fputc ('\n', asm_out_file); |
7e23cb16 | 5573 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb JW |
5574 | fputc ('\n', asm_out_file); |
5575 | } | |
5576 | ||
5577 | /* Output the source line number correspondence information. This | |
f19a6894 JW |
5578 | information goes into the .debug_line section. |
5579 | ||
5580 | If the format of this data changes, then the function size_of_line_info | |
5581 | must also be adjusted the same way. */ | |
71dfc51f | 5582 | |
a3f97cbb JW |
5583 | static void |
5584 | output_line_info () | |
5585 | { | |
a3f97cbb JW |
5586 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
5587 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5588 | register unsigned opc; | |
5589 | register unsigned n_op_args; | |
a3f97cbb JW |
5590 | register unsigned long ft_index; |
5591 | register unsigned long lt_index; | |
5592 | register unsigned long current_line; | |
5593 | register long line_offset; | |
5594 | register long line_delta; | |
5595 | register unsigned long current_file; | |
e90b62db | 5596 | register unsigned long function; |
71dfc51f | 5597 | |
7e23cb16 | 5598 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); |
c5cec899 | 5599 | if (flag_debug_asm) |
71dfc51f RK |
5600 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", |
5601 | ASM_COMMENT_START); | |
5602 | ||
a3f97cbb JW |
5603 | fputc ('\n', asm_out_file); |
5604 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 5605 | if (flag_debug_asm) |
71dfc51f RK |
5606 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5607 | ||
a3f97cbb | 5608 | fputc ('\n', asm_out_file); |
7e23cb16 | 5609 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); |
c5cec899 | 5610 | if (flag_debug_asm) |
71dfc51f RK |
5611 | fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); |
5612 | ||
a3f97cbb JW |
5613 | fputc ('\n', asm_out_file); |
5614 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
c5cec899 | 5615 | if (flag_debug_asm) |
71dfc51f RK |
5616 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", |
5617 | ASM_COMMENT_START); | |
5618 | ||
a3f97cbb JW |
5619 | fputc ('\n', asm_out_file); |
5620 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
c5cec899 | 5621 | if (flag_debug_asm) |
71dfc51f RK |
5622 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", |
5623 | ASM_COMMENT_START); | |
5624 | ||
a3f97cbb JW |
5625 | fputc ('\n', asm_out_file); |
5626 | fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE); | |
c5cec899 | 5627 | if (flag_debug_asm) |
71dfc51f RK |
5628 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", |
5629 | ASM_COMMENT_START); | |
5630 | ||
a3f97cbb JW |
5631 | fputc ('\n', asm_out_file); |
5632 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE); | |
c5cec899 | 5633 | if (flag_debug_asm) |
71dfc51f RK |
5634 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", |
5635 | ASM_COMMENT_START); | |
5636 | ||
a3f97cbb JW |
5637 | fputc ('\n', asm_out_file); |
5638 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); | |
c5cec899 | 5639 | if (flag_debug_asm) |
71dfc51f RK |
5640 | fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START); |
5641 | ||
a3f97cbb JW |
5642 | fputc ('\n', asm_out_file); |
5643 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
5644 | { | |
5645 | switch (opc) | |
5646 | { | |
5647 | case DW_LNS_advance_pc: | |
5648 | case DW_LNS_advance_line: | |
5649 | case DW_LNS_set_file: | |
5650 | case DW_LNS_set_column: | |
5651 | case DW_LNS_fixed_advance_pc: | |
5652 | n_op_args = 1; | |
5653 | break; | |
5654 | default: | |
5655 | n_op_args = 0; | |
5656 | break; | |
5657 | } | |
5658 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
c5cec899 | 5659 | if (flag_debug_asm) |
71dfc51f RK |
5660 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", |
5661 | ASM_COMMENT_START, opc, n_op_args); | |
a3f97cbb JW |
5662 | fputc ('\n', asm_out_file); |
5663 | } | |
71dfc51f | 5664 | |
c5cec899 | 5665 | if (flag_debug_asm) |
71dfc51f RK |
5666 | fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START); |
5667 | ||
a3f97cbb JW |
5668 | /* Include directory table is empty, at present */ |
5669 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5670 | fputc ('\n', asm_out_file); | |
c5cec899 | 5671 | if (flag_debug_asm) |
71dfc51f RK |
5672 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); |
5673 | ||
a3f97cbb JW |
5674 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
5675 | { | |
c5cec899 | 5676 | if (flag_debug_asm) |
8d4e65a6 JL |
5677 | { |
5678 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
5679 | fprintf (asm_out_file, "%s File Entry: 0x%x", | |
5680 | ASM_COMMENT_START, ft_index); | |
5681 | } | |
5682 | else | |
5683 | { | |
5684 | ASM_OUTPUT_ASCII (asm_out_file, | |
5685 | file_table[ft_index], | |
c2c85462 | 5686 | strlen (file_table[ft_index]) + 1); |
8d4e65a6 | 5687 | } |
71dfc51f | 5688 | |
a3f97cbb | 5689 | fputc ('\n', asm_out_file); |
71dfc51f | 5690 | |
a3f97cbb JW |
5691 | /* Include directory index */ |
5692 | output_uleb128 (0); | |
5693 | fputc ('\n', asm_out_file); | |
71dfc51f | 5694 | |
a3f97cbb JW |
5695 | /* Modification time */ |
5696 | output_uleb128 (0); | |
5697 | fputc ('\n', asm_out_file); | |
71dfc51f | 5698 | |
a3f97cbb JW |
5699 | /* File length in bytes */ |
5700 | output_uleb128 (0); | |
5701 | fputc ('\n', asm_out_file); | |
5702 | } | |
71dfc51f | 5703 | |
a3f97cbb JW |
5704 | /* Terminate the file name table */ |
5705 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5706 | fputc ('\n', asm_out_file); | |
5707 | ||
5708 | /* Set the address register to the first location in the text section */ | |
5709 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5710 | if (flag_debug_asm) |
71dfc51f RK |
5711 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5712 | ||
a3f97cbb JW |
5713 | fputc ('\n', asm_out_file); |
5714 | output_uleb128 (1 + PTR_SIZE); | |
5715 | fputc ('\n', asm_out_file); | |
5716 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5717 | fputc ('\n', asm_out_file); | |
bdb669cb | 5718 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
a3f97cbb JW |
5719 | fputc ('\n', asm_out_file); |
5720 | ||
5721 | /* Generate the line number to PC correspondence table, encoded as | |
5722 | a series of state machine operations. */ | |
5723 | current_file = 1; | |
5724 | current_line = 1; | |
bdb669cb | 5725 | strcpy (prev_line_label, TEXT_SECTION); |
a3f97cbb JW |
5726 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
5727 | { | |
e90b62db | 5728 | register dw_line_info_ref line_info; |
71dfc51f | 5729 | |
f19a6894 JW |
5730 | /* Emit debug info for the address of the current line, choosing |
5731 | the encoding that uses the least amount of space. */ | |
5732 | /* ??? Unfortunately, we have little choice here currently, and must | |
5733 | always use the most general form. Gcc does not know the address | |
5734 | delta itself, so we can't use DW_LNS_advance_pc. There are no known | |
5735 | dwarf2 aware assemblers at this time, so we can't use any special | |
5736 | pseudo ops that would allow the assembler to optimally encode this for | |
5737 | us. Many ports do have length attributes which will give an upper | |
5738 | bound on the address range. We could perhaps use length attributes | |
5739 | to determine when it is safe to use DW_LNS_fixed_advance_pc. */ | |
5c90448c | 5740 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
5741 | if (0) |
5742 | { | |
5743 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
5744 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5745 | if (flag_debug_asm) |
f19a6894 JW |
5746 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5747 | ASM_COMMENT_START); | |
5748 | ||
5749 | fputc ('\n', asm_out_file); | |
5750 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
5751 | fputc ('\n', asm_out_file); | |
5752 | } | |
5753 | else | |
5754 | { | |
5755 | /* This can handle any delta. This takes 4+PTR_SIZE bytes. */ | |
5756 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5757 | if (flag_debug_asm) |
f19a6894 JW |
5758 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5759 | ASM_COMMENT_START); | |
5760 | fputc ('\n', asm_out_file); | |
5761 | output_uleb128 (1 + PTR_SIZE); | |
5762 | fputc ('\n', asm_out_file); | |
5763 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5764 | fputc ('\n', asm_out_file); | |
5765 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5766 | fputc ('\n', asm_out_file); | |
5767 | } | |
5768 | strcpy (prev_line_label, line_label); | |
5769 | ||
5770 | /* Emit debug info for the source file of the current line, if | |
5771 | different from the previous line. */ | |
a3f97cbb JW |
5772 | line_info = &line_info_table[lt_index]; |
5773 | if (line_info->dw_file_num != current_file) | |
5774 | { | |
5775 | current_file = line_info->dw_file_num; | |
5776 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 5777 | if (flag_debug_asm) |
71dfc51f RK |
5778 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5779 | ||
a3f97cbb JW |
5780 | fputc ('\n', asm_out_file); |
5781 | output_uleb128 (current_file); | |
c5cec899 | 5782 | if (flag_debug_asm) |
b2932ae5 | 5783 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5784 | |
a3f97cbb JW |
5785 | fputc ('\n', asm_out_file); |
5786 | } | |
71dfc51f | 5787 | |
f19a6894 JW |
5788 | /* Emit debug info for the current line number, choosing the encoding |
5789 | that uses the least amount of space. */ | |
a94dbf2c JM |
5790 | line_offset = line_info->dw_line_num - current_line; |
5791 | line_delta = line_offset - DWARF_LINE_BASE; | |
5792 | current_line = line_info->dw_line_num; | |
5793 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
a3f97cbb | 5794 | { |
f19a6894 JW |
5795 | /* This can handle deltas from -10 to 234, using the current |
5796 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
5797 | takes 1 byte. */ | |
a94dbf2c JM |
5798 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, |
5799 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 5800 | if (flag_debug_asm) |
a94dbf2c JM |
5801 | fprintf (asm_out_file, |
5802 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
71dfc51f | 5803 | |
a94dbf2c JM |
5804 | fputc ('\n', asm_out_file); |
5805 | } | |
5806 | else | |
5807 | { | |
f19a6894 JW |
5808 | /* This can handle any delta. This takes at least 4 bytes, depending |
5809 | on the value being encoded. */ | |
a94dbf2c | 5810 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); |
c5cec899 | 5811 | if (flag_debug_asm) |
71dfc51f RK |
5812 | fprintf (asm_out_file, "\t%s advance to line %d", |
5813 | ASM_COMMENT_START, current_line); | |
5814 | ||
a94dbf2c JM |
5815 | fputc ('\n', asm_out_file); |
5816 | output_sleb128 (line_offset); | |
5817 | fputc ('\n', asm_out_file); | |
5818 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5819 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5820 | } |
a3f97cbb JW |
5821 | } |
5822 | ||
f19a6894 JW |
5823 | /* Emit debug info for the address of the end of the function. */ |
5824 | if (0) | |
5825 | { | |
5826 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5827 | if (flag_debug_asm) |
f19a6894 JW |
5828 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5829 | ASM_COMMENT_START); | |
71dfc51f | 5830 | |
f19a6894 JW |
5831 | fputc ('\n', asm_out_file); |
5832 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label); | |
5833 | fputc ('\n', asm_out_file); | |
5834 | } | |
5835 | else | |
5836 | { | |
5837 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5838 | if (flag_debug_asm) |
f19a6894 JW |
5839 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5840 | fputc ('\n', asm_out_file); | |
5841 | output_uleb128 (1 + PTR_SIZE); | |
5842 | fputc ('\n', asm_out_file); | |
5843 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5844 | fputc ('\n', asm_out_file); | |
5845 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label); | |
5846 | fputc ('\n', asm_out_file); | |
5847 | } | |
bdb669cb | 5848 | |
a3f97cbb JW |
5849 | /* Output the marker for the end of the line number info. */ |
5850 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5851 | if (flag_debug_asm) |
71dfc51f RK |
5852 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); |
5853 | ||
a3f97cbb JW |
5854 | fputc ('\n', asm_out_file); |
5855 | output_uleb128 (1); | |
5856 | fputc ('\n', asm_out_file); | |
5857 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5858 | fputc ('\n', asm_out_file); | |
e90b62db JM |
5859 | |
5860 | function = 0; | |
5861 | current_file = 1; | |
5862 | current_line = 1; | |
5863 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
5864 | { | |
5865 | register dw_separate_line_info_ref line_info | |
5866 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 5867 | |
f19a6894 JW |
5868 | /* Emit debug info for the address of the current line. If this is |
5869 | a new function, or the first line of a function, then we need | |
5870 | to handle it differently. */ | |
5c90448c JM |
5871 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
5872 | lt_index); | |
e90b62db JM |
5873 | if (function != line_info->function) |
5874 | { | |
5875 | function = line_info->function; | |
71dfc51f | 5876 | |
e90b62db JM |
5877 | /* Set the address register to the first line in the function */ |
5878 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5879 | if (flag_debug_asm) |
e90b62db JM |
5880 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5881 | ASM_COMMENT_START); | |
71dfc51f | 5882 | |
e90b62db JM |
5883 | fputc ('\n', asm_out_file); |
5884 | output_uleb128 (1 + PTR_SIZE); | |
5885 | fputc ('\n', asm_out_file); | |
5886 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5887 | fputc ('\n', asm_out_file); | |
5888 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5889 | fputc ('\n', asm_out_file); | |
5890 | } | |
5891 | else | |
5892 | { | |
f19a6894 JW |
5893 | /* ??? See the DW_LNS_advance_pc comment above. */ |
5894 | if (0) | |
5895 | { | |
5896 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5897 | if (flag_debug_asm) |
f19a6894 JW |
5898 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5899 | ASM_COMMENT_START); | |
71dfc51f | 5900 | |
f19a6894 JW |
5901 | fputc ('\n', asm_out_file); |
5902 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5903 | prev_line_label); | |
5904 | fputc ('\n', asm_out_file); | |
5905 | } | |
5906 | else | |
5907 | { | |
5908 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5909 | if (flag_debug_asm) |
f19a6894 JW |
5910 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5911 | ASM_COMMENT_START); | |
5912 | fputc ('\n', asm_out_file); | |
5913 | output_uleb128 (1 + PTR_SIZE); | |
5914 | fputc ('\n', asm_out_file); | |
5915 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5916 | fputc ('\n', asm_out_file); | |
5917 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5918 | fputc ('\n', asm_out_file); | |
5919 | } | |
e90b62db | 5920 | } |
f19a6894 | 5921 | strcpy (prev_line_label, line_label); |
71dfc51f | 5922 | |
f19a6894 JW |
5923 | /* Emit debug info for the source file of the current line, if |
5924 | different from the previous line. */ | |
e90b62db JM |
5925 | if (line_info->dw_file_num != current_file) |
5926 | { | |
5927 | current_file = line_info->dw_file_num; | |
5928 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 5929 | if (flag_debug_asm) |
71dfc51f RK |
5930 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5931 | ||
e90b62db JM |
5932 | fputc ('\n', asm_out_file); |
5933 | output_uleb128 (current_file); | |
c5cec899 | 5934 | if (flag_debug_asm) |
b2932ae5 | 5935 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5936 | |
e90b62db JM |
5937 | fputc ('\n', asm_out_file); |
5938 | } | |
71dfc51f | 5939 | |
f19a6894 JW |
5940 | /* Emit debug info for the current line number, choosing the encoding |
5941 | that uses the least amount of space. */ | |
e90b62db JM |
5942 | if (line_info->dw_line_num != current_line) |
5943 | { | |
5944 | line_offset = line_info->dw_line_num - current_line; | |
5945 | line_delta = line_offset - DWARF_LINE_BASE; | |
5946 | current_line = line_info->dw_line_num; | |
5947 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
5948 | { | |
5949 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5950 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 5951 | if (flag_debug_asm) |
71dfc51f RK |
5952 | fprintf (asm_out_file, |
5953 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
5954 | ||
e90b62db JM |
5955 | fputc ('\n', asm_out_file); |
5956 | } | |
5957 | else | |
5958 | { | |
5959 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
c5cec899 | 5960 | if (flag_debug_asm) |
71dfc51f RK |
5961 | fprintf (asm_out_file, "\t%s advance to line %d", |
5962 | ASM_COMMENT_START, current_line); | |
5963 | ||
e90b62db JM |
5964 | fputc ('\n', asm_out_file); |
5965 | output_sleb128 (line_offset); | |
5966 | fputc ('\n', asm_out_file); | |
5967 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5968 | fputc ('\n', asm_out_file); | |
5969 | } | |
5970 | } | |
71dfc51f | 5971 | |
e90b62db | 5972 | ++lt_index; |
e90b62db JM |
5973 | |
5974 | /* If we're done with a function, end its sequence. */ | |
5975 | if (lt_index == separate_line_info_table_in_use | |
5976 | || separate_line_info_table[lt_index].function != function) | |
5977 | { | |
5978 | current_file = 1; | |
5979 | current_line = 1; | |
71dfc51f | 5980 | |
f19a6894 | 5981 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 5982 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
5983 | if (0) |
5984 | { | |
5985 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5986 | if (flag_debug_asm) |
f19a6894 JW |
5987 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5988 | ASM_COMMENT_START); | |
5989 | ||
5990 | fputc ('\n', asm_out_file); | |
5991 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5992 | prev_line_label); | |
5993 | fputc ('\n', asm_out_file); | |
5994 | } | |
5995 | else | |
5996 | { | |
5997 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5998 | if (flag_debug_asm) |
f19a6894 JW |
5999 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6000 | ASM_COMMENT_START); | |
6001 | fputc ('\n', asm_out_file); | |
6002 | output_uleb128 (1 + PTR_SIZE); | |
6003 | fputc ('\n', asm_out_file); | |
6004 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6005 | fputc ('\n', asm_out_file); | |
6006 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6007 | fputc ('\n', asm_out_file); | |
6008 | } | |
e90b62db JM |
6009 | |
6010 | /* Output the marker for the end of this sequence. */ | |
6011 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6012 | if (flag_debug_asm) |
e90b62db JM |
6013 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", |
6014 | ASM_COMMENT_START); | |
71dfc51f | 6015 | |
e90b62db JM |
6016 | fputc ('\n', asm_out_file); |
6017 | output_uleb128 (1); | |
6018 | fputc ('\n', asm_out_file); | |
6019 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
6020 | fputc ('\n', asm_out_file); | |
6021 | } | |
6022 | } | |
a3f97cbb JW |
6023 | } |
6024 | \f | |
71dfc51f RK |
6025 | /* Given a pointer to a BLOCK node return non-zero if (and only if) the node |
6026 | in question represents the outermost pair of curly braces (i.e. the "body | |
6027 | block") of a function or method. | |
6028 | ||
6029 | For any BLOCK node representing a "body block" of a function or method, the | |
6030 | BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which | |
6031 | represents the outermost (function) scope for the function or method (i.e. | |
6032 | the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of | |
6033 | *that* node in turn will point to the relevant FUNCTION_DECL node. */ | |
6034 | ||
6035 | static inline int | |
a3f97cbb JW |
6036 | is_body_block (stmt) |
6037 | register tree stmt; | |
6038 | { | |
6039 | if (TREE_CODE (stmt) == BLOCK) | |
6040 | { | |
6041 | register tree parent = BLOCK_SUPERCONTEXT (stmt); | |
6042 | ||
6043 | if (TREE_CODE (parent) == BLOCK) | |
6044 | { | |
6045 | register tree grandparent = BLOCK_SUPERCONTEXT (parent); | |
6046 | ||
6047 | if (TREE_CODE (grandparent) == FUNCTION_DECL) | |
6048 | return 1; | |
6049 | } | |
6050 | } | |
71dfc51f | 6051 | |
a3f97cbb JW |
6052 | return 0; |
6053 | } | |
6054 | ||
a3f97cbb JW |
6055 | /* Given a pointer to a tree node for some base type, return a pointer to |
6056 | a DIE that describes the given type. | |
6057 | ||
6058 | This routine must only be called for GCC type nodes that correspond to | |
6059 | Dwarf base (fundamental) types. */ | |
71dfc51f | 6060 | |
a3f97cbb JW |
6061 | static dw_die_ref |
6062 | base_type_die (type) | |
6063 | register tree type; | |
6064 | { | |
a9d38797 JM |
6065 | register dw_die_ref base_type_result; |
6066 | register char *type_name; | |
6067 | register enum dwarf_type encoding; | |
71dfc51f | 6068 | register tree name = TYPE_NAME (type); |
a3f97cbb | 6069 | |
a9d38797 JM |
6070 | if (TREE_CODE (type) == ERROR_MARK |
6071 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
6072 | return 0; |
6073 | ||
71dfc51f RK |
6074 | if (TREE_CODE (name) == TYPE_DECL) |
6075 | name = DECL_NAME (name); | |
6076 | type_name = IDENTIFIER_POINTER (name); | |
a9d38797 | 6077 | |
a3f97cbb JW |
6078 | switch (TREE_CODE (type)) |
6079 | { | |
a3f97cbb | 6080 | case INTEGER_TYPE: |
a9d38797 | 6081 | /* Carefully distinguish the C character types, without messing |
a3f97cbb JW |
6082 | up if the language is not C. Note that we check only for the names |
6083 | that contain spaces; other names might occur by coincidence in other | |
6084 | languages. */ | |
a9d38797 JM |
6085 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
6086 | && (type == char_type_node | |
6087 | || ! strcmp (type_name, "signed char") | |
6088 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 6089 | { |
a9d38797 JM |
6090 | if (TREE_UNSIGNED (type)) |
6091 | encoding = DW_ATE_unsigned; | |
6092 | else | |
6093 | encoding = DW_ATE_signed; | |
6094 | break; | |
a3f97cbb | 6095 | } |
a9d38797 | 6096 | /* else fall through */ |
a3f97cbb | 6097 | |
a9d38797 JM |
6098 | case CHAR_TYPE: |
6099 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
6100 | if (TREE_UNSIGNED (type)) | |
6101 | encoding = DW_ATE_unsigned_char; | |
6102 | else | |
6103 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
6104 | break; |
6105 | ||
6106 | case REAL_TYPE: | |
a9d38797 | 6107 | encoding = DW_ATE_float; |
a3f97cbb JW |
6108 | break; |
6109 | ||
6110 | case COMPLEX_TYPE: | |
a9d38797 | 6111 | encoding = DW_ATE_complex_float; |
a3f97cbb JW |
6112 | break; |
6113 | ||
6114 | case BOOLEAN_TYPE: | |
a9d38797 JM |
6115 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
6116 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
6117 | break; |
6118 | ||
6119 | default: | |
a9d38797 | 6120 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
6121 | } |
6122 | ||
a9d38797 JM |
6123 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
6124 | add_AT_string (base_type_result, DW_AT_name, type_name); | |
6125 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
6126 | TYPE_PRECISION (type) / BITS_PER_UNIT); | |
6127 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); | |
a3f97cbb JW |
6128 | |
6129 | return base_type_result; | |
6130 | } | |
6131 | ||
6132 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
6133 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
6134 | a given type is generally the same as the given type, except that if the | |
6135 | given type is a pointer or reference type, then the root type of the given | |
6136 | type is the root type of the "basis" type for the pointer or reference | |
6137 | type. (This definition of the "root" type is recursive.) Also, the root | |
6138 | type of a `const' qualified type or a `volatile' qualified type is the | |
6139 | root type of the given type without the qualifiers. */ | |
71dfc51f | 6140 | |
a3f97cbb JW |
6141 | static tree |
6142 | root_type (type) | |
6143 | register tree type; | |
6144 | { | |
6145 | if (TREE_CODE (type) == ERROR_MARK) | |
6146 | return error_mark_node; | |
6147 | ||
6148 | switch (TREE_CODE (type)) | |
6149 | { | |
6150 | case ERROR_MARK: | |
6151 | return error_mark_node; | |
6152 | ||
6153 | case POINTER_TYPE: | |
6154 | case REFERENCE_TYPE: | |
6155 | return type_main_variant (root_type (TREE_TYPE (type))); | |
6156 | ||
6157 | default: | |
6158 | return type_main_variant (type); | |
6159 | } | |
6160 | } | |
6161 | ||
6162 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
6163 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
6164 | |
6165 | static inline int | |
a3f97cbb JW |
6166 | is_base_type (type) |
6167 | register tree type; | |
6168 | { | |
6169 | switch (TREE_CODE (type)) | |
6170 | { | |
6171 | case ERROR_MARK: | |
6172 | case VOID_TYPE: | |
6173 | case INTEGER_TYPE: | |
6174 | case REAL_TYPE: | |
6175 | case COMPLEX_TYPE: | |
6176 | case BOOLEAN_TYPE: | |
6177 | case CHAR_TYPE: | |
6178 | return 1; | |
6179 | ||
6180 | case SET_TYPE: | |
6181 | case ARRAY_TYPE: | |
6182 | case RECORD_TYPE: | |
6183 | case UNION_TYPE: | |
6184 | case QUAL_UNION_TYPE: | |
6185 | case ENUMERAL_TYPE: | |
6186 | case FUNCTION_TYPE: | |
6187 | case METHOD_TYPE: | |
6188 | case POINTER_TYPE: | |
6189 | case REFERENCE_TYPE: | |
6190 | case FILE_TYPE: | |
6191 | case OFFSET_TYPE: | |
6192 | case LANG_TYPE: | |
6193 | return 0; | |
6194 | ||
6195 | default: | |
6196 | abort (); | |
6197 | } | |
71dfc51f | 6198 | |
a3f97cbb JW |
6199 | return 0; |
6200 | } | |
6201 | ||
6202 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
6203 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 6204 | |
a3f97cbb JW |
6205 | static dw_die_ref |
6206 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
6207 | register tree type; | |
6208 | register int is_const_type; | |
6209 | register int is_volatile_type; | |
6210 | register dw_die_ref context_die; | |
6211 | { | |
6212 | register enum tree_code code = TREE_CODE (type); | |
6213 | register dw_die_ref mod_type_die = NULL; | |
6214 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 6215 | register tree item_type = NULL; |
a3f97cbb JW |
6216 | |
6217 | if (code != ERROR_MARK) | |
6218 | { | |
a94dbf2c | 6219 | type = build_type_variant (type, is_const_type, is_volatile_type); |
bdb669cb JM |
6220 | |
6221 | mod_type_die = lookup_type_die (type); | |
6222 | if (mod_type_die) | |
6223 | return mod_type_die; | |
6224 | ||
a94dbf2c JM |
6225 | /* Handle C typedef types. */ |
6226 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
6227 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
6228 | { | |
6229 | tree dtype = TREE_TYPE (TYPE_NAME (type)); | |
6230 | if (type == dtype) | |
6231 | { | |
6232 | /* For a named type, use the typedef. */ | |
6233 | gen_type_die (type, context_die); | |
6234 | mod_type_die = lookup_type_die (type); | |
6235 | } | |
71dfc51f | 6236 | |
a94dbf2c JM |
6237 | else if (is_const_type < TYPE_READONLY (dtype) |
6238 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
6239 | /* cv-unqualified version of named type. Just use the unnamed | |
6240 | type to which it refers. */ | |
71dfc51f RK |
6241 | mod_type_die |
6242 | = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), | |
6243 | is_const_type, is_volatile_type, | |
6244 | context_die); | |
6245 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
6246 | } |
6247 | ||
6248 | if (mod_type_die) | |
6249 | /* OK */; | |
6250 | else if (is_const_type) | |
a3f97cbb | 6251 | { |
ab72d377 | 6252 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 6253 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
6254 | } |
6255 | else if (is_volatile_type) | |
6256 | { | |
ab72d377 | 6257 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 6258 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
6259 | } |
6260 | else if (code == POINTER_TYPE) | |
6261 | { | |
ab72d377 | 6262 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 6263 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6264 | #if 0 |
a3f97cbb | 6265 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6266 | #endif |
a3f97cbb | 6267 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6268 | } |
6269 | else if (code == REFERENCE_TYPE) | |
6270 | { | |
ab72d377 | 6271 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 6272 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6273 | #if 0 |
a3f97cbb | 6274 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6275 | #endif |
a3f97cbb | 6276 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6277 | } |
6278 | else if (is_base_type (type)) | |
71dfc51f | 6279 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
6280 | else |
6281 | { | |
4b674448 JM |
6282 | gen_type_die (type, context_die); |
6283 | ||
a3f97cbb JW |
6284 | /* We have to get the type_main_variant here (and pass that to the |
6285 | `lookup_type_die' routine) because the ..._TYPE node we have | |
6286 | might simply be a *copy* of some original type node (where the | |
6287 | copy was created to help us keep track of typedef names) and | |
6288 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 6289 | ..._TYPE node. */ |
a3f97cbb | 6290 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
6291 | if (mod_type_die == NULL) |
6292 | abort (); | |
a3f97cbb JW |
6293 | } |
6294 | } | |
71dfc51f | 6295 | |
dfcf9891 JW |
6296 | equate_type_number_to_die (type, mod_type_die); |
6297 | if (item_type) | |
71dfc51f RK |
6298 | /* We must do this after the equate_type_number_to_die call, in case |
6299 | this is a recursive type. This ensures that the modified_type_die | |
6300 | recursion will terminate even if the type is recursive. Recursive | |
6301 | types are possible in Ada. */ | |
6302 | sub_die = modified_type_die (item_type, | |
6303 | TYPE_READONLY (item_type), | |
6304 | TYPE_VOLATILE (item_type), | |
6305 | context_die); | |
6306 | ||
a3f97cbb | 6307 | if (sub_die != NULL) |
71dfc51f RK |
6308 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
6309 | ||
a3f97cbb JW |
6310 | return mod_type_die; |
6311 | } | |
6312 | ||
a3f97cbb JW |
6313 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6314 | an enumerated type. */ | |
71dfc51f RK |
6315 | |
6316 | static inline int | |
a3f97cbb JW |
6317 | type_is_enum (type) |
6318 | register tree type; | |
6319 | { | |
6320 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
6321 | } | |
6322 | ||
a3f97cbb | 6323 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 6324 | |
a3f97cbb JW |
6325 | static dw_loc_descr_ref |
6326 | reg_loc_descriptor (rtl) | |
6327 | register rtx rtl; | |
6328 | { | |
6329 | register dw_loc_descr_ref loc_result = NULL; | |
6330 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 6331 | |
a3f97cbb | 6332 | if (reg >= 0 && reg <= 31) |
71dfc51f | 6333 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 6334 | else |
71dfc51f RK |
6335 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
6336 | ||
a3f97cbb JW |
6337 | return loc_result; |
6338 | } | |
6339 | ||
6340 | /* Return a location descriptor that designates a base+offset location. */ | |
71dfc51f | 6341 | |
a3f97cbb JW |
6342 | static dw_loc_descr_ref |
6343 | based_loc_descr (reg, offset) | |
6344 | unsigned reg; | |
6345 | long int offset; | |
6346 | { | |
6347 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
6348 | /* For the "frame base", we use the frame pointer or stack pointer |
6349 | registers, since the RTL for local variables is relative to one of | |
6350 | them. */ | |
6351 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 6352 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 6353 | : STACK_POINTER_REGNUM); |
71dfc51f | 6354 | |
a3f97cbb | 6355 | if (reg == fp_reg) |
71dfc51f | 6356 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
a3f97cbb | 6357 | else if (reg >= 0 && reg <= 31) |
71dfc51f | 6358 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 6359 | else |
71dfc51f RK |
6360 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
6361 | ||
a3f97cbb JW |
6362 | return loc_result; |
6363 | } | |
6364 | ||
6365 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
6366 | |
6367 | static inline int | |
a3f97cbb JW |
6368 | is_based_loc (rtl) |
6369 | register rtx rtl; | |
6370 | { | |
71dfc51f RK |
6371 | return (GET_CODE (rtl) == PLUS |
6372 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
6373 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
6374 | } |
6375 | ||
6376 | /* The following routine converts the RTL for a variable or parameter | |
6377 | (resident in memory) into an equivalent Dwarf representation of a | |
6378 | mechanism for getting the address of that same variable onto the top of a | |
6379 | hypothetical "address evaluation" stack. | |
71dfc51f | 6380 | |
a3f97cbb JW |
6381 | When creating memory location descriptors, we are effectively transforming |
6382 | the RTL for a memory-resident object into its Dwarf postfix expression | |
6383 | equivalent. This routine recursively descends an RTL tree, turning | |
6384 | it into Dwarf postfix code as it goes. */ | |
71dfc51f | 6385 | |
a3f97cbb JW |
6386 | static dw_loc_descr_ref |
6387 | mem_loc_descriptor (rtl) | |
6388 | register rtx rtl; | |
6389 | { | |
6390 | dw_loc_descr_ref mem_loc_result = NULL; | |
6391 | /* Note that for a dynamically sized array, the location we will generate a | |
6392 | description of here will be the lowest numbered location which is | |
6393 | actually within the array. That's *not* necessarily the same as the | |
6394 | zeroth element of the array. */ | |
71dfc51f | 6395 | |
a3f97cbb JW |
6396 | switch (GET_CODE (rtl)) |
6397 | { | |
6398 | case SUBREG: | |
6399 | /* The case of a subreg may arise when we have a local (register) | |
6400 | variable or a formal (register) parameter which doesn't quite fill | |
6401 | up an entire register. For now, just assume that it is | |
6402 | legitimate to make the Dwarf info refer to the whole register which | |
6403 | contains the given subreg. */ | |
6404 | rtl = XEXP (rtl, 0); | |
71dfc51f RK |
6405 | |
6406 | /* ... fall through ... */ | |
a3f97cbb JW |
6407 | |
6408 | case REG: | |
6409 | /* Whenever a register number forms a part of the description of the | |
6410 | method for calculating the (dynamic) address of a memory resident | |
6411 | object, DWARF rules require the register number be referred to as | |
6412 | a "base register". This distinction is not based in any way upon | |
6413 | what category of register the hardware believes the given register | |
6414 | belongs to. This is strictly DWARF terminology we're dealing with | |
6415 | here. Note that in cases where the location of a memory-resident | |
6416 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
6417 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
6418 | may just be OP_BASEREG (basereg). This may look deceptively like | |
6419 | the object in question was allocated to a register (rather than in | |
6420 | memory) so DWARF consumers need to be aware of the subtle | |
6421 | distinction between OP_REG and OP_BASEREG. */ | |
6422 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
6423 | break; | |
6424 | ||
6425 | case MEM: | |
6426 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
6427 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
6428 | break; | |
6429 | ||
6430 | case CONST: | |
6431 | case SYMBOL_REF: | |
6432 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
6433 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
6434 | mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl); | |
6435 | break; | |
6436 | ||
6437 | case PLUS: | |
6438 | if (is_based_loc (rtl)) | |
71dfc51f RK |
6439 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
6440 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
6441 | else |
6442 | { | |
6443 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6444 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6445 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0)); | |
6446 | } | |
6447 | break; | |
6448 | ||
dd2478ae JW |
6449 | case MULT: |
6450 | /* If a pseudo-reg is optimized away, it is possible for it to | |
6451 | be replaced with a MEM containing a multiply. */ | |
6452 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6453 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6454 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
6455 | break; | |
6456 | ||
a3f97cbb JW |
6457 | case CONST_INT: |
6458 | mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0); | |
6459 | break; | |
6460 | ||
6461 | default: | |
6462 | abort (); | |
6463 | } | |
71dfc51f | 6464 | |
a3f97cbb JW |
6465 | return mem_loc_result; |
6466 | } | |
6467 | ||
956d6950 | 6468 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
6469 | This is typically a complex variable. */ |
6470 | ||
6471 | static dw_loc_descr_ref | |
6472 | concat_loc_descriptor (x0, x1) | |
6473 | register rtx x0, x1; | |
6474 | { | |
6475 | dw_loc_descr_ref cc_loc_result = NULL; | |
6476 | ||
6477 | if (!is_pseudo_reg (x0) | |
6478 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
6479 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
6480 | add_loc_descr (&cc_loc_result, | |
6481 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
6482 | ||
6483 | if (!is_pseudo_reg (x1) | |
6484 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
6485 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
6486 | add_loc_descr (&cc_loc_result, | |
6487 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
6488 | ||
6489 | return cc_loc_result; | |
6490 | } | |
6491 | ||
a3f97cbb JW |
6492 | /* Output a proper Dwarf location descriptor for a variable or parameter |
6493 | which is either allocated in a register or in a memory location. For a | |
6494 | register, we just generate an OP_REG and the register number. For a | |
6495 | memory location we provide a Dwarf postfix expression describing how to | |
6496 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 6497 | |
a3f97cbb JW |
6498 | static dw_loc_descr_ref |
6499 | loc_descriptor (rtl) | |
6500 | register rtx rtl; | |
6501 | { | |
6502 | dw_loc_descr_ref loc_result = NULL; | |
6503 | switch (GET_CODE (rtl)) | |
6504 | { | |
6505 | case SUBREG: | |
a3f97cbb JW |
6506 | /* The case of a subreg may arise when we have a local (register) |
6507 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 6508 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
6509 | legitimate to make the Dwarf info refer to the whole register which |
6510 | contains the given subreg. */ | |
a3f97cbb | 6511 | rtl = XEXP (rtl, 0); |
71dfc51f RK |
6512 | |
6513 | /* ... fall through ... */ | |
a3f97cbb JW |
6514 | |
6515 | case REG: | |
5c90448c | 6516 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
6517 | break; |
6518 | ||
6519 | case MEM: | |
6520 | loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
6521 | break; | |
6522 | ||
4401bf24 JL |
6523 | case CONCAT: |
6524 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
6525 | break; | |
6526 | ||
a3f97cbb | 6527 | default: |
71dfc51f | 6528 | abort (); |
a3f97cbb | 6529 | } |
71dfc51f | 6530 | |
a3f97cbb JW |
6531 | return loc_result; |
6532 | } | |
6533 | ||
6534 | /* Given an unsigned value, round it up to the lowest multiple of `boundary' | |
6535 | which is not less than the value itself. */ | |
71dfc51f RK |
6536 | |
6537 | static inline unsigned | |
a3f97cbb JW |
6538 | ceiling (value, boundary) |
6539 | register unsigned value; | |
6540 | register unsigned boundary; | |
6541 | { | |
6542 | return (((value + boundary - 1) / boundary) * boundary); | |
6543 | } | |
6544 | ||
6545 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
6546 | pointer to the declared type for the relevant field variable, or return | |
6547 | `integer_type_node' if the given node turns out to be an | |
6548 | ERROR_MARK node. */ | |
71dfc51f RK |
6549 | |
6550 | static inline tree | |
a3f97cbb JW |
6551 | field_type (decl) |
6552 | register tree decl; | |
6553 | { | |
6554 | register tree type; | |
6555 | ||
6556 | if (TREE_CODE (decl) == ERROR_MARK) | |
6557 | return integer_type_node; | |
6558 | ||
6559 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 6560 | if (type == NULL_TREE) |
a3f97cbb JW |
6561 | type = TREE_TYPE (decl); |
6562 | ||
6563 | return type; | |
6564 | } | |
6565 | ||
6566 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6567 | node, return the alignment in bits for the type, or else return | |
6568 | BITS_PER_WORD if the node actually turns out to be an | |
6569 | ERROR_MARK node. */ | |
71dfc51f RK |
6570 | |
6571 | static inline unsigned | |
a3f97cbb JW |
6572 | simple_type_align_in_bits (type) |
6573 | register tree type; | |
6574 | { | |
6575 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
6576 | } | |
6577 | ||
6578 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6579 | node, return the size in bits for the type if it is a constant, or else | |
6580 | return the alignment for the type if the type's size is not constant, or | |
6581 | else return BITS_PER_WORD if the type actually turns out to be an | |
6582 | ERROR_MARK node. */ | |
71dfc51f RK |
6583 | |
6584 | static inline unsigned | |
a3f97cbb JW |
6585 | simple_type_size_in_bits (type) |
6586 | register tree type; | |
6587 | { | |
6588 | if (TREE_CODE (type) == ERROR_MARK) | |
6589 | return BITS_PER_WORD; | |
6590 | else | |
6591 | { | |
6592 | register tree type_size_tree = TYPE_SIZE (type); | |
6593 | ||
6594 | if (TREE_CODE (type_size_tree) != INTEGER_CST) | |
6595 | return TYPE_ALIGN (type); | |
6596 | ||
6597 | return (unsigned) TREE_INT_CST_LOW (type_size_tree); | |
6598 | } | |
6599 | } | |
6600 | ||
6601 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
6602 | return the byte offset of the lowest addressed byte of the "containing | |
6603 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
6604 | determine what that offset is, either because the argument turns out to | |
6605 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
6606 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 6607 | |
a3f97cbb JW |
6608 | static unsigned |
6609 | field_byte_offset (decl) | |
6610 | register tree decl; | |
6611 | { | |
6612 | register unsigned type_align_in_bytes; | |
6613 | register unsigned type_align_in_bits; | |
6614 | register unsigned type_size_in_bits; | |
6615 | register unsigned object_offset_in_align_units; | |
6616 | register unsigned object_offset_in_bits; | |
6617 | register unsigned object_offset_in_bytes; | |
6618 | register tree type; | |
6619 | register tree bitpos_tree; | |
6620 | register tree field_size_tree; | |
6621 | register unsigned bitpos_int; | |
6622 | register unsigned deepest_bitpos; | |
6623 | register unsigned field_size_in_bits; | |
6624 | ||
6625 | if (TREE_CODE (decl) == ERROR_MARK) | |
6626 | return 0; | |
6627 | ||
6628 | if (TREE_CODE (decl) != FIELD_DECL) | |
6629 | abort (); | |
6630 | ||
6631 | type = field_type (decl); | |
6632 | ||
6633 | bitpos_tree = DECL_FIELD_BITPOS (decl); | |
6634 | field_size_tree = DECL_SIZE (decl); | |
6635 | ||
6636 | /* We cannot yet cope with fields whose positions or sizes are variable, so | |
6637 | for now, when we see such things, we simply return 0. Someday, we may | |
6638 | be able to handle such cases, but it will be damn difficult. */ | |
6639 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
6640 | return 0; | |
6641 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
6642 | ||
6643 | if (TREE_CODE (field_size_tree) != INTEGER_CST) | |
6644 | return 0; | |
a3f97cbb | 6645 | |
71dfc51f | 6646 | field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree); |
a3f97cbb | 6647 | type_size_in_bits = simple_type_size_in_bits (type); |
a3f97cbb JW |
6648 | type_align_in_bits = simple_type_align_in_bits (type); |
6649 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
6650 | ||
6651 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
6652 | the starting bit offset (relative to the start of the containing | |
6653 | structure type) of the hypothetical "containing object" for a bit- | |
6654 | field. Thus, when computing the byte offset value for the start of the | |
6655 | "containing object" of a bit-field, we must deduce this information on | |
6656 | our own. This can be rather tricky to do in some cases. For example, | |
6657 | handling the following structure type definition when compiling for an | |
6658 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
6659 | can be very tricky: | |
6660 | ||
6661 | struct S { int field1; long long field2:31; }; | |
6662 | ||
6663 | Fortunately, there is a simple rule-of-thumb which can be | |
6664 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
6665 | 8 bytes for the structure shown above. It decides to do this based upon | |
6666 | one simple rule for bit-field allocation. Quite simply, GCC allocates | |
6667 | each "containing object" for each bit-field at the first (i.e. lowest | |
6668 | addressed) legitimate alignment boundary (based upon the required | |
6669 | minimum alignment for the declared type of the field) which it can | |
6670 | possibly use, subject to the condition that there is still enough | |
6671 | available space remaining in the containing object (when allocated at | |
6672 | the selected point) to fully accommodate all of the bits of the | |
6673 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
6674 | 8 bytes for each object of the structure type shown above. When looking | |
6675 | for a place to allocate the "containing object" for `field2', the | |
6676 | compiler simply tries to allocate a 64-bit "containing object" at each | |
6677 | successive 32-bit boundary (starting at zero) until it finds a place to | |
6678 | allocate that 64- bit field such that at least 31 contiguous (and | |
6679 | previously unallocated) bits remain within that selected 64 bit field. | |
6680 | (As it turns out, for the example above, the compiler finds that it is | |
6681 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
6682 | within the structure type.) Here we attempt to work backwards from the | |
6683 | limited set of facts we're given, and we try to deduce from those facts, | |
6684 | where GCC must have believed that the containing object started (within | |
6685 | the structure type). The value we deduce is then used (by the callers of | |
6686 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
6687 | for fields (both bit-fields and, in the case of DW_AT_location, regular | |
6688 | fields as well). */ | |
6689 | ||
6690 | /* Figure out the bit-distance from the start of the structure to the | |
6691 | "deepest" bit of the bit-field. */ | |
6692 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
6693 | ||
6694 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
6695 | lowest addressed bit of the containing object must be. */ | |
6696 | object_offset_in_bits | |
6697 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
6698 | ||
6699 | /* Compute the offset of the containing object in "alignment units". */ | |
6700 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
6701 | ||
6702 | /* Compute the offset of the containing object in bytes. */ | |
6703 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
6704 | ||
6705 | return object_offset_in_bytes; | |
6706 | } | |
a3f97cbb | 6707 | \f |
71dfc51f RK |
6708 | /* The following routines define various Dwarf attributes and any data |
6709 | associated with them. */ | |
a3f97cbb | 6710 | |
ef76d03b | 6711 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 6712 | |
ef76d03b | 6713 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
6714 | whole parameters. Note that the location attributes for struct fields are |
6715 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 6716 | |
a3f97cbb | 6717 | static void |
ef76d03b | 6718 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 6719 | dw_die_ref die; |
ef76d03b | 6720 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
6721 | register rtx rtl; |
6722 | { | |
a3f97cbb JW |
6723 | /* Handle a special case. If we are about to output a location descriptor |
6724 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 6725 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
6726 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
6727 | Currently, in some rare cases, variables can have DECL_RTL values which | |
6728 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
6729 | elsewhere in the compiler. We treat such cases as if the variable(s) in | |
6a7a9f01 | 6730 | question had been optimized out of existence. */ |
a3f97cbb | 6731 | |
6a7a9f01 JM |
6732 | if (is_pseudo_reg (rtl) |
6733 | || (GET_CODE (rtl) == MEM | |
4401bf24 JL |
6734 | && is_pseudo_reg (XEXP (rtl, 0))) |
6735 | || (GET_CODE (rtl) == CONCAT | |
6736 | && is_pseudo_reg (XEXP (rtl, 0)) | |
6737 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 6738 | return; |
a3f97cbb | 6739 | |
6a7a9f01 | 6740 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
6741 | } |
6742 | ||
6743 | /* Attach the specialized form of location attribute used for data | |
6744 | members of struct and union types. In the special case of a | |
6745 | FIELD_DECL node which represents a bit-field, the "offset" part | |
6746 | of this special location descriptor must indicate the distance | |
6747 | in bytes from the lowest-addressed byte of the containing struct | |
6748 | or union type to the lowest-addressed byte of the "containing | |
6749 | object" for the bit-field. (See the `field_byte_offset' function | |
6750 | above).. For any given bit-field, the "containing object" is a | |
6751 | hypothetical object (of some integral or enum type) within which | |
6752 | the given bit-field lives. The type of this hypothetical | |
6753 | "containing object" is always the same as the declared type of | |
6754 | the individual bit-field itself (for GCC anyway... the DWARF | |
6755 | spec doesn't actually mandate this). Note that it is the size | |
6756 | (in bytes) of the hypothetical "containing object" which will | |
6757 | be given in the DW_AT_byte_size attribute for this bit-field. | |
6758 | (See the `byte_size_attribute' function below.) It is also used | |
6759 | when calculating the value of the DW_AT_bit_offset attribute. | |
6760 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 6761 | |
a3f97cbb JW |
6762 | static void |
6763 | add_data_member_location_attribute (die, decl) | |
6764 | register dw_die_ref die; | |
6765 | register tree decl; | |
6766 | { | |
61b32c02 | 6767 | register unsigned long offset; |
a3f97cbb JW |
6768 | register dw_loc_descr_ref loc_descr; |
6769 | register enum dwarf_location_atom op; | |
6770 | ||
61b32c02 JM |
6771 | if (TREE_CODE (decl) == TREE_VEC) |
6772 | offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl)); | |
6773 | else | |
6774 | offset = field_byte_offset (decl); | |
6775 | ||
a3f97cbb JW |
6776 | /* The DWARF2 standard says that we should assume that the structure address |
6777 | is already on the stack, so we can specify a structure field address | |
6778 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 6779 | |
a3f97cbb JW |
6780 | #ifdef MIPS_DEBUGGING_INFO |
6781 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
6782 | correctly. It works only if we leave the offset on the stack. */ | |
6783 | op = DW_OP_constu; | |
6784 | #else | |
6785 | op = DW_OP_plus_uconst; | |
6786 | #endif | |
71dfc51f | 6787 | |
a3f97cbb JW |
6788 | loc_descr = new_loc_descr (op, offset, 0); |
6789 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
6790 | } | |
6791 | ||
6792 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
6793 | does not have a "location" either in memory or in a register. These | |
6794 | things can arise in GNU C when a constant is passed as an actual parameter | |
6795 | to an inlined function. They can also arise in C++ where declared | |
6796 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 6797 | |
a3f97cbb JW |
6798 | static void |
6799 | add_const_value_attribute (die, rtl) | |
6800 | register dw_die_ref die; | |
6801 | register rtx rtl; | |
6802 | { | |
6803 | switch (GET_CODE (rtl)) | |
6804 | { | |
6805 | case CONST_INT: | |
6806 | /* Note that a CONST_INT rtx could represent either an integer or a | |
6807 | floating-point constant. A CONST_INT is used whenever the constant | |
6808 | will fit into a single word. In all such cases, the original mode | |
6809 | of the constant value is wiped out, and the CONST_INT rtx is | |
6810 | assigned VOIDmode. */ | |
6811 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
6812 | break; | |
6813 | ||
6814 | case CONST_DOUBLE: | |
6815 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
6816 | floating-point constant. A CONST_DOUBLE is used whenever the | |
6817 | constant requires more than one word in order to be adequately | |
469ac993 JM |
6818 | represented. We output CONST_DOUBLEs as blocks. */ |
6819 | { | |
6820 | register enum machine_mode mode = GET_MODE (rtl); | |
6821 | ||
6822 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
6823 | { | |
71dfc51f RK |
6824 | register unsigned length = GET_MODE_SIZE (mode) / sizeof (long); |
6825 | long array[4]; | |
6826 | REAL_VALUE_TYPE rv; | |
469ac993 | 6827 | |
71dfc51f | 6828 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
6829 | switch (mode) |
6830 | { | |
6831 | case SFmode: | |
71dfc51f | 6832 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
6833 | break; |
6834 | ||
6835 | case DFmode: | |
71dfc51f | 6836 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
6837 | break; |
6838 | ||
6839 | case XFmode: | |
6840 | case TFmode: | |
71dfc51f | 6841 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
6842 | break; |
6843 | ||
6844 | default: | |
6845 | abort (); | |
6846 | } | |
6847 | ||
469ac993 JM |
6848 | add_AT_float (die, DW_AT_const_value, length, array); |
6849 | } | |
6850 | else | |
6851 | add_AT_long_long (die, DW_AT_const_value, | |
6852 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
6853 | } | |
a3f97cbb JW |
6854 | break; |
6855 | ||
6856 | case CONST_STRING: | |
6857 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
6858 | break; | |
6859 | ||
6860 | case SYMBOL_REF: | |
6861 | case LABEL_REF: | |
6862 | case CONST: | |
6863 | add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl)); | |
6864 | break; | |
6865 | ||
6866 | case PLUS: | |
6867 | /* In cases where an inlined instance of an inline function is passed | |
6868 | the address of an `auto' variable (which is local to the caller) we | |
6869 | can get a situation where the DECL_RTL of the artificial local | |
6870 | variable (for the inlining) which acts as a stand-in for the | |
6871 | corresponding formal parameter (of the inline function) will look | |
6872 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
6873 | exactly a compile-time constant expression, but it isn't the address | |
6874 | of the (artificial) local variable either. Rather, it represents the | |
6875 | *value* which the artificial local variable always has during its | |
6876 | lifetime. We currently have no way to represent such quasi-constant | |
6a7a9f01 | 6877 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
6878 | break; |
6879 | ||
6880 | default: | |
6881 | /* No other kinds of rtx should be possible here. */ | |
6882 | abort (); | |
6883 | } | |
6884 | ||
6885 | } | |
6886 | ||
6887 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
6888 | data attribute for a variable or a parameter. We generate the | |
6889 | DW_AT_const_value attribute only in those cases where the given variable | |
6890 | or parameter does not have a true "location" either in memory or in a | |
6891 | register. This can happen (for example) when a constant is passed as an | |
6892 | actual argument in a call to an inline function. (It's possible that | |
6893 | these things can crop up in other ways also.) Note that one type of | |
6894 | constant value which can be passed into an inlined function is a constant | |
6895 | pointer. This can happen for example if an actual argument in an inlined | |
6896 | function call evaluates to a compile-time constant address. */ | |
71dfc51f | 6897 | |
a3f97cbb JW |
6898 | static void |
6899 | add_location_or_const_value_attribute (die, decl) | |
6900 | register dw_die_ref die; | |
6901 | register tree decl; | |
6902 | { | |
6903 | register rtx rtl; | |
6904 | register tree declared_type; | |
6905 | register tree passed_type; | |
6906 | ||
6907 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f RK |
6908 | return; |
6909 | ||
6910 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
6911 | abort (); | |
6912 | ||
a3f97cbb JW |
6913 | /* Here we have to decide where we are going to say the parameter "lives" |
6914 | (as far as the debugger is concerned). We only have a couple of | |
6915 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 6916 | |
a3f97cbb | 6917 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 6918 | activation of the function. If optimization is enabled however, this |
a3f97cbb JW |
6919 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
6920 | that the parameter doesn't really live anywhere (as far as the code | |
6921 | generation parts of GCC are concerned) during most of the function's | |
6922 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
6923 | referenced within the function. |
6924 | ||
6925 | We could just generate a location descriptor here for all non-NULL | |
6926 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
6927 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
6928 | where DECL_RTL is NULL or is a pseudo-reg. | |
6929 | ||
6930 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
6931 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
6932 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
6933 | we can be sure that the parameter was passed using the same type as it is | |
6934 | declared to have within the function, and that its DECL_INCOMING_RTL | |
6935 | points us to a place where a value of that type is passed. | |
6936 | ||
6937 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
6938 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
6939 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
6940 | type which is *different* from the type of the parameter itself. Thus, | |
6941 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
6942 | such cases, the debugger would end up (for example) trying to fetch a | |
6943 | `float' from a place which actually contains the first part of a | |
6944 | `double'. That would lead to really incorrect and confusing | |
6945 | output at debug-time. | |
6946 | ||
6947 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
6948 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
6949 | are a couple of exceptions however. On little-endian machines we can | |
6950 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
6951 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
6952 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
6953 | when (on a little-endian machine) a non-prototyped function has a | |
6954 | parameter declared to be of type `short' or `char'. In such cases, | |
6955 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
6956 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
6957 | passed `int' value. If the debugger then uses that address to fetch | |
6958 | a `short' or a `char' (on a little-endian machine) the result will be | |
6959 | the correct data, so we allow for such exceptional cases below. | |
6960 | ||
6961 | Note that our goal here is to describe the place where the given formal | |
6962 | parameter lives during most of the function's activation (i.e. between | |
6963 | the end of the prologue and the start of the epilogue). We'll do that | |
6964 | as best as we can. Note however that if the given formal parameter is | |
6965 | modified sometime during the execution of the function, then a stack | |
6966 | backtrace (at debug-time) will show the function as having been | |
6967 | called with the *new* value rather than the value which was | |
6968 | originally passed in. This happens rarely enough that it is not | |
6969 | a major problem, but it *is* a problem, and I'd like to fix it. | |
6970 | ||
6971 | A future version of dwarf2out.c may generate two additional | |
6972 | attributes for any given DW_TAG_formal_parameter DIE which will | |
6973 | describe the "passed type" and the "passed location" for the | |
6974 | given formal parameter in addition to the attributes we now | |
6975 | generate to indicate the "declared type" and the "active | |
6976 | location" for each parameter. This additional set of attributes | |
6977 | could be used by debuggers for stack backtraces. Separately, note | |
6978 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
6979 | NULL also. This happens (for example) for inlined-instances of | |
6980 | inline function formal parameters which are never referenced. | |
6981 | This really shouldn't be happening. All PARM_DECL nodes should | |
6982 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
6983 | doesn't currently generate these values for inlined instances of | |
6984 | inline function parameters, so when we see such cases, we are | |
956d6950 | 6985 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
6986 | gets fixed). */ |
6987 | ||
6988 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
6989 | rtl = DECL_RTL (decl); | |
6990 | ||
6991 | if (TREE_CODE (decl) == PARM_DECL) | |
6992 | { | |
6993 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
6994 | { | |
6995 | declared_type = type_main_variant (TREE_TYPE (decl)); | |
6996 | passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 6997 | |
71dfc51f | 6998 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
6999 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
7000 | all* cases where (rtl == NULL_RTX) just below. */ | |
7001 | if (declared_type == passed_type) | |
71dfc51f RK |
7002 | rtl = DECL_INCOMING_RTL (decl); |
7003 | else if (! BYTES_BIG_ENDIAN | |
7004 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
7005 | && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) | |
7006 | rtl = DECL_INCOMING_RTL (decl); | |
a3f97cbb JW |
7007 | } |
7008 | } | |
71dfc51f | 7009 | |
61b32c02 JM |
7010 | if (rtl == NULL_RTX) |
7011 | return; | |
7012 | ||
1914f5da | 7013 | rtl = eliminate_regs (rtl, 0, NULL_RTX); |
6a7a9f01 JM |
7014 | #ifdef LEAF_REG_REMAP |
7015 | if (leaf_function) | |
5f52dcfe | 7016 | leaf_renumber_regs_insn (rtl); |
6a7a9f01 JM |
7017 | #endif |
7018 | ||
a3f97cbb JW |
7019 | switch (GET_CODE (rtl)) |
7020 | { | |
e9a25f70 JL |
7021 | case ADDRESSOF: |
7022 | /* The address of a variable that was optimized away; don't emit | |
7023 | anything. */ | |
7024 | break; | |
7025 | ||
a3f97cbb JW |
7026 | case CONST_INT: |
7027 | case CONST_DOUBLE: | |
7028 | case CONST_STRING: | |
7029 | case SYMBOL_REF: | |
7030 | case LABEL_REF: | |
7031 | case CONST: | |
7032 | case PLUS: | |
7033 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
7034 | add_const_value_attribute (die, rtl); | |
7035 | break; | |
7036 | ||
7037 | case MEM: | |
7038 | case REG: | |
7039 | case SUBREG: | |
4401bf24 | 7040 | case CONCAT: |
ef76d03b | 7041 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
7042 | break; |
7043 | ||
7044 | default: | |
71dfc51f | 7045 | abort (); |
a3f97cbb JW |
7046 | } |
7047 | } | |
7048 | ||
7049 | /* Generate an DW_AT_name attribute given some string value to be included as | |
7050 | the value of the attribute. */ | |
71dfc51f RK |
7051 | |
7052 | static inline void | |
a3f97cbb JW |
7053 | add_name_attribute (die, name_string) |
7054 | register dw_die_ref die; | |
7055 | register char *name_string; | |
7056 | { | |
71dfc51f RK |
7057 | if (name_string != NULL && *name_string != 0) |
7058 | add_AT_string (die, DW_AT_name, name_string); | |
a3f97cbb JW |
7059 | } |
7060 | ||
7061 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 7062 | a representation for that bound. */ |
71dfc51f | 7063 | |
a3f97cbb JW |
7064 | static void |
7065 | add_bound_info (subrange_die, bound_attr, bound) | |
7066 | register dw_die_ref subrange_die; | |
7067 | register enum dwarf_attribute bound_attr; | |
7068 | register tree bound; | |
7069 | { | |
a3f97cbb | 7070 | register unsigned bound_value = 0; |
ef76d03b JW |
7071 | |
7072 | /* If this is an Ada unconstrained array type, then don't emit any debug | |
7073 | info because the array bounds are unknown. They are parameterized when | |
7074 | the type is instantiated. */ | |
7075 | if (contains_placeholder_p (bound)) | |
7076 | return; | |
7077 | ||
a3f97cbb JW |
7078 | switch (TREE_CODE (bound)) |
7079 | { | |
7080 | case ERROR_MARK: | |
7081 | return; | |
7082 | ||
7083 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
7084 | case INTEGER_CST: | |
7085 | bound_value = TREE_INT_CST_LOW (bound); | |
141719a8 JM |
7086 | if (bound_attr == DW_AT_lower_bound |
7087 | && ((is_c_family () && bound_value == 0) | |
7088 | || (is_fortran () && bound_value == 1))) | |
7089 | /* use the default */; | |
7090 | else | |
7091 | add_AT_unsigned (subrange_die, bound_attr, bound_value); | |
a3f97cbb JW |
7092 | break; |
7093 | ||
b1ccbc24 | 7094 | case CONVERT_EXPR: |
a3f97cbb | 7095 | case NOP_EXPR: |
b1ccbc24 RK |
7096 | case NON_LVALUE_EXPR: |
7097 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
7098 | break; | |
7099 | ||
a3f97cbb JW |
7100 | case SAVE_EXPR: |
7101 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
7102 | access the upper bound values may be bogus. If they refer to a |
7103 | register, they may only describe how to get at these values at the | |
7104 | points in the generated code right after they have just been | |
7105 | computed. Worse yet, in the typical case, the upper bound values | |
7106 | will not even *be* computed in the optimized code (though the | |
7107 | number of elements will), so these SAVE_EXPRs are entirely | |
7108 | bogus. In order to compensate for this fact, we check here to see | |
7109 | if optimization is enabled, and if so, we don't add an attribute | |
7110 | for the (unknown and unknowable) upper bound. This should not | |
7111 | cause too much trouble for existing (stupid?) debuggers because | |
7112 | they have to deal with empty upper bounds location descriptions | |
7113 | anyway in order to be able to deal with incomplete array types. | |
7114 | Of course an intelligent debugger (GDB?) should be able to | |
7115 | comprehend that a missing upper bound specification in a array | |
7116 | type used for a storage class `auto' local array variable | |
7117 | indicates that the upper bound is both unknown (at compile- time) | |
7118 | and unknowable (at run-time) due to optimization. | |
7119 | ||
7120 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
7121 | value there unless it was going to be used repeatedly in the | |
7122 | function, i.e. for cleanups. */ | |
7123 | if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM) | |
a3f97cbb | 7124 | { |
466446b0 JM |
7125 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
7126 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
7127 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
7128 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
ef76d03b JW |
7129 | add_AT_location_description (decl_die, DW_AT_location, |
7130 | SAVE_EXPR_RTL (bound)); | |
466446b0 | 7131 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 7132 | } |
71dfc51f RK |
7133 | |
7134 | /* Else leave out the attribute. */ | |
a3f97cbb | 7135 | break; |
3f76745e | 7136 | |
ef76d03b JW |
7137 | case MAX_EXPR: |
7138 | case VAR_DECL: | |
c85f7c16 | 7139 | case COMPONENT_REF: |
ef76d03b JW |
7140 | /* ??? These types of bounds can be created by the Ada front end, |
7141 | and it isn't clear how to emit debug info for them. */ | |
7142 | break; | |
7143 | ||
3f76745e JM |
7144 | default: |
7145 | abort (); | |
a3f97cbb JW |
7146 | } |
7147 | } | |
7148 | ||
7149 | /* Note that the block of subscript information for an array type also | |
7150 | includes information about the element type of type given array type. */ | |
71dfc51f | 7151 | |
a3f97cbb JW |
7152 | static void |
7153 | add_subscript_info (type_die, type) | |
7154 | register dw_die_ref type_die; | |
7155 | register tree type; | |
7156 | { | |
7157 | register unsigned dimension_number; | |
7158 | register tree lower, upper; | |
7159 | register dw_die_ref subrange_die; | |
7160 | ||
7161 | /* The GNU compilers represent multidimensional array types as sequences of | |
7162 | one dimensional array types whose element types are themselves array | |
7163 | types. Here we squish that down, so that each multidimensional array | |
7164 | type gets only one array_type DIE in the Dwarf debugging info. The draft | |
7165 | Dwarf specification say that we are allowed to do this kind of | |
7166 | compression in C (because there is no difference between an array or | |
7167 | arrays and a multidimensional array in C) but for other source languages | |
7168 | (e.g. Ada) we probably shouldn't do this. */ | |
71dfc51f | 7169 | |
a3f97cbb JW |
7170 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7171 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7172 | We work around this by disabling this feature. See also | |
7173 | gen_array_type_die. */ | |
7174 | #ifndef MIPS_DEBUGGING_INFO | |
7175 | for (dimension_number = 0; | |
7176 | TREE_CODE (type) == ARRAY_TYPE; | |
7177 | type = TREE_TYPE (type), dimension_number++) | |
7178 | { | |
7179 | #endif | |
7180 | register tree domain = TYPE_DOMAIN (type); | |
7181 | ||
7182 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
7183 | and (in GNU C only) variable bounds. Handle all three forms | |
7184 | here. */ | |
7185 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
7186 | if (domain) | |
7187 | { | |
7188 | /* We have an array type with specified bounds. */ | |
7189 | lower = TYPE_MIN_VALUE (domain); | |
7190 | upper = TYPE_MAX_VALUE (domain); | |
7191 | ||
a9d38797 JM |
7192 | /* define the index type. */ |
7193 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
7194 | { |
7195 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
7196 | TREE_TYPE field. We can't emit debug info for this | |
7197 | because it is an unnamed integral type. */ | |
7198 | if (TREE_CODE (domain) == INTEGER_TYPE | |
7199 | && TYPE_NAME (domain) == NULL_TREE | |
7200 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
7201 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
7202 | ; | |
7203 | else | |
7204 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
7205 | type_die); | |
7206 | } | |
a9d38797 | 7207 | |
e1ee5cdc RH |
7208 | /* ??? If upper is NULL, the array has unspecified length, |
7209 | but it does have a lower bound. This happens with Fortran | |
7210 | dimension arr(N:*) | |
7211 | Since the debugger is definitely going to need to know N | |
7212 | to produce useful results, go ahead and output the lower | |
7213 | bound solo, and hope the debugger can cope. */ | |
7214 | ||
141719a8 | 7215 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
7216 | if (upper) |
7217 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
7218 | } |
7219 | else | |
71dfc51f | 7220 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
7221 | spec does not say how to handle this; let's just leave out the |
7222 | bounds. */ | |
71dfc51f RK |
7223 | ; |
7224 | ||
a3f97cbb JW |
7225 | #ifndef MIPS_DEBUGGING_INFO |
7226 | } | |
7227 | #endif | |
7228 | } | |
7229 | ||
7230 | static void | |
7231 | add_byte_size_attribute (die, tree_node) | |
7232 | dw_die_ref die; | |
7233 | register tree tree_node; | |
7234 | { | |
7235 | register unsigned size; | |
7236 | ||
7237 | switch (TREE_CODE (tree_node)) | |
7238 | { | |
7239 | case ERROR_MARK: | |
7240 | size = 0; | |
7241 | break; | |
7242 | case ENUMERAL_TYPE: | |
7243 | case RECORD_TYPE: | |
7244 | case UNION_TYPE: | |
7245 | case QUAL_UNION_TYPE: | |
7246 | size = int_size_in_bytes (tree_node); | |
7247 | break; | |
7248 | case FIELD_DECL: | |
7249 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
7250 | generally given as the number of bytes normally allocated for an | |
7251 | object of the *declared* type of the member itself. This is true | |
7252 | even for bit-fields. */ | |
7253 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
7254 | break; | |
7255 | default: | |
7256 | abort (); | |
7257 | } | |
7258 | ||
7259 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
7260 | indicates that the byte size of the entity in question is variable. We | |
7261 | have no good way of expressing this fact in Dwarf at the present time, | |
7262 | so just let the -1 pass on through. */ | |
7263 | ||
7264 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
7265 | } | |
7266 | ||
7267 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
7268 | which specifies the distance in bits from the highest order bit of the | |
7269 | "containing object" for the bit-field to the highest order bit of the | |
7270 | bit-field itself. | |
7271 | ||
b2932ae5 JM |
7272 | For any given bit-field, the "containing object" is a hypothetical |
7273 | object (of some integral or enum type) within which the given bit-field | |
7274 | lives. The type of this hypothetical "containing object" is always the | |
7275 | same as the declared type of the individual bit-field itself. The | |
7276 | determination of the exact location of the "containing object" for a | |
7277 | bit-field is rather complicated. It's handled by the | |
7278 | `field_byte_offset' function (above). | |
a3f97cbb JW |
7279 | |
7280 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
7281 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
7282 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
7283 | |
7284 | static inline void | |
a3f97cbb JW |
7285 | add_bit_offset_attribute (die, decl) |
7286 | register dw_die_ref die; | |
7287 | register tree decl; | |
7288 | { | |
7289 | register unsigned object_offset_in_bytes = field_byte_offset (decl); | |
7290 | register tree type = DECL_BIT_FIELD_TYPE (decl); | |
7291 | register tree bitpos_tree = DECL_FIELD_BITPOS (decl); | |
7292 | register unsigned bitpos_int; | |
7293 | register unsigned highest_order_object_bit_offset; | |
7294 | register unsigned highest_order_field_bit_offset; | |
7295 | register unsigned bit_offset; | |
7296 | ||
3a88cbd1 JL |
7297 | /* Must be a field and a bit field. */ |
7298 | if (!type | |
7299 | || TREE_CODE (decl) != FIELD_DECL) | |
7300 | abort (); | |
a3f97cbb JW |
7301 | |
7302 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
7303 | encounter such things, just return without generating any attribute | |
7304 | whatsoever. */ | |
7305 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
71dfc51f RK |
7306 | return; |
7307 | ||
a3f97cbb JW |
7308 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); |
7309 | ||
7310 | /* Note that the bit offset is always the distance (in bits) from the | |
7311 | highest-order bit of the "containing object" to the highest-order bit of | |
7312 | the bit-field itself. Since the "high-order end" of any object or field | |
7313 | is different on big-endian and little-endian machines, the computation | |
7314 | below must take account of these differences. */ | |
7315 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
7316 | highest_order_field_bit_offset = bitpos_int; | |
7317 | ||
71dfc51f | 7318 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb JW |
7319 | { |
7320 | highest_order_field_bit_offset | |
7321 | += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); | |
7322 | ||
7323 | highest_order_object_bit_offset += simple_type_size_in_bits (type); | |
7324 | } | |
71dfc51f RK |
7325 | |
7326 | bit_offset | |
7327 | = (! BYTES_BIG_ENDIAN | |
7328 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
7329 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
7330 | |
7331 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
7332 | } | |
7333 | ||
7334 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
7335 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
7336 | |
7337 | static inline void | |
a3f97cbb JW |
7338 | add_bit_size_attribute (die, decl) |
7339 | register dw_die_ref die; | |
7340 | register tree decl; | |
7341 | { | |
3a88cbd1 JL |
7342 | /* Must be a field and a bit field. */ |
7343 | if (TREE_CODE (decl) != FIELD_DECL | |
7344 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
7345 | abort (); | |
a3f97cbb JW |
7346 | add_AT_unsigned (die, DW_AT_bit_size, |
7347 | (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); | |
7348 | } | |
7349 | ||
88dad228 | 7350 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 7351 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
7352 | |
7353 | static inline void | |
a3f97cbb JW |
7354 | add_prototyped_attribute (die, func_type) |
7355 | register dw_die_ref die; | |
7356 | register tree func_type; | |
7357 | { | |
88dad228 JM |
7358 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
7359 | && TYPE_ARG_TYPES (func_type) != NULL) | |
7360 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
7361 | } |
7362 | ||
7363 | ||
7364 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found | |
7365 | by looking in either the type declaration or object declaration | |
7366 | equate table. */ | |
71dfc51f RK |
7367 | |
7368 | static inline void | |
a3f97cbb JW |
7369 | add_abstract_origin_attribute (die, origin) |
7370 | register dw_die_ref die; | |
7371 | register tree origin; | |
7372 | { | |
7373 | dw_die_ref origin_die = NULL; | |
7374 | if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd') | |
71dfc51f | 7375 | origin_die = lookup_decl_die (origin); |
a3f97cbb | 7376 | else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't') |
71dfc51f RK |
7377 | origin_die = lookup_type_die (origin); |
7378 | ||
a3f97cbb JW |
7379 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
7380 | } | |
7381 | ||
bdb669cb JM |
7382 | /* We do not currently support the pure_virtual attribute. */ |
7383 | ||
71dfc51f | 7384 | static inline void |
a3f97cbb JW |
7385 | add_pure_or_virtual_attribute (die, func_decl) |
7386 | register dw_die_ref die; | |
7387 | register tree func_decl; | |
7388 | { | |
a94dbf2c | 7389 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 7390 | { |
bdb669cb | 7391 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
71dfc51f RK |
7392 | add_AT_loc (die, DW_AT_vtable_elem_location, |
7393 | new_loc_descr (DW_OP_constu, | |
7394 | TREE_INT_CST_LOW (DECL_VINDEX (func_decl)), | |
7395 | 0)); | |
7396 | ||
a94dbf2c JM |
7397 | /* GNU extension: Record what type this method came from originally. */ |
7398 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
7399 | add_AT_die_ref (die, DW_AT_containing_type, | |
7400 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
7401 | } |
7402 | } | |
7403 | \f | |
b2932ae5 | 7404 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 7405 | |
b2932ae5 JM |
7406 | static void |
7407 | add_src_coords_attributes (die, decl) | |
7408 | register dw_die_ref die; | |
7409 | register tree decl; | |
7410 | { | |
7411 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 7412 | |
b2932ae5 JM |
7413 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
7414 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
7415 | } | |
7416 | ||
a3f97cbb JW |
7417 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
7418 | given decl, but only if it actually has a name. */ | |
71dfc51f | 7419 | |
a3f97cbb JW |
7420 | static void |
7421 | add_name_and_src_coords_attributes (die, decl) | |
7422 | register dw_die_ref die; | |
7423 | register tree decl; | |
7424 | { | |
61b32c02 | 7425 | register tree decl_name; |
71dfc51f | 7426 | |
a1d7ffe3 | 7427 | decl_name = DECL_NAME (decl); |
71dfc51f | 7428 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 7429 | { |
a1d7ffe3 | 7430 | add_name_attribute (die, dwarf2_name (decl, 0)); |
b2932ae5 | 7431 | add_src_coords_attributes (die, decl); |
a1d7ffe3 JM |
7432 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
7433 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) | |
7434 | add_AT_string (die, DW_AT_MIPS_linkage_name, | |
7435 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
7436 | } |
7437 | } | |
7438 | ||
7439 | /* Push a new declaration scope. */ | |
71dfc51f | 7440 | |
a3f97cbb JW |
7441 | static void |
7442 | push_decl_scope (scope) | |
7443 | tree scope; | |
7444 | { | |
7445 | /* Make room in the decl_scope_table, if necessary. */ | |
7446 | if (decl_scope_table_allocated == decl_scope_depth) | |
7447 | { | |
7448 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f RK |
7449 | decl_scope_table |
7450 | = (tree *) xrealloc (decl_scope_table, | |
7451 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 7452 | } |
71dfc51f | 7453 | |
a3f97cbb JW |
7454 | decl_scope_table[decl_scope_depth++] = scope; |
7455 | } | |
7456 | ||
7457 | /* Return the DIE for the scope the immediately contains this declaration. */ | |
71dfc51f | 7458 | |
a3f97cbb | 7459 | static dw_die_ref |
ab72d377 JM |
7460 | scope_die_for (t, context_die) |
7461 | register tree t; | |
a3f97cbb JW |
7462 | register dw_die_ref context_die; |
7463 | { | |
7464 | register dw_die_ref scope_die = NULL; | |
7465 | register tree containing_scope; | |
7466 | register unsigned long i; | |
7467 | ||
7468 | /* Walk back up the declaration tree looking for a place to define | |
7469 | this type. */ | |
ab72d377 JM |
7470 | if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') |
7471 | containing_scope = TYPE_CONTEXT (t); | |
a94dbf2c | 7472 | else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t)) |
ab72d377 JM |
7473 | containing_scope = decl_class_context (t); |
7474 | else | |
7475 | containing_scope = DECL_CONTEXT (t); | |
7476 | ||
ef76d03b JW |
7477 | /* Function-local tags and functions get stuck in limbo until they are |
7478 | fixed up by decls_for_scope. */ | |
7479 | if (context_die == NULL && containing_scope != NULL_TREE | |
7480 | && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t))) | |
7481 | return NULL; | |
7482 | ||
71dfc51f RK |
7483 | if (containing_scope == NULL_TREE) |
7484 | scope_die = comp_unit_die; | |
a3f97cbb JW |
7485 | else |
7486 | { | |
ab72d377 JM |
7487 | for (i = decl_scope_depth, scope_die = context_die; |
7488 | i > 0 && decl_scope_table[i - 1] != containing_scope; | |
7d4440be | 7489 | scope_die = scope_die->die_parent, --i) |
71dfc51f RK |
7490 | ; |
7491 | ||
ab72d377 | 7492 | if (i == 0) |
a3f97cbb | 7493 | { |
3a88cbd1 JL |
7494 | if (scope_die != comp_unit_die |
7495 | || TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't') | |
7496 | abort (); | |
7497 | if (debug_info_level > DINFO_LEVEL_TERSE | |
7498 | && !TREE_ASM_WRITTEN (containing_scope)) | |
7499 | abort (); | |
a3f97cbb JW |
7500 | } |
7501 | } | |
71dfc51f | 7502 | |
a3f97cbb JW |
7503 | return scope_die; |
7504 | } | |
7505 | ||
7506 | /* Pop a declaration scope. */ | |
71dfc51f | 7507 | static inline void |
a3f97cbb JW |
7508 | pop_decl_scope () |
7509 | { | |
3a88cbd1 JL |
7510 | if (decl_scope_depth <= 0) |
7511 | abort (); | |
a3f97cbb JW |
7512 | --decl_scope_depth; |
7513 | } | |
7514 | ||
7515 | /* Many forms of DIEs require a "type description" attribute. This | |
7516 | routine locates the proper "type descriptor" die for the type given | |
7517 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 7518 | |
a3f97cbb JW |
7519 | static void |
7520 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
7521 | register dw_die_ref object_die; | |
7522 | register tree type; | |
7523 | register int decl_const; | |
7524 | register int decl_volatile; | |
7525 | register dw_die_ref context_die; | |
7526 | { | |
7527 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
7528 | register dw_die_ref type_die = NULL; |
7529 | ||
ef76d03b JW |
7530 | /* ??? If this type is an unnamed subrange type of an integral or |
7531 | floating-point type, use the inner type. This is because we have no | |
7532 | support for unnamed types in base_type_die. This can happen if this is | |
7533 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
7534 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
7535 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
7536 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
7537 | ||
a3f97cbb | 7538 | if (code == ERROR_MARK) |
b1ccbc24 | 7539 | return; |
a3f97cbb JW |
7540 | |
7541 | /* Handle a special case. For functions whose return type is void, we | |
7542 | generate *no* type attribute. (Note that no object may have type | |
7543 | `void', so this only applies to function return types). */ | |
7544 | if (code == VOID_TYPE) | |
b1ccbc24 | 7545 | return; |
a3f97cbb | 7546 | |
a3f97cbb JW |
7547 | type_die = modified_type_die (type, |
7548 | decl_const || TYPE_READONLY (type), | |
7549 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 7550 | context_die); |
a3f97cbb | 7551 | if (type_die != NULL) |
71dfc51f | 7552 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
7553 | } |
7554 | ||
7555 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
7556 | a pointer to the (string) tag name for the given type, or zero if the type | |
7557 | was declared without a tag. */ | |
71dfc51f | 7558 | |
a3f97cbb JW |
7559 | static char * |
7560 | type_tag (type) | |
7561 | register tree type; | |
7562 | { | |
7563 | register char *name = 0; | |
7564 | ||
7565 | if (TYPE_NAME (type) != 0) | |
7566 | { | |
7567 | register tree t = 0; | |
7568 | ||
7569 | /* Find the IDENTIFIER_NODE for the type name. */ | |
7570 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
7571 | t = TYPE_NAME (type); | |
bdb669cb | 7572 | |
a3f97cbb JW |
7573 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
7574 | a TYPE_DECL node, regardless of whether or not a `typedef' was | |
bdb669cb | 7575 | involved. */ |
a94dbf2c JM |
7576 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
7577 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 7578 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 7579 | |
a3f97cbb JW |
7580 | /* Now get the name as a string, or invent one. */ |
7581 | if (t != 0) | |
a94dbf2c | 7582 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 7583 | } |
71dfc51f | 7584 | |
a3f97cbb JW |
7585 | return (name == 0 || *name == '\0') ? 0 : name; |
7586 | } | |
7587 | ||
7588 | /* Return the type associated with a data member, make a special check | |
7589 | for bit field types. */ | |
71dfc51f RK |
7590 | |
7591 | static inline tree | |
a3f97cbb JW |
7592 | member_declared_type (member) |
7593 | register tree member; | |
7594 | { | |
71dfc51f RK |
7595 | return (DECL_BIT_FIELD_TYPE (member) |
7596 | ? DECL_BIT_FIELD_TYPE (member) | |
7597 | : TREE_TYPE (member)); | |
a3f97cbb JW |
7598 | } |
7599 | ||
d291dd49 | 7600 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 7601 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 7602 | |
a3f97cbb | 7603 | static char * |
d291dd49 | 7604 | decl_start_label (decl) |
a3f97cbb JW |
7605 | register tree decl; |
7606 | { | |
7607 | rtx x; | |
7608 | char *fnname; | |
7609 | x = DECL_RTL (decl); | |
7610 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
7611 | abort (); |
7612 | ||
a3f97cbb JW |
7613 | x = XEXP (x, 0); |
7614 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
7615 | abort (); |
7616 | ||
a3f97cbb JW |
7617 | fnname = XSTR (x, 0); |
7618 | return fnname; | |
7619 | } | |
7620 | \f | |
956d6950 | 7621 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 7622 | the compilation unit. Debugging information is collected by walking |
88dad228 | 7623 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
7624 | |
7625 | static void | |
7626 | gen_array_type_die (type, context_die) | |
7627 | register tree type; | |
7628 | register dw_die_ref context_die; | |
7629 | { | |
ab72d377 | 7630 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 7631 | register dw_die_ref array_die; |
a3f97cbb | 7632 | register tree element_type; |
bdb669cb | 7633 | |
a9d38797 JM |
7634 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
7635 | the inner array type comes before the outer array type. Thus we must | |
7636 | call gen_type_die before we call new_die. See below also. */ | |
7637 | #ifdef MIPS_DEBUGGING_INFO | |
7638 | gen_type_die (TREE_TYPE (type), context_die); | |
7639 | #endif | |
7640 | ||
7641 | array_die = new_die (DW_TAG_array_type, scope_die); | |
7642 | ||
a3f97cbb JW |
7643 | #if 0 |
7644 | /* We default the array ordering. SDB will probably do | |
7645 | the right things even if DW_AT_ordering is not present. It's not even | |
7646 | an issue until we start to get into multidimensional arrays anyway. If | |
7647 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
7648 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
7649 | and when we find out that we need to put these in, we will only do so | |
7650 | for multidimensional arrays. */ | |
7651 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
7652 | #endif | |
7653 | ||
a9d38797 | 7654 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
7655 | /* The SGI compilers handle arrays of unknown bound by setting |
7656 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
7657 | if (! TYPE_DOMAIN (type)) |
7658 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
7659 | else | |
7660 | #endif | |
7661 | add_subscript_info (array_die, type); | |
a3f97cbb JW |
7662 | |
7663 | equate_type_number_to_die (type, array_die); | |
7664 | ||
7665 | /* Add representation of the type of the elements of this array type. */ | |
7666 | element_type = TREE_TYPE (type); | |
71dfc51f | 7667 | |
a3f97cbb JW |
7668 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7669 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7670 | We work around this by disabling this feature. See also | |
7671 | add_subscript_info. */ | |
7672 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
7673 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
7674 | element_type = TREE_TYPE (element_type); | |
7675 | ||
a3f97cbb | 7676 | gen_type_die (element_type, context_die); |
a9d38797 | 7677 | #endif |
a3f97cbb JW |
7678 | |
7679 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
7680 | } | |
7681 | ||
7682 | static void | |
7683 | gen_set_type_die (type, context_die) | |
7684 | register tree type; | |
7685 | register dw_die_ref context_die; | |
7686 | { | |
71dfc51f RK |
7687 | register dw_die_ref type_die |
7688 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
7689 | ||
a3f97cbb | 7690 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
7691 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
7692 | } | |
7693 | ||
7694 | static void | |
7695 | gen_entry_point_die (decl, context_die) | |
7696 | register tree decl; | |
7697 | register dw_die_ref context_die; | |
7698 | { | |
7699 | register tree origin = decl_ultimate_origin (decl); | |
7700 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
7701 | if (origin != NULL) | |
71dfc51f | 7702 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
7703 | else |
7704 | { | |
7705 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
7706 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
7707 | 0, 0, context_die); | |
7708 | } | |
71dfc51f | 7709 | |
a3f97cbb | 7710 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 7711 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 7712 | else |
71dfc51f | 7713 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb JW |
7714 | } |
7715 | ||
a94dbf2c JM |
7716 | /* Remember a type in the pending_types_list. */ |
7717 | ||
7718 | static void | |
7719 | pend_type (type) | |
7720 | register tree type; | |
7721 | { | |
7722 | if (pending_types == pending_types_allocated) | |
7723 | { | |
7724 | pending_types_allocated += PENDING_TYPES_INCREMENT; | |
7725 | pending_types_list | |
7726 | = (tree *) xrealloc (pending_types_list, | |
7727 | sizeof (tree) * pending_types_allocated); | |
7728 | } | |
71dfc51f | 7729 | |
a94dbf2c JM |
7730 | pending_types_list[pending_types++] = type; |
7731 | } | |
7732 | ||
7733 | /* Output any pending types (from the pending_types list) which we can output | |
7734 | now (taking into account the scope that we are working on now). | |
7735 | ||
7736 | For each type output, remove the given type from the pending_types_list | |
7737 | *before* we try to output it. */ | |
7738 | ||
7739 | static void | |
7740 | output_pending_types_for_scope (context_die) | |
7741 | register dw_die_ref context_die; | |
7742 | { | |
7743 | register tree type; | |
7744 | ||
7745 | while (pending_types) | |
7746 | { | |
7747 | --pending_types; | |
7748 | type = pending_types_list[pending_types]; | |
7749 | gen_type_die (type, context_die); | |
3a88cbd1 JL |
7750 | if (!TREE_ASM_WRITTEN (type)) |
7751 | abort (); | |
a94dbf2c JM |
7752 | } |
7753 | } | |
7754 | ||
a3f97cbb | 7755 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 7756 | |
a3f97cbb JW |
7757 | static void |
7758 | gen_inlined_enumeration_type_die (type, context_die) | |
7759 | register tree type; | |
7760 | register dw_die_ref context_die; | |
7761 | { | |
71dfc51f RK |
7762 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
7763 | scope_die_for (type, context_die)); | |
7764 | ||
3a88cbd1 JL |
7765 | if (!TREE_ASM_WRITTEN (type)) |
7766 | abort (); | |
a3f97cbb JW |
7767 | add_abstract_origin_attribute (type_die, type); |
7768 | } | |
7769 | ||
7770 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 7771 | |
a3f97cbb JW |
7772 | static void |
7773 | gen_inlined_structure_type_die (type, context_die) | |
7774 | register tree type; | |
7775 | register dw_die_ref context_die; | |
7776 | { | |
71dfc51f RK |
7777 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, |
7778 | scope_die_for (type, context_die)); | |
7779 | ||
3a88cbd1 JL |
7780 | if (!TREE_ASM_WRITTEN (type)) |
7781 | abort (); | |
a3f97cbb JW |
7782 | add_abstract_origin_attribute (type_die, type); |
7783 | } | |
7784 | ||
7785 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 7786 | |
a3f97cbb JW |
7787 | static void |
7788 | gen_inlined_union_type_die (type, context_die) | |
7789 | register tree type; | |
7790 | register dw_die_ref context_die; | |
7791 | { | |
71dfc51f RK |
7792 | register dw_die_ref type_die = new_die (DW_TAG_union_type, |
7793 | scope_die_for (type, context_die)); | |
7794 | ||
3a88cbd1 JL |
7795 | if (!TREE_ASM_WRITTEN (type)) |
7796 | abort (); | |
a3f97cbb JW |
7797 | add_abstract_origin_attribute (type_die, type); |
7798 | } | |
7799 | ||
7800 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
7801 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
7802 | enumerated type name/value is listed as a child of the enumerated type |
7803 | DIE. */ | |
71dfc51f | 7804 | |
a3f97cbb | 7805 | static void |
273dbe67 | 7806 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 7807 | register tree type; |
a3f97cbb JW |
7808 | register dw_die_ref context_die; |
7809 | { | |
273dbe67 JM |
7810 | register dw_die_ref type_die = lookup_type_die (type); |
7811 | ||
a3f97cbb JW |
7812 | if (type_die == NULL) |
7813 | { | |
7814 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 7815 | scope_die_for (type, context_die)); |
a3f97cbb JW |
7816 | equate_type_number_to_die (type, type_die); |
7817 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 7818 | } |
273dbe67 JM |
7819 | else if (! TYPE_SIZE (type)) |
7820 | return; | |
7821 | else | |
7822 | remove_AT (type_die, DW_AT_declaration); | |
7823 | ||
7824 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
7825 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
7826 | attribute or the DW_AT_element_list attribute. */ | |
7827 | if (TYPE_SIZE (type)) | |
a3f97cbb | 7828 | { |
273dbe67 | 7829 | register tree link; |
71dfc51f | 7830 | |
a082c85a | 7831 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 7832 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 7833 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 7834 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 7835 | |
ef76d03b JW |
7836 | /* If the first reference to this type was as the return type of an |
7837 | inline function, then it may not have a parent. Fix this now. */ | |
7838 | if (type_die->die_parent == NULL) | |
7839 | add_child_die (scope_die_for (type, context_die), type_die); | |
7840 | ||
273dbe67 JM |
7841 | for (link = TYPE_FIELDS (type); |
7842 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 7843 | { |
273dbe67 | 7844 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 7845 | |
273dbe67 JM |
7846 | add_name_attribute (enum_die, |
7847 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
7848 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
a3f97cbb | 7849 | (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); |
a3f97cbb JW |
7850 | } |
7851 | } | |
273dbe67 JM |
7852 | else |
7853 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
7854 | } |
7855 | ||
7856 | ||
7857 | /* Generate a DIE to represent either a real live formal parameter decl or to | |
7858 | represent just the type of some formal parameter position in some function | |
7859 | type. | |
71dfc51f | 7860 | |
a3f97cbb JW |
7861 | Note that this routine is a bit unusual because its argument may be a |
7862 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
7863 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
7864 | node. If it's the former then this function is being called to output a | |
7865 | DIE to represent a formal parameter object (or some inlining thereof). If | |
7866 | it's the latter, then this function is only being called to output a | |
7867 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
7868 | argument type of some subprogram type. */ | |
71dfc51f | 7869 | |
a94dbf2c | 7870 | static dw_die_ref |
a3f97cbb JW |
7871 | gen_formal_parameter_die (node, context_die) |
7872 | register tree node; | |
7873 | register dw_die_ref context_die; | |
7874 | { | |
71dfc51f RK |
7875 | register dw_die_ref parm_die |
7876 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 7877 | register tree origin; |
71dfc51f | 7878 | |
a3f97cbb JW |
7879 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
7880 | { | |
a3f97cbb JW |
7881 | case 'd': |
7882 | origin = decl_ultimate_origin (node); | |
7883 | if (origin != NULL) | |
a94dbf2c | 7884 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
7885 | else |
7886 | { | |
7887 | add_name_and_src_coords_attributes (parm_die, node); | |
7888 | add_type_attribute (parm_die, TREE_TYPE (node), | |
7889 | TREE_READONLY (node), | |
7890 | TREE_THIS_VOLATILE (node), | |
7891 | context_die); | |
bdb669cb JM |
7892 | if (DECL_ARTIFICIAL (node)) |
7893 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 7894 | } |
71dfc51f | 7895 | |
141719a8 JM |
7896 | equate_decl_number_to_die (node, parm_die); |
7897 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 7898 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 7899 | |
a3f97cbb JW |
7900 | break; |
7901 | ||
a3f97cbb | 7902 | case 't': |
71dfc51f | 7903 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
7904 | add_type_attribute (parm_die, node, 0, 0, context_die); |
7905 | break; | |
7906 | ||
a3f97cbb JW |
7907 | default: |
7908 | abort (); | |
7909 | } | |
71dfc51f | 7910 | |
a94dbf2c | 7911 | return parm_die; |
a3f97cbb JW |
7912 | } |
7913 | ||
7914 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
7915 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 7916 | |
a3f97cbb JW |
7917 | static void |
7918 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
7919 | register tree decl_or_type; | |
7920 | register dw_die_ref context_die; | |
7921 | { | |
7922 | register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters, | |
7923 | context_die); | |
a3f97cbb JW |
7924 | } |
7925 | ||
7926 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
7927 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
7928 | parameters as specified in some function type specification (except for | |
7929 | those which appear as part of a function *definition*). | |
71dfc51f RK |
7930 | |
7931 | Note we must be careful here to output all of the parameter DIEs before* | |
a3f97cbb JW |
7932 | we output any DIEs needed to represent the types of the formal parameters. |
7933 | This keeps svr4 SDB happy because it (incorrectly) thinks that the first | |
7934 | non-parameter DIE it sees ends the formal parameter list. */ | |
71dfc51f | 7935 | |
a3f97cbb JW |
7936 | static void |
7937 | gen_formal_types_die (function_or_method_type, context_die) | |
7938 | register tree function_or_method_type; | |
7939 | register dw_die_ref context_die; | |
7940 | { | |
7941 | register tree link; | |
7942 | register tree formal_type = NULL; | |
7943 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
7944 | ||
bdb669cb | 7945 | #if 0 |
a3f97cbb JW |
7946 | /* In the case where we are generating a formal types list for a C++ |
7947 | non-static member function type, skip over the first thing on the | |
7948 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
7949 | `this pointer'. The debugger should be able to figure out (without | |
7950 | being explicitly told) that this non-static member function type takes a | |
7951 | `this pointer' and should be able to figure what the type of that hidden | |
7952 | parameter is from the DW_AT_member attribute of the parent | |
7953 | DW_TAG_subroutine_type DIE. */ | |
7954 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
7955 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 7956 | #endif |
a3f97cbb JW |
7957 | |
7958 | /* Make our first pass over the list of formal parameter types and output a | |
7959 | DW_TAG_formal_parameter DIE for each one. */ | |
7960 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
7961 | { | |
a94dbf2c JM |
7962 | register dw_die_ref parm_die; |
7963 | ||
a3f97cbb JW |
7964 | formal_type = TREE_VALUE (link); |
7965 | if (formal_type == void_type_node) | |
7966 | break; | |
7967 | ||
7968 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c JM |
7969 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
7970 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE | |
7971 | && link == first_parm_type) | |
7972 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
7973 | } |
7974 | ||
7975 | /* If this function type has an ellipsis, add a | |
7976 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
7977 | if (formal_type != void_type_node) | |
7978 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
7979 | ||
7980 | /* Make our second (and final) pass over the list of formal parameter types | |
7981 | and output DIEs to represent those types (as necessary). */ | |
7982 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
7983 | link; | |
7984 | link = TREE_CHAIN (link)) | |
7985 | { | |
7986 | formal_type = TREE_VALUE (link); | |
7987 | if (formal_type == void_type_node) | |
7988 | break; | |
7989 | ||
b50c02f9 | 7990 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
7991 | } |
7992 | } | |
7993 | ||
7994 | /* Generate a DIE to represent a declared function (either file-scope or | |
7995 | block-local). */ | |
71dfc51f | 7996 | |
a3f97cbb JW |
7997 | static void |
7998 | gen_subprogram_die (decl, context_die) | |
7999 | register tree decl; | |
8000 | register dw_die_ref context_die; | |
8001 | { | |
8002 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
8003 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 8004 | register dw_die_ref subr_die; |
a3f97cbb | 8005 | register dw_loc_descr_ref fp_loc = NULL; |
b1ccbc24 | 8006 | register rtx fp_reg; |
a3f97cbb JW |
8007 | register tree fn_arg_types; |
8008 | register tree outer_scope; | |
a94dbf2c | 8009 | register dw_die_ref old_die = lookup_decl_die (decl); |
9c6cd30e JM |
8010 | register int declaration |
8011 | = (current_function_decl != decl | |
8012 | || (context_die | |
8013 | && (context_die->die_tag == DW_TAG_structure_type | |
8014 | || context_die->die_tag == DW_TAG_union_type))); | |
a3f97cbb | 8015 | |
a3f97cbb JW |
8016 | if (origin != NULL) |
8017 | { | |
4b674448 | 8018 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
8019 | add_abstract_origin_attribute (subr_die, origin); |
8020 | } | |
4401bf24 JL |
8021 | else if (old_die && DECL_ABSTRACT (decl) |
8022 | && get_AT_unsigned (old_die, DW_AT_inline)) | |
8023 | { | |
8024 | /* This must be a redefinition of an extern inline function. | |
8025 | We can just reuse the old die here. */ | |
8026 | subr_die = old_die; | |
8027 | ||
8028 | /* Clear out the inlined attribute and parm types. */ | |
8029 | remove_AT (subr_die, DW_AT_inline); | |
8030 | remove_children (subr_die); | |
8031 | } | |
bdb669cb JM |
8032 | else if (old_die) |
8033 | { | |
4b674448 JM |
8034 | register unsigned file_index |
8035 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
a94dbf2c | 8036 | |
3a88cbd1 JL |
8037 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) |
8038 | abort (); | |
4b674448 JM |
8039 | |
8040 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
8041 | maybe use the old DIE. We always want the DIE for this function |
8042 | that has the *_pc attributes to be under comp_unit_die so the | |
8043 | debugger can find it. For inlines, that is the concrete instance, | |
8044 | so we can use the old DIE here. For non-inline methods, we want a | |
8045 | specification DIE at toplevel, so we need a new DIE. For local | |
8046 | class methods, this does not apply. */ | |
8047 | if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die | |
8048 | || context_die == NULL) | |
8049 | && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
4b674448 JM |
8050 | && (get_AT_unsigned (old_die, DW_AT_decl_line) |
8051 | == DECL_SOURCE_LINE (decl))) | |
bdb669cb | 8052 | { |
4b674448 JM |
8053 | subr_die = old_die; |
8054 | ||
8055 | /* Clear out the declaration attribute and the parm types. */ | |
8056 | remove_AT (subr_die, DW_AT_declaration); | |
8057 | remove_children (subr_die); | |
8058 | } | |
8059 | else | |
8060 | { | |
8061 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
8062 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
8063 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8064 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
8065 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
8066 | != DECL_SOURCE_LINE (decl)) | |
8067 | add_AT_unsigned | |
8068 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8069 | } | |
8070 | } | |
a3f97cbb JW |
8071 | else |
8072 | { | |
4edb7b60 JM |
8073 | register dw_die_ref scope_die; |
8074 | ||
8075 | if (DECL_CONTEXT (decl)) | |
8076 | scope_die = scope_die_for (decl, context_die); | |
8077 | else | |
8078 | /* Don't put block extern declarations under comp_unit_die. */ | |
8079 | scope_die = context_die; | |
8080 | ||
8081 | subr_die = new_die (DW_TAG_subprogram, scope_die); | |
8082 | ||
273dbe67 JM |
8083 | if (TREE_PUBLIC (decl)) |
8084 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 8085 | |
a3f97cbb | 8086 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
8087 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8088 | { | |
8089 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 8090 | |
4927276d JM |
8091 | add_prototyped_attribute (subr_die, type); |
8092 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
8093 | } | |
71dfc51f | 8094 | |
a3f97cbb | 8095 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
8096 | if (DECL_ARTIFICIAL (decl)) |
8097 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
8098 | if (TREE_PROTECTED (decl)) |
8099 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
8100 | else if (TREE_PRIVATE (decl)) | |
8101 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8102 | } |
4edb7b60 | 8103 | |
a94dbf2c JM |
8104 | if (declaration) |
8105 | { | |
8106 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
8107 | ||
8108 | /* The first time we see a member function, it is in the context of | |
8109 | the class to which it belongs. We make sure of this by emitting | |
8110 | the class first. The next time is the definition, which is | |
8111 | handled above. The two may come from the same source text. */ | |
f6c74b02 | 8112 | if (DECL_CONTEXT (decl)) |
a94dbf2c JM |
8113 | equate_decl_number_to_die (decl, subr_die); |
8114 | } | |
8115 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 8116 | { |
4401bf24 JL |
8117 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions, |
8118 | but not for extern inline functions. We can't get this completely | |
8119 | correct because information about whether the function was declared | |
8120 | inline is not saved anywhere. */ | |
61b32c02 JM |
8121 | if (DECL_DEFER_OUTPUT (decl)) |
8122 | { | |
8123 | if (DECL_INLINE (decl)) | |
8124 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); | |
8125 | else | |
8126 | add_AT_unsigned (subr_die, DW_AT_inline, | |
8127 | DW_INL_declared_not_inlined); | |
8128 | } | |
8129 | else if (DECL_INLINE (decl)) | |
8130 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); | |
8131 | else | |
8132 | abort (); | |
8133 | ||
a3f97cbb JW |
8134 | equate_decl_number_to_die (decl, subr_die); |
8135 | } | |
8136 | else if (!DECL_EXTERNAL (decl)) | |
8137 | { | |
71dfc51f | 8138 | if (origin == NULL_TREE) |
ba7b35df | 8139 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 8140 | |
5c90448c JM |
8141 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
8142 | current_funcdef_number); | |
7d4440be | 8143 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
8144 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
8145 | current_funcdef_number); | |
a3f97cbb JW |
8146 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
8147 | ||
d291dd49 JM |
8148 | add_pubname (decl, subr_die); |
8149 | add_arange (decl, subr_die); | |
8150 | ||
a3f97cbb | 8151 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
8152 | /* Add a reference to the FDE for this routine. */ |
8153 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
8154 | #endif | |
8155 | ||
810429b7 JM |
8156 | /* Define the "frame base" location for this routine. We use the |
8157 | frame pointer or stack pointer registers, since the RTL for local | |
8158 | variables is relative to one of them. */ | |
b1ccbc24 RK |
8159 | fp_reg |
8160 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
8161 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 8162 | |
ef76d03b JW |
8163 | #if 0 |
8164 | /* ??? This fails for nested inline functions, because context_display | |
8165 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 8166 | if (current_function_needs_context) |
ef76d03b JW |
8167 | add_AT_location_description (subr_die, DW_AT_static_link, |
8168 | lookup_static_chain (decl)); | |
8169 | #endif | |
a3f97cbb JW |
8170 | } |
8171 | ||
8172 | /* Now output descriptions of the arguments for this function. This gets | |
8173 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list | |
8174 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing | |
8175 | `...' at the end of the formal parameter list. In order to find out if | |
8176 | there was a trailing ellipsis or not, we must instead look at the type | |
8177 | associated with the FUNCTION_DECL. This will be a node of type | |
8178 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
8179 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be | |
8180 | an ellipsis at the end. */ | |
ab72d377 | 8181 | push_decl_scope (decl); |
71dfc51f | 8182 | |
a3f97cbb JW |
8183 | /* In the case where we are describing a mere function declaration, all we |
8184 | need to do here (and all we *can* do here) is to describe the *types* of | |
8185 | its formal parameters. */ | |
4927276d | 8186 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 8187 | ; |
4edb7b60 JM |
8188 | else if (declaration) |
8189 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
a3f97cbb JW |
8190 | else |
8191 | { | |
8192 | /* Generate DIEs to represent all known formal parameters */ | |
8193 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
8194 | register tree parm; | |
8195 | ||
8196 | /* When generating DIEs, generate the unspecified_parameters DIE | |
8197 | instead if we come across the arg "__builtin_va_alist" */ | |
8198 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
8199 | if (TREE_CODE (parm) == PARM_DECL) |
8200 | { | |
db3cf6fb MS |
8201 | if (DECL_NAME (parm) |
8202 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
8203 | "__builtin_va_alist")) | |
71dfc51f RK |
8204 | gen_unspecified_parameters_die (parm, subr_die); |
8205 | else | |
8206 | gen_decl_die (parm, subr_die); | |
8207 | } | |
a3f97cbb JW |
8208 | |
8209 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
8210 | There are 2 more cases to do this for: 1) the ansi ... declaration - | |
8211 | this is detectable when the end of the arg list is not a | |
8212 | void_type_node 2) an unprototyped function declaration (not a | |
8213 | definition). This just means that we have no info about the | |
8214 | parameters at all. */ | |
8215 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 8216 | if (fn_arg_types != NULL) |
a3f97cbb JW |
8217 | { |
8218 | /* this is the prototyped case, check for ... */ | |
8219 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 8220 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 8221 | } |
71dfc51f RK |
8222 | else if (DECL_INITIAL (decl) == NULL_TREE) |
8223 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
8224 | } |
8225 | ||
8226 | /* Output Dwarf info for all of the stuff within the body of the function | |
8227 | (if it has one - it may be just a declaration). */ | |
8228 | outer_scope = DECL_INITIAL (decl); | |
8229 | ||
d7248bff JM |
8230 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
8231 | node created to represent a function. This outermost BLOCK actually | |
8232 | represents the outermost binding contour for the function, i.e. the | |
8233 | contour in which the function's formal parameters and labels get | |
8234 | declared. Curiously, it appears that the front end doesn't actually | |
8235 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
8236 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
8237 | list for the function instead.) The BLOCK_VARS list for the | |
8238 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
8239 | the function however, and we output DWARF info for those in | |
8240 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
8241 | node representing the function's outermost pair of curly braces, and | |
8242 | any blocks used for the base and member initializers of a C++ | |
8243 | constructor function. */ | |
4edb7b60 | 8244 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
8245 | { |
8246 | current_function_has_inlines = 0; | |
8247 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 8248 | |
ce61cc73 | 8249 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
8250 | if (current_function_has_inlines) |
8251 | { | |
8252 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
8253 | if (! comp_unit_has_inlines) | |
8254 | { | |
8255 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
8256 | comp_unit_has_inlines = 1; | |
8257 | } | |
8258 | } | |
8259 | #endif | |
8260 | } | |
71dfc51f | 8261 | |
ab72d377 | 8262 | pop_decl_scope (); |
a3f97cbb JW |
8263 | } |
8264 | ||
8265 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 8266 | |
a3f97cbb JW |
8267 | static void |
8268 | gen_variable_die (decl, context_die) | |
8269 | register tree decl; | |
8270 | register dw_die_ref context_die; | |
8271 | { | |
8272 | register tree origin = decl_ultimate_origin (decl); | |
8273 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 8274 | |
bdb669cb | 8275 | dw_die_ref old_die = lookup_decl_die (decl); |
4edb7b60 JM |
8276 | int declaration |
8277 | = (DECL_EXTERNAL (decl) | |
a94dbf2c JM |
8278 | || current_function_decl != decl_function_context (decl) |
8279 | || context_die->die_tag == DW_TAG_structure_type | |
8280 | || context_die->die_tag == DW_TAG_union_type); | |
4edb7b60 | 8281 | |
a3f97cbb | 8282 | if (origin != NULL) |
71dfc51f | 8283 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
8284 | /* Loop unrolling can create multiple blocks that refer to the same |
8285 | static variable, so we must test for the DW_AT_declaration flag. */ | |
8286 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
8287 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
8288 | sharing them. */ | |
8289 | else if (old_die && TREE_STATIC (decl) | |
8290 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 8291 | { |
f76b8156 | 8292 | /* ??? This is an instantiation of a C++ class level static. */ |
bdb669cb JM |
8293 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
8294 | if (DECL_NAME (decl)) | |
8295 | { | |
8296 | register unsigned file_index | |
8297 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 8298 | |
bdb669cb JM |
8299 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8300 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 8301 | |
bdb669cb JM |
8302 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
8303 | != DECL_SOURCE_LINE (decl)) | |
71dfc51f RK |
8304 | |
8305 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
8306 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
8307 | } |
8308 | } | |
a3f97cbb JW |
8309 | else |
8310 | { | |
8311 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
8312 | add_type_attribute (var_die, TREE_TYPE (decl), |
8313 | TREE_READONLY (decl), | |
8314 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 8315 | |
273dbe67 JM |
8316 | if (TREE_PUBLIC (decl)) |
8317 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 8318 | |
273dbe67 JM |
8319 | if (DECL_ARTIFICIAL (decl)) |
8320 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 8321 | |
a94dbf2c JM |
8322 | if (TREE_PROTECTED (decl)) |
8323 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8324 | |
a94dbf2c JM |
8325 | else if (TREE_PRIVATE (decl)) |
8326 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8327 | } |
4edb7b60 JM |
8328 | |
8329 | if (declaration) | |
8330 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
8331 | ||
8332 | if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl)) | |
8333 | equate_decl_number_to_die (decl, var_die); | |
8334 | ||
8335 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb | 8336 | { |
141719a8 | 8337 | equate_decl_number_to_die (decl, var_die); |
a3f97cbb | 8338 | add_location_or_const_value_attribute (var_die, decl); |
d291dd49 | 8339 | add_pubname (decl, var_die); |
a3f97cbb JW |
8340 | } |
8341 | } | |
8342 | ||
8343 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 8344 | |
a3f97cbb JW |
8345 | static void |
8346 | gen_label_die (decl, context_die) | |
8347 | register tree decl; | |
8348 | register dw_die_ref context_die; | |
8349 | { | |
8350 | register tree origin = decl_ultimate_origin (decl); | |
8351 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
8352 | register rtx insn; | |
8353 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5c90448c | 8354 | char label2[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8355 | |
a3f97cbb | 8356 | if (origin != NULL) |
71dfc51f | 8357 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 8358 | else |
71dfc51f RK |
8359 | add_name_and_src_coords_attributes (lbl_die, decl); |
8360 | ||
a3f97cbb | 8361 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 8362 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
8363 | else |
8364 | { | |
8365 | insn = DECL_RTL (decl); | |
8366 | if (GET_CODE (insn) == CODE_LABEL) | |
8367 | { | |
8368 | /* When optimization is enabled (via -O) some parts of the compiler | |
8369 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
8370 | represent source-level labels which were explicitly declared by | |
8371 | the user. This really shouldn't be happening though, so catch | |
8372 | it if it ever does happen. */ | |
8373 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
8374 | abort (); |
8375 | ||
5c90448c JM |
8376 | sprintf (label2, INSN_LABEL_FMT, current_funcdef_number); |
8377 | ASM_GENERATE_INTERNAL_LABEL (label, label2, | |
8378 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
8379 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
8380 | } | |
8381 | } | |
8382 | } | |
8383 | ||
8384 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 8385 | |
a3f97cbb | 8386 | static void |
d7248bff | 8387 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
8388 | register tree stmt; |
8389 | register dw_die_ref context_die; | |
d7248bff | 8390 | int depth; |
a3f97cbb JW |
8391 | { |
8392 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
8393 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
8394 | |
8395 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 8396 | { |
5c90448c JM |
8397 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
8398 | next_block_number); | |
a3f97cbb | 8399 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
5c90448c | 8400 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb JW |
8401 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
8402 | } | |
71dfc51f | 8403 | |
7d4440be | 8404 | push_decl_scope (stmt); |
d7248bff | 8405 | decls_for_scope (stmt, stmt_die, depth); |
7d4440be | 8406 | pop_decl_scope (); |
a3f97cbb JW |
8407 | } |
8408 | ||
8409 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 8410 | |
a3f97cbb | 8411 | static void |
d7248bff | 8412 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
8413 | register tree stmt; |
8414 | register dw_die_ref context_die; | |
d7248bff | 8415 | int depth; |
a3f97cbb | 8416 | { |
71dfc51f | 8417 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 8418 | { |
71dfc51f RK |
8419 | register dw_die_ref subr_die |
8420 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 8421 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 8422 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8423 | |
ab72d377 | 8424 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c JM |
8425 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
8426 | next_block_number); | |
a3f97cbb | 8427 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
5c90448c | 8428 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb | 8429 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
ab72d377 | 8430 | push_decl_scope (decl); |
d7248bff | 8431 | decls_for_scope (stmt, subr_die, depth); |
ab72d377 | 8432 | pop_decl_scope (); |
7e23cb16 | 8433 | current_function_has_inlines = 1; |
a3f97cbb | 8434 | } |
a3f97cbb JW |
8435 | } |
8436 | ||
8437 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 8438 | |
a3f97cbb JW |
8439 | static void |
8440 | gen_field_die (decl, context_die) | |
8441 | register tree decl; | |
8442 | register dw_die_ref context_die; | |
8443 | { | |
8444 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 8445 | |
a3f97cbb | 8446 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
8447 | add_type_attribute (decl_die, member_declared_type (decl), |
8448 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
8449 | context_die); | |
71dfc51f | 8450 | |
a3f97cbb JW |
8451 | /* If this is a bit field... */ |
8452 | if (DECL_BIT_FIELD_TYPE (decl)) | |
8453 | { | |
8454 | add_byte_size_attribute (decl_die, decl); | |
8455 | add_bit_size_attribute (decl_die, decl); | |
8456 | add_bit_offset_attribute (decl_die, decl); | |
8457 | } | |
71dfc51f | 8458 | |
a94dbf2c JM |
8459 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
8460 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 8461 | |
273dbe67 JM |
8462 | if (DECL_ARTIFICIAL (decl)) |
8463 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 8464 | |
a94dbf2c JM |
8465 | if (TREE_PROTECTED (decl)) |
8466 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8467 | |
a94dbf2c JM |
8468 | else if (TREE_PRIVATE (decl)) |
8469 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
8470 | } |
8471 | ||
ab72d377 JM |
8472 | #if 0 |
8473 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
8474 | Use modified_type_die instead. | |
a3f97cbb JW |
8475 | We keep this code here just in case these types of DIEs may be needed to |
8476 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8477 | static void | |
8478 | gen_pointer_type_die (type, context_die) | |
8479 | register tree type; | |
8480 | register dw_die_ref context_die; | |
8481 | { | |
71dfc51f RK |
8482 | register dw_die_ref ptr_die |
8483 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
8484 | ||
a3f97cbb | 8485 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8486 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8487 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
8488 | } |
8489 | ||
ab72d377 JM |
8490 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
8491 | Use modified_type_die instead. | |
a3f97cbb JW |
8492 | We keep this code here just in case these types of DIEs may be needed to |
8493 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8494 | static void | |
8495 | gen_reference_type_die (type, context_die) | |
8496 | register tree type; | |
8497 | register dw_die_ref context_die; | |
8498 | { | |
71dfc51f RK |
8499 | register dw_die_ref ref_die |
8500 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
8501 | ||
a3f97cbb | 8502 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 8503 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8504 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 8505 | } |
ab72d377 | 8506 | #endif |
a3f97cbb JW |
8507 | |
8508 | /* Generate a DIE for a pointer to a member type. */ | |
8509 | static void | |
8510 | gen_ptr_to_mbr_type_die (type, context_die) | |
8511 | register tree type; | |
8512 | register dw_die_ref context_die; | |
8513 | { | |
71dfc51f RK |
8514 | register dw_die_ref ptr_die |
8515 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
8516 | ||
a3f97cbb | 8517 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8518 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 8519 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
8520 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
8521 | } | |
8522 | ||
8523 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 8524 | |
a3f97cbb JW |
8525 | static void |
8526 | gen_compile_unit_die (main_input_filename) | |
8527 | register char *main_input_filename; | |
8528 | { | |
8529 | char producer[250]; | |
a3f97cbb JW |
8530 | char *wd = getpwd (); |
8531 | ||
8532 | comp_unit_die = new_die (DW_TAG_compile_unit, NULL); | |
bdb669cb JM |
8533 | add_name_attribute (comp_unit_die, main_input_filename); |
8534 | ||
71dfc51f RK |
8535 | if (wd != NULL) |
8536 | add_AT_string (comp_unit_die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
8537 | |
8538 | sprintf (producer, "%s %s", language_string, version_string); | |
8539 | ||
8540 | #ifdef MIPS_DEBUGGING_INFO | |
8541 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
8542 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
8543 | not appear in the producer string, the debugger reaches the conclusion | |
8544 | that the object file is stripped and has no debugging information. | |
8545 | To get the MIPS/SGI debugger to believe that there is debugging | |
8546 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
8547 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8548 | strcat (producer, " -g"); | |
a3f97cbb JW |
8549 | #endif |
8550 | ||
8551 | add_AT_string (comp_unit_die, DW_AT_producer, producer); | |
a9d38797 | 8552 | |
a3f97cbb | 8553 | if (strcmp (language_string, "GNU C++") == 0) |
a9d38797 | 8554 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus); |
71dfc51f | 8555 | |
a3f97cbb | 8556 | else if (strcmp (language_string, "GNU Ada") == 0) |
a9d38797 | 8557 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83); |
71dfc51f | 8558 | |
a9d38797 JM |
8559 | else if (strcmp (language_string, "GNU F77") == 0) |
8560 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77); | |
71dfc51f | 8561 | |
bc28c45b RK |
8562 | else if (strcmp (language_string, "GNU Pascal") == 0) |
8563 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83); | |
8564 | ||
a3f97cbb | 8565 | else if (flag_traditional) |
a9d38797 | 8566 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C); |
71dfc51f | 8567 | |
a3f97cbb | 8568 | else |
a9d38797 JM |
8569 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89); |
8570 | ||
8571 | #if 0 /* unimplemented */ | |
e90b62db | 8572 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
a9d38797 JM |
8573 | add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0); |
8574 | #endif | |
a3f97cbb JW |
8575 | } |
8576 | ||
8577 | /* Generate a DIE for a string type. */ | |
71dfc51f | 8578 | |
a3f97cbb JW |
8579 | static void |
8580 | gen_string_type_die (type, context_die) | |
8581 | register tree type; | |
8582 | register dw_die_ref context_die; | |
8583 | { | |
71dfc51f RK |
8584 | register dw_die_ref type_die |
8585 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
8586 | ||
bdb669cb | 8587 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
8588 | |
8589 | /* Fudge the string length attribute for now. */ | |
71dfc51f | 8590 | |
a3f97cbb | 8591 | /* TODO: add string length info. |
71dfc51f | 8592 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
8593 | bound_representation (upper_bound, 0, 'u'); */ |
8594 | } | |
8595 | ||
61b32c02 | 8596 | /* Generate the DIE for a base class. */ |
71dfc51f | 8597 | |
61b32c02 JM |
8598 | static void |
8599 | gen_inheritance_die (binfo, context_die) | |
8600 | register tree binfo; | |
8601 | register dw_die_ref context_die; | |
8602 | { | |
8603 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 8604 | |
61b32c02 JM |
8605 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
8606 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 8607 | |
61b32c02 JM |
8608 | if (TREE_VIA_VIRTUAL (binfo)) |
8609 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
8610 | if (TREE_VIA_PUBLIC (binfo)) | |
8611 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
8612 | else if (TREE_VIA_PROTECTED (binfo)) | |
8613 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
8614 | } | |
8615 | ||
956d6950 | 8616 | /* Generate a DIE for a class member. */ |
71dfc51f | 8617 | |
a3f97cbb JW |
8618 | static void |
8619 | gen_member_die (type, context_die) | |
8620 | register tree type; | |
8621 | register dw_die_ref context_die; | |
8622 | { | |
61b32c02 | 8623 | register tree member; |
71dfc51f | 8624 | |
a3f97cbb JW |
8625 | /* If this is not an incomplete type, output descriptions of each of its |
8626 | members. Note that as we output the DIEs necessary to represent the | |
8627 | members of this record or union type, we will also be trying to output | |
8628 | DIEs to represent the *types* of those members. However the `type' | |
8629 | function (above) will specifically avoid generating type DIEs for member | |
8630 | types *within* the list of member DIEs for this (containing) type execpt | |
8631 | for those types (of members) which are explicitly marked as also being | |
8632 | members of this (containing) type themselves. The g++ front- end can | |
8633 | force any given type to be treated as a member of some other | |
8634 | (containing) type by setting the TYPE_CONTEXT of the given (member) type | |
8635 | to point to the TREE node representing the appropriate (containing) | |
8636 | type. */ | |
8637 | ||
61b32c02 JM |
8638 | /* First output info about the base classes. */ |
8639 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 8640 | { |
61b32c02 JM |
8641 | register tree bases = TYPE_BINFO_BASETYPES (type); |
8642 | register int n_bases = TREE_VEC_LENGTH (bases); | |
8643 | register int i; | |
8644 | ||
8645 | for (i = 0; i < n_bases; i++) | |
8646 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
8647 | } |
8648 | ||
61b32c02 JM |
8649 | /* Now output info about the data members and type members. */ |
8650 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
8651 | gen_decl_die (member, context_die); | |
8652 | ||
a3f97cbb | 8653 | /* Now output info about the function members (if any). */ |
61b32c02 JM |
8654 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
8655 | gen_decl_die (member, context_die); | |
a3f97cbb JW |
8656 | } |
8657 | ||
8658 | /* Generate a DIE for a structure or union type. */ | |
71dfc51f | 8659 | |
a3f97cbb | 8660 | static void |
273dbe67 | 8661 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 8662 | register tree type; |
a3f97cbb JW |
8663 | register dw_die_ref context_die; |
8664 | { | |
273dbe67 | 8665 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
8666 | register dw_die_ref scope_die = 0; |
8667 | register int nested = 0; | |
273dbe67 JM |
8668 | |
8669 | if (type_die && ! TYPE_SIZE (type)) | |
8670 | return; | |
a082c85a | 8671 | |
71dfc51f | 8672 | if (TYPE_CONTEXT (type) != NULL_TREE |
a082c85a JM |
8673 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't') |
8674 | nested = 1; | |
8675 | ||
a94dbf2c | 8676 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
8677 | |
8678 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 8679 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 8680 | { |
273dbe67 | 8681 | register dw_die_ref old_die = type_die; |
71dfc51f | 8682 | |
a3f97cbb JW |
8683 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
8684 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 8685 | scope_die); |
a3f97cbb JW |
8686 | equate_type_number_to_die (type, type_die); |
8687 | add_name_attribute (type_die, type_tag (type)); | |
273dbe67 JM |
8688 | if (old_die) |
8689 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
a3f97cbb | 8690 | } |
4b674448 | 8691 | else |
273dbe67 | 8692 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb | 8693 | |
a94dbf2c JM |
8694 | /* If we're not in the right context to be defining this type, defer to |
8695 | avoid tricky recursion. */ | |
8696 | if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die) | |
8697 | { | |
8698 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
8699 | pend_type (type); | |
8700 | } | |
a3f97cbb JW |
8701 | /* If this type has been completed, then give it a byte_size attribute and |
8702 | then give a list of members. */ | |
a94dbf2c | 8703 | else if (TYPE_SIZE (type)) |
a3f97cbb JW |
8704 | { |
8705 | /* Prevent infinite recursion in cases where the type of some member of | |
8706 | this type is expressed in terms of this type itself. */ | |
8707 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 8708 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 8709 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 8710 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 8711 | |
ef76d03b JW |
8712 | /* If the first reference to this type was as the return type of an |
8713 | inline function, then it may not have a parent. Fix this now. */ | |
8714 | if (type_die->die_parent == NULL) | |
8715 | add_child_die (scope_die, type_die); | |
8716 | ||
273dbe67 JM |
8717 | push_decl_scope (type); |
8718 | gen_member_die (type, type_die); | |
8719 | pop_decl_scope (); | |
71dfc51f | 8720 | |
a94dbf2c JM |
8721 | /* GNU extension: Record what type our vtable lives in. */ |
8722 | if (TYPE_VFIELD (type)) | |
8723 | { | |
8724 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 8725 | |
a94dbf2c JM |
8726 | gen_type_die (vtype, context_die); |
8727 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
8728 | lookup_type_die (vtype)); | |
8729 | } | |
a3f97cbb | 8730 | } |
4b674448 JM |
8731 | else |
8732 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
8733 | } |
8734 | ||
8735 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 8736 | |
a3f97cbb JW |
8737 | static void |
8738 | gen_subroutine_type_die (type, context_die) | |
8739 | register tree type; | |
8740 | register dw_die_ref context_die; | |
8741 | { | |
8742 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
8743 | register dw_die_ref subr_die |
8744 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
8745 | ||
a3f97cbb JW |
8746 | equate_type_number_to_die (type, subr_die); |
8747 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 8748 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 8749 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
8750 | } |
8751 | ||
8752 | /* Generate a DIE for a type definition */ | |
71dfc51f | 8753 | |
a3f97cbb JW |
8754 | static void |
8755 | gen_typedef_die (decl, context_die) | |
8756 | register tree decl; | |
8757 | register dw_die_ref context_die; | |
8758 | { | |
a3f97cbb | 8759 | register dw_die_ref type_die; |
a94dbf2c JM |
8760 | register tree origin; |
8761 | ||
8762 | if (TREE_ASM_WRITTEN (decl)) | |
8763 | return; | |
8764 | TREE_ASM_WRITTEN (decl) = 1; | |
8765 | ||
ab72d377 | 8766 | type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die)); |
a94dbf2c | 8767 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 8768 | if (origin != NULL) |
a94dbf2c | 8769 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
8770 | else |
8771 | { | |
a94dbf2c | 8772 | register tree type; |
a3f97cbb | 8773 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
8774 | if (DECL_ORIGINAL_TYPE (decl)) |
8775 | { | |
8776 | type = DECL_ORIGINAL_TYPE (decl); | |
8777 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
8778 | } | |
8779 | else | |
8780 | type = TREE_TYPE (decl); | |
8781 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
8782 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 8783 | } |
71dfc51f | 8784 | |
a3f97cbb | 8785 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 8786 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
8787 | } |
8788 | ||
8789 | /* Generate a type description DIE. */ | |
71dfc51f | 8790 | |
a3f97cbb JW |
8791 | static void |
8792 | gen_type_die (type, context_die) | |
8793 | register tree type; | |
8794 | register dw_die_ref context_die; | |
8795 | { | |
71dfc51f RK |
8796 | if (type == NULL_TREE || type == error_mark_node) |
8797 | return; | |
a3f97cbb JW |
8798 | |
8799 | /* We are going to output a DIE to represent the unqualified version of of | |
8800 | this type (i.e. without any const or volatile qualifiers) so get the | |
8801 | main variant (i.e. the unqualified version) of this type now. */ | |
8802 | type = type_main_variant (type); | |
8803 | ||
8804 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 8805 | return; |
a3f97cbb | 8806 | |
a94dbf2c JM |
8807 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
8808 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
8809 | { | |
8810 | TREE_ASM_WRITTEN (type) = 1; | |
8811 | gen_decl_die (TYPE_NAME (type), context_die); | |
8812 | return; | |
8813 | } | |
8814 | ||
a3f97cbb JW |
8815 | switch (TREE_CODE (type)) |
8816 | { | |
8817 | case ERROR_MARK: | |
8818 | break; | |
8819 | ||
8820 | case POINTER_TYPE: | |
8821 | case REFERENCE_TYPE: | |
956d6950 JL |
8822 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
8823 | ensures that the gen_type_die recursion will terminate even if the | |
8824 | type is recursive. Recursive types are possible in Ada. */ | |
8825 | /* ??? We could perhaps do this for all types before the switch | |
8826 | statement. */ | |
8827 | TREE_ASM_WRITTEN (type) = 1; | |
8828 | ||
a3f97cbb JW |
8829 | /* For these types, all that is required is that we output a DIE (or a |
8830 | set of DIEs) to represent the "basis" type. */ | |
8831 | gen_type_die (TREE_TYPE (type), context_die); | |
8832 | break; | |
8833 | ||
8834 | case OFFSET_TYPE: | |
71dfc51f RK |
8835 | /* This code is used for C++ pointer-to-data-member types. |
8836 | Output a description of the relevant class type. */ | |
a3f97cbb | 8837 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 8838 | |
a3f97cbb JW |
8839 | /* Output a description of the type of the object pointed to. */ |
8840 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 8841 | |
a3f97cbb JW |
8842 | /* Now output a DIE to represent this pointer-to-data-member type |
8843 | itself. */ | |
8844 | gen_ptr_to_mbr_type_die (type, context_die); | |
8845 | break; | |
8846 | ||
8847 | case SET_TYPE: | |
8848 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
8849 | gen_set_type_die (type, context_die); | |
8850 | break; | |
8851 | ||
8852 | case FILE_TYPE: | |
8853 | gen_type_die (TREE_TYPE (type), context_die); | |
8854 | abort (); /* No way to represent these in Dwarf yet! */ | |
8855 | break; | |
8856 | ||
8857 | case FUNCTION_TYPE: | |
8858 | /* Force out return type (in case it wasn't forced out already). */ | |
8859 | gen_type_die (TREE_TYPE (type), context_die); | |
8860 | gen_subroutine_type_die (type, context_die); | |
8861 | break; | |
8862 | ||
8863 | case METHOD_TYPE: | |
8864 | /* Force out return type (in case it wasn't forced out already). */ | |
8865 | gen_type_die (TREE_TYPE (type), context_die); | |
8866 | gen_subroutine_type_die (type, context_die); | |
8867 | break; | |
8868 | ||
8869 | case ARRAY_TYPE: | |
8870 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
8871 | { | |
8872 | gen_type_die (TREE_TYPE (type), context_die); | |
8873 | gen_string_type_die (type, context_die); | |
8874 | } | |
8875 | else | |
71dfc51f | 8876 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
8877 | break; |
8878 | ||
8879 | case ENUMERAL_TYPE: | |
8880 | case RECORD_TYPE: | |
8881 | case UNION_TYPE: | |
8882 | case QUAL_UNION_TYPE: | |
a082c85a JM |
8883 | /* If this is a nested type whose containing class hasn't been |
8884 | written out yet, writing it out will cover this one, too. */ | |
8885 | if (TYPE_CONTEXT (type) | |
8886 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't' | |
8887 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
a94dbf2c JM |
8888 | { |
8889 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
8890 | ||
8891 | if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
8892 | return; | |
8893 | ||
8894 | /* If that failed, attach ourselves to the stub. */ | |
8895 | push_decl_scope (TYPE_CONTEXT (type)); | |
8896 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
8897 | } | |
8898 | ||
8899 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 8900 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 8901 | else |
273dbe67 | 8902 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 8903 | |
a94dbf2c JM |
8904 | if (TYPE_CONTEXT (type) |
8905 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't' | |
8906 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
8907 | pop_decl_scope (); | |
8908 | ||
4b674448 | 8909 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
8910 | it up if it is ever completed. gen_*_type_die will set it for us |
8911 | when appropriate. */ | |
8912 | return; | |
a3f97cbb JW |
8913 | |
8914 | case VOID_TYPE: | |
8915 | case INTEGER_TYPE: | |
8916 | case REAL_TYPE: | |
8917 | case COMPLEX_TYPE: | |
8918 | case BOOLEAN_TYPE: | |
8919 | case CHAR_TYPE: | |
8920 | /* No DIEs needed for fundamental types. */ | |
8921 | break; | |
8922 | ||
8923 | case LANG_TYPE: | |
8924 | /* No Dwarf representation currently defined. */ | |
8925 | break; | |
8926 | ||
8927 | default: | |
8928 | abort (); | |
8929 | } | |
8930 | ||
8931 | TREE_ASM_WRITTEN (type) = 1; | |
8932 | } | |
8933 | ||
8934 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 8935 | |
a3f97cbb JW |
8936 | static void |
8937 | gen_tagged_type_instantiation_die (type, context_die) | |
8938 | register tree type; | |
8939 | register dw_die_ref context_die; | |
8940 | { | |
71dfc51f RK |
8941 | if (type == NULL_TREE || type == error_mark_node) |
8942 | return; | |
a3f97cbb JW |
8943 | |
8944 | /* We are going to output a DIE to represent the unqualified version of of | |
8945 | this type (i.e. without any const or volatile qualifiers) so make sure | |
8946 | that we have the main variant (i.e. the unqualified version) of this | |
8947 | type now. */ | |
3a88cbd1 JL |
8948 | if (type != type_main_variant (type) |
8949 | || !TREE_ASM_WRITTEN (type)) | |
8950 | abort (); | |
a3f97cbb JW |
8951 | |
8952 | switch (TREE_CODE (type)) | |
8953 | { | |
8954 | case ERROR_MARK: | |
8955 | break; | |
8956 | ||
8957 | case ENUMERAL_TYPE: | |
8958 | gen_inlined_enumeration_type_die (type, context_die); | |
8959 | break; | |
8960 | ||
8961 | case RECORD_TYPE: | |
8962 | gen_inlined_structure_type_die (type, context_die); | |
8963 | break; | |
8964 | ||
8965 | case UNION_TYPE: | |
8966 | case QUAL_UNION_TYPE: | |
8967 | gen_inlined_union_type_die (type, context_die); | |
8968 | break; | |
8969 | ||
8970 | default: | |
71dfc51f | 8971 | abort (); |
a3f97cbb JW |
8972 | } |
8973 | } | |
8974 | ||
8975 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
8976 | things which are local to the given block. */ | |
71dfc51f | 8977 | |
a3f97cbb | 8978 | static void |
d7248bff | 8979 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
8980 | register tree stmt; |
8981 | register dw_die_ref context_die; | |
d7248bff | 8982 | int depth; |
a3f97cbb JW |
8983 | { |
8984 | register int must_output_die = 0; | |
8985 | register tree origin; | |
8986 | register tree decl; | |
8987 | register enum tree_code origin_code; | |
8988 | ||
8989 | /* Ignore blocks never really used to make RTL. */ | |
8990 | ||
71dfc51f RK |
8991 | if (stmt == NULL_TREE || !TREE_USED (stmt)) |
8992 | return; | |
a3f97cbb JW |
8993 | |
8994 | /* Determine the "ultimate origin" of this block. This block may be an | |
8995 | inlined instance of an inlined instance of inline function, so we have | |
8996 | to trace all of the way back through the origin chain to find out what | |
8997 | sort of node actually served as the original seed for the creation of | |
8998 | the current block. */ | |
8999 | origin = block_ultimate_origin (stmt); | |
9000 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
9001 | ||
9002 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
9003 | block. */ | |
9004 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
9005 | /* The outer scopes for inlinings *must* always be represented. We |
9006 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
9007 | must_output_die = 1; | |
a3f97cbb JW |
9008 | else |
9009 | { | |
9010 | /* In the case where the current block represents an inlining of the | |
9011 | "body block" of an inline function, we must *NOT* output any DIE for | |
9012 | this block because we have already output a DIE to represent the | |
9013 | whole inlined function scope and the "body block" of any function | |
9014 | doesn't really represent a different scope according to ANSI C | |
9015 | rules. So we check here to make sure that this block does not | |
9016 | represent a "body block inlining" before trying to set the | |
9017 | `must_output_die' flag. */ | |
d7248bff | 9018 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
9019 | { |
9020 | /* Determine if this block directly contains any "significant" | |
9021 | local declarations which we will need to output DIEs for. */ | |
9022 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
9023 | /* We are not in terse mode so *any* local declaration counts |
9024 | as being a "significant" one. */ | |
9025 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 9026 | else |
71dfc51f RK |
9027 | /* We are in terse mode, so only local (nested) function |
9028 | definitions count as "significant" local declarations. */ | |
9029 | for (decl = BLOCK_VARS (stmt); | |
9030 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9031 | if (TREE_CODE (decl) == FUNCTION_DECL | |
9032 | && DECL_INITIAL (decl)) | |
a3f97cbb | 9033 | { |
71dfc51f RK |
9034 | must_output_die = 1; |
9035 | break; | |
a3f97cbb | 9036 | } |
a3f97cbb JW |
9037 | } |
9038 | } | |
9039 | ||
9040 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
9041 | DIE for any block which contains no significant local declarations at | |
9042 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
9043 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
9044 | that in terse mode, our definition of what constitutes a "significant" | |
9045 | local declaration gets restricted to include only inlined function | |
9046 | instances and local (nested) function definitions. */ | |
9047 | if (must_output_die) | |
9048 | { | |
9049 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 9050 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 9051 | else |
71dfc51f | 9052 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
9053 | } |
9054 | else | |
d7248bff | 9055 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
9056 | } |
9057 | ||
9058 | /* Generate all of the decls declared within a given scope and (recursively) | |
9059 | all of it's sub-blocks. */ | |
71dfc51f | 9060 | |
a3f97cbb | 9061 | static void |
d7248bff | 9062 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
9063 | register tree stmt; |
9064 | register dw_die_ref context_die; | |
d7248bff | 9065 | int depth; |
a3f97cbb JW |
9066 | { |
9067 | register tree decl; | |
9068 | register tree subblocks; | |
71dfc51f | 9069 | |
a3f97cbb | 9070 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
9071 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
9072 | return; | |
9073 | ||
d7248bff | 9074 | if (!BLOCK_ABSTRACT (stmt) && depth > 0) |
71dfc51f | 9075 | next_block_number++; |
a3f97cbb | 9076 | |
88dad228 JM |
9077 | /* Output the DIEs to represent all of the data objects and typedefs |
9078 | declared directly within this block but not within any nested | |
9079 | sub-blocks. Also, nested function and tag DIEs have been | |
9080 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
9081 | for (decl = BLOCK_VARS (stmt); |
9082 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9083 | { | |
a94dbf2c JM |
9084 | register dw_die_ref die; |
9085 | ||
88dad228 | 9086 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 9087 | die = lookup_decl_die (decl); |
88dad228 | 9088 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
9089 | die = lookup_type_die (TREE_TYPE (decl)); |
9090 | else | |
9091 | die = NULL; | |
9092 | ||
71dfc51f | 9093 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 9094 | add_child_die (context_die, die); |
88dad228 JM |
9095 | else |
9096 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
9097 | } |
9098 | ||
9099 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
9100 | therein) of this block. */ | |
9101 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
9102 | subblocks != NULL; | |
9103 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 9104 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
9105 | } |
9106 | ||
a94dbf2c | 9107 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
9108 | |
9109 | static inline int | |
a94dbf2c JM |
9110 | is_redundant_typedef (decl) |
9111 | register tree decl; | |
9112 | { | |
9113 | if (TYPE_DECL_IS_STUB (decl)) | |
9114 | return 1; | |
71dfc51f | 9115 | |
a94dbf2c JM |
9116 | if (DECL_ARTIFICIAL (decl) |
9117 | && DECL_CONTEXT (decl) | |
9118 | && is_tagged_type (DECL_CONTEXT (decl)) | |
9119 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
9120 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
9121 | /* Also ignore the artificial member typedef for the class name. */ | |
9122 | return 1; | |
71dfc51f | 9123 | |
a94dbf2c JM |
9124 | return 0; |
9125 | } | |
9126 | ||
a3f97cbb | 9127 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 9128 | |
a3f97cbb JW |
9129 | static void |
9130 | gen_decl_die (decl, context_die) | |
9131 | register tree decl; | |
9132 | register dw_die_ref context_die; | |
9133 | { | |
9134 | register tree origin; | |
71dfc51f | 9135 | |
a3f97cbb JW |
9136 | /* Make a note of the decl node we are going to be working on. We may need |
9137 | to give the user the source coordinates of where it appeared in case we | |
9138 | notice (later on) that something about it looks screwy. */ | |
9139 | dwarf_last_decl = decl; | |
9140 | ||
9141 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f | 9142 | return; |
a3f97cbb JW |
9143 | |
9144 | /* If this ..._DECL node is marked to be ignored, then ignore it. But don't | |
9145 | ignore a function definition, since that would screw up our count of | |
9146 | blocks, and that it turn will completely screw up the the labels we will | |
9147 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
9148 | subsequent blocks). */ | |
9149 | if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL) | |
71dfc51f | 9150 | return; |
a3f97cbb | 9151 | |
a3f97cbb JW |
9152 | switch (TREE_CODE (decl)) |
9153 | { | |
9154 | case CONST_DECL: | |
9155 | /* The individual enumerators of an enum type get output when we output | |
9156 | the Dwarf representation of the relevant enum type itself. */ | |
9157 | break; | |
9158 | ||
9159 | case FUNCTION_DECL: | |
4edb7b60 JM |
9160 | /* Don't output any DIEs to represent mere function declarations, |
9161 | unless they are class members or explicit block externs. */ | |
9162 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
9163 | && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl))) | |
71dfc51f | 9164 | break; |
bdb669cb | 9165 | |
4927276d | 9166 | if (debug_info_level > DINFO_LEVEL_TERSE) |
a94dbf2c JM |
9167 | { |
9168 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
9169 | have described its return type. */ | |
9170 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
9171 | ||
9172 | /* And its containing type. */ | |
9173 | origin = decl_class_context (decl); | |
71dfc51f | 9174 | if (origin != NULL_TREE) |
a94dbf2c JM |
9175 | gen_type_die (origin, context_die); |
9176 | ||
9177 | /* And its virtual context. */ | |
71dfc51f | 9178 | if (DECL_VINDEX (decl) != NULL_TREE) |
a94dbf2c JM |
9179 | gen_type_die (DECL_CONTEXT (decl), context_die); |
9180 | } | |
a3f97cbb JW |
9181 | |
9182 | /* Now output a DIE to represent the function itself. */ | |
9183 | gen_subprogram_die (decl, context_die); | |
9184 | break; | |
9185 | ||
9186 | case TYPE_DECL: | |
9187 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 9188 | actual typedefs. */ |
a3f97cbb | 9189 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9190 | break; |
a3f97cbb | 9191 | |
5c90448c JM |
9192 | /* In the special case of a TYPE_DECL node representing the |
9193 | declaration of some type tag, if the given TYPE_DECL is marked as | |
a3f97cbb JW |
9194 | having been instantiated from some other (original) TYPE_DECL node |
9195 | (e.g. one which was generated within the original definition of an | |
9196 | inline function) we have to generate a special (abbreviated) | |
ef76d03b | 9197 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 9198 | DIE here. */ |
71dfc51f | 9199 | if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) |
a3f97cbb JW |
9200 | { |
9201 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
9202 | break; | |
9203 | } | |
a3f97cbb | 9204 | |
a94dbf2c JM |
9205 | if (is_redundant_typedef (decl)) |
9206 | gen_type_die (TREE_TYPE (decl), context_die); | |
9207 | else | |
71dfc51f RK |
9208 | /* Output a DIE to represent the typedef itself. */ |
9209 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
9210 | break; |
9211 | ||
9212 | case LABEL_DECL: | |
9213 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 9214 | gen_label_die (decl, context_die); |
a3f97cbb JW |
9215 | break; |
9216 | ||
9217 | case VAR_DECL: | |
9218 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9219 | variable declarations or definitions. */ | |
9220 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9221 | break; |
a3f97cbb JW |
9222 | |
9223 | /* Output any DIEs that are needed to specify the type of this data | |
9224 | object. */ | |
9225 | gen_type_die (TREE_TYPE (decl), context_die); | |
9226 | ||
a94dbf2c JM |
9227 | /* And its containing type. */ |
9228 | origin = decl_class_context (decl); | |
71dfc51f | 9229 | if (origin != NULL_TREE) |
a94dbf2c JM |
9230 | gen_type_die (origin, context_die); |
9231 | ||
a3f97cbb JW |
9232 | /* Now output the DIE to represent the data object itself. This gets |
9233 | complicated because of the possibility that the VAR_DECL really | |
9234 | represents an inlined instance of a formal parameter for an inline | |
9235 | function. */ | |
9236 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
9237 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
9238 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 9239 | else |
71dfc51f | 9240 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
9241 | break; |
9242 | ||
9243 | case FIELD_DECL: | |
a94dbf2c JM |
9244 | /* Ignore the nameless fields that are used to skip bits, but |
9245 | handle C++ anonymous unions. */ | |
71dfc51f RK |
9246 | if (DECL_NAME (decl) != NULL_TREE |
9247 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
9248 | { |
9249 | gen_type_die (member_declared_type (decl), context_die); | |
9250 | gen_field_die (decl, context_die); | |
9251 | } | |
9252 | break; | |
9253 | ||
9254 | case PARM_DECL: | |
9255 | gen_type_die (TREE_TYPE (decl), context_die); | |
9256 | gen_formal_parameter_die (decl, context_die); | |
9257 | break; | |
9258 | ||
9259 | default: | |
9260 | abort (); | |
9261 | } | |
a3f97cbb JW |
9262 | } |
9263 | \f | |
71dfc51f RK |
9264 | /* Write the debugging output for DECL. */ |
9265 | ||
a3f97cbb | 9266 | void |
88dad228 | 9267 | dwarf2out_decl (decl) |
a3f97cbb | 9268 | register tree decl; |
a3f97cbb | 9269 | { |
88dad228 JM |
9270 | register dw_die_ref context_die = comp_unit_die; |
9271 | ||
a3f97cbb | 9272 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 9273 | return; |
a3f97cbb JW |
9274 | |
9275 | /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta | |
9276 | hope that the node in question doesn't represent a function definition. | |
9277 | If it does, then totally ignoring it is bound to screw up our count of | |
9278 | blocks, and that it turn will completely screw up the the labels we will | |
9279 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
9280 | subsequent blocks). (It's too bad that BLOCK nodes don't carry their | |
9281 | own sequence numbers with them!) */ | |
9282 | if (DECL_IGNORED_P (decl)) | |
9283 | { | |
9284 | if (TREE_CODE (decl) == FUNCTION_DECL | |
9285 | && DECL_INITIAL (decl) != NULL) | |
71dfc51f RK |
9286 | abort (); |
9287 | ||
a3f97cbb JW |
9288 | return; |
9289 | } | |
9290 | ||
9291 | switch (TREE_CODE (decl)) | |
9292 | { | |
9293 | case FUNCTION_DECL: | |
9294 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a | |
9295 | builtin function. Explicit programmer-supplied declarations of | |
9296 | these same functions should NOT be ignored however. */ | |
9297 | if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) | |
b1ccbc24 | 9298 | return; |
a3f97cbb JW |
9299 | |
9300 | /* What we would really like to do here is to filter out all mere | |
9301 | file-scope declarations of file-scope functions which are never | |
9302 | referenced later within this translation unit (and keep all of ones | |
956d6950 | 9303 | that *are* referenced later on) but we aren't clairvoyant, so we have |
a3f97cbb JW |
9304 | no idea which functions will be referenced in the future (i.e. later |
9305 | on within the current translation unit). So here we just ignore all | |
9306 | file-scope function declarations which are not also definitions. If | |
956d6950 | 9307 | and when the debugger needs to know something about these functions, |
a3f97cbb JW |
9308 | it wil have to hunt around and find the DWARF information associated |
9309 | with the definition of the function. Note that we can't just check | |
9310 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent | |
9311 | definitions and which ones represent mere declarations. We have to | |
9312 | check `DECL_INITIAL' instead. That's because the C front-end | |
9313 | supports some weird semantics for "extern inline" function | |
9314 | definitions. These can get inlined within the current translation | |
9315 | unit (an thus, we need to generate DWARF info for their abstract | |
9316 | instances so that the DWARF info for the concrete inlined instances | |
9317 | can have something to refer to) but the compiler never generates any | |
9318 | out-of-lines instances of such things (despite the fact that they | |
9319 | *are* definitions). The important point is that the C front-end | |
9320 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 9321 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb JW |
9322 | plays some similar games for inline function definitions appearing |
9323 | within include files which also contain | |
9324 | `#pragma interface' pragmas. */ | |
9325 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 9326 | return; |
88dad228 | 9327 | |
9c6cd30e JM |
9328 | /* If we're a nested function, initially use a parent of NULL; if we're |
9329 | a plain function, this will be fixed up in decls_for_scope. If | |
9330 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 9331 | if (decl_function_context (decl)) |
9c6cd30e | 9332 | context_die = NULL; |
88dad228 | 9333 | |
a3f97cbb JW |
9334 | break; |
9335 | ||
9336 | case VAR_DECL: | |
9337 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object | |
9338 | declaration and if the declaration was never even referenced from | |
9339 | within this entire compilation unit. We suppress these DIEs in | |
9340 | order to save space in the .debug section (by eliminating entries | |
9341 | which are probably useless). Note that we must not suppress | |
9342 | block-local extern declarations (whether used or not) because that | |
9343 | would screw-up the debugger's name lookup mechanism and cause it to | |
9344 | miss things which really ought to be in scope at a given point. */ | |
9345 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 9346 | return; |
a3f97cbb JW |
9347 | |
9348 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9349 | variable declarations or definitions. */ | |
9350 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9351 | return; |
a3f97cbb JW |
9352 | break; |
9353 | ||
9354 | case TYPE_DECL: | |
9355 | /* Don't bother trying to generate any DIEs to represent any of the | |
a9d38797 JM |
9356 | normal built-in types for the language we are compiling. */ |
9357 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
9358 | { |
9359 | /* OK, we need to generate one for `bool' so GDB knows what type | |
9360 | comparisons have. */ | |
9361 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
9362 | == DW_LANG_C_plus_plus) | |
9363 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
9364 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 9365 | |
a94dbf2c JM |
9366 | return; |
9367 | } | |
a3f97cbb | 9368 | |
88dad228 | 9369 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 9370 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9371 | return; |
88dad228 JM |
9372 | |
9373 | /* If we're a function-scope tag, initially use a parent of NULL; | |
9374 | this will be fixed up in decls_for_scope. */ | |
9375 | if (decl_function_context (decl)) | |
3f76745e | 9376 | context_die = NULL; |
88dad228 | 9377 | |
a3f97cbb JW |
9378 | break; |
9379 | ||
9380 | default: | |
9381 | return; | |
9382 | } | |
9383 | ||
88dad228 | 9384 | gen_decl_die (decl, context_die); |
a94dbf2c | 9385 | output_pending_types_for_scope (comp_unit_die); |
a3f97cbb JW |
9386 | } |
9387 | ||
9388 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
9389 | a lexical block. */ | |
71dfc51f | 9390 | |
a3f97cbb | 9391 | void |
9a666dda | 9392 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
9393 | register unsigned blocknum; |
9394 | { | |
a3f97cbb | 9395 | function_section (current_function_decl); |
5c90448c | 9396 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
9397 | } |
9398 | ||
9399 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
9400 | lexical block. */ | |
71dfc51f | 9401 | |
a3f97cbb | 9402 | void |
9a666dda | 9403 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
9404 | register unsigned blocknum; |
9405 | { | |
a3f97cbb | 9406 | function_section (current_function_decl); |
5c90448c | 9407 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
9408 | } |
9409 | ||
9410 | /* Output a marker (i.e. a label) at a point in the assembly code which | |
9411 | corresponds to a given source level label. */ | |
71dfc51f | 9412 | |
a3f97cbb | 9413 | void |
9a666dda | 9414 | dwarf2out_label (insn) |
a3f97cbb JW |
9415 | register rtx insn; |
9416 | { | |
9417 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 9418 | |
a3f97cbb JW |
9419 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9420 | { | |
9421 | function_section (current_function_decl); | |
5c90448c JM |
9422 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number); |
9423 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label, | |
9424 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
9425 | } |
9426 | } | |
9427 | ||
a3f97cbb | 9428 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 9429 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
9430 | just a unique number which is associated with only that one filename. |
9431 | We need such numbers for the sake of generating labels | |
9432 | (in the .debug_sfnames section) and references to those | |
9433 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
9434 | If the filename given as an argument is not found in our current list, | |
9435 | add it to the list and assign it the next available unique index number. | |
9436 | In order to speed up searches, we remember the index of the filename | |
9437 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 9438 | |
a3f97cbb JW |
9439 | static unsigned |
9440 | lookup_filename (file_name) | |
9441 | char *file_name; | |
9442 | { | |
9443 | static unsigned last_file_lookup_index = 0; | |
a3f97cbb JW |
9444 | register unsigned i; |
9445 | ||
9446 | /* Check to see if the file name that was searched on the previous call | |
9447 | matches this file name. If so, return the index. */ | |
9448 | if (last_file_lookup_index != 0) | |
71dfc51f RK |
9449 | if (strcmp (file_name, file_table[last_file_lookup_index]) == 0) |
9450 | return last_file_lookup_index; | |
a3f97cbb JW |
9451 | |
9452 | /* Didn't match the previous lookup, search the table */ | |
9453 | for (i = 1; i < file_table_in_use; ++i) | |
71dfc51f RK |
9454 | if (strcmp (file_name, file_table[i]) == 0) |
9455 | { | |
9456 | last_file_lookup_index = i; | |
9457 | return i; | |
9458 | } | |
a3f97cbb JW |
9459 | |
9460 | /* Prepare to add a new table entry by making sure there is enough space in | |
9461 | the table to do so. If not, expand the current table. */ | |
9462 | if (file_table_in_use == file_table_allocated) | |
9463 | { | |
9464 | file_table_allocated += FILE_TABLE_INCREMENT; | |
9465 | file_table | |
71dfc51f RK |
9466 | = (char **) xrealloc (file_table, |
9467 | file_table_allocated * sizeof (char *)); | |
a3f97cbb JW |
9468 | } |
9469 | ||
71dfc51f | 9470 | /* Add the new entry to the end of the filename table. */ |
a3f97cbb JW |
9471 | file_table[file_table_in_use] = xstrdup (file_name); |
9472 | last_file_lookup_index = file_table_in_use++; | |
71dfc51f | 9473 | |
a3f97cbb JW |
9474 | return last_file_lookup_index; |
9475 | } | |
9476 | ||
9477 | /* Output a label to mark the beginning of a source code line entry | |
9478 | and record information relating to this source line, in | |
9479 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 9480 | |
a3f97cbb | 9481 | void |
9a666dda | 9482 | dwarf2out_line (filename, line) |
a3f97cbb JW |
9483 | register char *filename; |
9484 | register unsigned line; | |
9485 | { | |
a3f97cbb JW |
9486 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9487 | { | |
9488 | function_section (current_function_decl); | |
a3f97cbb | 9489 | |
e90b62db | 9490 | if (DECL_SECTION_NAME (current_function_decl)) |
a3f97cbb | 9491 | { |
e90b62db | 9492 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
9493 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
9494 | separate_line_info_table_in_use); | |
e90b62db JM |
9495 | fputc ('\n', asm_out_file); |
9496 | ||
9497 | /* expand the line info table if necessary */ | |
9498 | if (separate_line_info_table_in_use | |
9499 | == separate_line_info_table_allocated) | |
9500 | { | |
9501 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9502 | separate_line_info_table | |
71dfc51f RK |
9503 | = (dw_separate_line_info_ref) |
9504 | xrealloc (separate_line_info_table, | |
9505 | separate_line_info_table_allocated | |
9506 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 9507 | } |
71dfc51f RK |
9508 | |
9509 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9510 | line_info |
9511 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
9512 | line_info->dw_file_num = lookup_filename (filename); | |
9513 | line_info->dw_line_num = line; | |
9514 | line_info->function = current_funcdef_number; | |
9515 | } | |
9516 | else | |
9517 | { | |
9518 | register dw_line_info_ref line_info; | |
71dfc51f | 9519 | |
5c90448c JM |
9520 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
9521 | line_info_table_in_use); | |
e90b62db JM |
9522 | fputc ('\n', asm_out_file); |
9523 | ||
71dfc51f | 9524 | /* Expand the line info table if necessary. */ |
e90b62db JM |
9525 | if (line_info_table_in_use == line_info_table_allocated) |
9526 | { | |
9527 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9528 | line_info_table | |
71dfc51f RK |
9529 | = (dw_line_info_ref) |
9530 | xrealloc (line_info_table, | |
9531 | (line_info_table_allocated | |
9532 | * sizeof (dw_line_info_entry))); | |
e90b62db | 9533 | } |
71dfc51f RK |
9534 | |
9535 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9536 | line_info = &line_info_table[line_info_table_in_use++]; |
9537 | line_info->dw_file_num = lookup_filename (filename); | |
9538 | line_info->dw_line_num = line; | |
a3f97cbb | 9539 | } |
a3f97cbb JW |
9540 | } |
9541 | } | |
9542 | ||
9543 | /* Record the beginning of a new source file, for later output | |
9544 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 9545 | |
a3f97cbb | 9546 | void |
9a666dda | 9547 | dwarf2out_start_source_file (filename) |
a3f97cbb JW |
9548 | register char *filename; |
9549 | { | |
9550 | } | |
9551 | ||
9a666dda | 9552 | /* Record the end of a source file, for later output |
a3f97cbb | 9553 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 9554 | |
a3f97cbb | 9555 | void |
9a666dda | 9556 | dwarf2out_end_source_file () |
a3f97cbb JW |
9557 | { |
9558 | } | |
9559 | ||
9560 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9561 | the tail part of the directive line, i.e. the part which is past the | |
9562 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9563 | |
a3f97cbb | 9564 | void |
9a666dda | 9565 | dwarf2out_define (lineno, buffer) |
a3f97cbb JW |
9566 | register unsigned lineno; |
9567 | register char *buffer; | |
9568 | { | |
9569 | static int initialized = 0; | |
9570 | if (!initialized) | |
9571 | { | |
9a666dda | 9572 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
9573 | initialized = 1; |
9574 | } | |
9575 | } | |
9576 | ||
9577 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9578 | the tail part of the directive line, i.e. the part which is past the | |
9579 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9580 | |
a3f97cbb | 9581 | void |
9a666dda | 9582 | dwarf2out_undef (lineno, buffer) |
a3f97cbb JW |
9583 | register unsigned lineno; |
9584 | register char *buffer; | |
9585 | { | |
9586 | } | |
9587 | ||
9588 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 9589 | |
a3f97cbb | 9590 | void |
9a666dda | 9591 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb JW |
9592 | register FILE *asm_out_file; |
9593 | register char *main_input_filename; | |
9594 | { | |
a3f97cbb JW |
9595 | /* Remember the name of the primary input file. */ |
9596 | primary_filename = main_input_filename; | |
9597 | ||
9598 | /* Allocate the initial hunk of the file_table. */ | |
9599 | file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *)); | |
b1ccbc24 | 9600 | bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *)); |
a3f97cbb | 9601 | file_table_allocated = FILE_TABLE_INCREMENT; |
71dfc51f RK |
9602 | |
9603 | /* Skip the first entry - file numbers begin at 1. */ | |
a3f97cbb JW |
9604 | file_table_in_use = 1; |
9605 | ||
a3f97cbb JW |
9606 | /* Allocate the initial hunk of the decl_die_table. */ |
9607 | decl_die_table | |
9608 | = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9609 | bzero ((char *) decl_die_table, |
9610 | DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb JW |
9611 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
9612 | decl_die_table_in_use = 0; | |
9613 | ||
9614 | /* Allocate the initial hunk of the decl_scope_table. */ | |
9615 | decl_scope_table | |
9616 | = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
b1ccbc24 RK |
9617 | bzero ((char *) decl_scope_table, |
9618 | DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
a3f97cbb JW |
9619 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
9620 | decl_scope_depth = 0; | |
9621 | ||
9622 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
9623 | abbrev_die_table | |
9624 | = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT | |
9625 | * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9626 | bzero ((char *) abbrev_die_table, |
9627 | ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb | 9628 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 9629 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9630 | abbrev_die_table_in_use = 1; |
9631 | ||
9632 | /* Allocate the initial hunk of the line_info_table. */ | |
9633 | line_info_table | |
9634 | = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT | |
9635 | * sizeof (dw_line_info_entry)); | |
b1ccbc24 RK |
9636 | bzero ((char *) line_info_table, |
9637 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
a3f97cbb | 9638 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 9639 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9640 | line_info_table_in_use = 1; |
9641 | ||
a3f97cbb JW |
9642 | /* Generate the initial DIE for the .debug section. Note that the (string) |
9643 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE | |
9644 | will (typically) be a relative pathname and that this pathname should be | |
9645 | taken as being relative to the directory from which the compiler was | |
9646 | invoked when the given (base) source file was compiled. */ | |
9647 | gen_compile_unit_die (main_input_filename); | |
9648 | ||
5c90448c | 9649 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
a3f97cbb JW |
9650 | } |
9651 | ||
9652 | /* Output stuff that dwarf requires at the end of every file, | |
9653 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 9654 | |
a3f97cbb | 9655 | void |
9a666dda | 9656 | dwarf2out_finish () |
a3f97cbb | 9657 | { |
ef76d03b JW |
9658 | limbo_die_node *node, *next_node; |
9659 | dw_die_ref die; | |
9660 | dw_attr_ref a; | |
9661 | ||
9662 | /* Traverse the limbo die list, and add parent/child links. The only | |
9663 | dies without parents that should be here are concrete instances of | |
9664 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
9665 | For concrete instances, we can get the parent die from the abstract | |
9666 | instance. */ | |
9667 | for (node = limbo_die_list; node; node = next_node) | |
9668 | { | |
9669 | next_node = node->next; | |
9670 | die = node->die; | |
9671 | ||
9672 | if (die->die_parent == NULL) | |
9673 | { | |
9674 | a = get_AT (die, DW_AT_abstract_origin); | |
9675 | if (a) | |
9676 | add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die); | |
9677 | else if (die == comp_unit_die) | |
9678 | ; | |
9679 | else | |
9680 | abort (); | |
9681 | } | |
9682 | free (node); | |
9683 | } | |
9684 | ||
a3f97cbb JW |
9685 | /* Traverse the DIE tree and add sibling attributes to those DIE's |
9686 | that have children. */ | |
9687 | add_sibling_attributes (comp_unit_die); | |
9688 | ||
9689 | /* Output a terminator label for the .text section. */ | |
9690 | fputc ('\n', asm_out_file); | |
9691 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
5c90448c | 9692 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 9693 | |
bdb669cb | 9694 | #if 0 |
a3f97cbb JW |
9695 | /* Output a terminator label for the .data section. */ |
9696 | fputc ('\n', asm_out_file); | |
9697 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
5c90448c | 9698 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
9699 | |
9700 | /* Output a terminator label for the .bss section. */ | |
9701 | fputc ('\n', asm_out_file); | |
9702 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
5c90448c | 9703 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 9704 | #endif |
a3f97cbb | 9705 | |
e90b62db JM |
9706 | /* Output the source line correspondence table. */ |
9707 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
9708 | { | |
9709 | fputc ('\n', asm_out_file); | |
c53aa195 | 9710 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
e90b62db JM |
9711 | output_line_info (); |
9712 | ||
9713 | /* We can only use the low/high_pc attributes if all of the code | |
9714 | was in .text. */ | |
9715 | if (separate_line_info_table_in_use == 0) | |
9716 | { | |
9717 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION); | |
5c90448c | 9718 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); |
e90b62db | 9719 | } |
71dfc51f | 9720 | |
c53aa195 | 9721 | add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION); |
e90b62db JM |
9722 | } |
9723 | ||
a3f97cbb JW |
9724 | /* Output the abbreviation table. */ |
9725 | fputc ('\n', asm_out_file); | |
9726 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
9727 | build_abbrev_table (comp_unit_die); | |
9728 | output_abbrev_section (); | |
9729 | ||
a3f97cbb JW |
9730 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
9731 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
9732 | calc_die_sizes (comp_unit_die); | |
9733 | ||
a3f97cbb JW |
9734 | /* Output debugging information. */ |
9735 | fputc ('\n', asm_out_file); | |
c53aa195 | 9736 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
a3f97cbb JW |
9737 | output_compilation_unit_header (); |
9738 | output_die (comp_unit_die); | |
9739 | ||
d291dd49 JM |
9740 | if (pubname_table_in_use) |
9741 | { | |
9742 | /* Output public names table. */ | |
9743 | fputc ('\n', asm_out_file); | |
9744 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
9745 | output_pubnames (); | |
9746 | } | |
9747 | ||
a3f97cbb JW |
9748 | if (fde_table_in_use) |
9749 | { | |
a3f97cbb JW |
9750 | /* Output the address range information. */ |
9751 | fputc ('\n', asm_out_file); | |
9752 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
9753 | output_aranges (); | |
9754 | } | |
9755 | } | |
9a666dda | 9756 | #endif /* DWARF2_DEBUGGING_INFO */ |