]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
88ed5bb5 | 2 | Copyright (C) 1992, 93, 95-98, 1999 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 | |
5f38fdda JL |
21 | the Free Software Foundation, 59 Temple Place - Suite 330, |
22 | Boston, MA 02111-1307, USA. */ | |
a3f97cbb | 23 | |
3f76745e JM |
24 | /* The first part of this file deals with the DWARF 2 frame unwind |
25 | information, which is also used by the GCC efficient exception handling | |
26 | mechanism. The second part, controlled only by an #ifdef | |
27 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
28 | information. */ | |
29 | ||
0021b564 | 30 | #include "config.h" |
670ee920 | 31 | #include "system.h" |
0021b564 | 32 | #include "defaults.h" |
a3f97cbb JW |
33 | #include "tree.h" |
34 | #include "flags.h" | |
35 | #include "rtl.h" | |
36 | #include "hard-reg-set.h" | |
37 | #include "regs.h" | |
38 | #include "insn-config.h" | |
39 | #include "reload.h" | |
40 | #include "output.h" | |
71dfc51f | 41 | #include "expr.h" |
3f76745e | 42 | #include "except.h" |
a7cc7f29 | 43 | #include "dwarf2.h" |
76ead72b | 44 | #include "dwarf2out.h" |
10f0ad3d | 45 | #include "toplev.h" |
b170964a | 46 | #include "dyn-string.h" |
a3f97cbb | 47 | |
c85f7c16 JL |
48 | /* We cannot use <assert.h> in GCC source, since that would include |
49 | GCC's assert.h, which may not be compatible with the host compiler. */ | |
50 | #undef assert | |
51 | #ifdef NDEBUG | |
52 | # define assert(e) | |
53 | #else | |
54 | # define assert(e) do { if (! (e)) abort (); } while (0) | |
55 | #endif | |
56 | ||
0021b564 JM |
57 | /* Decide whether we want to emit frame unwind information for the current |
58 | translation unit. */ | |
59 | ||
60 | int | |
61 | dwarf2out_do_frame () | |
62 | { | |
63 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 JL |
64 | #ifdef DWARF2_FRAME_INFO |
65 | || DWARF2_FRAME_INFO | |
66 | #endif | |
0021b564 JM |
67 | #ifdef DWARF2_UNWIND_INFO |
68 | || (flag_exceptions && ! exceptions_via_longjmp) | |
69 | #endif | |
70 | ); | |
71 | } | |
72 | ||
73 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
74 | ||
eaf95893 RK |
75 | /* How to start an assembler comment. */ |
76 | #ifndef ASM_COMMENT_START | |
77 | #define ASM_COMMENT_START ";#" | |
78 | #endif | |
79 | ||
a3f97cbb JW |
80 | typedef struct dw_cfi_struct *dw_cfi_ref; |
81 | typedef struct dw_fde_struct *dw_fde_ref; | |
82 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
83 | |
84 | /* Call frames are described using a sequence of Call Frame | |
85 | Information instructions. The register number, offset | |
86 | and address fields are provided as possible operands; | |
87 | their use is selected by the opcode field. */ | |
71dfc51f | 88 | |
a3f97cbb | 89 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
90 | { |
91 | unsigned long dw_cfi_reg_num; | |
92 | long int dw_cfi_offset; | |
93 | char *dw_cfi_addr; | |
94 | } | |
a3f97cbb JW |
95 | dw_cfi_oprnd; |
96 | ||
97 | typedef struct dw_cfi_struct | |
71dfc51f RK |
98 | { |
99 | dw_cfi_ref dw_cfi_next; | |
100 | enum dwarf_call_frame_info dw_cfi_opc; | |
101 | dw_cfi_oprnd dw_cfi_oprnd1; | |
102 | dw_cfi_oprnd dw_cfi_oprnd2; | |
103 | } | |
a3f97cbb JW |
104 | dw_cfi_node; |
105 | ||
106 | /* All call frame descriptions (FDE's) in the GCC generated DWARF | |
4b674448 | 107 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
108 | the beginning of the .debug_frame section. This used of a single |
109 | CIE obviates the need to keep track of multiple CIE's | |
110 | in the DWARF generation routines below. */ | |
71dfc51f | 111 | |
a3f97cbb | 112 | typedef struct dw_fde_struct |
71dfc51f | 113 | { |
71dfc51f RK |
114 | char *dw_fde_begin; |
115 | char *dw_fde_current_label; | |
116 | char *dw_fde_end; | |
117 | dw_cfi_ref dw_fde_cfi; | |
118 | } | |
a3f97cbb JW |
119 | dw_fde_node; |
120 | ||
a3f97cbb JW |
121 | /* Maximum size (in bytes) of an artificially generated label. */ |
122 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
123 | ||
124 | /* Make sure we know the sizes of the various types dwarf can describe. These | |
125 | are only defaults. If the sizes are different for your target, you should | |
126 | override these values by defining the appropriate symbols in your tm.h | |
127 | file. */ | |
71dfc51f | 128 | |
a3f97cbb JW |
129 | #ifndef CHAR_TYPE_SIZE |
130 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
131 | #endif | |
a3f97cbb | 132 | #ifndef PTR_SIZE |
a9d38797 | 133 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
134 | #endif |
135 | ||
7e23cb16 JM |
136 | /* The size in bytes of a DWARF field indicating an offset or length |
137 | relative to a debug info section, specified to be 4 bytes in the DWARF-2 | |
138 | specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */ | |
71dfc51f | 139 | |
7e23cb16 JM |
140 | #ifndef DWARF_OFFSET_SIZE |
141 | #define DWARF_OFFSET_SIZE 4 | |
142 | #endif | |
143 | ||
9a666dda JM |
144 | #define DWARF_VERSION 2 |
145 | ||
7e23cb16 JM |
146 | /* Round SIZE up to the nearest BOUNDARY. */ |
147 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
148 | (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1)) | |
a3f97cbb | 149 | |
a3f97cbb | 150 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
469ac993 JM |
151 | #ifdef STACK_GROWS_DOWNWARD |
152 | #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD) | |
153 | #else | |
154 | #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD | |
155 | #endif | |
a3f97cbb | 156 | |
3f76745e JM |
157 | /* A pointer to the base of a table that contains frame description |
158 | information for each routine. */ | |
159 | static dw_fde_ref fde_table; | |
a3f97cbb | 160 | |
3f76745e JM |
161 | /* Number of elements currently allocated for fde_table. */ |
162 | static unsigned fde_table_allocated; | |
a94dbf2c | 163 | |
3f76745e JM |
164 | /* Number of elements in fde_table currently in use. */ |
165 | static unsigned fde_table_in_use; | |
a3f97cbb | 166 | |
3f76745e JM |
167 | /* Size (in elements) of increments by which we may expand the |
168 | fde_table. */ | |
169 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 170 | |
a94dbf2c JM |
171 | /* A list of call frame insns for the CIE. */ |
172 | static dw_cfi_ref cie_cfi_head; | |
173 | ||
a3f97cbb JW |
174 | /* The number of the current function definition for which debugging |
175 | information is being generated. These numbers range from 1 up to the | |
176 | maximum number of function definitions contained within the current | |
177 | compilation unit. These numbers are used to create unique label id's | |
178 | unique to each function definition. */ | |
4f988ea2 | 179 | static unsigned current_funcdef_number = 0; |
a3f97cbb JW |
180 | |
181 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
182 | attribute that accelerates the lookup of the FDE associated | |
183 | with the subprogram. This variable holds the table index of the FDE | |
184 | associated with the current function (body) definition. */ | |
185 | static unsigned current_funcdef_fde; | |
186 | ||
a3f97cbb | 187 | /* Forward declarations for functions defined in this file. */ |
71dfc51f RK |
188 | |
189 | static char *stripattributes PROTO((char *)); | |
3f76745e JM |
190 | static char *dwarf_cfi_name PROTO((unsigned)); |
191 | static dw_cfi_ref new_cfi PROTO((void)); | |
192 | static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref)); | |
71dfc51f RK |
193 | static unsigned long size_of_uleb128 PROTO((unsigned long)); |
194 | static unsigned long size_of_sleb128 PROTO((long)); | |
71dfc51f RK |
195 | static void output_uleb128 PROTO((unsigned long)); |
196 | static void output_sleb128 PROTO((long)); | |
71dfc51f RK |
197 | static void add_fde_cfi PROTO((char *, dw_cfi_ref)); |
198 | static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *, | |
199 | long *)); | |
200 | static void lookup_cfa PROTO((unsigned long *, long *)); | |
201 | static void reg_save PROTO((char *, unsigned, unsigned, | |
202 | long)); | |
203 | static void initial_return_save PROTO((rtx)); | |
71dfc51f | 204 | static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref)); |
3f76745e | 205 | static void output_call_frame_info PROTO((int)); |
71dfc51f | 206 | static unsigned reg_number PROTO((rtx)); |
1ad4f46b | 207 | static void dwarf2out_stack_adjust PROTO((rtx)); |
a3f97cbb JW |
208 | |
209 | /* Definitions of defaults for assembler-dependent names of various | |
210 | pseudo-ops and section names. | |
211 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
212 | assembler. */ | |
71dfc51f | 213 | |
0021b564 | 214 | #ifdef OBJECT_FORMAT_ELF |
a3f97cbb JW |
215 | #ifndef UNALIGNED_SHORT_ASM_OP |
216 | #define UNALIGNED_SHORT_ASM_OP ".2byte" | |
217 | #endif | |
218 | #ifndef UNALIGNED_INT_ASM_OP | |
219 | #define UNALIGNED_INT_ASM_OP ".4byte" | |
220 | #endif | |
7e23cb16 JM |
221 | #ifndef UNALIGNED_DOUBLE_INT_ASM_OP |
222 | #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte" | |
223 | #endif | |
0021b564 JM |
224 | #endif /* OBJECT_FORMAT_ELF */ |
225 | ||
a3f97cbb JW |
226 | #ifndef ASM_BYTE_OP |
227 | #define ASM_BYTE_OP ".byte" | |
228 | #endif | |
229 | ||
7e23cb16 JM |
230 | /* Data and reference forms for relocatable data. */ |
231 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
232 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
233 | ||
a3f97cbb JW |
234 | /* Pseudo-op for defining a new section. */ |
235 | #ifndef SECTION_ASM_OP | |
236 | #define SECTION_ASM_OP ".section" | |
237 | #endif | |
238 | ||
239 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
240 | print the SECTION_ASM_OP and the section name. The default here works for | |
241 | almost all svr4 assemblers, except for the sparc, where the section name | |
242 | must be enclosed in double quotes. (See sparcv4.h). */ | |
243 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
244 | #ifdef PUSHSECTION_FORMAT |
245 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
246 | #else | |
247 | #define SECTION_FORMAT "\t%s\t%s\n" | |
248 | #endif | |
a3f97cbb JW |
249 | #endif |
250 | ||
a3f97cbb JW |
251 | #ifndef FRAME_SECTION |
252 | #define FRAME_SECTION ".debug_frame" | |
253 | #endif | |
a3f97cbb | 254 | |
5c90448c JM |
255 | #ifndef FUNC_BEGIN_LABEL |
256 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 257 | #endif |
5c90448c JM |
258 | #ifndef FUNC_END_LABEL |
259 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 260 | #endif |
a6ab3aad JM |
261 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
262 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 263 | #define CIE_LENGTH_LABEL "LLCIE" |
a6ab3aad JM |
264 | #define FDE_AFTER_SIZE_LABEL "LSFDE" |
265 | #define FDE_END_LABEL "LEFDE" | |
2ed2af28 | 266 | #define FDE_LENGTH_LABEL "LLFDE" |
a3f97cbb | 267 | |
a3f97cbb JW |
268 | /* Definitions of defaults for various types of primitive assembly language |
269 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 270 | but typically, that is unnecessary. */ |
71dfc51f | 271 | |
a3f97cbb JW |
272 | #ifndef ASM_OUTPUT_SECTION |
273 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
274 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
275 | #endif | |
276 | ||
0021b564 JM |
277 | #ifndef ASM_OUTPUT_DWARF_DATA1 |
278 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
32bd96ff | 279 | fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE)) |
0021b564 JM |
280 | #endif |
281 | ||
bb727b5a JM |
282 | #ifndef ASM_OUTPUT_DWARF_DELTA1 |
283 | #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \ | |
284 | do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \ | |
285 | assemble_name (FILE, LABEL1); \ | |
286 | fprintf (FILE, "-"); \ | |
287 | assemble_name (FILE, LABEL2); \ | |
288 | } while (0) | |
289 | #endif | |
290 | ||
0021b564 JM |
291 | #ifdef UNALIGNED_INT_ASM_OP |
292 | ||
293 | #ifndef UNALIGNED_OFFSET_ASM_OP | |
294 | #define UNALIGNED_OFFSET_ASM_OP \ | |
295 | (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
296 | #endif | |
297 | ||
298 | #ifndef UNALIGNED_WORD_ASM_OP | |
299 | #define UNALIGNED_WORD_ASM_OP \ | |
300 | (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
301 | #endif | |
302 | ||
a3f97cbb JW |
303 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
304 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
305 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ | |
306 | assemble_name (FILE, LABEL1); \ | |
307 | fprintf (FILE, "-"); \ | |
308 | assemble_name (FILE, LABEL2); \ | |
309 | } while (0) | |
310 | #endif | |
311 | ||
312 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
313 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
314 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
315 | assemble_name (FILE, LABEL1); \ | |
316 | fprintf (FILE, "-"); \ | |
317 | assemble_name (FILE, LABEL2); \ | |
318 | } while (0) | |
319 | #endif | |
320 | ||
7e23cb16 JM |
321 | #ifndef ASM_OUTPUT_DWARF_DELTA |
322 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
323 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
324 | assemble_name (FILE, LABEL1); \ | |
325 | fprintf (FILE, "-"); \ | |
326 | assemble_name (FILE, LABEL2); \ | |
327 | } while (0) | |
328 | #endif | |
329 | ||
330 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA | |
331 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
332 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ | |
333 | assemble_name (FILE, LABEL1); \ | |
334 | fprintf (FILE, "-"); \ | |
335 | assemble_name (FILE, LABEL2); \ | |
336 | } while (0) | |
337 | #endif | |
338 | ||
a3f97cbb JW |
339 | #ifndef ASM_OUTPUT_DWARF_ADDR |
340 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
7e23cb16 | 341 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ |
a3f97cbb JW |
342 | assemble_name (FILE, LABEL); \ |
343 | } while (0) | |
344 | #endif | |
345 | ||
cba96cb7 JW |
346 | /* ??? This macro takes an RTX in dwarfout.c and a string in dwarf2out.c. |
347 | We resolve the conflict by creating a new macro ASM_OUTPUT_DWARF2_ADDR_CONST | |
348 | for ports that want to support both DWARF1 and DWARF2. This needs a better | |
349 | solution. See also the comments in sparc/sp64-elf.h. */ | |
350 | #ifdef ASM_OUTPUT_DWARF2_ADDR_CONST | |
351 | #undef ASM_OUTPUT_DWARF_ADDR_CONST | |
352 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \ | |
353 | ASM_OUTPUT_DWARF2_ADDR_CONST (FILE, ADDR) | |
354 | #endif | |
355 | ||
a3f97cbb JW |
356 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST |
357 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \ | |
7e23cb16 JM |
358 | fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR)) |
359 | #endif | |
360 | ||
7bb9fb0e JM |
361 | #ifndef ASM_OUTPUT_DWARF_OFFSET4 |
362 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ | |
363 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
364 | assemble_name (FILE, LABEL); \ | |
365 | } while (0) | |
366 | #endif | |
367 | ||
7e23cb16 JM |
368 | #ifndef ASM_OUTPUT_DWARF_OFFSET |
369 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ | |
370 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
371 | assemble_name (FILE, LABEL); \ | |
372 | } while (0) | |
a3f97cbb JW |
373 | #endif |
374 | ||
a3f97cbb JW |
375 | #ifndef ASM_OUTPUT_DWARF_DATA2 |
376 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
32bd96ff | 377 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
378 | #endif |
379 | ||
380 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
381 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
32bd96ff | 382 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
383 | #endif |
384 | ||
7e23cb16 JM |
385 | #ifndef ASM_OUTPUT_DWARF_DATA |
386 | #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \ | |
387 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \ | |
32bd96ff | 388 | (unsigned long) (VALUE)) |
7e23cb16 JM |
389 | #endif |
390 | ||
391 | #ifndef ASM_OUTPUT_DWARF_ADDR_DATA | |
392 | #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \ | |
393 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \ | |
32bd96ff | 394 | (unsigned long) (VALUE)) |
7e23cb16 JM |
395 | #endif |
396 | ||
a3f97cbb JW |
397 | #ifndef ASM_OUTPUT_DWARF_DATA8 |
398 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
399 | do { \ | |
400 | if (WORDS_BIG_ENDIAN) \ | |
401 | { \ | |
32bd96ff JM |
402 | fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\ |
403 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\ | |
a3f97cbb JW |
404 | } \ |
405 | else \ | |
406 | { \ | |
32bd96ff JM |
407 | fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \ |
408 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \ | |
a3f97cbb JW |
409 | } \ |
410 | } while (0) | |
411 | #endif | |
412 | ||
0021b564 JM |
413 | #else /* UNALIGNED_INT_ASM_OP */ |
414 | ||
415 | /* We don't have unaligned support, let's hope the normal output works for | |
416 | .debug_frame. */ | |
417 | ||
418 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
38a448ca | 419 | assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1) |
0021b564 | 420 | |
7bb9fb0e | 421 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ |
38a448ca | 422 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
7bb9fb0e | 423 | |
0021b564 | 424 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ |
38a448ca | 425 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
0021b564 JM |
426 | |
427 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
428 | assemble_integer (gen_rtx_MINUS (HImode, \ |
429 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
430 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
431 | 2, 1) |
432 | ||
433 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
434 | assemble_integer (gen_rtx_MINUS (SImode, \ |
435 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
436 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
437 | 4, 1) |
438 | ||
439 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
38a448ca RH |
440 | assemble_integer (gen_rtx_MINUS (Pmode, \ |
441 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ | |
442 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
443 | PTR_SIZE, 1) |
444 | ||
445 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
446 | ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2) | |
447 | ||
448 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
449 | assemble_integer (GEN_INT (VALUE), 4, 1) | |
450 | ||
451 | #endif /* UNALIGNED_INT_ASM_OP */ | |
452 | ||
2ed2af28 PDM |
453 | #ifdef SET_ASM_OP |
454 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
455 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
456 | do { \ | |
457 | fprintf (FILE, "\t%s\t", SET_ASM_OP); \ | |
458 | assemble_name (FILE, SY); \ | |
459 | fputc (',', FILE); \ | |
460 | assemble_name (FILE, HI); \ | |
461 | fputc ('-', FILE); \ | |
462 | assemble_name (FILE, LO); \ | |
463 | } while (0) | |
2ed2af28 PDM |
464 | #endif |
465 | #endif /* SET_ASM_OP */ | |
466 | ||
a6ab3aad | 467 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing |
2ed2af28 | 468 | newline is produced. When flag_debug_asm is asserted, we add commentary |
a6ab3aad JM |
469 | at the end of the line, so we must avoid output of a newline here. */ |
470 | #ifndef ASM_OUTPUT_DWARF_STRING | |
471 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
472 | do { \ | |
473 | register int slen = strlen(P); \ | |
474 | register char *p = (P); \ | |
475 | register int i; \ | |
476 | fprintf (FILE, "\t.ascii \""); \ | |
477 | for (i = 0; i < slen; i++) \ | |
478 | { \ | |
479 | register int c = p[i]; \ | |
480 | if (c == '\"' || c == '\\') \ | |
481 | putc ('\\', FILE); \ | |
482 | if (c >= ' ' && c < 0177) \ | |
483 | putc (c, FILE); \ | |
484 | else \ | |
485 | { \ | |
486 | fprintf (FILE, "\\%o", c); \ | |
487 | } \ | |
488 | } \ | |
489 | fprintf (FILE, "\\0\""); \ | |
490 | } \ | |
491 | while (0) | |
492 | #endif | |
493 | ||
c8cc5c4a | 494 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
495 | is the column for PC, or the first column after all of the hard |
496 | registers. */ | |
c8cc5c4a | 497 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
498 | #ifdef PC_REGNUM |
499 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
500 | #else | |
466446b0 | 501 | #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER |
a94dbf2c | 502 | #endif |
c8cc5c4a JM |
503 | #endif |
504 | ||
505 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 506 | default, we just provide columns for all registers. */ |
c8cc5c4a | 507 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 508 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 509 | #endif |
3f76745e | 510 | |
0021b564 JM |
511 | /* Hook used by __throw. */ |
512 | ||
513 | rtx | |
514 | expand_builtin_dwarf_fp_regnum () | |
515 | { | |
516 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
517 | } | |
518 | ||
a6ab3aad JM |
519 | /* The offset from the incoming value of %sp to the top of the stack frame |
520 | for the current function. */ | |
521 | #ifndef INCOMING_FRAME_SP_OFFSET | |
522 | #define INCOMING_FRAME_SP_OFFSET 0 | |
523 | #endif | |
524 | ||
71dfc51f | 525 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 526 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
527 | |
528 | static inline char * | |
a3f97cbb | 529 | stripattributes (s) |
71dfc51f | 530 | char *s; |
a3f97cbb | 531 | { |
bf20f341 | 532 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
533 | char *p = stripped; |
534 | ||
bf20f341 JW |
535 | *p++ = '*'; |
536 | ||
537 | while (*s && *s != ',') | |
538 | *p++ = *s++; | |
71dfc51f | 539 | |
a3f97cbb JW |
540 | *p = '\0'; |
541 | return stripped; | |
542 | } | |
543 | ||
3f76745e | 544 | /* Return the register number described by a given RTL node. */ |
71dfc51f | 545 | |
3f76745e JM |
546 | static unsigned |
547 | reg_number (rtl) | |
548 | register rtx rtl; | |
a3f97cbb | 549 | { |
3f76745e | 550 | register unsigned regno = REGNO (rtl); |
a3f97cbb | 551 | |
3f76745e | 552 | if (regno >= FIRST_PSEUDO_REGISTER) |
a3f97cbb | 553 | { |
3f76745e JM |
554 | warning ("internal regno botch: regno = %d\n", regno); |
555 | regno = 0; | |
556 | } | |
a3f97cbb | 557 | |
3f76745e JM |
558 | regno = DBX_REGISTER_NUMBER (regno); |
559 | return regno; | |
560 | } | |
a3f97cbb | 561 | |
2f3ca9e7 JM |
562 | struct reg_size_range |
563 | { | |
564 | int beg; | |
565 | int end; | |
566 | int size; | |
567 | }; | |
568 | ||
569 | /* Given a register number in REG_TREE, return an rtx for its size in bytes. | |
570 | We do this in kind of a roundabout way, by building up a list of | |
571 | register size ranges and seeing where our register falls in one of those | |
572 | ranges. We need to do it this way because REG_TREE is not a constant, | |
573 | and the target macros were not designed to make this task easy. */ | |
574 | ||
575 | rtx | |
576 | expand_builtin_dwarf_reg_size (reg_tree, target) | |
577 | tree reg_tree; | |
578 | rtx target; | |
579 | { | |
31c8581d | 580 | enum machine_mode mode; |
d1485032 | 581 | int size; |
2f3ca9e7 JM |
582 | struct reg_size_range ranges[5]; |
583 | tree t, t2; | |
584 | ||
d1485032 JM |
585 | int i = 0; |
586 | int n_ranges = 0; | |
587 | int last_size = -1; | |
2f3ca9e7 | 588 | |
d1485032 | 589 | for (; i < FIRST_PSEUDO_REGISTER; ++i) |
2f3ca9e7 | 590 | { |
d1485032 JM |
591 | /* The return address is out of order on the MIPS, and we don't use |
592 | copy_reg for it anyway, so we don't care here how large it is. */ | |
593 | if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN) | |
594 | continue; | |
595 | ||
31c8581d | 596 | mode = reg_raw_mode[i]; |
e5e809f4 | 597 | |
31c8581d JW |
598 | /* CCmode is arbitrarily given a size of 4 bytes. It is more useful |
599 | to use the same size as word_mode, since that reduces the number | |
600 | of ranges we need. It should not matter, since the result should | |
601 | never be used for a condition code register anyways. */ | |
e5e809f4 | 602 | if (GET_MODE_CLASS (mode) == MODE_CC) |
31c8581d | 603 | mode = word_mode; |
e5e809f4 | 604 | |
31c8581d JW |
605 | size = GET_MODE_SIZE (mode); |
606 | ||
e5e809f4 JL |
607 | /* If this register is not valid in the specified mode and |
608 | we have a previous size, use that for the size of this | |
609 | register to avoid making junk tiny ranges. */ | |
610 | if (! HARD_REGNO_MODE_OK (i, mode) && last_size != -1) | |
611 | size = last_size; | |
612 | ||
d1485032 | 613 | if (size != last_size) |
2f3ca9e7 | 614 | { |
2f3ca9e7 | 615 | ranges[n_ranges].beg = i; |
e5e809f4 | 616 | ranges[n_ranges].size = last_size = size; |
2f3ca9e7 | 617 | ++n_ranges; |
3a88cbd1 JL |
618 | if (n_ranges >= 5) |
619 | abort (); | |
2f3ca9e7 | 620 | } |
d1485032 | 621 | ranges[n_ranges-1].end = i; |
2f3ca9e7 | 622 | } |
2f3ca9e7 JM |
623 | |
624 | /* The usual case: fp regs surrounded by general regs. */ | |
625 | if (n_ranges == 3 && ranges[0].size == ranges[2].size) | |
626 | { | |
3a88cbd1 JL |
627 | if ((DWARF_FRAME_REGNUM (ranges[1].end) |
628 | - DWARF_FRAME_REGNUM (ranges[1].beg)) | |
629 | != ranges[1].end - ranges[1].beg) | |
630 | abort (); | |
2f3ca9e7 JM |
631 | t = fold (build (GE_EXPR, integer_type_node, reg_tree, |
632 | build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0))); | |
633 | t2 = fold (build (LE_EXPR, integer_type_node, reg_tree, | |
634 | build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0))); | |
635 | t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2)); | |
636 | t = fold (build (COND_EXPR, integer_type_node, t, | |
637 | build_int_2 (ranges[1].size, 0), | |
638 | build_int_2 (ranges[0].size, 0))); | |
639 | } | |
640 | else | |
641 | { | |
69fba037 JC |
642 | /* Initialize last_end to be larger than any possible |
643 | DWARF_FRAME_REGNUM. */ | |
644 | int last_end = 0x7fffffff; | |
2f3ca9e7 JM |
645 | --n_ranges; |
646 | t = build_int_2 (ranges[n_ranges].size, 0); | |
913f68c1 | 647 | do |
2f3ca9e7 | 648 | { |
913f68c1 JC |
649 | int beg = DWARF_FRAME_REGNUM (ranges[n_ranges].beg); |
650 | int end = DWARF_FRAME_REGNUM (ranges[n_ranges].end); | |
651 | if (beg < 0) | |
652 | continue; | |
653 | if (end >= last_end) | |
3a88cbd1 | 654 | abort (); |
913f68c1 JC |
655 | last_end = end; |
656 | if (end - beg != ranges[n_ranges].end - ranges[n_ranges].beg) | |
3a88cbd1 | 657 | abort (); |
2f3ca9e7 | 658 | t2 = fold (build (LE_EXPR, integer_type_node, reg_tree, |
913f68c1 | 659 | build_int_2 (end, 0))); |
2f3ca9e7 JM |
660 | t = fold (build (COND_EXPR, integer_type_node, t2, |
661 | build_int_2 (ranges[n_ranges].size, 0), t)); | |
662 | } | |
c9ab1458 | 663 | while (--n_ranges >= 0); |
2f3ca9e7 JM |
664 | } |
665 | return expand_expr (t, target, Pmode, 0); | |
666 | } | |
667 | ||
3f76745e | 668 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 669 | |
3f76745e JM |
670 | static char * |
671 | dwarf_cfi_name (cfi_opc) | |
672 | register unsigned cfi_opc; | |
673 | { | |
674 | switch (cfi_opc) | |
675 | { | |
676 | case DW_CFA_advance_loc: | |
677 | return "DW_CFA_advance_loc"; | |
678 | case DW_CFA_offset: | |
679 | return "DW_CFA_offset"; | |
680 | case DW_CFA_restore: | |
681 | return "DW_CFA_restore"; | |
682 | case DW_CFA_nop: | |
683 | return "DW_CFA_nop"; | |
684 | case DW_CFA_set_loc: | |
685 | return "DW_CFA_set_loc"; | |
686 | case DW_CFA_advance_loc1: | |
687 | return "DW_CFA_advance_loc1"; | |
688 | case DW_CFA_advance_loc2: | |
689 | return "DW_CFA_advance_loc2"; | |
690 | case DW_CFA_advance_loc4: | |
691 | return "DW_CFA_advance_loc4"; | |
692 | case DW_CFA_offset_extended: | |
693 | return "DW_CFA_offset_extended"; | |
694 | case DW_CFA_restore_extended: | |
695 | return "DW_CFA_restore_extended"; | |
696 | case DW_CFA_undefined: | |
697 | return "DW_CFA_undefined"; | |
698 | case DW_CFA_same_value: | |
699 | return "DW_CFA_same_value"; | |
700 | case DW_CFA_register: | |
701 | return "DW_CFA_register"; | |
702 | case DW_CFA_remember_state: | |
703 | return "DW_CFA_remember_state"; | |
704 | case DW_CFA_restore_state: | |
705 | return "DW_CFA_restore_state"; | |
706 | case DW_CFA_def_cfa: | |
707 | return "DW_CFA_def_cfa"; | |
708 | case DW_CFA_def_cfa_register: | |
709 | return "DW_CFA_def_cfa_register"; | |
710 | case DW_CFA_def_cfa_offset: | |
711 | return "DW_CFA_def_cfa_offset"; | |
c53aa195 | 712 | |
3f76745e JM |
713 | /* SGI/MIPS specific */ |
714 | case DW_CFA_MIPS_advance_loc8: | |
715 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
716 | |
717 | /* GNU extensions */ | |
718 | case DW_CFA_GNU_window_save: | |
719 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
720 | case DW_CFA_GNU_args_size: |
721 | return "DW_CFA_GNU_args_size"; | |
c53aa195 | 722 | |
3f76745e JM |
723 | default: |
724 | return "DW_CFA_<unknown>"; | |
725 | } | |
726 | } | |
a3f97cbb | 727 | |
3f76745e | 728 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 729 | |
3f76745e JM |
730 | static inline dw_cfi_ref |
731 | new_cfi () | |
732 | { | |
733 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 734 | |
3f76745e JM |
735 | cfi->dw_cfi_next = NULL; |
736 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
737 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 738 | |
3f76745e JM |
739 | return cfi; |
740 | } | |
a3f97cbb | 741 | |
3f76745e | 742 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 743 | |
3f76745e JM |
744 | static inline void |
745 | add_cfi (list_head, cfi) | |
746 | register dw_cfi_ref *list_head; | |
747 | register dw_cfi_ref cfi; | |
748 | { | |
749 | register dw_cfi_ref *p; | |
a3f97cbb | 750 | |
3f76745e JM |
751 | /* Find the end of the chain. */ |
752 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
753 | ; | |
754 | ||
755 | *p = cfi; | |
a3f97cbb JW |
756 | } |
757 | ||
3f76745e | 758 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 759 | |
c53aa195 | 760 | char * |
3f76745e | 761 | dwarf2out_cfi_label () |
a3f97cbb | 762 | { |
3f76745e JM |
763 | static char label[20]; |
764 | static unsigned long label_num = 0; | |
765 | ||
766 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); | |
767 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
768 | ||
769 | return label; | |
a3f97cbb JW |
770 | } |
771 | ||
3f76745e JM |
772 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
773 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 774 | |
3f76745e JM |
775 | static void |
776 | add_fde_cfi (label, cfi) | |
777 | register char *label; | |
778 | register dw_cfi_ref cfi; | |
a3f97cbb | 779 | { |
3f76745e JM |
780 | if (label) |
781 | { | |
782 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 783 | |
3f76745e JM |
784 | if (*label == 0) |
785 | label = dwarf2out_cfi_label (); | |
71dfc51f | 786 | |
3f76745e JM |
787 | if (fde->dw_fde_current_label == NULL |
788 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
789 | { | |
790 | register dw_cfi_ref xcfi; | |
a3f97cbb | 791 | |
3f76745e | 792 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 793 | |
3f76745e JM |
794 | /* Set the location counter to the new label. */ |
795 | xcfi = new_cfi (); | |
796 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
797 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
798 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
799 | } | |
71dfc51f | 800 | |
3f76745e JM |
801 | add_cfi (&fde->dw_fde_cfi, cfi); |
802 | } | |
803 | ||
804 | else | |
805 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
806 | } |
807 | ||
3f76745e | 808 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 809 | |
3f76745e JM |
810 | static inline void |
811 | lookup_cfa_1 (cfi, regp, offsetp) | |
812 | register dw_cfi_ref cfi; | |
813 | register unsigned long *regp; | |
814 | register long *offsetp; | |
a3f97cbb | 815 | { |
3f76745e JM |
816 | switch (cfi->dw_cfi_opc) |
817 | { | |
818 | case DW_CFA_def_cfa_offset: | |
819 | *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset; | |
820 | break; | |
821 | case DW_CFA_def_cfa_register: | |
822 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
823 | break; | |
824 | case DW_CFA_def_cfa: | |
825 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
826 | *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
827 | break; | |
e9a25f70 JL |
828 | default: |
829 | break; | |
3f76745e | 830 | } |
a3f97cbb JW |
831 | } |
832 | ||
3f76745e | 833 | /* Find the previous value for the CFA. */ |
71dfc51f | 834 | |
3f76745e JM |
835 | static void |
836 | lookup_cfa (regp, offsetp) | |
837 | register unsigned long *regp; | |
838 | register long *offsetp; | |
a3f97cbb | 839 | { |
3f76745e JM |
840 | register dw_cfi_ref cfi; |
841 | ||
842 | *regp = (unsigned long) -1; | |
843 | *offsetp = 0; | |
844 | ||
845 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
846 | lookup_cfa_1 (cfi, regp, offsetp); | |
847 | ||
848 | if (fde_table_in_use) | |
a3f97cbb | 849 | { |
3f76745e JM |
850 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
851 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
852 | lookup_cfa_1 (cfi, regp, offsetp); | |
a3f97cbb JW |
853 | } |
854 | } | |
855 | ||
3f76745e | 856 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
a6ab3aad | 857 | static unsigned long cfa_reg; |
3f76745e | 858 | static long cfa_offset; |
71dfc51f | 859 | |
3f76745e JM |
860 | /* The register used for saving registers to the stack, and its offset |
861 | from the CFA. */ | |
862 | static unsigned cfa_store_reg; | |
863 | static long cfa_store_offset; | |
864 | ||
0021b564 JM |
865 | /* The running total of the size of arguments pushed onto the stack. */ |
866 | static long args_size; | |
867 | ||
b57d9225 JM |
868 | /* The last args_size we actually output. */ |
869 | static long old_args_size; | |
870 | ||
3f76745e JM |
871 | /* Entry point to update the canonical frame address (CFA). |
872 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
873 | calculated from REG+OFFSET. */ | |
874 | ||
875 | void | |
876 | dwarf2out_def_cfa (label, reg, offset) | |
877 | register char *label; | |
878 | register unsigned reg; | |
879 | register long offset; | |
a3f97cbb | 880 | { |
3f76745e JM |
881 | register dw_cfi_ref cfi; |
882 | unsigned long old_reg; | |
883 | long old_offset; | |
884 | ||
5bef9b1f JM |
885 | cfa_reg = reg; |
886 | cfa_offset = offset; | |
887 | if (cfa_store_reg == reg) | |
888 | cfa_store_offset = offset; | |
889 | ||
3f76745e JM |
890 | reg = DWARF_FRAME_REGNUM (reg); |
891 | lookup_cfa (&old_reg, &old_offset); | |
892 | ||
893 | if (reg == old_reg && offset == old_offset) | |
894 | return; | |
895 | ||
896 | cfi = new_cfi (); | |
897 | ||
898 | if (reg == old_reg) | |
a3f97cbb | 899 | { |
3f76745e JM |
900 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
901 | cfi->dw_cfi_oprnd1.dw_cfi_offset = offset; | |
902 | } | |
a3f97cbb | 903 | |
3f76745e JM |
904 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
905 | else if (offset == old_offset && old_reg != (unsigned long) -1) | |
906 | { | |
907 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; | |
908 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
909 | } | |
910 | #endif | |
a3f97cbb | 911 | |
3f76745e JM |
912 | else |
913 | { | |
914 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
915 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
916 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
a3f97cbb | 917 | } |
3f76745e JM |
918 | |
919 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
920 | } |
921 | ||
3f76745e JM |
922 | /* Add the CFI for saving a register. REG is the CFA column number. |
923 | LABEL is passed to add_fde_cfi. | |
924 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
925 | otherwise it is saved in SREG. */ | |
71dfc51f | 926 | |
3f76745e JM |
927 | static void |
928 | reg_save (label, reg, sreg, offset) | |
929 | register char * label; | |
930 | register unsigned reg; | |
931 | register unsigned sreg; | |
932 | register long offset; | |
a3f97cbb | 933 | { |
3f76745e JM |
934 | register dw_cfi_ref cfi = new_cfi (); |
935 | ||
936 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
937 | ||
85066503 MH |
938 | /* The following comparison is correct. -1 is used to indicate that |
939 | the value isn't a register number. */ | |
940 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 941 | { |
3f76745e JM |
942 | if (reg & ~0x3f) |
943 | /* The register number won't fit in 6 bits, so we have to use | |
944 | the long form. */ | |
945 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
946 | else | |
947 | cfi->dw_cfi_opc = DW_CFA_offset; | |
948 | ||
949 | offset /= DWARF_CIE_DATA_ALIGNMENT; | |
3a88cbd1 JL |
950 | if (offset < 0) |
951 | abort (); | |
3f76745e JM |
952 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
953 | } | |
954 | else | |
955 | { | |
956 | cfi->dw_cfi_opc = DW_CFA_register; | |
957 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
958 | } | |
959 | ||
960 | add_fde_cfi (label, cfi); | |
961 | } | |
962 | ||
c53aa195 JM |
963 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
964 | This CFI tells the unwinder that it needs to restore the window registers | |
965 | from the previous frame's window save area. | |
966 | ||
967 | ??? Perhaps we should note in the CIE where windows are saved (instead of | |
968 | assuming 0(cfa)) and what registers are in the window. */ | |
969 | ||
970 | void | |
971 | dwarf2out_window_save (label) | |
972 | register char * label; | |
973 | { | |
974 | register dw_cfi_ref cfi = new_cfi (); | |
975 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
976 | add_fde_cfi (label, cfi); | |
977 | } | |
978 | ||
0021b564 JM |
979 | /* Add a CFI to update the running total of the size of arguments |
980 | pushed onto the stack. */ | |
981 | ||
982 | void | |
983 | dwarf2out_args_size (label, size) | |
984 | char *label; | |
985 | long size; | |
986 | { | |
b57d9225 JM |
987 | register dw_cfi_ref cfi; |
988 | ||
989 | if (size == old_args_size) | |
990 | return; | |
991 | old_args_size = size; | |
992 | ||
993 | cfi = new_cfi (); | |
0021b564 JM |
994 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
995 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
996 | add_fde_cfi (label, cfi); | |
997 | } | |
998 | ||
c53aa195 JM |
999 | /* Entry point for saving a register to the stack. REG is the GCC register |
1000 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
1001 | |
1002 | void | |
1003 | dwarf2out_reg_save (label, reg, offset) | |
1004 | register char * label; | |
1005 | register unsigned reg; | |
1006 | register long offset; | |
1007 | { | |
1008 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
1009 | } | |
1010 | ||
c53aa195 JM |
1011 | /* Entry point for saving the return address in the stack. |
1012 | LABEL and OFFSET are passed to reg_save. */ | |
1013 | ||
1014 | void | |
1015 | dwarf2out_return_save (label, offset) | |
1016 | register char * label; | |
1017 | register long offset; | |
1018 | { | |
1019 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
1020 | } | |
1021 | ||
1022 | /* Entry point for saving the return address in a register. | |
1023 | LABEL and SREG are passed to reg_save. */ | |
1024 | ||
1025 | void | |
1026 | dwarf2out_return_reg (label, sreg) | |
1027 | register char * label; | |
1028 | register unsigned sreg; | |
1029 | { | |
1030 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
1031 | } | |
1032 | ||
3f76745e JM |
1033 | /* Record the initial position of the return address. RTL is |
1034 | INCOMING_RETURN_ADDR_RTX. */ | |
1035 | ||
1036 | static void | |
1037 | initial_return_save (rtl) | |
1038 | register rtx rtl; | |
1039 | { | |
973838fd | 1040 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
1041 | long offset = 0; |
1042 | ||
1043 | switch (GET_CODE (rtl)) | |
1044 | { | |
1045 | case REG: | |
1046 | /* RA is in a register. */ | |
1047 | reg = reg_number (rtl); | |
1048 | break; | |
1049 | case MEM: | |
1050 | /* RA is on the stack. */ | |
1051 | rtl = XEXP (rtl, 0); | |
1052 | switch (GET_CODE (rtl)) | |
1053 | { | |
1054 | case REG: | |
3a88cbd1 JL |
1055 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
1056 | abort (); | |
3f76745e JM |
1057 | offset = 0; |
1058 | break; | |
1059 | case PLUS: | |
3a88cbd1 JL |
1060 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1061 | abort (); | |
3f76745e JM |
1062 | offset = INTVAL (XEXP (rtl, 1)); |
1063 | break; | |
1064 | case MINUS: | |
3a88cbd1 JL |
1065 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1066 | abort (); | |
3f76745e JM |
1067 | offset = -INTVAL (XEXP (rtl, 1)); |
1068 | break; | |
1069 | default: | |
1070 | abort (); | |
1071 | } | |
1072 | break; | |
c53aa195 JM |
1073 | case PLUS: |
1074 | /* The return address is at some offset from any value we can | |
1075 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
1076 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
1077 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
1078 | abort (); | |
c53aa195 JM |
1079 | initial_return_save (XEXP (rtl, 0)); |
1080 | return; | |
a3f97cbb | 1081 | default: |
3f76745e | 1082 | abort (); |
a3f97cbb | 1083 | } |
3f76745e | 1084 | |
a6ab3aad | 1085 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset); |
a3f97cbb JW |
1086 | } |
1087 | ||
0021b564 JM |
1088 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1089 | make a note of it if it does. EH uses this information to find out how | |
1090 | much extra space it needs to pop off the stack. */ | |
1091 | ||
1092 | static void | |
1093 | dwarf2out_stack_adjust (insn) | |
1094 | rtx insn; | |
1095 | { | |
0021b564 JM |
1096 | long offset; |
1097 | char *label; | |
1098 | ||
b57d9225 JM |
1099 | if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN) |
1100 | { | |
1101 | /* Extract the size of the args from the CALL rtx itself. */ | |
1102 | ||
1103 | insn = PATTERN (insn); | |
1104 | if (GET_CODE (insn) == PARALLEL) | |
1105 | insn = XVECEXP (insn, 0, 0); | |
1106 | if (GET_CODE (insn) == SET) | |
1107 | insn = SET_SRC (insn); | |
1108 | assert (GET_CODE (insn) == CALL); | |
1109 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); | |
1110 | return; | |
1111 | } | |
1112 | ||
1113 | /* If only calls can throw, and we have a frame pointer, | |
1114 | save up adjustments until we see the CALL_INSN. */ | |
1115 | else if (! asynchronous_exceptions | |
1116 | && cfa_reg != STACK_POINTER_REGNUM) | |
1117 | return; | |
1118 | ||
6020d360 | 1119 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1120 | { |
6020d360 JM |
1121 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1122 | the compiler will have already emitted a stack adjustment, but | |
1123 | doesn't bother for calls to noreturn functions. */ | |
1124 | #ifdef STACK_GROWS_DOWNWARD | |
1125 | offset = -args_size; | |
1126 | #else | |
1127 | offset = args_size; | |
1128 | #endif | |
0021b564 | 1129 | } |
6020d360 | 1130 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 1131 | { |
6020d360 JM |
1132 | rtx src, dest; |
1133 | enum rtx_code code; | |
1134 | ||
1135 | insn = PATTERN (insn); | |
1136 | src = SET_SRC (insn); | |
1137 | dest = SET_DEST (insn); | |
0021b564 | 1138 | |
6020d360 JM |
1139 | if (dest == stack_pointer_rtx) |
1140 | { | |
1141 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
1142 | code = GET_CODE (src); | |
1143 | if (! (code == PLUS || code == MINUS) | |
1144 | || XEXP (src, 0) != stack_pointer_rtx | |
1145 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1146 | return; | |
1147 | ||
1148 | offset = INTVAL (XEXP (src, 1)); | |
1149 | } | |
1150 | else if (GET_CODE (dest) == MEM) | |
1151 | { | |
1152 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1153 | src = XEXP (dest, 0); | |
1154 | code = GET_CODE (src); | |
1155 | ||
1156 | if (! (code == PRE_DEC || code == PRE_INC) | |
1157 | || XEXP (src, 0) != stack_pointer_rtx) | |
1158 | return; | |
1159 | ||
1160 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1161 | } | |
1162 | else | |
0021b564 JM |
1163 | return; |
1164 | ||
6020d360 JM |
1165 | if (code == PLUS || code == PRE_INC) |
1166 | offset = -offset; | |
0021b564 JM |
1167 | } |
1168 | else | |
1169 | return; | |
1170 | ||
6020d360 JM |
1171 | if (offset == 0) |
1172 | return; | |
1173 | ||
0021b564 JM |
1174 | if (cfa_reg == STACK_POINTER_REGNUM) |
1175 | cfa_offset += offset; | |
1176 | ||
1177 | #ifndef STACK_GROWS_DOWNWARD | |
1178 | offset = -offset; | |
1179 | #endif | |
1180 | args_size += offset; | |
1181 | if (args_size < 0) | |
1182 | args_size = 0; | |
1183 | ||
1184 | label = dwarf2out_cfi_label (); | |
1185 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1186 | dwarf2out_args_size (label, args_size); | |
1187 | } | |
1188 | ||
3f76745e JM |
1189 | /* Record call frame debugging information for INSN, which either |
1190 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1191 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1192 | |
3f76745e JM |
1193 | void |
1194 | dwarf2out_frame_debug (insn) | |
1195 | rtx insn; | |
a3f97cbb | 1196 | { |
3f76745e JM |
1197 | char *label; |
1198 | rtx src, dest; | |
1199 | long offset; | |
1200 | ||
1201 | /* A temporary register used in adjusting SP or setting up the store_reg. */ | |
1202 | static unsigned cfa_temp_reg; | |
1203 | static long cfa_temp_value; | |
1204 | ||
1205 | if (insn == NULL_RTX) | |
a3f97cbb | 1206 | { |
3f76745e | 1207 | /* Set up state for generating call frame debug info. */ |
a6ab3aad | 1208 | lookup_cfa (&cfa_reg, &cfa_offset); |
3a88cbd1 JL |
1209 | if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) |
1210 | abort (); | |
3f76745e | 1211 | cfa_reg = STACK_POINTER_REGNUM; |
a6ab3aad JM |
1212 | cfa_store_reg = cfa_reg; |
1213 | cfa_store_offset = cfa_offset; | |
3f76745e JM |
1214 | cfa_temp_reg = -1; |
1215 | cfa_temp_value = 0; | |
1216 | return; | |
1217 | } | |
1218 | ||
0021b564 JM |
1219 | if (! RTX_FRAME_RELATED_P (insn)) |
1220 | { | |
6020d360 | 1221 | dwarf2out_stack_adjust (insn); |
0021b564 JM |
1222 | return; |
1223 | } | |
1224 | ||
3f76745e JM |
1225 | label = dwarf2out_cfi_label (); |
1226 | ||
07ebc930 RH |
1227 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1228 | if (src) | |
1229 | insn = XEXP (src, 0); | |
1230 | else | |
1231 | insn = PATTERN (insn); | |
1232 | ||
267c09ab JM |
1233 | /* Assume that in a PARALLEL prologue insn, only the first elt is |
1234 | significant. Currently this is true. */ | |
1235 | if (GET_CODE (insn) == PARALLEL) | |
1236 | insn = XVECEXP (insn, 0, 0); | |
3a88cbd1 JL |
1237 | if (GET_CODE (insn) != SET) |
1238 | abort (); | |
3f76745e JM |
1239 | |
1240 | src = SET_SRC (insn); | |
1241 | dest = SET_DEST (insn); | |
1242 | ||
1243 | switch (GET_CODE (dest)) | |
1244 | { | |
1245 | case REG: | |
1246 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
1247 | relative to the current CFA register. */ | |
1248 | switch (GET_CODE (src)) | |
1249 | { | |
1250 | /* Setting FP from SP. */ | |
1251 | case REG: | |
c84e2712 | 1252 | if (cfa_reg != (unsigned) REGNO (src)) |
3a88cbd1 JL |
1253 | abort (); |
1254 | if (REGNO (dest) != STACK_POINTER_REGNUM | |
1255 | && !(frame_pointer_needed | |
1256 | && REGNO (dest) == HARD_FRAME_POINTER_REGNUM)) | |
1257 | abort (); | |
3f76745e JM |
1258 | cfa_reg = REGNO (dest); |
1259 | break; | |
1260 | ||
1261 | case PLUS: | |
1262 | case MINUS: | |
1263 | if (dest == stack_pointer_rtx) | |
1264 | { | |
1265 | /* Adjusting SP. */ | |
1266 | switch (GET_CODE (XEXP (src, 1))) | |
1267 | { | |
1268 | case CONST_INT: | |
1269 | offset = INTVAL (XEXP (src, 1)); | |
1270 | break; | |
1271 | case REG: | |
c84e2712 | 1272 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg) |
3a88cbd1 | 1273 | abort (); |
3f76745e JM |
1274 | offset = cfa_temp_value; |
1275 | break; | |
1276 | default: | |
1277 | abort (); | |
1278 | } | |
1279 | ||
0021b564 JM |
1280 | if (XEXP (src, 0) == hard_frame_pointer_rtx) |
1281 | { | |
1282 | /* Restoring SP from FP in the epilogue. */ | |
c84e2712 | 1283 | if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
3a88cbd1 | 1284 | abort (); |
0021b564 JM |
1285 | cfa_reg = STACK_POINTER_REGNUM; |
1286 | } | |
3a88cbd1 JL |
1287 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1288 | abort (); | |
0021b564 | 1289 | |
3f76745e JM |
1290 | if (GET_CODE (src) == PLUS) |
1291 | offset = -offset; | |
1292 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1293 | cfa_offset += offset; | |
1294 | if (cfa_store_reg == STACK_POINTER_REGNUM) | |
1295 | cfa_store_offset += offset; | |
3f76745e | 1296 | } |
63d96a95 GK |
1297 | else if (dest == hard_frame_pointer_rtx) |
1298 | { | |
1299 | /* Either setting the FP from an offset of the SP, | |
1300 | or adjusting the FP */ | |
1301 | if (! frame_pointer_needed | |
1302 | || REGNO (dest) != HARD_FRAME_POINTER_REGNUM) | |
1303 | abort (); | |
1304 | ||
1305 | if (XEXP (src, 0) == stack_pointer_rtx | |
1306 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1307 | { | |
1308 | if (cfa_reg != STACK_POINTER_REGNUM) | |
1309 | abort (); | |
1310 | offset = INTVAL (XEXP (src, 1)); | |
1311 | if (GET_CODE (src) == PLUS) | |
1312 | offset = -offset; | |
1313 | cfa_offset += offset; | |
1314 | cfa_reg = HARD_FRAME_POINTER_REGNUM; | |
1315 | } | |
1316 | else if (XEXP (src, 0) == hard_frame_pointer_rtx | |
1317 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1318 | { | |
c84e2712 | 1319 | if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
63d96a95 GK |
1320 | abort (); |
1321 | offset = INTVAL (XEXP (src, 1)); | |
1322 | if (GET_CODE (src) == PLUS) | |
1323 | offset = -offset; | |
1324 | cfa_offset += offset; | |
1325 | } | |
1326 | ||
1327 | else | |
1328 | abort(); | |
1329 | } | |
3f76745e JM |
1330 | else |
1331 | { | |
3a88cbd1 | 1332 | if (GET_CODE (src) != PLUS |
31d52528 | 1333 | || XEXP (src, 1) != stack_pointer_rtx) |
3a88cbd1 JL |
1334 | abort (); |
1335 | if (GET_CODE (XEXP (src, 0)) != REG | |
c84e2712 | 1336 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg) |
3a88cbd1 | 1337 | abort (); |
218c2cdb JW |
1338 | if (cfa_reg != STACK_POINTER_REGNUM) |
1339 | abort (); | |
3f76745e | 1340 | cfa_store_reg = REGNO (dest); |
218c2cdb | 1341 | cfa_store_offset = cfa_offset - cfa_temp_value; |
3f76745e JM |
1342 | } |
1343 | break; | |
1344 | ||
1345 | case CONST_INT: | |
1346 | cfa_temp_reg = REGNO (dest); | |
1347 | cfa_temp_value = INTVAL (src); | |
1348 | break; | |
1349 | ||
ef76d03b | 1350 | case IOR: |
3a88cbd1 | 1351 | if (GET_CODE (XEXP (src, 0)) != REG |
c84e2712 KG |
1352 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg |
1353 | || (unsigned) REGNO (dest) != cfa_temp_reg | |
3a88cbd1 JL |
1354 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
1355 | abort (); | |
ef76d03b JW |
1356 | cfa_temp_value |= INTVAL (XEXP (src, 1)); |
1357 | break; | |
1358 | ||
3f76745e JM |
1359 | default: |
1360 | abort (); | |
1361 | } | |
1362 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1363 | break; | |
1364 | ||
1365 | case MEM: | |
1366 | /* Saving a register to the stack. Make sure dest is relative to the | |
1367 | CFA register. */ | |
3a88cbd1 JL |
1368 | if (GET_CODE (src) != REG) |
1369 | abort (); | |
3f76745e JM |
1370 | switch (GET_CODE (XEXP (dest, 0))) |
1371 | { | |
1372 | /* With a push. */ | |
1373 | case PRE_INC: | |
1374 | case PRE_DEC: | |
1375 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
0021b564 | 1376 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) |
3f76745e JM |
1377 | offset = -offset; |
1378 | ||
3a88cbd1 JL |
1379 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
1380 | || cfa_store_reg != STACK_POINTER_REGNUM) | |
1381 | abort (); | |
3f76745e JM |
1382 | cfa_store_offset += offset; |
1383 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1384 | cfa_offset = cfa_store_offset; | |
1385 | ||
1386 | offset = -cfa_store_offset; | |
1387 | break; | |
1388 | ||
1389 | /* With an offset. */ | |
1390 | case PLUS: | |
1391 | case MINUS: | |
1392 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); | |
1393 | if (GET_CODE (src) == MINUS) | |
1394 | offset = -offset; | |
1395 | ||
c84e2712 | 1396 | if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
3a88cbd1 | 1397 | abort (); |
3f76745e JM |
1398 | offset -= cfa_store_offset; |
1399 | break; | |
1400 | ||
07ebc930 RH |
1401 | /* Without an offset. */ |
1402 | case REG: | |
c84e2712 | 1403 | if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0))) |
07ebc930 RH |
1404 | abort(); |
1405 | offset = -cfa_store_offset; | |
1406 | break; | |
1407 | ||
3f76745e JM |
1408 | default: |
1409 | abort (); | |
1410 | } | |
1411 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1412 | dwarf2out_reg_save (label, REGNO (src), offset); | |
1413 | break; | |
1414 | ||
1415 | default: | |
1416 | abort (); | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | /* Return the size of an unsigned LEB128 quantity. */ | |
1421 | ||
1422 | static inline unsigned long | |
1423 | size_of_uleb128 (value) | |
1424 | register unsigned long value; | |
1425 | { | |
1426 | register unsigned long size = 0; | |
1427 | register unsigned byte; | |
1428 | ||
1429 | do | |
1430 | { | |
1431 | byte = (value & 0x7f); | |
1432 | value >>= 7; | |
1433 | size += 1; | |
1434 | } | |
1435 | while (value != 0); | |
1436 | ||
1437 | return size; | |
1438 | } | |
1439 | ||
1440 | /* Return the size of a signed LEB128 quantity. */ | |
1441 | ||
1442 | static inline unsigned long | |
1443 | size_of_sleb128 (value) | |
1444 | register long value; | |
1445 | { | |
1446 | register unsigned long size = 0; | |
1447 | register unsigned byte; | |
1448 | ||
1449 | do | |
1450 | { | |
1451 | byte = (value & 0x7f); | |
1452 | value >>= 7; | |
1453 | size += 1; | |
1454 | } | |
1455 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
1456 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1457 | ||
1458 | return size; | |
1459 | } | |
1460 | ||
3f76745e JM |
1461 | /* Output an unsigned LEB128 quantity. */ |
1462 | ||
1463 | static void | |
1464 | output_uleb128 (value) | |
1465 | register unsigned long value; | |
1466 | { | |
1467 | unsigned long save_value = value; | |
1468 | ||
1469 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1470 | do | |
1471 | { | |
1472 | register unsigned byte = (value & 0x7f); | |
1473 | value >>= 7; | |
1474 | if (value != 0) | |
1475 | /* More bytes to follow. */ | |
1476 | byte |= 0x80; | |
1477 | ||
1478 | fprintf (asm_out_file, "0x%x", byte); | |
1479 | if (value != 0) | |
1480 | fprintf (asm_out_file, ","); | |
1481 | } | |
1482 | while (value != 0); | |
1483 | ||
c5cec899 | 1484 | if (flag_debug_asm) |
2d8b0f3a | 1485 | fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value); |
3f76745e JM |
1486 | } |
1487 | ||
1488 | /* Output an signed LEB128 quantity. */ | |
1489 | ||
1490 | static void | |
1491 | output_sleb128 (value) | |
1492 | register long value; | |
1493 | { | |
1494 | register int more; | |
1495 | register unsigned byte; | |
1496 | long save_value = value; | |
1497 | ||
1498 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1499 | do | |
1500 | { | |
1501 | byte = (value & 0x7f); | |
1502 | /* arithmetic shift */ | |
1503 | value >>= 7; | |
1504 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
1505 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1506 | if (more) | |
1507 | byte |= 0x80; | |
1508 | ||
1509 | fprintf (asm_out_file, "0x%x", byte); | |
1510 | if (more) | |
1511 | fprintf (asm_out_file, ","); | |
1512 | } | |
1513 | ||
1514 | while (more); | |
c5cec899 | 1515 | if (flag_debug_asm) |
2d8b0f3a | 1516 | fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value); |
3f76745e JM |
1517 | } |
1518 | ||
1519 | /* Output a Call Frame Information opcode and its operand(s). */ | |
1520 | ||
1521 | static void | |
1522 | output_cfi (cfi, fde) | |
1523 | register dw_cfi_ref cfi; | |
1524 | register dw_fde_ref fde; | |
1525 | { | |
1526 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1527 | { | |
1528 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1529 | cfi->dw_cfi_opc | |
1530 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
c5cec899 | 1531 | if (flag_debug_asm) |
2d8b0f3a | 1532 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx", |
3f76745e JM |
1533 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset); |
1534 | fputc ('\n', asm_out_file); | |
1535 | } | |
1536 | ||
1537 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
1538 | { | |
1539 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1540 | cfi->dw_cfi_opc | |
1541 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1542 | if (flag_debug_asm) |
2d8b0f3a | 1543 | fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx", |
3f76745e JM |
1544 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1545 | ||
1546 | fputc ('\n', asm_out_file); | |
1547 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1548 | fputc ('\n', asm_out_file); | |
1549 | } | |
1550 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1551 | { | |
1552 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1553 | cfi->dw_cfi_opc | |
1554 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1555 | if (flag_debug_asm) |
2d8b0f3a | 1556 | fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx", |
3f76745e JM |
1557 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1558 | ||
1559 | fputc ('\n', asm_out_file); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
c5cec899 | 1564 | if (flag_debug_asm) |
3f76745e JM |
1565 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
1566 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
1567 | ||
1568 | fputc ('\n', asm_out_file); | |
1569 | switch (cfi->dw_cfi_opc) | |
1570 | { | |
1571 | case DW_CFA_set_loc: | |
1572 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr); | |
1573 | fputc ('\n', asm_out_file); | |
1574 | break; | |
1575 | case DW_CFA_advance_loc1: | |
bb727b5a JM |
1576 | ASM_OUTPUT_DWARF_DELTA1 (asm_out_file, |
1577 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1578 | fde->dw_fde_current_label); | |
1579 | fputc ('\n', asm_out_file); | |
1580 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e JM |
1581 | break; |
1582 | case DW_CFA_advance_loc2: | |
1583 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, | |
1584 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1585 | fde->dw_fde_current_label); | |
1586 | fputc ('\n', asm_out_file); | |
1587 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1588 | break; | |
1589 | case DW_CFA_advance_loc4: | |
1590 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
1591 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1592 | fde->dw_fde_current_label); | |
1593 | fputc ('\n', asm_out_file); | |
1594 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1595 | break; | |
1596 | #ifdef MIPS_DEBUGGING_INFO | |
1597 | case DW_CFA_MIPS_advance_loc8: | |
1598 | /* TODO: not currently implemented. */ | |
1599 | abort (); | |
1600 | break; | |
1601 | #endif | |
1602 | case DW_CFA_offset_extended: | |
1603 | case DW_CFA_def_cfa: | |
1604 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1605 | fputc ('\n', asm_out_file); | |
1606 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1607 | fputc ('\n', asm_out_file); | |
1608 | break; | |
1609 | case DW_CFA_restore_extended: | |
1610 | case DW_CFA_undefined: | |
1611 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1612 | fputc ('\n', asm_out_file); | |
1613 | break; | |
1614 | case DW_CFA_same_value: | |
1615 | case DW_CFA_def_cfa_register: | |
1616 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1617 | fputc ('\n', asm_out_file); | |
1618 | break; | |
1619 | case DW_CFA_register: | |
1620 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1621 | fputc ('\n', asm_out_file); | |
1622 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
1623 | fputc ('\n', asm_out_file); | |
1624 | break; | |
1625 | case DW_CFA_def_cfa_offset: | |
1626 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1627 | fputc ('\n', asm_out_file); | |
1628 | break; | |
c53aa195 JM |
1629 | case DW_CFA_GNU_window_save: |
1630 | break; | |
0021b564 JM |
1631 | case DW_CFA_GNU_args_size: |
1632 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1633 | fputc ('\n', asm_out_file); | |
1634 | break; | |
3f76745e JM |
1635 | default: |
1636 | break; | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | ||
0021b564 JM |
1641 | #if !defined (EH_FRAME_SECTION) |
1642 | #if defined (EH_FRAME_SECTION_ASM_OP) | |
1643 | #define EH_FRAME_SECTION() eh_frame_section(); | |
1644 | #else | |
1645 | #if defined (ASM_OUTPUT_SECTION_NAME) | |
1646 | #define EH_FRAME_SECTION() \ | |
1647 | do { \ | |
1648 | named_section (NULL_TREE, ".eh_frame", 0); \ | |
1649 | } while (0) | |
1650 | #endif | |
1651 | #endif | |
1652 | #endif | |
1653 | ||
d460fb3c JM |
1654 | /* If we aren't using crtstuff to run ctors, don't use it for EH. */ |
1655 | #if !defined (HAS_INIT_SECTION) && !defined (INIT_SECTION_ASM_OP) | |
1656 | #undef EH_FRAME_SECTION | |
1657 | #endif | |
1658 | ||
3f76745e JM |
1659 | /* Output the call frame information used to used to record information |
1660 | that relates to calculating the frame pointer, and records the | |
1661 | location of saved registers. */ | |
1662 | ||
1663 | static void | |
1664 | output_call_frame_info (for_eh) | |
1665 | int for_eh; | |
1666 | { | |
2d8b0f3a | 1667 | register unsigned long i; |
3f76745e | 1668 | register dw_fde_ref fde; |
3f76745e | 1669 | register dw_cfi_ref cfi; |
a6ab3aad | 1670 | char l1[20], l2[20]; |
2ed2af28 PDM |
1671 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1672 | char ld[20]; | |
1673 | #endif | |
a6ab3aad JM |
1674 | |
1675 | /* Do we want to include a pointer to the exception table? */ | |
1676 | int eh_ptr = for_eh && exception_table_p (); | |
3f76745e | 1677 | |
3f76745e | 1678 | fputc ('\n', asm_out_file); |
e9e30253 | 1679 | |
aa0c1401 JL |
1680 | /* We're going to be generating comments, so turn on app. */ |
1681 | if (flag_debug_asm) | |
1682 | app_enable (); | |
956d6950 | 1683 | |
3f76745e JM |
1684 | if (for_eh) |
1685 | { | |
1686 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1687 | EH_FRAME_SECTION (); |
3f76745e | 1688 | #else |
496651db | 1689 | tree label = get_file_function_name ('F'); |
0021b564 | 1690 | |
3167de5b | 1691 | force_data_section (); |
f4744807 | 1692 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
0021b564 JM |
1693 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1694 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1695 | #endif |
1696 | assemble_label ("__FRAME_BEGIN__"); | |
1697 | } | |
1698 | else | |
1699 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
1700 | ||
1701 | /* Output the CIE. */ | |
a6ab3aad JM |
1702 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1703 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2ed2af28 PDM |
1704 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1705 | ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh); | |
1706 | if (for_eh) | |
7bb9fb0e | 1707 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1708 | else |
1709 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1710 | #else | |
267c09ab JM |
1711 | if (for_eh) |
1712 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1713 | else | |
1714 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1715 | #endif |
c5cec899 | 1716 | if (flag_debug_asm) |
3f76745e JM |
1717 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", |
1718 | ASM_COMMENT_START); | |
1719 | ||
1720 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1721 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1722 | ||
d84e64d4 JM |
1723 | if (for_eh) |
1724 | /* Now that the CIE pointer is PC-relative for EH, | |
1725 | use 0 to identify the CIE. */ | |
1726 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
1727 | else | |
1728 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1729 | ||
c5cec899 | 1730 | if (flag_debug_asm) |
3f76745e JM |
1731 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START); |
1732 | ||
1733 | fputc ('\n', asm_out_file); | |
d84e64d4 | 1734 | if (! for_eh && DWARF_OFFSET_SIZE == 8) |
3f76745e JM |
1735 | { |
1736 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1737 | fputc ('\n', asm_out_file); | |
1738 | } | |
1739 | ||
1740 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
c5cec899 | 1741 | if (flag_debug_asm) |
3f76745e JM |
1742 | fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START); |
1743 | ||
1744 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1745 | if (eh_ptr) |
1746 | { | |
d84e64d4 JM |
1747 | /* The CIE contains a pointer to the exception region info for the |
1748 | frame. Make the augmentation string three bytes (including the | |
1749 | trailing null) so the pointer is 4-byte aligned. The Solaris ld | |
1750 | can't handle unaligned relocs. */ | |
c5cec899 | 1751 | if (flag_debug_asm) |
8d4e65a6 JL |
1752 | { |
1753 | ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh"); | |
1754 | fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START); | |
1755 | } | |
1756 | else | |
1757 | { | |
c2c85462 | 1758 | ASM_OUTPUT_ASCII (asm_out_file, "eh", 3); |
8d4e65a6 | 1759 | } |
d84e64d4 JM |
1760 | fputc ('\n', asm_out_file); |
1761 | ||
1762 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__"); | |
1763 | if (flag_debug_asm) | |
1764 | fprintf (asm_out_file, "\t%s pointer to exception region info", | |
1765 | ASM_COMMENT_START); | |
a6ab3aad JM |
1766 | } |
1767 | else | |
1768 | { | |
1769 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 1770 | if (flag_debug_asm) |
a6ab3aad JM |
1771 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", |
1772 | ASM_COMMENT_START); | |
1773 | } | |
3f76745e JM |
1774 | |
1775 | fputc ('\n', asm_out_file); | |
1776 | output_uleb128 (1); | |
c5cec899 | 1777 | if (flag_debug_asm) |
3f76745e JM |
1778 | fprintf (asm_out_file, " (CIE Code Alignment Factor)"); |
1779 | ||
1780 | fputc ('\n', asm_out_file); | |
1781 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
c5cec899 | 1782 | if (flag_debug_asm) |
3f76745e JM |
1783 | fprintf (asm_out_file, " (CIE Data Alignment Factor)"); |
1784 | ||
1785 | fputc ('\n', asm_out_file); | |
1786 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN); | |
c5cec899 | 1787 | if (flag_debug_asm) |
3f76745e JM |
1788 | fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START); |
1789 | ||
1790 | fputc ('\n', asm_out_file); | |
1791 | ||
1792 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1793 | output_cfi (cfi, NULL); | |
1794 | ||
1795 | /* Pad the CIE out to an address sized boundary. */ | |
a6ab3aad JM |
1796 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
1797 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
2ed2af28 PDM |
1798 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1799 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1800 | if (flag_debug_asm) |
1801 | fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START); | |
1802 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1803 | #endif |
3f76745e JM |
1804 | |
1805 | /* Loop through all of the FDE's. */ | |
1806 | for (i = 0; i < fde_table_in_use; ++i) | |
1807 | { | |
1808 | fde = &fde_table[i]; | |
3f76745e | 1809 | |
a6ab3aad JM |
1810 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2); |
1811 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2); | |
2ed2af28 PDM |
1812 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1813 | ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2); | |
1814 | if (for_eh) | |
7bb9fb0e | 1815 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1816 | else |
1817 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1818 | #else | |
267c09ab JM |
1819 | if (for_eh) |
1820 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1821 | else | |
1822 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1823 | #endif |
c5cec899 | 1824 | if (flag_debug_asm) |
3f76745e | 1825 | fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START); |
3f76745e | 1826 | fputc ('\n', asm_out_file); |
a6ab3aad JM |
1827 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1828 | ||
eef906d6 JW |
1829 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1830 | emits a target dependent sized offset when for_eh is not true. | |
1831 | This inconsistency may confuse gdb. The only case where we need a | |
1832 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1833 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1834 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1835 | If the for_eh case is changed, then the struct in frame.c has | |
1836 | to be adjusted appropriately. */ | |
3f76745e | 1837 | if (for_eh) |
21af493b | 1838 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__"); |
3f76745e JM |
1839 | else |
1840 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION)); | |
c5cec899 | 1841 | if (flag_debug_asm) |
3f76745e JM |
1842 | fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START); |
1843 | ||
1844 | fputc ('\n', asm_out_file); | |
1845 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
c5cec899 | 1846 | if (flag_debug_asm) |
3f76745e JM |
1847 | fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START); |
1848 | ||
1849 | fputc ('\n', asm_out_file); | |
1850 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, | |
1851 | fde->dw_fde_end, fde->dw_fde_begin); | |
c5cec899 | 1852 | if (flag_debug_asm) |
3f76745e JM |
1853 | fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START); |
1854 | ||
1855 | fputc ('\n', asm_out_file); | |
1856 | ||
1857 | /* Loop through the Call Frame Instructions associated with | |
1858 | this FDE. */ | |
1859 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1860 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1861 | output_cfi (cfi, fde); | |
1862 | ||
a6ab3aad JM |
1863 | /* Pad the FDE out to an address sized boundary. */ |
1864 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1865 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
2ed2af28 PDM |
1866 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1867 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1868 | if (flag_debug_asm) |
1869 | fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START); | |
1870 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1871 | #endif |
3f76745e JM |
1872 | } |
1873 | #ifndef EH_FRAME_SECTION | |
1874 | if (for_eh) | |
1875 | { | |
1876 | /* Emit terminating zero for table. */ | |
267c09ab | 1877 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
3f76745e JM |
1878 | fputc ('\n', asm_out_file); |
1879 | } | |
1880 | #endif | |
a6ab3aad JM |
1881 | #ifdef MIPS_DEBUGGING_INFO |
1882 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1883 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1884 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1885 | #endif | |
aa0c1401 JL |
1886 | |
1887 | /* Turn off app to make assembly quicker. */ | |
1888 | if (flag_debug_asm) | |
1889 | app_disable (); | |
a6ab3aad JM |
1890 | } |
1891 | ||
3f76745e JM |
1892 | /* Output a marker (i.e. a label) for the beginning of a function, before |
1893 | the prologue. */ | |
1894 | ||
1895 | void | |
1896 | dwarf2out_begin_prologue () | |
1897 | { | |
1898 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1899 | register dw_fde_ref fde; | |
1900 | ||
4f988ea2 JM |
1901 | ++current_funcdef_number; |
1902 | ||
3f76745e JM |
1903 | function_section (current_function_decl); |
1904 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
1905 | current_funcdef_number); | |
1906 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1907 | ||
1908 | /* Expand the fde table if necessary. */ | |
1909 | if (fde_table_in_use == fde_table_allocated) | |
1910 | { | |
1911 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
1912 | fde_table | |
1913 | = (dw_fde_ref) xrealloc (fde_table, | |
1914 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 1915 | } |
3f76745e JM |
1916 | |
1917 | /* Record the FDE associated with this function. */ | |
1918 | current_funcdef_fde = fde_table_in_use; | |
1919 | ||
1920 | /* Add the new FDE at the end of the fde_table. */ | |
1921 | fde = &fde_table[fde_table_in_use++]; | |
1922 | fde->dw_fde_begin = xstrdup (label); | |
1923 | fde->dw_fde_current_label = NULL; | |
1924 | fde->dw_fde_end = NULL; | |
1925 | fde->dw_fde_cfi = NULL; | |
0021b564 | 1926 | |
b57d9225 | 1927 | args_size = old_args_size = 0; |
3f76745e JM |
1928 | } |
1929 | ||
1930 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
1931 | for a function definition. This gets called *after* the epilogue code has | |
1932 | been generated. */ | |
1933 | ||
1934 | void | |
1935 | dwarf2out_end_epilogue () | |
1936 | { | |
1937 | dw_fde_ref fde; | |
1938 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1939 | ||
1940 | /* Output a label to mark the endpoint of the code generated for this | |
1941 | function. */ | |
1942 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
1943 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1944 | fde = &fde_table[fde_table_in_use - 1]; | |
1945 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
1946 | } |
1947 | ||
1948 | void | |
1949 | dwarf2out_frame_init () | |
1950 | { | |
1951 | /* Allocate the initial hunk of the fde_table. */ | |
1952 | fde_table | |
1953 | = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1954 | bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1955 | fde_table_allocated = FDE_TABLE_INCREMENT; | |
1956 | fde_table_in_use = 0; | |
1957 | ||
1958 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
1959 | sake of lookup_cfa. */ | |
1960 | ||
a6ab3aad | 1961 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
1962 | /* On entry, the Canonical Frame Address is at SP. */ |
1963 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
1964 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
1965 | #endif |
1966 | } | |
1967 | ||
1968 | void | |
1969 | dwarf2out_frame_finish () | |
1970 | { | |
3f76745e | 1971 | /* Output call frame information. */ |
a6ab3aad | 1972 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
1973 | if (write_symbols == DWARF2_DEBUG) |
1974 | output_call_frame_info (0); | |
1975 | if (flag_exceptions && ! exceptions_via_longjmp) | |
1976 | output_call_frame_info (1); | |
a6ab3aad JM |
1977 | #else |
1978 | if (write_symbols == DWARF2_DEBUG | |
1979 | || (flag_exceptions && ! exceptions_via_longjmp)) | |
1980 | output_call_frame_info (1); | |
1981 | #endif | |
3f76745e JM |
1982 | } |
1983 | ||
1984 | #endif /* .debug_frame support */ | |
1985 | ||
1986 | /* And now, the support for symbolic debugging information. */ | |
1987 | #ifdef DWARF2_DEBUGGING_INFO | |
1988 | ||
e179bf0f | 1989 | extern char *getpwd PROTO((void)); |
3f76745e JM |
1990 | |
1991 | /* NOTE: In the comments in this file, many references are made to | |
1992 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
1993 | throughout the remainder of this file. */ | |
1994 | ||
1995 | /* An internal representation of the DWARF output is built, and then | |
1996 | walked to generate the DWARF debugging info. The walk of the internal | |
1997 | representation is done after the entire program has been compiled. | |
1998 | The types below are used to describe the internal representation. */ | |
1999 | ||
2000 | /* Each DIE may have a series of attribute/value pairs. Values | |
2001 | can take on several forms. The forms that are used in this | |
2002 | implementation are listed below. */ | |
2003 | ||
2004 | typedef enum | |
2005 | { | |
2006 | dw_val_class_addr, | |
2007 | dw_val_class_loc, | |
2008 | dw_val_class_const, | |
2009 | dw_val_class_unsigned_const, | |
2010 | dw_val_class_long_long, | |
2011 | dw_val_class_float, | |
2012 | dw_val_class_flag, | |
2013 | dw_val_class_die_ref, | |
2014 | dw_val_class_fde_ref, | |
2015 | dw_val_class_lbl_id, | |
2016 | dw_val_class_section_offset, | |
2017 | dw_val_class_str | |
a3f97cbb | 2018 | } |
3f76745e | 2019 | dw_val_class; |
a3f97cbb | 2020 | |
3f76745e JM |
2021 | /* Various DIE's use offsets relative to the beginning of the |
2022 | .debug_info section to refer to each other. */ | |
71dfc51f | 2023 | |
3f76745e JM |
2024 | typedef long int dw_offset; |
2025 | ||
2026 | /* Define typedefs here to avoid circular dependencies. */ | |
2027 | ||
2028 | typedef struct die_struct *dw_die_ref; | |
2029 | typedef struct dw_attr_struct *dw_attr_ref; | |
2030 | typedef struct dw_val_struct *dw_val_ref; | |
2031 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
2032 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
2033 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
2034 | typedef struct pubname_struct *pubname_ref; | |
2035 | typedef dw_die_ref *arange_ref; | |
2036 | ||
2037 | /* Describe a double word constant value. */ | |
2038 | ||
2039 | typedef struct dw_long_long_struct | |
a3f97cbb | 2040 | { |
3f76745e JM |
2041 | unsigned long hi; |
2042 | unsigned long low; | |
2043 | } | |
2044 | dw_long_long_const; | |
2045 | ||
2046 | /* Describe a floating point constant value. */ | |
2047 | ||
2048 | typedef struct dw_fp_struct | |
2049 | { | |
2050 | long *array; | |
2051 | unsigned length; | |
2052 | } | |
2053 | dw_float_const; | |
2054 | ||
2055 | /* Each entry in the line_info_table maintains the file and | |
956d6950 | 2056 | line number associated with the label generated for that |
3f76745e JM |
2057 | entry. The label gives the PC value associated with |
2058 | the line number entry. */ | |
2059 | ||
2060 | typedef struct dw_line_info_struct | |
2061 | { | |
2062 | unsigned long dw_file_num; | |
2063 | unsigned long dw_line_num; | |
2064 | } | |
2065 | dw_line_info_entry; | |
2066 | ||
2067 | /* Line information for functions in separate sections; each one gets its | |
2068 | own sequence. */ | |
2069 | typedef struct dw_separate_line_info_struct | |
2070 | { | |
2071 | unsigned long dw_file_num; | |
2072 | unsigned long dw_line_num; | |
2073 | unsigned long function; | |
2074 | } | |
2075 | dw_separate_line_info_entry; | |
2076 | ||
956d6950 | 2077 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2078 | represented internally. */ |
2079 | ||
2080 | typedef struct dw_val_struct | |
2081 | { | |
2082 | dw_val_class val_class; | |
2083 | union | |
a3f97cbb | 2084 | { |
3f76745e JM |
2085 | char *val_addr; |
2086 | dw_loc_descr_ref val_loc; | |
2087 | long int val_int; | |
2088 | long unsigned val_unsigned; | |
2089 | dw_long_long_const val_long_long; | |
2090 | dw_float_const val_float; | |
2091 | dw_die_ref val_die_ref; | |
2092 | unsigned val_fde_index; | |
2093 | char *val_str; | |
2094 | char *val_lbl_id; | |
1553e85a | 2095 | char *val_section; |
3f76745e | 2096 | unsigned char val_flag; |
a3f97cbb | 2097 | } |
3f76745e JM |
2098 | v; |
2099 | } | |
2100 | dw_val_node; | |
2101 | ||
2102 | /* Locations in memory are described using a sequence of stack machine | |
2103 | operations. */ | |
2104 | ||
2105 | typedef struct dw_loc_descr_struct | |
2106 | { | |
2107 | dw_loc_descr_ref dw_loc_next; | |
2108 | enum dwarf_location_atom dw_loc_opc; | |
2109 | dw_val_node dw_loc_oprnd1; | |
2110 | dw_val_node dw_loc_oprnd2; | |
2111 | } | |
2112 | dw_loc_descr_node; | |
2113 | ||
2114 | /* Each DIE attribute has a field specifying the attribute kind, | |
2115 | a link to the next attribute in the chain, and an attribute value. | |
2116 | Attributes are typically linked below the DIE they modify. */ | |
2117 | ||
2118 | typedef struct dw_attr_struct | |
2119 | { | |
2120 | enum dwarf_attribute dw_attr; | |
2121 | dw_attr_ref dw_attr_next; | |
2122 | dw_val_node dw_attr_val; | |
2123 | } | |
2124 | dw_attr_node; | |
2125 | ||
2126 | /* The Debugging Information Entry (DIE) structure */ | |
2127 | ||
2128 | typedef struct die_struct | |
2129 | { | |
2130 | enum dwarf_tag die_tag; | |
2131 | dw_attr_ref die_attr; | |
2132 | dw_attr_ref die_attr_last; | |
2133 | dw_die_ref die_parent; | |
2134 | dw_die_ref die_child; | |
2135 | dw_die_ref die_child_last; | |
2136 | dw_die_ref die_sib; | |
2137 | dw_offset die_offset; | |
2138 | unsigned long die_abbrev; | |
a3f97cbb | 2139 | } |
3f76745e JM |
2140 | die_node; |
2141 | ||
2142 | /* The pubname structure */ | |
2143 | ||
2144 | typedef struct pubname_struct | |
2145 | { | |
2146 | dw_die_ref die; | |
2147 | char * name; | |
2148 | } | |
2149 | pubname_entry; | |
2150 | ||
ef76d03b JW |
2151 | /* The limbo die list structure. */ |
2152 | typedef struct limbo_die_struct | |
2153 | { | |
2154 | dw_die_ref die; | |
2155 | struct limbo_die_struct *next; | |
2156 | } | |
2157 | limbo_die_node; | |
2158 | ||
3f76745e JM |
2159 | /* How to start an assembler comment. */ |
2160 | #ifndef ASM_COMMENT_START | |
2161 | #define ASM_COMMENT_START ";#" | |
2162 | #endif | |
2163 | ||
2164 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
2165 | implicitly generated for a tagged type. | |
2166 | ||
2167 | Note that unlike the gcc front end (which generates a NULL named | |
2168 | TYPE_DECL node for each complete tagged type, each array type, and | |
2169 | each function type node created) the g++ front end generates a | |
2170 | _named_ TYPE_DECL node for each tagged type node created. | |
2171 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
2172 | generate a DW_TAG_typedef DIE for them. */ | |
2173 | ||
2174 | #define TYPE_DECL_IS_STUB(decl) \ | |
2175 | (DECL_NAME (decl) == NULL_TREE \ | |
2176 | || (DECL_ARTIFICIAL (decl) \ | |
2177 | && is_tagged_type (TREE_TYPE (decl)) \ | |
ef76d03b JW |
2178 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ |
2179 | /* This is necessary for stub decls that \ | |
2180 | appear in nested inline functions. */ \ | |
2181 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
2182 | && (decl_ultimate_origin (decl) \ | |
2183 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3f76745e JM |
2184 | |
2185 | /* Information concerning the compilation unit's programming | |
2186 | language, and compiler version. */ | |
2187 | ||
2188 | extern int flag_traditional; | |
2189 | extern char *version_string; | |
2190 | extern char *language_string; | |
2191 | ||
2192 | /* Fixed size portion of the DWARF compilation unit header. */ | |
2193 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
2194 | ||
2195 | /* Fixed size portion of debugging line information prolog. */ | |
2196 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
2197 | ||
2198 | /* Fixed size portion of public names info. */ | |
2199 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
2200 | ||
2201 | /* Fixed size portion of the address range info. */ | |
2202 | #define DWARF_ARANGES_HEADER_SIZE \ | |
2203 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE) | |
2204 | ||
2205 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
2206 | In this implementation of DWARF, this field is used for information | |
2207 | purposes only. Since GCC generates assembly language, we have | |
2208 | no a priori knowledge of how many instruction bytes are generated | |
2209 | for each source line, and therefore can use only the DW_LNE_set_address | |
2210 | and DW_LNS_fixed_advance_pc line information commands. */ | |
2211 | ||
2212 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
2213 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
2214 | #endif | |
2215 | ||
2216 | /* Minimum line offset in a special line info. opcode. | |
2217 | This value was chosen to give a reasonable range of values. */ | |
2218 | #define DWARF_LINE_BASE -10 | |
2219 | ||
2220 | /* First special line opcde - leave room for the standard opcodes. */ | |
2221 | #define DWARF_LINE_OPCODE_BASE 10 | |
2222 | ||
2223 | /* Range of line offsets in a special line info. opcode. */ | |
2224 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
2225 | ||
2226 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
2227 | In the present implementation, we do not mark any lines as | |
2228 | the beginning of a source statement, because that information | |
2229 | is not made available by the GCC front-end. */ | |
2230 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
2231 | ||
2232 | /* This location is used by calc_die_sizes() to keep track | |
2233 | the offset of each DIE within the .debug_info section. */ | |
2234 | static unsigned long next_die_offset; | |
2235 | ||
2236 | /* Record the root of the DIE's built for the current compilation unit. */ | |
2237 | static dw_die_ref comp_unit_die; | |
2238 | ||
ef76d03b JW |
2239 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
2240 | static limbo_die_node *limbo_die_list = 0; | |
3f76745e JM |
2241 | |
2242 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
2243 | static char **file_table; | |
2244 | ||
2245 | /* Total number of entries in the table (i.e. array) pointed to by | |
2246 | `file_table'. This is the *total* and includes both used and unused | |
2247 | slots. */ | |
2248 | static unsigned file_table_allocated; | |
a3f97cbb | 2249 | |
3f76745e JM |
2250 | /* Number of entries in the file_table which are actually in use. */ |
2251 | static unsigned file_table_in_use; | |
71dfc51f | 2252 | |
3f76745e JM |
2253 | /* Size (in elements) of increments by which we may expand the filename |
2254 | table. */ | |
2255 | #define FILE_TABLE_INCREMENT 64 | |
71dfc51f | 2256 | |
3f76745e JM |
2257 | /* Local pointer to the name of the main input file. Initialized in |
2258 | dwarf2out_init. */ | |
2259 | static char *primary_filename; | |
a3f97cbb | 2260 | |
3f76745e JM |
2261 | /* For Dwarf output, we must assign lexical-blocks id numbers in the order in |
2262 | which their beginnings are encountered. We output Dwarf debugging info | |
2263 | that refers to the beginnings and ends of the ranges of code for each | |
2264 | lexical block. The labels themselves are generated in final.c, which | |
2265 | assigns numbers to the blocks in the same way. */ | |
2266 | static unsigned next_block_number = 2; | |
a3f97cbb | 2267 | |
3f76745e JM |
2268 | /* A pointer to the base of a table of references to DIE's that describe |
2269 | declarations. The table is indexed by DECL_UID() which is a unique | |
956d6950 | 2270 | number identifying each decl. */ |
3f76745e | 2271 | static dw_die_ref *decl_die_table; |
71dfc51f | 2272 | |
3f76745e JM |
2273 | /* Number of elements currently allocated for the decl_die_table. */ |
2274 | static unsigned decl_die_table_allocated; | |
a3f97cbb | 2275 | |
3f76745e JM |
2276 | /* Number of elements in decl_die_table currently in use. */ |
2277 | static unsigned decl_die_table_in_use; | |
71dfc51f | 2278 | |
3f76745e JM |
2279 | /* Size (in elements) of increments by which we may expand the |
2280 | decl_die_table. */ | |
2281 | #define DECL_DIE_TABLE_INCREMENT 256 | |
a3f97cbb | 2282 | |
e3e7774e JW |
2283 | /* Structure used for the decl_scope table. scope is the current declaration |
2284 | scope, and previous is the entry that is the parent of this scope. This | |
2285 | is usually but not always the immediately preceeding entry. */ | |
2286 | ||
2287 | typedef struct decl_scope_struct | |
2288 | { | |
2289 | tree scope; | |
2290 | int previous; | |
2291 | } | |
2292 | decl_scope_node; | |
2293 | ||
3f76745e JM |
2294 | /* A pointer to the base of a table of references to declaration |
2295 | scopes. This table is a display which tracks the nesting | |
2296 | of declaration scopes at the current scope and containing | |
2297 | scopes. This table is used to find the proper place to | |
2298 | define type declaration DIE's. */ | |
e3e7774e | 2299 | static decl_scope_node *decl_scope_table; |
a3f97cbb | 2300 | |
3f76745e | 2301 | /* Number of elements currently allocated for the decl_scope_table. */ |
e3e7774e | 2302 | static int decl_scope_table_allocated; |
71dfc51f | 2303 | |
956d6950 | 2304 | /* Current level of nesting of declaration scopes. */ |
e3e7774e | 2305 | static int decl_scope_depth; |
bdb669cb | 2306 | |
3f76745e JM |
2307 | /* Size (in elements) of increments by which we may expand the |
2308 | decl_scope_table. */ | |
2309 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
bdb669cb | 2310 | |
3f76745e JM |
2311 | /* A pointer to the base of a list of references to DIE's that |
2312 | are uniquely identified by their tag, presence/absence of | |
2313 | children DIE's, and list of attribute/value pairs. */ | |
2314 | static dw_die_ref *abbrev_die_table; | |
71dfc51f | 2315 | |
3f76745e JM |
2316 | /* Number of elements currently allocated for abbrev_die_table. */ |
2317 | static unsigned abbrev_die_table_allocated; | |
bdb669cb | 2318 | |
3f76745e JM |
2319 | /* Number of elements in type_die_table currently in use. */ |
2320 | static unsigned abbrev_die_table_in_use; | |
bdb669cb | 2321 | |
3f76745e JM |
2322 | /* Size (in elements) of increments by which we may expand the |
2323 | abbrev_die_table. */ | |
2324 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
71dfc51f | 2325 | |
3f76745e JM |
2326 | /* A pointer to the base of a table that contains line information |
2327 | for each source code line in .text in the compilation unit. */ | |
2328 | static dw_line_info_ref line_info_table; | |
a3f97cbb | 2329 | |
3f76745e JM |
2330 | /* Number of elements currently allocated for line_info_table. */ |
2331 | static unsigned line_info_table_allocated; | |
71dfc51f | 2332 | |
3f76745e JM |
2333 | /* Number of elements in separate_line_info_table currently in use. */ |
2334 | static unsigned separate_line_info_table_in_use; | |
71dfc51f | 2335 | |
3f76745e JM |
2336 | /* A pointer to the base of a table that contains line information |
2337 | for each source code line outside of .text in the compilation unit. */ | |
2338 | static dw_separate_line_info_ref separate_line_info_table; | |
a3f97cbb | 2339 | |
3f76745e JM |
2340 | /* Number of elements currently allocated for separate_line_info_table. */ |
2341 | static unsigned separate_line_info_table_allocated; | |
71dfc51f | 2342 | |
3f76745e JM |
2343 | /* Number of elements in line_info_table currently in use. */ |
2344 | static unsigned line_info_table_in_use; | |
71dfc51f | 2345 | |
3f76745e JM |
2346 | /* Size (in elements) of increments by which we may expand the |
2347 | line_info_table. */ | |
2348 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
a3f97cbb | 2349 | |
3f76745e JM |
2350 | /* A pointer to the base of a table that contains a list of publicly |
2351 | accessible names. */ | |
2352 | static pubname_ref pubname_table; | |
71dfc51f | 2353 | |
3f76745e JM |
2354 | /* Number of elements currently allocated for pubname_table. */ |
2355 | static unsigned pubname_table_allocated; | |
2356 | ||
2357 | /* Number of elements in pubname_table currently in use. */ | |
2358 | static unsigned pubname_table_in_use; | |
2359 | ||
2360 | /* Size (in elements) of increments by which we may expand the | |
2361 | pubname_table. */ | |
2362 | #define PUBNAME_TABLE_INCREMENT 64 | |
2363 | ||
2364 | /* A pointer to the base of a table that contains a list of publicly | |
2365 | accessible names. */ | |
2366 | static arange_ref arange_table; | |
71dfc51f | 2367 | |
3f76745e JM |
2368 | /* Number of elements currently allocated for arange_table. */ |
2369 | static unsigned arange_table_allocated; | |
a3f97cbb | 2370 | |
3f76745e JM |
2371 | /* Number of elements in arange_table currently in use. */ |
2372 | static unsigned arange_table_in_use; | |
71dfc51f | 2373 | |
3f76745e JM |
2374 | /* Size (in elements) of increments by which we may expand the |
2375 | arange_table. */ | |
2376 | #define ARANGE_TABLE_INCREMENT 64 | |
71dfc51f | 2377 | |
3f76745e JM |
2378 | /* A pointer to the base of a list of pending types which we haven't |
2379 | generated DIEs for yet, but which we will have to come back to | |
2380 | later on. */ | |
469ac993 | 2381 | |
3f76745e | 2382 | static tree *pending_types_list; |
71dfc51f | 2383 | |
3f76745e JM |
2384 | /* Number of elements currently allocated for the pending_types_list. */ |
2385 | static unsigned pending_types_allocated; | |
71dfc51f | 2386 | |
3f76745e JM |
2387 | /* Number of elements of pending_types_list currently in use. */ |
2388 | static unsigned pending_types; | |
a3f97cbb | 2389 | |
3f76745e JM |
2390 | /* Size (in elements) of increments by which we may expand the pending |
2391 | types list. Actually, a single hunk of space of this size should | |
2392 | be enough for most typical programs. */ | |
2393 | #define PENDING_TYPES_INCREMENT 64 | |
71dfc51f | 2394 | |
3f76745e JM |
2395 | /* Record whether the function being analyzed contains inlined functions. */ |
2396 | static int current_function_has_inlines; | |
2d8b0f3a | 2397 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
3f76745e | 2398 | static int comp_unit_has_inlines; |
2d8b0f3a | 2399 | #endif |
71dfc51f | 2400 | |
3f76745e JM |
2401 | /* A pointer to the ..._DECL node which we have most recently been working |
2402 | on. We keep this around just in case something about it looks screwy and | |
2403 | we want to tell the user what the source coordinates for the actual | |
2404 | declaration are. */ | |
2405 | static tree dwarf_last_decl; | |
a3f97cbb | 2406 | |
3f76745e | 2407 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 2408 | |
b170964a | 2409 | static void addr_const_to_string PROTO((dyn_string_t, rtx)); |
3f76745e JM |
2410 | static char *addr_to_string PROTO((rtx)); |
2411 | static int is_pseudo_reg PROTO((rtx)); | |
2412 | static tree type_main_variant PROTO((tree)); | |
2413 | static int is_tagged_type PROTO((tree)); | |
2414 | static char *dwarf_tag_name PROTO((unsigned)); | |
2415 | static char *dwarf_attr_name PROTO((unsigned)); | |
2416 | static char *dwarf_form_name PROTO((unsigned)); | |
2417 | static char *dwarf_stack_op_name PROTO((unsigned)); | |
487a6e06 | 2418 | #if 0 |
3f76745e | 2419 | static char *dwarf_type_encoding_name PROTO((unsigned)); |
487a6e06 | 2420 | #endif |
3f76745e JM |
2421 | static tree decl_ultimate_origin PROTO((tree)); |
2422 | static tree block_ultimate_origin PROTO((tree)); | |
2423 | static tree decl_class_context PROTO((tree)); | |
2424 | static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref)); | |
2425 | static void add_AT_flag PROTO((dw_die_ref, | |
2426 | enum dwarf_attribute, | |
2427 | unsigned)); | |
2428 | static void add_AT_int PROTO((dw_die_ref, | |
2429 | enum dwarf_attribute, long)); | |
2430 | static void add_AT_unsigned PROTO((dw_die_ref, | |
2431 | enum dwarf_attribute, | |
2432 | unsigned long)); | |
2433 | static void add_AT_long_long PROTO((dw_die_ref, | |
2434 | enum dwarf_attribute, | |
2435 | unsigned long, unsigned long)); | |
2436 | static void add_AT_float PROTO((dw_die_ref, | |
2437 | enum dwarf_attribute, | |
2438 | unsigned, long *)); | |
2439 | static void add_AT_string PROTO((dw_die_ref, | |
2440 | enum dwarf_attribute, char *)); | |
2441 | static void add_AT_die_ref PROTO((dw_die_ref, | |
2442 | enum dwarf_attribute, | |
2443 | dw_die_ref)); | |
2444 | static void add_AT_fde_ref PROTO((dw_die_ref, | |
2445 | enum dwarf_attribute, | |
2446 | unsigned)); | |
2447 | static void add_AT_loc PROTO((dw_die_ref, | |
2448 | enum dwarf_attribute, | |
2449 | dw_loc_descr_ref)); | |
2450 | static void add_AT_addr PROTO((dw_die_ref, | |
2451 | enum dwarf_attribute, char *)); | |
2452 | static void add_AT_lbl_id PROTO((dw_die_ref, | |
2453 | enum dwarf_attribute, char *)); | |
956d6950 | 2454 | static void add_AT_section_offset PROTO((dw_die_ref, |
3f76745e JM |
2455 | enum dwarf_attribute, char *)); |
2456 | static int is_extern_subr_die PROTO((dw_die_ref)); | |
2457 | static dw_attr_ref get_AT PROTO((dw_die_ref, | |
2458 | enum dwarf_attribute)); | |
2459 | static char *get_AT_low_pc PROTO((dw_die_ref)); | |
2460 | static char *get_AT_hi_pc PROTO((dw_die_ref)); | |
2461 | static char *get_AT_string PROTO((dw_die_ref, | |
2462 | enum dwarf_attribute)); | |
2463 | static int get_AT_flag PROTO((dw_die_ref, | |
2464 | enum dwarf_attribute)); | |
2465 | static unsigned get_AT_unsigned PROTO((dw_die_ref, | |
2466 | enum dwarf_attribute)); | |
2467 | static int is_c_family PROTO((void)); | |
2468 | static int is_fortran PROTO((void)); | |
2469 | static void remove_AT PROTO((dw_die_ref, | |
2470 | enum dwarf_attribute)); | |
2471 | static void remove_children PROTO((dw_die_ref)); | |
2472 | static void add_child_die PROTO((dw_die_ref, dw_die_ref)); | |
2473 | static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref)); | |
2474 | static dw_die_ref lookup_type_die PROTO((tree)); | |
2475 | static void equate_type_number_to_die PROTO((tree, dw_die_ref)); | |
2476 | static dw_die_ref lookup_decl_die PROTO((tree)); | |
2477 | static void equate_decl_number_to_die PROTO((tree, dw_die_ref)); | |
2478 | static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom, | |
2479 | unsigned long, unsigned long)); | |
2480 | static void add_loc_descr PROTO((dw_loc_descr_ref *, | |
2481 | dw_loc_descr_ref)); | |
2482 | static void print_spaces PROTO((FILE *)); | |
2483 | static void print_die PROTO((dw_die_ref, FILE *)); | |
2484 | static void print_dwarf_line_table PROTO((FILE *)); | |
956d6950 | 2485 | static void add_sibling_attributes PROTO((dw_die_ref)); |
3f76745e JM |
2486 | static void build_abbrev_table PROTO((dw_die_ref)); |
2487 | static unsigned long size_of_string PROTO((char *)); | |
2488 | static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref)); | |
2489 | static unsigned long size_of_locs PROTO((dw_loc_descr_ref)); | |
2490 | static int constant_size PROTO((long unsigned)); | |
2491 | static unsigned long size_of_die PROTO((dw_die_ref)); | |
2492 | static void calc_die_sizes PROTO((dw_die_ref)); | |
2d8b0f3a | 2493 | static unsigned long size_of_line_prolog PROTO((void)); |
3f76745e JM |
2494 | static unsigned long size_of_line_info PROTO((void)); |
2495 | static unsigned long size_of_pubnames PROTO((void)); | |
2496 | static unsigned long size_of_aranges PROTO((void)); | |
2497 | static enum dwarf_form value_format PROTO((dw_val_ref)); | |
2498 | static void output_value_format PROTO((dw_val_ref)); | |
2499 | static void output_abbrev_section PROTO((void)); | |
2500 | static void output_loc_operands PROTO((dw_loc_descr_ref)); | |
2501 | static unsigned long sibling_offset PROTO((dw_die_ref)); | |
2502 | static void output_die PROTO((dw_die_ref)); | |
2503 | static void output_compilation_unit_header PROTO((void)); | |
2504 | static char *dwarf2_name PROTO((tree, int)); | |
2505 | static void add_pubname PROTO((tree, dw_die_ref)); | |
2506 | static void output_pubnames PROTO((void)); | |
2d8b0f3a JL |
2507 | static void add_arange PROTO((tree, dw_die_ref)); |
2508 | static void output_aranges PROTO((void)); | |
3f76745e JM |
2509 | static void output_line_info PROTO((void)); |
2510 | static int is_body_block PROTO((tree)); | |
2511 | static dw_die_ref base_type_die PROTO((tree)); | |
2512 | static tree root_type PROTO((tree)); | |
2513 | static int is_base_type PROTO((tree)); | |
2514 | static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref)); | |
2515 | static int type_is_enum PROTO((tree)); | |
4401bf24 | 2516 | static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx)); |
3f76745e JM |
2517 | static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long)); |
2518 | static int is_based_loc PROTO((rtx)); | |
2519 | static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx)); | |
4401bf24 | 2520 | static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx)); |
3f76745e JM |
2521 | static dw_loc_descr_ref loc_descriptor PROTO((rtx)); |
2522 | static unsigned ceiling PROTO((unsigned, unsigned)); | |
2523 | static tree field_type PROTO((tree)); | |
2524 | static unsigned simple_type_align_in_bits PROTO((tree)); | |
2525 | static unsigned simple_type_size_in_bits PROTO((tree)); | |
2526 | static unsigned field_byte_offset PROTO((tree)); | |
ef76d03b JW |
2527 | static void add_AT_location_description PROTO((dw_die_ref, |
2528 | enum dwarf_attribute, rtx)); | |
3f76745e JM |
2529 | static void add_data_member_location_attribute PROTO((dw_die_ref, tree)); |
2530 | static void add_const_value_attribute PROTO((dw_die_ref, rtx)); | |
2531 | static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree)); | |
2532 | static void add_name_attribute PROTO((dw_die_ref, char *)); | |
2533 | static void add_bound_info PROTO((dw_die_ref, | |
2534 | enum dwarf_attribute, tree)); | |
2535 | static void add_subscript_info PROTO((dw_die_ref, tree)); | |
2536 | static void add_byte_size_attribute PROTO((dw_die_ref, tree)); | |
2537 | static void add_bit_offset_attribute PROTO((dw_die_ref, tree)); | |
2538 | static void add_bit_size_attribute PROTO((dw_die_ref, tree)); | |
2539 | static void add_prototyped_attribute PROTO((dw_die_ref, tree)); | |
2540 | static void add_abstract_origin_attribute PROTO((dw_die_ref, tree)); | |
2541 | static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree)); | |
2542 | static void add_src_coords_attributes PROTO((dw_die_ref, tree)); | |
2d8b0f3a | 2543 | static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree)); |
3f76745e JM |
2544 | static void push_decl_scope PROTO((tree)); |
2545 | static dw_die_ref scope_die_for PROTO((tree, dw_die_ref)); | |
2546 | static void pop_decl_scope PROTO((void)); | |
2547 | static void add_type_attribute PROTO((dw_die_ref, tree, int, int, | |
2548 | dw_die_ref)); | |
2549 | static char *type_tag PROTO((tree)); | |
2550 | static tree member_declared_type PROTO((tree)); | |
487a6e06 | 2551 | #if 0 |
3f76745e | 2552 | static char *decl_start_label PROTO((tree)); |
487a6e06 | 2553 | #endif |
2d8b0f3a | 2554 | static void gen_array_type_die PROTO((tree, dw_die_ref)); |
3f76745e | 2555 | static void gen_set_type_die PROTO((tree, dw_die_ref)); |
d6f4ec51 | 2556 | #if 0 |
3f76745e | 2557 | static void gen_entry_point_die PROTO((tree, dw_die_ref)); |
d6f4ec51 | 2558 | #endif |
3f76745e JM |
2559 | static void pend_type PROTO((tree)); |
2560 | static void output_pending_types_for_scope PROTO((dw_die_ref)); | |
2561 | static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2562 | static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref)); | |
2563 | static void gen_inlined_union_type_die PROTO((tree, dw_die_ref)); | |
2564 | static void gen_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2565 | static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref)); | |
2566 | static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref)); | |
2567 | static void gen_formal_types_die PROTO((tree, dw_die_ref)); | |
2568 | static void gen_subprogram_die PROTO((tree, dw_die_ref)); | |
2569 | static void gen_variable_die PROTO((tree, dw_die_ref)); | |
2570 | static void gen_label_die PROTO((tree, dw_die_ref)); | |
2571 | static void gen_lexical_block_die PROTO((tree, dw_die_ref, int)); | |
2d8b0f3a | 2572 | static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int)); |
3f76745e JM |
2573 | static void gen_field_die PROTO((tree, dw_die_ref)); |
2574 | static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref)); | |
2575 | static void gen_compile_unit_die PROTO((char *)); | |
2576 | static void gen_string_type_die PROTO((tree, dw_die_ref)); | |
2577 | static void gen_inheritance_die PROTO((tree, dw_die_ref)); | |
2578 | static void gen_member_die PROTO((tree, dw_die_ref)); | |
2579 | static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref)); | |
2580 | static void gen_subroutine_type_die PROTO((tree, dw_die_ref)); | |
2581 | static void gen_typedef_die PROTO((tree, dw_die_ref)); | |
2582 | static void gen_type_die PROTO((tree, dw_die_ref)); | |
2583 | static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref)); | |
2584 | static void gen_block_die PROTO((tree, dw_die_ref, int)); | |
2585 | static void decls_for_scope PROTO((tree, dw_die_ref, int)); | |
2586 | static int is_redundant_typedef PROTO((tree)); | |
2587 | static void gen_decl_die PROTO((tree, dw_die_ref)); | |
2588 | static unsigned lookup_filename PROTO((char *)); | |
71dfc51f | 2589 | |
3f76745e | 2590 | /* Section names used to hold DWARF debugging information. */ |
c53aa195 JM |
2591 | #ifndef DEBUG_INFO_SECTION |
2592 | #define DEBUG_INFO_SECTION ".debug_info" | |
3f76745e JM |
2593 | #endif |
2594 | #ifndef ABBREV_SECTION | |
2595 | #define ABBREV_SECTION ".debug_abbrev" | |
2596 | #endif | |
2597 | #ifndef ARANGES_SECTION | |
2598 | #define ARANGES_SECTION ".debug_aranges" | |
2599 | #endif | |
2600 | #ifndef DW_MACINFO_SECTION | |
2601 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
2602 | #endif | |
c53aa195 JM |
2603 | #ifndef DEBUG_LINE_SECTION |
2604 | #define DEBUG_LINE_SECTION ".debug_line" | |
3f76745e JM |
2605 | #endif |
2606 | #ifndef LOC_SECTION | |
2607 | #define LOC_SECTION ".debug_loc" | |
2608 | #endif | |
2609 | #ifndef PUBNAMES_SECTION | |
2610 | #define PUBNAMES_SECTION ".debug_pubnames" | |
2611 | #endif | |
2612 | #ifndef STR_SECTION | |
2613 | #define STR_SECTION ".debug_str" | |
2614 | #endif | |
a3f97cbb | 2615 | |
956d6950 | 2616 | /* Standard ELF section names for compiled code and data. */ |
3f76745e JM |
2617 | #ifndef TEXT_SECTION |
2618 | #define TEXT_SECTION ".text" | |
2619 | #endif | |
2620 | #ifndef DATA_SECTION | |
2621 | #define DATA_SECTION ".data" | |
2622 | #endif | |
2623 | #ifndef BSS_SECTION | |
2624 | #define BSS_SECTION ".bss" | |
2625 | #endif | |
71dfc51f | 2626 | |
a3f97cbb | 2627 | |
3f76745e JM |
2628 | /* Definitions of defaults for formats and names of various special |
2629 | (artificial) labels which may be generated within this file (when the -g | |
2630 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
2631 | If necessary, these may be overridden from within the tm.h file, but | |
2632 | typically, overriding these defaults is unnecessary. */ | |
a3f97cbb | 2633 | |
257ebd1f | 2634 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 2635 | |
3f76745e JM |
2636 | #ifndef TEXT_END_LABEL |
2637 | #define TEXT_END_LABEL "Letext" | |
2638 | #endif | |
2639 | #ifndef DATA_END_LABEL | |
2640 | #define DATA_END_LABEL "Ledata" | |
2641 | #endif | |
2642 | #ifndef BSS_END_LABEL | |
2643 | #define BSS_END_LABEL "Lebss" | |
2644 | #endif | |
2645 | #ifndef INSN_LABEL_FMT | |
2646 | #define INSN_LABEL_FMT "LI%u_" | |
2647 | #endif | |
2648 | #ifndef BLOCK_BEGIN_LABEL | |
2649 | #define BLOCK_BEGIN_LABEL "LBB" | |
2650 | #endif | |
2651 | #ifndef BLOCK_END_LABEL | |
2652 | #define BLOCK_END_LABEL "LBE" | |
2653 | #endif | |
2654 | #ifndef BODY_BEGIN_LABEL | |
2655 | #define BODY_BEGIN_LABEL "Lbb" | |
2656 | #endif | |
2657 | #ifndef BODY_END_LABEL | |
2658 | #define BODY_END_LABEL "Lbe" | |
2659 | #endif | |
2660 | #ifndef LINE_CODE_LABEL | |
2661 | #define LINE_CODE_LABEL "LM" | |
2662 | #endif | |
2663 | #ifndef SEPARATE_LINE_CODE_LABEL | |
2664 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
2665 | #endif | |
71dfc51f | 2666 | |
3f76745e JM |
2667 | /* Convert a reference to the assembler name of a C-level name. This |
2668 | macro has the same effect as ASM_OUTPUT_LABELREF, but copies to | |
2669 | a string rather than writing to a file. */ | |
2670 | #ifndef ASM_NAME_TO_STRING | |
19283265 RH |
2671 | #define ASM_NAME_TO_STRING(STR, NAME) \ |
2672 | do { \ | |
2673 | if ((NAME)[0] == '*') \ | |
2674 | dyn_string_append (STR, NAME + 1); \ | |
2675 | else \ | |
2676 | { \ | |
2677 | dyn_string_append (STR, user_label_prefix); \ | |
2678 | dyn_string_append (STR, NAME); \ | |
2679 | } \ | |
2680 | } \ | |
3f76745e JM |
2681 | while (0) |
2682 | #endif | |
2683 | \f | |
2684 | /* Convert an integer constant expression into assembler syntax. Addition | |
2685 | and subtraction are the only arithmetic that may appear in these | |
2686 | expressions. This is an adaptation of output_addr_const in final.c. | |
2687 | Here, the target of the conversion is a string buffer. We can't use | |
2688 | output_addr_const directly, because it writes to a file. */ | |
71dfc51f | 2689 | |
3f76745e JM |
2690 | static void |
2691 | addr_const_to_string (str, x) | |
b170964a | 2692 | dyn_string_t str; |
3f76745e | 2693 | rtx x; |
a3f97cbb | 2694 | { |
3f76745e | 2695 | char buf1[256]; |
71dfc51f | 2696 | |
3f76745e | 2697 | restart: |
3f76745e JM |
2698 | switch (GET_CODE (x)) |
2699 | { | |
2700 | case PC: | |
2701 | if (flag_pic) | |
b170964a | 2702 | dyn_string_append (str, ","); |
3f76745e JM |
2703 | else |
2704 | abort (); | |
2705 | break; | |
71dfc51f | 2706 | |
3f76745e | 2707 | case SYMBOL_REF: |
b170964a | 2708 | ASM_NAME_TO_STRING (str, XSTR (x, 0)); |
3f76745e | 2709 | break; |
a3f97cbb | 2710 | |
3f76745e JM |
2711 | case LABEL_REF: |
2712 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); | |
b170964a | 2713 | ASM_NAME_TO_STRING (str, buf1); |
3f76745e | 2714 | break; |
71dfc51f | 2715 | |
3f76745e JM |
2716 | case CODE_LABEL: |
2717 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); | |
b170964a | 2718 | ASM_NAME_TO_STRING (str, buf1); |
3f76745e | 2719 | break; |
71dfc51f | 2720 | |
3f76745e JM |
2721 | case CONST_INT: |
2722 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
b170964a | 2723 | dyn_string_append (str, buf1); |
3f76745e | 2724 | break; |
a3f97cbb | 2725 | |
3f76745e JM |
2726 | case CONST: |
2727 | /* This used to output parentheses around the expression, but that does | |
2728 | not work on the 386 (either ATT or BSD assembler). */ | |
b170964a | 2729 | addr_const_to_string (str, XEXP (x, 0)); |
3f76745e | 2730 | break; |
71dfc51f | 2731 | |
3f76745e JM |
2732 | case CONST_DOUBLE: |
2733 | if (GET_MODE (x) == VOIDmode) | |
2734 | { | |
2735 | /* We can use %d if the number is one word and positive. */ | |
2736 | if (CONST_DOUBLE_HIGH (x)) | |
2737 | sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX, | |
2738 | CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); | |
2739 | else if (CONST_DOUBLE_LOW (x) < 0) | |
2740 | sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x)); | |
2741 | else | |
2742 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, | |
2743 | CONST_DOUBLE_LOW (x)); | |
b170964a | 2744 | dyn_string_append (str, buf1); |
3f76745e JM |
2745 | } |
2746 | else | |
2747 | /* We can't handle floating point constants; PRINT_OPERAND must | |
2748 | handle them. */ | |
2749 | output_operand_lossage ("floating constant misused"); | |
2750 | break; | |
71dfc51f | 2751 | |
3f76745e JM |
2752 | case PLUS: |
2753 | /* Some assemblers need integer constants to appear last (eg masm). */ | |
2754 | if (GET_CODE (XEXP (x, 0)) == CONST_INT) | |
a3f97cbb | 2755 | { |
b170964a | 2756 | addr_const_to_string (str, XEXP (x, 1)); |
3f76745e | 2757 | if (INTVAL (XEXP (x, 0)) >= 0) |
b170964a | 2758 | dyn_string_append (str, "+"); |
3f76745e | 2759 | |
b170964a | 2760 | addr_const_to_string (str, XEXP (x, 0)); |
a3f97cbb | 2761 | } |
3f76745e JM |
2762 | else |
2763 | { | |
b170964a | 2764 | addr_const_to_string (str, XEXP (x, 0)); |
3f76745e | 2765 | if (INTVAL (XEXP (x, 1)) >= 0) |
b170964a | 2766 | dyn_string_append (str, "+"); |
71dfc51f | 2767 | |
b170964a | 2768 | addr_const_to_string (str, XEXP (x, 1)); |
3f76745e JM |
2769 | } |
2770 | break; | |
a3f97cbb | 2771 | |
3f76745e JM |
2772 | case MINUS: |
2773 | /* Avoid outputting things like x-x or x+5-x, since some assemblers | |
2774 | can't handle that. */ | |
2775 | x = simplify_subtraction (x); | |
2776 | if (GET_CODE (x) != MINUS) | |
2777 | goto restart; | |
71dfc51f | 2778 | |
b170964a MM |
2779 | addr_const_to_string (str, XEXP (x, 0)); |
2780 | dyn_string_append (str, "-"); | |
3f76745e JM |
2781 | if (GET_CODE (XEXP (x, 1)) == CONST_INT |
2782 | && INTVAL (XEXP (x, 1)) < 0) | |
a3f97cbb | 2783 | { |
b170964a MM |
2784 | dyn_string_append (str, ASM_OPEN_PAREN); |
2785 | addr_const_to_string (str, XEXP (x, 1)); | |
2786 | dyn_string_append (str, ASM_CLOSE_PAREN); | |
3f76745e JM |
2787 | } |
2788 | else | |
b170964a | 2789 | addr_const_to_string (str, XEXP (x, 1)); |
3f76745e | 2790 | break; |
71dfc51f | 2791 | |
3f76745e JM |
2792 | case ZERO_EXTEND: |
2793 | case SIGN_EXTEND: | |
b170964a | 2794 | addr_const_to_string (str, XEXP (x, 0)); |
3f76745e | 2795 | break; |
71dfc51f | 2796 | |
3f76745e JM |
2797 | default: |
2798 | output_operand_lossage ("invalid expression as operand"); | |
2799 | } | |
d291dd49 JM |
2800 | } |
2801 | ||
3f76745e JM |
2802 | /* Convert an address constant to a string, and return a pointer to |
2803 | a copy of the result, located on the heap. */ | |
71dfc51f | 2804 | |
3f76745e JM |
2805 | static char * |
2806 | addr_to_string (x) | |
2807 | rtx x; | |
d291dd49 | 2808 | { |
b170964a MM |
2809 | dyn_string_t ds = dyn_string_new (256); |
2810 | char *s; | |
2811 | ||
2812 | addr_const_to_string (ds, x); | |
2813 | ||
2814 | /* Return the dynamically allocated string, but free the | |
2815 | dyn_string_t itself. */ | |
2816 | s = ds->s; | |
2817 | free (ds); | |
2818 | return s; | |
d291dd49 JM |
2819 | } |
2820 | ||
956d6950 | 2821 | /* Test if rtl node points to a pseudo register. */ |
71dfc51f | 2822 | |
3f76745e JM |
2823 | static inline int |
2824 | is_pseudo_reg (rtl) | |
2825 | register rtx rtl; | |
d291dd49 | 2826 | { |
3f76745e JM |
2827 | return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) |
2828 | || ((GET_CODE (rtl) == SUBREG) | |
2829 | && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER))); | |
d291dd49 JM |
2830 | } |
2831 | ||
3f76745e JM |
2832 | /* Return a reference to a type, with its const and volatile qualifiers |
2833 | removed. */ | |
71dfc51f | 2834 | |
3f76745e JM |
2835 | static inline tree |
2836 | type_main_variant (type) | |
2837 | register tree type; | |
d291dd49 | 2838 | { |
3f76745e | 2839 | type = TYPE_MAIN_VARIANT (type); |
71dfc51f | 2840 | |
3f76745e JM |
2841 | /* There really should be only one main variant among any group of variants |
2842 | of a given type (and all of the MAIN_VARIANT values for all members of | |
2843 | the group should point to that one type) but sometimes the C front-end | |
2844 | messes this up for array types, so we work around that bug here. */ | |
71dfc51f | 2845 | |
3f76745e JM |
2846 | if (TREE_CODE (type) == ARRAY_TYPE) |
2847 | while (type != TYPE_MAIN_VARIANT (type)) | |
2848 | type = TYPE_MAIN_VARIANT (type); | |
2849 | ||
2850 | return type; | |
a3f97cbb JW |
2851 | } |
2852 | ||
3f76745e | 2853 | /* Return non-zero if the given type node represents a tagged type. */ |
71dfc51f RK |
2854 | |
2855 | static inline int | |
3f76745e JM |
2856 | is_tagged_type (type) |
2857 | register tree type; | |
bdb669cb | 2858 | { |
3f76745e | 2859 | register enum tree_code code = TREE_CODE (type); |
71dfc51f | 2860 | |
3f76745e JM |
2861 | return (code == RECORD_TYPE || code == UNION_TYPE |
2862 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
bdb669cb JM |
2863 | } |
2864 | ||
3f76745e | 2865 | /* Convert a DIE tag into its string name. */ |
71dfc51f | 2866 | |
3f76745e JM |
2867 | static char * |
2868 | dwarf_tag_name (tag) | |
2869 | register unsigned tag; | |
bdb669cb | 2870 | { |
3f76745e JM |
2871 | switch (tag) |
2872 | { | |
2873 | case DW_TAG_padding: | |
2874 | return "DW_TAG_padding"; | |
2875 | case DW_TAG_array_type: | |
2876 | return "DW_TAG_array_type"; | |
2877 | case DW_TAG_class_type: | |
2878 | return "DW_TAG_class_type"; | |
2879 | case DW_TAG_entry_point: | |
2880 | return "DW_TAG_entry_point"; | |
2881 | case DW_TAG_enumeration_type: | |
2882 | return "DW_TAG_enumeration_type"; | |
2883 | case DW_TAG_formal_parameter: | |
2884 | return "DW_TAG_formal_parameter"; | |
2885 | case DW_TAG_imported_declaration: | |
2886 | return "DW_TAG_imported_declaration"; | |
2887 | case DW_TAG_label: | |
2888 | return "DW_TAG_label"; | |
2889 | case DW_TAG_lexical_block: | |
2890 | return "DW_TAG_lexical_block"; | |
2891 | case DW_TAG_member: | |
2892 | return "DW_TAG_member"; | |
2893 | case DW_TAG_pointer_type: | |
2894 | return "DW_TAG_pointer_type"; | |
2895 | case DW_TAG_reference_type: | |
2896 | return "DW_TAG_reference_type"; | |
2897 | case DW_TAG_compile_unit: | |
2898 | return "DW_TAG_compile_unit"; | |
2899 | case DW_TAG_string_type: | |
2900 | return "DW_TAG_string_type"; | |
2901 | case DW_TAG_structure_type: | |
2902 | return "DW_TAG_structure_type"; | |
2903 | case DW_TAG_subroutine_type: | |
2904 | return "DW_TAG_subroutine_type"; | |
2905 | case DW_TAG_typedef: | |
2906 | return "DW_TAG_typedef"; | |
2907 | case DW_TAG_union_type: | |
2908 | return "DW_TAG_union_type"; | |
2909 | case DW_TAG_unspecified_parameters: | |
2910 | return "DW_TAG_unspecified_parameters"; | |
2911 | case DW_TAG_variant: | |
2912 | return "DW_TAG_variant"; | |
2913 | case DW_TAG_common_block: | |
2914 | return "DW_TAG_common_block"; | |
2915 | case DW_TAG_common_inclusion: | |
2916 | return "DW_TAG_common_inclusion"; | |
2917 | case DW_TAG_inheritance: | |
2918 | return "DW_TAG_inheritance"; | |
2919 | case DW_TAG_inlined_subroutine: | |
2920 | return "DW_TAG_inlined_subroutine"; | |
2921 | case DW_TAG_module: | |
2922 | return "DW_TAG_module"; | |
2923 | case DW_TAG_ptr_to_member_type: | |
2924 | return "DW_TAG_ptr_to_member_type"; | |
2925 | case DW_TAG_set_type: | |
2926 | return "DW_TAG_set_type"; | |
2927 | case DW_TAG_subrange_type: | |
2928 | return "DW_TAG_subrange_type"; | |
2929 | case DW_TAG_with_stmt: | |
2930 | return "DW_TAG_with_stmt"; | |
2931 | case DW_TAG_access_declaration: | |
2932 | return "DW_TAG_access_declaration"; | |
2933 | case DW_TAG_base_type: | |
2934 | return "DW_TAG_base_type"; | |
2935 | case DW_TAG_catch_block: | |
2936 | return "DW_TAG_catch_block"; | |
2937 | case DW_TAG_const_type: | |
2938 | return "DW_TAG_const_type"; | |
2939 | case DW_TAG_constant: | |
2940 | return "DW_TAG_constant"; | |
2941 | case DW_TAG_enumerator: | |
2942 | return "DW_TAG_enumerator"; | |
2943 | case DW_TAG_file_type: | |
2944 | return "DW_TAG_file_type"; | |
2945 | case DW_TAG_friend: | |
2946 | return "DW_TAG_friend"; | |
2947 | case DW_TAG_namelist: | |
2948 | return "DW_TAG_namelist"; | |
2949 | case DW_TAG_namelist_item: | |
2950 | return "DW_TAG_namelist_item"; | |
2951 | case DW_TAG_packed_type: | |
2952 | return "DW_TAG_packed_type"; | |
2953 | case DW_TAG_subprogram: | |
2954 | return "DW_TAG_subprogram"; | |
2955 | case DW_TAG_template_type_param: | |
2956 | return "DW_TAG_template_type_param"; | |
2957 | case DW_TAG_template_value_param: | |
2958 | return "DW_TAG_template_value_param"; | |
2959 | case DW_TAG_thrown_type: | |
2960 | return "DW_TAG_thrown_type"; | |
2961 | case DW_TAG_try_block: | |
2962 | return "DW_TAG_try_block"; | |
2963 | case DW_TAG_variant_part: | |
2964 | return "DW_TAG_variant_part"; | |
2965 | case DW_TAG_variable: | |
2966 | return "DW_TAG_variable"; | |
2967 | case DW_TAG_volatile_type: | |
2968 | return "DW_TAG_volatile_type"; | |
2969 | case DW_TAG_MIPS_loop: | |
2970 | return "DW_TAG_MIPS_loop"; | |
2971 | case DW_TAG_format_label: | |
2972 | return "DW_TAG_format_label"; | |
2973 | case DW_TAG_function_template: | |
2974 | return "DW_TAG_function_template"; | |
2975 | case DW_TAG_class_template: | |
2976 | return "DW_TAG_class_template"; | |
2977 | default: | |
2978 | return "DW_TAG_<unknown>"; | |
2979 | } | |
bdb669cb | 2980 | } |
a3f97cbb | 2981 | |
3f76745e | 2982 | /* Convert a DWARF attribute code into its string name. */ |
71dfc51f | 2983 | |
3f76745e JM |
2984 | static char * |
2985 | dwarf_attr_name (attr) | |
2986 | register unsigned attr; | |
4b674448 | 2987 | { |
3f76745e | 2988 | switch (attr) |
4b674448 | 2989 | { |
3f76745e JM |
2990 | case DW_AT_sibling: |
2991 | return "DW_AT_sibling"; | |
2992 | case DW_AT_location: | |
2993 | return "DW_AT_location"; | |
2994 | case DW_AT_name: | |
2995 | return "DW_AT_name"; | |
2996 | case DW_AT_ordering: | |
2997 | return "DW_AT_ordering"; | |
2998 | case DW_AT_subscr_data: | |
2999 | return "DW_AT_subscr_data"; | |
3000 | case DW_AT_byte_size: | |
3001 | return "DW_AT_byte_size"; | |
3002 | case DW_AT_bit_offset: | |
3003 | return "DW_AT_bit_offset"; | |
3004 | case DW_AT_bit_size: | |
3005 | return "DW_AT_bit_size"; | |
3006 | case DW_AT_element_list: | |
3007 | return "DW_AT_element_list"; | |
3008 | case DW_AT_stmt_list: | |
3009 | return "DW_AT_stmt_list"; | |
3010 | case DW_AT_low_pc: | |
3011 | return "DW_AT_low_pc"; | |
3012 | case DW_AT_high_pc: | |
3013 | return "DW_AT_high_pc"; | |
3014 | case DW_AT_language: | |
3015 | return "DW_AT_language"; | |
3016 | case DW_AT_member: | |
3017 | return "DW_AT_member"; | |
3018 | case DW_AT_discr: | |
3019 | return "DW_AT_discr"; | |
3020 | case DW_AT_discr_value: | |
3021 | return "DW_AT_discr_value"; | |
3022 | case DW_AT_visibility: | |
3023 | return "DW_AT_visibility"; | |
3024 | case DW_AT_import: | |
3025 | return "DW_AT_import"; | |
3026 | case DW_AT_string_length: | |
3027 | return "DW_AT_string_length"; | |
3028 | case DW_AT_common_reference: | |
3029 | return "DW_AT_common_reference"; | |
3030 | case DW_AT_comp_dir: | |
3031 | return "DW_AT_comp_dir"; | |
3032 | case DW_AT_const_value: | |
3033 | return "DW_AT_const_value"; | |
3034 | case DW_AT_containing_type: | |
3035 | return "DW_AT_containing_type"; | |
3036 | case DW_AT_default_value: | |
3037 | return "DW_AT_default_value"; | |
3038 | case DW_AT_inline: | |
3039 | return "DW_AT_inline"; | |
3040 | case DW_AT_is_optional: | |
3041 | return "DW_AT_is_optional"; | |
3042 | case DW_AT_lower_bound: | |
3043 | return "DW_AT_lower_bound"; | |
3044 | case DW_AT_producer: | |
3045 | return "DW_AT_producer"; | |
3046 | case DW_AT_prototyped: | |
3047 | return "DW_AT_prototyped"; | |
3048 | case DW_AT_return_addr: | |
3049 | return "DW_AT_return_addr"; | |
3050 | case DW_AT_start_scope: | |
3051 | return "DW_AT_start_scope"; | |
3052 | case DW_AT_stride_size: | |
3053 | return "DW_AT_stride_size"; | |
3054 | case DW_AT_upper_bound: | |
3055 | return "DW_AT_upper_bound"; | |
3056 | case DW_AT_abstract_origin: | |
3057 | return "DW_AT_abstract_origin"; | |
3058 | case DW_AT_accessibility: | |
3059 | return "DW_AT_accessibility"; | |
3060 | case DW_AT_address_class: | |
3061 | return "DW_AT_address_class"; | |
3062 | case DW_AT_artificial: | |
3063 | return "DW_AT_artificial"; | |
3064 | case DW_AT_base_types: | |
3065 | return "DW_AT_base_types"; | |
3066 | case DW_AT_calling_convention: | |
3067 | return "DW_AT_calling_convention"; | |
3068 | case DW_AT_count: | |
3069 | return "DW_AT_count"; | |
3070 | case DW_AT_data_member_location: | |
3071 | return "DW_AT_data_member_location"; | |
3072 | case DW_AT_decl_column: | |
3073 | return "DW_AT_decl_column"; | |
3074 | case DW_AT_decl_file: | |
3075 | return "DW_AT_decl_file"; | |
3076 | case DW_AT_decl_line: | |
3077 | return "DW_AT_decl_line"; | |
3078 | case DW_AT_declaration: | |
3079 | return "DW_AT_declaration"; | |
3080 | case DW_AT_discr_list: | |
3081 | return "DW_AT_discr_list"; | |
3082 | case DW_AT_encoding: | |
3083 | return "DW_AT_encoding"; | |
3084 | case DW_AT_external: | |
3085 | return "DW_AT_external"; | |
3086 | case DW_AT_frame_base: | |
3087 | return "DW_AT_frame_base"; | |
3088 | case DW_AT_friend: | |
3089 | return "DW_AT_friend"; | |
3090 | case DW_AT_identifier_case: | |
3091 | return "DW_AT_identifier_case"; | |
3092 | case DW_AT_macro_info: | |
3093 | return "DW_AT_macro_info"; | |
3094 | case DW_AT_namelist_items: | |
3095 | return "DW_AT_namelist_items"; | |
3096 | case DW_AT_priority: | |
3097 | return "DW_AT_priority"; | |
3098 | case DW_AT_segment: | |
3099 | return "DW_AT_segment"; | |
3100 | case DW_AT_specification: | |
3101 | return "DW_AT_specification"; | |
3102 | case DW_AT_static_link: | |
3103 | return "DW_AT_static_link"; | |
3104 | case DW_AT_type: | |
3105 | return "DW_AT_type"; | |
3106 | case DW_AT_use_location: | |
3107 | return "DW_AT_use_location"; | |
3108 | case DW_AT_variable_parameter: | |
3109 | return "DW_AT_variable_parameter"; | |
3110 | case DW_AT_virtuality: | |
3111 | return "DW_AT_virtuality"; | |
3112 | case DW_AT_vtable_elem_location: | |
3113 | return "DW_AT_vtable_elem_location"; | |
71dfc51f | 3114 | |
3f76745e JM |
3115 | case DW_AT_MIPS_fde: |
3116 | return "DW_AT_MIPS_fde"; | |
3117 | case DW_AT_MIPS_loop_begin: | |
3118 | return "DW_AT_MIPS_loop_begin"; | |
3119 | case DW_AT_MIPS_tail_loop_begin: | |
3120 | return "DW_AT_MIPS_tail_loop_begin"; | |
3121 | case DW_AT_MIPS_epilog_begin: | |
3122 | return "DW_AT_MIPS_epilog_begin"; | |
3123 | case DW_AT_MIPS_loop_unroll_factor: | |
3124 | return "DW_AT_MIPS_loop_unroll_factor"; | |
3125 | case DW_AT_MIPS_software_pipeline_depth: | |
3126 | return "DW_AT_MIPS_software_pipeline_depth"; | |
3127 | case DW_AT_MIPS_linkage_name: | |
3128 | return "DW_AT_MIPS_linkage_name"; | |
3129 | case DW_AT_MIPS_stride: | |
3130 | return "DW_AT_MIPS_stride"; | |
3131 | case DW_AT_MIPS_abstract_name: | |
3132 | return "DW_AT_MIPS_abstract_name"; | |
3133 | case DW_AT_MIPS_clone_origin: | |
3134 | return "DW_AT_MIPS_clone_origin"; | |
3135 | case DW_AT_MIPS_has_inlines: | |
3136 | return "DW_AT_MIPS_has_inlines"; | |
71dfc51f | 3137 | |
3f76745e JM |
3138 | case DW_AT_sf_names: |
3139 | return "DW_AT_sf_names"; | |
3140 | case DW_AT_src_info: | |
3141 | return "DW_AT_src_info"; | |
3142 | case DW_AT_mac_info: | |
3143 | return "DW_AT_mac_info"; | |
3144 | case DW_AT_src_coords: | |
3145 | return "DW_AT_src_coords"; | |
3146 | case DW_AT_body_begin: | |
3147 | return "DW_AT_body_begin"; | |
3148 | case DW_AT_body_end: | |
3149 | return "DW_AT_body_end"; | |
3150 | default: | |
3151 | return "DW_AT_<unknown>"; | |
4b674448 JM |
3152 | } |
3153 | } | |
3154 | ||
3f76745e | 3155 | /* Convert a DWARF value form code into its string name. */ |
71dfc51f | 3156 | |
3f76745e JM |
3157 | static char * |
3158 | dwarf_form_name (form) | |
3159 | register unsigned form; | |
4b674448 | 3160 | { |
3f76745e | 3161 | switch (form) |
4b674448 | 3162 | { |
3f76745e JM |
3163 | case DW_FORM_addr: |
3164 | return "DW_FORM_addr"; | |
3165 | case DW_FORM_block2: | |
3166 | return "DW_FORM_block2"; | |
3167 | case DW_FORM_block4: | |
3168 | return "DW_FORM_block4"; | |
3169 | case DW_FORM_data2: | |
3170 | return "DW_FORM_data2"; | |
3171 | case DW_FORM_data4: | |
3172 | return "DW_FORM_data4"; | |
3173 | case DW_FORM_data8: | |
3174 | return "DW_FORM_data8"; | |
3175 | case DW_FORM_string: | |
3176 | return "DW_FORM_string"; | |
3177 | case DW_FORM_block: | |
3178 | return "DW_FORM_block"; | |
3179 | case DW_FORM_block1: | |
3180 | return "DW_FORM_block1"; | |
3181 | case DW_FORM_data1: | |
3182 | return "DW_FORM_data1"; | |
3183 | case DW_FORM_flag: | |
3184 | return "DW_FORM_flag"; | |
3185 | case DW_FORM_sdata: | |
3186 | return "DW_FORM_sdata"; | |
3187 | case DW_FORM_strp: | |
3188 | return "DW_FORM_strp"; | |
3189 | case DW_FORM_udata: | |
3190 | return "DW_FORM_udata"; | |
3191 | case DW_FORM_ref_addr: | |
3192 | return "DW_FORM_ref_addr"; | |
3193 | case DW_FORM_ref1: | |
3194 | return "DW_FORM_ref1"; | |
3195 | case DW_FORM_ref2: | |
3196 | return "DW_FORM_ref2"; | |
3197 | case DW_FORM_ref4: | |
3198 | return "DW_FORM_ref4"; | |
3199 | case DW_FORM_ref8: | |
3200 | return "DW_FORM_ref8"; | |
3201 | case DW_FORM_ref_udata: | |
3202 | return "DW_FORM_ref_udata"; | |
3203 | case DW_FORM_indirect: | |
3204 | return "DW_FORM_indirect"; | |
3205 | default: | |
3206 | return "DW_FORM_<unknown>"; | |
4b674448 JM |
3207 | } |
3208 | } | |
3209 | ||
3f76745e | 3210 | /* Convert a DWARF stack opcode into its string name. */ |
71dfc51f | 3211 | |
3f76745e JM |
3212 | static char * |
3213 | dwarf_stack_op_name (op) | |
3214 | register unsigned op; | |
a3f97cbb | 3215 | { |
3f76745e | 3216 | switch (op) |
a3f97cbb | 3217 | { |
3f76745e JM |
3218 | case DW_OP_addr: |
3219 | return "DW_OP_addr"; | |
3220 | case DW_OP_deref: | |
3221 | return "DW_OP_deref"; | |
3222 | case DW_OP_const1u: | |
3223 | return "DW_OP_const1u"; | |
3224 | case DW_OP_const1s: | |
3225 | return "DW_OP_const1s"; | |
3226 | case DW_OP_const2u: | |
3227 | return "DW_OP_const2u"; | |
3228 | case DW_OP_const2s: | |
3229 | return "DW_OP_const2s"; | |
3230 | case DW_OP_const4u: | |
3231 | return "DW_OP_const4u"; | |
3232 | case DW_OP_const4s: | |
3233 | return "DW_OP_const4s"; | |
3234 | case DW_OP_const8u: | |
3235 | return "DW_OP_const8u"; | |
3236 | case DW_OP_const8s: | |
3237 | return "DW_OP_const8s"; | |
3238 | case DW_OP_constu: | |
3239 | return "DW_OP_constu"; | |
3240 | case DW_OP_consts: | |
3241 | return "DW_OP_consts"; | |
3242 | case DW_OP_dup: | |
3243 | return "DW_OP_dup"; | |
3244 | case DW_OP_drop: | |
3245 | return "DW_OP_drop"; | |
3246 | case DW_OP_over: | |
3247 | return "DW_OP_over"; | |
3248 | case DW_OP_pick: | |
3249 | return "DW_OP_pick"; | |
3250 | case DW_OP_swap: | |
3251 | return "DW_OP_swap"; | |
3252 | case DW_OP_rot: | |
3253 | return "DW_OP_rot"; | |
3254 | case DW_OP_xderef: | |
3255 | return "DW_OP_xderef"; | |
3256 | case DW_OP_abs: | |
3257 | return "DW_OP_abs"; | |
3258 | case DW_OP_and: | |
3259 | return "DW_OP_and"; | |
3260 | case DW_OP_div: | |
3261 | return "DW_OP_div"; | |
3262 | case DW_OP_minus: | |
3263 | return "DW_OP_minus"; | |
3264 | case DW_OP_mod: | |
3265 | return "DW_OP_mod"; | |
3266 | case DW_OP_mul: | |
3267 | return "DW_OP_mul"; | |
3268 | case DW_OP_neg: | |
3269 | return "DW_OP_neg"; | |
3270 | case DW_OP_not: | |
3271 | return "DW_OP_not"; | |
3272 | case DW_OP_or: | |
3273 | return "DW_OP_or"; | |
3274 | case DW_OP_plus: | |
3275 | return "DW_OP_plus"; | |
3276 | case DW_OP_plus_uconst: | |
3277 | return "DW_OP_plus_uconst"; | |
3278 | case DW_OP_shl: | |
3279 | return "DW_OP_shl"; | |
3280 | case DW_OP_shr: | |
3281 | return "DW_OP_shr"; | |
3282 | case DW_OP_shra: | |
3283 | return "DW_OP_shra"; | |
3284 | case DW_OP_xor: | |
3285 | return "DW_OP_xor"; | |
3286 | case DW_OP_bra: | |
3287 | return "DW_OP_bra"; | |
3288 | case DW_OP_eq: | |
3289 | return "DW_OP_eq"; | |
3290 | case DW_OP_ge: | |
3291 | return "DW_OP_ge"; | |
3292 | case DW_OP_gt: | |
3293 | return "DW_OP_gt"; | |
3294 | case DW_OP_le: | |
3295 | return "DW_OP_le"; | |
3296 | case DW_OP_lt: | |
3297 | return "DW_OP_lt"; | |
3298 | case DW_OP_ne: | |
3299 | return "DW_OP_ne"; | |
3300 | case DW_OP_skip: | |
3301 | return "DW_OP_skip"; | |
3302 | case DW_OP_lit0: | |
3303 | return "DW_OP_lit0"; | |
3304 | case DW_OP_lit1: | |
3305 | return "DW_OP_lit1"; | |
3306 | case DW_OP_lit2: | |
3307 | return "DW_OP_lit2"; | |
3308 | case DW_OP_lit3: | |
3309 | return "DW_OP_lit3"; | |
3310 | case DW_OP_lit4: | |
3311 | return "DW_OP_lit4"; | |
3312 | case DW_OP_lit5: | |
3313 | return "DW_OP_lit5"; | |
3314 | case DW_OP_lit6: | |
3315 | return "DW_OP_lit6"; | |
3316 | case DW_OP_lit7: | |
3317 | return "DW_OP_lit7"; | |
3318 | case DW_OP_lit8: | |
3319 | return "DW_OP_lit8"; | |
3320 | case DW_OP_lit9: | |
3321 | return "DW_OP_lit9"; | |
3322 | case DW_OP_lit10: | |
3323 | return "DW_OP_lit10"; | |
3324 | case DW_OP_lit11: | |
3325 | return "DW_OP_lit11"; | |
3326 | case DW_OP_lit12: | |
3327 | return "DW_OP_lit12"; | |
3328 | case DW_OP_lit13: | |
3329 | return "DW_OP_lit13"; | |
3330 | case DW_OP_lit14: | |
3331 | return "DW_OP_lit14"; | |
3332 | case DW_OP_lit15: | |
3333 | return "DW_OP_lit15"; | |
3334 | case DW_OP_lit16: | |
3335 | return "DW_OP_lit16"; | |
3336 | case DW_OP_lit17: | |
3337 | return "DW_OP_lit17"; | |
3338 | case DW_OP_lit18: | |
3339 | return "DW_OP_lit18"; | |
3340 | case DW_OP_lit19: | |
3341 | return "DW_OP_lit19"; | |
3342 | case DW_OP_lit20: | |
3343 | return "DW_OP_lit20"; | |
3344 | case DW_OP_lit21: | |
3345 | return "DW_OP_lit21"; | |
3346 | case DW_OP_lit22: | |
3347 | return "DW_OP_lit22"; | |
3348 | case DW_OP_lit23: | |
3349 | return "DW_OP_lit23"; | |
3350 | case DW_OP_lit24: | |
3351 | return "DW_OP_lit24"; | |
3352 | case DW_OP_lit25: | |
3353 | return "DW_OP_lit25"; | |
3354 | case DW_OP_lit26: | |
3355 | return "DW_OP_lit26"; | |
3356 | case DW_OP_lit27: | |
3357 | return "DW_OP_lit27"; | |
3358 | case DW_OP_lit28: | |
3359 | return "DW_OP_lit28"; | |
3360 | case DW_OP_lit29: | |
3361 | return "DW_OP_lit29"; | |
3362 | case DW_OP_lit30: | |
3363 | return "DW_OP_lit30"; | |
3364 | case DW_OP_lit31: | |
3365 | return "DW_OP_lit31"; | |
3366 | case DW_OP_reg0: | |
3367 | return "DW_OP_reg0"; | |
3368 | case DW_OP_reg1: | |
3369 | return "DW_OP_reg1"; | |
3370 | case DW_OP_reg2: | |
3371 | return "DW_OP_reg2"; | |
3372 | case DW_OP_reg3: | |
3373 | return "DW_OP_reg3"; | |
3374 | case DW_OP_reg4: | |
3375 | return "DW_OP_reg4"; | |
3376 | case DW_OP_reg5: | |
3377 | return "DW_OP_reg5"; | |
3378 | case DW_OP_reg6: | |
3379 | return "DW_OP_reg6"; | |
3380 | case DW_OP_reg7: | |
3381 | return "DW_OP_reg7"; | |
3382 | case DW_OP_reg8: | |
3383 | return "DW_OP_reg8"; | |
3384 | case DW_OP_reg9: | |
3385 | return "DW_OP_reg9"; | |
3386 | case DW_OP_reg10: | |
3387 | return "DW_OP_reg10"; | |
3388 | case DW_OP_reg11: | |
3389 | return "DW_OP_reg11"; | |
3390 | case DW_OP_reg12: | |
3391 | return "DW_OP_reg12"; | |
3392 | case DW_OP_reg13: | |
3393 | return "DW_OP_reg13"; | |
3394 | case DW_OP_reg14: | |
3395 | return "DW_OP_reg14"; | |
3396 | case DW_OP_reg15: | |
3397 | return "DW_OP_reg15"; | |
3398 | case DW_OP_reg16: | |
3399 | return "DW_OP_reg16"; | |
3400 | case DW_OP_reg17: | |
3401 | return "DW_OP_reg17"; | |
3402 | case DW_OP_reg18: | |
3403 | return "DW_OP_reg18"; | |
3404 | case DW_OP_reg19: | |
3405 | return "DW_OP_reg19"; | |
3406 | case DW_OP_reg20: | |
3407 | return "DW_OP_reg20"; | |
3408 | case DW_OP_reg21: | |
3409 | return "DW_OP_reg21"; | |
3410 | case DW_OP_reg22: | |
3411 | return "DW_OP_reg22"; | |
3412 | case DW_OP_reg23: | |
3413 | return "DW_OP_reg23"; | |
3414 | case DW_OP_reg24: | |
3415 | return "DW_OP_reg24"; | |
3416 | case DW_OP_reg25: | |
3417 | return "DW_OP_reg25"; | |
3418 | case DW_OP_reg26: | |
3419 | return "DW_OP_reg26"; | |
3420 | case DW_OP_reg27: | |
3421 | return "DW_OP_reg27"; | |
3422 | case DW_OP_reg28: | |
3423 | return "DW_OP_reg28"; | |
3424 | case DW_OP_reg29: | |
3425 | return "DW_OP_reg29"; | |
3426 | case DW_OP_reg30: | |
3427 | return "DW_OP_reg30"; | |
3428 | case DW_OP_reg31: | |
3429 | return "DW_OP_reg31"; | |
3430 | case DW_OP_breg0: | |
3431 | return "DW_OP_breg0"; | |
3432 | case DW_OP_breg1: | |
3433 | return "DW_OP_breg1"; | |
3434 | case DW_OP_breg2: | |
3435 | return "DW_OP_breg2"; | |
3436 | case DW_OP_breg3: | |
3437 | return "DW_OP_breg3"; | |
3438 | case DW_OP_breg4: | |
3439 | return "DW_OP_breg4"; | |
3440 | case DW_OP_breg5: | |
3441 | return "DW_OP_breg5"; | |
3442 | case DW_OP_breg6: | |
3443 | return "DW_OP_breg6"; | |
3444 | case DW_OP_breg7: | |
3445 | return "DW_OP_breg7"; | |
3446 | case DW_OP_breg8: | |
3447 | return "DW_OP_breg8"; | |
3448 | case DW_OP_breg9: | |
3449 | return "DW_OP_breg9"; | |
3450 | case DW_OP_breg10: | |
3451 | return "DW_OP_breg10"; | |
3452 | case DW_OP_breg11: | |
3453 | return "DW_OP_breg11"; | |
3454 | case DW_OP_breg12: | |
3455 | return "DW_OP_breg12"; | |
3456 | case DW_OP_breg13: | |
3457 | return "DW_OP_breg13"; | |
3458 | case DW_OP_breg14: | |
3459 | return "DW_OP_breg14"; | |
3460 | case DW_OP_breg15: | |
3461 | return "DW_OP_breg15"; | |
3462 | case DW_OP_breg16: | |
3463 | return "DW_OP_breg16"; | |
3464 | case DW_OP_breg17: | |
3465 | return "DW_OP_breg17"; | |
3466 | case DW_OP_breg18: | |
3467 | return "DW_OP_breg18"; | |
3468 | case DW_OP_breg19: | |
3469 | return "DW_OP_breg19"; | |
3470 | case DW_OP_breg20: | |
3471 | return "DW_OP_breg20"; | |
3472 | case DW_OP_breg21: | |
3473 | return "DW_OP_breg21"; | |
3474 | case DW_OP_breg22: | |
3475 | return "DW_OP_breg22"; | |
3476 | case DW_OP_breg23: | |
3477 | return "DW_OP_breg23"; | |
3478 | case DW_OP_breg24: | |
3479 | return "DW_OP_breg24"; | |
3480 | case DW_OP_breg25: | |
3481 | return "DW_OP_breg25"; | |
3482 | case DW_OP_breg26: | |
3483 | return "DW_OP_breg26"; | |
3484 | case DW_OP_breg27: | |
3485 | return "DW_OP_breg27"; | |
3486 | case DW_OP_breg28: | |
3487 | return "DW_OP_breg28"; | |
3488 | case DW_OP_breg29: | |
3489 | return "DW_OP_breg29"; | |
3490 | case DW_OP_breg30: | |
3491 | return "DW_OP_breg30"; | |
3492 | case DW_OP_breg31: | |
3493 | return "DW_OP_breg31"; | |
3494 | case DW_OP_regx: | |
3495 | return "DW_OP_regx"; | |
3496 | case DW_OP_fbreg: | |
3497 | return "DW_OP_fbreg"; | |
3498 | case DW_OP_bregx: | |
3499 | return "DW_OP_bregx"; | |
3500 | case DW_OP_piece: | |
3501 | return "DW_OP_piece"; | |
3502 | case DW_OP_deref_size: | |
3503 | return "DW_OP_deref_size"; | |
3504 | case DW_OP_xderef_size: | |
3505 | return "DW_OP_xderef_size"; | |
3506 | case DW_OP_nop: | |
3507 | return "DW_OP_nop"; | |
3508 | default: | |
3509 | return "OP_<unknown>"; | |
a3f97cbb JW |
3510 | } |
3511 | } | |
3512 | ||
3f76745e | 3513 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 3514 | |
487a6e06 | 3515 | #if 0 |
3f76745e JM |
3516 | static char * |
3517 | dwarf_type_encoding_name (enc) | |
3518 | register unsigned enc; | |
a3f97cbb | 3519 | { |
3f76745e | 3520 | switch (enc) |
a3f97cbb | 3521 | { |
3f76745e JM |
3522 | case DW_ATE_address: |
3523 | return "DW_ATE_address"; | |
3524 | case DW_ATE_boolean: | |
3525 | return "DW_ATE_boolean"; | |
3526 | case DW_ATE_complex_float: | |
3527 | return "DW_ATE_complex_float"; | |
3528 | case DW_ATE_float: | |
3529 | return "DW_ATE_float"; | |
3530 | case DW_ATE_signed: | |
3531 | return "DW_ATE_signed"; | |
3532 | case DW_ATE_signed_char: | |
3533 | return "DW_ATE_signed_char"; | |
3534 | case DW_ATE_unsigned: | |
3535 | return "DW_ATE_unsigned"; | |
3536 | case DW_ATE_unsigned_char: | |
3537 | return "DW_ATE_unsigned_char"; | |
3538 | default: | |
3539 | return "DW_ATE_<unknown>"; | |
3540 | } | |
a3f97cbb | 3541 | } |
487a6e06 | 3542 | #endif |
3f76745e JM |
3543 | \f |
3544 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
3545 | instance of an inlined instance of a decl which is local to an inline | |
3546 | function, so we have to trace all of the way back through the origin chain | |
3547 | to find out what sort of node actually served as the original seed for the | |
3548 | given block. */ | |
a3f97cbb | 3549 | |
3f76745e JM |
3550 | static tree |
3551 | decl_ultimate_origin (decl) | |
3552 | register tree decl; | |
a3f97cbb | 3553 | { |
02e24c7a MM |
3554 | #ifdef ENABLE_CHECKING |
3555 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) | |
3556 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
3557 | most distant ancestor, this should never happen. */ | |
3558 | abort (); | |
3559 | #endif | |
3f76745e | 3560 | |
02e24c7a | 3561 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
3562 | } |
3563 | ||
3f76745e JM |
3564 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
3565 | instance of an inlined instance of a block which is local to an inline | |
3566 | function, so we have to trace all of the way back through the origin chain | |
3567 | to find out what sort of node actually served as the original seed for the | |
3568 | given block. */ | |
71dfc51f | 3569 | |
3f76745e JM |
3570 | static tree |
3571 | block_ultimate_origin (block) | |
3572 | register tree block; | |
a3f97cbb | 3573 | { |
3f76745e | 3574 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 3575 | |
3f76745e JM |
3576 | if (immediate_origin == NULL_TREE) |
3577 | return NULL_TREE; | |
3578 | else | |
3579 | { | |
3580 | register tree ret_val; | |
3581 | register tree lookahead = immediate_origin; | |
71dfc51f | 3582 | |
3f76745e JM |
3583 | do |
3584 | { | |
3585 | ret_val = lookahead; | |
3586 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
3587 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
3588 | : NULL; | |
3589 | } | |
3590 | while (lookahead != NULL && lookahead != ret_val); | |
3591 | ||
3592 | return ret_val; | |
3593 | } | |
a3f97cbb JW |
3594 | } |
3595 | ||
3f76745e JM |
3596 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
3597 | of a virtual function may refer to a base class, so we check the 'this' | |
3598 | parameter. */ | |
71dfc51f | 3599 | |
3f76745e JM |
3600 | static tree |
3601 | decl_class_context (decl) | |
3602 | tree decl; | |
a3f97cbb | 3603 | { |
3f76745e | 3604 | tree context = NULL_TREE; |
71dfc51f | 3605 | |
3f76745e JM |
3606 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
3607 | context = DECL_CONTEXT (decl); | |
3608 | else | |
3609 | context = TYPE_MAIN_VARIANT | |
3610 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 3611 | |
3f76745e JM |
3612 | if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't') |
3613 | context = NULL_TREE; | |
3614 | ||
3615 | return context; | |
a3f97cbb JW |
3616 | } |
3617 | \f | |
3f76745e | 3618 | /* Add an attribute/value pair to a DIE */ |
71dfc51f RK |
3619 | |
3620 | static inline void | |
3f76745e JM |
3621 | add_dwarf_attr (die, attr) |
3622 | register dw_die_ref die; | |
3623 | register dw_attr_ref attr; | |
a3f97cbb | 3624 | { |
3f76745e | 3625 | if (die != NULL && attr != NULL) |
a3f97cbb | 3626 | { |
3f76745e | 3627 | if (die->die_attr == NULL) |
a3f97cbb | 3628 | { |
3f76745e JM |
3629 | die->die_attr = attr; |
3630 | die->die_attr_last = attr; | |
3631 | } | |
3632 | else | |
3633 | { | |
3634 | die->die_attr_last->dw_attr_next = attr; | |
3635 | die->die_attr_last = attr; | |
a3f97cbb | 3636 | } |
a3f97cbb JW |
3637 | } |
3638 | } | |
3639 | ||
3f76745e | 3640 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 3641 | |
3f76745e JM |
3642 | static inline void |
3643 | add_AT_flag (die, attr_kind, flag) | |
3644 | register dw_die_ref die; | |
3645 | register enum dwarf_attribute attr_kind; | |
3646 | register unsigned flag; | |
a3f97cbb | 3647 | { |
3f76745e | 3648 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3649 | |
3f76745e JM |
3650 | attr->dw_attr_next = NULL; |
3651 | attr->dw_attr = attr_kind; | |
3652 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
3653 | attr->dw_attr_val.v.val_flag = flag; | |
3654 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3655 | } |
3656 | ||
3f76745e | 3657 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 3658 | |
3f76745e JM |
3659 | static inline void |
3660 | add_AT_int (die, attr_kind, int_val) | |
3661 | register dw_die_ref die; | |
3662 | register enum dwarf_attribute attr_kind; | |
3663 | register long int int_val; | |
a3f97cbb | 3664 | { |
3f76745e JM |
3665 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3666 | ||
3667 | attr->dw_attr_next = NULL; | |
3668 | attr->dw_attr = attr_kind; | |
3669 | attr->dw_attr_val.val_class = dw_val_class_const; | |
3670 | attr->dw_attr_val.v.val_int = int_val; | |
3671 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3672 | } |
3673 | ||
3f76745e | 3674 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 3675 | |
3f76745e JM |
3676 | static inline void |
3677 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
3678 | register dw_die_ref die; | |
3679 | register enum dwarf_attribute attr_kind; | |
3680 | register unsigned long unsigned_val; | |
a3f97cbb | 3681 | { |
3f76745e JM |
3682 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3683 | ||
3684 | attr->dw_attr_next = NULL; | |
3685 | attr->dw_attr = attr_kind; | |
3686 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
3687 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
3688 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3689 | } |
71dfc51f | 3690 | |
3f76745e JM |
3691 | /* Add an unsigned double integer attribute value to a DIE. */ |
3692 | ||
3693 | static inline void | |
3694 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 3695 | register dw_die_ref die; |
3f76745e JM |
3696 | register enum dwarf_attribute attr_kind; |
3697 | register unsigned long val_hi; | |
3698 | register unsigned long val_low; | |
a3f97cbb | 3699 | { |
3f76745e | 3700 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3701 | |
3f76745e JM |
3702 | attr->dw_attr_next = NULL; |
3703 | attr->dw_attr = attr_kind; | |
3704 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
3705 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
3706 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
3707 | add_dwarf_attr (die, attr); | |
3708 | } | |
71dfc51f | 3709 | |
3f76745e | 3710 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 3711 | |
3f76745e JM |
3712 | static inline void |
3713 | add_AT_float (die, attr_kind, length, array) | |
3714 | register dw_die_ref die; | |
3715 | register enum dwarf_attribute attr_kind; | |
3716 | register unsigned length; | |
3717 | register long *array; | |
3718 | { | |
3719 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
3720 | ||
3721 | attr->dw_attr_next = NULL; | |
3722 | attr->dw_attr = attr_kind; | |
3723 | attr->dw_attr_val.val_class = dw_val_class_float; | |
3724 | attr->dw_attr_val.v.val_float.length = length; | |
3725 | attr->dw_attr_val.v.val_float.array = array; | |
3726 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3727 | } |
3728 | ||
3f76745e | 3729 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 3730 | |
3f76745e JM |
3731 | static inline void |
3732 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 3733 | register dw_die_ref die; |
3f76745e JM |
3734 | register enum dwarf_attribute attr_kind; |
3735 | register char *str; | |
a3f97cbb | 3736 | { |
3f76745e | 3737 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3738 | |
3f76745e JM |
3739 | attr->dw_attr_next = NULL; |
3740 | attr->dw_attr = attr_kind; | |
3741 | attr->dw_attr_val.val_class = dw_val_class_str; | |
3742 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
3743 | add_dwarf_attr (die, attr); | |
3744 | } | |
71dfc51f | 3745 | |
3f76745e | 3746 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 3747 | |
3f76745e JM |
3748 | static inline void |
3749 | add_AT_die_ref (die, attr_kind, targ_die) | |
3750 | register dw_die_ref die; | |
3751 | register enum dwarf_attribute attr_kind; | |
3752 | register dw_die_ref targ_die; | |
3753 | { | |
3754 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3755 | |
3f76745e JM |
3756 | attr->dw_attr_next = NULL; |
3757 | attr->dw_attr = attr_kind; | |
3758 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
3759 | attr->dw_attr_val.v.val_die_ref = targ_die; | |
3760 | add_dwarf_attr (die, attr); | |
3761 | } | |
b1ccbc24 | 3762 | |
3f76745e | 3763 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 3764 | |
3f76745e JM |
3765 | static inline void |
3766 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
3767 | register dw_die_ref die; | |
3768 | register enum dwarf_attribute attr_kind; | |
3769 | register unsigned targ_fde; | |
3770 | { | |
3771 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 3772 | |
3f76745e JM |
3773 | attr->dw_attr_next = NULL; |
3774 | attr->dw_attr = attr_kind; | |
3775 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
3776 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
3777 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3778 | } |
71dfc51f | 3779 | |
3f76745e | 3780 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 3781 | |
3f76745e JM |
3782 | static inline void |
3783 | add_AT_loc (die, attr_kind, loc) | |
3784 | register dw_die_ref die; | |
3785 | register enum dwarf_attribute attr_kind; | |
3786 | register dw_loc_descr_ref loc; | |
3787 | { | |
3788 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3789 | |
3f76745e JM |
3790 | attr->dw_attr_next = NULL; |
3791 | attr->dw_attr = attr_kind; | |
3792 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
3793 | attr->dw_attr_val.v.val_loc = loc; | |
3794 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3795 | } |
3796 | ||
3f76745e | 3797 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 3798 | |
3f76745e JM |
3799 | static inline void |
3800 | add_AT_addr (die, attr_kind, addr) | |
3801 | register dw_die_ref die; | |
3802 | register enum dwarf_attribute attr_kind; | |
3803 | char *addr; | |
a3f97cbb | 3804 | { |
3f76745e | 3805 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3806 | |
3f76745e JM |
3807 | attr->dw_attr_next = NULL; |
3808 | attr->dw_attr = attr_kind; | |
3809 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
3810 | attr->dw_attr_val.v.val_addr = addr; | |
3811 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3812 | } |
3813 | ||
3f76745e | 3814 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 3815 | |
3f76745e JM |
3816 | static inline void |
3817 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
3818 | register dw_die_ref die; | |
3819 | register enum dwarf_attribute attr_kind; | |
3820 | register char *lbl_id; | |
a3f97cbb | 3821 | { |
3f76745e | 3822 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3823 | |
3f76745e JM |
3824 | attr->dw_attr_next = NULL; |
3825 | attr->dw_attr = attr_kind; | |
3826 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
3827 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
3828 | add_dwarf_attr (die, attr); | |
3829 | } | |
71dfc51f | 3830 | |
3f76745e JM |
3831 | /* Add a section offset attribute value to a DIE. */ |
3832 | ||
3833 | static inline void | |
1553e85a | 3834 | add_AT_section_offset (die, attr_kind, section) |
3f76745e JM |
3835 | register dw_die_ref die; |
3836 | register enum dwarf_attribute attr_kind; | |
1553e85a | 3837 | register char *section; |
3f76745e JM |
3838 | { |
3839 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3840 | |
3f76745e JM |
3841 | attr->dw_attr_next = NULL; |
3842 | attr->dw_attr = attr_kind; | |
3843 | attr->dw_attr_val.val_class = dw_val_class_section_offset; | |
1553e85a | 3844 | attr->dw_attr_val.v.val_section = section; |
3f76745e JM |
3845 | add_dwarf_attr (die, attr); |
3846 | ||
a3f97cbb JW |
3847 | } |
3848 | ||
3f76745e | 3849 | /* Test if die refers to an external subroutine. */ |
71dfc51f | 3850 | |
3f76745e JM |
3851 | static inline int |
3852 | is_extern_subr_die (die) | |
3853 | register dw_die_ref die; | |
a3f97cbb | 3854 | { |
3f76745e JM |
3855 | register dw_attr_ref a; |
3856 | register int is_subr = FALSE; | |
3857 | register int is_extern = FALSE; | |
71dfc51f | 3858 | |
3f76745e | 3859 | if (die != NULL && die->die_tag == DW_TAG_subprogram) |
a3f97cbb | 3860 | { |
3f76745e JM |
3861 | is_subr = TRUE; |
3862 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3863 | { | |
3864 | if (a->dw_attr == DW_AT_external | |
3865 | && a->dw_attr_val.val_class == dw_val_class_flag | |
3866 | && a->dw_attr_val.v.val_flag != 0) | |
3867 | { | |
3868 | is_extern = TRUE; | |
3869 | break; | |
3870 | } | |
3871 | } | |
a3f97cbb | 3872 | } |
71dfc51f | 3873 | |
3f76745e | 3874 | return is_subr && is_extern; |
a3f97cbb JW |
3875 | } |
3876 | ||
3f76745e | 3877 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 3878 | |
3f76745e JM |
3879 | static inline dw_attr_ref |
3880 | get_AT (die, attr_kind) | |
3881 | register dw_die_ref die; | |
3882 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 3883 | { |
3f76745e JM |
3884 | register dw_attr_ref a; |
3885 | register dw_die_ref spec = NULL; | |
3886 | ||
3887 | if (die != NULL) | |
3888 | { | |
3889 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3890 | { | |
3891 | if (a->dw_attr == attr_kind) | |
3892 | return a; | |
71dfc51f | 3893 | |
3f76745e JM |
3894 | if (a->dw_attr == DW_AT_specification |
3895 | || a->dw_attr == DW_AT_abstract_origin) | |
3896 | spec = a->dw_attr_val.v.val_die_ref; | |
3897 | } | |
71dfc51f | 3898 | |
3f76745e JM |
3899 | if (spec) |
3900 | return get_AT (spec, attr_kind); | |
3901 | } | |
3902 | ||
3903 | return NULL; | |
f37230f0 JM |
3904 | } |
3905 | ||
3f76745e JM |
3906 | /* Return the "low pc" attribute value, typically associated with |
3907 | a subprogram DIE. Return null if the "low pc" attribute is | |
3908 | either not prsent, or if it cannot be represented as an | |
3909 | assembler label identifier. */ | |
71dfc51f | 3910 | |
3f76745e JM |
3911 | static inline char * |
3912 | get_AT_low_pc (die) | |
3913 | register dw_die_ref die; | |
7e23cb16 | 3914 | { |
3f76745e | 3915 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
7e23cb16 | 3916 | |
3f76745e JM |
3917 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3918 | return a->dw_attr_val.v.val_lbl_id; | |
7e23cb16 | 3919 | |
3f76745e | 3920 | return NULL; |
7e23cb16 JM |
3921 | } |
3922 | ||
3f76745e JM |
3923 | /* Return the "high pc" attribute value, typically associated with |
3924 | a subprogram DIE. Return null if the "high pc" attribute is | |
3925 | either not prsent, or if it cannot be represented as an | |
3926 | assembler label identifier. */ | |
71dfc51f | 3927 | |
3f76745e JM |
3928 | static inline char * |
3929 | get_AT_hi_pc (die) | |
a3f97cbb JW |
3930 | register dw_die_ref die; |
3931 | { | |
3f76745e | 3932 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
71dfc51f | 3933 | |
3f76745e JM |
3934 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3935 | return a->dw_attr_val.v.val_lbl_id; | |
f37230f0 | 3936 | |
3f76745e JM |
3937 | return NULL; |
3938 | } | |
3939 | ||
3940 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
3941 | NULL if it is not present. */ | |
71dfc51f | 3942 | |
3f76745e JM |
3943 | static inline char * |
3944 | get_AT_string (die, attr_kind) | |
3945 | register dw_die_ref die; | |
3946 | register enum dwarf_attribute attr_kind; | |
3947 | { | |
3948 | register dw_attr_ref a = get_AT (die, attr_kind); | |
3949 | ||
3950 | if (a && a->dw_attr_val.val_class == dw_val_class_str) | |
3951 | return a->dw_attr_val.v.val_str; | |
3952 | ||
3953 | return NULL; | |
a3f97cbb JW |
3954 | } |
3955 | ||
3f76745e JM |
3956 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
3957 | if it is not present. */ | |
71dfc51f | 3958 | |
3f76745e JM |
3959 | static inline int |
3960 | get_AT_flag (die, attr_kind) | |
3961 | register dw_die_ref die; | |
3962 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3963 | { |
3f76745e | 3964 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3965 | |
3f76745e JM |
3966 | if (a && a->dw_attr_val.val_class == dw_val_class_flag) |
3967 | return a->dw_attr_val.v.val_flag; | |
71dfc51f | 3968 | |
3f76745e | 3969 | return -1; |
a3f97cbb JW |
3970 | } |
3971 | ||
3f76745e JM |
3972 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
3973 | if it is not present. */ | |
71dfc51f | 3974 | |
3f76745e JM |
3975 | static inline unsigned |
3976 | get_AT_unsigned (die, attr_kind) | |
3977 | register dw_die_ref die; | |
3978 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3979 | { |
3f76745e | 3980 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3981 | |
3f76745e JM |
3982 | if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const) |
3983 | return a->dw_attr_val.v.val_unsigned; | |
71dfc51f | 3984 | |
3f76745e JM |
3985 | return 0; |
3986 | } | |
71dfc51f | 3987 | |
3f76745e JM |
3988 | static inline int |
3989 | is_c_family () | |
3990 | { | |
3991 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3992 | |
3f76745e JM |
3993 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
3994 | || lang == DW_LANG_C_plus_plus); | |
3995 | } | |
71dfc51f | 3996 | |
3f76745e JM |
3997 | static inline int |
3998 | is_fortran () | |
3999 | { | |
4000 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4001 | |
3f76745e JM |
4002 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
4003 | } | |
71dfc51f | 4004 | |
3f76745e | 4005 | /* Remove the specified attribute if present. */ |
71dfc51f | 4006 | |
3f76745e JM |
4007 | static inline void |
4008 | remove_AT (die, attr_kind) | |
4009 | register dw_die_ref die; | |
4010 | register enum dwarf_attribute attr_kind; | |
4011 | { | |
4012 | register dw_attr_ref a; | |
4013 | register dw_attr_ref removed = NULL;; | |
a3f97cbb | 4014 | |
3f76745e JM |
4015 | if (die != NULL) |
4016 | { | |
4017 | if (die->die_attr->dw_attr == attr_kind) | |
4018 | { | |
4019 | removed = die->die_attr; | |
4020 | if (die->die_attr_last == die->die_attr) | |
4021 | die->die_attr_last = NULL; | |
71dfc51f | 4022 | |
3f76745e JM |
4023 | die->die_attr = die->die_attr->dw_attr_next; |
4024 | } | |
71dfc51f | 4025 | |
3f76745e JM |
4026 | else |
4027 | for (a = die->die_attr; a->dw_attr_next != NULL; | |
4028 | a = a->dw_attr_next) | |
4029 | if (a->dw_attr_next->dw_attr == attr_kind) | |
4030 | { | |
4031 | removed = a->dw_attr_next; | |
4032 | if (die->die_attr_last == a->dw_attr_next) | |
4033 | die->die_attr_last = a; | |
71dfc51f | 4034 | |
3f76745e JM |
4035 | a->dw_attr_next = a->dw_attr_next->dw_attr_next; |
4036 | break; | |
4037 | } | |
71dfc51f | 4038 | |
3f76745e JM |
4039 | if (removed != 0) |
4040 | free (removed); | |
4041 | } | |
4042 | } | |
71dfc51f | 4043 | |
3f76745e | 4044 | /* Discard the children of this DIE. */ |
71dfc51f | 4045 | |
3f76745e JM |
4046 | static inline void |
4047 | remove_children (die) | |
4048 | register dw_die_ref die; | |
4049 | { | |
4050 | register dw_die_ref child_die = die->die_child; | |
4051 | ||
4052 | die->die_child = NULL; | |
4053 | die->die_child_last = NULL; | |
4054 | ||
4055 | while (child_die != NULL) | |
a3f97cbb | 4056 | { |
3f76745e JM |
4057 | register dw_die_ref tmp_die = child_die; |
4058 | register dw_attr_ref a; | |
71dfc51f | 4059 | |
3f76745e JM |
4060 | child_die = child_die->die_sib; |
4061 | ||
4062 | for (a = tmp_die->die_attr; a != NULL; ) | |
a3f97cbb | 4063 | { |
3f76745e | 4064 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4065 | |
3f76745e JM |
4066 | a = a->dw_attr_next; |
4067 | free (tmp_a); | |
a3f97cbb | 4068 | } |
71dfc51f | 4069 | |
3f76745e JM |
4070 | free (tmp_die); |
4071 | } | |
4072 | } | |
71dfc51f | 4073 | |
3f76745e | 4074 | /* Add a child DIE below its parent. */ |
71dfc51f | 4075 | |
3f76745e JM |
4076 | static inline void |
4077 | add_child_die (die, child_die) | |
4078 | register dw_die_ref die; | |
4079 | register dw_die_ref child_die; | |
4080 | { | |
4081 | if (die != NULL && child_die != NULL) | |
e90b62db | 4082 | { |
3a88cbd1 JL |
4083 | if (die == child_die) |
4084 | abort (); | |
3f76745e JM |
4085 | child_die->die_parent = die; |
4086 | child_die->die_sib = NULL; | |
4087 | ||
4088 | if (die->die_child == NULL) | |
e90b62db | 4089 | { |
3f76745e JM |
4090 | die->die_child = child_die; |
4091 | die->die_child_last = child_die; | |
e90b62db JM |
4092 | } |
4093 | else | |
e90b62db | 4094 | { |
3f76745e JM |
4095 | die->die_child_last->die_sib = child_die; |
4096 | die->die_child_last = child_die; | |
e90b62db | 4097 | } |
3f76745e JM |
4098 | } |
4099 | } | |
4100 | ||
4101 | /* Return a pointer to a newly created DIE node. */ | |
4102 | ||
4103 | static inline dw_die_ref | |
4104 | new_die (tag_value, parent_die) | |
4105 | register enum dwarf_tag tag_value; | |
4106 | register dw_die_ref parent_die; | |
4107 | { | |
4108 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
4109 | ||
4110 | die->die_tag = tag_value; | |
4111 | die->die_abbrev = 0; | |
4112 | die->die_offset = 0; | |
4113 | die->die_child = NULL; | |
4114 | die->die_parent = NULL; | |
4115 | die->die_sib = NULL; | |
4116 | die->die_child_last = NULL; | |
4117 | die->die_attr = NULL; | |
4118 | die->die_attr_last = NULL; | |
4119 | ||
4120 | if (parent_die != NULL) | |
4121 | add_child_die (parent_die, die); | |
4122 | else | |
ef76d03b JW |
4123 | { |
4124 | limbo_die_node *limbo_node; | |
4125 | ||
4126 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4127 | limbo_node->die = die; | |
4128 | limbo_node->next = limbo_die_list; | |
4129 | limbo_die_list = limbo_node; | |
4130 | } | |
71dfc51f | 4131 | |
3f76745e JM |
4132 | return die; |
4133 | } | |
71dfc51f | 4134 | |
3f76745e | 4135 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4136 | |
3f76745e JM |
4137 | static inline dw_die_ref |
4138 | lookup_type_die (type) | |
4139 | register tree type; | |
4140 | { | |
4141 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
4142 | } | |
e90b62db | 4143 | |
3f76745e | 4144 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4145 | |
3f76745e JM |
4146 | static void |
4147 | equate_type_number_to_die (type, type_die) | |
4148 | register tree type; | |
4149 | register dw_die_ref type_die; | |
4150 | { | |
4151 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4152 | } | |
71dfc51f | 4153 | |
3f76745e | 4154 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4155 | |
3f76745e JM |
4156 | static inline dw_die_ref |
4157 | lookup_decl_die (decl) | |
4158 | register tree decl; | |
4159 | { | |
4160 | register unsigned decl_id = DECL_UID (decl); | |
4161 | ||
4162 | return (decl_id < decl_die_table_in_use | |
4163 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4164 | } |
4165 | ||
3f76745e | 4166 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4167 | |
3f76745e JM |
4168 | static void |
4169 | equate_decl_number_to_die (decl, decl_die) | |
4170 | register tree decl; | |
4171 | register dw_die_ref decl_die; | |
a3f97cbb | 4172 | { |
3f76745e | 4173 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 4174 | register unsigned num_allocated; |
d291dd49 | 4175 | |
3f76745e | 4176 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4177 | { |
3f76745e JM |
4178 | num_allocated |
4179 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4180 | / DECL_DIE_TABLE_INCREMENT) | |
4181 | * DECL_DIE_TABLE_INCREMENT; | |
4182 | ||
4183 | decl_die_table | |
4184 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4185 | sizeof (dw_die_ref) * num_allocated); | |
4186 | ||
4187 | bzero ((char *) &decl_die_table[decl_die_table_allocated], | |
4188 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); | |
4189 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4190 | } |
71dfc51f | 4191 | |
3f76745e JM |
4192 | if (decl_id >= decl_die_table_in_use) |
4193 | decl_die_table_in_use = (decl_id + 1); | |
4194 | ||
4195 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb JW |
4196 | } |
4197 | ||
3f76745e JM |
4198 | /* Return a pointer to a newly allocated location description. Location |
4199 | descriptions are simple expression terms that can be strung | |
4200 | together to form more complicated location (address) descriptions. */ | |
71dfc51f | 4201 | |
3f76745e JM |
4202 | static inline dw_loc_descr_ref |
4203 | new_loc_descr (op, oprnd1, oprnd2) | |
4204 | register enum dwarf_location_atom op; | |
4205 | register unsigned long oprnd1; | |
4206 | register unsigned long oprnd2; | |
a3f97cbb | 4207 | { |
3f76745e JM |
4208 | register dw_loc_descr_ref descr |
4209 | = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node)); | |
71dfc51f | 4210 | |
3f76745e JM |
4211 | descr->dw_loc_next = NULL; |
4212 | descr->dw_loc_opc = op; | |
4213 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
4214 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
4215 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
4216 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 4217 | |
3f76745e | 4218 | return descr; |
a3f97cbb | 4219 | } |
71dfc51f | 4220 | |
3f76745e JM |
4221 | /* Add a location description term to a location description expression. */ |
4222 | ||
4223 | static inline void | |
4224 | add_loc_descr (list_head, descr) | |
4225 | register dw_loc_descr_ref *list_head; | |
4226 | register dw_loc_descr_ref descr; | |
a3f97cbb | 4227 | { |
3f76745e | 4228 | register dw_loc_descr_ref *d; |
71dfc51f | 4229 | |
3f76745e JM |
4230 | /* Find the end of the chain. */ |
4231 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
4232 | ; | |
71dfc51f | 4233 | |
3f76745e JM |
4234 | *d = descr; |
4235 | } | |
4236 | \f | |
4237 | /* Keep track of the number of spaces used to indent the | |
4238 | output of the debugging routines that print the structure of | |
4239 | the DIE internal representation. */ | |
4240 | static int print_indent; | |
71dfc51f | 4241 | |
3f76745e JM |
4242 | /* Indent the line the number of spaces given by print_indent. */ |
4243 | ||
4244 | static inline void | |
4245 | print_spaces (outfile) | |
4246 | FILE *outfile; | |
4247 | { | |
4248 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4249 | } |
4250 | ||
956d6950 | 4251 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4252 | This routine is a debugging aid only. */ |
71dfc51f | 4253 | |
a3f97cbb | 4254 | static void |
3f76745e JM |
4255 | print_die (die, outfile) |
4256 | dw_die_ref die; | |
4257 | FILE *outfile; | |
a3f97cbb | 4258 | { |
3f76745e JM |
4259 | register dw_attr_ref a; |
4260 | register dw_die_ref c; | |
71dfc51f | 4261 | |
3f76745e | 4262 | print_spaces (outfile); |
2d8b0f3a | 4263 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
4264 | die->die_offset, dwarf_tag_name (die->die_tag)); |
4265 | print_spaces (outfile); | |
2d8b0f3a JL |
4266 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
4267 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
4268 | |
4269 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 4270 | { |
3f76745e JM |
4271 | print_spaces (outfile); |
4272 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
4273 | ||
4274 | switch (a->dw_attr_val.val_class) | |
4275 | { | |
4276 | case dw_val_class_addr: | |
4277 | fprintf (outfile, "address"); | |
4278 | break; | |
4279 | case dw_val_class_loc: | |
4280 | fprintf (outfile, "location descriptor"); | |
4281 | break; | |
4282 | case dw_val_class_const: | |
2d8b0f3a | 4283 | fprintf (outfile, "%ld", a->dw_attr_val.v.val_int); |
3f76745e JM |
4284 | break; |
4285 | case dw_val_class_unsigned_const: | |
2d8b0f3a | 4286 | fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned); |
3f76745e JM |
4287 | break; |
4288 | case dw_val_class_long_long: | |
2d8b0f3a | 4289 | fprintf (outfile, "constant (%lu,%lu)", |
3f76745e JM |
4290 | a->dw_attr_val.v.val_long_long.hi, |
4291 | a->dw_attr_val.v.val_long_long.low); | |
4292 | break; | |
4293 | case dw_val_class_float: | |
4294 | fprintf (outfile, "floating-point constant"); | |
4295 | break; | |
4296 | case dw_val_class_flag: | |
4297 | fprintf (outfile, "%u", a->dw_attr_val.v.val_flag); | |
4298 | break; | |
4299 | case dw_val_class_die_ref: | |
4300 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
2d8b0f3a | 4301 | fprintf (outfile, "die -> %lu", |
3f76745e JM |
4302 | a->dw_attr_val.v.val_die_ref->die_offset); |
4303 | else | |
4304 | fprintf (outfile, "die -> <null>"); | |
4305 | break; | |
4306 | case dw_val_class_lbl_id: | |
4307 | fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id); | |
4308 | break; | |
4309 | case dw_val_class_section_offset: | |
1553e85a | 4310 | fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section); |
3f76745e JM |
4311 | break; |
4312 | case dw_val_class_str: | |
4313 | if (a->dw_attr_val.v.val_str != NULL) | |
4314 | fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str); | |
4315 | else | |
4316 | fprintf (outfile, "<null>"); | |
4317 | break; | |
e9a25f70 JL |
4318 | default: |
4319 | break; | |
3f76745e JM |
4320 | } |
4321 | ||
4322 | fprintf (outfile, "\n"); | |
4323 | } | |
4324 | ||
4325 | if (die->die_child != NULL) | |
4326 | { | |
4327 | print_indent += 4; | |
4328 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4329 | print_die (c, outfile); | |
71dfc51f | 4330 | |
3f76745e | 4331 | print_indent -= 4; |
a3f97cbb | 4332 | } |
a3f97cbb JW |
4333 | } |
4334 | ||
3f76745e JM |
4335 | /* Print the contents of the source code line number correspondence table. |
4336 | This routine is a debugging aid only. */ | |
71dfc51f | 4337 | |
3f76745e JM |
4338 | static void |
4339 | print_dwarf_line_table (outfile) | |
4340 | FILE *outfile; | |
a3f97cbb | 4341 | { |
3f76745e JM |
4342 | register unsigned i; |
4343 | register dw_line_info_ref line_info; | |
4344 | ||
4345 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
4346 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 4347 | { |
3f76745e JM |
4348 | line_info = &line_info_table[i]; |
4349 | fprintf (outfile, "%5d: ", i); | |
4350 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
2d8b0f3a | 4351 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 4352 | fprintf (outfile, "\n"); |
a3f97cbb | 4353 | } |
3f76745e JM |
4354 | |
4355 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
4356 | } |
4357 | ||
3f76745e JM |
4358 | /* Print the information collected for a given DIE. */ |
4359 | ||
4360 | void | |
4361 | debug_dwarf_die (die) | |
4362 | dw_die_ref die; | |
4363 | { | |
4364 | print_die (die, stderr); | |
4365 | } | |
4366 | ||
4367 | /* Print all DWARF information collected for the compilation unit. | |
4368 | This routine is a debugging aid only. */ | |
4369 | ||
4370 | void | |
4371 | debug_dwarf () | |
4372 | { | |
4373 | print_indent = 0; | |
4374 | print_die (comp_unit_die, stderr); | |
4375 | print_dwarf_line_table (stderr); | |
4376 | } | |
4377 | \f | |
4378 | /* Traverse the DIE, and add a sibling attribute if it may have the | |
4379 | effect of speeding up access to siblings. To save some space, | |
4380 | avoid generating sibling attributes for DIE's without children. */ | |
71dfc51f | 4381 | |
f37230f0 | 4382 | static void |
3f76745e JM |
4383 | add_sibling_attributes(die) |
4384 | register dw_die_ref die; | |
f37230f0 | 4385 | { |
3f76745e JM |
4386 | register dw_die_ref c; |
4387 | register dw_attr_ref attr; | |
4388 | if (die != comp_unit_die && die->die_child != NULL) | |
4389 | { | |
4390 | attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4391 | attr->dw_attr_next = NULL; | |
4392 | attr->dw_attr = DW_AT_sibling; | |
4393 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
4394 | attr->dw_attr_val.v.val_die_ref = die->die_sib; | |
71dfc51f | 4395 | |
3f76745e JM |
4396 | /* Add the sibling link to the front of the attribute list. */ |
4397 | attr->dw_attr_next = die->die_attr; | |
4398 | if (die->die_attr == NULL) | |
4399 | die->die_attr_last = attr; | |
71dfc51f | 4400 | |
3f76745e JM |
4401 | die->die_attr = attr; |
4402 | } | |
4403 | ||
4404 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4405 | add_sibling_attributes (c); | |
a3f97cbb JW |
4406 | } |
4407 | ||
3f76745e JM |
4408 | /* The format of each DIE (and its attribute value pairs) |
4409 | is encoded in an abbreviation table. This routine builds the | |
4410 | abbreviation table and assigns a unique abbreviation id for | |
4411 | each abbreviation entry. The children of each die are visited | |
4412 | recursively. */ | |
71dfc51f | 4413 | |
a3f97cbb | 4414 | static void |
3f76745e JM |
4415 | build_abbrev_table (die) |
4416 | register dw_die_ref die; | |
a3f97cbb | 4417 | { |
3f76745e JM |
4418 | register unsigned long abbrev_id; |
4419 | register unsigned long n_alloc; | |
4420 | register dw_die_ref c; | |
4421 | register dw_attr_ref d_attr, a_attr; | |
a3f97cbb JW |
4422 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
4423 | { | |
4424 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4425 | |
3f76745e JM |
4426 | if (abbrev->die_tag == die->die_tag) |
4427 | { | |
4428 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
4429 | { | |
4430 | a_attr = abbrev->die_attr; | |
4431 | d_attr = die->die_attr; | |
71dfc51f | 4432 | |
3f76745e JM |
4433 | while (a_attr != NULL && d_attr != NULL) |
4434 | { | |
4435 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
4436 | || (value_format (&a_attr->dw_attr_val) | |
4437 | != value_format (&d_attr->dw_attr_val))) | |
4438 | break; | |
71dfc51f | 4439 | |
3f76745e JM |
4440 | a_attr = a_attr->dw_attr_next; |
4441 | d_attr = d_attr->dw_attr_next; | |
4442 | } | |
71dfc51f | 4443 | |
3f76745e JM |
4444 | if (a_attr == NULL && d_attr == NULL) |
4445 | break; | |
4446 | } | |
4447 | } | |
4448 | } | |
71dfc51f | 4449 | |
3f76745e JM |
4450 | if (abbrev_id >= abbrev_die_table_in_use) |
4451 | { | |
4452 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
a3f97cbb | 4453 | { |
3f76745e JM |
4454 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; |
4455 | abbrev_die_table | |
c760091a | 4456 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
966f5dff | 4457 | sizeof (dw_die_ref) * n_alloc); |
71dfc51f | 4458 | |
3f76745e JM |
4459 | bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated], |
4460 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); | |
4461 | abbrev_die_table_allocated = n_alloc; | |
a3f97cbb | 4462 | } |
71dfc51f | 4463 | |
3f76745e JM |
4464 | ++abbrev_die_table_in_use; |
4465 | abbrev_die_table[abbrev_id] = die; | |
a3f97cbb | 4466 | } |
3f76745e JM |
4467 | |
4468 | die->die_abbrev = abbrev_id; | |
4469 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4470 | build_abbrev_table (c); | |
a3f97cbb | 4471 | } |
3f76745e | 4472 | \f |
243e7835 JW |
4473 | /* Return the size of a string, including the null byte. |
4474 | ||
4475 | This used to treat backslashes as escapes, and hence they were not included | |
4476 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
4477 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
4478 | we must include them in the count. */ | |
a3f97cbb | 4479 | |
3f76745e JM |
4480 | static unsigned long |
4481 | size_of_string (str) | |
4482 | register char *str; | |
4483 | { | |
243e7835 | 4484 | return strlen (str) + 1; |
3f76745e JM |
4485 | } |
4486 | ||
4487 | /* Return the size of a location descriptor. */ | |
4488 | ||
4489 | static unsigned long | |
4490 | size_of_loc_descr (loc) | |
a3f97cbb JW |
4491 | register dw_loc_descr_ref loc; |
4492 | { | |
3f76745e | 4493 | register unsigned long size = 1; |
71dfc51f | 4494 | |
a3f97cbb JW |
4495 | switch (loc->dw_loc_opc) |
4496 | { | |
4497 | case DW_OP_addr: | |
3f76745e | 4498 | size += PTR_SIZE; |
a3f97cbb JW |
4499 | break; |
4500 | case DW_OP_const1u: | |
4501 | case DW_OP_const1s: | |
3f76745e | 4502 | size += 1; |
a3f97cbb JW |
4503 | break; |
4504 | case DW_OP_const2u: | |
4505 | case DW_OP_const2s: | |
3f76745e | 4506 | size += 2; |
a3f97cbb JW |
4507 | break; |
4508 | case DW_OP_const4u: | |
4509 | case DW_OP_const4s: | |
3f76745e | 4510 | size += 4; |
a3f97cbb JW |
4511 | break; |
4512 | case DW_OP_const8u: | |
4513 | case DW_OP_const8s: | |
3f76745e | 4514 | size += 8; |
a3f97cbb JW |
4515 | break; |
4516 | case DW_OP_constu: | |
3f76745e | 4517 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4518 | break; |
4519 | case DW_OP_consts: | |
3f76745e | 4520 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4521 | break; |
4522 | case DW_OP_pick: | |
3f76745e | 4523 | size += 1; |
a3f97cbb JW |
4524 | break; |
4525 | case DW_OP_plus_uconst: | |
3f76745e | 4526 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4527 | break; |
4528 | case DW_OP_skip: | |
4529 | case DW_OP_bra: | |
3f76745e | 4530 | size += 2; |
a3f97cbb JW |
4531 | break; |
4532 | case DW_OP_breg0: | |
4533 | case DW_OP_breg1: | |
4534 | case DW_OP_breg2: | |
4535 | case DW_OP_breg3: | |
4536 | case DW_OP_breg4: | |
4537 | case DW_OP_breg5: | |
4538 | case DW_OP_breg6: | |
4539 | case DW_OP_breg7: | |
4540 | case DW_OP_breg8: | |
4541 | case DW_OP_breg9: | |
4542 | case DW_OP_breg10: | |
4543 | case DW_OP_breg11: | |
4544 | case DW_OP_breg12: | |
4545 | case DW_OP_breg13: | |
4546 | case DW_OP_breg14: | |
4547 | case DW_OP_breg15: | |
4548 | case DW_OP_breg16: | |
4549 | case DW_OP_breg17: | |
4550 | case DW_OP_breg18: | |
4551 | case DW_OP_breg19: | |
4552 | case DW_OP_breg20: | |
4553 | case DW_OP_breg21: | |
4554 | case DW_OP_breg22: | |
4555 | case DW_OP_breg23: | |
4556 | case DW_OP_breg24: | |
4557 | case DW_OP_breg25: | |
4558 | case DW_OP_breg26: | |
4559 | case DW_OP_breg27: | |
4560 | case DW_OP_breg28: | |
4561 | case DW_OP_breg29: | |
4562 | case DW_OP_breg30: | |
4563 | case DW_OP_breg31: | |
3f76745e | 4564 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4565 | break; |
4566 | case DW_OP_regx: | |
3f76745e | 4567 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4568 | break; |
4569 | case DW_OP_fbreg: | |
3f76745e | 4570 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4571 | break; |
4572 | case DW_OP_bregx: | |
3f76745e JM |
4573 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
4574 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
a3f97cbb JW |
4575 | break; |
4576 | case DW_OP_piece: | |
3f76745e | 4577 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4578 | break; |
4579 | case DW_OP_deref_size: | |
4580 | case DW_OP_xderef_size: | |
3f76745e | 4581 | size += 1; |
a3f97cbb JW |
4582 | break; |
4583 | default: | |
4584 | break; | |
4585 | } | |
3f76745e JM |
4586 | |
4587 | return size; | |
a3f97cbb JW |
4588 | } |
4589 | ||
3f76745e | 4590 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 4591 | |
a3f97cbb | 4592 | static unsigned long |
3f76745e JM |
4593 | size_of_locs (loc) |
4594 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4595 | { |
3f76745e | 4596 | register unsigned long size = 0; |
71dfc51f | 4597 | |
3f76745e JM |
4598 | for (; loc != NULL; loc = loc->dw_loc_next) |
4599 | size += size_of_loc_descr (loc); | |
4600 | ||
4601 | return size; | |
4602 | } | |
4603 | ||
4604 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
4605 | ||
4606 | static int | |
4607 | constant_size (value) | |
4608 | long unsigned value; | |
4609 | { | |
4610 | int log; | |
4611 | ||
4612 | if (value == 0) | |
4613 | log = 0; | |
a3f97cbb | 4614 | else |
3f76745e | 4615 | log = floor_log2 (value); |
71dfc51f | 4616 | |
3f76745e JM |
4617 | log = log / 8; |
4618 | log = 1 << (floor_log2 (log) + 1); | |
4619 | ||
4620 | return log; | |
a3f97cbb JW |
4621 | } |
4622 | ||
3f76745e JM |
4623 | /* Return the size of a DIE, as it is represented in the |
4624 | .debug_info section. */ | |
71dfc51f | 4625 | |
3f76745e JM |
4626 | static unsigned long |
4627 | size_of_die (die) | |
a3f97cbb JW |
4628 | register dw_die_ref die; |
4629 | { | |
3f76745e | 4630 | register unsigned long size = 0; |
a3f97cbb | 4631 | register dw_attr_ref a; |
71dfc51f | 4632 | |
3f76745e | 4633 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
4634 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
4635 | { | |
4636 | switch (a->dw_attr_val.val_class) | |
4637 | { | |
4638 | case dw_val_class_addr: | |
3f76745e | 4639 | size += PTR_SIZE; |
a3f97cbb JW |
4640 | break; |
4641 | case dw_val_class_loc: | |
3f76745e JM |
4642 | { |
4643 | register unsigned long lsize | |
4644 | = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 4645 | |
3f76745e JM |
4646 | /* Block length. */ |
4647 | size += constant_size (lsize); | |
4648 | size += lsize; | |
4649 | } | |
a3f97cbb JW |
4650 | break; |
4651 | case dw_val_class_const: | |
3f76745e | 4652 | size += 4; |
a3f97cbb JW |
4653 | break; |
4654 | case dw_val_class_unsigned_const: | |
3f76745e | 4655 | size += constant_size (a->dw_attr_val.v.val_unsigned); |
a3f97cbb | 4656 | break; |
469ac993 | 4657 | case dw_val_class_long_long: |
3f76745e | 4658 | size += 1 + 8; /* block */ |
469ac993 JM |
4659 | break; |
4660 | case dw_val_class_float: | |
3f76745e | 4661 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
4662 | break; |
4663 | case dw_val_class_flag: | |
3f76745e | 4664 | size += 1; |
a3f97cbb JW |
4665 | break; |
4666 | case dw_val_class_die_ref: | |
3f76745e | 4667 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4668 | break; |
4669 | case dw_val_class_fde_ref: | |
3f76745e | 4670 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4671 | break; |
4672 | case dw_val_class_lbl_id: | |
3f76745e JM |
4673 | size += PTR_SIZE; |
4674 | break; | |
4675 | case dw_val_class_section_offset: | |
4676 | size += DWARF_OFFSET_SIZE; | |
4677 | break; | |
4678 | case dw_val_class_str: | |
4679 | size += size_of_string (a->dw_attr_val.v.val_str); | |
4680 | break; | |
4681 | default: | |
4682 | abort (); | |
4683 | } | |
a3f97cbb | 4684 | } |
3f76745e JM |
4685 | |
4686 | return size; | |
a3f97cbb JW |
4687 | } |
4688 | ||
956d6950 | 4689 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
4690 | Visits the DIE's children recursively. Updates the global |
4691 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 4692 | current value of next_die_offset to update the die_offset |
3f76745e | 4693 | field in each DIE. */ |
71dfc51f | 4694 | |
a3f97cbb | 4695 | static void |
3f76745e JM |
4696 | calc_die_sizes (die) |
4697 | dw_die_ref die; | |
a3f97cbb | 4698 | { |
3f76745e JM |
4699 | register dw_die_ref c; |
4700 | die->die_offset = next_die_offset; | |
4701 | next_die_offset += size_of_die (die); | |
71dfc51f | 4702 | |
3f76745e JM |
4703 | for (c = die->die_child; c != NULL; c = c->die_sib) |
4704 | calc_die_sizes (c); | |
71dfc51f | 4705 | |
3f76745e JM |
4706 | if (die->die_child != NULL) |
4707 | /* Count the null byte used to terminate sibling lists. */ | |
4708 | next_die_offset += 1; | |
a3f97cbb JW |
4709 | } |
4710 | ||
3f76745e JM |
4711 | /* Return the size of the line information prolog generated for the |
4712 | compilation unit. */ | |
469ac993 | 4713 | |
3f76745e JM |
4714 | static unsigned long |
4715 | size_of_line_prolog () | |
a94dbf2c | 4716 | { |
3f76745e JM |
4717 | register unsigned long size; |
4718 | register unsigned long ft_index; | |
a94dbf2c | 4719 | |
3f76745e | 4720 | size = DWARF_LINE_PROLOG_HEADER_SIZE; |
469ac993 | 4721 | |
3f76745e JM |
4722 | /* Count the size of the table giving number of args for each |
4723 | standard opcode. */ | |
4724 | size += DWARF_LINE_OPCODE_BASE - 1; | |
71dfc51f | 4725 | |
3f76745e | 4726 | /* Include directory table is empty (at present). Count only the |
38e01259 | 4727 | null byte used to terminate the table. */ |
3f76745e | 4728 | size += 1; |
71dfc51f | 4729 | |
3f76745e JM |
4730 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
4731 | { | |
4732 | /* File name entry. */ | |
4733 | size += size_of_string (file_table[ft_index]); | |
a94dbf2c | 4734 | |
3f76745e JM |
4735 | /* Include directory index. */ |
4736 | size += size_of_uleb128 (0); | |
a94dbf2c | 4737 | |
3f76745e JM |
4738 | /* Modification time. */ |
4739 | size += size_of_uleb128 (0); | |
71dfc51f | 4740 | |
3f76745e JM |
4741 | /* File length in bytes. */ |
4742 | size += size_of_uleb128 (0); | |
a94dbf2c | 4743 | } |
71dfc51f | 4744 | |
3f76745e JM |
4745 | /* Count the file table terminator. */ |
4746 | size += 1; | |
4747 | return size; | |
a94dbf2c JM |
4748 | } |
4749 | ||
3f76745e JM |
4750 | /* Return the size of the line information generated for this |
4751 | compilation unit. */ | |
71dfc51f | 4752 | |
3f76745e JM |
4753 | static unsigned long |
4754 | size_of_line_info () | |
a94dbf2c | 4755 | { |
3f76745e JM |
4756 | register unsigned long size; |
4757 | register unsigned long lt_index; | |
4758 | register unsigned long current_line; | |
4759 | register long line_offset; | |
4760 | register long line_delta; | |
4761 | register unsigned long current_file; | |
4762 | register unsigned long function; | |
f19a6894 JW |
4763 | unsigned long size_of_set_address; |
4764 | ||
4765 | /* Size of a DW_LNE_set_address instruction. */ | |
4766 | size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE; | |
a94dbf2c | 4767 | |
3f76745e JM |
4768 | /* Version number. */ |
4769 | size = 2; | |
71dfc51f | 4770 | |
3f76745e JM |
4771 | /* Prolog length specifier. */ |
4772 | size += DWARF_OFFSET_SIZE; | |
71dfc51f | 4773 | |
3f76745e JM |
4774 | /* Prolog. */ |
4775 | size += size_of_line_prolog (); | |
a94dbf2c | 4776 | |
3f76745e | 4777 | /* Set address register instruction. */ |
f19a6894 | 4778 | size += size_of_set_address; |
71dfc51f | 4779 | |
3f76745e JM |
4780 | current_file = 1; |
4781 | current_line = 1; | |
4782 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) | |
a94dbf2c | 4783 | { |
3f76745e JM |
4784 | register dw_line_info_ref line_info; |
4785 | ||
4786 | /* Advance pc instruction. */ | |
f19a6894 JW |
4787 | /* ??? See the DW_LNS_advance_pc comment in output_line_info. */ |
4788 | if (0) | |
4789 | size += 1 + 2; | |
4790 | else | |
4791 | size += size_of_set_address; | |
4792 | ||
3f76745e JM |
4793 | line_info = &line_info_table[lt_index]; |
4794 | if (line_info->dw_file_num != current_file) | |
4795 | { | |
4796 | /* Set file number instruction. */ | |
4797 | size += 1; | |
4798 | current_file = line_info->dw_file_num; | |
4799 | size += size_of_uleb128 (current_file); | |
4800 | } | |
4801 | ||
4802 | if (line_info->dw_line_num != current_line) | |
4803 | { | |
4804 | line_offset = line_info->dw_line_num - current_line; | |
4805 | line_delta = line_offset - DWARF_LINE_BASE; | |
4806 | current_line = line_info->dw_line_num; | |
4807 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4808 | /* 1-byte special line number instruction. */ | |
4809 | size += 1; | |
4810 | else | |
4811 | { | |
4812 | /* Advance line instruction. */ | |
4813 | size += 1; | |
4814 | size += size_of_sleb128 (line_offset); | |
4815 | /* Generate line entry instruction. */ | |
4816 | size += 1; | |
4817 | } | |
4818 | } | |
a94dbf2c | 4819 | } |
a94dbf2c | 4820 | |
3f76745e | 4821 | /* Advance pc instruction. */ |
f19a6894 JW |
4822 | if (0) |
4823 | size += 1 + 2; | |
4824 | else | |
4825 | size += size_of_set_address; | |
a94dbf2c | 4826 | |
3f76745e JM |
4827 | /* End of line number info. marker. */ |
4828 | size += 1 + size_of_uleb128 (1) + 1; | |
a94dbf2c | 4829 | |
3f76745e JM |
4830 | function = 0; |
4831 | current_file = 1; | |
4832 | current_line = 1; | |
4833 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
4834 | { | |
4835 | register dw_separate_line_info_ref line_info | |
4836 | = &separate_line_info_table[lt_index]; | |
4837 | if (function != line_info->function) | |
4838 | { | |
4839 | function = line_info->function; | |
4840 | /* Set address register instruction. */ | |
f19a6894 | 4841 | size += size_of_set_address; |
3f76745e JM |
4842 | } |
4843 | else | |
f19a6894 JW |
4844 | { |
4845 | /* Advance pc instruction. */ | |
4846 | if (0) | |
4847 | size += 1 + 2; | |
4848 | else | |
4849 | size += size_of_set_address; | |
4850 | } | |
3f76745e JM |
4851 | |
4852 | if (line_info->dw_file_num != current_file) | |
4853 | { | |
4854 | /* Set file number instruction. */ | |
4855 | size += 1; | |
4856 | current_file = line_info->dw_file_num; | |
4857 | size += size_of_uleb128 (current_file); | |
4858 | } | |
4859 | ||
4860 | if (line_info->dw_line_num != current_line) | |
4861 | { | |
4862 | line_offset = line_info->dw_line_num - current_line; | |
4863 | line_delta = line_offset - DWARF_LINE_BASE; | |
4864 | current_line = line_info->dw_line_num; | |
4865 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4866 | /* 1-byte special line number instruction. */ | |
4867 | size += 1; | |
4868 | else | |
4869 | { | |
4870 | /* Advance line instruction. */ | |
4871 | size += 1; | |
4872 | size += size_of_sleb128 (line_offset); | |
a94dbf2c | 4873 | |
3f76745e JM |
4874 | /* Generate line entry instruction. */ |
4875 | size += 1; | |
4876 | } | |
4877 | } | |
a94dbf2c | 4878 | |
3f76745e | 4879 | ++lt_index; |
a94dbf2c | 4880 | |
3f76745e JM |
4881 | /* If we're done with a function, end its sequence. */ |
4882 | if (lt_index == separate_line_info_table_in_use | |
4883 | || separate_line_info_table[lt_index].function != function) | |
4884 | { | |
4885 | current_file = 1; | |
4886 | current_line = 1; | |
71dfc51f | 4887 | |
3f76745e | 4888 | /* Advance pc instruction. */ |
f19a6894 JW |
4889 | if (0) |
4890 | size += 1 + 2; | |
4891 | else | |
4892 | size += size_of_set_address; | |
71dfc51f | 4893 | |
3f76745e JM |
4894 | /* End of line number info. marker. */ |
4895 | size += 1 + size_of_uleb128 (1) + 1; | |
4896 | } | |
a94dbf2c JM |
4897 | } |
4898 | ||
3f76745e | 4899 | return size; |
a94dbf2c JM |
4900 | } |
4901 | ||
3f76745e JM |
4902 | /* Return the size of the .debug_pubnames table generated for the |
4903 | compilation unit. */ | |
a94dbf2c | 4904 | |
3f76745e JM |
4905 | static unsigned long |
4906 | size_of_pubnames () | |
a94dbf2c | 4907 | { |
3f76745e JM |
4908 | register unsigned long size; |
4909 | register unsigned i; | |
469ac993 | 4910 | |
3f76745e JM |
4911 | size = DWARF_PUBNAMES_HEADER_SIZE; |
4912 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 4913 | { |
3f76745e JM |
4914 | register pubname_ref p = &pubname_table[i]; |
4915 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
4916 | } |
4917 | ||
3f76745e JM |
4918 | size += DWARF_OFFSET_SIZE; |
4919 | return size; | |
a94dbf2c JM |
4920 | } |
4921 | ||
956d6950 | 4922 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 4923 | |
3f76745e JM |
4924 | static unsigned long |
4925 | size_of_aranges () | |
469ac993 | 4926 | { |
3f76745e | 4927 | register unsigned long size; |
469ac993 | 4928 | |
3f76745e | 4929 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 4930 | |
3f76745e JM |
4931 | /* Count the address/length pair for this compilation unit. */ |
4932 | size += 2 * PTR_SIZE; | |
4933 | size += 2 * PTR_SIZE * arange_table_in_use; | |
469ac993 | 4934 | |
3f76745e JM |
4935 | /* Count the two zero words used to terminated the address range table. */ |
4936 | size += 2 * PTR_SIZE; | |
4937 | return size; | |
4938 | } | |
4939 | \f | |
4940 | /* Select the encoding of an attribute value. */ | |
4941 | ||
4942 | static enum dwarf_form | |
4943 | value_format (v) | |
4944 | dw_val_ref v; | |
4945 | { | |
4946 | switch (v->val_class) | |
469ac993 | 4947 | { |
3f76745e JM |
4948 | case dw_val_class_addr: |
4949 | return DW_FORM_addr; | |
4950 | case dw_val_class_loc: | |
4951 | switch (constant_size (size_of_locs (v->v.val_loc))) | |
469ac993 | 4952 | { |
3f76745e JM |
4953 | case 1: |
4954 | return DW_FORM_block1; | |
4955 | case 2: | |
4956 | return DW_FORM_block2; | |
469ac993 JM |
4957 | default: |
4958 | abort (); | |
4959 | } | |
3f76745e JM |
4960 | case dw_val_class_const: |
4961 | return DW_FORM_data4; | |
4962 | case dw_val_class_unsigned_const: | |
4963 | switch (constant_size (v->v.val_unsigned)) | |
4964 | { | |
4965 | case 1: | |
4966 | return DW_FORM_data1; | |
4967 | case 2: | |
4968 | return DW_FORM_data2; | |
4969 | case 4: | |
4970 | return DW_FORM_data4; | |
4971 | case 8: | |
4972 | return DW_FORM_data8; | |
4973 | default: | |
4974 | abort (); | |
4975 | } | |
4976 | case dw_val_class_long_long: | |
4977 | return DW_FORM_block1; | |
4978 | case dw_val_class_float: | |
4979 | return DW_FORM_block1; | |
4980 | case dw_val_class_flag: | |
4981 | return DW_FORM_flag; | |
4982 | case dw_val_class_die_ref: | |
4983 | return DW_FORM_ref; | |
4984 | case dw_val_class_fde_ref: | |
4985 | return DW_FORM_data; | |
4986 | case dw_val_class_lbl_id: | |
4987 | return DW_FORM_addr; | |
4988 | case dw_val_class_section_offset: | |
4989 | return DW_FORM_data; | |
4990 | case dw_val_class_str: | |
4991 | return DW_FORM_string; | |
469ac993 JM |
4992 | default: |
4993 | abort (); | |
4994 | } | |
a94dbf2c JM |
4995 | } |
4996 | ||
3f76745e | 4997 | /* Output the encoding of an attribute value. */ |
469ac993 | 4998 | |
3f76745e JM |
4999 | static void |
5000 | output_value_format (v) | |
5001 | dw_val_ref v; | |
a94dbf2c | 5002 | { |
3f76745e | 5003 | enum dwarf_form form = value_format (v); |
71dfc51f | 5004 | |
3f76745e | 5005 | output_uleb128 (form); |
c5cec899 | 5006 | if (flag_debug_asm) |
3f76745e | 5007 | fprintf (asm_out_file, " (%s)", dwarf_form_name (form)); |
141719a8 | 5008 | |
3f76745e JM |
5009 | fputc ('\n', asm_out_file); |
5010 | } | |
469ac993 | 5011 | |
3f76745e JM |
5012 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5013 | table. */ | |
469ac993 | 5014 | |
3f76745e JM |
5015 | static void |
5016 | output_abbrev_section () | |
5017 | { | |
5018 | unsigned long abbrev_id; | |
71dfc51f | 5019 | |
3f76745e JM |
5020 | dw_attr_ref a_attr; |
5021 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5022 | { | |
5023 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 5024 | |
3f76745e | 5025 | output_uleb128 (abbrev_id); |
c5cec899 | 5026 | if (flag_debug_asm) |
3f76745e | 5027 | fprintf (asm_out_file, " (abbrev code)"); |
469ac993 | 5028 | |
3f76745e JM |
5029 | fputc ('\n', asm_out_file); |
5030 | output_uleb128 (abbrev->die_tag); | |
c5cec899 | 5031 | if (flag_debug_asm) |
3f76745e JM |
5032 | fprintf (asm_out_file, " (TAG: %s)", |
5033 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 5034 | |
3f76745e JM |
5035 | fputc ('\n', asm_out_file); |
5036 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, | |
5037 | abbrev->die_child != NULL ? DW_children_yes : DW_children_no); | |
469ac993 | 5038 | |
c5cec899 | 5039 | if (flag_debug_asm) |
3f76745e JM |
5040 | fprintf (asm_out_file, "\t%s %s", |
5041 | ASM_COMMENT_START, | |
5042 | (abbrev->die_child != NULL | |
5043 | ? "DW_children_yes" : "DW_children_no")); | |
5044 | ||
5045 | fputc ('\n', asm_out_file); | |
5046 | ||
5047 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
5048 | a_attr = a_attr->dw_attr_next) | |
5049 | { | |
5050 | output_uleb128 (a_attr->dw_attr); | |
c5cec899 | 5051 | if (flag_debug_asm) |
3f76745e JM |
5052 | fprintf (asm_out_file, " (%s)", |
5053 | dwarf_attr_name (a_attr->dw_attr)); | |
5054 | ||
5055 | fputc ('\n', asm_out_file); | |
5056 | output_value_format (&a_attr->dw_attr_val); | |
469ac993 | 5057 | } |
469ac993 | 5058 | |
3f76745e | 5059 | fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); |
469ac993 | 5060 | } |
a94dbf2c JM |
5061 | } |
5062 | ||
3f76745e | 5063 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 5064 | |
3f76745e JM |
5065 | static void |
5066 | output_loc_operands (loc) | |
5067 | register dw_loc_descr_ref loc; | |
a3f97cbb | 5068 | { |
3f76745e JM |
5069 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
5070 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
71dfc51f | 5071 | |
3f76745e | 5072 | switch (loc->dw_loc_opc) |
a3f97cbb | 5073 | { |
3f76745e JM |
5074 | case DW_OP_addr: |
5075 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); | |
5076 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5077 | break; |
3f76745e JM |
5078 | case DW_OP_const1u: |
5079 | case DW_OP_const1s: | |
5080 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
5081 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5082 | break; |
3f76745e JM |
5083 | case DW_OP_const2u: |
5084 | case DW_OP_const2s: | |
5085 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
5086 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5087 | break; |
3f76745e JM |
5088 | case DW_OP_const4u: |
5089 | case DW_OP_const4s: | |
5090 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); | |
5091 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5092 | break; |
3f76745e JM |
5093 | case DW_OP_const8u: |
5094 | case DW_OP_const8s: | |
5095 | abort (); | |
5096 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5097 | break; |
3f76745e JM |
5098 | case DW_OP_constu: |
5099 | output_uleb128 (val1->v.val_unsigned); | |
5100 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5101 | break; |
3f76745e JM |
5102 | case DW_OP_consts: |
5103 | output_sleb128 (val1->v.val_int); | |
5104 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5105 | break; |
3f76745e JM |
5106 | case DW_OP_pick: |
5107 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
5108 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5109 | break; |
3f76745e JM |
5110 | case DW_OP_plus_uconst: |
5111 | output_uleb128 (val1->v.val_unsigned); | |
5112 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5113 | break; |
3f76745e JM |
5114 | case DW_OP_skip: |
5115 | case DW_OP_bra: | |
5116 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
5117 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5118 | break; |
3f76745e JM |
5119 | case DW_OP_breg0: |
5120 | case DW_OP_breg1: | |
5121 | case DW_OP_breg2: | |
5122 | case DW_OP_breg3: | |
5123 | case DW_OP_breg4: | |
5124 | case DW_OP_breg5: | |
5125 | case DW_OP_breg6: | |
5126 | case DW_OP_breg7: | |
5127 | case DW_OP_breg8: | |
5128 | case DW_OP_breg9: | |
5129 | case DW_OP_breg10: | |
5130 | case DW_OP_breg11: | |
5131 | case DW_OP_breg12: | |
5132 | case DW_OP_breg13: | |
5133 | case DW_OP_breg14: | |
5134 | case DW_OP_breg15: | |
5135 | case DW_OP_breg16: | |
5136 | case DW_OP_breg17: | |
5137 | case DW_OP_breg18: | |
5138 | case DW_OP_breg19: | |
5139 | case DW_OP_breg20: | |
5140 | case DW_OP_breg21: | |
5141 | case DW_OP_breg22: | |
5142 | case DW_OP_breg23: | |
5143 | case DW_OP_breg24: | |
5144 | case DW_OP_breg25: | |
5145 | case DW_OP_breg26: | |
5146 | case DW_OP_breg27: | |
5147 | case DW_OP_breg28: | |
5148 | case DW_OP_breg29: | |
5149 | case DW_OP_breg30: | |
5150 | case DW_OP_breg31: | |
5151 | output_sleb128 (val1->v.val_int); | |
5152 | fputc ('\n', asm_out_file); | |
5153 | break; | |
5154 | case DW_OP_regx: | |
5155 | output_uleb128 (val1->v.val_unsigned); | |
5156 | fputc ('\n', asm_out_file); | |
5157 | break; | |
5158 | case DW_OP_fbreg: | |
5159 | output_sleb128 (val1->v.val_int); | |
5160 | fputc ('\n', asm_out_file); | |
5161 | break; | |
5162 | case DW_OP_bregx: | |
5163 | output_uleb128 (val1->v.val_unsigned); | |
5164 | fputc ('\n', asm_out_file); | |
5165 | output_sleb128 (val2->v.val_int); | |
5166 | fputc ('\n', asm_out_file); | |
5167 | break; | |
5168 | case DW_OP_piece: | |
5169 | output_uleb128 (val1->v.val_unsigned); | |
5170 | fputc ('\n', asm_out_file); | |
5171 | break; | |
5172 | case DW_OP_deref_size: | |
5173 | case DW_OP_xderef_size: | |
5174 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
5175 | fputc ('\n', asm_out_file); | |
a3f97cbb JW |
5176 | break; |
5177 | default: | |
5178 | break; | |
5179 | } | |
a3f97cbb JW |
5180 | } |
5181 | ||
3f76745e | 5182 | /* Compute the offset of a sibling. */ |
71dfc51f | 5183 | |
3f76745e JM |
5184 | static unsigned long |
5185 | sibling_offset (die) | |
5186 | dw_die_ref die; | |
a3f97cbb | 5187 | { |
3f76745e | 5188 | unsigned long offset; |
71dfc51f | 5189 | |
3f76745e JM |
5190 | if (die->die_child_last == NULL) |
5191 | offset = die->die_offset + size_of_die (die); | |
5192 | else | |
5193 | offset = sibling_offset (die->die_child_last) + 1; | |
71dfc51f | 5194 | |
3f76745e | 5195 | return offset; |
a3f97cbb JW |
5196 | } |
5197 | ||
3f76745e JM |
5198 | /* Output the DIE and its attributes. Called recursively to generate |
5199 | the definitions of each child DIE. */ | |
71dfc51f | 5200 | |
a3f97cbb | 5201 | static void |
3f76745e JM |
5202 | output_die (die) |
5203 | register dw_die_ref die; | |
a3f97cbb | 5204 | { |
3f76745e JM |
5205 | register dw_attr_ref a; |
5206 | register dw_die_ref c; | |
5207 | register unsigned long ref_offset; | |
5208 | register unsigned long size; | |
5209 | register dw_loc_descr_ref loc; | |
a94dbf2c | 5210 | |
3f76745e | 5211 | output_uleb128 (die->die_abbrev); |
c5cec899 | 5212 | if (flag_debug_asm) |
2d8b0f3a | 5213 | fprintf (asm_out_file, " (DIE (0x%lx) %s)", |
3f76745e | 5214 | die->die_offset, dwarf_tag_name (die->die_tag)); |
a94dbf2c | 5215 | |
3f76745e | 5216 | fputc ('\n', asm_out_file); |
a94dbf2c | 5217 | |
3f76745e | 5218 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 5219 | { |
3f76745e JM |
5220 | switch (a->dw_attr_val.val_class) |
5221 | { | |
5222 | case dw_val_class_addr: | |
5223 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, | |
5224 | a->dw_attr_val.v.val_addr); | |
5225 | break; | |
a3f97cbb | 5226 | |
3f76745e JM |
5227 | case dw_val_class_loc: |
5228 | size = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 5229 | |
3f76745e JM |
5230 | /* Output the block length for this list of location operations. */ |
5231 | switch (constant_size (size)) | |
5232 | { | |
5233 | case 1: | |
5234 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size); | |
5235 | break; | |
5236 | case 2: | |
5237 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
5238 | break; | |
5239 | default: | |
5240 | abort (); | |
5241 | } | |
71dfc51f | 5242 | |
c5cec899 | 5243 | if (flag_debug_asm) |
3f76745e JM |
5244 | fprintf (asm_out_file, "\t%s %s", |
5245 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
71dfc51f | 5246 | |
3f76745e JM |
5247 | fputc ('\n', asm_out_file); |
5248 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
5249 | loc = loc->dw_loc_next) | |
5250 | { | |
5251 | /* Output the opcode. */ | |
5252 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
c5cec899 | 5253 | if (flag_debug_asm) |
3f76745e JM |
5254 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
5255 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
71dfc51f | 5256 | |
3f76745e | 5257 | fputc ('\n', asm_out_file); |
71dfc51f | 5258 | |
3f76745e JM |
5259 | /* Output the operand(s) (if any). */ |
5260 | output_loc_operands (loc); | |
5261 | } | |
a3f97cbb | 5262 | break; |
3f76745e JM |
5263 | |
5264 | case dw_val_class_const: | |
5265 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int); | |
a3f97cbb | 5266 | break; |
3f76745e JM |
5267 | |
5268 | case dw_val_class_unsigned_const: | |
5269 | switch (constant_size (a->dw_attr_val.v.val_unsigned)) | |
5270 | { | |
5271 | case 1: | |
5272 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5273 | a->dw_attr_val.v.val_unsigned); | |
5274 | break; | |
5275 | case 2: | |
5276 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, | |
5277 | a->dw_attr_val.v.val_unsigned); | |
5278 | break; | |
5279 | case 4: | |
5280 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5281 | a->dw_attr_val.v.val_unsigned); | |
5282 | break; | |
5283 | case 8: | |
5284 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5285 | a->dw_attr_val.v.val_long_long.hi, | |
5286 | a->dw_attr_val.v.val_long_long.low); | |
5287 | break; | |
5288 | default: | |
5289 | abort (); | |
5290 | } | |
a3f97cbb | 5291 | break; |
3f76745e JM |
5292 | |
5293 | case dw_val_class_long_long: | |
5294 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8); | |
c5cec899 | 5295 | if (flag_debug_asm) |
3f76745e JM |
5296 | fprintf (asm_out_file, "\t%s %s", |
5297 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5298 | ||
5299 | fputc ('\n', asm_out_file); | |
5300 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5301 | a->dw_attr_val.v.val_long_long.hi, | |
5302 | a->dw_attr_val.v.val_long_long.low); | |
5303 | ||
c5cec899 | 5304 | if (flag_debug_asm) |
3f76745e JM |
5305 | fprintf (asm_out_file, |
5306 | "\t%s long long constant", ASM_COMMENT_START); | |
5307 | ||
5308 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5309 | break; |
3f76745e JM |
5310 | |
5311 | case dw_val_class_float: | |
c84e2712 KG |
5312 | { |
5313 | register unsigned int i; | |
5314 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5315 | a->dw_attr_val.v.val_float.length * 4); | |
5316 | if (flag_debug_asm) | |
5317 | fprintf (asm_out_file, "\t%s %s", | |
5318 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5319 | ||
5320 | fputc ('\n', asm_out_file); | |
5321 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) | |
5322 | { | |
5323 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5324 | a->dw_attr_val.v.val_float.array[i]); | |
5325 | if (flag_debug_asm) | |
5326 | fprintf (asm_out_file, "\t%s fp constant word %u", | |
5327 | ASM_COMMENT_START, i); | |
5328 | ||
5329 | fputc ('\n', asm_out_file); | |
5330 | } | |
a3f97cbb | 5331 | break; |
c84e2712 | 5332 | } |
3f76745e JM |
5333 | |
5334 | case dw_val_class_flag: | |
5335 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag); | |
a3f97cbb | 5336 | break; |
3f76745e JM |
5337 | |
5338 | case dw_val_class_die_ref: | |
5339 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
5340 | ref_offset = a->dw_attr_val.v.val_die_ref->die_offset; | |
5341 | else if (a->dw_attr == DW_AT_sibling) | |
5342 | ref_offset = sibling_offset(die); | |
5343 | else | |
5344 | abort (); | |
5345 | ||
5346 | ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset); | |
a3f97cbb | 5347 | break; |
3f76745e JM |
5348 | |
5349 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
5350 | { |
5351 | char l1[20]; | |
5352 | ASM_GENERATE_INTERNAL_LABEL | |
5353 | (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2); | |
5354 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1); | |
5355 | fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE); | |
5356 | } | |
a3f97cbb | 5357 | break; |
a3f97cbb | 5358 | |
3f76745e JM |
5359 | case dw_val_class_lbl_id: |
5360 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id); | |
5361 | break; | |
71dfc51f | 5362 | |
3f76745e JM |
5363 | case dw_val_class_section_offset: |
5364 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, | |
1553e85a JL |
5365 | stripattributes |
5366 | (a->dw_attr_val.v.val_section)); | |
3f76745e | 5367 | break; |
a3f97cbb | 5368 | |
3f76745e | 5369 | case dw_val_class_str: |
8d4e65a6 JL |
5370 | if (flag_debug_asm) |
5371 | ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str); | |
5372 | else | |
5373 | ASM_OUTPUT_ASCII (asm_out_file, | |
5374 | a->dw_attr_val.v.val_str, | |
c84e2712 | 5375 | (int) strlen (a->dw_attr_val.v.val_str) + 1); |
3f76745e | 5376 | break; |
b2932ae5 | 5377 | |
3f76745e JM |
5378 | default: |
5379 | abort (); | |
5380 | } | |
a94dbf2c | 5381 | |
3f76745e JM |
5382 | if (a->dw_attr_val.val_class != dw_val_class_loc |
5383 | && a->dw_attr_val.val_class != dw_val_class_long_long | |
5384 | && a->dw_attr_val.val_class != dw_val_class_float) | |
5385 | { | |
c5cec899 | 5386 | if (flag_debug_asm) |
3f76745e JM |
5387 | fprintf (asm_out_file, "\t%s %s", |
5388 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
b2932ae5 | 5389 | |
3f76745e JM |
5390 | fputc ('\n', asm_out_file); |
5391 | } | |
5392 | } | |
71dfc51f | 5393 | |
3f76745e JM |
5394 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5395 | output_die (c); | |
71dfc51f | 5396 | |
3f76745e | 5397 | if (die->die_child != NULL) |
7e23cb16 | 5398 | { |
3f76745e JM |
5399 | /* Add null byte to terminate sibling list. */ |
5400 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5401 | if (flag_debug_asm) |
2d8b0f3a | 5402 | fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx", |
3f76745e JM |
5403 | ASM_COMMENT_START, die->die_offset); |
5404 | ||
7e23cb16 JM |
5405 | fputc ('\n', asm_out_file); |
5406 | } | |
3f76745e | 5407 | } |
71dfc51f | 5408 | |
3f76745e JM |
5409 | /* Output the compilation unit that appears at the beginning of the |
5410 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 5411 | |
3f76745e JM |
5412 | static void |
5413 | output_compilation_unit_header () | |
5414 | { | |
5415 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE); | |
c5cec899 | 5416 | if (flag_debug_asm) |
3f76745e JM |
5417 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", |
5418 | ASM_COMMENT_START); | |
71dfc51f | 5419 | |
a3f97cbb | 5420 | fputc ('\n', asm_out_file); |
3f76745e | 5421 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
c5cec899 | 5422 | if (flag_debug_asm) |
3f76745e | 5423 | fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START); |
71dfc51f | 5424 | |
a3f97cbb | 5425 | fputc ('\n', asm_out_file); |
1553e85a | 5426 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION)); |
c5cec899 | 5427 | if (flag_debug_asm) |
3f76745e JM |
5428 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", |
5429 | ASM_COMMENT_START); | |
71dfc51f | 5430 | |
a3f97cbb | 5431 | fputc ('\n', asm_out_file); |
3f76745e | 5432 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); |
c5cec899 | 5433 | if (flag_debug_asm) |
3f76745e | 5434 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START); |
71dfc51f | 5435 | |
a3f97cbb | 5436 | fputc ('\n', asm_out_file); |
a3f97cbb JW |
5437 | } |
5438 | ||
a1d7ffe3 JM |
5439 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
5440 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
5441 | argument list, and maybe the scope. */ | |
5442 | ||
71dfc51f | 5443 | static char * |
a1d7ffe3 JM |
5444 | dwarf2_name (decl, scope) |
5445 | tree decl; | |
5446 | int scope; | |
5447 | { | |
5448 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
5449 | } | |
5450 | ||
d291dd49 | 5451 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 5452 | |
d291dd49 JM |
5453 | static void |
5454 | add_pubname (decl, die) | |
5455 | tree decl; | |
5456 | dw_die_ref die; | |
5457 | { | |
5458 | pubname_ref p; | |
5459 | ||
5460 | if (! TREE_PUBLIC (decl)) | |
5461 | return; | |
5462 | ||
5463 | if (pubname_table_in_use == pubname_table_allocated) | |
5464 | { | |
5465 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
5466 | pubname_table = (pubname_ref) xrealloc | |
5467 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
5468 | } | |
71dfc51f | 5469 | |
d291dd49 JM |
5470 | p = &pubname_table[pubname_table_in_use++]; |
5471 | p->die = die; | |
a1d7ffe3 JM |
5472 | |
5473 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
5474 | } |
5475 | ||
a3f97cbb JW |
5476 | /* Output the public names table used to speed up access to externally |
5477 | visible names. For now, only generate entries for externally | |
5478 | visible procedures. */ | |
71dfc51f | 5479 | |
a3f97cbb JW |
5480 | static void |
5481 | output_pubnames () | |
5482 | { | |
d291dd49 | 5483 | register unsigned i; |
71dfc51f RK |
5484 | register unsigned long pubnames_length = size_of_pubnames (); |
5485 | ||
5486 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length); | |
5487 | ||
c5cec899 | 5488 | if (flag_debug_asm) |
71dfc51f RK |
5489 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", |
5490 | ASM_COMMENT_START); | |
5491 | ||
a3f97cbb JW |
5492 | fputc ('\n', asm_out_file); |
5493 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
71dfc51f | 5494 | |
c5cec899 | 5495 | if (flag_debug_asm) |
71dfc51f RK |
5496 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5497 | ||
a3f97cbb | 5498 | fputc ('\n', asm_out_file); |
1553e85a | 5499 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
c5cec899 | 5500 | if (flag_debug_asm) |
71dfc51f RK |
5501 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5502 | ASM_COMMENT_START); | |
5503 | ||
a3f97cbb | 5504 | fputc ('\n', asm_out_file); |
7e23cb16 | 5505 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset); |
c5cec899 | 5506 | if (flag_debug_asm) |
71dfc51f RK |
5507 | fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START); |
5508 | ||
a3f97cbb | 5509 | fputc ('\n', asm_out_file); |
d291dd49 | 5510 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 5511 | { |
d291dd49 | 5512 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 5513 | |
7e23cb16 | 5514 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset); |
c5cec899 | 5515 | if (flag_debug_asm) |
71dfc51f RK |
5516 | fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START); |
5517 | ||
d291dd49 JM |
5518 | fputc ('\n', asm_out_file); |
5519 | ||
c5cec899 | 5520 | if (flag_debug_asm) |
8d4e65a6 JL |
5521 | { |
5522 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
5523 | fprintf (asm_out_file, "%s external name", ASM_COMMENT_START); | |
5524 | } | |
5525 | else | |
5526 | { | |
c84e2712 KG |
5527 | ASM_OUTPUT_ASCII (asm_out_file, pub->name, |
5528 | (int) strlen (pub->name) + 1); | |
8d4e65a6 | 5529 | } |
71dfc51f | 5530 | |
d291dd49 | 5531 | fputc ('\n', asm_out_file); |
a3f97cbb | 5532 | } |
71dfc51f | 5533 | |
7e23cb16 | 5534 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); |
a3f97cbb JW |
5535 | fputc ('\n', asm_out_file); |
5536 | } | |
5537 | ||
d291dd49 | 5538 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 5539 | |
d291dd49 JM |
5540 | static void |
5541 | add_arange (decl, die) | |
5542 | tree decl; | |
5543 | dw_die_ref die; | |
5544 | { | |
5545 | if (! DECL_SECTION_NAME (decl)) | |
5546 | return; | |
5547 | ||
5548 | if (arange_table_in_use == arange_table_allocated) | |
5549 | { | |
5550 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
5551 | arange_table |
5552 | = (arange_ref) xrealloc (arange_table, | |
5553 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 5554 | } |
71dfc51f | 5555 | |
d291dd49 JM |
5556 | arange_table[arange_table_in_use++] = die; |
5557 | } | |
5558 | ||
a3f97cbb JW |
5559 | /* Output the information that goes into the .debug_aranges table. |
5560 | Namely, define the beginning and ending address range of the | |
5561 | text section generated for this compilation unit. */ | |
71dfc51f | 5562 | |
a3f97cbb JW |
5563 | static void |
5564 | output_aranges () | |
5565 | { | |
d291dd49 | 5566 | register unsigned i; |
71dfc51f RK |
5567 | register unsigned long aranges_length = size_of_aranges (); |
5568 | ||
5569 | ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length); | |
c5cec899 | 5570 | if (flag_debug_asm) |
71dfc51f RK |
5571 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", |
5572 | ASM_COMMENT_START); | |
5573 | ||
a3f97cbb JW |
5574 | fputc ('\n', asm_out_file); |
5575 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 5576 | if (flag_debug_asm) |
71dfc51f RK |
5577 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5578 | ||
a3f97cbb | 5579 | fputc ('\n', asm_out_file); |
1553e85a | 5580 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
c5cec899 | 5581 | if (flag_debug_asm) |
71dfc51f RK |
5582 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5583 | ASM_COMMENT_START); | |
5584 | ||
a3f97cbb JW |
5585 | fputc ('\n', asm_out_file); |
5586 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); | |
c5cec899 | 5587 | if (flag_debug_asm) |
71dfc51f RK |
5588 | fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START); |
5589 | ||
a3f97cbb JW |
5590 | fputc ('\n', asm_out_file); |
5591 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5592 | if (flag_debug_asm) |
71dfc51f RK |
5593 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", |
5594 | ASM_COMMENT_START); | |
5595 | ||
a3f97cbb JW |
5596 | fputc ('\n', asm_out_file); |
5597 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
7e23cb16 JM |
5598 | if (PTR_SIZE == 8) |
5599 | fprintf (asm_out_file, ",0,0"); | |
71dfc51f | 5600 | |
c5cec899 | 5601 | if (flag_debug_asm) |
71dfc51f RK |
5602 | fprintf (asm_out_file, "\t%s Pad to %d byte boundary", |
5603 | ASM_COMMENT_START, 2 * PTR_SIZE); | |
5604 | ||
a3f97cbb | 5605 | fputc ('\n', asm_out_file); |
49bcd085 | 5606 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (TEXT_SECTION)); |
c5cec899 | 5607 | if (flag_debug_asm) |
71dfc51f RK |
5608 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5609 | ||
a3f97cbb | 5610 | fputc ('\n', asm_out_file); |
71208e03 JW |
5611 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, |
5612 | stripattributes (TEXT_SECTION)); | |
c5cec899 | 5613 | if (flag_debug_asm) |
71dfc51f RK |
5614 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5615 | ||
a3f97cbb | 5616 | fputc ('\n', asm_out_file); |
d291dd49 JM |
5617 | for (i = 0; i < arange_table_in_use; ++i) |
5618 | { | |
5619 | dw_die_ref a = arange_table[i]; | |
71dfc51f | 5620 | |
d291dd49 JM |
5621 | if (a->die_tag == DW_TAG_subprogram) |
5622 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a)); | |
5623 | else | |
a1d7ffe3 JM |
5624 | { |
5625 | char *name = get_AT_string (a, DW_AT_MIPS_linkage_name); | |
5626 | if (! name) | |
5627 | name = get_AT_string (a, DW_AT_name); | |
71dfc51f | 5628 | |
a1d7ffe3 JM |
5629 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, name); |
5630 | } | |
71dfc51f | 5631 | |
c5cec899 | 5632 | if (flag_debug_asm) |
71dfc51f RK |
5633 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5634 | ||
d291dd49 JM |
5635 | fputc ('\n', asm_out_file); |
5636 | if (a->die_tag == DW_TAG_subprogram) | |
7e23cb16 JM |
5637 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a), |
5638 | get_AT_low_pc (a)); | |
d291dd49 | 5639 | else |
7e23cb16 JM |
5640 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, |
5641 | get_AT_unsigned (a, DW_AT_byte_size)); | |
71dfc51f | 5642 | |
c5cec899 | 5643 | if (flag_debug_asm) |
71dfc51f RK |
5644 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5645 | ||
d291dd49 JM |
5646 | fputc ('\n', asm_out_file); |
5647 | } | |
71dfc51f | 5648 | |
a3f97cbb | 5649 | /* Output the terminator words. */ |
7e23cb16 | 5650 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb | 5651 | fputc ('\n', asm_out_file); |
7e23cb16 | 5652 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb JW |
5653 | fputc ('\n', asm_out_file); |
5654 | } | |
5655 | ||
5656 | /* Output the source line number correspondence information. This | |
f19a6894 JW |
5657 | information goes into the .debug_line section. |
5658 | ||
5659 | If the format of this data changes, then the function size_of_line_info | |
5660 | must also be adjusted the same way. */ | |
71dfc51f | 5661 | |
a3f97cbb JW |
5662 | static void |
5663 | output_line_info () | |
5664 | { | |
a3f97cbb JW |
5665 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
5666 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5667 | register unsigned opc; | |
5668 | register unsigned n_op_args; | |
a3f97cbb JW |
5669 | register unsigned long ft_index; |
5670 | register unsigned long lt_index; | |
5671 | register unsigned long current_line; | |
5672 | register long line_offset; | |
5673 | register long line_delta; | |
5674 | register unsigned long current_file; | |
e90b62db | 5675 | register unsigned long function; |
71dfc51f | 5676 | |
7e23cb16 | 5677 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); |
c5cec899 | 5678 | if (flag_debug_asm) |
71dfc51f RK |
5679 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", |
5680 | ASM_COMMENT_START); | |
5681 | ||
a3f97cbb JW |
5682 | fputc ('\n', asm_out_file); |
5683 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 5684 | if (flag_debug_asm) |
71dfc51f RK |
5685 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5686 | ||
a3f97cbb | 5687 | fputc ('\n', asm_out_file); |
7e23cb16 | 5688 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); |
c5cec899 | 5689 | if (flag_debug_asm) |
71dfc51f RK |
5690 | fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); |
5691 | ||
a3f97cbb JW |
5692 | fputc ('\n', asm_out_file); |
5693 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
c5cec899 | 5694 | if (flag_debug_asm) |
71dfc51f RK |
5695 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", |
5696 | ASM_COMMENT_START); | |
5697 | ||
a3f97cbb JW |
5698 | fputc ('\n', asm_out_file); |
5699 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
c5cec899 | 5700 | if (flag_debug_asm) |
71dfc51f RK |
5701 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", |
5702 | ASM_COMMENT_START); | |
5703 | ||
a3f97cbb JW |
5704 | fputc ('\n', asm_out_file); |
5705 | fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE); | |
c5cec899 | 5706 | if (flag_debug_asm) |
71dfc51f RK |
5707 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", |
5708 | ASM_COMMENT_START); | |
5709 | ||
a3f97cbb JW |
5710 | fputc ('\n', asm_out_file); |
5711 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE); | |
c5cec899 | 5712 | if (flag_debug_asm) |
71dfc51f RK |
5713 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", |
5714 | ASM_COMMENT_START); | |
5715 | ||
a3f97cbb JW |
5716 | fputc ('\n', asm_out_file); |
5717 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); | |
c5cec899 | 5718 | if (flag_debug_asm) |
71dfc51f RK |
5719 | fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START); |
5720 | ||
a3f97cbb JW |
5721 | fputc ('\n', asm_out_file); |
5722 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
5723 | { | |
5724 | switch (opc) | |
5725 | { | |
5726 | case DW_LNS_advance_pc: | |
5727 | case DW_LNS_advance_line: | |
5728 | case DW_LNS_set_file: | |
5729 | case DW_LNS_set_column: | |
5730 | case DW_LNS_fixed_advance_pc: | |
5731 | n_op_args = 1; | |
5732 | break; | |
5733 | default: | |
5734 | n_op_args = 0; | |
5735 | break; | |
5736 | } | |
5737 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
c5cec899 | 5738 | if (flag_debug_asm) |
71dfc51f RK |
5739 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", |
5740 | ASM_COMMENT_START, opc, n_op_args); | |
a3f97cbb JW |
5741 | fputc ('\n', asm_out_file); |
5742 | } | |
71dfc51f | 5743 | |
c5cec899 | 5744 | if (flag_debug_asm) |
71dfc51f RK |
5745 | fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START); |
5746 | ||
a3f97cbb JW |
5747 | /* Include directory table is empty, at present */ |
5748 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5749 | fputc ('\n', asm_out_file); | |
c5cec899 | 5750 | if (flag_debug_asm) |
71dfc51f RK |
5751 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); |
5752 | ||
a3f97cbb JW |
5753 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
5754 | { | |
c5cec899 | 5755 | if (flag_debug_asm) |
8d4e65a6 JL |
5756 | { |
5757 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
2d8b0f3a | 5758 | fprintf (asm_out_file, "%s File Entry: 0x%lx", |
8d4e65a6 JL |
5759 | ASM_COMMENT_START, ft_index); |
5760 | } | |
5761 | else | |
5762 | { | |
5763 | ASM_OUTPUT_ASCII (asm_out_file, | |
5764 | file_table[ft_index], | |
c84e2712 | 5765 | (int) strlen (file_table[ft_index]) + 1); |
8d4e65a6 | 5766 | } |
71dfc51f | 5767 | |
a3f97cbb | 5768 | fputc ('\n', asm_out_file); |
71dfc51f | 5769 | |
a3f97cbb JW |
5770 | /* Include directory index */ |
5771 | output_uleb128 (0); | |
5772 | fputc ('\n', asm_out_file); | |
71dfc51f | 5773 | |
a3f97cbb JW |
5774 | /* Modification time */ |
5775 | output_uleb128 (0); | |
5776 | fputc ('\n', asm_out_file); | |
71dfc51f | 5777 | |
a3f97cbb JW |
5778 | /* File length in bytes */ |
5779 | output_uleb128 (0); | |
5780 | fputc ('\n', asm_out_file); | |
5781 | } | |
71dfc51f | 5782 | |
a3f97cbb JW |
5783 | /* Terminate the file name table */ |
5784 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5785 | fputc ('\n', asm_out_file); | |
5786 | ||
5787 | /* Set the address register to the first location in the text section */ | |
5788 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5789 | if (flag_debug_asm) |
71dfc51f RK |
5790 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5791 | ||
a3f97cbb JW |
5792 | fputc ('\n', asm_out_file); |
5793 | output_uleb128 (1 + PTR_SIZE); | |
5794 | fputc ('\n', asm_out_file); | |
5795 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5796 | fputc ('\n', asm_out_file); | |
49bcd085 | 5797 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, stripattributes (TEXT_SECTION)); |
a3f97cbb JW |
5798 | fputc ('\n', asm_out_file); |
5799 | ||
5800 | /* Generate the line number to PC correspondence table, encoded as | |
5801 | a series of state machine operations. */ | |
5802 | current_file = 1; | |
5803 | current_line = 1; | |
49bcd085 | 5804 | strcpy (prev_line_label, stripattributes (TEXT_SECTION)); |
a3f97cbb JW |
5805 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
5806 | { | |
e90b62db | 5807 | register dw_line_info_ref line_info; |
71dfc51f | 5808 | |
f19a6894 JW |
5809 | /* Emit debug info for the address of the current line, choosing |
5810 | the encoding that uses the least amount of space. */ | |
5811 | /* ??? Unfortunately, we have little choice here currently, and must | |
5812 | always use the most general form. Gcc does not know the address | |
5813 | delta itself, so we can't use DW_LNS_advance_pc. There are no known | |
5814 | dwarf2 aware assemblers at this time, so we can't use any special | |
5815 | pseudo ops that would allow the assembler to optimally encode this for | |
5816 | us. Many ports do have length attributes which will give an upper | |
5817 | bound on the address range. We could perhaps use length attributes | |
5818 | to determine when it is safe to use DW_LNS_fixed_advance_pc. */ | |
5c90448c | 5819 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
5820 | if (0) |
5821 | { | |
5822 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
5823 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5824 | if (flag_debug_asm) |
f19a6894 JW |
5825 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5826 | ASM_COMMENT_START); | |
5827 | ||
5828 | fputc ('\n', asm_out_file); | |
5829 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
5830 | fputc ('\n', asm_out_file); | |
5831 | } | |
5832 | else | |
5833 | { | |
5834 | /* This can handle any delta. This takes 4+PTR_SIZE bytes. */ | |
5835 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5836 | if (flag_debug_asm) |
f19a6894 JW |
5837 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5838 | ASM_COMMENT_START); | |
5839 | fputc ('\n', asm_out_file); | |
5840 | output_uleb128 (1 + PTR_SIZE); | |
5841 | fputc ('\n', asm_out_file); | |
5842 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5843 | fputc ('\n', asm_out_file); | |
5844 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5845 | fputc ('\n', asm_out_file); | |
5846 | } | |
5847 | strcpy (prev_line_label, line_label); | |
5848 | ||
5849 | /* Emit debug info for the source file of the current line, if | |
5850 | different from the previous line. */ | |
a3f97cbb JW |
5851 | line_info = &line_info_table[lt_index]; |
5852 | if (line_info->dw_file_num != current_file) | |
5853 | { | |
5854 | current_file = line_info->dw_file_num; | |
5855 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 5856 | if (flag_debug_asm) |
71dfc51f RK |
5857 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5858 | ||
a3f97cbb JW |
5859 | fputc ('\n', asm_out_file); |
5860 | output_uleb128 (current_file); | |
c5cec899 | 5861 | if (flag_debug_asm) |
b2932ae5 | 5862 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5863 | |
a3f97cbb JW |
5864 | fputc ('\n', asm_out_file); |
5865 | } | |
71dfc51f | 5866 | |
f19a6894 JW |
5867 | /* Emit debug info for the current line number, choosing the encoding |
5868 | that uses the least amount of space. */ | |
a94dbf2c JM |
5869 | line_offset = line_info->dw_line_num - current_line; |
5870 | line_delta = line_offset - DWARF_LINE_BASE; | |
5871 | current_line = line_info->dw_line_num; | |
5872 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
a3f97cbb | 5873 | { |
f19a6894 JW |
5874 | /* This can handle deltas from -10 to 234, using the current |
5875 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
5876 | takes 1 byte. */ | |
a94dbf2c JM |
5877 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, |
5878 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 5879 | if (flag_debug_asm) |
a94dbf2c | 5880 | fprintf (asm_out_file, |
2d8b0f3a | 5881 | "\t%s line %ld", ASM_COMMENT_START, current_line); |
71dfc51f | 5882 | |
a94dbf2c JM |
5883 | fputc ('\n', asm_out_file); |
5884 | } | |
5885 | else | |
5886 | { | |
f19a6894 JW |
5887 | /* This can handle any delta. This takes at least 4 bytes, depending |
5888 | on the value being encoded. */ | |
a94dbf2c | 5889 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); |
c5cec899 | 5890 | if (flag_debug_asm) |
2d8b0f3a | 5891 | fprintf (asm_out_file, "\t%s advance to line %ld", |
71dfc51f RK |
5892 | ASM_COMMENT_START, current_line); |
5893 | ||
a94dbf2c JM |
5894 | fputc ('\n', asm_out_file); |
5895 | output_sleb128 (line_offset); | |
5896 | fputc ('\n', asm_out_file); | |
5897 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5898 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5899 | } |
a3f97cbb JW |
5900 | } |
5901 | ||
f19a6894 JW |
5902 | /* Emit debug info for the address of the end of the function. */ |
5903 | if (0) | |
5904 | { | |
5905 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5906 | if (flag_debug_asm) |
f19a6894 JW |
5907 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5908 | ASM_COMMENT_START); | |
71dfc51f | 5909 | |
f19a6894 JW |
5910 | fputc ('\n', asm_out_file); |
5911 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label); | |
5912 | fputc ('\n', asm_out_file); | |
5913 | } | |
5914 | else | |
5915 | { | |
5916 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5917 | if (flag_debug_asm) |
f19a6894 JW |
5918 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5919 | fputc ('\n', asm_out_file); | |
5920 | output_uleb128 (1 + PTR_SIZE); | |
5921 | fputc ('\n', asm_out_file); | |
5922 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5923 | fputc ('\n', asm_out_file); | |
5924 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label); | |
5925 | fputc ('\n', asm_out_file); | |
5926 | } | |
bdb669cb | 5927 | |
a3f97cbb JW |
5928 | /* Output the marker for the end of the line number info. */ |
5929 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5930 | if (flag_debug_asm) |
71dfc51f RK |
5931 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); |
5932 | ||
a3f97cbb JW |
5933 | fputc ('\n', asm_out_file); |
5934 | output_uleb128 (1); | |
5935 | fputc ('\n', asm_out_file); | |
5936 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5937 | fputc ('\n', asm_out_file); | |
e90b62db JM |
5938 | |
5939 | function = 0; | |
5940 | current_file = 1; | |
5941 | current_line = 1; | |
5942 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
5943 | { | |
5944 | register dw_separate_line_info_ref line_info | |
5945 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 5946 | |
f19a6894 JW |
5947 | /* Emit debug info for the address of the current line. If this is |
5948 | a new function, or the first line of a function, then we need | |
5949 | to handle it differently. */ | |
5c90448c JM |
5950 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
5951 | lt_index); | |
e90b62db JM |
5952 | if (function != line_info->function) |
5953 | { | |
5954 | function = line_info->function; | |
71dfc51f | 5955 | |
e90b62db JM |
5956 | /* Set the address register to the first line in the function */ |
5957 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5958 | if (flag_debug_asm) |
e90b62db JM |
5959 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5960 | ASM_COMMENT_START); | |
71dfc51f | 5961 | |
e90b62db JM |
5962 | fputc ('\n', asm_out_file); |
5963 | output_uleb128 (1 + PTR_SIZE); | |
5964 | fputc ('\n', asm_out_file); | |
5965 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5966 | fputc ('\n', asm_out_file); | |
5967 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5968 | fputc ('\n', asm_out_file); | |
5969 | } | |
5970 | else | |
5971 | { | |
f19a6894 JW |
5972 | /* ??? See the DW_LNS_advance_pc comment above. */ |
5973 | if (0) | |
5974 | { | |
5975 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5976 | if (flag_debug_asm) |
f19a6894 JW |
5977 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5978 | ASM_COMMENT_START); | |
71dfc51f | 5979 | |
f19a6894 JW |
5980 | fputc ('\n', asm_out_file); |
5981 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5982 | prev_line_label); | |
5983 | fputc ('\n', asm_out_file); | |
5984 | } | |
5985 | else | |
5986 | { | |
5987 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5988 | if (flag_debug_asm) |
f19a6894 JW |
5989 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5990 | ASM_COMMENT_START); | |
5991 | fputc ('\n', asm_out_file); | |
5992 | output_uleb128 (1 + PTR_SIZE); | |
5993 | fputc ('\n', asm_out_file); | |
5994 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5995 | fputc ('\n', asm_out_file); | |
5996 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5997 | fputc ('\n', asm_out_file); | |
5998 | } | |
e90b62db | 5999 | } |
f19a6894 | 6000 | strcpy (prev_line_label, line_label); |
71dfc51f | 6001 | |
f19a6894 JW |
6002 | /* Emit debug info for the source file of the current line, if |
6003 | different from the previous line. */ | |
e90b62db JM |
6004 | if (line_info->dw_file_num != current_file) |
6005 | { | |
6006 | current_file = line_info->dw_file_num; | |
6007 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 6008 | if (flag_debug_asm) |
71dfc51f RK |
6009 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
6010 | ||
e90b62db JM |
6011 | fputc ('\n', asm_out_file); |
6012 | output_uleb128 (current_file); | |
c5cec899 | 6013 | if (flag_debug_asm) |
b2932ae5 | 6014 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 6015 | |
e90b62db JM |
6016 | fputc ('\n', asm_out_file); |
6017 | } | |
71dfc51f | 6018 | |
f19a6894 JW |
6019 | /* Emit debug info for the current line number, choosing the encoding |
6020 | that uses the least amount of space. */ | |
e90b62db JM |
6021 | if (line_info->dw_line_num != current_line) |
6022 | { | |
6023 | line_offset = line_info->dw_line_num - current_line; | |
6024 | line_delta = line_offset - DWARF_LINE_BASE; | |
6025 | current_line = line_info->dw_line_num; | |
6026 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6027 | { | |
6028 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
6029 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 6030 | if (flag_debug_asm) |
71dfc51f | 6031 | fprintf (asm_out_file, |
2d8b0f3a | 6032 | "\t%s line %ld", ASM_COMMENT_START, current_line); |
71dfc51f | 6033 | |
e90b62db JM |
6034 | fputc ('\n', asm_out_file); |
6035 | } | |
6036 | else | |
6037 | { | |
6038 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
c5cec899 | 6039 | if (flag_debug_asm) |
2d8b0f3a | 6040 | fprintf (asm_out_file, "\t%s advance to line %ld", |
71dfc51f RK |
6041 | ASM_COMMENT_START, current_line); |
6042 | ||
e90b62db JM |
6043 | fputc ('\n', asm_out_file); |
6044 | output_sleb128 (line_offset); | |
6045 | fputc ('\n', asm_out_file); | |
6046 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
6047 | fputc ('\n', asm_out_file); | |
6048 | } | |
6049 | } | |
71dfc51f | 6050 | |
e90b62db | 6051 | ++lt_index; |
e90b62db JM |
6052 | |
6053 | /* If we're done with a function, end its sequence. */ | |
6054 | if (lt_index == separate_line_info_table_in_use | |
6055 | || separate_line_info_table[lt_index].function != function) | |
6056 | { | |
6057 | current_file = 1; | |
6058 | current_line = 1; | |
71dfc51f | 6059 | |
f19a6894 | 6060 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 6061 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
6062 | if (0) |
6063 | { | |
6064 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 6065 | if (flag_debug_asm) |
f19a6894 JW |
6066 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
6067 | ASM_COMMENT_START); | |
6068 | ||
6069 | fputc ('\n', asm_out_file); | |
6070 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
6071 | prev_line_label); | |
6072 | fputc ('\n', asm_out_file); | |
6073 | } | |
6074 | else | |
6075 | { | |
6076 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6077 | if (flag_debug_asm) |
f19a6894 JW |
6078 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6079 | ASM_COMMENT_START); | |
6080 | fputc ('\n', asm_out_file); | |
6081 | output_uleb128 (1 + PTR_SIZE); | |
6082 | fputc ('\n', asm_out_file); | |
6083 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6084 | fputc ('\n', asm_out_file); | |
6085 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6086 | fputc ('\n', asm_out_file); | |
6087 | } | |
e90b62db JM |
6088 | |
6089 | /* Output the marker for the end of this sequence. */ | |
6090 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6091 | if (flag_debug_asm) |
e90b62db JM |
6092 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", |
6093 | ASM_COMMENT_START); | |
71dfc51f | 6094 | |
e90b62db JM |
6095 | fputc ('\n', asm_out_file); |
6096 | output_uleb128 (1); | |
6097 | fputc ('\n', asm_out_file); | |
6098 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
6099 | fputc ('\n', asm_out_file); | |
6100 | } | |
6101 | } | |
a3f97cbb JW |
6102 | } |
6103 | \f | |
71dfc51f RK |
6104 | /* Given a pointer to a BLOCK node return non-zero if (and only if) the node |
6105 | in question represents the outermost pair of curly braces (i.e. the "body | |
6106 | block") of a function or method. | |
6107 | ||
6108 | For any BLOCK node representing a "body block" of a function or method, the | |
6109 | BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which | |
6110 | represents the outermost (function) scope for the function or method (i.e. | |
6111 | the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of | |
6112 | *that* node in turn will point to the relevant FUNCTION_DECL node. */ | |
6113 | ||
6114 | static inline int | |
a3f97cbb JW |
6115 | is_body_block (stmt) |
6116 | register tree stmt; | |
6117 | { | |
6118 | if (TREE_CODE (stmt) == BLOCK) | |
6119 | { | |
6120 | register tree parent = BLOCK_SUPERCONTEXT (stmt); | |
6121 | ||
6122 | if (TREE_CODE (parent) == BLOCK) | |
6123 | { | |
6124 | register tree grandparent = BLOCK_SUPERCONTEXT (parent); | |
6125 | ||
6126 | if (TREE_CODE (grandparent) == FUNCTION_DECL) | |
6127 | return 1; | |
6128 | } | |
6129 | } | |
71dfc51f | 6130 | |
a3f97cbb JW |
6131 | return 0; |
6132 | } | |
6133 | ||
a3f97cbb JW |
6134 | /* Given a pointer to a tree node for some base type, return a pointer to |
6135 | a DIE that describes the given type. | |
6136 | ||
6137 | This routine must only be called for GCC type nodes that correspond to | |
6138 | Dwarf base (fundamental) types. */ | |
71dfc51f | 6139 | |
a3f97cbb JW |
6140 | static dw_die_ref |
6141 | base_type_die (type) | |
6142 | register tree type; | |
6143 | { | |
a9d38797 JM |
6144 | register dw_die_ref base_type_result; |
6145 | register char *type_name; | |
6146 | register enum dwarf_type encoding; | |
71dfc51f | 6147 | register tree name = TYPE_NAME (type); |
a3f97cbb | 6148 | |
a9d38797 JM |
6149 | if (TREE_CODE (type) == ERROR_MARK |
6150 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
6151 | return 0; |
6152 | ||
71dfc51f RK |
6153 | if (TREE_CODE (name) == TYPE_DECL) |
6154 | name = DECL_NAME (name); | |
6155 | type_name = IDENTIFIER_POINTER (name); | |
a9d38797 | 6156 | |
a3f97cbb JW |
6157 | switch (TREE_CODE (type)) |
6158 | { | |
a3f97cbb | 6159 | case INTEGER_TYPE: |
a9d38797 | 6160 | /* Carefully distinguish the C character types, without messing |
a3f97cbb JW |
6161 | up if the language is not C. Note that we check only for the names |
6162 | that contain spaces; other names might occur by coincidence in other | |
6163 | languages. */ | |
a9d38797 JM |
6164 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
6165 | && (type == char_type_node | |
6166 | || ! strcmp (type_name, "signed char") | |
6167 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 6168 | { |
a9d38797 JM |
6169 | if (TREE_UNSIGNED (type)) |
6170 | encoding = DW_ATE_unsigned; | |
6171 | else | |
6172 | encoding = DW_ATE_signed; | |
6173 | break; | |
a3f97cbb | 6174 | } |
a9d38797 | 6175 | /* else fall through */ |
a3f97cbb | 6176 | |
a9d38797 JM |
6177 | case CHAR_TYPE: |
6178 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
6179 | if (TREE_UNSIGNED (type)) | |
6180 | encoding = DW_ATE_unsigned_char; | |
6181 | else | |
6182 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
6183 | break; |
6184 | ||
6185 | case REAL_TYPE: | |
a9d38797 | 6186 | encoding = DW_ATE_float; |
a3f97cbb JW |
6187 | break; |
6188 | ||
6189 | case COMPLEX_TYPE: | |
a9d38797 | 6190 | encoding = DW_ATE_complex_float; |
a3f97cbb JW |
6191 | break; |
6192 | ||
6193 | case BOOLEAN_TYPE: | |
a9d38797 JM |
6194 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
6195 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
6196 | break; |
6197 | ||
6198 | default: | |
a9d38797 | 6199 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
6200 | } |
6201 | ||
a9d38797 JM |
6202 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
6203 | add_AT_string (base_type_result, DW_AT_name, type_name); | |
6204 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 6205 | int_size_in_bytes (type)); |
a9d38797 | 6206 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
6207 | |
6208 | return base_type_result; | |
6209 | } | |
6210 | ||
6211 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
6212 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
6213 | a given type is generally the same as the given type, except that if the | |
6214 | given type is a pointer or reference type, then the root type of the given | |
6215 | type is the root type of the "basis" type for the pointer or reference | |
6216 | type. (This definition of the "root" type is recursive.) Also, the root | |
6217 | type of a `const' qualified type or a `volatile' qualified type is the | |
6218 | root type of the given type without the qualifiers. */ | |
71dfc51f | 6219 | |
a3f97cbb JW |
6220 | static tree |
6221 | root_type (type) | |
6222 | register tree type; | |
6223 | { | |
6224 | if (TREE_CODE (type) == ERROR_MARK) | |
6225 | return error_mark_node; | |
6226 | ||
6227 | switch (TREE_CODE (type)) | |
6228 | { | |
6229 | case ERROR_MARK: | |
6230 | return error_mark_node; | |
6231 | ||
6232 | case POINTER_TYPE: | |
6233 | case REFERENCE_TYPE: | |
6234 | return type_main_variant (root_type (TREE_TYPE (type))); | |
6235 | ||
6236 | default: | |
6237 | return type_main_variant (type); | |
6238 | } | |
6239 | } | |
6240 | ||
6241 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
6242 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
6243 | |
6244 | static inline int | |
a3f97cbb JW |
6245 | is_base_type (type) |
6246 | register tree type; | |
6247 | { | |
6248 | switch (TREE_CODE (type)) | |
6249 | { | |
6250 | case ERROR_MARK: | |
6251 | case VOID_TYPE: | |
6252 | case INTEGER_TYPE: | |
6253 | case REAL_TYPE: | |
6254 | case COMPLEX_TYPE: | |
6255 | case BOOLEAN_TYPE: | |
6256 | case CHAR_TYPE: | |
6257 | return 1; | |
6258 | ||
6259 | case SET_TYPE: | |
6260 | case ARRAY_TYPE: | |
6261 | case RECORD_TYPE: | |
6262 | case UNION_TYPE: | |
6263 | case QUAL_UNION_TYPE: | |
6264 | case ENUMERAL_TYPE: | |
6265 | case FUNCTION_TYPE: | |
6266 | case METHOD_TYPE: | |
6267 | case POINTER_TYPE: | |
6268 | case REFERENCE_TYPE: | |
6269 | case FILE_TYPE: | |
6270 | case OFFSET_TYPE: | |
6271 | case LANG_TYPE: | |
6272 | return 0; | |
6273 | ||
6274 | default: | |
6275 | abort (); | |
6276 | } | |
71dfc51f | 6277 | |
a3f97cbb JW |
6278 | return 0; |
6279 | } | |
6280 | ||
6281 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
6282 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 6283 | |
a3f97cbb JW |
6284 | static dw_die_ref |
6285 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
6286 | register tree type; | |
6287 | register int is_const_type; | |
6288 | register int is_volatile_type; | |
6289 | register dw_die_ref context_die; | |
6290 | { | |
6291 | register enum tree_code code = TREE_CODE (type); | |
6292 | register dw_die_ref mod_type_die = NULL; | |
6293 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 6294 | register tree item_type = NULL; |
a3f97cbb JW |
6295 | |
6296 | if (code != ERROR_MARK) | |
6297 | { | |
a94dbf2c | 6298 | type = build_type_variant (type, is_const_type, is_volatile_type); |
bdb669cb JM |
6299 | |
6300 | mod_type_die = lookup_type_die (type); | |
6301 | if (mod_type_die) | |
6302 | return mod_type_die; | |
6303 | ||
a94dbf2c JM |
6304 | /* Handle C typedef types. */ |
6305 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
6306 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
6307 | { | |
6308 | tree dtype = TREE_TYPE (TYPE_NAME (type)); | |
6309 | if (type == dtype) | |
6310 | { | |
6311 | /* For a named type, use the typedef. */ | |
6312 | gen_type_die (type, context_die); | |
6313 | mod_type_die = lookup_type_die (type); | |
6314 | } | |
71dfc51f | 6315 | |
a94dbf2c JM |
6316 | else if (is_const_type < TYPE_READONLY (dtype) |
6317 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
6318 | /* cv-unqualified version of named type. Just use the unnamed | |
6319 | type to which it refers. */ | |
71dfc51f RK |
6320 | mod_type_die |
6321 | = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), | |
6322 | is_const_type, is_volatile_type, | |
6323 | context_die); | |
6324 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
6325 | } |
6326 | ||
6327 | if (mod_type_die) | |
6328 | /* OK */; | |
6329 | else if (is_const_type) | |
a3f97cbb | 6330 | { |
ab72d377 | 6331 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 6332 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
6333 | } |
6334 | else if (is_volatile_type) | |
6335 | { | |
ab72d377 | 6336 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 6337 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
6338 | } |
6339 | else if (code == POINTER_TYPE) | |
6340 | { | |
ab72d377 | 6341 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 6342 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6343 | #if 0 |
a3f97cbb | 6344 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6345 | #endif |
a3f97cbb | 6346 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6347 | } |
6348 | else if (code == REFERENCE_TYPE) | |
6349 | { | |
ab72d377 | 6350 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 6351 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6352 | #if 0 |
a3f97cbb | 6353 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6354 | #endif |
a3f97cbb | 6355 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6356 | } |
6357 | else if (is_base_type (type)) | |
71dfc51f | 6358 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
6359 | else |
6360 | { | |
4b674448 JM |
6361 | gen_type_die (type, context_die); |
6362 | ||
a3f97cbb JW |
6363 | /* We have to get the type_main_variant here (and pass that to the |
6364 | `lookup_type_die' routine) because the ..._TYPE node we have | |
6365 | might simply be a *copy* of some original type node (where the | |
6366 | copy was created to help us keep track of typedef names) and | |
6367 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 6368 | ..._TYPE node. */ |
a3f97cbb | 6369 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
6370 | if (mod_type_die == NULL) |
6371 | abort (); | |
a3f97cbb JW |
6372 | } |
6373 | } | |
71dfc51f | 6374 | |
dfcf9891 JW |
6375 | equate_type_number_to_die (type, mod_type_die); |
6376 | if (item_type) | |
71dfc51f RK |
6377 | /* We must do this after the equate_type_number_to_die call, in case |
6378 | this is a recursive type. This ensures that the modified_type_die | |
6379 | recursion will terminate even if the type is recursive. Recursive | |
6380 | types are possible in Ada. */ | |
6381 | sub_die = modified_type_die (item_type, | |
6382 | TYPE_READONLY (item_type), | |
6383 | TYPE_VOLATILE (item_type), | |
6384 | context_die); | |
6385 | ||
a3f97cbb | 6386 | if (sub_die != NULL) |
71dfc51f RK |
6387 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
6388 | ||
a3f97cbb JW |
6389 | return mod_type_die; |
6390 | } | |
6391 | ||
a3f97cbb JW |
6392 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6393 | an enumerated type. */ | |
71dfc51f RK |
6394 | |
6395 | static inline int | |
a3f97cbb JW |
6396 | type_is_enum (type) |
6397 | register tree type; | |
6398 | { | |
6399 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
6400 | } | |
6401 | ||
a3f97cbb | 6402 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 6403 | |
a3f97cbb JW |
6404 | static dw_loc_descr_ref |
6405 | reg_loc_descriptor (rtl) | |
6406 | register rtx rtl; | |
6407 | { | |
6408 | register dw_loc_descr_ref loc_result = NULL; | |
6409 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 6410 | |
85066503 | 6411 | if (reg <= 31) |
71dfc51f | 6412 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 6413 | else |
71dfc51f RK |
6414 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
6415 | ||
a3f97cbb JW |
6416 | return loc_result; |
6417 | } | |
6418 | ||
6419 | /* Return a location descriptor that designates a base+offset location. */ | |
71dfc51f | 6420 | |
a3f97cbb JW |
6421 | static dw_loc_descr_ref |
6422 | based_loc_descr (reg, offset) | |
6423 | unsigned reg; | |
6424 | long int offset; | |
6425 | { | |
6426 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
6427 | /* For the "frame base", we use the frame pointer or stack pointer |
6428 | registers, since the RTL for local variables is relative to one of | |
6429 | them. */ | |
6430 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 6431 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 6432 | : STACK_POINTER_REGNUM); |
71dfc51f | 6433 | |
a3f97cbb | 6434 | if (reg == fp_reg) |
71dfc51f | 6435 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 6436 | else if (reg <= 31) |
71dfc51f | 6437 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 6438 | else |
71dfc51f RK |
6439 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
6440 | ||
a3f97cbb JW |
6441 | return loc_result; |
6442 | } | |
6443 | ||
6444 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
6445 | |
6446 | static inline int | |
a3f97cbb JW |
6447 | is_based_loc (rtl) |
6448 | register rtx rtl; | |
6449 | { | |
71dfc51f RK |
6450 | return (GET_CODE (rtl) == PLUS |
6451 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
6452 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
6453 | } |
6454 | ||
6455 | /* The following routine converts the RTL for a variable or parameter | |
6456 | (resident in memory) into an equivalent Dwarf representation of a | |
6457 | mechanism for getting the address of that same variable onto the top of a | |
6458 | hypothetical "address evaluation" stack. | |
71dfc51f | 6459 | |
a3f97cbb JW |
6460 | When creating memory location descriptors, we are effectively transforming |
6461 | the RTL for a memory-resident object into its Dwarf postfix expression | |
6462 | equivalent. This routine recursively descends an RTL tree, turning | |
6463 | it into Dwarf postfix code as it goes. */ | |
71dfc51f | 6464 | |
a3f97cbb JW |
6465 | static dw_loc_descr_ref |
6466 | mem_loc_descriptor (rtl) | |
6467 | register rtx rtl; | |
6468 | { | |
6469 | dw_loc_descr_ref mem_loc_result = NULL; | |
6470 | /* Note that for a dynamically sized array, the location we will generate a | |
6471 | description of here will be the lowest numbered location which is | |
6472 | actually within the array. That's *not* necessarily the same as the | |
6473 | zeroth element of the array. */ | |
71dfc51f | 6474 | |
a3f97cbb JW |
6475 | switch (GET_CODE (rtl)) |
6476 | { | |
6477 | case SUBREG: | |
6478 | /* The case of a subreg may arise when we have a local (register) | |
6479 | variable or a formal (register) parameter which doesn't quite fill | |
6480 | up an entire register. For now, just assume that it is | |
6481 | legitimate to make the Dwarf info refer to the whole register which | |
6482 | contains the given subreg. */ | |
6483 | rtl = XEXP (rtl, 0); | |
71dfc51f RK |
6484 | |
6485 | /* ... fall through ... */ | |
a3f97cbb JW |
6486 | |
6487 | case REG: | |
6488 | /* Whenever a register number forms a part of the description of the | |
6489 | method for calculating the (dynamic) address of a memory resident | |
6490 | object, DWARF rules require the register number be referred to as | |
6491 | a "base register". This distinction is not based in any way upon | |
6492 | what category of register the hardware believes the given register | |
6493 | belongs to. This is strictly DWARF terminology we're dealing with | |
6494 | here. Note that in cases where the location of a memory-resident | |
6495 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
6496 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
6497 | may just be OP_BASEREG (basereg). This may look deceptively like | |
6498 | the object in question was allocated to a register (rather than in | |
6499 | memory) so DWARF consumers need to be aware of the subtle | |
6500 | distinction between OP_REG and OP_BASEREG. */ | |
6501 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
6502 | break; | |
6503 | ||
6504 | case MEM: | |
6505 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
6506 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
6507 | break; | |
6508 | ||
6509 | case CONST: | |
6510 | case SYMBOL_REF: | |
6511 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
6512 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
6513 | mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl); | |
6514 | break; | |
6515 | ||
6516 | case PLUS: | |
6517 | if (is_based_loc (rtl)) | |
71dfc51f RK |
6518 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
6519 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
6520 | else |
6521 | { | |
6522 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6523 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6524 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0)); | |
6525 | } | |
6526 | break; | |
6527 | ||
dd2478ae JW |
6528 | case MULT: |
6529 | /* If a pseudo-reg is optimized away, it is possible for it to | |
6530 | be replaced with a MEM containing a multiply. */ | |
6531 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6532 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6533 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
6534 | break; | |
6535 | ||
a3f97cbb JW |
6536 | case CONST_INT: |
6537 | mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0); | |
6538 | break; | |
6539 | ||
6540 | default: | |
6541 | abort (); | |
6542 | } | |
71dfc51f | 6543 | |
a3f97cbb JW |
6544 | return mem_loc_result; |
6545 | } | |
6546 | ||
956d6950 | 6547 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
6548 | This is typically a complex variable. */ |
6549 | ||
6550 | static dw_loc_descr_ref | |
6551 | concat_loc_descriptor (x0, x1) | |
6552 | register rtx x0, x1; | |
6553 | { | |
6554 | dw_loc_descr_ref cc_loc_result = NULL; | |
6555 | ||
6556 | if (!is_pseudo_reg (x0) | |
6557 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
6558 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
6559 | add_loc_descr (&cc_loc_result, | |
6560 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
6561 | ||
6562 | if (!is_pseudo_reg (x1) | |
6563 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
6564 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
6565 | add_loc_descr (&cc_loc_result, | |
6566 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
6567 | ||
6568 | return cc_loc_result; | |
6569 | } | |
6570 | ||
a3f97cbb JW |
6571 | /* Output a proper Dwarf location descriptor for a variable or parameter |
6572 | which is either allocated in a register or in a memory location. For a | |
6573 | register, we just generate an OP_REG and the register number. For a | |
6574 | memory location we provide a Dwarf postfix expression describing how to | |
6575 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 6576 | |
a3f97cbb JW |
6577 | static dw_loc_descr_ref |
6578 | loc_descriptor (rtl) | |
6579 | register rtx rtl; | |
6580 | { | |
6581 | dw_loc_descr_ref loc_result = NULL; | |
6582 | switch (GET_CODE (rtl)) | |
6583 | { | |
6584 | case SUBREG: | |
a3f97cbb JW |
6585 | /* The case of a subreg may arise when we have a local (register) |
6586 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 6587 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
6588 | legitimate to make the Dwarf info refer to the whole register which |
6589 | contains the given subreg. */ | |
a3f97cbb | 6590 | rtl = XEXP (rtl, 0); |
71dfc51f RK |
6591 | |
6592 | /* ... fall through ... */ | |
a3f97cbb JW |
6593 | |
6594 | case REG: | |
5c90448c | 6595 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
6596 | break; |
6597 | ||
6598 | case MEM: | |
6599 | loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
6600 | break; | |
6601 | ||
4401bf24 JL |
6602 | case CONCAT: |
6603 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
6604 | break; | |
6605 | ||
a3f97cbb | 6606 | default: |
71dfc51f | 6607 | abort (); |
a3f97cbb | 6608 | } |
71dfc51f | 6609 | |
a3f97cbb JW |
6610 | return loc_result; |
6611 | } | |
6612 | ||
6613 | /* Given an unsigned value, round it up to the lowest multiple of `boundary' | |
6614 | which is not less than the value itself. */ | |
71dfc51f RK |
6615 | |
6616 | static inline unsigned | |
a3f97cbb JW |
6617 | ceiling (value, boundary) |
6618 | register unsigned value; | |
6619 | register unsigned boundary; | |
6620 | { | |
6621 | return (((value + boundary - 1) / boundary) * boundary); | |
6622 | } | |
6623 | ||
6624 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
6625 | pointer to the declared type for the relevant field variable, or return | |
6626 | `integer_type_node' if the given node turns out to be an | |
6627 | ERROR_MARK node. */ | |
71dfc51f RK |
6628 | |
6629 | static inline tree | |
a3f97cbb JW |
6630 | field_type (decl) |
6631 | register tree decl; | |
6632 | { | |
6633 | register tree type; | |
6634 | ||
6635 | if (TREE_CODE (decl) == ERROR_MARK) | |
6636 | return integer_type_node; | |
6637 | ||
6638 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 6639 | if (type == NULL_TREE) |
a3f97cbb JW |
6640 | type = TREE_TYPE (decl); |
6641 | ||
6642 | return type; | |
6643 | } | |
6644 | ||
6645 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6646 | node, return the alignment in bits for the type, or else return | |
6647 | BITS_PER_WORD if the node actually turns out to be an | |
6648 | ERROR_MARK node. */ | |
71dfc51f RK |
6649 | |
6650 | static inline unsigned | |
a3f97cbb JW |
6651 | simple_type_align_in_bits (type) |
6652 | register tree type; | |
6653 | { | |
6654 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
6655 | } | |
6656 | ||
6657 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6658 | node, return the size in bits for the type if it is a constant, or else | |
6659 | return the alignment for the type if the type's size is not constant, or | |
6660 | else return BITS_PER_WORD if the type actually turns out to be an | |
6661 | ERROR_MARK node. */ | |
71dfc51f RK |
6662 | |
6663 | static inline unsigned | |
a3f97cbb JW |
6664 | simple_type_size_in_bits (type) |
6665 | register tree type; | |
6666 | { | |
6667 | if (TREE_CODE (type) == ERROR_MARK) | |
6668 | return BITS_PER_WORD; | |
6669 | else | |
6670 | { | |
6671 | register tree type_size_tree = TYPE_SIZE (type); | |
6672 | ||
6673 | if (TREE_CODE (type_size_tree) != INTEGER_CST) | |
6674 | return TYPE_ALIGN (type); | |
6675 | ||
6676 | return (unsigned) TREE_INT_CST_LOW (type_size_tree); | |
6677 | } | |
6678 | } | |
6679 | ||
6680 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
6681 | return the byte offset of the lowest addressed byte of the "containing | |
6682 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
6683 | determine what that offset is, either because the argument turns out to | |
6684 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
6685 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 6686 | |
a3f97cbb JW |
6687 | static unsigned |
6688 | field_byte_offset (decl) | |
6689 | register tree decl; | |
6690 | { | |
6691 | register unsigned type_align_in_bytes; | |
6692 | register unsigned type_align_in_bits; | |
6693 | register unsigned type_size_in_bits; | |
6694 | register unsigned object_offset_in_align_units; | |
6695 | register unsigned object_offset_in_bits; | |
6696 | register unsigned object_offset_in_bytes; | |
6697 | register tree type; | |
6698 | register tree bitpos_tree; | |
6699 | register tree field_size_tree; | |
6700 | register unsigned bitpos_int; | |
6701 | register unsigned deepest_bitpos; | |
6702 | register unsigned field_size_in_bits; | |
6703 | ||
6704 | if (TREE_CODE (decl) == ERROR_MARK) | |
6705 | return 0; | |
6706 | ||
6707 | if (TREE_CODE (decl) != FIELD_DECL) | |
6708 | abort (); | |
6709 | ||
6710 | type = field_type (decl); | |
6711 | ||
6712 | bitpos_tree = DECL_FIELD_BITPOS (decl); | |
6713 | field_size_tree = DECL_SIZE (decl); | |
6714 | ||
6715 | /* We cannot yet cope with fields whose positions or sizes are variable, so | |
6716 | for now, when we see such things, we simply return 0. Someday, we may | |
6717 | be able to handle such cases, but it will be damn difficult. */ | |
6718 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
6719 | return 0; | |
6720 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
6721 | ||
6722 | if (TREE_CODE (field_size_tree) != INTEGER_CST) | |
6723 | return 0; | |
a3f97cbb | 6724 | |
71dfc51f | 6725 | field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree); |
a3f97cbb | 6726 | type_size_in_bits = simple_type_size_in_bits (type); |
a3f97cbb JW |
6727 | type_align_in_bits = simple_type_align_in_bits (type); |
6728 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
6729 | ||
6730 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
6731 | the starting bit offset (relative to the start of the containing | |
6732 | structure type) of the hypothetical "containing object" for a bit- | |
6733 | field. Thus, when computing the byte offset value for the start of the | |
6734 | "containing object" of a bit-field, we must deduce this information on | |
6735 | our own. This can be rather tricky to do in some cases. For example, | |
6736 | handling the following structure type definition when compiling for an | |
6737 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
6738 | can be very tricky: | |
6739 | ||
6740 | struct S { int field1; long long field2:31; }; | |
6741 | ||
6742 | Fortunately, there is a simple rule-of-thumb which can be | |
6743 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
6744 | 8 bytes for the structure shown above. It decides to do this based upon | |
6745 | one simple rule for bit-field allocation. Quite simply, GCC allocates | |
6746 | each "containing object" for each bit-field at the first (i.e. lowest | |
6747 | addressed) legitimate alignment boundary (based upon the required | |
6748 | minimum alignment for the declared type of the field) which it can | |
6749 | possibly use, subject to the condition that there is still enough | |
6750 | available space remaining in the containing object (when allocated at | |
6751 | the selected point) to fully accommodate all of the bits of the | |
6752 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
6753 | 8 bytes for each object of the structure type shown above. When looking | |
6754 | for a place to allocate the "containing object" for `field2', the | |
6755 | compiler simply tries to allocate a 64-bit "containing object" at each | |
6756 | successive 32-bit boundary (starting at zero) until it finds a place to | |
6757 | allocate that 64- bit field such that at least 31 contiguous (and | |
6758 | previously unallocated) bits remain within that selected 64 bit field. | |
6759 | (As it turns out, for the example above, the compiler finds that it is | |
6760 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
6761 | within the structure type.) Here we attempt to work backwards from the | |
6762 | limited set of facts we're given, and we try to deduce from those facts, | |
6763 | where GCC must have believed that the containing object started (within | |
6764 | the structure type). The value we deduce is then used (by the callers of | |
6765 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
6766 | for fields (both bit-fields and, in the case of DW_AT_location, regular | |
6767 | fields as well). */ | |
6768 | ||
6769 | /* Figure out the bit-distance from the start of the structure to the | |
6770 | "deepest" bit of the bit-field. */ | |
6771 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
6772 | ||
6773 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
6774 | lowest addressed bit of the containing object must be. */ | |
6775 | object_offset_in_bits | |
6776 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
6777 | ||
6778 | /* Compute the offset of the containing object in "alignment units". */ | |
6779 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
6780 | ||
6781 | /* Compute the offset of the containing object in bytes. */ | |
6782 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
6783 | ||
6784 | return object_offset_in_bytes; | |
6785 | } | |
a3f97cbb | 6786 | \f |
71dfc51f RK |
6787 | /* The following routines define various Dwarf attributes and any data |
6788 | associated with them. */ | |
a3f97cbb | 6789 | |
ef76d03b | 6790 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 6791 | |
ef76d03b | 6792 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
6793 | whole parameters. Note that the location attributes for struct fields are |
6794 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 6795 | |
a3f97cbb | 6796 | static void |
ef76d03b | 6797 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 6798 | dw_die_ref die; |
ef76d03b | 6799 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
6800 | register rtx rtl; |
6801 | { | |
a3f97cbb JW |
6802 | /* Handle a special case. If we are about to output a location descriptor |
6803 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 6804 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
6805 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
6806 | Currently, in some rare cases, variables can have DECL_RTL values which | |
6807 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
6808 | elsewhere in the compiler. We treat such cases as if the variable(s) in | |
6a7a9f01 | 6809 | question had been optimized out of existence. */ |
a3f97cbb | 6810 | |
6a7a9f01 JM |
6811 | if (is_pseudo_reg (rtl) |
6812 | || (GET_CODE (rtl) == MEM | |
4401bf24 JL |
6813 | && is_pseudo_reg (XEXP (rtl, 0))) |
6814 | || (GET_CODE (rtl) == CONCAT | |
6815 | && is_pseudo_reg (XEXP (rtl, 0)) | |
6816 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 6817 | return; |
a3f97cbb | 6818 | |
6a7a9f01 | 6819 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
6820 | } |
6821 | ||
6822 | /* Attach the specialized form of location attribute used for data | |
6823 | members of struct and union types. In the special case of a | |
6824 | FIELD_DECL node which represents a bit-field, the "offset" part | |
6825 | of this special location descriptor must indicate the distance | |
6826 | in bytes from the lowest-addressed byte of the containing struct | |
6827 | or union type to the lowest-addressed byte of the "containing | |
6828 | object" for the bit-field. (See the `field_byte_offset' function | |
6829 | above).. For any given bit-field, the "containing object" is a | |
6830 | hypothetical object (of some integral or enum type) within which | |
6831 | the given bit-field lives. The type of this hypothetical | |
6832 | "containing object" is always the same as the declared type of | |
6833 | the individual bit-field itself (for GCC anyway... the DWARF | |
6834 | spec doesn't actually mandate this). Note that it is the size | |
6835 | (in bytes) of the hypothetical "containing object" which will | |
6836 | be given in the DW_AT_byte_size attribute for this bit-field. | |
6837 | (See the `byte_size_attribute' function below.) It is also used | |
6838 | when calculating the value of the DW_AT_bit_offset attribute. | |
6839 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 6840 | |
a3f97cbb JW |
6841 | static void |
6842 | add_data_member_location_attribute (die, decl) | |
6843 | register dw_die_ref die; | |
6844 | register tree decl; | |
6845 | { | |
61b32c02 | 6846 | register unsigned long offset; |
a3f97cbb JW |
6847 | register dw_loc_descr_ref loc_descr; |
6848 | register enum dwarf_location_atom op; | |
6849 | ||
61b32c02 JM |
6850 | if (TREE_CODE (decl) == TREE_VEC) |
6851 | offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl)); | |
6852 | else | |
6853 | offset = field_byte_offset (decl); | |
6854 | ||
a3f97cbb JW |
6855 | /* The DWARF2 standard says that we should assume that the structure address |
6856 | is already on the stack, so we can specify a structure field address | |
6857 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 6858 | |
a3f97cbb JW |
6859 | #ifdef MIPS_DEBUGGING_INFO |
6860 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
6861 | correctly. It works only if we leave the offset on the stack. */ | |
6862 | op = DW_OP_constu; | |
6863 | #else | |
6864 | op = DW_OP_plus_uconst; | |
6865 | #endif | |
71dfc51f | 6866 | |
a3f97cbb JW |
6867 | loc_descr = new_loc_descr (op, offset, 0); |
6868 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
6869 | } | |
6870 | ||
6871 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
6872 | does not have a "location" either in memory or in a register. These | |
6873 | things can arise in GNU C when a constant is passed as an actual parameter | |
6874 | to an inlined function. They can also arise in C++ where declared | |
6875 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 6876 | |
a3f97cbb JW |
6877 | static void |
6878 | add_const_value_attribute (die, rtl) | |
6879 | register dw_die_ref die; | |
6880 | register rtx rtl; | |
6881 | { | |
6882 | switch (GET_CODE (rtl)) | |
6883 | { | |
6884 | case CONST_INT: | |
6885 | /* Note that a CONST_INT rtx could represent either an integer or a | |
6886 | floating-point constant. A CONST_INT is used whenever the constant | |
6887 | will fit into a single word. In all such cases, the original mode | |
6888 | of the constant value is wiped out, and the CONST_INT rtx is | |
6889 | assigned VOIDmode. */ | |
6890 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
6891 | break; | |
6892 | ||
6893 | case CONST_DOUBLE: | |
6894 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
6895 | floating-point constant. A CONST_DOUBLE is used whenever the | |
6896 | constant requires more than one word in order to be adequately | |
469ac993 JM |
6897 | represented. We output CONST_DOUBLEs as blocks. */ |
6898 | { | |
6899 | register enum machine_mode mode = GET_MODE (rtl); | |
6900 | ||
6901 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
6902 | { | |
71dfc51f RK |
6903 | register unsigned length = GET_MODE_SIZE (mode) / sizeof (long); |
6904 | long array[4]; | |
6905 | REAL_VALUE_TYPE rv; | |
469ac993 | 6906 | |
71dfc51f | 6907 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
6908 | switch (mode) |
6909 | { | |
6910 | case SFmode: | |
71dfc51f | 6911 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
6912 | break; |
6913 | ||
6914 | case DFmode: | |
71dfc51f | 6915 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
6916 | break; |
6917 | ||
6918 | case XFmode: | |
6919 | case TFmode: | |
71dfc51f | 6920 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
6921 | break; |
6922 | ||
6923 | default: | |
6924 | abort (); | |
6925 | } | |
6926 | ||
469ac993 JM |
6927 | add_AT_float (die, DW_AT_const_value, length, array); |
6928 | } | |
6929 | else | |
6930 | add_AT_long_long (die, DW_AT_const_value, | |
6931 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
6932 | } | |
a3f97cbb JW |
6933 | break; |
6934 | ||
6935 | case CONST_STRING: | |
6936 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
6937 | break; | |
6938 | ||
6939 | case SYMBOL_REF: | |
6940 | case LABEL_REF: | |
6941 | case CONST: | |
6942 | add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl)); | |
6943 | break; | |
6944 | ||
6945 | case PLUS: | |
6946 | /* In cases where an inlined instance of an inline function is passed | |
6947 | the address of an `auto' variable (which is local to the caller) we | |
6948 | can get a situation where the DECL_RTL of the artificial local | |
6949 | variable (for the inlining) which acts as a stand-in for the | |
6950 | corresponding formal parameter (of the inline function) will look | |
6951 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
6952 | exactly a compile-time constant expression, but it isn't the address | |
6953 | of the (artificial) local variable either. Rather, it represents the | |
6954 | *value* which the artificial local variable always has during its | |
6955 | lifetime. We currently have no way to represent such quasi-constant | |
6a7a9f01 | 6956 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
6957 | break; |
6958 | ||
6959 | default: | |
6960 | /* No other kinds of rtx should be possible here. */ | |
6961 | abort (); | |
6962 | } | |
6963 | ||
6964 | } | |
6965 | ||
6966 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
6967 | data attribute for a variable or a parameter. We generate the | |
6968 | DW_AT_const_value attribute only in those cases where the given variable | |
6969 | or parameter does not have a true "location" either in memory or in a | |
6970 | register. This can happen (for example) when a constant is passed as an | |
6971 | actual argument in a call to an inline function. (It's possible that | |
6972 | these things can crop up in other ways also.) Note that one type of | |
6973 | constant value which can be passed into an inlined function is a constant | |
6974 | pointer. This can happen for example if an actual argument in an inlined | |
6975 | function call evaluates to a compile-time constant address. */ | |
71dfc51f | 6976 | |
a3f97cbb JW |
6977 | static void |
6978 | add_location_or_const_value_attribute (die, decl) | |
6979 | register dw_die_ref die; | |
6980 | register tree decl; | |
6981 | { | |
6982 | register rtx rtl; | |
6983 | register tree declared_type; | |
6984 | register tree passed_type; | |
6985 | ||
6986 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f RK |
6987 | return; |
6988 | ||
6989 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
6990 | abort (); | |
6991 | ||
a3f97cbb JW |
6992 | /* Here we have to decide where we are going to say the parameter "lives" |
6993 | (as far as the debugger is concerned). We only have a couple of | |
6994 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 6995 | |
a3f97cbb | 6996 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 6997 | activation of the function. If optimization is enabled however, this |
a3f97cbb JW |
6998 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
6999 | that the parameter doesn't really live anywhere (as far as the code | |
7000 | generation parts of GCC are concerned) during most of the function's | |
7001 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
7002 | referenced within the function. |
7003 | ||
7004 | We could just generate a location descriptor here for all non-NULL | |
7005 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
7006 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
7007 | where DECL_RTL is NULL or is a pseudo-reg. | |
7008 | ||
7009 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
7010 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
7011 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
7012 | we can be sure that the parameter was passed using the same type as it is | |
7013 | declared to have within the function, and that its DECL_INCOMING_RTL | |
7014 | points us to a place where a value of that type is passed. | |
7015 | ||
7016 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
7017 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
7018 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
7019 | type which is *different* from the type of the parameter itself. Thus, | |
7020 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
7021 | such cases, the debugger would end up (for example) trying to fetch a | |
7022 | `float' from a place which actually contains the first part of a | |
7023 | `double'. That would lead to really incorrect and confusing | |
7024 | output at debug-time. | |
7025 | ||
7026 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
7027 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
7028 | are a couple of exceptions however. On little-endian machines we can | |
7029 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
7030 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
7031 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
7032 | when (on a little-endian machine) a non-prototyped function has a | |
7033 | parameter declared to be of type `short' or `char'. In such cases, | |
7034 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
7035 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
7036 | passed `int' value. If the debugger then uses that address to fetch | |
7037 | a `short' or a `char' (on a little-endian machine) the result will be | |
7038 | the correct data, so we allow for such exceptional cases below. | |
7039 | ||
7040 | Note that our goal here is to describe the place where the given formal | |
7041 | parameter lives during most of the function's activation (i.e. between | |
7042 | the end of the prologue and the start of the epilogue). We'll do that | |
7043 | as best as we can. Note however that if the given formal parameter is | |
7044 | modified sometime during the execution of the function, then a stack | |
7045 | backtrace (at debug-time) will show the function as having been | |
7046 | called with the *new* value rather than the value which was | |
7047 | originally passed in. This happens rarely enough that it is not | |
7048 | a major problem, but it *is* a problem, and I'd like to fix it. | |
7049 | ||
7050 | A future version of dwarf2out.c may generate two additional | |
7051 | attributes for any given DW_TAG_formal_parameter DIE which will | |
7052 | describe the "passed type" and the "passed location" for the | |
7053 | given formal parameter in addition to the attributes we now | |
7054 | generate to indicate the "declared type" and the "active | |
7055 | location" for each parameter. This additional set of attributes | |
7056 | could be used by debuggers for stack backtraces. Separately, note | |
7057 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
7058 | NULL also. This happens (for example) for inlined-instances of | |
7059 | inline function formal parameters which are never referenced. | |
7060 | This really shouldn't be happening. All PARM_DECL nodes should | |
7061 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
7062 | doesn't currently generate these values for inlined instances of | |
7063 | inline function parameters, so when we see such cases, we are | |
956d6950 | 7064 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
7065 | gets fixed). */ |
7066 | ||
7067 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
7068 | rtl = DECL_RTL (decl); | |
7069 | ||
7070 | if (TREE_CODE (decl) == PARM_DECL) | |
7071 | { | |
7072 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
7073 | { | |
7074 | declared_type = type_main_variant (TREE_TYPE (decl)); | |
7075 | passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 7076 | |
71dfc51f | 7077 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
7078 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
7079 | all* cases where (rtl == NULL_RTX) just below. */ | |
7080 | if (declared_type == passed_type) | |
71dfc51f RK |
7081 | rtl = DECL_INCOMING_RTL (decl); |
7082 | else if (! BYTES_BIG_ENDIAN | |
7083 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
7084 | && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) | |
7085 | rtl = DECL_INCOMING_RTL (decl); | |
a3f97cbb | 7086 | } |
5a904a61 JW |
7087 | |
7088 | /* If the parm was passed in registers, but lives on the stack, then | |
7089 | make a big endian correction if the mode of the type of the | |
7090 | parameter is not the same as the mode of the rtl. */ | |
7091 | /* ??? This is the same series of checks that are made in dbxout.c before | |
7092 | we reach the big endian correction code there. It isn't clear if all | |
7093 | of these checks are necessary here, but keeping them all is the safe | |
7094 | thing to do. */ | |
7095 | else if (GET_CODE (rtl) == MEM | |
7096 | && XEXP (rtl, 0) != const0_rtx | |
7097 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
7098 | /* Not passed in memory. */ | |
7099 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
7100 | /* Not passed by invisible reference. */ | |
7101 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
7102 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
7103 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
7104 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
7105 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
7106 | #endif | |
7107 | ) | |
7108 | /* Big endian correction check. */ | |
7109 | && BYTES_BIG_ENDIAN | |
7110 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
7111 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
7112 | < UNITS_PER_WORD)) | |
7113 | { | |
7114 | int offset = (UNITS_PER_WORD | |
7115 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
7116 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
7117 | plus_constant (XEXP (rtl, 0), offset)); | |
7118 | } | |
a3f97cbb | 7119 | } |
71dfc51f | 7120 | |
61b32c02 JM |
7121 | if (rtl == NULL_RTX) |
7122 | return; | |
7123 | ||
1914f5da | 7124 | rtl = eliminate_regs (rtl, 0, NULL_RTX); |
6a7a9f01 JM |
7125 | #ifdef LEAF_REG_REMAP |
7126 | if (leaf_function) | |
5f52dcfe | 7127 | leaf_renumber_regs_insn (rtl); |
6a7a9f01 JM |
7128 | #endif |
7129 | ||
a3f97cbb JW |
7130 | switch (GET_CODE (rtl)) |
7131 | { | |
e9a25f70 JL |
7132 | case ADDRESSOF: |
7133 | /* The address of a variable that was optimized away; don't emit | |
7134 | anything. */ | |
7135 | break; | |
7136 | ||
a3f97cbb JW |
7137 | case CONST_INT: |
7138 | case CONST_DOUBLE: | |
7139 | case CONST_STRING: | |
7140 | case SYMBOL_REF: | |
7141 | case LABEL_REF: | |
7142 | case CONST: | |
7143 | case PLUS: | |
7144 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
7145 | add_const_value_attribute (die, rtl); | |
7146 | break; | |
7147 | ||
7148 | case MEM: | |
7149 | case REG: | |
7150 | case SUBREG: | |
4401bf24 | 7151 | case CONCAT: |
ef76d03b | 7152 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
7153 | break; |
7154 | ||
7155 | default: | |
71dfc51f | 7156 | abort (); |
a3f97cbb JW |
7157 | } |
7158 | } | |
7159 | ||
7160 | /* Generate an DW_AT_name attribute given some string value to be included as | |
7161 | the value of the attribute. */ | |
71dfc51f RK |
7162 | |
7163 | static inline void | |
a3f97cbb JW |
7164 | add_name_attribute (die, name_string) |
7165 | register dw_die_ref die; | |
7166 | register char *name_string; | |
7167 | { | |
71dfc51f RK |
7168 | if (name_string != NULL && *name_string != 0) |
7169 | add_AT_string (die, DW_AT_name, name_string); | |
a3f97cbb JW |
7170 | } |
7171 | ||
7172 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 7173 | a representation for that bound. */ |
71dfc51f | 7174 | |
a3f97cbb JW |
7175 | static void |
7176 | add_bound_info (subrange_die, bound_attr, bound) | |
7177 | register dw_die_ref subrange_die; | |
7178 | register enum dwarf_attribute bound_attr; | |
7179 | register tree bound; | |
7180 | { | |
a3f97cbb | 7181 | register unsigned bound_value = 0; |
ef76d03b JW |
7182 | |
7183 | /* If this is an Ada unconstrained array type, then don't emit any debug | |
7184 | info because the array bounds are unknown. They are parameterized when | |
7185 | the type is instantiated. */ | |
7186 | if (contains_placeholder_p (bound)) | |
7187 | return; | |
7188 | ||
a3f97cbb JW |
7189 | switch (TREE_CODE (bound)) |
7190 | { | |
7191 | case ERROR_MARK: | |
7192 | return; | |
7193 | ||
7194 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
7195 | case INTEGER_CST: | |
7196 | bound_value = TREE_INT_CST_LOW (bound); | |
141719a8 JM |
7197 | if (bound_attr == DW_AT_lower_bound |
7198 | && ((is_c_family () && bound_value == 0) | |
7199 | || (is_fortran () && bound_value == 1))) | |
7200 | /* use the default */; | |
7201 | else | |
7202 | add_AT_unsigned (subrange_die, bound_attr, bound_value); | |
a3f97cbb JW |
7203 | break; |
7204 | ||
b1ccbc24 | 7205 | case CONVERT_EXPR: |
a3f97cbb | 7206 | case NOP_EXPR: |
b1ccbc24 RK |
7207 | case NON_LVALUE_EXPR: |
7208 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
7209 | break; | |
7210 | ||
a3f97cbb JW |
7211 | case SAVE_EXPR: |
7212 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
7213 | access the upper bound values may be bogus. If they refer to a |
7214 | register, they may only describe how to get at these values at the | |
7215 | points in the generated code right after they have just been | |
7216 | computed. Worse yet, in the typical case, the upper bound values | |
7217 | will not even *be* computed in the optimized code (though the | |
7218 | number of elements will), so these SAVE_EXPRs are entirely | |
7219 | bogus. In order to compensate for this fact, we check here to see | |
7220 | if optimization is enabled, and if so, we don't add an attribute | |
7221 | for the (unknown and unknowable) upper bound. This should not | |
7222 | cause too much trouble for existing (stupid?) debuggers because | |
7223 | they have to deal with empty upper bounds location descriptions | |
7224 | anyway in order to be able to deal with incomplete array types. | |
7225 | Of course an intelligent debugger (GDB?) should be able to | |
7226 | comprehend that a missing upper bound specification in a array | |
7227 | type used for a storage class `auto' local array variable | |
7228 | indicates that the upper bound is both unknown (at compile- time) | |
7229 | and unknowable (at run-time) due to optimization. | |
7230 | ||
7231 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
7232 | value there unless it was going to be used repeatedly in the | |
7233 | function, i.e. for cleanups. */ | |
7234 | if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM) | |
a3f97cbb | 7235 | { |
466446b0 JM |
7236 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
7237 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
7238 | register rtx loc = SAVE_EXPR_RTL (bound); |
7239 | ||
7240 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
7241 | it references an outer function's frame. */ | |
7242 | ||
7243 | if (GET_CODE (loc) == MEM) | |
7244 | { | |
7245 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
7246 | ||
7247 | if (XEXP (loc, 0) != new_addr) | |
7248 | loc = gen_rtx (MEM, GET_MODE (loc), new_addr); | |
7249 | } | |
7250 | ||
466446b0 JM |
7251 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
7252 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 7253 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 7254 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 7255 | } |
71dfc51f RK |
7256 | |
7257 | /* Else leave out the attribute. */ | |
a3f97cbb | 7258 | break; |
3f76745e | 7259 | |
ef76d03b JW |
7260 | case MAX_EXPR: |
7261 | case VAR_DECL: | |
c85f7c16 | 7262 | case COMPONENT_REF: |
ef76d03b JW |
7263 | /* ??? These types of bounds can be created by the Ada front end, |
7264 | and it isn't clear how to emit debug info for them. */ | |
7265 | break; | |
7266 | ||
3f76745e JM |
7267 | default: |
7268 | abort (); | |
a3f97cbb JW |
7269 | } |
7270 | } | |
7271 | ||
7272 | /* Note that the block of subscript information for an array type also | |
7273 | includes information about the element type of type given array type. */ | |
71dfc51f | 7274 | |
a3f97cbb JW |
7275 | static void |
7276 | add_subscript_info (type_die, type) | |
7277 | register dw_die_ref type_die; | |
7278 | register tree type; | |
7279 | { | |
081f5e7e | 7280 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 7281 | register unsigned dimension_number; |
081f5e7e | 7282 | #endif |
a3f97cbb JW |
7283 | register tree lower, upper; |
7284 | register dw_die_ref subrange_die; | |
7285 | ||
7286 | /* The GNU compilers represent multidimensional array types as sequences of | |
7287 | one dimensional array types whose element types are themselves array | |
7288 | types. Here we squish that down, so that each multidimensional array | |
7289 | type gets only one array_type DIE in the Dwarf debugging info. The draft | |
7290 | Dwarf specification say that we are allowed to do this kind of | |
7291 | compression in C (because there is no difference between an array or | |
7292 | arrays and a multidimensional array in C) but for other source languages | |
7293 | (e.g. Ada) we probably shouldn't do this. */ | |
71dfc51f | 7294 | |
a3f97cbb JW |
7295 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7296 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7297 | We work around this by disabling this feature. See also | |
7298 | gen_array_type_die. */ | |
7299 | #ifndef MIPS_DEBUGGING_INFO | |
7300 | for (dimension_number = 0; | |
7301 | TREE_CODE (type) == ARRAY_TYPE; | |
7302 | type = TREE_TYPE (type), dimension_number++) | |
7303 | { | |
7304 | #endif | |
7305 | register tree domain = TYPE_DOMAIN (type); | |
7306 | ||
7307 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
7308 | and (in GNU C only) variable bounds. Handle all three forms | |
7309 | here. */ | |
7310 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
7311 | if (domain) | |
7312 | { | |
7313 | /* We have an array type with specified bounds. */ | |
7314 | lower = TYPE_MIN_VALUE (domain); | |
7315 | upper = TYPE_MAX_VALUE (domain); | |
7316 | ||
a9d38797 JM |
7317 | /* define the index type. */ |
7318 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
7319 | { |
7320 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
7321 | TREE_TYPE field. We can't emit debug info for this | |
7322 | because it is an unnamed integral type. */ | |
7323 | if (TREE_CODE (domain) == INTEGER_TYPE | |
7324 | && TYPE_NAME (domain) == NULL_TREE | |
7325 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
7326 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
7327 | ; | |
7328 | else | |
7329 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
7330 | type_die); | |
7331 | } | |
a9d38797 | 7332 | |
e1ee5cdc RH |
7333 | /* ??? If upper is NULL, the array has unspecified length, |
7334 | but it does have a lower bound. This happens with Fortran | |
7335 | dimension arr(N:*) | |
7336 | Since the debugger is definitely going to need to know N | |
7337 | to produce useful results, go ahead and output the lower | |
7338 | bound solo, and hope the debugger can cope. */ | |
7339 | ||
141719a8 | 7340 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
7341 | if (upper) |
7342 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
7343 | } |
7344 | else | |
71dfc51f | 7345 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
7346 | spec does not say how to handle this; let's just leave out the |
7347 | bounds. */ | |
2d8b0f3a JL |
7348 | {;} |
7349 | ||
71dfc51f | 7350 | |
a3f97cbb JW |
7351 | #ifndef MIPS_DEBUGGING_INFO |
7352 | } | |
7353 | #endif | |
7354 | } | |
7355 | ||
7356 | static void | |
7357 | add_byte_size_attribute (die, tree_node) | |
7358 | dw_die_ref die; | |
7359 | register tree tree_node; | |
7360 | { | |
7361 | register unsigned size; | |
7362 | ||
7363 | switch (TREE_CODE (tree_node)) | |
7364 | { | |
7365 | case ERROR_MARK: | |
7366 | size = 0; | |
7367 | break; | |
7368 | case ENUMERAL_TYPE: | |
7369 | case RECORD_TYPE: | |
7370 | case UNION_TYPE: | |
7371 | case QUAL_UNION_TYPE: | |
7372 | size = int_size_in_bytes (tree_node); | |
7373 | break; | |
7374 | case FIELD_DECL: | |
7375 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
7376 | generally given as the number of bytes normally allocated for an | |
7377 | object of the *declared* type of the member itself. This is true | |
7378 | even for bit-fields. */ | |
7379 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
7380 | break; | |
7381 | default: | |
7382 | abort (); | |
7383 | } | |
7384 | ||
7385 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
7386 | indicates that the byte size of the entity in question is variable. We | |
7387 | have no good way of expressing this fact in Dwarf at the present time, | |
7388 | so just let the -1 pass on through. */ | |
7389 | ||
7390 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
7391 | } | |
7392 | ||
7393 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
7394 | which specifies the distance in bits from the highest order bit of the | |
7395 | "containing object" for the bit-field to the highest order bit of the | |
7396 | bit-field itself. | |
7397 | ||
b2932ae5 JM |
7398 | For any given bit-field, the "containing object" is a hypothetical |
7399 | object (of some integral or enum type) within which the given bit-field | |
7400 | lives. The type of this hypothetical "containing object" is always the | |
7401 | same as the declared type of the individual bit-field itself. The | |
7402 | determination of the exact location of the "containing object" for a | |
7403 | bit-field is rather complicated. It's handled by the | |
7404 | `field_byte_offset' function (above). | |
a3f97cbb JW |
7405 | |
7406 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
7407 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
7408 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
7409 | |
7410 | static inline void | |
a3f97cbb JW |
7411 | add_bit_offset_attribute (die, decl) |
7412 | register dw_die_ref die; | |
7413 | register tree decl; | |
7414 | { | |
7415 | register unsigned object_offset_in_bytes = field_byte_offset (decl); | |
7416 | register tree type = DECL_BIT_FIELD_TYPE (decl); | |
7417 | register tree bitpos_tree = DECL_FIELD_BITPOS (decl); | |
7418 | register unsigned bitpos_int; | |
7419 | register unsigned highest_order_object_bit_offset; | |
7420 | register unsigned highest_order_field_bit_offset; | |
7421 | register unsigned bit_offset; | |
7422 | ||
3a88cbd1 JL |
7423 | /* Must be a field and a bit field. */ |
7424 | if (!type | |
7425 | || TREE_CODE (decl) != FIELD_DECL) | |
7426 | abort (); | |
a3f97cbb JW |
7427 | |
7428 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
7429 | encounter such things, just return without generating any attribute | |
7430 | whatsoever. */ | |
7431 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
71dfc51f RK |
7432 | return; |
7433 | ||
a3f97cbb JW |
7434 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); |
7435 | ||
7436 | /* Note that the bit offset is always the distance (in bits) from the | |
7437 | highest-order bit of the "containing object" to the highest-order bit of | |
7438 | the bit-field itself. Since the "high-order end" of any object or field | |
7439 | is different on big-endian and little-endian machines, the computation | |
7440 | below must take account of these differences. */ | |
7441 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
7442 | highest_order_field_bit_offset = bitpos_int; | |
7443 | ||
71dfc51f | 7444 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb JW |
7445 | { |
7446 | highest_order_field_bit_offset | |
7447 | += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); | |
7448 | ||
7449 | highest_order_object_bit_offset += simple_type_size_in_bits (type); | |
7450 | } | |
71dfc51f RK |
7451 | |
7452 | bit_offset | |
7453 | = (! BYTES_BIG_ENDIAN | |
7454 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
7455 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
7456 | |
7457 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
7458 | } | |
7459 | ||
7460 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
7461 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
7462 | |
7463 | static inline void | |
a3f97cbb JW |
7464 | add_bit_size_attribute (die, decl) |
7465 | register dw_die_ref die; | |
7466 | register tree decl; | |
7467 | { | |
3a88cbd1 JL |
7468 | /* Must be a field and a bit field. */ |
7469 | if (TREE_CODE (decl) != FIELD_DECL | |
7470 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
7471 | abort (); | |
a3f97cbb JW |
7472 | add_AT_unsigned (die, DW_AT_bit_size, |
7473 | (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); | |
7474 | } | |
7475 | ||
88dad228 | 7476 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 7477 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
7478 | |
7479 | static inline void | |
a3f97cbb JW |
7480 | add_prototyped_attribute (die, func_type) |
7481 | register dw_die_ref die; | |
7482 | register tree func_type; | |
7483 | { | |
88dad228 JM |
7484 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
7485 | && TYPE_ARG_TYPES (func_type) != NULL) | |
7486 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
7487 | } |
7488 | ||
7489 | ||
7490 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found | |
7491 | by looking in either the type declaration or object declaration | |
7492 | equate table. */ | |
71dfc51f RK |
7493 | |
7494 | static inline void | |
a3f97cbb JW |
7495 | add_abstract_origin_attribute (die, origin) |
7496 | register dw_die_ref die; | |
7497 | register tree origin; | |
7498 | { | |
7499 | dw_die_ref origin_die = NULL; | |
7500 | if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd') | |
71dfc51f | 7501 | origin_die = lookup_decl_die (origin); |
a3f97cbb | 7502 | else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't') |
71dfc51f RK |
7503 | origin_die = lookup_type_die (origin); |
7504 | ||
a3f97cbb JW |
7505 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
7506 | } | |
7507 | ||
bdb669cb JM |
7508 | /* We do not currently support the pure_virtual attribute. */ |
7509 | ||
71dfc51f | 7510 | static inline void |
a3f97cbb JW |
7511 | add_pure_or_virtual_attribute (die, func_decl) |
7512 | register dw_die_ref die; | |
7513 | register tree func_decl; | |
7514 | { | |
a94dbf2c | 7515 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 7516 | { |
bdb669cb | 7517 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
71dfc51f RK |
7518 | add_AT_loc (die, DW_AT_vtable_elem_location, |
7519 | new_loc_descr (DW_OP_constu, | |
7520 | TREE_INT_CST_LOW (DECL_VINDEX (func_decl)), | |
7521 | 0)); | |
7522 | ||
a94dbf2c JM |
7523 | /* GNU extension: Record what type this method came from originally. */ |
7524 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
7525 | add_AT_die_ref (die, DW_AT_containing_type, | |
7526 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
7527 | } |
7528 | } | |
7529 | \f | |
b2932ae5 | 7530 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 7531 | |
b2932ae5 JM |
7532 | static void |
7533 | add_src_coords_attributes (die, decl) | |
7534 | register dw_die_ref die; | |
7535 | register tree decl; | |
7536 | { | |
7537 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 7538 | |
b2932ae5 JM |
7539 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
7540 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
7541 | } | |
7542 | ||
a3f97cbb JW |
7543 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
7544 | given decl, but only if it actually has a name. */ | |
71dfc51f | 7545 | |
a3f97cbb JW |
7546 | static void |
7547 | add_name_and_src_coords_attributes (die, decl) | |
7548 | register dw_die_ref die; | |
7549 | register tree decl; | |
7550 | { | |
61b32c02 | 7551 | register tree decl_name; |
71dfc51f | 7552 | |
a1d7ffe3 | 7553 | decl_name = DECL_NAME (decl); |
71dfc51f | 7554 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 7555 | { |
a1d7ffe3 | 7556 | add_name_attribute (die, dwarf2_name (decl, 0)); |
b2932ae5 | 7557 | add_src_coords_attributes (die, decl); |
a1d7ffe3 JM |
7558 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
7559 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) | |
7560 | add_AT_string (die, DW_AT_MIPS_linkage_name, | |
7561 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
7562 | } |
7563 | } | |
7564 | ||
7565 | /* Push a new declaration scope. */ | |
71dfc51f | 7566 | |
a3f97cbb JW |
7567 | static void |
7568 | push_decl_scope (scope) | |
7569 | tree scope; | |
7570 | { | |
e3e7774e JW |
7571 | tree containing_scope; |
7572 | int i; | |
7573 | ||
a3f97cbb JW |
7574 | /* Make room in the decl_scope_table, if necessary. */ |
7575 | if (decl_scope_table_allocated == decl_scope_depth) | |
7576 | { | |
7577 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 7578 | decl_scope_table |
e3e7774e JW |
7579 | = (decl_scope_node *) xrealloc (decl_scope_table, |
7580 | (decl_scope_table_allocated | |
7581 | * sizeof (decl_scope_node))); | |
a3f97cbb | 7582 | } |
71dfc51f | 7583 | |
e3e7774e JW |
7584 | decl_scope_table[decl_scope_depth].scope = scope; |
7585 | ||
7586 | /* Sometimes, while recursively emitting subtypes within a class type, | |
7587 | we end up recuring on a subtype at a higher level then the current | |
7588 | subtype. In such a case, we need to search the decl_scope_table to | |
7589 | find the parent of this subtype. */ | |
7590 | ||
5f2f160c | 7591 | if (AGGREGATE_TYPE_P (scope)) |
e3e7774e JW |
7592 | containing_scope = TYPE_CONTEXT (scope); |
7593 | else | |
7594 | containing_scope = NULL_TREE; | |
7595 | ||
7596 | /* The normal case. */ | |
7597 | if (decl_scope_depth == 0 | |
7598 | || containing_scope == NULL_TREE | |
2addbe1d JM |
7599 | /* Ignore namespaces for the moment. */ |
7600 | || TREE_CODE (containing_scope) == NAMESPACE_DECL | |
e3e7774e JW |
7601 | || containing_scope == decl_scope_table[decl_scope_depth - 1].scope) |
7602 | decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1; | |
7603 | else | |
7604 | { | |
7605 | /* We need to search for the containing_scope. */ | |
7606 | for (i = 0; i < decl_scope_depth; i++) | |
7607 | if (decl_scope_table[i].scope == containing_scope) | |
7608 | break; | |
7609 | ||
7610 | if (i == decl_scope_depth) | |
7611 | abort (); | |
7612 | else | |
7613 | decl_scope_table[decl_scope_depth].previous = i; | |
7614 | } | |
7615 | ||
7616 | decl_scope_depth++; | |
a3f97cbb JW |
7617 | } |
7618 | ||
2addbe1d | 7619 | /* Return the DIE for the scope that immediately contains this declaration. */ |
71dfc51f | 7620 | |
a3f97cbb | 7621 | static dw_die_ref |
ab72d377 JM |
7622 | scope_die_for (t, context_die) |
7623 | register tree t; | |
a3f97cbb JW |
7624 | register dw_die_ref context_die; |
7625 | { | |
7626 | register dw_die_ref scope_die = NULL; | |
7627 | register tree containing_scope; | |
e3e7774e | 7628 | register int i; |
a3f97cbb JW |
7629 | |
7630 | /* Walk back up the declaration tree looking for a place to define | |
7631 | this type. */ | |
ab72d377 JM |
7632 | if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') |
7633 | containing_scope = TYPE_CONTEXT (t); | |
a94dbf2c | 7634 | else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t)) |
ab72d377 JM |
7635 | containing_scope = decl_class_context (t); |
7636 | else | |
7637 | containing_scope = DECL_CONTEXT (t); | |
7638 | ||
2addbe1d JM |
7639 | /* Ignore namespaces for the moment. */ |
7640 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
7641 | containing_scope = NULL_TREE; | |
7642 | ||
5f2f160c JM |
7643 | /* Ignore function type "scopes" from the C frontend. They mean that |
7644 | a tagged type is local to a parmlist of a function declarator, but | |
7645 | that isn't useful to DWARF. */ | |
7646 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
7647 | containing_scope = NULL_TREE; | |
7648 | ||
ef76d03b JW |
7649 | /* Function-local tags and functions get stuck in limbo until they are |
7650 | fixed up by decls_for_scope. */ | |
7651 | if (context_die == NULL && containing_scope != NULL_TREE | |
7652 | && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t))) | |
7653 | return NULL; | |
7654 | ||
71dfc51f RK |
7655 | if (containing_scope == NULL_TREE) |
7656 | scope_die = comp_unit_die; | |
a3f97cbb JW |
7657 | else |
7658 | { | |
e3e7774e JW |
7659 | for (i = decl_scope_depth - 1, scope_die = context_die; |
7660 | i >= 0 && decl_scope_table[i].scope != containing_scope; | |
7661 | (scope_die = scope_die->die_parent, | |
7662 | i = decl_scope_table[i].previous)) | |
71dfc51f RK |
7663 | ; |
7664 | ||
0c84c618 JW |
7665 | /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor |
7666 | does it try to handle types defined by TYPE_DECLs. Such types | |
7667 | thus have an incorrect TYPE_CONTEXT, which points to the block | |
7668 | they were originally defined in, instead of the current block | |
7669 | created by function inlining. We try to detect that here and | |
7670 | work around it. */ | |
7671 | ||
7672 | if (i < 0 && scope_die == comp_unit_die | |
7673 | && TREE_CODE (containing_scope) == BLOCK | |
7674 | && is_tagged_type (t) | |
7675 | && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope) | |
7676 | == containing_scope)) | |
7677 | { | |
7678 | scope_die = context_die; | |
7679 | /* Since the checks below are no longer applicable. */ | |
7680 | i = 0; | |
7681 | } | |
7682 | ||
e3e7774e | 7683 | if (i < 0) |
a3f97cbb | 7684 | { |
6646d96c | 7685 | if (TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't') |
3a88cbd1 JL |
7686 | abort (); |
7687 | if (debug_info_level > DINFO_LEVEL_TERSE | |
7688 | && !TREE_ASM_WRITTEN (containing_scope)) | |
7689 | abort (); | |
6646d96c JM |
7690 | |
7691 | /* If none of the current dies are suitable, we get file scope. */ | |
7692 | scope_die = comp_unit_die; | |
a3f97cbb JW |
7693 | } |
7694 | } | |
71dfc51f | 7695 | |
a3f97cbb JW |
7696 | return scope_die; |
7697 | } | |
7698 | ||
7699 | /* Pop a declaration scope. */ | |
71dfc51f | 7700 | static inline void |
a3f97cbb JW |
7701 | pop_decl_scope () |
7702 | { | |
3a88cbd1 JL |
7703 | if (decl_scope_depth <= 0) |
7704 | abort (); | |
a3f97cbb JW |
7705 | --decl_scope_depth; |
7706 | } | |
7707 | ||
7708 | /* Many forms of DIEs require a "type description" attribute. This | |
7709 | routine locates the proper "type descriptor" die for the type given | |
7710 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 7711 | |
a3f97cbb JW |
7712 | static void |
7713 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
7714 | register dw_die_ref object_die; | |
7715 | register tree type; | |
7716 | register int decl_const; | |
7717 | register int decl_volatile; | |
7718 | register dw_die_ref context_die; | |
7719 | { | |
7720 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
7721 | register dw_die_ref type_die = NULL; |
7722 | ||
ef76d03b JW |
7723 | /* ??? If this type is an unnamed subrange type of an integral or |
7724 | floating-point type, use the inner type. This is because we have no | |
7725 | support for unnamed types in base_type_die. This can happen if this is | |
7726 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
7727 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
7728 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
7729 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
7730 | ||
a3f97cbb | 7731 | if (code == ERROR_MARK) |
b1ccbc24 | 7732 | return; |
a3f97cbb JW |
7733 | |
7734 | /* Handle a special case. For functions whose return type is void, we | |
7735 | generate *no* type attribute. (Note that no object may have type | |
7736 | `void', so this only applies to function return types). */ | |
7737 | if (code == VOID_TYPE) | |
b1ccbc24 | 7738 | return; |
a3f97cbb | 7739 | |
a3f97cbb JW |
7740 | type_die = modified_type_die (type, |
7741 | decl_const || TYPE_READONLY (type), | |
7742 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 7743 | context_die); |
a3f97cbb | 7744 | if (type_die != NULL) |
71dfc51f | 7745 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
7746 | } |
7747 | ||
7748 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
7749 | a pointer to the (string) tag name for the given type, or zero if the type | |
7750 | was declared without a tag. */ | |
71dfc51f | 7751 | |
a3f97cbb JW |
7752 | static char * |
7753 | type_tag (type) | |
7754 | register tree type; | |
7755 | { | |
7756 | register char *name = 0; | |
7757 | ||
7758 | if (TYPE_NAME (type) != 0) | |
7759 | { | |
7760 | register tree t = 0; | |
7761 | ||
7762 | /* Find the IDENTIFIER_NODE for the type name. */ | |
7763 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
7764 | t = TYPE_NAME (type); | |
bdb669cb | 7765 | |
a3f97cbb JW |
7766 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
7767 | a TYPE_DECL node, regardless of whether or not a `typedef' was | |
bdb669cb | 7768 | involved. */ |
a94dbf2c JM |
7769 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
7770 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 7771 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 7772 | |
a3f97cbb JW |
7773 | /* Now get the name as a string, or invent one. */ |
7774 | if (t != 0) | |
a94dbf2c | 7775 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 7776 | } |
71dfc51f | 7777 | |
a3f97cbb JW |
7778 | return (name == 0 || *name == '\0') ? 0 : name; |
7779 | } | |
7780 | ||
7781 | /* Return the type associated with a data member, make a special check | |
7782 | for bit field types. */ | |
71dfc51f RK |
7783 | |
7784 | static inline tree | |
a3f97cbb JW |
7785 | member_declared_type (member) |
7786 | register tree member; | |
7787 | { | |
71dfc51f RK |
7788 | return (DECL_BIT_FIELD_TYPE (member) |
7789 | ? DECL_BIT_FIELD_TYPE (member) | |
7790 | : TREE_TYPE (member)); | |
a3f97cbb JW |
7791 | } |
7792 | ||
d291dd49 | 7793 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 7794 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 7795 | |
487a6e06 | 7796 | #if 0 |
a3f97cbb | 7797 | static char * |
d291dd49 | 7798 | decl_start_label (decl) |
a3f97cbb JW |
7799 | register tree decl; |
7800 | { | |
7801 | rtx x; | |
7802 | char *fnname; | |
7803 | x = DECL_RTL (decl); | |
7804 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
7805 | abort (); |
7806 | ||
a3f97cbb JW |
7807 | x = XEXP (x, 0); |
7808 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
7809 | abort (); |
7810 | ||
a3f97cbb JW |
7811 | fnname = XSTR (x, 0); |
7812 | return fnname; | |
7813 | } | |
487a6e06 | 7814 | #endif |
a3f97cbb | 7815 | \f |
956d6950 | 7816 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 7817 | the compilation unit. Debugging information is collected by walking |
88dad228 | 7818 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
7819 | |
7820 | static void | |
7821 | gen_array_type_die (type, context_die) | |
7822 | register tree type; | |
7823 | register dw_die_ref context_die; | |
7824 | { | |
ab72d377 | 7825 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 7826 | register dw_die_ref array_die; |
a3f97cbb | 7827 | register tree element_type; |
bdb669cb | 7828 | |
a9d38797 JM |
7829 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
7830 | the inner array type comes before the outer array type. Thus we must | |
7831 | call gen_type_die before we call new_die. See below also. */ | |
7832 | #ifdef MIPS_DEBUGGING_INFO | |
7833 | gen_type_die (TREE_TYPE (type), context_die); | |
7834 | #endif | |
7835 | ||
7836 | array_die = new_die (DW_TAG_array_type, scope_die); | |
7837 | ||
a3f97cbb JW |
7838 | #if 0 |
7839 | /* We default the array ordering. SDB will probably do | |
7840 | the right things even if DW_AT_ordering is not present. It's not even | |
7841 | an issue until we start to get into multidimensional arrays anyway. If | |
7842 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
7843 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
7844 | and when we find out that we need to put these in, we will only do so | |
7845 | for multidimensional arrays. */ | |
7846 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
7847 | #endif | |
7848 | ||
a9d38797 | 7849 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
7850 | /* The SGI compilers handle arrays of unknown bound by setting |
7851 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
7852 | if (! TYPE_DOMAIN (type)) |
7853 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
7854 | else | |
7855 | #endif | |
7856 | add_subscript_info (array_die, type); | |
a3f97cbb JW |
7857 | |
7858 | equate_type_number_to_die (type, array_die); | |
7859 | ||
7860 | /* Add representation of the type of the elements of this array type. */ | |
7861 | element_type = TREE_TYPE (type); | |
71dfc51f | 7862 | |
a3f97cbb JW |
7863 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7864 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7865 | We work around this by disabling this feature. See also | |
7866 | add_subscript_info. */ | |
7867 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
7868 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
7869 | element_type = TREE_TYPE (element_type); | |
7870 | ||
a3f97cbb | 7871 | gen_type_die (element_type, context_die); |
a9d38797 | 7872 | #endif |
a3f97cbb JW |
7873 | |
7874 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
7875 | } | |
7876 | ||
7877 | static void | |
7878 | gen_set_type_die (type, context_die) | |
7879 | register tree type; | |
7880 | register dw_die_ref context_die; | |
7881 | { | |
71dfc51f RK |
7882 | register dw_die_ref type_die |
7883 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
7884 | ||
a3f97cbb | 7885 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
7886 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
7887 | } | |
7888 | ||
d6f4ec51 | 7889 | #if 0 |
a3f97cbb JW |
7890 | static void |
7891 | gen_entry_point_die (decl, context_die) | |
7892 | register tree decl; | |
7893 | register dw_die_ref context_die; | |
7894 | { | |
7895 | register tree origin = decl_ultimate_origin (decl); | |
7896 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
7897 | if (origin != NULL) | |
71dfc51f | 7898 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
7899 | else |
7900 | { | |
7901 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
7902 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
7903 | 0, 0, context_die); | |
7904 | } | |
71dfc51f | 7905 | |
a3f97cbb | 7906 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 7907 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 7908 | else |
71dfc51f | 7909 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 7910 | } |
d6f4ec51 | 7911 | #endif |
a3f97cbb | 7912 | |
a94dbf2c JM |
7913 | /* Remember a type in the pending_types_list. */ |
7914 | ||
7915 | static void | |
7916 | pend_type (type) | |
7917 | register tree type; | |
7918 | { | |
7919 | if (pending_types == pending_types_allocated) | |
7920 | { | |
7921 | pending_types_allocated += PENDING_TYPES_INCREMENT; | |
7922 | pending_types_list | |
7923 | = (tree *) xrealloc (pending_types_list, | |
7924 | sizeof (tree) * pending_types_allocated); | |
7925 | } | |
71dfc51f | 7926 | |
a94dbf2c JM |
7927 | pending_types_list[pending_types++] = type; |
7928 | } | |
7929 | ||
7930 | /* Output any pending types (from the pending_types list) which we can output | |
7931 | now (taking into account the scope that we are working on now). | |
7932 | ||
7933 | For each type output, remove the given type from the pending_types_list | |
7934 | *before* we try to output it. */ | |
7935 | ||
7936 | static void | |
7937 | output_pending_types_for_scope (context_die) | |
7938 | register dw_die_ref context_die; | |
7939 | { | |
7940 | register tree type; | |
7941 | ||
7942 | while (pending_types) | |
7943 | { | |
7944 | --pending_types; | |
7945 | type = pending_types_list[pending_types]; | |
7946 | gen_type_die (type, context_die); | |
3a88cbd1 JL |
7947 | if (!TREE_ASM_WRITTEN (type)) |
7948 | abort (); | |
a94dbf2c JM |
7949 | } |
7950 | } | |
7951 | ||
a3f97cbb | 7952 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 7953 | |
a3f97cbb JW |
7954 | static void |
7955 | gen_inlined_enumeration_type_die (type, context_die) | |
7956 | register tree type; | |
7957 | register dw_die_ref context_die; | |
7958 | { | |
71dfc51f RK |
7959 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
7960 | scope_die_for (type, context_die)); | |
7961 | ||
3a88cbd1 JL |
7962 | if (!TREE_ASM_WRITTEN (type)) |
7963 | abort (); | |
a3f97cbb JW |
7964 | add_abstract_origin_attribute (type_die, type); |
7965 | } | |
7966 | ||
7967 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 7968 | |
a3f97cbb JW |
7969 | static void |
7970 | gen_inlined_structure_type_die (type, context_die) | |
7971 | register tree type; | |
7972 | register dw_die_ref context_die; | |
7973 | { | |
71dfc51f RK |
7974 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, |
7975 | scope_die_for (type, context_die)); | |
7976 | ||
3a88cbd1 JL |
7977 | if (!TREE_ASM_WRITTEN (type)) |
7978 | abort (); | |
a3f97cbb JW |
7979 | add_abstract_origin_attribute (type_die, type); |
7980 | } | |
7981 | ||
7982 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 7983 | |
a3f97cbb JW |
7984 | static void |
7985 | gen_inlined_union_type_die (type, context_die) | |
7986 | register tree type; | |
7987 | register dw_die_ref context_die; | |
7988 | { | |
71dfc51f RK |
7989 | register dw_die_ref type_die = new_die (DW_TAG_union_type, |
7990 | scope_die_for (type, context_die)); | |
7991 | ||
3a88cbd1 JL |
7992 | if (!TREE_ASM_WRITTEN (type)) |
7993 | abort (); | |
a3f97cbb JW |
7994 | add_abstract_origin_attribute (type_die, type); |
7995 | } | |
7996 | ||
7997 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
7998 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
7999 | enumerated type name/value is listed as a child of the enumerated type |
8000 | DIE. */ | |
71dfc51f | 8001 | |
a3f97cbb | 8002 | static void |
273dbe67 | 8003 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 8004 | register tree type; |
a3f97cbb JW |
8005 | register dw_die_ref context_die; |
8006 | { | |
273dbe67 JM |
8007 | register dw_die_ref type_die = lookup_type_die (type); |
8008 | ||
a3f97cbb JW |
8009 | if (type_die == NULL) |
8010 | { | |
8011 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 8012 | scope_die_for (type, context_die)); |
a3f97cbb JW |
8013 | equate_type_number_to_die (type, type_die); |
8014 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 8015 | } |
273dbe67 JM |
8016 | else if (! TYPE_SIZE (type)) |
8017 | return; | |
8018 | else | |
8019 | remove_AT (type_die, DW_AT_declaration); | |
8020 | ||
8021 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
8022 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
8023 | attribute or the DW_AT_element_list attribute. */ | |
8024 | if (TYPE_SIZE (type)) | |
a3f97cbb | 8025 | { |
273dbe67 | 8026 | register tree link; |
71dfc51f | 8027 | |
a082c85a | 8028 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 8029 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 8030 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 8031 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 8032 | |
ef76d03b JW |
8033 | /* If the first reference to this type was as the return type of an |
8034 | inline function, then it may not have a parent. Fix this now. */ | |
8035 | if (type_die->die_parent == NULL) | |
8036 | add_child_die (scope_die_for (type, context_die), type_die); | |
8037 | ||
273dbe67 JM |
8038 | for (link = TYPE_FIELDS (type); |
8039 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 8040 | { |
273dbe67 | 8041 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 8042 | |
273dbe67 JM |
8043 | add_name_attribute (enum_die, |
8044 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
8045 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
a3f97cbb | 8046 | (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); |
a3f97cbb JW |
8047 | } |
8048 | } | |
273dbe67 JM |
8049 | else |
8050 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
8051 | } |
8052 | ||
8053 | ||
8054 | /* Generate a DIE to represent either a real live formal parameter decl or to | |
8055 | represent just the type of some formal parameter position in some function | |
8056 | type. | |
71dfc51f | 8057 | |
a3f97cbb JW |
8058 | Note that this routine is a bit unusual because its argument may be a |
8059 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
8060 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
8061 | node. If it's the former then this function is being called to output a | |
8062 | DIE to represent a formal parameter object (or some inlining thereof). If | |
8063 | it's the latter, then this function is only being called to output a | |
8064 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
8065 | argument type of some subprogram type. */ | |
71dfc51f | 8066 | |
a94dbf2c | 8067 | static dw_die_ref |
a3f97cbb JW |
8068 | gen_formal_parameter_die (node, context_die) |
8069 | register tree node; | |
8070 | register dw_die_ref context_die; | |
8071 | { | |
71dfc51f RK |
8072 | register dw_die_ref parm_die |
8073 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 8074 | register tree origin; |
71dfc51f | 8075 | |
a3f97cbb JW |
8076 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
8077 | { | |
a3f97cbb JW |
8078 | case 'd': |
8079 | origin = decl_ultimate_origin (node); | |
8080 | if (origin != NULL) | |
a94dbf2c | 8081 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
8082 | else |
8083 | { | |
8084 | add_name_and_src_coords_attributes (parm_die, node); | |
8085 | add_type_attribute (parm_die, TREE_TYPE (node), | |
8086 | TREE_READONLY (node), | |
8087 | TREE_THIS_VOLATILE (node), | |
8088 | context_die); | |
bdb669cb JM |
8089 | if (DECL_ARTIFICIAL (node)) |
8090 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 8091 | } |
71dfc51f | 8092 | |
141719a8 JM |
8093 | equate_decl_number_to_die (node, parm_die); |
8094 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 8095 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 8096 | |
a3f97cbb JW |
8097 | break; |
8098 | ||
a3f97cbb | 8099 | case 't': |
71dfc51f | 8100 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
8101 | add_type_attribute (parm_die, node, 0, 0, context_die); |
8102 | break; | |
8103 | ||
a3f97cbb JW |
8104 | default: |
8105 | abort (); | |
8106 | } | |
71dfc51f | 8107 | |
a94dbf2c | 8108 | return parm_die; |
a3f97cbb JW |
8109 | } |
8110 | ||
8111 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
8112 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 8113 | |
a3f97cbb JW |
8114 | static void |
8115 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
8116 | register tree decl_or_type; | |
8117 | register dw_die_ref context_die; | |
8118 | { | |
487a6e06 | 8119 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
8120 | } |
8121 | ||
8122 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
8123 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
8124 | parameters as specified in some function type specification (except for | |
8125 | those which appear as part of a function *definition*). | |
71dfc51f RK |
8126 | |
8127 | Note we must be careful here to output all of the parameter DIEs before* | |
a3f97cbb JW |
8128 | we output any DIEs needed to represent the types of the formal parameters. |
8129 | This keeps svr4 SDB happy because it (incorrectly) thinks that the first | |
8130 | non-parameter DIE it sees ends the formal parameter list. */ | |
71dfc51f | 8131 | |
a3f97cbb JW |
8132 | static void |
8133 | gen_formal_types_die (function_or_method_type, context_die) | |
8134 | register tree function_or_method_type; | |
8135 | register dw_die_ref context_die; | |
8136 | { | |
8137 | register tree link; | |
8138 | register tree formal_type = NULL; | |
8139 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
8140 | ||
bdb669cb | 8141 | #if 0 |
a3f97cbb JW |
8142 | /* In the case where we are generating a formal types list for a C++ |
8143 | non-static member function type, skip over the first thing on the | |
8144 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
8145 | `this pointer'. The debugger should be able to figure out (without | |
8146 | being explicitly told) that this non-static member function type takes a | |
8147 | `this pointer' and should be able to figure what the type of that hidden | |
8148 | parameter is from the DW_AT_member attribute of the parent | |
8149 | DW_TAG_subroutine_type DIE. */ | |
8150 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
8151 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 8152 | #endif |
a3f97cbb JW |
8153 | |
8154 | /* Make our first pass over the list of formal parameter types and output a | |
8155 | DW_TAG_formal_parameter DIE for each one. */ | |
8156 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
8157 | { | |
a94dbf2c JM |
8158 | register dw_die_ref parm_die; |
8159 | ||
a3f97cbb JW |
8160 | formal_type = TREE_VALUE (link); |
8161 | if (formal_type == void_type_node) | |
8162 | break; | |
8163 | ||
8164 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c JM |
8165 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
8166 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE | |
8167 | && link == first_parm_type) | |
8168 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
8169 | } |
8170 | ||
8171 | /* If this function type has an ellipsis, add a | |
8172 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
8173 | if (formal_type != void_type_node) | |
8174 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
8175 | ||
8176 | /* Make our second (and final) pass over the list of formal parameter types | |
8177 | and output DIEs to represent those types (as necessary). */ | |
8178 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
8179 | link; | |
8180 | link = TREE_CHAIN (link)) | |
8181 | { | |
8182 | formal_type = TREE_VALUE (link); | |
8183 | if (formal_type == void_type_node) | |
8184 | break; | |
8185 | ||
b50c02f9 | 8186 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
8187 | } |
8188 | } | |
8189 | ||
8190 | /* Generate a DIE to represent a declared function (either file-scope or | |
8191 | block-local). */ | |
71dfc51f | 8192 | |
a3f97cbb JW |
8193 | static void |
8194 | gen_subprogram_die (decl, context_die) | |
8195 | register tree decl; | |
8196 | register dw_die_ref context_die; | |
8197 | { | |
8198 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
8199 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 8200 | register dw_die_ref subr_die; |
b1ccbc24 | 8201 | register rtx fp_reg; |
a3f97cbb JW |
8202 | register tree fn_arg_types; |
8203 | register tree outer_scope; | |
a94dbf2c | 8204 | register dw_die_ref old_die = lookup_decl_die (decl); |
9c6cd30e JM |
8205 | register int declaration |
8206 | = (current_function_decl != decl | |
8207 | || (context_die | |
8208 | && (context_die->die_tag == DW_TAG_structure_type | |
8209 | || context_die->die_tag == DW_TAG_union_type))); | |
a3f97cbb | 8210 | |
a3f97cbb JW |
8211 | if (origin != NULL) |
8212 | { | |
4b674448 | 8213 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
8214 | add_abstract_origin_attribute (subr_die, origin); |
8215 | } | |
4401bf24 JL |
8216 | else if (old_die && DECL_ABSTRACT (decl) |
8217 | && get_AT_unsigned (old_die, DW_AT_inline)) | |
8218 | { | |
8219 | /* This must be a redefinition of an extern inline function. | |
8220 | We can just reuse the old die here. */ | |
8221 | subr_die = old_die; | |
8222 | ||
8223 | /* Clear out the inlined attribute and parm types. */ | |
8224 | remove_AT (subr_die, DW_AT_inline); | |
8225 | remove_children (subr_die); | |
8226 | } | |
bdb669cb JM |
8227 | else if (old_die) |
8228 | { | |
4b674448 JM |
8229 | register unsigned file_index |
8230 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
a94dbf2c | 8231 | |
3a88cbd1 | 8232 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) |
b75ab88b NC |
8233 | { |
8234 | /* ??? This can happen if there is a bug in the program, for | |
8235 | instance, if it has duplicate function definitions. Ideally, | |
8236 | we should detect this case and ignore it. For now, if we have | |
8237 | already reported an error, any error at all, then assume that | |
8238 | we got here because of a input error, not a dwarf2 bug. */ | |
8239 | extern int errorcount; | |
8240 | if (errorcount) | |
8241 | return; | |
8242 | abort (); | |
8243 | } | |
4b674448 JM |
8244 | |
8245 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
8246 | maybe use the old DIE. We always want the DIE for this function |
8247 | that has the *_pc attributes to be under comp_unit_die so the | |
8248 | debugger can find it. For inlines, that is the concrete instance, | |
8249 | so we can use the old DIE here. For non-inline methods, we want a | |
8250 | specification DIE at toplevel, so we need a new DIE. For local | |
8251 | class methods, this does not apply. */ | |
8252 | if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die | |
8253 | || context_die == NULL) | |
8254 | && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
4b674448 JM |
8255 | && (get_AT_unsigned (old_die, DW_AT_decl_line) |
8256 | == DECL_SOURCE_LINE (decl))) | |
bdb669cb | 8257 | { |
4b674448 JM |
8258 | subr_die = old_die; |
8259 | ||
8260 | /* Clear out the declaration attribute and the parm types. */ | |
8261 | remove_AT (subr_die, DW_AT_declaration); | |
8262 | remove_children (subr_die); | |
8263 | } | |
8264 | else | |
8265 | { | |
8266 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
8267 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
8268 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8269 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
8270 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
8271 | != DECL_SOURCE_LINE (decl)) | |
8272 | add_AT_unsigned | |
8273 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8274 | } | |
8275 | } | |
a3f97cbb JW |
8276 | else |
8277 | { | |
4edb7b60 JM |
8278 | register dw_die_ref scope_die; |
8279 | ||
8280 | if (DECL_CONTEXT (decl)) | |
8281 | scope_die = scope_die_for (decl, context_die); | |
8282 | else | |
8283 | /* Don't put block extern declarations under comp_unit_die. */ | |
8284 | scope_die = context_die; | |
8285 | ||
8286 | subr_die = new_die (DW_TAG_subprogram, scope_die); | |
8287 | ||
273dbe67 JM |
8288 | if (TREE_PUBLIC (decl)) |
8289 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 8290 | |
a3f97cbb | 8291 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
8292 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8293 | { | |
8294 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 8295 | |
4927276d JM |
8296 | add_prototyped_attribute (subr_die, type); |
8297 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
8298 | } | |
71dfc51f | 8299 | |
a3f97cbb | 8300 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
8301 | if (DECL_ARTIFICIAL (decl)) |
8302 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
8303 | if (TREE_PROTECTED (decl)) |
8304 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
8305 | else if (TREE_PRIVATE (decl)) | |
8306 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8307 | } |
4edb7b60 | 8308 | |
a94dbf2c JM |
8309 | if (declaration) |
8310 | { | |
8311 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
8312 | ||
8313 | /* The first time we see a member function, it is in the context of | |
8314 | the class to which it belongs. We make sure of this by emitting | |
8315 | the class first. The next time is the definition, which is | |
8316 | handled above. The two may come from the same source text. */ | |
f6c74b02 | 8317 | if (DECL_CONTEXT (decl)) |
a94dbf2c JM |
8318 | equate_decl_number_to_die (decl, subr_die); |
8319 | } | |
8320 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 8321 | { |
4401bf24 JL |
8322 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions, |
8323 | but not for extern inline functions. We can't get this completely | |
8324 | correct because information about whether the function was declared | |
8325 | inline is not saved anywhere. */ | |
61b32c02 JM |
8326 | if (DECL_DEFER_OUTPUT (decl)) |
8327 | { | |
8328 | if (DECL_INLINE (decl)) | |
8329 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); | |
8330 | else | |
8331 | add_AT_unsigned (subr_die, DW_AT_inline, | |
8332 | DW_INL_declared_not_inlined); | |
8333 | } | |
8334 | else if (DECL_INLINE (decl)) | |
8335 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); | |
8336 | else | |
8337 | abort (); | |
8338 | ||
a3f97cbb JW |
8339 | equate_decl_number_to_die (decl, subr_die); |
8340 | } | |
8341 | else if (!DECL_EXTERNAL (decl)) | |
8342 | { | |
71dfc51f | 8343 | if (origin == NULL_TREE) |
ba7b35df | 8344 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 8345 | |
5c90448c JM |
8346 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
8347 | current_funcdef_number); | |
7d4440be | 8348 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
8349 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
8350 | current_funcdef_number); | |
a3f97cbb JW |
8351 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
8352 | ||
d291dd49 JM |
8353 | add_pubname (decl, subr_die); |
8354 | add_arange (decl, subr_die); | |
8355 | ||
a3f97cbb | 8356 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
8357 | /* Add a reference to the FDE for this routine. */ |
8358 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
8359 | #endif | |
8360 | ||
810429b7 JM |
8361 | /* Define the "frame base" location for this routine. We use the |
8362 | frame pointer or stack pointer registers, since the RTL for local | |
8363 | variables is relative to one of them. */ | |
b1ccbc24 RK |
8364 | fp_reg |
8365 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
8366 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 8367 | |
ef76d03b JW |
8368 | #if 0 |
8369 | /* ??? This fails for nested inline functions, because context_display | |
8370 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 8371 | if (current_function_needs_context) |
ef76d03b JW |
8372 | add_AT_location_description (subr_die, DW_AT_static_link, |
8373 | lookup_static_chain (decl)); | |
8374 | #endif | |
a3f97cbb JW |
8375 | } |
8376 | ||
8377 | /* Now output descriptions of the arguments for this function. This gets | |
8378 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list | |
8379 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing | |
8380 | `...' at the end of the formal parameter list. In order to find out if | |
8381 | there was a trailing ellipsis or not, we must instead look at the type | |
8382 | associated with the FUNCTION_DECL. This will be a node of type | |
8383 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
8384 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be | |
8385 | an ellipsis at the end. */ | |
ab72d377 | 8386 | push_decl_scope (decl); |
71dfc51f | 8387 | |
a3f97cbb JW |
8388 | /* In the case where we are describing a mere function declaration, all we |
8389 | need to do here (and all we *can* do here) is to describe the *types* of | |
8390 | its formal parameters. */ | |
4927276d | 8391 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 8392 | ; |
4edb7b60 JM |
8393 | else if (declaration) |
8394 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
a3f97cbb JW |
8395 | else |
8396 | { | |
8397 | /* Generate DIEs to represent all known formal parameters */ | |
8398 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
8399 | register tree parm; | |
8400 | ||
8401 | /* When generating DIEs, generate the unspecified_parameters DIE | |
8402 | instead if we come across the arg "__builtin_va_alist" */ | |
8403 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
8404 | if (TREE_CODE (parm) == PARM_DECL) |
8405 | { | |
db3cf6fb MS |
8406 | if (DECL_NAME (parm) |
8407 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
8408 | "__builtin_va_alist")) | |
71dfc51f RK |
8409 | gen_unspecified_parameters_die (parm, subr_die); |
8410 | else | |
8411 | gen_decl_die (parm, subr_die); | |
8412 | } | |
a3f97cbb JW |
8413 | |
8414 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
8415 | There are 2 more cases to do this for: 1) the ansi ... declaration - | |
8416 | this is detectable when the end of the arg list is not a | |
8417 | void_type_node 2) an unprototyped function declaration (not a | |
8418 | definition). This just means that we have no info about the | |
8419 | parameters at all. */ | |
8420 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 8421 | if (fn_arg_types != NULL) |
a3f97cbb JW |
8422 | { |
8423 | /* this is the prototyped case, check for ... */ | |
8424 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 8425 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 8426 | } |
71dfc51f RK |
8427 | else if (DECL_INITIAL (decl) == NULL_TREE) |
8428 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
8429 | } |
8430 | ||
8431 | /* Output Dwarf info for all of the stuff within the body of the function | |
8432 | (if it has one - it may be just a declaration). */ | |
8433 | outer_scope = DECL_INITIAL (decl); | |
8434 | ||
d7248bff JM |
8435 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
8436 | node created to represent a function. This outermost BLOCK actually | |
8437 | represents the outermost binding contour for the function, i.e. the | |
8438 | contour in which the function's formal parameters and labels get | |
8439 | declared. Curiously, it appears that the front end doesn't actually | |
8440 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
8441 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
8442 | list for the function instead.) The BLOCK_VARS list for the | |
8443 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
8444 | the function however, and we output DWARF info for those in | |
8445 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
8446 | node representing the function's outermost pair of curly braces, and | |
8447 | any blocks used for the base and member initializers of a C++ | |
8448 | constructor function. */ | |
4edb7b60 | 8449 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
8450 | { |
8451 | current_function_has_inlines = 0; | |
8452 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 8453 | |
ce61cc73 | 8454 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
8455 | if (current_function_has_inlines) |
8456 | { | |
8457 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
8458 | if (! comp_unit_has_inlines) | |
8459 | { | |
8460 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
8461 | comp_unit_has_inlines = 1; | |
8462 | } | |
8463 | } | |
8464 | #endif | |
8465 | } | |
71dfc51f | 8466 | |
ab72d377 | 8467 | pop_decl_scope (); |
a3f97cbb JW |
8468 | } |
8469 | ||
8470 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 8471 | |
a3f97cbb JW |
8472 | static void |
8473 | gen_variable_die (decl, context_die) | |
8474 | register tree decl; | |
8475 | register dw_die_ref context_die; | |
8476 | { | |
8477 | register tree origin = decl_ultimate_origin (decl); | |
8478 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 8479 | |
bdb669cb | 8480 | dw_die_ref old_die = lookup_decl_die (decl); |
4edb7b60 JM |
8481 | int declaration |
8482 | = (DECL_EXTERNAL (decl) | |
a94dbf2c JM |
8483 | || current_function_decl != decl_function_context (decl) |
8484 | || context_die->die_tag == DW_TAG_structure_type | |
8485 | || context_die->die_tag == DW_TAG_union_type); | |
4edb7b60 | 8486 | |
a3f97cbb | 8487 | if (origin != NULL) |
71dfc51f | 8488 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
8489 | /* Loop unrolling can create multiple blocks that refer to the same |
8490 | static variable, so we must test for the DW_AT_declaration flag. */ | |
8491 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
8492 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
8493 | sharing them. */ | |
8494 | else if (old_die && TREE_STATIC (decl) | |
8495 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 8496 | { |
f76b8156 | 8497 | /* ??? This is an instantiation of a C++ class level static. */ |
bdb669cb JM |
8498 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
8499 | if (DECL_NAME (decl)) | |
8500 | { | |
8501 | register unsigned file_index | |
8502 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 8503 | |
bdb669cb JM |
8504 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8505 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 8506 | |
bdb669cb JM |
8507 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
8508 | != DECL_SOURCE_LINE (decl)) | |
71dfc51f RK |
8509 | |
8510 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
8511 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
8512 | } |
8513 | } | |
a3f97cbb JW |
8514 | else |
8515 | { | |
8516 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
8517 | add_type_attribute (var_die, TREE_TYPE (decl), |
8518 | TREE_READONLY (decl), | |
8519 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 8520 | |
273dbe67 JM |
8521 | if (TREE_PUBLIC (decl)) |
8522 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 8523 | |
273dbe67 JM |
8524 | if (DECL_ARTIFICIAL (decl)) |
8525 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 8526 | |
a94dbf2c JM |
8527 | if (TREE_PROTECTED (decl)) |
8528 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8529 | |
a94dbf2c JM |
8530 | else if (TREE_PRIVATE (decl)) |
8531 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8532 | } |
4edb7b60 JM |
8533 | |
8534 | if (declaration) | |
8535 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
8536 | ||
8537 | if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl)) | |
8538 | equate_decl_number_to_die (decl, var_die); | |
8539 | ||
8540 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb | 8541 | { |
141719a8 | 8542 | equate_decl_number_to_die (decl, var_die); |
a3f97cbb | 8543 | add_location_or_const_value_attribute (var_die, decl); |
d291dd49 | 8544 | add_pubname (decl, var_die); |
a3f97cbb JW |
8545 | } |
8546 | } | |
8547 | ||
8548 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 8549 | |
a3f97cbb JW |
8550 | static void |
8551 | gen_label_die (decl, context_die) | |
8552 | register tree decl; | |
8553 | register dw_die_ref context_die; | |
8554 | { | |
8555 | register tree origin = decl_ultimate_origin (decl); | |
8556 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
8557 | register rtx insn; | |
8558 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5c90448c | 8559 | char label2[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8560 | |
a3f97cbb | 8561 | if (origin != NULL) |
71dfc51f | 8562 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 8563 | else |
71dfc51f RK |
8564 | add_name_and_src_coords_attributes (lbl_die, decl); |
8565 | ||
a3f97cbb | 8566 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 8567 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
8568 | else |
8569 | { | |
8570 | insn = DECL_RTL (decl); | |
8571 | if (GET_CODE (insn) == CODE_LABEL) | |
8572 | { | |
8573 | /* When optimization is enabled (via -O) some parts of the compiler | |
8574 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
8575 | represent source-level labels which were explicitly declared by | |
8576 | the user. This really shouldn't be happening though, so catch | |
8577 | it if it ever does happen. */ | |
8578 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
8579 | abort (); |
8580 | ||
5c90448c JM |
8581 | sprintf (label2, INSN_LABEL_FMT, current_funcdef_number); |
8582 | ASM_GENERATE_INTERNAL_LABEL (label, label2, | |
8583 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
8584 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
8585 | } | |
8586 | } | |
8587 | } | |
8588 | ||
8589 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 8590 | |
a3f97cbb | 8591 | static void |
d7248bff | 8592 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
8593 | register tree stmt; |
8594 | register dw_die_ref context_die; | |
d7248bff | 8595 | int depth; |
a3f97cbb JW |
8596 | { |
8597 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
8598 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
8599 | |
8600 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 8601 | { |
5c90448c JM |
8602 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
8603 | next_block_number); | |
a3f97cbb | 8604 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
5c90448c | 8605 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb JW |
8606 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
8607 | } | |
71dfc51f | 8608 | |
7d4440be | 8609 | push_decl_scope (stmt); |
d7248bff | 8610 | decls_for_scope (stmt, stmt_die, depth); |
7d4440be | 8611 | pop_decl_scope (); |
a3f97cbb JW |
8612 | } |
8613 | ||
8614 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 8615 | |
a3f97cbb | 8616 | static void |
d7248bff | 8617 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
8618 | register tree stmt; |
8619 | register dw_die_ref context_die; | |
d7248bff | 8620 | int depth; |
a3f97cbb | 8621 | { |
71dfc51f | 8622 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 8623 | { |
71dfc51f RK |
8624 | register dw_die_ref subr_die |
8625 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 8626 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 8627 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8628 | |
ab72d377 | 8629 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c JM |
8630 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
8631 | next_block_number); | |
a3f97cbb | 8632 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
5c90448c | 8633 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb | 8634 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
ab72d377 | 8635 | push_decl_scope (decl); |
d7248bff | 8636 | decls_for_scope (stmt, subr_die, depth); |
ab72d377 | 8637 | pop_decl_scope (); |
7e23cb16 | 8638 | current_function_has_inlines = 1; |
a3f97cbb | 8639 | } |
a3f97cbb JW |
8640 | } |
8641 | ||
8642 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 8643 | |
a3f97cbb JW |
8644 | static void |
8645 | gen_field_die (decl, context_die) | |
8646 | register tree decl; | |
8647 | register dw_die_ref context_die; | |
8648 | { | |
8649 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 8650 | |
a3f97cbb | 8651 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
8652 | add_type_attribute (decl_die, member_declared_type (decl), |
8653 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
8654 | context_die); | |
71dfc51f | 8655 | |
a3f97cbb JW |
8656 | /* If this is a bit field... */ |
8657 | if (DECL_BIT_FIELD_TYPE (decl)) | |
8658 | { | |
8659 | add_byte_size_attribute (decl_die, decl); | |
8660 | add_bit_size_attribute (decl_die, decl); | |
8661 | add_bit_offset_attribute (decl_die, decl); | |
8662 | } | |
71dfc51f | 8663 | |
a94dbf2c JM |
8664 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
8665 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 8666 | |
273dbe67 JM |
8667 | if (DECL_ARTIFICIAL (decl)) |
8668 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 8669 | |
a94dbf2c JM |
8670 | if (TREE_PROTECTED (decl)) |
8671 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8672 | |
a94dbf2c JM |
8673 | else if (TREE_PRIVATE (decl)) |
8674 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
8675 | } |
8676 | ||
ab72d377 JM |
8677 | #if 0 |
8678 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
8679 | Use modified_type_die instead. | |
a3f97cbb JW |
8680 | We keep this code here just in case these types of DIEs may be needed to |
8681 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8682 | static void | |
8683 | gen_pointer_type_die (type, context_die) | |
8684 | register tree type; | |
8685 | register dw_die_ref context_die; | |
8686 | { | |
71dfc51f RK |
8687 | register dw_die_ref ptr_die |
8688 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
8689 | ||
a3f97cbb | 8690 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8691 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8692 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
8693 | } |
8694 | ||
ab72d377 JM |
8695 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
8696 | Use modified_type_die instead. | |
a3f97cbb JW |
8697 | We keep this code here just in case these types of DIEs may be needed to |
8698 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8699 | static void | |
8700 | gen_reference_type_die (type, context_die) | |
8701 | register tree type; | |
8702 | register dw_die_ref context_die; | |
8703 | { | |
71dfc51f RK |
8704 | register dw_die_ref ref_die |
8705 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
8706 | ||
a3f97cbb | 8707 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 8708 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8709 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 8710 | } |
ab72d377 | 8711 | #endif |
a3f97cbb JW |
8712 | |
8713 | /* Generate a DIE for a pointer to a member type. */ | |
8714 | static void | |
8715 | gen_ptr_to_mbr_type_die (type, context_die) | |
8716 | register tree type; | |
8717 | register dw_die_ref context_die; | |
8718 | { | |
71dfc51f RK |
8719 | register dw_die_ref ptr_die |
8720 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
8721 | ||
a3f97cbb | 8722 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8723 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 8724 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
8725 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
8726 | } | |
8727 | ||
8728 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 8729 | |
a3f97cbb JW |
8730 | static void |
8731 | gen_compile_unit_die (main_input_filename) | |
8732 | register char *main_input_filename; | |
8733 | { | |
8734 | char producer[250]; | |
a3f97cbb JW |
8735 | char *wd = getpwd (); |
8736 | ||
8737 | comp_unit_die = new_die (DW_TAG_compile_unit, NULL); | |
bdb669cb JM |
8738 | add_name_attribute (comp_unit_die, main_input_filename); |
8739 | ||
71dfc51f RK |
8740 | if (wd != NULL) |
8741 | add_AT_string (comp_unit_die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
8742 | |
8743 | sprintf (producer, "%s %s", language_string, version_string); | |
8744 | ||
8745 | #ifdef MIPS_DEBUGGING_INFO | |
8746 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
8747 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
8748 | not appear in the producer string, the debugger reaches the conclusion | |
8749 | that the object file is stripped and has no debugging information. | |
8750 | To get the MIPS/SGI debugger to believe that there is debugging | |
8751 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
8752 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8753 | strcat (producer, " -g"); | |
a3f97cbb JW |
8754 | #endif |
8755 | ||
8756 | add_AT_string (comp_unit_die, DW_AT_producer, producer); | |
a9d38797 | 8757 | |
a3f97cbb | 8758 | if (strcmp (language_string, "GNU C++") == 0) |
a9d38797 | 8759 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus); |
71dfc51f | 8760 | |
a3f97cbb | 8761 | else if (strcmp (language_string, "GNU Ada") == 0) |
a9d38797 | 8762 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83); |
71dfc51f | 8763 | |
a9d38797 JM |
8764 | else if (strcmp (language_string, "GNU F77") == 0) |
8765 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77); | |
71dfc51f | 8766 | |
bc28c45b RK |
8767 | else if (strcmp (language_string, "GNU Pascal") == 0) |
8768 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83); | |
8769 | ||
a3f97cbb | 8770 | else if (flag_traditional) |
a9d38797 | 8771 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C); |
71dfc51f | 8772 | |
a3f97cbb | 8773 | else |
a9d38797 JM |
8774 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89); |
8775 | ||
8776 | #if 0 /* unimplemented */ | |
e90b62db | 8777 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
a9d38797 JM |
8778 | add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0); |
8779 | #endif | |
a3f97cbb JW |
8780 | } |
8781 | ||
8782 | /* Generate a DIE for a string type. */ | |
71dfc51f | 8783 | |
a3f97cbb JW |
8784 | static void |
8785 | gen_string_type_die (type, context_die) | |
8786 | register tree type; | |
8787 | register dw_die_ref context_die; | |
8788 | { | |
71dfc51f RK |
8789 | register dw_die_ref type_die |
8790 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
8791 | ||
bdb669cb | 8792 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
8793 | |
8794 | /* Fudge the string length attribute for now. */ | |
71dfc51f | 8795 | |
a3f97cbb | 8796 | /* TODO: add string length info. |
71dfc51f | 8797 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
8798 | bound_representation (upper_bound, 0, 'u'); */ |
8799 | } | |
8800 | ||
61b32c02 | 8801 | /* Generate the DIE for a base class. */ |
71dfc51f | 8802 | |
61b32c02 JM |
8803 | static void |
8804 | gen_inheritance_die (binfo, context_die) | |
8805 | register tree binfo; | |
8806 | register dw_die_ref context_die; | |
8807 | { | |
8808 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 8809 | |
61b32c02 JM |
8810 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
8811 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 8812 | |
61b32c02 JM |
8813 | if (TREE_VIA_VIRTUAL (binfo)) |
8814 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
8815 | if (TREE_VIA_PUBLIC (binfo)) | |
8816 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
8817 | else if (TREE_VIA_PROTECTED (binfo)) | |
8818 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
8819 | } | |
8820 | ||
956d6950 | 8821 | /* Generate a DIE for a class member. */ |
71dfc51f | 8822 | |
a3f97cbb JW |
8823 | static void |
8824 | gen_member_die (type, context_die) | |
8825 | register tree type; | |
8826 | register dw_die_ref context_die; | |
8827 | { | |
61b32c02 | 8828 | register tree member; |
71dfc51f | 8829 | |
a3f97cbb JW |
8830 | /* If this is not an incomplete type, output descriptions of each of its |
8831 | members. Note that as we output the DIEs necessary to represent the | |
8832 | members of this record or union type, we will also be trying to output | |
8833 | DIEs to represent the *types* of those members. However the `type' | |
8834 | function (above) will specifically avoid generating type DIEs for member | |
8835 | types *within* the list of member DIEs for this (containing) type execpt | |
8836 | for those types (of members) which are explicitly marked as also being | |
8837 | members of this (containing) type themselves. The g++ front- end can | |
8838 | force any given type to be treated as a member of some other | |
8839 | (containing) type by setting the TYPE_CONTEXT of the given (member) type | |
8840 | to point to the TREE node representing the appropriate (containing) | |
8841 | type. */ | |
8842 | ||
61b32c02 JM |
8843 | /* First output info about the base classes. */ |
8844 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 8845 | { |
61b32c02 JM |
8846 | register tree bases = TYPE_BINFO_BASETYPES (type); |
8847 | register int n_bases = TREE_VEC_LENGTH (bases); | |
8848 | register int i; | |
8849 | ||
8850 | for (i = 0; i < n_bases; i++) | |
8851 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
8852 | } |
8853 | ||
61b32c02 JM |
8854 | /* Now output info about the data members and type members. */ |
8855 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
8856 | gen_decl_die (member, context_die); | |
8857 | ||
a3f97cbb | 8858 | /* Now output info about the function members (if any). */ |
61b32c02 JM |
8859 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
8860 | gen_decl_die (member, context_die); | |
a3f97cbb JW |
8861 | } |
8862 | ||
8863 | /* Generate a DIE for a structure or union type. */ | |
71dfc51f | 8864 | |
a3f97cbb | 8865 | static void |
273dbe67 | 8866 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 8867 | register tree type; |
a3f97cbb JW |
8868 | register dw_die_ref context_die; |
8869 | { | |
273dbe67 | 8870 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
8871 | register dw_die_ref scope_die = 0; |
8872 | register int nested = 0; | |
273dbe67 JM |
8873 | |
8874 | if (type_die && ! TYPE_SIZE (type)) | |
8875 | return; | |
a082c85a | 8876 | |
71dfc51f | 8877 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 8878 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
8879 | nested = 1; |
8880 | ||
a94dbf2c | 8881 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
8882 | |
8883 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 8884 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 8885 | { |
273dbe67 | 8886 | register dw_die_ref old_die = type_die; |
71dfc51f | 8887 | |
a3f97cbb JW |
8888 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
8889 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 8890 | scope_die); |
a3f97cbb JW |
8891 | equate_type_number_to_die (type, type_die); |
8892 | add_name_attribute (type_die, type_tag (type)); | |
273dbe67 JM |
8893 | if (old_die) |
8894 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
a3f97cbb | 8895 | } |
4b674448 | 8896 | else |
273dbe67 | 8897 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb | 8898 | |
a94dbf2c JM |
8899 | /* If we're not in the right context to be defining this type, defer to |
8900 | avoid tricky recursion. */ | |
8901 | if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die) | |
8902 | { | |
8903 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
8904 | pend_type (type); | |
8905 | } | |
a3f97cbb JW |
8906 | /* If this type has been completed, then give it a byte_size attribute and |
8907 | then give a list of members. */ | |
a94dbf2c | 8908 | else if (TYPE_SIZE (type)) |
a3f97cbb JW |
8909 | { |
8910 | /* Prevent infinite recursion in cases where the type of some member of | |
8911 | this type is expressed in terms of this type itself. */ | |
8912 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 8913 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 8914 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 8915 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 8916 | |
ef76d03b JW |
8917 | /* If the first reference to this type was as the return type of an |
8918 | inline function, then it may not have a parent. Fix this now. */ | |
8919 | if (type_die->die_parent == NULL) | |
8920 | add_child_die (scope_die, type_die); | |
8921 | ||
273dbe67 JM |
8922 | push_decl_scope (type); |
8923 | gen_member_die (type, type_die); | |
8924 | pop_decl_scope (); | |
71dfc51f | 8925 | |
a94dbf2c JM |
8926 | /* GNU extension: Record what type our vtable lives in. */ |
8927 | if (TYPE_VFIELD (type)) | |
8928 | { | |
8929 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 8930 | |
a94dbf2c JM |
8931 | gen_type_die (vtype, context_die); |
8932 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
8933 | lookup_type_die (vtype)); | |
8934 | } | |
a3f97cbb | 8935 | } |
4b674448 JM |
8936 | else |
8937 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
8938 | } |
8939 | ||
8940 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 8941 | |
a3f97cbb JW |
8942 | static void |
8943 | gen_subroutine_type_die (type, context_die) | |
8944 | register tree type; | |
8945 | register dw_die_ref context_die; | |
8946 | { | |
8947 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
8948 | register dw_die_ref subr_die |
8949 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
8950 | ||
a3f97cbb JW |
8951 | equate_type_number_to_die (type, subr_die); |
8952 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 8953 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 8954 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
8955 | } |
8956 | ||
8957 | /* Generate a DIE for a type definition */ | |
71dfc51f | 8958 | |
a3f97cbb JW |
8959 | static void |
8960 | gen_typedef_die (decl, context_die) | |
8961 | register tree decl; | |
8962 | register dw_die_ref context_die; | |
8963 | { | |
a3f97cbb | 8964 | register dw_die_ref type_die; |
a94dbf2c JM |
8965 | register tree origin; |
8966 | ||
8967 | if (TREE_ASM_WRITTEN (decl)) | |
8968 | return; | |
8969 | TREE_ASM_WRITTEN (decl) = 1; | |
8970 | ||
ab72d377 | 8971 | type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die)); |
a94dbf2c | 8972 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 8973 | if (origin != NULL) |
a94dbf2c | 8974 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
8975 | else |
8976 | { | |
a94dbf2c | 8977 | register tree type; |
a3f97cbb | 8978 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
8979 | if (DECL_ORIGINAL_TYPE (decl)) |
8980 | { | |
8981 | type = DECL_ORIGINAL_TYPE (decl); | |
8982 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
8983 | } | |
8984 | else | |
8985 | type = TREE_TYPE (decl); | |
8986 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
8987 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 8988 | } |
71dfc51f | 8989 | |
a3f97cbb | 8990 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 8991 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
8992 | } |
8993 | ||
8994 | /* Generate a type description DIE. */ | |
71dfc51f | 8995 | |
a3f97cbb JW |
8996 | static void |
8997 | gen_type_die (type, context_die) | |
8998 | register tree type; | |
8999 | register dw_die_ref context_die; | |
9000 | { | |
71dfc51f RK |
9001 | if (type == NULL_TREE || type == error_mark_node) |
9002 | return; | |
a3f97cbb | 9003 | |
38e01259 | 9004 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
9005 | this type (i.e. without any const or volatile qualifiers) so get the |
9006 | main variant (i.e. the unqualified version) of this type now. */ | |
9007 | type = type_main_variant (type); | |
9008 | ||
9009 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 9010 | return; |
a3f97cbb | 9011 | |
a94dbf2c JM |
9012 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9013 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
9014 | { | |
9015 | TREE_ASM_WRITTEN (type) = 1; | |
9016 | gen_decl_die (TYPE_NAME (type), context_die); | |
9017 | return; | |
9018 | } | |
9019 | ||
a3f97cbb JW |
9020 | switch (TREE_CODE (type)) |
9021 | { | |
9022 | case ERROR_MARK: | |
9023 | break; | |
9024 | ||
9025 | case POINTER_TYPE: | |
9026 | case REFERENCE_TYPE: | |
956d6950 JL |
9027 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
9028 | ensures that the gen_type_die recursion will terminate even if the | |
9029 | type is recursive. Recursive types are possible in Ada. */ | |
9030 | /* ??? We could perhaps do this for all types before the switch | |
9031 | statement. */ | |
9032 | TREE_ASM_WRITTEN (type) = 1; | |
9033 | ||
a3f97cbb JW |
9034 | /* For these types, all that is required is that we output a DIE (or a |
9035 | set of DIEs) to represent the "basis" type. */ | |
9036 | gen_type_die (TREE_TYPE (type), context_die); | |
9037 | break; | |
9038 | ||
9039 | case OFFSET_TYPE: | |
71dfc51f RK |
9040 | /* This code is used for C++ pointer-to-data-member types. |
9041 | Output a description of the relevant class type. */ | |
a3f97cbb | 9042 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 9043 | |
a3f97cbb JW |
9044 | /* Output a description of the type of the object pointed to. */ |
9045 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 9046 | |
a3f97cbb JW |
9047 | /* Now output a DIE to represent this pointer-to-data-member type |
9048 | itself. */ | |
9049 | gen_ptr_to_mbr_type_die (type, context_die); | |
9050 | break; | |
9051 | ||
9052 | case SET_TYPE: | |
9053 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
9054 | gen_set_type_die (type, context_die); | |
9055 | break; | |
9056 | ||
9057 | case FILE_TYPE: | |
9058 | gen_type_die (TREE_TYPE (type), context_die); | |
9059 | abort (); /* No way to represent these in Dwarf yet! */ | |
9060 | break; | |
9061 | ||
9062 | case FUNCTION_TYPE: | |
9063 | /* Force out return type (in case it wasn't forced out already). */ | |
9064 | gen_type_die (TREE_TYPE (type), context_die); | |
9065 | gen_subroutine_type_die (type, context_die); | |
9066 | break; | |
9067 | ||
9068 | case METHOD_TYPE: | |
9069 | /* Force out return type (in case it wasn't forced out already). */ | |
9070 | gen_type_die (TREE_TYPE (type), context_die); | |
9071 | gen_subroutine_type_die (type, context_die); | |
9072 | break; | |
9073 | ||
9074 | case ARRAY_TYPE: | |
9075 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
9076 | { | |
9077 | gen_type_die (TREE_TYPE (type), context_die); | |
9078 | gen_string_type_die (type, context_die); | |
9079 | } | |
9080 | else | |
71dfc51f | 9081 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
9082 | break; |
9083 | ||
9084 | case ENUMERAL_TYPE: | |
9085 | case RECORD_TYPE: | |
9086 | case UNION_TYPE: | |
9087 | case QUAL_UNION_TYPE: | |
a082c85a JM |
9088 | /* If this is a nested type whose containing class hasn't been |
9089 | written out yet, writing it out will cover this one, too. */ | |
9090 | if (TYPE_CONTEXT (type) | |
5f2f160c | 9091 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 9092 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
9093 | { |
9094 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
9095 | ||
9096 | if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
9097 | return; | |
9098 | ||
9099 | /* If that failed, attach ourselves to the stub. */ | |
9100 | push_decl_scope (TYPE_CONTEXT (type)); | |
9101 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
9102 | } | |
9103 | ||
9104 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 9105 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 9106 | else |
273dbe67 | 9107 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 9108 | |
a94dbf2c | 9109 | if (TYPE_CONTEXT (type) |
5f2f160c | 9110 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a94dbf2c JM |
9111 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
9112 | pop_decl_scope (); | |
9113 | ||
4b674448 | 9114 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
9115 | it up if it is ever completed. gen_*_type_die will set it for us |
9116 | when appropriate. */ | |
9117 | return; | |
a3f97cbb JW |
9118 | |
9119 | case VOID_TYPE: | |
9120 | case INTEGER_TYPE: | |
9121 | case REAL_TYPE: | |
9122 | case COMPLEX_TYPE: | |
9123 | case BOOLEAN_TYPE: | |
9124 | case CHAR_TYPE: | |
9125 | /* No DIEs needed for fundamental types. */ | |
9126 | break; | |
9127 | ||
9128 | case LANG_TYPE: | |
9129 | /* No Dwarf representation currently defined. */ | |
9130 | break; | |
9131 | ||
9132 | default: | |
9133 | abort (); | |
9134 | } | |
9135 | ||
9136 | TREE_ASM_WRITTEN (type) = 1; | |
9137 | } | |
9138 | ||
9139 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 9140 | |
a3f97cbb JW |
9141 | static void |
9142 | gen_tagged_type_instantiation_die (type, context_die) | |
9143 | register tree type; | |
9144 | register dw_die_ref context_die; | |
9145 | { | |
71dfc51f RK |
9146 | if (type == NULL_TREE || type == error_mark_node) |
9147 | return; | |
a3f97cbb | 9148 | |
38e01259 | 9149 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
9150 | this type (i.e. without any const or volatile qualifiers) so make sure |
9151 | that we have the main variant (i.e. the unqualified version) of this | |
9152 | type now. */ | |
3a88cbd1 JL |
9153 | if (type != type_main_variant (type) |
9154 | || !TREE_ASM_WRITTEN (type)) | |
9155 | abort (); | |
a3f97cbb JW |
9156 | |
9157 | switch (TREE_CODE (type)) | |
9158 | { | |
9159 | case ERROR_MARK: | |
9160 | break; | |
9161 | ||
9162 | case ENUMERAL_TYPE: | |
9163 | gen_inlined_enumeration_type_die (type, context_die); | |
9164 | break; | |
9165 | ||
9166 | case RECORD_TYPE: | |
9167 | gen_inlined_structure_type_die (type, context_die); | |
9168 | break; | |
9169 | ||
9170 | case UNION_TYPE: | |
9171 | case QUAL_UNION_TYPE: | |
9172 | gen_inlined_union_type_die (type, context_die); | |
9173 | break; | |
9174 | ||
9175 | default: | |
71dfc51f | 9176 | abort (); |
a3f97cbb JW |
9177 | } |
9178 | } | |
9179 | ||
9180 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
9181 | things which are local to the given block. */ | |
71dfc51f | 9182 | |
a3f97cbb | 9183 | static void |
d7248bff | 9184 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
9185 | register tree stmt; |
9186 | register dw_die_ref context_die; | |
d7248bff | 9187 | int depth; |
a3f97cbb JW |
9188 | { |
9189 | register int must_output_die = 0; | |
9190 | register tree origin; | |
9191 | register tree decl; | |
9192 | register enum tree_code origin_code; | |
9193 | ||
9194 | /* Ignore blocks never really used to make RTL. */ | |
9195 | ||
71dfc51f RK |
9196 | if (stmt == NULL_TREE || !TREE_USED (stmt)) |
9197 | return; | |
a3f97cbb JW |
9198 | |
9199 | /* Determine the "ultimate origin" of this block. This block may be an | |
9200 | inlined instance of an inlined instance of inline function, so we have | |
9201 | to trace all of the way back through the origin chain to find out what | |
9202 | sort of node actually served as the original seed for the creation of | |
9203 | the current block. */ | |
9204 | origin = block_ultimate_origin (stmt); | |
9205 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
9206 | ||
9207 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
9208 | block. */ | |
9209 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
9210 | /* The outer scopes for inlinings *must* always be represented. We |
9211 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
9212 | must_output_die = 1; | |
a3f97cbb JW |
9213 | else |
9214 | { | |
9215 | /* In the case where the current block represents an inlining of the | |
9216 | "body block" of an inline function, we must *NOT* output any DIE for | |
9217 | this block because we have already output a DIE to represent the | |
9218 | whole inlined function scope and the "body block" of any function | |
9219 | doesn't really represent a different scope according to ANSI C | |
9220 | rules. So we check here to make sure that this block does not | |
9221 | represent a "body block inlining" before trying to set the | |
9222 | `must_output_die' flag. */ | |
d7248bff | 9223 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
9224 | { |
9225 | /* Determine if this block directly contains any "significant" | |
9226 | local declarations which we will need to output DIEs for. */ | |
9227 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
9228 | /* We are not in terse mode so *any* local declaration counts |
9229 | as being a "significant" one. */ | |
9230 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 9231 | else |
71dfc51f RK |
9232 | /* We are in terse mode, so only local (nested) function |
9233 | definitions count as "significant" local declarations. */ | |
9234 | for (decl = BLOCK_VARS (stmt); | |
9235 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9236 | if (TREE_CODE (decl) == FUNCTION_DECL | |
9237 | && DECL_INITIAL (decl)) | |
a3f97cbb | 9238 | { |
71dfc51f RK |
9239 | must_output_die = 1; |
9240 | break; | |
a3f97cbb | 9241 | } |
a3f97cbb JW |
9242 | } |
9243 | } | |
9244 | ||
9245 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
9246 | DIE for any block which contains no significant local declarations at | |
9247 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
9248 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
9249 | that in terse mode, our definition of what constitutes a "significant" | |
9250 | local declaration gets restricted to include only inlined function | |
9251 | instances and local (nested) function definitions. */ | |
9252 | if (must_output_die) | |
9253 | { | |
9254 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 9255 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 9256 | else |
71dfc51f | 9257 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
9258 | } |
9259 | else | |
d7248bff | 9260 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
9261 | } |
9262 | ||
9263 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 9264 | all of its sub-blocks. */ |
71dfc51f | 9265 | |
a3f97cbb | 9266 | static void |
d7248bff | 9267 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
9268 | register tree stmt; |
9269 | register dw_die_ref context_die; | |
d7248bff | 9270 | int depth; |
a3f97cbb JW |
9271 | { |
9272 | register tree decl; | |
9273 | register tree subblocks; | |
71dfc51f | 9274 | |
a3f97cbb | 9275 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
9276 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
9277 | return; | |
9278 | ||
d7248bff | 9279 | if (!BLOCK_ABSTRACT (stmt) && depth > 0) |
71dfc51f | 9280 | next_block_number++; |
a3f97cbb | 9281 | |
88dad228 JM |
9282 | /* Output the DIEs to represent all of the data objects and typedefs |
9283 | declared directly within this block but not within any nested | |
9284 | sub-blocks. Also, nested function and tag DIEs have been | |
9285 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
9286 | for (decl = BLOCK_VARS (stmt); |
9287 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9288 | { | |
a94dbf2c JM |
9289 | register dw_die_ref die; |
9290 | ||
88dad228 | 9291 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 9292 | die = lookup_decl_die (decl); |
88dad228 | 9293 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
9294 | die = lookup_type_die (TREE_TYPE (decl)); |
9295 | else | |
9296 | die = NULL; | |
9297 | ||
71dfc51f | 9298 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 9299 | add_child_die (context_die, die); |
88dad228 JM |
9300 | else |
9301 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
9302 | } |
9303 | ||
9304 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
9305 | therein) of this block. */ | |
9306 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
9307 | subblocks != NULL; | |
9308 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 9309 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
9310 | } |
9311 | ||
a94dbf2c | 9312 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
9313 | |
9314 | static inline int | |
a94dbf2c JM |
9315 | is_redundant_typedef (decl) |
9316 | register tree decl; | |
9317 | { | |
9318 | if (TYPE_DECL_IS_STUB (decl)) | |
9319 | return 1; | |
71dfc51f | 9320 | |
a94dbf2c JM |
9321 | if (DECL_ARTIFICIAL (decl) |
9322 | && DECL_CONTEXT (decl) | |
9323 | && is_tagged_type (DECL_CONTEXT (decl)) | |
9324 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
9325 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
9326 | /* Also ignore the artificial member typedef for the class name. */ | |
9327 | return 1; | |
71dfc51f | 9328 | |
a94dbf2c JM |
9329 | return 0; |
9330 | } | |
9331 | ||
a3f97cbb | 9332 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 9333 | |
a3f97cbb JW |
9334 | static void |
9335 | gen_decl_die (decl, context_die) | |
9336 | register tree decl; | |
9337 | register dw_die_ref context_die; | |
9338 | { | |
9339 | register tree origin; | |
71dfc51f | 9340 | |
a3f97cbb JW |
9341 | /* Make a note of the decl node we are going to be working on. We may need |
9342 | to give the user the source coordinates of where it appeared in case we | |
9343 | notice (later on) that something about it looks screwy. */ | |
9344 | dwarf_last_decl = decl; | |
9345 | ||
9346 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f | 9347 | return; |
a3f97cbb JW |
9348 | |
9349 | /* If this ..._DECL node is marked to be ignored, then ignore it. But don't | |
9350 | ignore a function definition, since that would screw up our count of | |
38e01259 | 9351 | blocks, and that in turn will completely screw up the labels we will |
a3f97cbb JW |
9352 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for |
9353 | subsequent blocks). */ | |
9354 | if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL) | |
71dfc51f | 9355 | return; |
a3f97cbb | 9356 | |
a3f97cbb JW |
9357 | switch (TREE_CODE (decl)) |
9358 | { | |
9359 | case CONST_DECL: | |
9360 | /* The individual enumerators of an enum type get output when we output | |
9361 | the Dwarf representation of the relevant enum type itself. */ | |
9362 | break; | |
9363 | ||
9364 | case FUNCTION_DECL: | |
4edb7b60 JM |
9365 | /* Don't output any DIEs to represent mere function declarations, |
9366 | unless they are class members or explicit block externs. */ | |
9367 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
9368 | && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl))) | |
71dfc51f | 9369 | break; |
bdb669cb | 9370 | |
4927276d | 9371 | if (debug_info_level > DINFO_LEVEL_TERSE) |
a94dbf2c JM |
9372 | { |
9373 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
9374 | have described its return type. */ | |
9375 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
9376 | ||
9377 | /* And its containing type. */ | |
9378 | origin = decl_class_context (decl); | |
71dfc51f | 9379 | if (origin != NULL_TREE) |
a94dbf2c JM |
9380 | gen_type_die (origin, context_die); |
9381 | ||
9382 | /* And its virtual context. */ | |
71dfc51f | 9383 | if (DECL_VINDEX (decl) != NULL_TREE) |
a94dbf2c JM |
9384 | gen_type_die (DECL_CONTEXT (decl), context_die); |
9385 | } | |
a3f97cbb JW |
9386 | |
9387 | /* Now output a DIE to represent the function itself. */ | |
9388 | gen_subprogram_die (decl, context_die); | |
9389 | break; | |
9390 | ||
9391 | case TYPE_DECL: | |
9392 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 9393 | actual typedefs. */ |
a3f97cbb | 9394 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9395 | break; |
a3f97cbb | 9396 | |
5c90448c JM |
9397 | /* In the special case of a TYPE_DECL node representing the |
9398 | declaration of some type tag, if the given TYPE_DECL is marked as | |
a3f97cbb JW |
9399 | having been instantiated from some other (original) TYPE_DECL node |
9400 | (e.g. one which was generated within the original definition of an | |
9401 | inline function) we have to generate a special (abbreviated) | |
ef76d03b | 9402 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 9403 | DIE here. */ |
71dfc51f | 9404 | if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) |
a3f97cbb JW |
9405 | { |
9406 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
9407 | break; | |
9408 | } | |
a3f97cbb | 9409 | |
a94dbf2c JM |
9410 | if (is_redundant_typedef (decl)) |
9411 | gen_type_die (TREE_TYPE (decl), context_die); | |
9412 | else | |
71dfc51f RK |
9413 | /* Output a DIE to represent the typedef itself. */ |
9414 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
9415 | break; |
9416 | ||
9417 | case LABEL_DECL: | |
9418 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 9419 | gen_label_die (decl, context_die); |
a3f97cbb JW |
9420 | break; |
9421 | ||
9422 | case VAR_DECL: | |
9423 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9424 | variable declarations or definitions. */ | |
9425 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9426 | break; |
a3f97cbb JW |
9427 | |
9428 | /* Output any DIEs that are needed to specify the type of this data | |
9429 | object. */ | |
9430 | gen_type_die (TREE_TYPE (decl), context_die); | |
9431 | ||
a94dbf2c JM |
9432 | /* And its containing type. */ |
9433 | origin = decl_class_context (decl); | |
71dfc51f | 9434 | if (origin != NULL_TREE) |
a94dbf2c JM |
9435 | gen_type_die (origin, context_die); |
9436 | ||
a3f97cbb JW |
9437 | /* Now output the DIE to represent the data object itself. This gets |
9438 | complicated because of the possibility that the VAR_DECL really | |
9439 | represents an inlined instance of a formal parameter for an inline | |
9440 | function. */ | |
9441 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
9442 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
9443 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 9444 | else |
71dfc51f | 9445 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
9446 | break; |
9447 | ||
9448 | case FIELD_DECL: | |
a94dbf2c JM |
9449 | /* Ignore the nameless fields that are used to skip bits, but |
9450 | handle C++ anonymous unions. */ | |
71dfc51f RK |
9451 | if (DECL_NAME (decl) != NULL_TREE |
9452 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
9453 | { |
9454 | gen_type_die (member_declared_type (decl), context_die); | |
9455 | gen_field_die (decl, context_die); | |
9456 | } | |
9457 | break; | |
9458 | ||
9459 | case PARM_DECL: | |
9460 | gen_type_die (TREE_TYPE (decl), context_die); | |
9461 | gen_formal_parameter_die (decl, context_die); | |
9462 | break; | |
9463 | ||
9464 | default: | |
9465 | abort (); | |
9466 | } | |
a3f97cbb JW |
9467 | } |
9468 | \f | |
71dfc51f RK |
9469 | /* Write the debugging output for DECL. */ |
9470 | ||
a3f97cbb | 9471 | void |
88dad228 | 9472 | dwarf2out_decl (decl) |
a3f97cbb | 9473 | register tree decl; |
a3f97cbb | 9474 | { |
88dad228 JM |
9475 | register dw_die_ref context_die = comp_unit_die; |
9476 | ||
a3f97cbb | 9477 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 9478 | return; |
a3f97cbb JW |
9479 | |
9480 | /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta | |
9481 | hope that the node in question doesn't represent a function definition. | |
9482 | If it does, then totally ignoring it is bound to screw up our count of | |
38e01259 | 9483 | blocks, and that in turn will completely screw up the labels we will |
a3f97cbb JW |
9484 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for |
9485 | subsequent blocks). (It's too bad that BLOCK nodes don't carry their | |
9486 | own sequence numbers with them!) */ | |
9487 | if (DECL_IGNORED_P (decl)) | |
9488 | { | |
9489 | if (TREE_CODE (decl) == FUNCTION_DECL | |
02e24c7a | 9490 | && DECL_INITIAL (decl) != NULL) |
71dfc51f RK |
9491 | abort (); |
9492 | ||
a3f97cbb JW |
9493 | return; |
9494 | } | |
9495 | ||
9496 | switch (TREE_CODE (decl)) | |
9497 | { | |
9498 | case FUNCTION_DECL: | |
9499 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a | |
9500 | builtin function. Explicit programmer-supplied declarations of | |
9501 | these same functions should NOT be ignored however. */ | |
9502 | if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) | |
b1ccbc24 | 9503 | return; |
a3f97cbb JW |
9504 | |
9505 | /* What we would really like to do here is to filter out all mere | |
9506 | file-scope declarations of file-scope functions which are never | |
9507 | referenced later within this translation unit (and keep all of ones | |
956d6950 | 9508 | that *are* referenced later on) but we aren't clairvoyant, so we have |
a3f97cbb JW |
9509 | no idea which functions will be referenced in the future (i.e. later |
9510 | on within the current translation unit). So here we just ignore all | |
9511 | file-scope function declarations which are not also definitions. If | |
956d6950 | 9512 | and when the debugger needs to know something about these functions, |
a3f97cbb JW |
9513 | it wil have to hunt around and find the DWARF information associated |
9514 | with the definition of the function. Note that we can't just check | |
9515 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent | |
9516 | definitions and which ones represent mere declarations. We have to | |
9517 | check `DECL_INITIAL' instead. That's because the C front-end | |
9518 | supports some weird semantics for "extern inline" function | |
9519 | definitions. These can get inlined within the current translation | |
9520 | unit (an thus, we need to generate DWARF info for their abstract | |
9521 | instances so that the DWARF info for the concrete inlined instances | |
9522 | can have something to refer to) but the compiler never generates any | |
9523 | out-of-lines instances of such things (despite the fact that they | |
9524 | *are* definitions). The important point is that the C front-end | |
9525 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 9526 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb JW |
9527 | plays some similar games for inline function definitions appearing |
9528 | within include files which also contain | |
9529 | `#pragma interface' pragmas. */ | |
9530 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 9531 | return; |
88dad228 | 9532 | |
9c6cd30e JM |
9533 | /* If we're a nested function, initially use a parent of NULL; if we're |
9534 | a plain function, this will be fixed up in decls_for_scope. If | |
9535 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 9536 | if (decl_function_context (decl)) |
9c6cd30e | 9537 | context_die = NULL; |
88dad228 | 9538 | |
a3f97cbb JW |
9539 | break; |
9540 | ||
9541 | case VAR_DECL: | |
9542 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object | |
9543 | declaration and if the declaration was never even referenced from | |
9544 | within this entire compilation unit. We suppress these DIEs in | |
9545 | order to save space in the .debug section (by eliminating entries | |
9546 | which are probably useless). Note that we must not suppress | |
9547 | block-local extern declarations (whether used or not) because that | |
9548 | would screw-up the debugger's name lookup mechanism and cause it to | |
9549 | miss things which really ought to be in scope at a given point. */ | |
9550 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 9551 | return; |
a3f97cbb JW |
9552 | |
9553 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9554 | variable declarations or definitions. */ | |
9555 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9556 | return; |
a3f97cbb JW |
9557 | break; |
9558 | ||
9559 | case TYPE_DECL: | |
9560 | /* Don't bother trying to generate any DIEs to represent any of the | |
a9d38797 JM |
9561 | normal built-in types for the language we are compiling. */ |
9562 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
9563 | { |
9564 | /* OK, we need to generate one for `bool' so GDB knows what type | |
9565 | comparisons have. */ | |
9566 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
9567 | == DW_LANG_C_plus_plus) | |
9568 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
9569 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 9570 | |
a94dbf2c JM |
9571 | return; |
9572 | } | |
a3f97cbb | 9573 | |
88dad228 | 9574 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 9575 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9576 | return; |
88dad228 JM |
9577 | |
9578 | /* If we're a function-scope tag, initially use a parent of NULL; | |
9579 | this will be fixed up in decls_for_scope. */ | |
9580 | if (decl_function_context (decl)) | |
3f76745e | 9581 | context_die = NULL; |
88dad228 | 9582 | |
a3f97cbb JW |
9583 | break; |
9584 | ||
9585 | default: | |
9586 | return; | |
9587 | } | |
9588 | ||
88dad228 | 9589 | gen_decl_die (decl, context_die); |
a94dbf2c | 9590 | output_pending_types_for_scope (comp_unit_die); |
a3f97cbb JW |
9591 | } |
9592 | ||
9593 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
9594 | a lexical block. */ | |
71dfc51f | 9595 | |
a3f97cbb | 9596 | void |
9a666dda | 9597 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
9598 | register unsigned blocknum; |
9599 | { | |
a3f97cbb | 9600 | function_section (current_function_decl); |
5c90448c | 9601 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
9602 | } |
9603 | ||
9604 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
9605 | lexical block. */ | |
71dfc51f | 9606 | |
a3f97cbb | 9607 | void |
9a666dda | 9608 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
9609 | register unsigned blocknum; |
9610 | { | |
a3f97cbb | 9611 | function_section (current_function_decl); |
5c90448c | 9612 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
9613 | } |
9614 | ||
9615 | /* Output a marker (i.e. a label) at a point in the assembly code which | |
9616 | corresponds to a given source level label. */ | |
71dfc51f | 9617 | |
a3f97cbb | 9618 | void |
9a666dda | 9619 | dwarf2out_label (insn) |
a3f97cbb JW |
9620 | register rtx insn; |
9621 | { | |
9622 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 9623 | |
a3f97cbb JW |
9624 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9625 | { | |
9626 | function_section (current_function_decl); | |
5c90448c JM |
9627 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number); |
9628 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label, | |
9629 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
9630 | } |
9631 | } | |
9632 | ||
a3f97cbb | 9633 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 9634 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
9635 | just a unique number which is associated with only that one filename. |
9636 | We need such numbers for the sake of generating labels | |
9637 | (in the .debug_sfnames section) and references to those | |
9638 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
9639 | If the filename given as an argument is not found in our current list, | |
9640 | add it to the list and assign it the next available unique index number. | |
9641 | In order to speed up searches, we remember the index of the filename | |
9642 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 9643 | |
a3f97cbb JW |
9644 | static unsigned |
9645 | lookup_filename (file_name) | |
9646 | char *file_name; | |
9647 | { | |
9648 | static unsigned last_file_lookup_index = 0; | |
a3f97cbb JW |
9649 | register unsigned i; |
9650 | ||
9651 | /* Check to see if the file name that was searched on the previous call | |
9652 | matches this file name. If so, return the index. */ | |
9653 | if (last_file_lookup_index != 0) | |
71dfc51f RK |
9654 | if (strcmp (file_name, file_table[last_file_lookup_index]) == 0) |
9655 | return last_file_lookup_index; | |
a3f97cbb JW |
9656 | |
9657 | /* Didn't match the previous lookup, search the table */ | |
9658 | for (i = 1; i < file_table_in_use; ++i) | |
71dfc51f RK |
9659 | if (strcmp (file_name, file_table[i]) == 0) |
9660 | { | |
9661 | last_file_lookup_index = i; | |
9662 | return i; | |
9663 | } | |
a3f97cbb JW |
9664 | |
9665 | /* Prepare to add a new table entry by making sure there is enough space in | |
9666 | the table to do so. If not, expand the current table. */ | |
9667 | if (file_table_in_use == file_table_allocated) | |
9668 | { | |
9669 | file_table_allocated += FILE_TABLE_INCREMENT; | |
9670 | file_table | |
71dfc51f RK |
9671 | = (char **) xrealloc (file_table, |
9672 | file_table_allocated * sizeof (char *)); | |
a3f97cbb JW |
9673 | } |
9674 | ||
71dfc51f | 9675 | /* Add the new entry to the end of the filename table. */ |
a3f97cbb JW |
9676 | file_table[file_table_in_use] = xstrdup (file_name); |
9677 | last_file_lookup_index = file_table_in_use++; | |
71dfc51f | 9678 | |
a3f97cbb JW |
9679 | return last_file_lookup_index; |
9680 | } | |
9681 | ||
9682 | /* Output a label to mark the beginning of a source code line entry | |
9683 | and record information relating to this source line, in | |
9684 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 9685 | |
a3f97cbb | 9686 | void |
9a666dda | 9687 | dwarf2out_line (filename, line) |
a3f97cbb JW |
9688 | register char *filename; |
9689 | register unsigned line; | |
9690 | { | |
a3f97cbb JW |
9691 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9692 | { | |
9693 | function_section (current_function_decl); | |
a3f97cbb | 9694 | |
e90b62db | 9695 | if (DECL_SECTION_NAME (current_function_decl)) |
a3f97cbb | 9696 | { |
e90b62db | 9697 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
9698 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
9699 | separate_line_info_table_in_use); | |
e90b62db JM |
9700 | fputc ('\n', asm_out_file); |
9701 | ||
9702 | /* expand the line info table if necessary */ | |
9703 | if (separate_line_info_table_in_use | |
9704 | == separate_line_info_table_allocated) | |
9705 | { | |
9706 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9707 | separate_line_info_table | |
71dfc51f RK |
9708 | = (dw_separate_line_info_ref) |
9709 | xrealloc (separate_line_info_table, | |
9710 | separate_line_info_table_allocated | |
9711 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 9712 | } |
71dfc51f RK |
9713 | |
9714 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9715 | line_info |
9716 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
9717 | line_info->dw_file_num = lookup_filename (filename); | |
9718 | line_info->dw_line_num = line; | |
9719 | line_info->function = current_funcdef_number; | |
9720 | } | |
9721 | else | |
9722 | { | |
9723 | register dw_line_info_ref line_info; | |
71dfc51f | 9724 | |
5c90448c JM |
9725 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
9726 | line_info_table_in_use); | |
e90b62db JM |
9727 | fputc ('\n', asm_out_file); |
9728 | ||
71dfc51f | 9729 | /* Expand the line info table if necessary. */ |
e90b62db JM |
9730 | if (line_info_table_in_use == line_info_table_allocated) |
9731 | { | |
9732 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9733 | line_info_table | |
71dfc51f RK |
9734 | = (dw_line_info_ref) |
9735 | xrealloc (line_info_table, | |
9736 | (line_info_table_allocated | |
9737 | * sizeof (dw_line_info_entry))); | |
e90b62db | 9738 | } |
71dfc51f RK |
9739 | |
9740 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9741 | line_info = &line_info_table[line_info_table_in_use++]; |
9742 | line_info->dw_file_num = lookup_filename (filename); | |
9743 | line_info->dw_line_num = line; | |
a3f97cbb | 9744 | } |
a3f97cbb JW |
9745 | } |
9746 | } | |
9747 | ||
9748 | /* Record the beginning of a new source file, for later output | |
9749 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 9750 | |
a3f97cbb | 9751 | void |
9a666dda | 9752 | dwarf2out_start_source_file (filename) |
487a6e06 | 9753 | register char *filename ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9754 | { |
9755 | } | |
9756 | ||
9a666dda | 9757 | /* Record the end of a source file, for later output |
a3f97cbb | 9758 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 9759 | |
a3f97cbb | 9760 | void |
9a666dda | 9761 | dwarf2out_end_source_file () |
a3f97cbb JW |
9762 | { |
9763 | } | |
9764 | ||
9765 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9766 | the tail part of the directive line, i.e. the part which is past the | |
9767 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9768 | |
a3f97cbb | 9769 | void |
9a666dda | 9770 | dwarf2out_define (lineno, buffer) |
a3f97cbb JW |
9771 | register unsigned lineno; |
9772 | register char *buffer; | |
9773 | { | |
9774 | static int initialized = 0; | |
9775 | if (!initialized) | |
9776 | { | |
9a666dda | 9777 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
9778 | initialized = 1; |
9779 | } | |
9780 | } | |
9781 | ||
9782 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9783 | the tail part of the directive line, i.e. the part which is past the | |
9784 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9785 | |
a3f97cbb | 9786 | void |
9a666dda | 9787 | dwarf2out_undef (lineno, buffer) |
487a6e06 KG |
9788 | register unsigned lineno ATTRIBUTE_UNUSED; |
9789 | register char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb JW |
9790 | { |
9791 | } | |
9792 | ||
9793 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 9794 | |
a3f97cbb | 9795 | void |
9a666dda | 9796 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb JW |
9797 | register FILE *asm_out_file; |
9798 | register char *main_input_filename; | |
9799 | { | |
a3f97cbb JW |
9800 | /* Remember the name of the primary input file. */ |
9801 | primary_filename = main_input_filename; | |
9802 | ||
9803 | /* Allocate the initial hunk of the file_table. */ | |
9804 | file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *)); | |
b1ccbc24 | 9805 | bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *)); |
a3f97cbb | 9806 | file_table_allocated = FILE_TABLE_INCREMENT; |
71dfc51f RK |
9807 | |
9808 | /* Skip the first entry - file numbers begin at 1. */ | |
a3f97cbb JW |
9809 | file_table_in_use = 1; |
9810 | ||
a3f97cbb JW |
9811 | /* Allocate the initial hunk of the decl_die_table. */ |
9812 | decl_die_table | |
9813 | = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9814 | bzero ((char *) decl_die_table, |
9815 | DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb JW |
9816 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
9817 | decl_die_table_in_use = 0; | |
9818 | ||
9819 | /* Allocate the initial hunk of the decl_scope_table. */ | |
9820 | decl_scope_table | |
e3e7774e JW |
9821 | = (decl_scope_node *) xmalloc (DECL_SCOPE_TABLE_INCREMENT |
9822 | * sizeof (decl_scope_node)); | |
b1ccbc24 | 9823 | bzero ((char *) decl_scope_table, |
e3e7774e | 9824 | DECL_SCOPE_TABLE_INCREMENT * sizeof (decl_scope_node)); |
a3f97cbb JW |
9825 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
9826 | decl_scope_depth = 0; | |
9827 | ||
9828 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
9829 | abbrev_die_table | |
9830 | = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT | |
9831 | * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9832 | bzero ((char *) abbrev_die_table, |
9833 | ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb | 9834 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 9835 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9836 | abbrev_die_table_in_use = 1; |
9837 | ||
9838 | /* Allocate the initial hunk of the line_info_table. */ | |
9839 | line_info_table | |
9840 | = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT | |
9841 | * sizeof (dw_line_info_entry)); | |
b1ccbc24 RK |
9842 | bzero ((char *) line_info_table, |
9843 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
a3f97cbb | 9844 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 9845 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9846 | line_info_table_in_use = 1; |
9847 | ||
a3f97cbb JW |
9848 | /* Generate the initial DIE for the .debug section. Note that the (string) |
9849 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE | |
9850 | will (typically) be a relative pathname and that this pathname should be | |
9851 | taken as being relative to the directory from which the compiler was | |
9852 | invoked when the given (base) source file was compiled. */ | |
9853 | gen_compile_unit_die (main_input_filename); | |
9854 | ||
5c90448c | 9855 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
a3f97cbb JW |
9856 | } |
9857 | ||
9858 | /* Output stuff that dwarf requires at the end of every file, | |
9859 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 9860 | |
a3f97cbb | 9861 | void |
9a666dda | 9862 | dwarf2out_finish () |
a3f97cbb | 9863 | { |
ef76d03b JW |
9864 | limbo_die_node *node, *next_node; |
9865 | dw_die_ref die; | |
9866 | dw_attr_ref a; | |
9867 | ||
9868 | /* Traverse the limbo die list, and add parent/child links. The only | |
9869 | dies without parents that should be here are concrete instances of | |
9870 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
9871 | For concrete instances, we can get the parent die from the abstract | |
9872 | instance. */ | |
9873 | for (node = limbo_die_list; node; node = next_node) | |
9874 | { | |
9875 | next_node = node->next; | |
9876 | die = node->die; | |
9877 | ||
9878 | if (die->die_parent == NULL) | |
9879 | { | |
9880 | a = get_AT (die, DW_AT_abstract_origin); | |
9881 | if (a) | |
9882 | add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die); | |
9883 | else if (die == comp_unit_die) | |
9884 | ; | |
9885 | else | |
9886 | abort (); | |
9887 | } | |
9888 | free (node); | |
9889 | } | |
9890 | ||
a3f97cbb JW |
9891 | /* Traverse the DIE tree and add sibling attributes to those DIE's |
9892 | that have children. */ | |
9893 | add_sibling_attributes (comp_unit_die); | |
9894 | ||
9895 | /* Output a terminator label for the .text section. */ | |
9896 | fputc ('\n', asm_out_file); | |
9897 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
5c90448c | 9898 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 9899 | |
bdb669cb | 9900 | #if 0 |
a3f97cbb JW |
9901 | /* Output a terminator label for the .data section. */ |
9902 | fputc ('\n', asm_out_file); | |
9903 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
5c90448c | 9904 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
9905 | |
9906 | /* Output a terminator label for the .bss section. */ | |
9907 | fputc ('\n', asm_out_file); | |
9908 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
5c90448c | 9909 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 9910 | #endif |
a3f97cbb | 9911 | |
e90b62db JM |
9912 | /* Output the source line correspondence table. */ |
9913 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
9914 | { | |
9915 | fputc ('\n', asm_out_file); | |
c53aa195 | 9916 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
e90b62db JM |
9917 | output_line_info (); |
9918 | ||
9919 | /* We can only use the low/high_pc attributes if all of the code | |
9920 | was in .text. */ | |
9921 | if (separate_line_info_table_in_use == 0) | |
9922 | { | |
71208e03 JW |
9923 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, |
9924 | stripattributes (TEXT_SECTION)); | |
5c90448c | 9925 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); |
e90b62db | 9926 | } |
71dfc51f | 9927 | |
1553e85a | 9928 | add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION); |
e90b62db JM |
9929 | } |
9930 | ||
a3f97cbb JW |
9931 | /* Output the abbreviation table. */ |
9932 | fputc ('\n', asm_out_file); | |
9933 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
9934 | build_abbrev_table (comp_unit_die); | |
9935 | output_abbrev_section (); | |
9936 | ||
a3f97cbb JW |
9937 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
9938 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
9939 | calc_die_sizes (comp_unit_die); | |
9940 | ||
a3f97cbb JW |
9941 | /* Output debugging information. */ |
9942 | fputc ('\n', asm_out_file); | |
c53aa195 | 9943 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
a3f97cbb JW |
9944 | output_compilation_unit_header (); |
9945 | output_die (comp_unit_die); | |
9946 | ||
d291dd49 JM |
9947 | if (pubname_table_in_use) |
9948 | { | |
9949 | /* Output public names table. */ | |
9950 | fputc ('\n', asm_out_file); | |
9951 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
9952 | output_pubnames (); | |
9953 | } | |
9954 | ||
a3f97cbb JW |
9955 | if (fde_table_in_use) |
9956 | { | |
a3f97cbb JW |
9957 | /* Output the address range information. */ |
9958 | fputc ('\n', asm_out_file); | |
9959 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
9960 | output_aranges (); | |
9961 | } | |
9962 | } | |
9a666dda | 9963 | #endif /* DWARF2_DEBUGGING_INFO */ |