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