]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
06ceef4e RK |
2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
e9a25f70 JL |
4 | Contributed by Gary Funck (gary@intrepid.com). |
5 | Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). | |
469ac993 | 6 | Extensively modified by Jason Merrill (jason@cygnus.com). |
a3f97cbb JW |
7 | |
8 | This file is part of GNU CC. | |
9 | ||
10 | GNU CC is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GNU CC is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GNU CC; see the file COPYING. If not, write to | |
5f38fdda JL |
22 | the Free Software Foundation, 59 Temple Place - Suite 330, |
23 | Boston, MA 02111-1307, USA. */ | |
a3f97cbb | 24 | |
a96c67ec | 25 | /* TODO: Implement .debug_str handling, and share entries somehow. |
348bb3c7 JM |
26 | Eliminate duplicates by putting common info in a separate section |
27 | to be collected by the linker and referring to it with | |
28 | DW_FORM_ref_addr. | |
29 | Emit .debug_line header even when there are no functions, since | |
30 | the file numbers are used by .debug_info. Alternately, leave | |
31 | out locations for types and decls. | |
32 | Avoid talking about ctors and op= for PODs. | |
33 | Factor out common prologue sequences into multiple CIEs. */ | |
34 | ||
3f76745e JM |
35 | /* The first part of this file deals with the DWARF 2 frame unwind |
36 | information, which is also used by the GCC efficient exception handling | |
37 | mechanism. The second part, controlled only by an #ifdef | |
38 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
39 | information. */ | |
40 | ||
0021b564 | 41 | #include "config.h" |
670ee920 | 42 | #include "system.h" |
0021b564 | 43 | #include "defaults.h" |
a3f97cbb JW |
44 | #include "tree.h" |
45 | #include "flags.h" | |
46 | #include "rtl.h" | |
47 | #include "hard-reg-set.h" | |
48 | #include "regs.h" | |
49 | #include "insn-config.h" | |
50 | #include "reload.h" | |
51 | #include "output.h" | |
71dfc51f | 52 | #include "expr.h" |
3f76745e | 53 | #include "except.h" |
a7cc7f29 | 54 | #include "dwarf2.h" |
76ead72b | 55 | #include "dwarf2out.h" |
10f0ad3d | 56 | #include "toplev.h" |
1865dbb5 | 57 | #include "varray.h" |
951a525f | 58 | #include "ggc.h" |
57bed152 | 59 | #include "tm_p.h" |
a3f97cbb | 60 | |
c85f7c16 JL |
61 | /* We cannot use <assert.h> in GCC source, since that would include |
62 | GCC's assert.h, which may not be compatible with the host compiler. */ | |
63 | #undef assert | |
64 | #ifdef NDEBUG | |
65 | # define assert(e) | |
66 | #else | |
67 | # define assert(e) do { if (! (e)) abort (); } while (0) | |
68 | #endif | |
69 | ||
0021b564 JM |
70 | /* Decide whether we want to emit frame unwind information for the current |
71 | translation unit. */ | |
72 | ||
73 | int | |
74 | dwarf2out_do_frame () | |
75 | { | |
76 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 JL |
77 | #ifdef DWARF2_FRAME_INFO |
78 | || DWARF2_FRAME_INFO | |
79 | #endif | |
0021b564 | 80 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 81 | || flag_unwind_tables |
0021b564 JM |
82 | || (flag_exceptions && ! exceptions_via_longjmp) |
83 | #endif | |
84 | ); | |
85 | } | |
86 | ||
87 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
88 | ||
eaf95893 RK |
89 | /* How to start an assembler comment. */ |
90 | #ifndef ASM_COMMENT_START | |
91 | #define ASM_COMMENT_START ";#" | |
92 | #endif | |
93 | ||
a3f97cbb JW |
94 | typedef struct dw_cfi_struct *dw_cfi_ref; |
95 | typedef struct dw_fde_struct *dw_fde_ref; | |
96 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
97 | |
98 | /* Call frames are described using a sequence of Call Frame | |
99 | Information instructions. The register number, offset | |
100 | and address fields are provided as possible operands; | |
101 | their use is selected by the opcode field. */ | |
71dfc51f | 102 | |
a3f97cbb | 103 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
104 | { |
105 | unsigned long dw_cfi_reg_num; | |
106 | long int dw_cfi_offset; | |
107 | char *dw_cfi_addr; | |
108 | } | |
a3f97cbb JW |
109 | dw_cfi_oprnd; |
110 | ||
111 | typedef struct dw_cfi_struct | |
71dfc51f RK |
112 | { |
113 | dw_cfi_ref dw_cfi_next; | |
114 | enum dwarf_call_frame_info dw_cfi_opc; | |
115 | dw_cfi_oprnd dw_cfi_oprnd1; | |
116 | dw_cfi_oprnd dw_cfi_oprnd2; | |
117 | } | |
a3f97cbb JW |
118 | dw_cfi_node; |
119 | ||
120 | /* All call frame descriptions (FDE's) in the GCC generated DWARF | |
4b674448 | 121 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
122 | the beginning of the .debug_frame section. This used of a single |
123 | CIE obviates the need to keep track of multiple CIE's | |
124 | in the DWARF generation routines below. */ | |
71dfc51f | 125 | |
a3f97cbb | 126 | typedef struct dw_fde_struct |
71dfc51f | 127 | { |
71dfc51f RK |
128 | char *dw_fde_begin; |
129 | char *dw_fde_current_label; | |
130 | char *dw_fde_end; | |
131 | dw_cfi_ref dw_fde_cfi; | |
737faf14 | 132 | int nothrow; |
71dfc51f | 133 | } |
a3f97cbb JW |
134 | dw_fde_node; |
135 | ||
a3f97cbb JW |
136 | /* Maximum size (in bytes) of an artificially generated label. */ |
137 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
138 | ||
139 | /* Make sure we know the sizes of the various types dwarf can describe. These | |
140 | are only defaults. If the sizes are different for your target, you should | |
141 | override these values by defining the appropriate symbols in your tm.h | |
142 | file. */ | |
71dfc51f | 143 | |
a3f97cbb JW |
144 | #ifndef CHAR_TYPE_SIZE |
145 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
146 | #endif | |
a1a4189d JB |
147 | |
148 | /* The size of the target's pointer type. */ | |
a3f97cbb | 149 | #ifndef PTR_SIZE |
a9d38797 | 150 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
151 | #endif |
152 | ||
a1a4189d JB |
153 | /* The size of addresses as they appear in the Dwarf 2 data. |
154 | Some architectures use word addresses to refer to code locations, | |
155 | but Dwarf 2 info always uses byte addresses. On such machines, | |
156 | Dwarf 2 addresses need to be larger than the architecture's | |
157 | pointers. */ | |
158 | #ifndef DWARF2_ADDR_SIZE | |
159 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
160 | #endif | |
161 | ||
7e23cb16 | 162 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
163 | relative to a debug info section, specified to be 4 bytes in the |
164 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 165 | as PTR_SIZE. */ |
71dfc51f | 166 | |
7e23cb16 JM |
167 | #ifndef DWARF_OFFSET_SIZE |
168 | #define DWARF_OFFSET_SIZE 4 | |
169 | #endif | |
170 | ||
9a666dda JM |
171 | #define DWARF_VERSION 2 |
172 | ||
7e23cb16 JM |
173 | /* Round SIZE up to the nearest BOUNDARY. */ |
174 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 175 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 176 | |
a3f97cbb | 177 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
469ac993 | 178 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 179 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 180 | #else |
08cb3d38 | 181 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 182 | #endif |
a3f97cbb | 183 | |
3f76745e JM |
184 | /* A pointer to the base of a table that contains frame description |
185 | information for each routine. */ | |
186 | static dw_fde_ref fde_table; | |
a3f97cbb | 187 | |
3f76745e JM |
188 | /* Number of elements currently allocated for fde_table. */ |
189 | static unsigned fde_table_allocated; | |
a94dbf2c | 190 | |
3f76745e JM |
191 | /* Number of elements in fde_table currently in use. */ |
192 | static unsigned fde_table_in_use; | |
a3f97cbb | 193 | |
3f76745e JM |
194 | /* Size (in elements) of increments by which we may expand the |
195 | fde_table. */ | |
196 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 197 | |
a94dbf2c JM |
198 | /* A list of call frame insns for the CIE. */ |
199 | static dw_cfi_ref cie_cfi_head; | |
200 | ||
a3f97cbb JW |
201 | /* The number of the current function definition for which debugging |
202 | information is being generated. These numbers range from 1 up to the | |
203 | maximum number of function definitions contained within the current | |
204 | compilation unit. These numbers are used to create unique label id's | |
205 | unique to each function definition. */ | |
4f988ea2 | 206 | static unsigned current_funcdef_number = 0; |
a3f97cbb JW |
207 | |
208 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
209 | attribute that accelerates the lookup of the FDE associated | |
210 | with the subprogram. This variable holds the table index of the FDE | |
211 | associated with the current function (body) definition. */ | |
212 | static unsigned current_funcdef_fde; | |
213 | ||
a3f97cbb | 214 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 215 | |
83d2b3b9 KG |
216 | static char *stripattributes PARAMS ((const char *)); |
217 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
218 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
219 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
220 | static unsigned long size_of_uleb128 PARAMS ((unsigned long)); | |
221 | static unsigned long size_of_sleb128 PARAMS ((long)); | |
222 | static void output_uleb128 PARAMS ((unsigned long)); | |
223 | static void output_sleb128 PARAMS ((long)); | |
224 | static void add_fde_cfi PARAMS ((char *, dw_cfi_ref)); | |
225 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, unsigned long *, | |
226 | long *)); | |
227 | static void lookup_cfa PARAMS ((unsigned long *, long *)); | |
228 | static void reg_save PARAMS ((char *, unsigned, unsigned, | |
229 | long)); | |
230 | static void initial_return_save PARAMS ((rtx)); | |
231 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref)); | |
232 | static void output_call_frame_info PARAMS ((int)); | |
770ae6cc | 233 | static unsigned int reg_number PARAMS ((rtx)); |
83d2b3b9 KG |
234 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
235 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, char *)); | |
a3f97cbb JW |
236 | |
237 | /* Definitions of defaults for assembler-dependent names of various | |
238 | pseudo-ops and section names. | |
239 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
240 | assembler. */ | |
71dfc51f | 241 | |
0021b564 | 242 | #ifdef OBJECT_FORMAT_ELF |
a3f97cbb JW |
243 | #ifndef UNALIGNED_SHORT_ASM_OP |
244 | #define UNALIGNED_SHORT_ASM_OP ".2byte" | |
245 | #endif | |
246 | #ifndef UNALIGNED_INT_ASM_OP | |
247 | #define UNALIGNED_INT_ASM_OP ".4byte" | |
248 | #endif | |
7e23cb16 JM |
249 | #ifndef UNALIGNED_DOUBLE_INT_ASM_OP |
250 | #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte" | |
251 | #endif | |
0021b564 JM |
252 | #endif /* OBJECT_FORMAT_ELF */ |
253 | ||
a3f97cbb JW |
254 | #ifndef ASM_BYTE_OP |
255 | #define ASM_BYTE_OP ".byte" | |
256 | #endif | |
257 | ||
7e23cb16 JM |
258 | /* Data and reference forms for relocatable data. */ |
259 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
260 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
261 | ||
a3f97cbb JW |
262 | /* Pseudo-op for defining a new section. */ |
263 | #ifndef SECTION_ASM_OP | |
264 | #define SECTION_ASM_OP ".section" | |
265 | #endif | |
266 | ||
267 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
268 | print the SECTION_ASM_OP and the section name. The default here works for | |
269 | almost all svr4 assemblers, except for the sparc, where the section name | |
270 | must be enclosed in double quotes. (See sparcv4.h). */ | |
271 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
272 | #ifdef PUSHSECTION_FORMAT |
273 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
274 | #else | |
275 | #define SECTION_FORMAT "\t%s\t%s\n" | |
276 | #endif | |
a3f97cbb JW |
277 | #endif |
278 | ||
a3f97cbb JW |
279 | #ifndef FRAME_SECTION |
280 | #define FRAME_SECTION ".debug_frame" | |
281 | #endif | |
a3f97cbb | 282 | |
5c90448c JM |
283 | #ifndef FUNC_BEGIN_LABEL |
284 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 285 | #endif |
5c90448c JM |
286 | #ifndef FUNC_END_LABEL |
287 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 288 | #endif |
a6ab3aad JM |
289 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
290 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 291 | #define CIE_LENGTH_LABEL "LLCIE" |
a6ab3aad JM |
292 | #define FDE_AFTER_SIZE_LABEL "LSFDE" |
293 | #define FDE_END_LABEL "LEFDE" | |
2ed2af28 | 294 | #define FDE_LENGTH_LABEL "LLFDE" |
a3f97cbb | 295 | |
a3f97cbb JW |
296 | /* Definitions of defaults for various types of primitive assembly language |
297 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 298 | but typically, that is unnecessary. */ |
71dfc51f | 299 | |
a3f97cbb JW |
300 | #ifndef ASM_OUTPUT_SECTION |
301 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
302 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
303 | #endif | |
304 | ||
0021b564 JM |
305 | #ifndef ASM_OUTPUT_DWARF_DATA1 |
306 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
32bd96ff | 307 | fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE)) |
0021b564 JM |
308 | #endif |
309 | ||
bb727b5a JM |
310 | #ifndef ASM_OUTPUT_DWARF_DELTA1 |
311 | #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \ | |
312 | do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \ | |
313 | assemble_name (FILE, LABEL1); \ | |
314 | fprintf (FILE, "-"); \ | |
315 | assemble_name (FILE, LABEL2); \ | |
316 | } while (0) | |
317 | #endif | |
318 | ||
0021b564 JM |
319 | #ifdef UNALIGNED_INT_ASM_OP |
320 | ||
321 | #ifndef UNALIGNED_OFFSET_ASM_OP | |
322 | #define UNALIGNED_OFFSET_ASM_OP \ | |
323 | (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
324 | #endif | |
325 | ||
326 | #ifndef UNALIGNED_WORD_ASM_OP | |
a1a4189d JB |
327 | #define UNALIGNED_WORD_ASM_OP \ |
328 | ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \ | |
329 | : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \ | |
330 | : UNALIGNED_INT_ASM_OP) | |
0021b564 JM |
331 | #endif |
332 | ||
a3f97cbb JW |
333 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
334 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
335 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ | |
336 | assemble_name (FILE, LABEL1); \ | |
337 | fprintf (FILE, "-"); \ | |
338 | assemble_name (FILE, LABEL2); \ | |
339 | } while (0) | |
340 | #endif | |
341 | ||
342 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
343 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
344 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
345 | assemble_name (FILE, LABEL1); \ | |
346 | fprintf (FILE, "-"); \ | |
347 | assemble_name (FILE, LABEL2); \ | |
348 | } while (0) | |
349 | #endif | |
350 | ||
7e23cb16 JM |
351 | #ifndef ASM_OUTPUT_DWARF_DELTA |
352 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
353 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
354 | assemble_name (FILE, LABEL1); \ | |
355 | fprintf (FILE, "-"); \ | |
356 | assemble_name (FILE, LABEL2); \ | |
357 | } while (0) | |
358 | #endif | |
359 | ||
360 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA | |
361 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
362 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ | |
363 | assemble_name (FILE, LABEL1); \ | |
364 | fprintf (FILE, "-"); \ | |
365 | assemble_name (FILE, LABEL2); \ | |
366 | } while (0) | |
367 | #endif | |
368 | ||
a3f97cbb JW |
369 | #ifndef ASM_OUTPUT_DWARF_ADDR |
370 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
7e23cb16 | 371 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ |
a3f97cbb JW |
372 | assemble_name (FILE, LABEL); \ |
373 | } while (0) | |
374 | #endif | |
375 | ||
376 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
1865dbb5 JM |
377 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ |
378 | do { \ | |
262b6384 | 379 | fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ |
1865dbb5 | 380 | output_addr_const ((FILE), (RTX)); \ |
1865dbb5 | 381 | } while (0) |
7e23cb16 JM |
382 | #endif |
383 | ||
7bb9fb0e JM |
384 | #ifndef ASM_OUTPUT_DWARF_OFFSET4 |
385 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ | |
386 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
387 | assemble_name (FILE, LABEL); \ | |
388 | } while (0) | |
389 | #endif | |
390 | ||
7e23cb16 JM |
391 | #ifndef ASM_OUTPUT_DWARF_OFFSET |
392 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ | |
393 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
394 | assemble_name (FILE, LABEL); \ | |
395 | } while (0) | |
a3f97cbb JW |
396 | #endif |
397 | ||
a3f97cbb JW |
398 | #ifndef ASM_OUTPUT_DWARF_DATA2 |
399 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
32bd96ff | 400 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
401 | #endif |
402 | ||
403 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
404 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
32bd96ff | 405 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
406 | #endif |
407 | ||
7e23cb16 JM |
408 | #ifndef ASM_OUTPUT_DWARF_DATA |
409 | #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \ | |
410 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \ | |
32bd96ff | 411 | (unsigned long) (VALUE)) |
7e23cb16 JM |
412 | #endif |
413 | ||
414 | #ifndef ASM_OUTPUT_DWARF_ADDR_DATA | |
415 | #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \ | |
416 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \ | |
32bd96ff | 417 | (unsigned long) (VALUE)) |
7e23cb16 JM |
418 | #endif |
419 | ||
a3f97cbb JW |
420 | #ifndef ASM_OUTPUT_DWARF_DATA8 |
421 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
422 | do { \ | |
423 | if (WORDS_BIG_ENDIAN) \ | |
424 | { \ | |
32bd96ff JM |
425 | fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\ |
426 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\ | |
a3f97cbb JW |
427 | } \ |
428 | else \ | |
429 | { \ | |
32bd96ff JM |
430 | fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \ |
431 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \ | |
a3f97cbb JW |
432 | } \ |
433 | } while (0) | |
434 | #endif | |
435 | ||
0021b564 JM |
436 | #else /* UNALIGNED_INT_ASM_OP */ |
437 | ||
438 | /* We don't have unaligned support, let's hope the normal output works for | |
439 | .debug_frame. */ | |
440 | ||
441 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
a1a4189d | 442 | assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1) |
0021b564 | 443 | |
7bb9fb0e | 444 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ |
38a448ca | 445 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
7bb9fb0e | 446 | |
0021b564 | 447 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ |
38a448ca | 448 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
0021b564 JM |
449 | |
450 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
38a448ca | 451 | assemble_integer (gen_rtx_MINUS (HImode, \ |
c5c76735 JL |
452 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
453 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
454 | 2, 1) |
455 | ||
456 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
38a448ca | 457 | assemble_integer (gen_rtx_MINUS (SImode, \ |
c5c76735 JL |
458 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
459 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 JM |
460 | 4, 1) |
461 | ||
462 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
38a448ca | 463 | assemble_integer (gen_rtx_MINUS (Pmode, \ |
c5c76735 JL |
464 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
465 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
a1a4189d | 466 | DWARF2_ADDR_SIZE, 1) |
0021b564 JM |
467 | |
468 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
469 | ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2) | |
470 | ||
471 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
472 | assemble_integer (GEN_INT (VALUE), 4, 1) | |
473 | ||
474 | #endif /* UNALIGNED_INT_ASM_OP */ | |
475 | ||
2ed2af28 PDM |
476 | #ifdef SET_ASM_OP |
477 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
478 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
479 | do { \ | |
480 | fprintf (FILE, "\t%s\t", SET_ASM_OP); \ | |
481 | assemble_name (FILE, SY); \ | |
482 | fputc (',', FILE); \ | |
483 | assemble_name (FILE, HI); \ | |
484 | fputc ('-', FILE); \ | |
485 | assemble_name (FILE, LO); \ | |
486 | } while (0) | |
2ed2af28 PDM |
487 | #endif |
488 | #endif /* SET_ASM_OP */ | |
489 | ||
a6ab3aad | 490 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing |
2ed2af28 | 491 | newline is produced. When flag_debug_asm is asserted, we add commentary |
a6ab3aad JM |
492 | at the end of the line, so we must avoid output of a newline here. */ |
493 | #ifndef ASM_OUTPUT_DWARF_STRING | |
494 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
495 | do { \ | |
496 | register int slen = strlen(P); \ | |
d560ee52 | 497 | register const char *p = (P); \ |
a6ab3aad JM |
498 | register int i; \ |
499 | fprintf (FILE, "\t.ascii \""); \ | |
500 | for (i = 0; i < slen; i++) \ | |
501 | { \ | |
502 | register int c = p[i]; \ | |
503 | if (c == '\"' || c == '\\') \ | |
504 | putc ('\\', FILE); \ | |
f3ad1f9c | 505 | if (ISPRINT(c)) \ |
a6ab3aad JM |
506 | putc (c, FILE); \ |
507 | else \ | |
508 | { \ | |
509 | fprintf (FILE, "\\%o", c); \ | |
510 | } \ | |
511 | } \ | |
512 | fprintf (FILE, "\\0\""); \ | |
513 | } \ | |
514 | while (0) | |
515 | #endif | |
516 | ||
c8cc5c4a | 517 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
518 | is the column for PC, or the first column after all of the hard |
519 | registers. */ | |
c8cc5c4a | 520 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
521 | #ifdef PC_REGNUM |
522 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
523 | #else | |
3073d01c | 524 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 525 | #endif |
c8cc5c4a JM |
526 | #endif |
527 | ||
528 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 529 | default, we just provide columns for all registers. */ |
c8cc5c4a | 530 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 531 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 532 | #endif |
3f76745e | 533 | |
0021b564 JM |
534 | /* Hook used by __throw. */ |
535 | ||
536 | rtx | |
537 | expand_builtin_dwarf_fp_regnum () | |
538 | { | |
539 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
540 | } | |
541 | ||
a6ab3aad JM |
542 | /* The offset from the incoming value of %sp to the top of the stack frame |
543 | for the current function. */ | |
544 | #ifndef INCOMING_FRAME_SP_OFFSET | |
545 | #define INCOMING_FRAME_SP_OFFSET 0 | |
546 | #endif | |
547 | ||
71dfc51f | 548 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 549 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
550 | |
551 | static inline char * | |
a3f97cbb | 552 | stripattributes (s) |
d560ee52 | 553 | const char *s; |
a3f97cbb | 554 | { |
bf20f341 | 555 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
556 | char *p = stripped; |
557 | ||
bf20f341 JW |
558 | *p++ = '*'; |
559 | ||
560 | while (*s && *s != ',') | |
561 | *p++ = *s++; | |
71dfc51f | 562 | |
a3f97cbb JW |
563 | *p = '\0'; |
564 | return stripped; | |
565 | } | |
566 | ||
3f76745e | 567 | /* Return the register number described by a given RTL node. */ |
71dfc51f | 568 | |
770ae6cc | 569 | static unsigned int |
3f76745e JM |
570 | reg_number (rtl) |
571 | register rtx rtl; | |
a3f97cbb | 572 | { |
3f76745e | 573 | register unsigned regno = REGNO (rtl); |
a3f97cbb | 574 | |
2c849145 | 575 | if (regno >= FIRST_PSEUDO_REGISTER) |
a3f97cbb | 576 | { |
3f76745e JM |
577 | warning ("internal regno botch: regno = %d\n", regno); |
578 | regno = 0; | |
579 | } | |
a3f97cbb | 580 | |
3f76745e JM |
581 | regno = DBX_REGISTER_NUMBER (regno); |
582 | return regno; | |
583 | } | |
a3f97cbb | 584 | |
d9d5c9de | 585 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 586 | |
d9d5c9de BS |
587 | void |
588 | expand_builtin_init_dwarf_reg_sizes (address) | |
589 | tree address; | |
2f3ca9e7 | 590 | { |
d9d5c9de BS |
591 | int i; |
592 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
593 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
594 | rtx mem = gen_rtx_MEM (mode, addr); | |
2f3ca9e7 | 595 | |
3073d01c | 596 | for (i = 0; i < DWARF_FRAME_REGISTERS; ++i) |
2f3ca9e7 | 597 | { |
d9d5c9de BS |
598 | int offset = i * GET_MODE_SIZE (mode); |
599 | int size = GET_MODE_SIZE (reg_raw_mode[i]); | |
2f3ca9e7 | 600 | |
d9d5c9de BS |
601 | emit_move_insn (change_address (mem, mode, |
602 | plus_constant (addr, offset)), | |
603 | GEN_INT (size)); | |
2f3ca9e7 | 604 | } |
2f3ca9e7 JM |
605 | } |
606 | ||
3f76745e | 607 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 608 | |
d560ee52 | 609 | static const char * |
3f76745e JM |
610 | dwarf_cfi_name (cfi_opc) |
611 | register unsigned cfi_opc; | |
612 | { | |
613 | switch (cfi_opc) | |
614 | { | |
615 | case DW_CFA_advance_loc: | |
616 | return "DW_CFA_advance_loc"; | |
617 | case DW_CFA_offset: | |
618 | return "DW_CFA_offset"; | |
619 | case DW_CFA_restore: | |
620 | return "DW_CFA_restore"; | |
621 | case DW_CFA_nop: | |
622 | return "DW_CFA_nop"; | |
623 | case DW_CFA_set_loc: | |
624 | return "DW_CFA_set_loc"; | |
625 | case DW_CFA_advance_loc1: | |
626 | return "DW_CFA_advance_loc1"; | |
627 | case DW_CFA_advance_loc2: | |
628 | return "DW_CFA_advance_loc2"; | |
629 | case DW_CFA_advance_loc4: | |
630 | return "DW_CFA_advance_loc4"; | |
631 | case DW_CFA_offset_extended: | |
632 | return "DW_CFA_offset_extended"; | |
633 | case DW_CFA_restore_extended: | |
634 | return "DW_CFA_restore_extended"; | |
635 | case DW_CFA_undefined: | |
636 | return "DW_CFA_undefined"; | |
637 | case DW_CFA_same_value: | |
638 | return "DW_CFA_same_value"; | |
639 | case DW_CFA_register: | |
640 | return "DW_CFA_register"; | |
641 | case DW_CFA_remember_state: | |
642 | return "DW_CFA_remember_state"; | |
643 | case DW_CFA_restore_state: | |
644 | return "DW_CFA_restore_state"; | |
645 | case DW_CFA_def_cfa: | |
646 | return "DW_CFA_def_cfa"; | |
647 | case DW_CFA_def_cfa_register: | |
648 | return "DW_CFA_def_cfa_register"; | |
649 | case DW_CFA_def_cfa_offset: | |
650 | return "DW_CFA_def_cfa_offset"; | |
c53aa195 | 651 | |
3f76745e JM |
652 | /* SGI/MIPS specific */ |
653 | case DW_CFA_MIPS_advance_loc8: | |
654 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
655 | |
656 | /* GNU extensions */ | |
657 | case DW_CFA_GNU_window_save: | |
658 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
659 | case DW_CFA_GNU_args_size: |
660 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
661 | case DW_CFA_GNU_negative_offset_extended: |
662 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 663 | |
3f76745e JM |
664 | default: |
665 | return "DW_CFA_<unknown>"; | |
666 | } | |
667 | } | |
a3f97cbb | 668 | |
3f76745e | 669 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 670 | |
3f76745e JM |
671 | static inline dw_cfi_ref |
672 | new_cfi () | |
673 | { | |
674 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 675 | |
3f76745e JM |
676 | cfi->dw_cfi_next = NULL; |
677 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
678 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 679 | |
3f76745e JM |
680 | return cfi; |
681 | } | |
a3f97cbb | 682 | |
3f76745e | 683 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 684 | |
3f76745e JM |
685 | static inline void |
686 | add_cfi (list_head, cfi) | |
687 | register dw_cfi_ref *list_head; | |
688 | register dw_cfi_ref cfi; | |
689 | { | |
690 | register dw_cfi_ref *p; | |
a3f97cbb | 691 | |
3f76745e JM |
692 | /* Find the end of the chain. */ |
693 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
694 | ; | |
695 | ||
696 | *p = cfi; | |
a3f97cbb JW |
697 | } |
698 | ||
3f76745e | 699 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 700 | |
c53aa195 | 701 | char * |
3f76745e | 702 | dwarf2out_cfi_label () |
a3f97cbb | 703 | { |
3f76745e JM |
704 | static char label[20]; |
705 | static unsigned long label_num = 0; | |
706 | ||
707 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); | |
708 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
709 | ||
710 | return label; | |
a3f97cbb JW |
711 | } |
712 | ||
3f76745e JM |
713 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
714 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 715 | |
3f76745e JM |
716 | static void |
717 | add_fde_cfi (label, cfi) | |
718 | register char *label; | |
719 | register dw_cfi_ref cfi; | |
a3f97cbb | 720 | { |
3f76745e JM |
721 | if (label) |
722 | { | |
723 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 724 | |
3f76745e JM |
725 | if (*label == 0) |
726 | label = dwarf2out_cfi_label (); | |
71dfc51f | 727 | |
3f76745e JM |
728 | if (fde->dw_fde_current_label == NULL |
729 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
730 | { | |
731 | register dw_cfi_ref xcfi; | |
a3f97cbb | 732 | |
3f76745e | 733 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 734 | |
3f76745e JM |
735 | /* Set the location counter to the new label. */ |
736 | xcfi = new_cfi (); | |
737 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
738 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
739 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
740 | } | |
71dfc51f | 741 | |
3f76745e JM |
742 | add_cfi (&fde->dw_fde_cfi, cfi); |
743 | } | |
744 | ||
745 | else | |
746 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
747 | } |
748 | ||
3f76745e | 749 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 750 | |
3f76745e JM |
751 | static inline void |
752 | lookup_cfa_1 (cfi, regp, offsetp) | |
753 | register dw_cfi_ref cfi; | |
754 | register unsigned long *regp; | |
755 | register long *offsetp; | |
a3f97cbb | 756 | { |
3f76745e JM |
757 | switch (cfi->dw_cfi_opc) |
758 | { | |
759 | case DW_CFA_def_cfa_offset: | |
760 | *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset; | |
761 | break; | |
762 | case DW_CFA_def_cfa_register: | |
763 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
764 | break; | |
765 | case DW_CFA_def_cfa: | |
766 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
767 | *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
768 | break; | |
e9a25f70 JL |
769 | default: |
770 | break; | |
3f76745e | 771 | } |
a3f97cbb JW |
772 | } |
773 | ||
3f76745e | 774 | /* Find the previous value for the CFA. */ |
71dfc51f | 775 | |
3f76745e JM |
776 | static void |
777 | lookup_cfa (regp, offsetp) | |
778 | register unsigned long *regp; | |
779 | register long *offsetp; | |
a3f97cbb | 780 | { |
3f76745e JM |
781 | register dw_cfi_ref cfi; |
782 | ||
783 | *regp = (unsigned long) -1; | |
784 | *offsetp = 0; | |
785 | ||
786 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
787 | lookup_cfa_1 (cfi, regp, offsetp); | |
788 | ||
789 | if (fde_table_in_use) | |
a3f97cbb | 790 | { |
3f76745e JM |
791 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
792 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
793 | lookup_cfa_1 (cfi, regp, offsetp); | |
a3f97cbb JW |
794 | } |
795 | } | |
796 | ||
3f76745e | 797 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
a6ab3aad | 798 | static unsigned long cfa_reg; |
3f76745e | 799 | static long cfa_offset; |
71dfc51f | 800 | |
3f76745e JM |
801 | /* The register used for saving registers to the stack, and its offset |
802 | from the CFA. */ | |
803 | static unsigned cfa_store_reg; | |
804 | static long cfa_store_offset; | |
805 | ||
0021b564 JM |
806 | /* The running total of the size of arguments pushed onto the stack. */ |
807 | static long args_size; | |
808 | ||
b57d9225 JM |
809 | /* The last args_size we actually output. */ |
810 | static long old_args_size; | |
811 | ||
3f76745e JM |
812 | /* Entry point to update the canonical frame address (CFA). |
813 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
814 | calculated from REG+OFFSET. */ | |
815 | ||
816 | void | |
817 | dwarf2out_def_cfa (label, reg, offset) | |
818 | register char *label; | |
819 | register unsigned reg; | |
820 | register long offset; | |
a3f97cbb | 821 | { |
3f76745e JM |
822 | register dw_cfi_ref cfi; |
823 | unsigned long old_reg; | |
824 | long old_offset; | |
825 | ||
5bef9b1f JM |
826 | cfa_reg = reg; |
827 | cfa_offset = offset; | |
828 | if (cfa_store_reg == reg) | |
829 | cfa_store_offset = offset; | |
830 | ||
3f76745e JM |
831 | reg = DWARF_FRAME_REGNUM (reg); |
832 | lookup_cfa (&old_reg, &old_offset); | |
833 | ||
834 | if (reg == old_reg && offset == old_offset) | |
835 | return; | |
836 | ||
837 | cfi = new_cfi (); | |
838 | ||
839 | if (reg == old_reg) | |
a3f97cbb | 840 | { |
3f76745e JM |
841 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
842 | cfi->dw_cfi_oprnd1.dw_cfi_offset = offset; | |
843 | } | |
a3f97cbb | 844 | |
3f76745e JM |
845 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
846 | else if (offset == old_offset && old_reg != (unsigned long) -1) | |
847 | { | |
848 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; | |
849 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
850 | } | |
851 | #endif | |
a3f97cbb | 852 | |
3f76745e JM |
853 | else |
854 | { | |
855 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
856 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
857 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
a3f97cbb | 858 | } |
3f76745e JM |
859 | |
860 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
861 | } |
862 | ||
3f76745e JM |
863 | /* Add the CFI for saving a register. REG is the CFA column number. |
864 | LABEL is passed to add_fde_cfi. | |
865 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
866 | otherwise it is saved in SREG. */ | |
71dfc51f | 867 | |
3f76745e JM |
868 | static void |
869 | reg_save (label, reg, sreg, offset) | |
870 | register char * label; | |
871 | register unsigned reg; | |
872 | register unsigned sreg; | |
873 | register long offset; | |
a3f97cbb | 874 | { |
3f76745e JM |
875 | register dw_cfi_ref cfi = new_cfi (); |
876 | ||
877 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
878 | ||
85066503 MH |
879 | /* The following comparison is correct. -1 is used to indicate that |
880 | the value isn't a register number. */ | |
881 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 882 | { |
3f76745e JM |
883 | if (reg & ~0x3f) |
884 | /* The register number won't fit in 6 bits, so we have to use | |
885 | the long form. */ | |
886 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
887 | else | |
888 | cfi->dw_cfi_opc = DW_CFA_offset; | |
889 | ||
890 | offset /= DWARF_CIE_DATA_ALIGNMENT; | |
3a88cbd1 | 891 | if (offset < 0) |
3f388b42 GK |
892 | { |
893 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
894 | offset = -offset; | |
895 | } | |
3f76745e JM |
896 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
897 | } | |
2c849145 JM |
898 | else if (sreg == reg) |
899 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
900 | return; | |
3f76745e JM |
901 | else |
902 | { | |
903 | cfi->dw_cfi_opc = DW_CFA_register; | |
904 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
905 | } | |
906 | ||
907 | add_fde_cfi (label, cfi); | |
908 | } | |
909 | ||
c53aa195 JM |
910 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
911 | This CFI tells the unwinder that it needs to restore the window registers | |
912 | from the previous frame's window save area. | |
913 | ||
914 | ??? Perhaps we should note in the CIE where windows are saved (instead of | |
915 | assuming 0(cfa)) and what registers are in the window. */ | |
916 | ||
917 | void | |
918 | dwarf2out_window_save (label) | |
919 | register char * label; | |
920 | { | |
921 | register dw_cfi_ref cfi = new_cfi (); | |
922 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
923 | add_fde_cfi (label, cfi); | |
924 | } | |
925 | ||
0021b564 JM |
926 | /* Add a CFI to update the running total of the size of arguments |
927 | pushed onto the stack. */ | |
928 | ||
929 | void | |
930 | dwarf2out_args_size (label, size) | |
931 | char *label; | |
932 | long size; | |
933 | { | |
b57d9225 JM |
934 | register dw_cfi_ref cfi; |
935 | ||
936 | if (size == old_args_size) | |
937 | return; | |
938 | old_args_size = size; | |
939 | ||
940 | cfi = new_cfi (); | |
0021b564 JM |
941 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
942 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
943 | add_fde_cfi (label, cfi); | |
944 | } | |
945 | ||
c53aa195 JM |
946 | /* Entry point for saving a register to the stack. REG is the GCC register |
947 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
948 | |
949 | void | |
950 | dwarf2out_reg_save (label, reg, offset) | |
951 | register char * label; | |
952 | register unsigned reg; | |
953 | register long offset; | |
954 | { | |
955 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
956 | } | |
957 | ||
c53aa195 JM |
958 | /* Entry point for saving the return address in the stack. |
959 | LABEL and OFFSET are passed to reg_save. */ | |
960 | ||
961 | void | |
962 | dwarf2out_return_save (label, offset) | |
963 | register char * label; | |
964 | register long offset; | |
965 | { | |
966 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
967 | } | |
968 | ||
969 | /* Entry point for saving the return address in a register. | |
970 | LABEL and SREG are passed to reg_save. */ | |
971 | ||
972 | void | |
973 | dwarf2out_return_reg (label, sreg) | |
974 | register char * label; | |
975 | register unsigned sreg; | |
976 | { | |
977 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
978 | } | |
979 | ||
3f76745e JM |
980 | /* Record the initial position of the return address. RTL is |
981 | INCOMING_RETURN_ADDR_RTX. */ | |
982 | ||
983 | static void | |
984 | initial_return_save (rtl) | |
985 | register rtx rtl; | |
986 | { | |
973838fd | 987 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
988 | long offset = 0; |
989 | ||
990 | switch (GET_CODE (rtl)) | |
991 | { | |
992 | case REG: | |
993 | /* RA is in a register. */ | |
2c849145 | 994 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e JM |
995 | break; |
996 | case MEM: | |
997 | /* RA is on the stack. */ | |
998 | rtl = XEXP (rtl, 0); | |
999 | switch (GET_CODE (rtl)) | |
1000 | { | |
1001 | case REG: | |
3a88cbd1 JL |
1002 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
1003 | abort (); | |
3f76745e JM |
1004 | offset = 0; |
1005 | break; | |
1006 | case PLUS: | |
3a88cbd1 JL |
1007 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1008 | abort (); | |
3f76745e JM |
1009 | offset = INTVAL (XEXP (rtl, 1)); |
1010 | break; | |
1011 | case MINUS: | |
3a88cbd1 JL |
1012 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1013 | abort (); | |
3f76745e JM |
1014 | offset = -INTVAL (XEXP (rtl, 1)); |
1015 | break; | |
1016 | default: | |
1017 | abort (); | |
1018 | } | |
1019 | break; | |
c53aa195 JM |
1020 | case PLUS: |
1021 | /* The return address is at some offset from any value we can | |
1022 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
1023 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
1024 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
1025 | abort (); | |
c53aa195 JM |
1026 | initial_return_save (XEXP (rtl, 0)); |
1027 | return; | |
a3f97cbb | 1028 | default: |
3f76745e | 1029 | abort (); |
a3f97cbb | 1030 | } |
3f76745e | 1031 | |
a6ab3aad | 1032 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset); |
a3f97cbb JW |
1033 | } |
1034 | ||
0021b564 JM |
1035 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1036 | make a note of it if it does. EH uses this information to find out how | |
1037 | much extra space it needs to pop off the stack. */ | |
1038 | ||
1039 | static void | |
1040 | dwarf2out_stack_adjust (insn) | |
1041 | rtx insn; | |
1042 | { | |
0021b564 JM |
1043 | long offset; |
1044 | char *label; | |
1045 | ||
b57d9225 JM |
1046 | if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN) |
1047 | { | |
1048 | /* Extract the size of the args from the CALL rtx itself. */ | |
1049 | ||
1050 | insn = PATTERN (insn); | |
1051 | if (GET_CODE (insn) == PARALLEL) | |
1052 | insn = XVECEXP (insn, 0, 0); | |
1053 | if (GET_CODE (insn) == SET) | |
1054 | insn = SET_SRC (insn); | |
1055 | assert (GET_CODE (insn) == CALL); | |
1056 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); | |
1057 | return; | |
1058 | } | |
1059 | ||
1060 | /* If only calls can throw, and we have a frame pointer, | |
1061 | save up adjustments until we see the CALL_INSN. */ | |
1062 | else if (! asynchronous_exceptions | |
1063 | && cfa_reg != STACK_POINTER_REGNUM) | |
1064 | return; | |
1065 | ||
6020d360 | 1066 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1067 | { |
6020d360 JM |
1068 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1069 | the compiler will have already emitted a stack adjustment, but | |
1070 | doesn't bother for calls to noreturn functions. */ | |
1071 | #ifdef STACK_GROWS_DOWNWARD | |
1072 | offset = -args_size; | |
1073 | #else | |
1074 | offset = args_size; | |
1075 | #endif | |
0021b564 | 1076 | } |
6020d360 | 1077 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 1078 | { |
6020d360 JM |
1079 | rtx src, dest; |
1080 | enum rtx_code code; | |
1081 | ||
1082 | insn = PATTERN (insn); | |
1083 | src = SET_SRC (insn); | |
1084 | dest = SET_DEST (insn); | |
0021b564 | 1085 | |
6020d360 JM |
1086 | if (dest == stack_pointer_rtx) |
1087 | { | |
1088 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
1089 | code = GET_CODE (src); | |
1090 | if (! (code == PLUS || code == MINUS) | |
1091 | || XEXP (src, 0) != stack_pointer_rtx | |
1092 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1093 | return; | |
1094 | ||
1095 | offset = INTVAL (XEXP (src, 1)); | |
1096 | } | |
1097 | else if (GET_CODE (dest) == MEM) | |
1098 | { | |
1099 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1100 | src = XEXP (dest, 0); | |
1101 | code = GET_CODE (src); | |
1102 | ||
1103 | if (! (code == PRE_DEC || code == PRE_INC) | |
1104 | || XEXP (src, 0) != stack_pointer_rtx) | |
1105 | return; | |
1106 | ||
1107 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1108 | } | |
1109 | else | |
0021b564 JM |
1110 | return; |
1111 | ||
6020d360 JM |
1112 | if (code == PLUS || code == PRE_INC) |
1113 | offset = -offset; | |
0021b564 JM |
1114 | } |
1115 | else | |
1116 | return; | |
1117 | ||
6020d360 JM |
1118 | if (offset == 0) |
1119 | return; | |
1120 | ||
0021b564 JM |
1121 | if (cfa_reg == STACK_POINTER_REGNUM) |
1122 | cfa_offset += offset; | |
1123 | ||
1124 | #ifndef STACK_GROWS_DOWNWARD | |
1125 | offset = -offset; | |
1126 | #endif | |
1127 | args_size += offset; | |
1128 | if (args_size < 0) | |
1129 | args_size = 0; | |
1130 | ||
1131 | label = dwarf2out_cfi_label (); | |
1132 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1133 | dwarf2out_args_size (label, args_size); | |
1134 | } | |
1135 | ||
b664de3a AM |
1136 | /* A temporary register used in adjusting SP or setting up the store_reg. */ |
1137 | static unsigned cfa_temp_reg; | |
1138 | ||
1139 | /* A temporary value used in adjusting SP or setting up the store_reg. */ | |
1140 | static long cfa_temp_value; | |
1141 | ||
1142 | /* Record call frame debugging information for an expression, which either | |
1143 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1144 | register to the stack. */ | |
1145 | ||
1146 | static void | |
1147 | dwarf2out_frame_debug_expr (expr, label) | |
1148 | rtx expr; | |
1149 | char *label; | |
1150 | { | |
1151 | rtx src, dest; | |
1152 | long offset; | |
1153 | ||
1154 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1155 | the PARALLEL independantly. The first element is always processed if | |
1156 | it is a SET. This is for backward compatability. Other elements | |
1157 | are processed only if they are SETs and the RTX_FRAME_RELATED_P | |
1158 | flag is set in them. */ | |
1159 | ||
1160 | if (GET_CODE (expr) == PARALLEL) | |
1161 | { | |
1162 | int par_index; | |
1163 | int limit = XVECLEN (expr, 0); | |
1164 | ||
1165 | for (par_index = 0; par_index < limit; par_index++) | |
1166 | { | |
1167 | rtx x = XVECEXP (expr, 0, par_index); | |
1168 | ||
1169 | if (GET_CODE (x) == SET && | |
1170 | (RTX_FRAME_RELATED_P (x) || par_index == 0)) | |
2618f955 | 1171 | dwarf2out_frame_debug_expr (x, label); |
b664de3a AM |
1172 | } |
1173 | return; | |
1174 | } | |
1175 | ||
1176 | if (GET_CODE (expr) != SET) | |
1177 | abort (); | |
1178 | ||
1179 | src = SET_SRC (expr); | |
1180 | dest = SET_DEST (expr); | |
1181 | ||
1182 | switch (GET_CODE (dest)) | |
1183 | { | |
1184 | case REG: | |
1185 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
1186 | relative to the current CFA register. */ | |
1187 | switch (GET_CODE (src)) | |
1188 | { | |
1189 | /* Setting FP from SP. */ | |
1190 | case REG: | |
1191 | if (cfa_reg != (unsigned) REGNO (src)) | |
1192 | abort (); | |
2c849145 JM |
1193 | |
1194 | /* We used to require that dest be either SP or FP, but the | |
1195 | ARM copies SP to a temporary register, and from there to | |
1196 | FP. So we just rely on the backends to only set | |
1197 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
b664de3a AM |
1198 | cfa_reg = REGNO (dest); |
1199 | break; | |
1200 | ||
1201 | case PLUS: | |
1202 | case MINUS: | |
1203 | if (dest == stack_pointer_rtx) | |
1204 | { | |
2618f955 MM |
1205 | /* Adjusting SP. */ |
1206 | switch (GET_CODE (XEXP (src, 1))) | |
1207 | { | |
1208 | case CONST_INT: | |
1209 | offset = INTVAL (XEXP (src, 1)); | |
1210 | break; | |
1211 | case REG: | |
1212 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg) | |
1213 | abort (); | |
1214 | offset = cfa_temp_value; | |
1215 | break; | |
1216 | default: | |
1217 | abort (); | |
1218 | } | |
1219 | ||
1220 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1221 | { | |
1222 | /* Restoring SP from FP in the epilogue. */ | |
1223 | if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM) | |
1224 | abort (); | |
1225 | cfa_reg = STACK_POINTER_REGNUM; | |
1226 | } | |
1227 | else if (XEXP (src, 0) != stack_pointer_rtx) | |
1228 | abort (); | |
1229 | ||
1230 | if (GET_CODE (src) == PLUS) | |
1231 | offset = -offset; | |
1232 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1233 | cfa_offset += offset; | |
1234 | if (cfa_store_reg == STACK_POINTER_REGNUM) | |
1235 | cfa_store_offset += offset; | |
b664de3a AM |
1236 | } |
1237 | else if (dest == hard_frame_pointer_rtx) | |
1238 | { | |
2618f955 MM |
1239 | /* Either setting the FP from an offset of the SP, |
1240 | or adjusting the FP */ | |
2c849145 | 1241 | if (! frame_pointer_needed) |
2618f955 MM |
1242 | abort (); |
1243 | ||
2c849145 JM |
1244 | if (GET_CODE (XEXP (src, 0)) == REG |
1245 | && (unsigned) REGNO (XEXP (src, 0)) == cfa_reg | |
2618f955 MM |
1246 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1247 | { | |
2618f955 MM |
1248 | offset = INTVAL (XEXP (src, 1)); |
1249 | if (GET_CODE (src) == PLUS) | |
1250 | offset = -offset; | |
1251 | cfa_offset += offset; | |
1252 | cfa_reg = HARD_FRAME_POINTER_REGNUM; | |
1253 | } | |
2618f955 MM |
1254 | else |
1255 | abort(); | |
b664de3a AM |
1256 | } |
1257 | else | |
1258 | { | |
2618f955 MM |
1259 | if (GET_CODE (src) != PLUS |
1260 | || XEXP (src, 1) != stack_pointer_rtx) | |
1261 | abort (); | |
1262 | if (GET_CODE (XEXP (src, 0)) != REG | |
1263 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg) | |
1264 | abort (); | |
1265 | if (cfa_reg != STACK_POINTER_REGNUM) | |
1266 | abort (); | |
1267 | cfa_store_reg = REGNO (dest); | |
1268 | cfa_store_offset = cfa_offset - cfa_temp_value; | |
b664de3a AM |
1269 | } |
1270 | break; | |
1271 | ||
1272 | case CONST_INT: | |
1273 | cfa_temp_reg = REGNO (dest); | |
1274 | cfa_temp_value = INTVAL (src); | |
1275 | break; | |
1276 | ||
1277 | case IOR: | |
1278 | if (GET_CODE (XEXP (src, 0)) != REG | |
2618f955 MM |
1279 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg |
1280 | || (unsigned) REGNO (dest) != cfa_temp_reg | |
1281 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
b664de3a AM |
1282 | abort (); |
1283 | cfa_temp_value |= INTVAL (XEXP (src, 1)); | |
1284 | break; | |
1285 | ||
1286 | default: | |
1287 | abort (); | |
1288 | } | |
1289 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
2618f955 | 1290 | break; |
b664de3a | 1291 | |
2618f955 MM |
1292 | case MEM: |
1293 | /* Saving a register to the stack. Make sure dest is relative to the | |
1294 | CFA register. */ | |
1295 | if (GET_CODE (src) != REG) | |
1296 | abort (); | |
1297 | switch (GET_CODE (XEXP (dest, 0))) | |
1298 | { | |
1299 | /* With a push. */ | |
1300 | case PRE_INC: | |
1301 | case PRE_DEC: | |
1302 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1303 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1304 | offset = -offset; | |
b664de3a | 1305 | |
2618f955 MM |
1306 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
1307 | || cfa_store_reg != STACK_POINTER_REGNUM) | |
1308 | abort (); | |
1309 | cfa_store_offset += offset; | |
1310 | if (cfa_reg == STACK_POINTER_REGNUM) | |
1311 | cfa_offset = cfa_store_offset; | |
b664de3a | 1312 | |
2618f955 MM |
1313 | offset = -cfa_store_offset; |
1314 | break; | |
b664de3a | 1315 | |
2618f955 MM |
1316 | /* With an offset. */ |
1317 | case PLUS: | |
1318 | case MINUS: | |
1319 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); | |
1320 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1321 | offset = -offset; | |
b664de3a | 1322 | |
2618f955 MM |
1323 | if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1324 | abort (); | |
1325 | offset -= cfa_store_offset; | |
1326 | break; | |
1327 | ||
1328 | /* Without an offset. */ | |
1329 | case REG: | |
770ae6cc | 1330 | if (cfa_store_reg != REGNO (XEXP (dest, 0))) |
2618f955 MM |
1331 | abort(); |
1332 | offset = -cfa_store_offset; | |
1333 | break; | |
1334 | ||
1335 | default: | |
1336 | abort (); | |
1337 | } | |
1338 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
1339 | dwarf2out_reg_save (label, REGNO (src), offset); | |
1340 | break; | |
1341 | ||
1342 | default: | |
1343 | abort (); | |
1344 | } | |
b664de3a AM |
1345 | } |
1346 | ||
1347 | ||
3f76745e JM |
1348 | /* Record call frame debugging information for INSN, which either |
1349 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1350 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1351 | |
3f76745e JM |
1352 | void |
1353 | dwarf2out_frame_debug (insn) | |
1354 | rtx insn; | |
a3f97cbb | 1355 | { |
3f76745e | 1356 | char *label; |
b664de3a | 1357 | rtx src; |
3f76745e JM |
1358 | |
1359 | if (insn == NULL_RTX) | |
a3f97cbb | 1360 | { |
3f76745e | 1361 | /* Set up state for generating call frame debug info. */ |
a6ab3aad | 1362 | lookup_cfa (&cfa_reg, &cfa_offset); |
fcd7f76b | 1363 | if (cfa_reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) |
3a88cbd1 | 1364 | abort (); |
3f76745e | 1365 | cfa_reg = STACK_POINTER_REGNUM; |
a6ab3aad JM |
1366 | cfa_store_reg = cfa_reg; |
1367 | cfa_store_offset = cfa_offset; | |
3f76745e JM |
1368 | cfa_temp_reg = -1; |
1369 | cfa_temp_value = 0; | |
1370 | return; | |
1371 | } | |
1372 | ||
0021b564 JM |
1373 | if (! RTX_FRAME_RELATED_P (insn)) |
1374 | { | |
6020d360 | 1375 | dwarf2out_stack_adjust (insn); |
0021b564 JM |
1376 | return; |
1377 | } | |
1378 | ||
3f76745e JM |
1379 | label = dwarf2out_cfi_label (); |
1380 | ||
07ebc930 RH |
1381 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1382 | if (src) | |
1383 | insn = XEXP (src, 0); | |
b664de3a | 1384 | else |
07ebc930 RH |
1385 | insn = PATTERN (insn); |
1386 | ||
b664de3a | 1387 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1388 | } |
1389 | ||
1390 | /* Return the size of an unsigned LEB128 quantity. */ | |
1391 | ||
1392 | static inline unsigned long | |
1393 | size_of_uleb128 (value) | |
1394 | register unsigned long value; | |
1395 | { | |
1396 | register unsigned long size = 0; | |
1397 | register unsigned byte; | |
1398 | ||
1399 | do | |
1400 | { | |
1401 | byte = (value & 0x7f); | |
1402 | value >>= 7; | |
1403 | size += 1; | |
1404 | } | |
1405 | while (value != 0); | |
1406 | ||
1407 | return size; | |
1408 | } | |
1409 | ||
1410 | /* Return the size of a signed LEB128 quantity. */ | |
1411 | ||
1412 | static inline unsigned long | |
1413 | size_of_sleb128 (value) | |
1414 | register long value; | |
1415 | { | |
1416 | register unsigned long size = 0; | |
1417 | register unsigned byte; | |
1418 | ||
1419 | do | |
1420 | { | |
1421 | byte = (value & 0x7f); | |
1422 | value >>= 7; | |
1423 | size += 1; | |
1424 | } | |
1425 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
1426 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1427 | ||
1428 | return size; | |
1429 | } | |
1430 | ||
3f76745e JM |
1431 | /* Output an unsigned LEB128 quantity. */ |
1432 | ||
1433 | static void | |
1434 | output_uleb128 (value) | |
1435 | register unsigned long value; | |
1436 | { | |
1437 | unsigned long save_value = value; | |
1438 | ||
1439 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1440 | do | |
1441 | { | |
1442 | register unsigned byte = (value & 0x7f); | |
1443 | value >>= 7; | |
1444 | if (value != 0) | |
1445 | /* More bytes to follow. */ | |
1446 | byte |= 0x80; | |
1447 | ||
1448 | fprintf (asm_out_file, "0x%x", byte); | |
1449 | if (value != 0) | |
1450 | fprintf (asm_out_file, ","); | |
1451 | } | |
1452 | while (value != 0); | |
1453 | ||
c5cec899 | 1454 | if (flag_debug_asm) |
2d8b0f3a | 1455 | fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value); |
3f76745e JM |
1456 | } |
1457 | ||
1458 | /* Output an signed LEB128 quantity. */ | |
1459 | ||
1460 | static void | |
1461 | output_sleb128 (value) | |
1462 | register long value; | |
1463 | { | |
1464 | register int more; | |
1465 | register unsigned byte; | |
1466 | long save_value = value; | |
1467 | ||
1468 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1469 | do | |
1470 | { | |
1471 | byte = (value & 0x7f); | |
1472 | /* arithmetic shift */ | |
1473 | value >>= 7; | |
1474 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
1475 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1476 | if (more) | |
1477 | byte |= 0x80; | |
1478 | ||
1479 | fprintf (asm_out_file, "0x%x", byte); | |
1480 | if (more) | |
1481 | fprintf (asm_out_file, ","); | |
1482 | } | |
1483 | ||
1484 | while (more); | |
c5cec899 | 1485 | if (flag_debug_asm) |
2d8b0f3a | 1486 | fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value); |
3f76745e JM |
1487 | } |
1488 | ||
1489 | /* Output a Call Frame Information opcode and its operand(s). */ | |
1490 | ||
1491 | static void | |
1492 | output_cfi (cfi, fde) | |
1493 | register dw_cfi_ref cfi; | |
1494 | register dw_fde_ref fde; | |
1495 | { | |
1496 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1497 | { | |
1498 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1499 | cfi->dw_cfi_opc | |
1500 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
c5cec899 | 1501 | if (flag_debug_asm) |
2d8b0f3a | 1502 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx", |
3f76745e JM |
1503 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset); |
1504 | fputc ('\n', asm_out_file); | |
1505 | } | |
1506 | ||
1507 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
1508 | { | |
1509 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1510 | cfi->dw_cfi_opc | |
1511 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1512 | if (flag_debug_asm) |
2d8b0f3a | 1513 | fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx", |
3f76745e JM |
1514 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1515 | ||
1516 | fputc ('\n', asm_out_file); | |
1517 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1518 | fputc ('\n', asm_out_file); | |
1519 | } | |
1520 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1521 | { | |
1522 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1523 | cfi->dw_cfi_opc | |
1524 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1525 | if (flag_debug_asm) |
2d8b0f3a | 1526 | fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx", |
3f76745e JM |
1527 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1528 | ||
1529 | fputc ('\n', asm_out_file); | |
1530 | } | |
1531 | else | |
1532 | { | |
1533 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
c5cec899 | 1534 | if (flag_debug_asm) |
3f76745e JM |
1535 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
1536 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
1537 | ||
1538 | fputc ('\n', asm_out_file); | |
1539 | switch (cfi->dw_cfi_opc) | |
1540 | { | |
1541 | case DW_CFA_set_loc: | |
1542 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr); | |
1543 | fputc ('\n', asm_out_file); | |
1544 | break; | |
1545 | case DW_CFA_advance_loc1: | |
bb727b5a JM |
1546 | ASM_OUTPUT_DWARF_DELTA1 (asm_out_file, |
1547 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1548 | fde->dw_fde_current_label); | |
1549 | fputc ('\n', asm_out_file); | |
1550 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e JM |
1551 | break; |
1552 | case DW_CFA_advance_loc2: | |
1553 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, | |
1554 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1555 | fde->dw_fde_current_label); | |
1556 | fputc ('\n', asm_out_file); | |
1557 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1558 | break; | |
1559 | case DW_CFA_advance_loc4: | |
1560 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
1561 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1562 | fde->dw_fde_current_label); | |
1563 | fputc ('\n', asm_out_file); | |
1564 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1565 | break; | |
1566 | #ifdef MIPS_DEBUGGING_INFO | |
1567 | case DW_CFA_MIPS_advance_loc8: | |
1568 | /* TODO: not currently implemented. */ | |
1569 | abort (); | |
1570 | break; | |
1571 | #endif | |
1572 | case DW_CFA_offset_extended: | |
3f388b42 | 1573 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e JM |
1574 | case DW_CFA_def_cfa: |
1575 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1576 | fputc ('\n', asm_out_file); | |
1577 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1578 | fputc ('\n', asm_out_file); | |
1579 | break; | |
1580 | case DW_CFA_restore_extended: | |
1581 | case DW_CFA_undefined: | |
1582 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1583 | fputc ('\n', asm_out_file); | |
1584 | break; | |
1585 | case DW_CFA_same_value: | |
1586 | case DW_CFA_def_cfa_register: | |
1587 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1588 | fputc ('\n', asm_out_file); | |
1589 | break; | |
1590 | case DW_CFA_register: | |
1591 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1592 | fputc ('\n', asm_out_file); | |
1593 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
1594 | fputc ('\n', asm_out_file); | |
1595 | break; | |
1596 | case DW_CFA_def_cfa_offset: | |
1597 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1598 | fputc ('\n', asm_out_file); | |
1599 | break; | |
c53aa195 JM |
1600 | case DW_CFA_GNU_window_save: |
1601 | break; | |
0021b564 JM |
1602 | case DW_CFA_GNU_args_size: |
1603 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1604 | fputc ('\n', asm_out_file); | |
1605 | break; | |
3f76745e JM |
1606 | default: |
1607 | break; | |
1608 | } | |
1609 | } | |
1610 | } | |
1611 | ||
1612 | /* Output the call frame information used to used to record information | |
1613 | that relates to calculating the frame pointer, and records the | |
1614 | location of saved registers. */ | |
1615 | ||
1616 | static void | |
1617 | output_call_frame_info (for_eh) | |
1618 | int for_eh; | |
1619 | { | |
2d8b0f3a | 1620 | register unsigned long i; |
3f76745e | 1621 | register dw_fde_ref fde; |
3f76745e | 1622 | register dw_cfi_ref cfi; |
a6ab3aad | 1623 | char l1[20], l2[20]; |
2ed2af28 PDM |
1624 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1625 | char ld[20]; | |
1626 | #endif | |
a6ab3aad JM |
1627 | |
1628 | /* Do we want to include a pointer to the exception table? */ | |
1629 | int eh_ptr = for_eh && exception_table_p (); | |
3f76745e | 1630 | |
737faf14 JM |
1631 | /* If we don't have any functions we'll want to unwind out of, don't |
1632 | emit any EH unwind information. */ | |
1633 | if (for_eh) | |
1634 | { | |
1635 | for (i = 0; i < fde_table_in_use; ++i) | |
1636 | if (! fde_table[i].nothrow) | |
1637 | goto found; | |
1638 | return; | |
1639 | found:; | |
1640 | } | |
1641 | ||
3f76745e | 1642 | fputc ('\n', asm_out_file); |
e9e30253 | 1643 | |
aa0c1401 JL |
1644 | /* We're going to be generating comments, so turn on app. */ |
1645 | if (flag_debug_asm) | |
1646 | app_enable (); | |
956d6950 | 1647 | |
3f76745e JM |
1648 | if (for_eh) |
1649 | { | |
1650 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1651 | EH_FRAME_SECTION (); |
3f76745e | 1652 | #else |
496651db | 1653 | tree label = get_file_function_name ('F'); |
0021b564 | 1654 | |
3167de5b | 1655 | force_data_section (); |
a1a4189d | 1656 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
0021b564 JM |
1657 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1658 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1659 | #endif |
1660 | assemble_label ("__FRAME_BEGIN__"); | |
1661 | } | |
1662 | else | |
1663 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
1664 | ||
1665 | /* Output the CIE. */ | |
a6ab3aad JM |
1666 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1667 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2ed2af28 PDM |
1668 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1669 | ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh); | |
1670 | if (for_eh) | |
7bb9fb0e | 1671 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1672 | else |
1673 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1674 | #else | |
267c09ab JM |
1675 | if (for_eh) |
1676 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1677 | else | |
1678 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1679 | #endif |
c5cec899 | 1680 | if (flag_debug_asm) |
3f76745e JM |
1681 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", |
1682 | ASM_COMMENT_START); | |
1683 | ||
1684 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1685 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1686 | ||
d84e64d4 JM |
1687 | if (for_eh) |
1688 | /* Now that the CIE pointer is PC-relative for EH, | |
1689 | use 0 to identify the CIE. */ | |
1690 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
1691 | else | |
1692 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1693 | ||
c5cec899 | 1694 | if (flag_debug_asm) |
3f76745e JM |
1695 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START); |
1696 | ||
1697 | fputc ('\n', asm_out_file); | |
d84e64d4 | 1698 | if (! for_eh && DWARF_OFFSET_SIZE == 8) |
3f76745e JM |
1699 | { |
1700 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1701 | fputc ('\n', asm_out_file); | |
1702 | } | |
1703 | ||
1704 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
c5cec899 | 1705 | if (flag_debug_asm) |
3f76745e JM |
1706 | fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START); |
1707 | ||
1708 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1709 | if (eh_ptr) |
1710 | { | |
d84e64d4 JM |
1711 | /* The CIE contains a pointer to the exception region info for the |
1712 | frame. Make the augmentation string three bytes (including the | |
1713 | trailing null) so the pointer is 4-byte aligned. The Solaris ld | |
1714 | can't handle unaligned relocs. */ | |
c5cec899 | 1715 | if (flag_debug_asm) |
8d4e65a6 JL |
1716 | { |
1717 | ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh"); | |
1718 | fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START); | |
1719 | } | |
1720 | else | |
1721 | { | |
c2c85462 | 1722 | ASM_OUTPUT_ASCII (asm_out_file, "eh", 3); |
8d4e65a6 | 1723 | } |
d84e64d4 JM |
1724 | fputc ('\n', asm_out_file); |
1725 | ||
1726 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__"); | |
1727 | if (flag_debug_asm) | |
1728 | fprintf (asm_out_file, "\t%s pointer to exception region info", | |
1729 | ASM_COMMENT_START); | |
a6ab3aad JM |
1730 | } |
1731 | else | |
1732 | { | |
1733 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 1734 | if (flag_debug_asm) |
a6ab3aad JM |
1735 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", |
1736 | ASM_COMMENT_START); | |
1737 | } | |
3f76745e JM |
1738 | |
1739 | fputc ('\n', asm_out_file); | |
1740 | output_uleb128 (1); | |
c5cec899 | 1741 | if (flag_debug_asm) |
3f76745e JM |
1742 | fprintf (asm_out_file, " (CIE Code Alignment Factor)"); |
1743 | ||
1744 | fputc ('\n', asm_out_file); | |
1745 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
c5cec899 | 1746 | if (flag_debug_asm) |
3f76745e JM |
1747 | fprintf (asm_out_file, " (CIE Data Alignment Factor)"); |
1748 | ||
1749 | fputc ('\n', asm_out_file); | |
1750 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN); | |
c5cec899 | 1751 | if (flag_debug_asm) |
3f76745e JM |
1752 | fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START); |
1753 | ||
1754 | fputc ('\n', asm_out_file); | |
1755 | ||
1756 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1757 | output_cfi (cfi, NULL); | |
1758 | ||
1759 | /* Pad the CIE out to an address sized boundary. */ | |
a1a4189d | 1760 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
a6ab3aad | 1761 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
2ed2af28 PDM |
1762 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1763 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1764 | if (flag_debug_asm) |
1765 | fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START); | |
1766 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1767 | #endif |
3f76745e JM |
1768 | |
1769 | /* Loop through all of the FDE's. */ | |
1770 | for (i = 0; i < fde_table_in_use; ++i) | |
1771 | { | |
1772 | fde = &fde_table[i]; | |
3f76745e | 1773 | |
737faf14 JM |
1774 | /* Don't emit EH unwind info for leaf functions. */ |
1775 | if (for_eh && fde->nothrow) | |
1776 | continue; | |
1777 | ||
a6ab3aad JM |
1778 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2); |
1779 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2); | |
2ed2af28 PDM |
1780 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1781 | ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2); | |
1782 | if (for_eh) | |
7bb9fb0e | 1783 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1784 | else |
1785 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1786 | #else | |
267c09ab JM |
1787 | if (for_eh) |
1788 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1789 | else | |
1790 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1791 | #endif |
c5cec899 | 1792 | if (flag_debug_asm) |
3f76745e | 1793 | fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START); |
3f76745e | 1794 | fputc ('\n', asm_out_file); |
a6ab3aad JM |
1795 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1796 | ||
eef906d6 JW |
1797 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1798 | emits a target dependent sized offset when for_eh is not true. | |
1799 | This inconsistency may confuse gdb. The only case where we need a | |
1800 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1801 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1802 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1803 | If the for_eh case is changed, then the struct in frame.c has | |
1804 | to be adjusted appropriately. */ | |
3f76745e | 1805 | if (for_eh) |
21af493b | 1806 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__"); |
3f76745e JM |
1807 | else |
1808 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION)); | |
c5cec899 | 1809 | if (flag_debug_asm) |
3f76745e JM |
1810 | fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START); |
1811 | ||
1812 | fputc ('\n', asm_out_file); | |
1813 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
c5cec899 | 1814 | if (flag_debug_asm) |
3f76745e JM |
1815 | fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START); |
1816 | ||
1817 | fputc ('\n', asm_out_file); | |
1818 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, | |
1819 | fde->dw_fde_end, fde->dw_fde_begin); | |
c5cec899 | 1820 | if (flag_debug_asm) |
3f76745e JM |
1821 | fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START); |
1822 | ||
1823 | fputc ('\n', asm_out_file); | |
1824 | ||
1825 | /* Loop through the Call Frame Instructions associated with | |
1826 | this FDE. */ | |
1827 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1828 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1829 | output_cfi (cfi, fde); | |
1830 | ||
a6ab3aad | 1831 | /* Pad the FDE out to an address sized boundary. */ |
a1a4189d | 1832 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
a6ab3aad | 1833 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
2ed2af28 PDM |
1834 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1835 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1836 | if (flag_debug_asm) |
1837 | fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START); | |
1838 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1839 | #endif |
3f76745e JM |
1840 | } |
1841 | #ifndef EH_FRAME_SECTION | |
1842 | if (for_eh) | |
1843 | { | |
1844 | /* Emit terminating zero for table. */ | |
267c09ab | 1845 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
3f76745e JM |
1846 | fputc ('\n', asm_out_file); |
1847 | } | |
1848 | #endif | |
a6ab3aad JM |
1849 | #ifdef MIPS_DEBUGGING_INFO |
1850 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1851 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1852 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1853 | #endif | |
aa0c1401 JL |
1854 | |
1855 | /* Turn off app to make assembly quicker. */ | |
1856 | if (flag_debug_asm) | |
1857 | app_disable (); | |
a6ab3aad JM |
1858 | } |
1859 | ||
3f76745e JM |
1860 | /* Output a marker (i.e. a label) for the beginning of a function, before |
1861 | the prologue. */ | |
1862 | ||
1863 | void | |
1864 | dwarf2out_begin_prologue () | |
1865 | { | |
1866 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1867 | register dw_fde_ref fde; | |
1868 | ||
4f988ea2 JM |
1869 | ++current_funcdef_number; |
1870 | ||
3f76745e JM |
1871 | function_section (current_function_decl); |
1872 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
1873 | current_funcdef_number); | |
1874 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
00262c8a | 1875 | current_function_func_begin_label = get_identifier (label); |
3f76745e JM |
1876 | |
1877 | /* Expand the fde table if necessary. */ | |
1878 | if (fde_table_in_use == fde_table_allocated) | |
1879 | { | |
1880 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
1881 | fde_table | |
1882 | = (dw_fde_ref) xrealloc (fde_table, | |
1883 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 1884 | } |
3f76745e JM |
1885 | |
1886 | /* Record the FDE associated with this function. */ | |
1887 | current_funcdef_fde = fde_table_in_use; | |
1888 | ||
1889 | /* Add the new FDE at the end of the fde_table. */ | |
1890 | fde = &fde_table[fde_table_in_use++]; | |
1891 | fde->dw_fde_begin = xstrdup (label); | |
1892 | fde->dw_fde_current_label = NULL; | |
1893 | fde->dw_fde_end = NULL; | |
1894 | fde->dw_fde_cfi = NULL; | |
fb13d4d0 | 1895 | fde->nothrow = current_function_nothrow; |
737faf14 | 1896 | |
b57d9225 | 1897 | args_size = old_args_size = 0; |
3f76745e JM |
1898 | } |
1899 | ||
1900 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
1901 | for a function definition. This gets called *after* the epilogue code has | |
1902 | been generated. */ | |
1903 | ||
1904 | void | |
1905 | dwarf2out_end_epilogue () | |
1906 | { | |
1907 | dw_fde_ref fde; | |
1908 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1909 | ||
1910 | /* Output a label to mark the endpoint of the code generated for this | |
1911 | function. */ | |
1912 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
1913 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1914 | fde = &fde_table[fde_table_in_use - 1]; | |
1915 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
1916 | } |
1917 | ||
1918 | void | |
1919 | dwarf2out_frame_init () | |
1920 | { | |
1921 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 1922 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
1923 | fde_table_allocated = FDE_TABLE_INCREMENT; |
1924 | fde_table_in_use = 0; | |
1925 | ||
1926 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
1927 | sake of lookup_cfa. */ | |
1928 | ||
a6ab3aad | 1929 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
1930 | /* On entry, the Canonical Frame Address is at SP. */ |
1931 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
1932 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
1933 | #endif |
1934 | } | |
1935 | ||
1936 | void | |
1937 | dwarf2out_frame_finish () | |
1938 | { | |
3f76745e | 1939 | /* Output call frame information. */ |
a6ab3aad | 1940 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
1941 | if (write_symbols == DWARF2_DEBUG) |
1942 | output_call_frame_info (0); | |
14a774a9 | 1943 | if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp)) |
3f76745e | 1944 | output_call_frame_info (1); |
a6ab3aad JM |
1945 | #else |
1946 | if (write_symbols == DWARF2_DEBUG | |
14a774a9 | 1947 | || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp)) |
a6ab3aad JM |
1948 | output_call_frame_info (1); |
1949 | #endif | |
3f76745e JM |
1950 | } |
1951 | ||
1952 | #endif /* .debug_frame support */ | |
1953 | ||
1954 | /* And now, the support for symbolic debugging information. */ | |
1955 | #ifdef DWARF2_DEBUGGING_INFO | |
1956 | ||
3f76745e JM |
1957 | /* NOTE: In the comments in this file, many references are made to |
1958 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
1959 | throughout the remainder of this file. */ | |
1960 | ||
1961 | /* An internal representation of the DWARF output is built, and then | |
1962 | walked to generate the DWARF debugging info. The walk of the internal | |
1963 | representation is done after the entire program has been compiled. | |
1964 | The types below are used to describe the internal representation. */ | |
1965 | ||
1966 | /* Each DIE may have a series of attribute/value pairs. Values | |
1967 | can take on several forms. The forms that are used in this | |
1968 | implementation are listed below. */ | |
1969 | ||
1970 | typedef enum | |
1971 | { | |
1972 | dw_val_class_addr, | |
1973 | dw_val_class_loc, | |
1974 | dw_val_class_const, | |
1975 | dw_val_class_unsigned_const, | |
1976 | dw_val_class_long_long, | |
1977 | dw_val_class_float, | |
1978 | dw_val_class_flag, | |
1979 | dw_val_class_die_ref, | |
1980 | dw_val_class_fde_ref, | |
1981 | dw_val_class_lbl_id, | |
8b790721 | 1982 | dw_val_class_lbl_offset, |
3f76745e | 1983 | dw_val_class_str |
a3f97cbb | 1984 | } |
3f76745e | 1985 | dw_val_class; |
a3f97cbb | 1986 | |
3f76745e JM |
1987 | /* Various DIE's use offsets relative to the beginning of the |
1988 | .debug_info section to refer to each other. */ | |
71dfc51f | 1989 | |
3f76745e JM |
1990 | typedef long int dw_offset; |
1991 | ||
1992 | /* Define typedefs here to avoid circular dependencies. */ | |
1993 | ||
1994 | typedef struct die_struct *dw_die_ref; | |
1995 | typedef struct dw_attr_struct *dw_attr_ref; | |
1996 | typedef struct dw_val_struct *dw_val_ref; | |
1997 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
1998 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
1999 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
2000 | typedef struct pubname_struct *pubname_ref; | |
2001 | typedef dw_die_ref *arange_ref; | |
2002 | ||
2003 | /* Describe a double word constant value. */ | |
2004 | ||
2005 | typedef struct dw_long_long_struct | |
a3f97cbb | 2006 | { |
3f76745e JM |
2007 | unsigned long hi; |
2008 | unsigned long low; | |
2009 | } | |
2010 | dw_long_long_const; | |
2011 | ||
2012 | /* Describe a floating point constant value. */ | |
2013 | ||
2014 | typedef struct dw_fp_struct | |
2015 | { | |
2016 | long *array; | |
2017 | unsigned length; | |
2018 | } | |
2019 | dw_float_const; | |
2020 | ||
2021 | /* Each entry in the line_info_table maintains the file and | |
956d6950 | 2022 | line number associated with the label generated for that |
3f76745e JM |
2023 | entry. The label gives the PC value associated with |
2024 | the line number entry. */ | |
2025 | ||
2026 | typedef struct dw_line_info_struct | |
2027 | { | |
2028 | unsigned long dw_file_num; | |
2029 | unsigned long dw_line_num; | |
2030 | } | |
2031 | dw_line_info_entry; | |
2032 | ||
2033 | /* Line information for functions in separate sections; each one gets its | |
2034 | own sequence. */ | |
2035 | typedef struct dw_separate_line_info_struct | |
2036 | { | |
2037 | unsigned long dw_file_num; | |
2038 | unsigned long dw_line_num; | |
2039 | unsigned long function; | |
2040 | } | |
2041 | dw_separate_line_info_entry; | |
2042 | ||
956d6950 | 2043 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2044 | represented internally. */ |
2045 | ||
2046 | typedef struct dw_val_struct | |
2047 | { | |
2048 | dw_val_class val_class; | |
2049 | union | |
a3f97cbb | 2050 | { |
1865dbb5 | 2051 | rtx val_addr; |
3f76745e JM |
2052 | dw_loc_descr_ref val_loc; |
2053 | long int val_int; | |
2054 | long unsigned val_unsigned; | |
2055 | dw_long_long_const val_long_long; | |
2056 | dw_float_const val_float; | |
2057 | dw_die_ref val_die_ref; | |
2058 | unsigned val_fde_index; | |
2059 | char *val_str; | |
2060 | char *val_lbl_id; | |
3f76745e | 2061 | unsigned char val_flag; |
a3f97cbb | 2062 | } |
3f76745e JM |
2063 | v; |
2064 | } | |
2065 | dw_val_node; | |
2066 | ||
2067 | /* Locations in memory are described using a sequence of stack machine | |
2068 | operations. */ | |
2069 | ||
2070 | typedef struct dw_loc_descr_struct | |
2071 | { | |
2072 | dw_loc_descr_ref dw_loc_next; | |
2073 | enum dwarf_location_atom dw_loc_opc; | |
2074 | dw_val_node dw_loc_oprnd1; | |
2075 | dw_val_node dw_loc_oprnd2; | |
2076 | } | |
2077 | dw_loc_descr_node; | |
2078 | ||
2079 | /* Each DIE attribute has a field specifying the attribute kind, | |
2080 | a link to the next attribute in the chain, and an attribute value. | |
2081 | Attributes are typically linked below the DIE they modify. */ | |
2082 | ||
2083 | typedef struct dw_attr_struct | |
2084 | { | |
2085 | enum dwarf_attribute dw_attr; | |
2086 | dw_attr_ref dw_attr_next; | |
2087 | dw_val_node dw_attr_val; | |
2088 | } | |
2089 | dw_attr_node; | |
2090 | ||
2091 | /* The Debugging Information Entry (DIE) structure */ | |
2092 | ||
2093 | typedef struct die_struct | |
2094 | { | |
2095 | enum dwarf_tag die_tag; | |
2096 | dw_attr_ref die_attr; | |
3f76745e JM |
2097 | dw_die_ref die_parent; |
2098 | dw_die_ref die_child; | |
3f76745e JM |
2099 | dw_die_ref die_sib; |
2100 | dw_offset die_offset; | |
2101 | unsigned long die_abbrev; | |
a3f97cbb | 2102 | } |
3f76745e JM |
2103 | die_node; |
2104 | ||
2105 | /* The pubname structure */ | |
2106 | ||
2107 | typedef struct pubname_struct | |
2108 | { | |
2109 | dw_die_ref die; | |
2110 | char * name; | |
2111 | } | |
2112 | pubname_entry; | |
2113 | ||
ef76d03b JW |
2114 | /* The limbo die list structure. */ |
2115 | typedef struct limbo_die_struct | |
2116 | { | |
2117 | dw_die_ref die; | |
2118 | struct limbo_die_struct *next; | |
2119 | } | |
2120 | limbo_die_node; | |
2121 | ||
3f76745e JM |
2122 | /* How to start an assembler comment. */ |
2123 | #ifndef ASM_COMMENT_START | |
2124 | #define ASM_COMMENT_START ";#" | |
2125 | #endif | |
2126 | ||
2127 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
2128 | implicitly generated for a tagged type. | |
2129 | ||
2130 | Note that unlike the gcc front end (which generates a NULL named | |
2131 | TYPE_DECL node for each complete tagged type, each array type, and | |
2132 | each function type node created) the g++ front end generates a | |
2133 | _named_ TYPE_DECL node for each tagged type node created. | |
2134 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
2135 | generate a DW_TAG_typedef DIE for them. */ | |
2136 | ||
2137 | #define TYPE_DECL_IS_STUB(decl) \ | |
2138 | (DECL_NAME (decl) == NULL_TREE \ | |
2139 | || (DECL_ARTIFICIAL (decl) \ | |
2140 | && is_tagged_type (TREE_TYPE (decl)) \ | |
ef76d03b JW |
2141 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ |
2142 | /* This is necessary for stub decls that \ | |
2143 | appear in nested inline functions. */ \ | |
2144 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
2145 | && (decl_ultimate_origin (decl) \ | |
2146 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3f76745e JM |
2147 | |
2148 | /* Information concerning the compilation unit's programming | |
2149 | language, and compiler version. */ | |
2150 | ||
2151 | extern int flag_traditional; | |
3f76745e JM |
2152 | |
2153 | /* Fixed size portion of the DWARF compilation unit header. */ | |
2154 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
2155 | ||
2156 | /* Fixed size portion of debugging line information prolog. */ | |
2157 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
2158 | ||
2159 | /* Fixed size portion of public names info. */ | |
2160 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
2161 | ||
2162 | /* Fixed size portion of the address range info. */ | |
a1a4189d JB |
2163 | #define DWARF_ARANGES_HEADER_SIZE \ |
2164 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
2165 | - DWARF_OFFSET_SIZE) | |
3f76745e | 2166 | |
262b6384 SC |
2167 | /* Size of padding portion in the address range info. It must be |
2168 | aligned to twice the pointer size. */ | |
2169 | #define DWARF_ARANGES_PAD_SIZE \ | |
a1a4189d | 2170 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ |
262b6384 SC |
2171 | - (2 * DWARF_OFFSET_SIZE + 4)) |
2172 | ||
b2244e22 JW |
2173 | /* The default is to have gcc emit the line number tables. */ |
2174 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO | |
2175 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 | |
2176 | #endif | |
2177 | ||
3f76745e JM |
2178 | /* Define the architecture-dependent minimum instruction length (in bytes). |
2179 | In this implementation of DWARF, this field is used for information | |
2180 | purposes only. Since GCC generates assembly language, we have | |
2181 | no a priori knowledge of how many instruction bytes are generated | |
2182 | for each source line, and therefore can use only the DW_LNE_set_address | |
2183 | and DW_LNS_fixed_advance_pc line information commands. */ | |
2184 | ||
2185 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
2186 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
2187 | #endif | |
2188 | ||
2189 | /* Minimum line offset in a special line info. opcode. | |
2190 | This value was chosen to give a reasonable range of values. */ | |
2191 | #define DWARF_LINE_BASE -10 | |
2192 | ||
2193 | /* First special line opcde - leave room for the standard opcodes. */ | |
2194 | #define DWARF_LINE_OPCODE_BASE 10 | |
2195 | ||
2196 | /* Range of line offsets in a special line info. opcode. */ | |
2197 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
2198 | ||
2199 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
2200 | In the present implementation, we do not mark any lines as | |
2201 | the beginning of a source statement, because that information | |
2202 | is not made available by the GCC front-end. */ | |
2203 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
2204 | ||
2205 | /* This location is used by calc_die_sizes() to keep track | |
2206 | the offset of each DIE within the .debug_info section. */ | |
2207 | static unsigned long next_die_offset; | |
2208 | ||
2209 | /* Record the root of the DIE's built for the current compilation unit. */ | |
2210 | static dw_die_ref comp_unit_die; | |
2211 | ||
ef76d03b JW |
2212 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
2213 | static limbo_die_node *limbo_die_list = 0; | |
3f76745e JM |
2214 | |
2215 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
2216 | static char **file_table; | |
2217 | ||
2218 | /* Total number of entries in the table (i.e. array) pointed to by | |
2219 | `file_table'. This is the *total* and includes both used and unused | |
2220 | slots. */ | |
2221 | static unsigned file_table_allocated; | |
a3f97cbb | 2222 | |
3f76745e JM |
2223 | /* Number of entries in the file_table which are actually in use. */ |
2224 | static unsigned file_table_in_use; | |
71dfc51f | 2225 | |
3f76745e JM |
2226 | /* Size (in elements) of increments by which we may expand the filename |
2227 | table. */ | |
2228 | #define FILE_TABLE_INCREMENT 64 | |
71dfc51f | 2229 | |
3f76745e JM |
2230 | /* Local pointer to the name of the main input file. Initialized in |
2231 | dwarf2out_init. */ | |
2232 | static char *primary_filename; | |
a3f97cbb | 2233 | |
3f76745e JM |
2234 | /* A pointer to the base of a table of references to DIE's that describe |
2235 | declarations. The table is indexed by DECL_UID() which is a unique | |
956d6950 | 2236 | number identifying each decl. */ |
3f76745e | 2237 | static dw_die_ref *decl_die_table; |
71dfc51f | 2238 | |
3f76745e JM |
2239 | /* Number of elements currently allocated for the decl_die_table. */ |
2240 | static unsigned decl_die_table_allocated; | |
a3f97cbb | 2241 | |
3f76745e JM |
2242 | /* Number of elements in decl_die_table currently in use. */ |
2243 | static unsigned decl_die_table_in_use; | |
71dfc51f | 2244 | |
3f76745e JM |
2245 | /* Size (in elements) of increments by which we may expand the |
2246 | decl_die_table. */ | |
2247 | #define DECL_DIE_TABLE_INCREMENT 256 | |
a3f97cbb | 2248 | |
3f76745e JM |
2249 | /* A pointer to the base of a table of references to declaration |
2250 | scopes. This table is a display which tracks the nesting | |
2251 | of declaration scopes at the current scope and containing | |
2252 | scopes. This table is used to find the proper place to | |
2253 | define type declaration DIE's. */ | |
777ad4c2 | 2254 | static tree *decl_scope_table; |
a3f97cbb | 2255 | |
3f76745e | 2256 | /* Number of elements currently allocated for the decl_scope_table. */ |
e3e7774e | 2257 | static int decl_scope_table_allocated; |
71dfc51f | 2258 | |
956d6950 | 2259 | /* Current level of nesting of declaration scopes. */ |
e3e7774e | 2260 | static int decl_scope_depth; |
bdb669cb | 2261 | |
3f76745e JM |
2262 | /* Size (in elements) of increments by which we may expand the |
2263 | decl_scope_table. */ | |
2264 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
bdb669cb | 2265 | |
3f76745e JM |
2266 | /* A pointer to the base of a list of references to DIE's that |
2267 | are uniquely identified by their tag, presence/absence of | |
2268 | children DIE's, and list of attribute/value pairs. */ | |
2269 | static dw_die_ref *abbrev_die_table; | |
71dfc51f | 2270 | |
3f76745e JM |
2271 | /* Number of elements currently allocated for abbrev_die_table. */ |
2272 | static unsigned abbrev_die_table_allocated; | |
bdb669cb | 2273 | |
3f76745e JM |
2274 | /* Number of elements in type_die_table currently in use. */ |
2275 | static unsigned abbrev_die_table_in_use; | |
bdb669cb | 2276 | |
3f76745e JM |
2277 | /* Size (in elements) of increments by which we may expand the |
2278 | abbrev_die_table. */ | |
2279 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
71dfc51f | 2280 | |
3f76745e JM |
2281 | /* A pointer to the base of a table that contains line information |
2282 | for each source code line in .text in the compilation unit. */ | |
2283 | static dw_line_info_ref line_info_table; | |
a3f97cbb | 2284 | |
3f76745e JM |
2285 | /* Number of elements currently allocated for line_info_table. */ |
2286 | static unsigned line_info_table_allocated; | |
71dfc51f | 2287 | |
3f76745e JM |
2288 | /* Number of elements in separate_line_info_table currently in use. */ |
2289 | static unsigned separate_line_info_table_in_use; | |
71dfc51f | 2290 | |
3f76745e JM |
2291 | /* A pointer to the base of a table that contains line information |
2292 | for each source code line outside of .text in the compilation unit. */ | |
2293 | static dw_separate_line_info_ref separate_line_info_table; | |
a3f97cbb | 2294 | |
3f76745e JM |
2295 | /* Number of elements currently allocated for separate_line_info_table. */ |
2296 | static unsigned separate_line_info_table_allocated; | |
71dfc51f | 2297 | |
3f76745e JM |
2298 | /* Number of elements in line_info_table currently in use. */ |
2299 | static unsigned line_info_table_in_use; | |
71dfc51f | 2300 | |
3f76745e JM |
2301 | /* Size (in elements) of increments by which we may expand the |
2302 | line_info_table. */ | |
2303 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
a3f97cbb | 2304 | |
3f76745e JM |
2305 | /* A pointer to the base of a table that contains a list of publicly |
2306 | accessible names. */ | |
2307 | static pubname_ref pubname_table; | |
71dfc51f | 2308 | |
3f76745e JM |
2309 | /* Number of elements currently allocated for pubname_table. */ |
2310 | static unsigned pubname_table_allocated; | |
2311 | ||
2312 | /* Number of elements in pubname_table currently in use. */ | |
2313 | static unsigned pubname_table_in_use; | |
2314 | ||
2315 | /* Size (in elements) of increments by which we may expand the | |
2316 | pubname_table. */ | |
2317 | #define PUBNAME_TABLE_INCREMENT 64 | |
2318 | ||
2319 | /* A pointer to the base of a table that contains a list of publicly | |
2320 | accessible names. */ | |
2321 | static arange_ref arange_table; | |
71dfc51f | 2322 | |
3f76745e JM |
2323 | /* Number of elements currently allocated for arange_table. */ |
2324 | static unsigned arange_table_allocated; | |
a3f97cbb | 2325 | |
3f76745e JM |
2326 | /* Number of elements in arange_table currently in use. */ |
2327 | static unsigned arange_table_in_use; | |
71dfc51f | 2328 | |
3f76745e JM |
2329 | /* Size (in elements) of increments by which we may expand the |
2330 | arange_table. */ | |
2331 | #define ARANGE_TABLE_INCREMENT 64 | |
71dfc51f | 2332 | |
8a8c3656 JM |
2333 | /* A pointer to the base of a list of incomplete types which might be |
2334 | completed at some later time. */ | |
2335 | ||
2336 | static tree *incomplete_types_list; | |
2337 | ||
2338 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
2339 | static unsigned incomplete_types_allocated; | |
2340 | ||
2341 | /* Number of elements of incomplete_types_list currently in use. */ | |
2342 | static unsigned incomplete_types; | |
2343 | ||
2344 | /* Size (in elements) of increments by which we may expand the incomplete | |
2345 | types list. Actually, a single hunk of space of this size should | |
2346 | be enough for most typical programs. */ | |
2347 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
2348 | ||
3f76745e JM |
2349 | /* Record whether the function being analyzed contains inlined functions. */ |
2350 | static int current_function_has_inlines; | |
2d8b0f3a | 2351 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
3f76745e | 2352 | static int comp_unit_has_inlines; |
2d8b0f3a | 2353 | #endif |
71dfc51f | 2354 | |
1865dbb5 JM |
2355 | /* Array of RTXes referenced by the debugging information, which therefore |
2356 | must be kept around forever. We do this rather than perform GC on | |
2357 | the dwarf info because almost all of the dwarf info lives forever, and | |
2358 | it's easier to support non-GC frontends this way. */ | |
2359 | static varray_type used_rtx_varray; | |
2360 | ||
3f76745e | 2361 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 2362 | |
83d2b3b9 KG |
2363 | static int is_pseudo_reg PARAMS ((rtx)); |
2364 | static tree type_main_variant PARAMS ((tree)); | |
2365 | static int is_tagged_type PARAMS ((tree)); | |
2366 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
2367 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
2368 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
2369 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); | |
487a6e06 | 2370 | #if 0 |
83d2b3b9 KG |
2371 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); |
2372 | #endif | |
2373 | static tree decl_ultimate_origin PARAMS ((tree)); | |
2374 | static tree block_ultimate_origin PARAMS ((tree)); | |
2375 | static tree decl_class_context PARAMS ((tree)); | |
2376 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
2377 | static void add_AT_flag PARAMS ((dw_die_ref, | |
2378 | enum dwarf_attribute, | |
2379 | unsigned)); | |
2380 | static void add_AT_int PARAMS ((dw_die_ref, | |
2381 | enum dwarf_attribute, long)); | |
2382 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
2383 | enum dwarf_attribute, | |
2384 | unsigned long)); | |
2385 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
2386 | enum dwarf_attribute, | |
2387 | unsigned long, | |
2388 | unsigned long)); | |
2389 | static void add_AT_float PARAMS ((dw_die_ref, | |
2390 | enum dwarf_attribute, | |
2391 | unsigned, long *)); | |
2392 | static void add_AT_string PARAMS ((dw_die_ref, | |
2393 | enum dwarf_attribute, | |
2394 | const char *)); | |
2395 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
2396 | enum dwarf_attribute, | |
2397 | dw_die_ref)); | |
2398 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
2399 | enum dwarf_attribute, | |
2400 | unsigned)); | |
2401 | static void add_AT_loc PARAMS ((dw_die_ref, | |
2402 | enum dwarf_attribute, | |
2403 | dw_loc_descr_ref)); | |
2404 | static void add_AT_addr PARAMS ((dw_die_ref, | |
2405 | enum dwarf_attribute, | |
1865dbb5 | 2406 | rtx)); |
83d2b3b9 KG |
2407 | static void add_AT_lbl_id PARAMS ((dw_die_ref, |
2408 | enum dwarf_attribute, | |
2409 | char *)); | |
2410 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
2411 | enum dwarf_attribute, | |
2412 | char *)); | |
2413 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, | |
2414 | enum dwarf_attribute)); | |
2415 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
2416 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
2417 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
2418 | enum dwarf_attribute)); | |
2419 | static int get_AT_flag PARAMS ((dw_die_ref, | |
2420 | enum dwarf_attribute)); | |
2421 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
2422 | enum dwarf_attribute)); | |
f19f17e0 JM |
2423 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, |
2424 | enum dwarf_attribute)); | |
83d2b3b9 KG |
2425 | static int is_c_family PARAMS ((void)); |
2426 | static int is_fortran PARAMS ((void)); | |
2427 | static void remove_AT PARAMS ((dw_die_ref, | |
2428 | enum dwarf_attribute)); | |
2429 | static void remove_children PARAMS ((dw_die_ref)); | |
2430 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
2431 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
2432 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
2433 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
2434 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
2435 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
2436 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2437 | unsigned long, | |
2438 | unsigned long)); | |
2439 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2440 | dw_loc_descr_ref)); | |
2441 | static void print_spaces PARAMS ((FILE *)); | |
2442 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
2443 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
2444 | static void add_sibling_attributes PARAMS ((dw_die_ref)); | |
2445 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
2446 | static unsigned long size_of_string PARAMS ((const char *)); | |
2447 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2448 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2449 | static int constant_size PARAMS ((long unsigned)); | |
2450 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
2451 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
2452 | static unsigned long size_of_line_prolog PARAMS ((void)); | |
2453 | static unsigned long size_of_pubnames PARAMS ((void)); | |
2454 | static unsigned long size_of_aranges PARAMS ((void)); | |
2455 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
2456 | static void output_value_format PARAMS ((dw_attr_ref)); | |
2457 | static void output_abbrev_section PARAMS ((void)); | |
2458 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2459 | static void output_die PARAMS ((dw_die_ref)); | |
2460 | static void output_compilation_unit_header PARAMS ((void)); | |
2461 | static const char *dwarf2_name PARAMS ((tree, int)); | |
2462 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
2463 | static void output_pubnames PARAMS ((void)); | |
2464 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
2465 | static void output_aranges PARAMS ((void)); | |
2466 | static void output_line_info PARAMS ((void)); | |
83d2b3b9 KG |
2467 | static dw_die_ref base_type_die PARAMS ((tree)); |
2468 | static tree root_type PARAMS ((tree)); | |
2469 | static int is_base_type PARAMS ((tree)); | |
2470 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
2471 | static int type_is_enum PARAMS ((tree)); | |
2472 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
2473 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); | |
2474 | static int is_based_loc PARAMS ((rtx)); | |
2475 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
2476 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
2477 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
665f2503 | 2478 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
83d2b3b9 | 2479 | static tree field_type PARAMS ((tree)); |
665f2503 RK |
2480 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); |
2481 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); | |
2482 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
83d2b3b9 KG |
2483 | static void add_AT_location_description PARAMS ((dw_die_ref, |
2484 | enum dwarf_attribute, rtx)); | |
2485 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
2486 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
2487 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); | |
2488 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); | |
2489 | static void add_bound_info PARAMS ((dw_die_ref, | |
2490 | enum dwarf_attribute, tree)); | |
2491 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
2492 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
2493 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
2494 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
2495 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
2496 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
2497 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
2498 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
2499 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
2500 | static void push_decl_scope PARAMS ((tree)); | |
2501 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
2502 | static void pop_decl_scope PARAMS ((void)); | |
2503 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
2504 | dw_die_ref)); | |
2505 | static char *type_tag PARAMS ((tree)); | |
2506 | static tree member_declared_type PARAMS ((tree)); | |
487a6e06 | 2507 | #if 0 |
83d2b3b9 | 2508 | static char *decl_start_label PARAMS ((tree)); |
487a6e06 | 2509 | #endif |
83d2b3b9 KG |
2510 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); |
2511 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
d6f4ec51 | 2512 | #if 0 |
83d2b3b9 KG |
2513 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); |
2514 | #endif | |
2515 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
2516 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
2517 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
2518 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
2519 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
2520 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
2521 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
2522 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
2523 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
2524 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
2525 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
2526 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
2527 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
2528 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
2529 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
2530 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
2531 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
2532 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
2533 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
2534 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
2535 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
2536 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
2537 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
2538 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
2539 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
2540 | static int is_redundant_typedef PARAMS ((tree)); | |
2541 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
2542 | static unsigned lookup_filename PARAMS ((const char *)); | |
2543 | static void add_incomplete_type PARAMS ((tree)); | |
2544 | static void retry_incomplete_types PARAMS ((void)); | |
2545 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
2546 | static void gen_abstract_function PARAMS ((tree)); | |
c6991660 KG |
2547 | static rtx save_rtx PARAMS ((rtx)); |
2548 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
2549 | static void reverse_die_lists PARAMS ((dw_die_ref)); | |
71dfc51f | 2550 | |
3f76745e | 2551 | /* Section names used to hold DWARF debugging information. */ |
c53aa195 JM |
2552 | #ifndef DEBUG_INFO_SECTION |
2553 | #define DEBUG_INFO_SECTION ".debug_info" | |
3f76745e JM |
2554 | #endif |
2555 | #ifndef ABBREV_SECTION | |
2556 | #define ABBREV_SECTION ".debug_abbrev" | |
2557 | #endif | |
2558 | #ifndef ARANGES_SECTION | |
2559 | #define ARANGES_SECTION ".debug_aranges" | |
2560 | #endif | |
2561 | #ifndef DW_MACINFO_SECTION | |
2562 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
2563 | #endif | |
c53aa195 JM |
2564 | #ifndef DEBUG_LINE_SECTION |
2565 | #define DEBUG_LINE_SECTION ".debug_line" | |
3f76745e JM |
2566 | #endif |
2567 | #ifndef LOC_SECTION | |
2568 | #define LOC_SECTION ".debug_loc" | |
2569 | #endif | |
2570 | #ifndef PUBNAMES_SECTION | |
2571 | #define PUBNAMES_SECTION ".debug_pubnames" | |
2572 | #endif | |
2573 | #ifndef STR_SECTION | |
2574 | #define STR_SECTION ".debug_str" | |
2575 | #endif | |
a3f97cbb | 2576 | |
956d6950 | 2577 | /* Standard ELF section names for compiled code and data. */ |
3f76745e JM |
2578 | #ifndef TEXT_SECTION |
2579 | #define TEXT_SECTION ".text" | |
2580 | #endif | |
2581 | #ifndef DATA_SECTION | |
2582 | #define DATA_SECTION ".data" | |
2583 | #endif | |
2584 | #ifndef BSS_SECTION | |
2585 | #define BSS_SECTION ".bss" | |
2586 | #endif | |
71dfc51f | 2587 | |
8b790721 JM |
2588 | /* Labels we insert at beginning sections we can reference instead of |
2589 | the section names themselves. */ | |
2590 | ||
2591 | #ifndef TEXT_SECTION_LABEL | |
2592 | #define TEXT_SECTION_LABEL "Ltext" | |
2593 | #endif | |
2594 | #ifndef DEBUG_LINE_SECTION_LABEL | |
2595 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" | |
2596 | #endif | |
2597 | #ifndef DEBUG_INFO_SECTION_LABEL | |
2598 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" | |
2599 | #endif | |
2600 | #ifndef ABBREV_SECTION_LABEL | |
2601 | #define ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
2602 | #endif | |
2603 | ||
a3f97cbb | 2604 | |
3f76745e JM |
2605 | /* Definitions of defaults for formats and names of various special |
2606 | (artificial) labels which may be generated within this file (when the -g | |
2607 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
2608 | If necessary, these may be overridden from within the tm.h file, but | |
2609 | typically, overriding these defaults is unnecessary. */ | |
a3f97cbb | 2610 | |
257ebd1f | 2611 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
8b790721 JM |
2612 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2613 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2614 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2615 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 2616 | |
3f76745e JM |
2617 | #ifndef TEXT_END_LABEL |
2618 | #define TEXT_END_LABEL "Letext" | |
2619 | #endif | |
2620 | #ifndef DATA_END_LABEL | |
2621 | #define DATA_END_LABEL "Ledata" | |
2622 | #endif | |
2623 | #ifndef BSS_END_LABEL | |
2624 | #define BSS_END_LABEL "Lebss" | |
2625 | #endif | |
2626 | #ifndef INSN_LABEL_FMT | |
2627 | #define INSN_LABEL_FMT "LI%u_" | |
2628 | #endif | |
2629 | #ifndef BLOCK_BEGIN_LABEL | |
2630 | #define BLOCK_BEGIN_LABEL "LBB" | |
2631 | #endif | |
2632 | #ifndef BLOCK_END_LABEL | |
2633 | #define BLOCK_END_LABEL "LBE" | |
2634 | #endif | |
2635 | #ifndef BODY_BEGIN_LABEL | |
2636 | #define BODY_BEGIN_LABEL "Lbb" | |
2637 | #endif | |
2638 | #ifndef BODY_END_LABEL | |
2639 | #define BODY_END_LABEL "Lbe" | |
2640 | #endif | |
2641 | #ifndef LINE_CODE_LABEL | |
2642 | #define LINE_CODE_LABEL "LM" | |
2643 | #endif | |
2644 | #ifndef SEPARATE_LINE_CODE_LABEL | |
2645 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
2646 | #endif | |
3f76745e | 2647 | \f |
14a774a9 RK |
2648 | /* We allow a language front-end to designate a function that is to be |
2649 | called to "demangle" any name before it it put into a DIE. */ | |
2650 | ||
83d2b3b9 | 2651 | static const char *(*demangle_name_func) PARAMS ((const char *)); |
14a774a9 RK |
2652 | |
2653 | void | |
2654 | dwarf2out_set_demangle_name_func (func) | |
83d2b3b9 | 2655 | const char *(*func) PARAMS ((const char *)); |
14a774a9 RK |
2656 | { |
2657 | demangle_name_func = func; | |
2658 | } | |
2659 | \f | |
1865dbb5 JM |
2660 | /* Return an rtx like ORIG which lives forever. If we're doing GC, |
2661 | that means adding it to used_rtx_varray. If not, that means making | |
2662 | a copy on the permanent_obstack. */ | |
71dfc51f | 2663 | |
1865dbb5 JM |
2664 | static rtx |
2665 | save_rtx (orig) | |
2666 | register rtx orig; | |
a3f97cbb | 2667 | { |
1865dbb5 JM |
2668 | if (ggc_p) |
2669 | VARRAY_PUSH_RTX (used_rtx_varray, orig); | |
2670 | else | |
3f76745e | 2671 | { |
1865dbb5 JM |
2672 | push_obstacks_nochange (); |
2673 | end_temporary_allocation (); | |
2674 | orig = copy_rtx (orig); | |
2675 | pop_obstacks (); | |
3f76745e | 2676 | } |
b170964a | 2677 | |
1865dbb5 | 2678 | return orig; |
d291dd49 JM |
2679 | } |
2680 | ||
956d6950 | 2681 | /* Test if rtl node points to a pseudo register. */ |
71dfc51f | 2682 | |
3f76745e JM |
2683 | static inline int |
2684 | is_pseudo_reg (rtl) | |
2685 | register rtx rtl; | |
d291dd49 | 2686 | { |
770ae6cc RK |
2687 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
2688 | || (GET_CODE (rtl) == SUBREG | |
2689 | && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)); | |
d291dd49 JM |
2690 | } |
2691 | ||
3f76745e JM |
2692 | /* Return a reference to a type, with its const and volatile qualifiers |
2693 | removed. */ | |
71dfc51f | 2694 | |
3f76745e JM |
2695 | static inline tree |
2696 | type_main_variant (type) | |
2697 | register tree type; | |
d291dd49 | 2698 | { |
3f76745e | 2699 | type = TYPE_MAIN_VARIANT (type); |
71dfc51f | 2700 | |
3f76745e JM |
2701 | /* There really should be only one main variant among any group of variants |
2702 | of a given type (and all of the MAIN_VARIANT values for all members of | |
2703 | the group should point to that one type) but sometimes the C front-end | |
2704 | messes this up for array types, so we work around that bug here. */ | |
71dfc51f | 2705 | |
3f76745e JM |
2706 | if (TREE_CODE (type) == ARRAY_TYPE) |
2707 | while (type != TYPE_MAIN_VARIANT (type)) | |
2708 | type = TYPE_MAIN_VARIANT (type); | |
2709 | ||
2710 | return type; | |
a3f97cbb JW |
2711 | } |
2712 | ||
3f76745e | 2713 | /* Return non-zero if the given type node represents a tagged type. */ |
71dfc51f RK |
2714 | |
2715 | static inline int | |
3f76745e JM |
2716 | is_tagged_type (type) |
2717 | register tree type; | |
bdb669cb | 2718 | { |
3f76745e | 2719 | register enum tree_code code = TREE_CODE (type); |
71dfc51f | 2720 | |
3f76745e JM |
2721 | return (code == RECORD_TYPE || code == UNION_TYPE |
2722 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
bdb669cb JM |
2723 | } |
2724 | ||
3f76745e | 2725 | /* Convert a DIE tag into its string name. */ |
71dfc51f | 2726 | |
d560ee52 | 2727 | static const char * |
3f76745e JM |
2728 | dwarf_tag_name (tag) |
2729 | register unsigned tag; | |
bdb669cb | 2730 | { |
3f76745e JM |
2731 | switch (tag) |
2732 | { | |
2733 | case DW_TAG_padding: | |
2734 | return "DW_TAG_padding"; | |
2735 | case DW_TAG_array_type: | |
2736 | return "DW_TAG_array_type"; | |
2737 | case DW_TAG_class_type: | |
2738 | return "DW_TAG_class_type"; | |
2739 | case DW_TAG_entry_point: | |
2740 | return "DW_TAG_entry_point"; | |
2741 | case DW_TAG_enumeration_type: | |
2742 | return "DW_TAG_enumeration_type"; | |
2743 | case DW_TAG_formal_parameter: | |
2744 | return "DW_TAG_formal_parameter"; | |
2745 | case DW_TAG_imported_declaration: | |
2746 | return "DW_TAG_imported_declaration"; | |
2747 | case DW_TAG_label: | |
2748 | return "DW_TAG_label"; | |
2749 | case DW_TAG_lexical_block: | |
2750 | return "DW_TAG_lexical_block"; | |
2751 | case DW_TAG_member: | |
2752 | return "DW_TAG_member"; | |
2753 | case DW_TAG_pointer_type: | |
2754 | return "DW_TAG_pointer_type"; | |
2755 | case DW_TAG_reference_type: | |
2756 | return "DW_TAG_reference_type"; | |
2757 | case DW_TAG_compile_unit: | |
2758 | return "DW_TAG_compile_unit"; | |
2759 | case DW_TAG_string_type: | |
2760 | return "DW_TAG_string_type"; | |
2761 | case DW_TAG_structure_type: | |
2762 | return "DW_TAG_structure_type"; | |
2763 | case DW_TAG_subroutine_type: | |
2764 | return "DW_TAG_subroutine_type"; | |
2765 | case DW_TAG_typedef: | |
2766 | return "DW_TAG_typedef"; | |
2767 | case DW_TAG_union_type: | |
2768 | return "DW_TAG_union_type"; | |
2769 | case DW_TAG_unspecified_parameters: | |
2770 | return "DW_TAG_unspecified_parameters"; | |
2771 | case DW_TAG_variant: | |
2772 | return "DW_TAG_variant"; | |
2773 | case DW_TAG_common_block: | |
2774 | return "DW_TAG_common_block"; | |
2775 | case DW_TAG_common_inclusion: | |
2776 | return "DW_TAG_common_inclusion"; | |
2777 | case DW_TAG_inheritance: | |
2778 | return "DW_TAG_inheritance"; | |
2779 | case DW_TAG_inlined_subroutine: | |
2780 | return "DW_TAG_inlined_subroutine"; | |
2781 | case DW_TAG_module: | |
2782 | return "DW_TAG_module"; | |
2783 | case DW_TAG_ptr_to_member_type: | |
2784 | return "DW_TAG_ptr_to_member_type"; | |
2785 | case DW_TAG_set_type: | |
2786 | return "DW_TAG_set_type"; | |
2787 | case DW_TAG_subrange_type: | |
2788 | return "DW_TAG_subrange_type"; | |
2789 | case DW_TAG_with_stmt: | |
2790 | return "DW_TAG_with_stmt"; | |
2791 | case DW_TAG_access_declaration: | |
2792 | return "DW_TAG_access_declaration"; | |
2793 | case DW_TAG_base_type: | |
2794 | return "DW_TAG_base_type"; | |
2795 | case DW_TAG_catch_block: | |
2796 | return "DW_TAG_catch_block"; | |
2797 | case DW_TAG_const_type: | |
2798 | return "DW_TAG_const_type"; | |
2799 | case DW_TAG_constant: | |
2800 | return "DW_TAG_constant"; | |
2801 | case DW_TAG_enumerator: | |
2802 | return "DW_TAG_enumerator"; | |
2803 | case DW_TAG_file_type: | |
2804 | return "DW_TAG_file_type"; | |
2805 | case DW_TAG_friend: | |
2806 | return "DW_TAG_friend"; | |
2807 | case DW_TAG_namelist: | |
2808 | return "DW_TAG_namelist"; | |
2809 | case DW_TAG_namelist_item: | |
2810 | return "DW_TAG_namelist_item"; | |
2811 | case DW_TAG_packed_type: | |
2812 | return "DW_TAG_packed_type"; | |
2813 | case DW_TAG_subprogram: | |
2814 | return "DW_TAG_subprogram"; | |
2815 | case DW_TAG_template_type_param: | |
2816 | return "DW_TAG_template_type_param"; | |
2817 | case DW_TAG_template_value_param: | |
2818 | return "DW_TAG_template_value_param"; | |
2819 | case DW_TAG_thrown_type: | |
2820 | return "DW_TAG_thrown_type"; | |
2821 | case DW_TAG_try_block: | |
2822 | return "DW_TAG_try_block"; | |
2823 | case DW_TAG_variant_part: | |
2824 | return "DW_TAG_variant_part"; | |
2825 | case DW_TAG_variable: | |
2826 | return "DW_TAG_variable"; | |
2827 | case DW_TAG_volatile_type: | |
2828 | return "DW_TAG_volatile_type"; | |
2829 | case DW_TAG_MIPS_loop: | |
2830 | return "DW_TAG_MIPS_loop"; | |
2831 | case DW_TAG_format_label: | |
2832 | return "DW_TAG_format_label"; | |
2833 | case DW_TAG_function_template: | |
2834 | return "DW_TAG_function_template"; | |
2835 | case DW_TAG_class_template: | |
2836 | return "DW_TAG_class_template"; | |
2837 | default: | |
2838 | return "DW_TAG_<unknown>"; | |
2839 | } | |
bdb669cb | 2840 | } |
a3f97cbb | 2841 | |
3f76745e | 2842 | /* Convert a DWARF attribute code into its string name. */ |
71dfc51f | 2843 | |
d560ee52 | 2844 | static const char * |
3f76745e JM |
2845 | dwarf_attr_name (attr) |
2846 | register unsigned attr; | |
4b674448 | 2847 | { |
3f76745e | 2848 | switch (attr) |
4b674448 | 2849 | { |
3f76745e JM |
2850 | case DW_AT_sibling: |
2851 | return "DW_AT_sibling"; | |
2852 | case DW_AT_location: | |
2853 | return "DW_AT_location"; | |
2854 | case DW_AT_name: | |
2855 | return "DW_AT_name"; | |
2856 | case DW_AT_ordering: | |
2857 | return "DW_AT_ordering"; | |
2858 | case DW_AT_subscr_data: | |
2859 | return "DW_AT_subscr_data"; | |
2860 | case DW_AT_byte_size: | |
2861 | return "DW_AT_byte_size"; | |
2862 | case DW_AT_bit_offset: | |
2863 | return "DW_AT_bit_offset"; | |
2864 | case DW_AT_bit_size: | |
2865 | return "DW_AT_bit_size"; | |
2866 | case DW_AT_element_list: | |
2867 | return "DW_AT_element_list"; | |
2868 | case DW_AT_stmt_list: | |
2869 | return "DW_AT_stmt_list"; | |
2870 | case DW_AT_low_pc: | |
2871 | return "DW_AT_low_pc"; | |
2872 | case DW_AT_high_pc: | |
2873 | return "DW_AT_high_pc"; | |
2874 | case DW_AT_language: | |
2875 | return "DW_AT_language"; | |
2876 | case DW_AT_member: | |
2877 | return "DW_AT_member"; | |
2878 | case DW_AT_discr: | |
2879 | return "DW_AT_discr"; | |
2880 | case DW_AT_discr_value: | |
2881 | return "DW_AT_discr_value"; | |
2882 | case DW_AT_visibility: | |
2883 | return "DW_AT_visibility"; | |
2884 | case DW_AT_import: | |
2885 | return "DW_AT_import"; | |
2886 | case DW_AT_string_length: | |
2887 | return "DW_AT_string_length"; | |
2888 | case DW_AT_common_reference: | |
2889 | return "DW_AT_common_reference"; | |
2890 | case DW_AT_comp_dir: | |
2891 | return "DW_AT_comp_dir"; | |
2892 | case DW_AT_const_value: | |
2893 | return "DW_AT_const_value"; | |
2894 | case DW_AT_containing_type: | |
2895 | return "DW_AT_containing_type"; | |
2896 | case DW_AT_default_value: | |
2897 | return "DW_AT_default_value"; | |
2898 | case DW_AT_inline: | |
2899 | return "DW_AT_inline"; | |
2900 | case DW_AT_is_optional: | |
2901 | return "DW_AT_is_optional"; | |
2902 | case DW_AT_lower_bound: | |
2903 | return "DW_AT_lower_bound"; | |
2904 | case DW_AT_producer: | |
2905 | return "DW_AT_producer"; | |
2906 | case DW_AT_prototyped: | |
2907 | return "DW_AT_prototyped"; | |
2908 | case DW_AT_return_addr: | |
2909 | return "DW_AT_return_addr"; | |
2910 | case DW_AT_start_scope: | |
2911 | return "DW_AT_start_scope"; | |
2912 | case DW_AT_stride_size: | |
2913 | return "DW_AT_stride_size"; | |
2914 | case DW_AT_upper_bound: | |
2915 | return "DW_AT_upper_bound"; | |
2916 | case DW_AT_abstract_origin: | |
2917 | return "DW_AT_abstract_origin"; | |
2918 | case DW_AT_accessibility: | |
2919 | return "DW_AT_accessibility"; | |
2920 | case DW_AT_address_class: | |
2921 | return "DW_AT_address_class"; | |
2922 | case DW_AT_artificial: | |
2923 | return "DW_AT_artificial"; | |
2924 | case DW_AT_base_types: | |
2925 | return "DW_AT_base_types"; | |
2926 | case DW_AT_calling_convention: | |
2927 | return "DW_AT_calling_convention"; | |
2928 | case DW_AT_count: | |
2929 | return "DW_AT_count"; | |
2930 | case DW_AT_data_member_location: | |
2931 | return "DW_AT_data_member_location"; | |
2932 | case DW_AT_decl_column: | |
2933 | return "DW_AT_decl_column"; | |
2934 | case DW_AT_decl_file: | |
2935 | return "DW_AT_decl_file"; | |
2936 | case DW_AT_decl_line: | |
2937 | return "DW_AT_decl_line"; | |
2938 | case DW_AT_declaration: | |
2939 | return "DW_AT_declaration"; | |
2940 | case DW_AT_discr_list: | |
2941 | return "DW_AT_discr_list"; | |
2942 | case DW_AT_encoding: | |
2943 | return "DW_AT_encoding"; | |
2944 | case DW_AT_external: | |
2945 | return "DW_AT_external"; | |
2946 | case DW_AT_frame_base: | |
2947 | return "DW_AT_frame_base"; | |
2948 | case DW_AT_friend: | |
2949 | return "DW_AT_friend"; | |
2950 | case DW_AT_identifier_case: | |
2951 | return "DW_AT_identifier_case"; | |
2952 | case DW_AT_macro_info: | |
2953 | return "DW_AT_macro_info"; | |
2954 | case DW_AT_namelist_items: | |
2955 | return "DW_AT_namelist_items"; | |
2956 | case DW_AT_priority: | |
2957 | return "DW_AT_priority"; | |
2958 | case DW_AT_segment: | |
2959 | return "DW_AT_segment"; | |
2960 | case DW_AT_specification: | |
2961 | return "DW_AT_specification"; | |
2962 | case DW_AT_static_link: | |
2963 | return "DW_AT_static_link"; | |
2964 | case DW_AT_type: | |
2965 | return "DW_AT_type"; | |
2966 | case DW_AT_use_location: | |
2967 | return "DW_AT_use_location"; | |
2968 | case DW_AT_variable_parameter: | |
2969 | return "DW_AT_variable_parameter"; | |
2970 | case DW_AT_virtuality: | |
2971 | return "DW_AT_virtuality"; | |
2972 | case DW_AT_vtable_elem_location: | |
2973 | return "DW_AT_vtable_elem_location"; | |
71dfc51f | 2974 | |
3f76745e JM |
2975 | case DW_AT_MIPS_fde: |
2976 | return "DW_AT_MIPS_fde"; | |
2977 | case DW_AT_MIPS_loop_begin: | |
2978 | return "DW_AT_MIPS_loop_begin"; | |
2979 | case DW_AT_MIPS_tail_loop_begin: | |
2980 | return "DW_AT_MIPS_tail_loop_begin"; | |
2981 | case DW_AT_MIPS_epilog_begin: | |
2982 | return "DW_AT_MIPS_epilog_begin"; | |
2983 | case DW_AT_MIPS_loop_unroll_factor: | |
2984 | return "DW_AT_MIPS_loop_unroll_factor"; | |
2985 | case DW_AT_MIPS_software_pipeline_depth: | |
2986 | return "DW_AT_MIPS_software_pipeline_depth"; | |
2987 | case DW_AT_MIPS_linkage_name: | |
2988 | return "DW_AT_MIPS_linkage_name"; | |
2989 | case DW_AT_MIPS_stride: | |
2990 | return "DW_AT_MIPS_stride"; | |
2991 | case DW_AT_MIPS_abstract_name: | |
2992 | return "DW_AT_MIPS_abstract_name"; | |
2993 | case DW_AT_MIPS_clone_origin: | |
2994 | return "DW_AT_MIPS_clone_origin"; | |
2995 | case DW_AT_MIPS_has_inlines: | |
2996 | return "DW_AT_MIPS_has_inlines"; | |
71dfc51f | 2997 | |
3f76745e JM |
2998 | case DW_AT_sf_names: |
2999 | return "DW_AT_sf_names"; | |
3000 | case DW_AT_src_info: | |
3001 | return "DW_AT_src_info"; | |
3002 | case DW_AT_mac_info: | |
3003 | return "DW_AT_mac_info"; | |
3004 | case DW_AT_src_coords: | |
3005 | return "DW_AT_src_coords"; | |
3006 | case DW_AT_body_begin: | |
3007 | return "DW_AT_body_begin"; | |
3008 | case DW_AT_body_end: | |
3009 | return "DW_AT_body_end"; | |
3010 | default: | |
3011 | return "DW_AT_<unknown>"; | |
4b674448 JM |
3012 | } |
3013 | } | |
3014 | ||
3f76745e | 3015 | /* Convert a DWARF value form code into its string name. */ |
71dfc51f | 3016 | |
d560ee52 | 3017 | static const char * |
3f76745e JM |
3018 | dwarf_form_name (form) |
3019 | register unsigned form; | |
4b674448 | 3020 | { |
3f76745e | 3021 | switch (form) |
4b674448 | 3022 | { |
3f76745e JM |
3023 | case DW_FORM_addr: |
3024 | return "DW_FORM_addr"; | |
3025 | case DW_FORM_block2: | |
3026 | return "DW_FORM_block2"; | |
3027 | case DW_FORM_block4: | |
3028 | return "DW_FORM_block4"; | |
3029 | case DW_FORM_data2: | |
3030 | return "DW_FORM_data2"; | |
3031 | case DW_FORM_data4: | |
3032 | return "DW_FORM_data4"; | |
3033 | case DW_FORM_data8: | |
3034 | return "DW_FORM_data8"; | |
3035 | case DW_FORM_string: | |
3036 | return "DW_FORM_string"; | |
3037 | case DW_FORM_block: | |
3038 | return "DW_FORM_block"; | |
3039 | case DW_FORM_block1: | |
3040 | return "DW_FORM_block1"; | |
3041 | case DW_FORM_data1: | |
3042 | return "DW_FORM_data1"; | |
3043 | case DW_FORM_flag: | |
3044 | return "DW_FORM_flag"; | |
3045 | case DW_FORM_sdata: | |
3046 | return "DW_FORM_sdata"; | |
3047 | case DW_FORM_strp: | |
3048 | return "DW_FORM_strp"; | |
3049 | case DW_FORM_udata: | |
3050 | return "DW_FORM_udata"; | |
3051 | case DW_FORM_ref_addr: | |
3052 | return "DW_FORM_ref_addr"; | |
3053 | case DW_FORM_ref1: | |
3054 | return "DW_FORM_ref1"; | |
3055 | case DW_FORM_ref2: | |
3056 | return "DW_FORM_ref2"; | |
3057 | case DW_FORM_ref4: | |
3058 | return "DW_FORM_ref4"; | |
3059 | case DW_FORM_ref8: | |
3060 | return "DW_FORM_ref8"; | |
3061 | case DW_FORM_ref_udata: | |
3062 | return "DW_FORM_ref_udata"; | |
3063 | case DW_FORM_indirect: | |
3064 | return "DW_FORM_indirect"; | |
3065 | default: | |
3066 | return "DW_FORM_<unknown>"; | |
4b674448 JM |
3067 | } |
3068 | } | |
3069 | ||
3f76745e | 3070 | /* Convert a DWARF stack opcode into its string name. */ |
71dfc51f | 3071 | |
d560ee52 | 3072 | static const char * |
3f76745e JM |
3073 | dwarf_stack_op_name (op) |
3074 | register unsigned op; | |
a3f97cbb | 3075 | { |
3f76745e | 3076 | switch (op) |
a3f97cbb | 3077 | { |
3f76745e JM |
3078 | case DW_OP_addr: |
3079 | return "DW_OP_addr"; | |
3080 | case DW_OP_deref: | |
3081 | return "DW_OP_deref"; | |
3082 | case DW_OP_const1u: | |
3083 | return "DW_OP_const1u"; | |
3084 | case DW_OP_const1s: | |
3085 | return "DW_OP_const1s"; | |
3086 | case DW_OP_const2u: | |
3087 | return "DW_OP_const2u"; | |
3088 | case DW_OP_const2s: | |
3089 | return "DW_OP_const2s"; | |
3090 | case DW_OP_const4u: | |
3091 | return "DW_OP_const4u"; | |
3092 | case DW_OP_const4s: | |
3093 | return "DW_OP_const4s"; | |
3094 | case DW_OP_const8u: | |
3095 | return "DW_OP_const8u"; | |
3096 | case DW_OP_const8s: | |
3097 | return "DW_OP_const8s"; | |
3098 | case DW_OP_constu: | |
3099 | return "DW_OP_constu"; | |
3100 | case DW_OP_consts: | |
3101 | return "DW_OP_consts"; | |
3102 | case DW_OP_dup: | |
3103 | return "DW_OP_dup"; | |
3104 | case DW_OP_drop: | |
3105 | return "DW_OP_drop"; | |
3106 | case DW_OP_over: | |
3107 | return "DW_OP_over"; | |
3108 | case DW_OP_pick: | |
3109 | return "DW_OP_pick"; | |
3110 | case DW_OP_swap: | |
3111 | return "DW_OP_swap"; | |
3112 | case DW_OP_rot: | |
3113 | return "DW_OP_rot"; | |
3114 | case DW_OP_xderef: | |
3115 | return "DW_OP_xderef"; | |
3116 | case DW_OP_abs: | |
3117 | return "DW_OP_abs"; | |
3118 | case DW_OP_and: | |
3119 | return "DW_OP_and"; | |
3120 | case DW_OP_div: | |
3121 | return "DW_OP_div"; | |
3122 | case DW_OP_minus: | |
3123 | return "DW_OP_minus"; | |
3124 | case DW_OP_mod: | |
3125 | return "DW_OP_mod"; | |
3126 | case DW_OP_mul: | |
3127 | return "DW_OP_mul"; | |
3128 | case DW_OP_neg: | |
3129 | return "DW_OP_neg"; | |
3130 | case DW_OP_not: | |
3131 | return "DW_OP_not"; | |
3132 | case DW_OP_or: | |
3133 | return "DW_OP_or"; | |
3134 | case DW_OP_plus: | |
3135 | return "DW_OP_plus"; | |
3136 | case DW_OP_plus_uconst: | |
3137 | return "DW_OP_plus_uconst"; | |
3138 | case DW_OP_shl: | |
3139 | return "DW_OP_shl"; | |
3140 | case DW_OP_shr: | |
3141 | return "DW_OP_shr"; | |
3142 | case DW_OP_shra: | |
3143 | return "DW_OP_shra"; | |
3144 | case DW_OP_xor: | |
3145 | return "DW_OP_xor"; | |
3146 | case DW_OP_bra: | |
3147 | return "DW_OP_bra"; | |
3148 | case DW_OP_eq: | |
3149 | return "DW_OP_eq"; | |
3150 | case DW_OP_ge: | |
3151 | return "DW_OP_ge"; | |
3152 | case DW_OP_gt: | |
3153 | return "DW_OP_gt"; | |
3154 | case DW_OP_le: | |
3155 | return "DW_OP_le"; | |
3156 | case DW_OP_lt: | |
3157 | return "DW_OP_lt"; | |
3158 | case DW_OP_ne: | |
3159 | return "DW_OP_ne"; | |
3160 | case DW_OP_skip: | |
3161 | return "DW_OP_skip"; | |
3162 | case DW_OP_lit0: | |
3163 | return "DW_OP_lit0"; | |
3164 | case DW_OP_lit1: | |
3165 | return "DW_OP_lit1"; | |
3166 | case DW_OP_lit2: | |
3167 | return "DW_OP_lit2"; | |
3168 | case DW_OP_lit3: | |
3169 | return "DW_OP_lit3"; | |
3170 | case DW_OP_lit4: | |
3171 | return "DW_OP_lit4"; | |
3172 | case DW_OP_lit5: | |
3173 | return "DW_OP_lit5"; | |
3174 | case DW_OP_lit6: | |
3175 | return "DW_OP_lit6"; | |
3176 | case DW_OP_lit7: | |
3177 | return "DW_OP_lit7"; | |
3178 | case DW_OP_lit8: | |
3179 | return "DW_OP_lit8"; | |
3180 | case DW_OP_lit9: | |
3181 | return "DW_OP_lit9"; | |
3182 | case DW_OP_lit10: | |
3183 | return "DW_OP_lit10"; | |
3184 | case DW_OP_lit11: | |
3185 | return "DW_OP_lit11"; | |
3186 | case DW_OP_lit12: | |
3187 | return "DW_OP_lit12"; | |
3188 | case DW_OP_lit13: | |
3189 | return "DW_OP_lit13"; | |
3190 | case DW_OP_lit14: | |
3191 | return "DW_OP_lit14"; | |
3192 | case DW_OP_lit15: | |
3193 | return "DW_OP_lit15"; | |
3194 | case DW_OP_lit16: | |
3195 | return "DW_OP_lit16"; | |
3196 | case DW_OP_lit17: | |
3197 | return "DW_OP_lit17"; | |
3198 | case DW_OP_lit18: | |
3199 | return "DW_OP_lit18"; | |
3200 | case DW_OP_lit19: | |
3201 | return "DW_OP_lit19"; | |
3202 | case DW_OP_lit20: | |
3203 | return "DW_OP_lit20"; | |
3204 | case DW_OP_lit21: | |
3205 | return "DW_OP_lit21"; | |
3206 | case DW_OP_lit22: | |
3207 | return "DW_OP_lit22"; | |
3208 | case DW_OP_lit23: | |
3209 | return "DW_OP_lit23"; | |
3210 | case DW_OP_lit24: | |
3211 | return "DW_OP_lit24"; | |
3212 | case DW_OP_lit25: | |
3213 | return "DW_OP_lit25"; | |
3214 | case DW_OP_lit26: | |
3215 | return "DW_OP_lit26"; | |
3216 | case DW_OP_lit27: | |
3217 | return "DW_OP_lit27"; | |
3218 | case DW_OP_lit28: | |
3219 | return "DW_OP_lit28"; | |
3220 | case DW_OP_lit29: | |
3221 | return "DW_OP_lit29"; | |
3222 | case DW_OP_lit30: | |
3223 | return "DW_OP_lit30"; | |
3224 | case DW_OP_lit31: | |
3225 | return "DW_OP_lit31"; | |
3226 | case DW_OP_reg0: | |
3227 | return "DW_OP_reg0"; | |
3228 | case DW_OP_reg1: | |
3229 | return "DW_OP_reg1"; | |
3230 | case DW_OP_reg2: | |
3231 | return "DW_OP_reg2"; | |
3232 | case DW_OP_reg3: | |
3233 | return "DW_OP_reg3"; | |
3234 | case DW_OP_reg4: | |
3235 | return "DW_OP_reg4"; | |
3236 | case DW_OP_reg5: | |
3237 | return "DW_OP_reg5"; | |
3238 | case DW_OP_reg6: | |
3239 | return "DW_OP_reg6"; | |
3240 | case DW_OP_reg7: | |
3241 | return "DW_OP_reg7"; | |
3242 | case DW_OP_reg8: | |
3243 | return "DW_OP_reg8"; | |
3244 | case DW_OP_reg9: | |
3245 | return "DW_OP_reg9"; | |
3246 | case DW_OP_reg10: | |
3247 | return "DW_OP_reg10"; | |
3248 | case DW_OP_reg11: | |
3249 | return "DW_OP_reg11"; | |
3250 | case DW_OP_reg12: | |
3251 | return "DW_OP_reg12"; | |
3252 | case DW_OP_reg13: | |
3253 | return "DW_OP_reg13"; | |
3254 | case DW_OP_reg14: | |
3255 | return "DW_OP_reg14"; | |
3256 | case DW_OP_reg15: | |
3257 | return "DW_OP_reg15"; | |
3258 | case DW_OP_reg16: | |
3259 | return "DW_OP_reg16"; | |
3260 | case DW_OP_reg17: | |
3261 | return "DW_OP_reg17"; | |
3262 | case DW_OP_reg18: | |
3263 | return "DW_OP_reg18"; | |
3264 | case DW_OP_reg19: | |
3265 | return "DW_OP_reg19"; | |
3266 | case DW_OP_reg20: | |
3267 | return "DW_OP_reg20"; | |
3268 | case DW_OP_reg21: | |
3269 | return "DW_OP_reg21"; | |
3270 | case DW_OP_reg22: | |
3271 | return "DW_OP_reg22"; | |
3272 | case DW_OP_reg23: | |
3273 | return "DW_OP_reg23"; | |
3274 | case DW_OP_reg24: | |
3275 | return "DW_OP_reg24"; | |
3276 | case DW_OP_reg25: | |
3277 | return "DW_OP_reg25"; | |
3278 | case DW_OP_reg26: | |
3279 | return "DW_OP_reg26"; | |
3280 | case DW_OP_reg27: | |
3281 | return "DW_OP_reg27"; | |
3282 | case DW_OP_reg28: | |
3283 | return "DW_OP_reg28"; | |
3284 | case DW_OP_reg29: | |
3285 | return "DW_OP_reg29"; | |
3286 | case DW_OP_reg30: | |
3287 | return "DW_OP_reg30"; | |
3288 | case DW_OP_reg31: | |
3289 | return "DW_OP_reg31"; | |
3290 | case DW_OP_breg0: | |
3291 | return "DW_OP_breg0"; | |
3292 | case DW_OP_breg1: | |
3293 | return "DW_OP_breg1"; | |
3294 | case DW_OP_breg2: | |
3295 | return "DW_OP_breg2"; | |
3296 | case DW_OP_breg3: | |
3297 | return "DW_OP_breg3"; | |
3298 | case DW_OP_breg4: | |
3299 | return "DW_OP_breg4"; | |
3300 | case DW_OP_breg5: | |
3301 | return "DW_OP_breg5"; | |
3302 | case DW_OP_breg6: | |
3303 | return "DW_OP_breg6"; | |
3304 | case DW_OP_breg7: | |
3305 | return "DW_OP_breg7"; | |
3306 | case DW_OP_breg8: | |
3307 | return "DW_OP_breg8"; | |
3308 | case DW_OP_breg9: | |
3309 | return "DW_OP_breg9"; | |
3310 | case DW_OP_breg10: | |
3311 | return "DW_OP_breg10"; | |
3312 | case DW_OP_breg11: | |
3313 | return "DW_OP_breg11"; | |
3314 | case DW_OP_breg12: | |
3315 | return "DW_OP_breg12"; | |
3316 | case DW_OP_breg13: | |
3317 | return "DW_OP_breg13"; | |
3318 | case DW_OP_breg14: | |
3319 | return "DW_OP_breg14"; | |
3320 | case DW_OP_breg15: | |
3321 | return "DW_OP_breg15"; | |
3322 | case DW_OP_breg16: | |
3323 | return "DW_OP_breg16"; | |
3324 | case DW_OP_breg17: | |
3325 | return "DW_OP_breg17"; | |
3326 | case DW_OP_breg18: | |
3327 | return "DW_OP_breg18"; | |
3328 | case DW_OP_breg19: | |
3329 | return "DW_OP_breg19"; | |
3330 | case DW_OP_breg20: | |
3331 | return "DW_OP_breg20"; | |
3332 | case DW_OP_breg21: | |
3333 | return "DW_OP_breg21"; | |
3334 | case DW_OP_breg22: | |
3335 | return "DW_OP_breg22"; | |
3336 | case DW_OP_breg23: | |
3337 | return "DW_OP_breg23"; | |
3338 | case DW_OP_breg24: | |
3339 | return "DW_OP_breg24"; | |
3340 | case DW_OP_breg25: | |
3341 | return "DW_OP_breg25"; | |
3342 | case DW_OP_breg26: | |
3343 | return "DW_OP_breg26"; | |
3344 | case DW_OP_breg27: | |
3345 | return "DW_OP_breg27"; | |
3346 | case DW_OP_breg28: | |
3347 | return "DW_OP_breg28"; | |
3348 | case DW_OP_breg29: | |
3349 | return "DW_OP_breg29"; | |
3350 | case DW_OP_breg30: | |
3351 | return "DW_OP_breg30"; | |
3352 | case DW_OP_breg31: | |
3353 | return "DW_OP_breg31"; | |
3354 | case DW_OP_regx: | |
3355 | return "DW_OP_regx"; | |
3356 | case DW_OP_fbreg: | |
3357 | return "DW_OP_fbreg"; | |
3358 | case DW_OP_bregx: | |
3359 | return "DW_OP_bregx"; | |
3360 | case DW_OP_piece: | |
3361 | return "DW_OP_piece"; | |
3362 | case DW_OP_deref_size: | |
3363 | return "DW_OP_deref_size"; | |
3364 | case DW_OP_xderef_size: | |
3365 | return "DW_OP_xderef_size"; | |
3366 | case DW_OP_nop: | |
3367 | return "DW_OP_nop"; | |
3368 | default: | |
3369 | return "OP_<unknown>"; | |
a3f97cbb JW |
3370 | } |
3371 | } | |
3372 | ||
3f76745e | 3373 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 3374 | |
487a6e06 | 3375 | #if 0 |
d560ee52 | 3376 | static const char * |
3f76745e JM |
3377 | dwarf_type_encoding_name (enc) |
3378 | register unsigned enc; | |
a3f97cbb | 3379 | { |
3f76745e | 3380 | switch (enc) |
a3f97cbb | 3381 | { |
3f76745e JM |
3382 | case DW_ATE_address: |
3383 | return "DW_ATE_address"; | |
3384 | case DW_ATE_boolean: | |
3385 | return "DW_ATE_boolean"; | |
3386 | case DW_ATE_complex_float: | |
3387 | return "DW_ATE_complex_float"; | |
3388 | case DW_ATE_float: | |
3389 | return "DW_ATE_float"; | |
3390 | case DW_ATE_signed: | |
3391 | return "DW_ATE_signed"; | |
3392 | case DW_ATE_signed_char: | |
3393 | return "DW_ATE_signed_char"; | |
3394 | case DW_ATE_unsigned: | |
3395 | return "DW_ATE_unsigned"; | |
3396 | case DW_ATE_unsigned_char: | |
3397 | return "DW_ATE_unsigned_char"; | |
3398 | default: | |
3399 | return "DW_ATE_<unknown>"; | |
3400 | } | |
a3f97cbb | 3401 | } |
487a6e06 | 3402 | #endif |
3f76745e JM |
3403 | \f |
3404 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
3405 | instance of an inlined instance of a decl which is local to an inline | |
3406 | function, so we have to trace all of the way back through the origin chain | |
3407 | to find out what sort of node actually served as the original seed for the | |
3408 | given block. */ | |
a3f97cbb | 3409 | |
3f76745e JM |
3410 | static tree |
3411 | decl_ultimate_origin (decl) | |
3412 | register tree decl; | |
a3f97cbb | 3413 | { |
10a11b75 JM |
3414 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
3415 | nodes in the function to point to themselves; ignore that if | |
3416 | we're trying to output the abstract instance of this function. */ | |
3417 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
3418 | return NULL_TREE; | |
3419 | ||
02e24c7a MM |
3420 | #ifdef ENABLE_CHECKING |
3421 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) | |
3422 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
3423 | most distant ancestor, this should never happen. */ | |
3424 | abort (); | |
3425 | #endif | |
3f76745e | 3426 | |
02e24c7a | 3427 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
3428 | } |
3429 | ||
3f76745e JM |
3430 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
3431 | instance of an inlined instance of a block which is local to an inline | |
3432 | function, so we have to trace all of the way back through the origin chain | |
3433 | to find out what sort of node actually served as the original seed for the | |
3434 | given block. */ | |
71dfc51f | 3435 | |
3f76745e JM |
3436 | static tree |
3437 | block_ultimate_origin (block) | |
3438 | register tree block; | |
a3f97cbb | 3439 | { |
3f76745e | 3440 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 3441 | |
10a11b75 JM |
3442 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
3443 | nodes in the function to point to themselves; ignore that if | |
3444 | we're trying to output the abstract instance of this function. */ | |
3445 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
3446 | return NULL_TREE; | |
3447 | ||
3f76745e JM |
3448 | if (immediate_origin == NULL_TREE) |
3449 | return NULL_TREE; | |
3450 | else | |
3451 | { | |
3452 | register tree ret_val; | |
3453 | register tree lookahead = immediate_origin; | |
71dfc51f | 3454 | |
3f76745e JM |
3455 | do |
3456 | { | |
3457 | ret_val = lookahead; | |
3458 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
3459 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
3460 | : NULL; | |
3461 | } | |
3462 | while (lookahead != NULL && lookahead != ret_val); | |
3463 | ||
3464 | return ret_val; | |
3465 | } | |
a3f97cbb JW |
3466 | } |
3467 | ||
3f76745e JM |
3468 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
3469 | of a virtual function may refer to a base class, so we check the 'this' | |
3470 | parameter. */ | |
71dfc51f | 3471 | |
3f76745e JM |
3472 | static tree |
3473 | decl_class_context (decl) | |
3474 | tree decl; | |
a3f97cbb | 3475 | { |
3f76745e | 3476 | tree context = NULL_TREE; |
71dfc51f | 3477 | |
3f76745e JM |
3478 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
3479 | context = DECL_CONTEXT (decl); | |
3480 | else | |
3481 | context = TYPE_MAIN_VARIANT | |
3482 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 3483 | |
2f939d94 | 3484 | if (context && !TYPE_P (context)) |
3f76745e JM |
3485 | context = NULL_TREE; |
3486 | ||
3487 | return context; | |
a3f97cbb JW |
3488 | } |
3489 | \f | |
a96c67ec JM |
3490 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
3491 | addition order, and correct that in add_sibling_attributes. */ | |
71dfc51f RK |
3492 | |
3493 | static inline void | |
3f76745e JM |
3494 | add_dwarf_attr (die, attr) |
3495 | register dw_die_ref die; | |
3496 | register dw_attr_ref attr; | |
a3f97cbb | 3497 | { |
3f76745e | 3498 | if (die != NULL && attr != NULL) |
a3f97cbb | 3499 | { |
a96c67ec JM |
3500 | attr->dw_attr_next = die->die_attr; |
3501 | die->die_attr = attr; | |
a3f97cbb JW |
3502 | } |
3503 | } | |
3504 | ||
c6991660 | 3505 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3506 | static inline dw_val_class |
3507 | AT_class (a) | |
3508 | dw_attr_ref a; | |
3509 | { | |
3510 | return a->dw_attr_val.val_class; | |
3511 | } | |
3512 | ||
3f76745e | 3513 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 3514 | |
3f76745e JM |
3515 | static inline void |
3516 | add_AT_flag (die, attr_kind, flag) | |
3517 | register dw_die_ref die; | |
3518 | register enum dwarf_attribute attr_kind; | |
3519 | register unsigned flag; | |
a3f97cbb | 3520 | { |
3f76745e | 3521 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3522 | |
3f76745e JM |
3523 | attr->dw_attr_next = NULL; |
3524 | attr->dw_attr = attr_kind; | |
3525 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
3526 | attr->dw_attr_val.v.val_flag = flag; | |
3527 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3528 | } |
3529 | ||
c6991660 | 3530 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3531 | static inline unsigned |
3532 | AT_flag (a) | |
3533 | register dw_attr_ref a; | |
3534 | { | |
3535 | if (a && AT_class (a) == dw_val_class_flag) | |
3536 | return a->dw_attr_val.v.val_flag; | |
3537 | ||
3538 | return 0; | |
3539 | } | |
3540 | ||
3f76745e | 3541 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 3542 | |
3f76745e JM |
3543 | static inline void |
3544 | add_AT_int (die, attr_kind, int_val) | |
3545 | register dw_die_ref die; | |
3546 | register enum dwarf_attribute attr_kind; | |
3547 | register long int int_val; | |
a3f97cbb | 3548 | { |
3f76745e JM |
3549 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3550 | ||
3551 | attr->dw_attr_next = NULL; | |
3552 | attr->dw_attr = attr_kind; | |
3553 | attr->dw_attr_val.val_class = dw_val_class_const; | |
3554 | attr->dw_attr_val.v.val_int = int_val; | |
3555 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3556 | } |
3557 | ||
c6991660 | 3558 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3559 | static inline long int |
3560 | AT_int (a) | |
3561 | register dw_attr_ref a; | |
3562 | { | |
3563 | if (a && AT_class (a) == dw_val_class_const) | |
3564 | return a->dw_attr_val.v.val_int; | |
3565 | ||
3566 | return 0; | |
3567 | } | |
3568 | ||
3f76745e | 3569 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 3570 | |
3f76745e JM |
3571 | static inline void |
3572 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
3573 | register dw_die_ref die; | |
3574 | register enum dwarf_attribute attr_kind; | |
3575 | register unsigned long unsigned_val; | |
a3f97cbb | 3576 | { |
3f76745e JM |
3577 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3578 | ||
3579 | attr->dw_attr_next = NULL; | |
3580 | attr->dw_attr = attr_kind; | |
3581 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
3582 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
3583 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3584 | } |
71dfc51f | 3585 | |
c6991660 | 3586 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3587 | static inline unsigned long |
3588 | AT_unsigned (a) | |
3589 | register dw_attr_ref a; | |
3590 | { | |
3591 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
3592 | return a->dw_attr_val.v.val_unsigned; | |
3593 | ||
3594 | return 0; | |
3595 | } | |
3596 | ||
3f76745e JM |
3597 | /* Add an unsigned double integer attribute value to a DIE. */ |
3598 | ||
3599 | static inline void | |
3600 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 3601 | register dw_die_ref die; |
3f76745e JM |
3602 | register enum dwarf_attribute attr_kind; |
3603 | register unsigned long val_hi; | |
3604 | register unsigned long val_low; | |
a3f97cbb | 3605 | { |
3f76745e | 3606 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3607 | |
3f76745e JM |
3608 | attr->dw_attr_next = NULL; |
3609 | attr->dw_attr = attr_kind; | |
3610 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
3611 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
3612 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
3613 | add_dwarf_attr (die, attr); | |
3614 | } | |
71dfc51f | 3615 | |
3f76745e | 3616 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 3617 | |
3f76745e JM |
3618 | static inline void |
3619 | add_AT_float (die, attr_kind, length, array) | |
3620 | register dw_die_ref die; | |
3621 | register enum dwarf_attribute attr_kind; | |
3622 | register unsigned length; | |
3623 | register long *array; | |
3624 | { | |
3625 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
3626 | ||
3627 | attr->dw_attr_next = NULL; | |
3628 | attr->dw_attr = attr_kind; | |
3629 | attr->dw_attr_val.val_class = dw_val_class_float; | |
3630 | attr->dw_attr_val.v.val_float.length = length; | |
3631 | attr->dw_attr_val.v.val_float.array = array; | |
3632 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3633 | } |
3634 | ||
3f76745e | 3635 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 3636 | |
3f76745e JM |
3637 | static inline void |
3638 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 3639 | register dw_die_ref die; |
3f76745e | 3640 | register enum dwarf_attribute attr_kind; |
d560ee52 | 3641 | register const char *str; |
a3f97cbb | 3642 | { |
3f76745e | 3643 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3644 | |
3f76745e JM |
3645 | attr->dw_attr_next = NULL; |
3646 | attr->dw_attr = attr_kind; | |
3647 | attr->dw_attr_val.val_class = dw_val_class_str; | |
3648 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
3649 | add_dwarf_attr (die, attr); | |
3650 | } | |
71dfc51f | 3651 | |
c6991660 | 3652 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3653 | static inline const char * |
3654 | AT_string (a) | |
3655 | register dw_attr_ref a; | |
3656 | { | |
3657 | if (a && AT_class (a) == dw_val_class_str) | |
3658 | return a->dw_attr_val.v.val_str; | |
3659 | ||
3660 | return NULL; | |
3661 | } | |
3662 | ||
3f76745e | 3663 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 3664 | |
3f76745e JM |
3665 | static inline void |
3666 | add_AT_die_ref (die, attr_kind, targ_die) | |
3667 | register dw_die_ref die; | |
3668 | register enum dwarf_attribute attr_kind; | |
3669 | register dw_die_ref targ_die; | |
3670 | { | |
3671 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3672 | |
3f76745e JM |
3673 | attr->dw_attr_next = NULL; |
3674 | attr->dw_attr = attr_kind; | |
3675 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
3676 | attr->dw_attr_val.v.val_die_ref = targ_die; | |
3677 | add_dwarf_attr (die, attr); | |
3678 | } | |
b1ccbc24 | 3679 | |
c6991660 | 3680 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3681 | static inline dw_die_ref |
3682 | AT_ref (a) | |
3683 | register dw_attr_ref a; | |
3684 | { | |
3685 | if (a && AT_class (a) == dw_val_class_die_ref) | |
3686 | return a->dw_attr_val.v.val_die_ref; | |
3687 | ||
3688 | return NULL; | |
3689 | } | |
3690 | ||
3f76745e | 3691 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 3692 | |
3f76745e JM |
3693 | static inline void |
3694 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
3695 | register dw_die_ref die; | |
3696 | register enum dwarf_attribute attr_kind; | |
3697 | register unsigned targ_fde; | |
3698 | { | |
3699 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 3700 | |
3f76745e JM |
3701 | attr->dw_attr_next = NULL; |
3702 | attr->dw_attr = attr_kind; | |
3703 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
3704 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
3705 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3706 | } |
71dfc51f | 3707 | |
3f76745e | 3708 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 3709 | |
3f76745e JM |
3710 | static inline void |
3711 | add_AT_loc (die, attr_kind, loc) | |
3712 | register dw_die_ref die; | |
3713 | register enum dwarf_attribute attr_kind; | |
3714 | register dw_loc_descr_ref loc; | |
3715 | { | |
3716 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3717 | |
3f76745e JM |
3718 | attr->dw_attr_next = NULL; |
3719 | attr->dw_attr = attr_kind; | |
3720 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
3721 | attr->dw_attr_val.v.val_loc = loc; | |
3722 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3723 | } |
3724 | ||
c6991660 | 3725 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3726 | static inline dw_loc_descr_ref |
3727 | AT_loc (a) | |
3728 | register dw_attr_ref a; | |
3729 | { | |
3730 | if (a && AT_class (a) == dw_val_class_loc) | |
3731 | return a->dw_attr_val.v.val_loc; | |
3732 | ||
3733 | return NULL; | |
3734 | } | |
3735 | ||
3f76745e | 3736 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 3737 | |
3f76745e JM |
3738 | static inline void |
3739 | add_AT_addr (die, attr_kind, addr) | |
3740 | register dw_die_ref die; | |
3741 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 3742 | rtx addr; |
a3f97cbb | 3743 | { |
3f76745e | 3744 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3745 | |
3f76745e JM |
3746 | attr->dw_attr_next = NULL; |
3747 | attr->dw_attr = attr_kind; | |
3748 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
3749 | attr->dw_attr_val.v.val_addr = addr; | |
3750 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3751 | } |
3752 | ||
c6991660 | 3753 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 3754 | static inline rtx |
a96c67ec JM |
3755 | AT_addr (a) |
3756 | register dw_attr_ref a; | |
3757 | { | |
3758 | if (a && AT_class (a) == dw_val_class_addr) | |
3759 | return a->dw_attr_val.v.val_addr; | |
3760 | ||
3761 | return NULL; | |
3762 | } | |
3763 | ||
3f76745e | 3764 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 3765 | |
3f76745e JM |
3766 | static inline void |
3767 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
3768 | register dw_die_ref die; | |
3769 | register enum dwarf_attribute attr_kind; | |
3770 | register char *lbl_id; | |
a3f97cbb | 3771 | { |
3f76745e | 3772 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3773 | |
3f76745e JM |
3774 | attr->dw_attr_next = NULL; |
3775 | attr->dw_attr = attr_kind; | |
3776 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
3777 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
3778 | add_dwarf_attr (die, attr); | |
3779 | } | |
71dfc51f | 3780 | |
3f76745e JM |
3781 | /* Add a section offset attribute value to a DIE. */ |
3782 | ||
3783 | static inline void | |
8b790721 | 3784 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
3785 | register dw_die_ref die; |
3786 | register enum dwarf_attribute attr_kind; | |
8b790721 | 3787 | register char *label; |
3f76745e JM |
3788 | { |
3789 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3790 | |
3f76745e JM |
3791 | attr->dw_attr_next = NULL; |
3792 | attr->dw_attr = attr_kind; | |
8b790721 | 3793 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 3794 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e JM |
3795 | add_dwarf_attr (die, attr); |
3796 | ||
a3f97cbb JW |
3797 | } |
3798 | ||
c6991660 | 3799 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
3800 | static inline const char * |
3801 | AT_lbl (a) | |
3802 | register dw_attr_ref a; | |
a3f97cbb | 3803 | { |
a96c67ec JM |
3804 | if (a && (AT_class (a) == dw_val_class_lbl_id |
3805 | || AT_class (a) == dw_val_class_lbl_offset)) | |
3806 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 3807 | |
a96c67ec | 3808 | return NULL; |
a3f97cbb JW |
3809 | } |
3810 | ||
3f76745e | 3811 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 3812 | |
3f76745e JM |
3813 | static inline dw_attr_ref |
3814 | get_AT (die, attr_kind) | |
3815 | register dw_die_ref die; | |
3816 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 3817 | { |
3f76745e JM |
3818 | register dw_attr_ref a; |
3819 | register dw_die_ref spec = NULL; | |
3820 | ||
3821 | if (die != NULL) | |
3822 | { | |
3823 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3824 | { | |
3825 | if (a->dw_attr == attr_kind) | |
3826 | return a; | |
71dfc51f | 3827 | |
3f76745e JM |
3828 | if (a->dw_attr == DW_AT_specification |
3829 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 3830 | spec = AT_ref (a); |
3f76745e | 3831 | } |
71dfc51f | 3832 | |
3f76745e JM |
3833 | if (spec) |
3834 | return get_AT (spec, attr_kind); | |
3835 | } | |
3836 | ||
3837 | return NULL; | |
f37230f0 JM |
3838 | } |
3839 | ||
3f76745e JM |
3840 | /* Return the "low pc" attribute value, typically associated with |
3841 | a subprogram DIE. Return null if the "low pc" attribute is | |
3842 | either not prsent, or if it cannot be represented as an | |
3843 | assembler label identifier. */ | |
71dfc51f | 3844 | |
a96c67ec | 3845 | static inline const char * |
3f76745e JM |
3846 | get_AT_low_pc (die) |
3847 | register dw_die_ref die; | |
7e23cb16 | 3848 | { |
3f76745e | 3849 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
a96c67ec | 3850 | return AT_lbl (a); |
7e23cb16 JM |
3851 | } |
3852 | ||
3f76745e JM |
3853 | /* Return the "high pc" attribute value, typically associated with |
3854 | a subprogram DIE. Return null if the "high pc" attribute is | |
3855 | either not prsent, or if it cannot be represented as an | |
3856 | assembler label identifier. */ | |
71dfc51f | 3857 | |
a96c67ec | 3858 | static inline const char * |
3f76745e | 3859 | get_AT_hi_pc (die) |
a3f97cbb JW |
3860 | register dw_die_ref die; |
3861 | { | |
3f76745e | 3862 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
a96c67ec | 3863 | return AT_lbl (a); |
3f76745e JM |
3864 | } |
3865 | ||
3866 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
3867 | NULL if it is not present. */ | |
71dfc51f | 3868 | |
a96c67ec | 3869 | static inline const char * |
3f76745e JM |
3870 | get_AT_string (die, attr_kind) |
3871 | register dw_die_ref die; | |
3872 | register enum dwarf_attribute attr_kind; | |
3873 | { | |
3874 | register dw_attr_ref a = get_AT (die, attr_kind); | |
a96c67ec | 3875 | return AT_string (a); |
a3f97cbb JW |
3876 | } |
3877 | ||
3f76745e JM |
3878 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
3879 | if it is not present. */ | |
71dfc51f | 3880 | |
3f76745e JM |
3881 | static inline int |
3882 | get_AT_flag (die, attr_kind) | |
3883 | register dw_die_ref die; | |
3884 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3885 | { |
3f76745e | 3886 | register dw_attr_ref a = get_AT (die, attr_kind); |
a96c67ec | 3887 | return AT_flag (a); |
a3f97cbb JW |
3888 | } |
3889 | ||
3f76745e JM |
3890 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
3891 | if it is not present. */ | |
71dfc51f | 3892 | |
3f76745e JM |
3893 | static inline unsigned |
3894 | get_AT_unsigned (die, attr_kind) | |
3895 | register dw_die_ref die; | |
3896 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3897 | { |
3f76745e | 3898 | register dw_attr_ref a = get_AT (die, attr_kind); |
a96c67ec JM |
3899 | return AT_unsigned (a); |
3900 | } | |
71dfc51f | 3901 | |
a96c67ec JM |
3902 | static inline dw_die_ref |
3903 | get_AT_ref (die, attr_kind) | |
3904 | dw_die_ref die; | |
3905 | register enum dwarf_attribute attr_kind; | |
3906 | { | |
3907 | register dw_attr_ref a = get_AT (die, attr_kind); | |
3908 | return AT_ref (a); | |
3f76745e | 3909 | } |
71dfc51f | 3910 | |
3f76745e JM |
3911 | static inline int |
3912 | is_c_family () | |
3913 | { | |
3914 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3915 | |
3f76745e JM |
3916 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
3917 | || lang == DW_LANG_C_plus_plus); | |
3918 | } | |
71dfc51f | 3919 | |
3f76745e JM |
3920 | static inline int |
3921 | is_fortran () | |
3922 | { | |
3923 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3924 | |
3f76745e JM |
3925 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
3926 | } | |
71dfc51f | 3927 | |
10a11b75 | 3928 | /* Free up the memory used by A. */ |
71dfc51f | 3929 | |
c6991660 | 3930 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 3931 | static inline void |
10a11b75 JM |
3932 | free_AT (a) |
3933 | dw_attr_ref a; | |
3934 | { | |
3935 | switch (AT_class (a)) | |
3936 | { | |
10a11b75 JM |
3937 | case dw_val_class_str: |
3938 | case dw_val_class_lbl_id: | |
3939 | case dw_val_class_lbl_offset: | |
3940 | free (a->dw_attr_val.v.val_str); | |
3941 | break; | |
3942 | ||
3943 | default: | |
3944 | break; | |
3945 | } | |
3946 | ||
3947 | free (a); | |
3948 | } | |
3949 | ||
3950 | /* Remove the specified attribute if present. */ | |
3951 | ||
3952 | static void | |
3f76745e JM |
3953 | remove_AT (die, attr_kind) |
3954 | register dw_die_ref die; | |
3955 | register enum dwarf_attribute attr_kind; | |
3956 | { | |
a96c67ec | 3957 | register dw_attr_ref *p; |
6d649d26 | 3958 | register dw_attr_ref removed = NULL; |
a3f97cbb | 3959 | |
3f76745e JM |
3960 | if (die != NULL) |
3961 | { | |
a96c67ec JM |
3962 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
3963 | if ((*p)->dw_attr == attr_kind) | |
3964 | { | |
3965 | removed = *p; | |
3966 | *p = (*p)->dw_attr_next; | |
3967 | break; | |
3968 | } | |
71dfc51f | 3969 | |
a96c67ec | 3970 | if (removed != 0) |
10a11b75 JM |
3971 | free_AT (removed); |
3972 | } | |
3973 | } | |
71dfc51f | 3974 | |
10a11b75 | 3975 | /* Free up the memory used by DIE. */ |
71dfc51f | 3976 | |
c6991660 | 3977 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
3978 | static inline void |
3979 | free_die (die) | |
3980 | dw_die_ref die; | |
3981 | { | |
3982 | remove_children (die); | |
3983 | free (die); | |
3f76745e | 3984 | } |
71dfc51f | 3985 | |
3f76745e | 3986 | /* Discard the children of this DIE. */ |
71dfc51f | 3987 | |
10a11b75 | 3988 | static void |
3f76745e JM |
3989 | remove_children (die) |
3990 | register dw_die_ref die; | |
3991 | { | |
3992 | register dw_die_ref child_die = die->die_child; | |
3993 | ||
3994 | die->die_child = NULL; | |
3f76745e JM |
3995 | |
3996 | while (child_die != NULL) | |
a3f97cbb | 3997 | { |
3f76745e JM |
3998 | register dw_die_ref tmp_die = child_die; |
3999 | register dw_attr_ref a; | |
71dfc51f | 4000 | |
3f76745e JM |
4001 | child_die = child_die->die_sib; |
4002 | ||
4003 | for (a = tmp_die->die_attr; a != NULL; ) | |
a3f97cbb | 4004 | { |
3f76745e | 4005 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4006 | |
3f76745e | 4007 | a = a->dw_attr_next; |
10a11b75 | 4008 | free_AT (tmp_a); |
a3f97cbb | 4009 | } |
71dfc51f | 4010 | |
10a11b75 | 4011 | free_die (tmp_die); |
3f76745e JM |
4012 | } |
4013 | } | |
71dfc51f | 4014 | |
a96c67ec JM |
4015 | /* Add a child DIE below its parent. We build the lists up in reverse |
4016 | addition order, and correct that in add_sibling_attributes. */ | |
71dfc51f | 4017 | |
3f76745e JM |
4018 | static inline void |
4019 | add_child_die (die, child_die) | |
4020 | register dw_die_ref die; | |
4021 | register dw_die_ref child_die; | |
4022 | { | |
4023 | if (die != NULL && child_die != NULL) | |
e90b62db | 4024 | { |
3a88cbd1 JL |
4025 | if (die == child_die) |
4026 | abort (); | |
3f76745e | 4027 | child_die->die_parent = die; |
a96c67ec JM |
4028 | child_die->die_sib = die->die_child; |
4029 | die->die_child = child_die; | |
3f76745e JM |
4030 | } |
4031 | } | |
4032 | ||
2081603c JM |
4033 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4034 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4035 | |
4036 | static void | |
4037 | splice_child_die (parent, child) | |
4038 | dw_die_ref parent, child; | |
4039 | { | |
4040 | dw_die_ref *p; | |
4041 | ||
4042 | /* We want the declaration DIE from inside the class, not the | |
4043 | specification DIE at toplevel. */ | |
4044 | if (child->die_parent != parent) | |
2081603c JM |
4045 | { |
4046 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4047 | if (tmp) | |
4048 | child = tmp; | |
4049 | } | |
10a11b75 | 4050 | |
2081603c JM |
4051 | if (child->die_parent != parent |
4052 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4053 | abort (); |
4054 | ||
4055 | for (p = &(parent->die_child); *p; p = &((*p)->die_sib)) | |
4056 | if (*p == child) | |
4057 | { | |
4058 | *p = child->die_sib; | |
4059 | break; | |
4060 | } | |
4061 | ||
4062 | child->die_sib = parent->die_child; | |
4063 | parent->die_child = child; | |
4064 | } | |
4065 | ||
3f76745e JM |
4066 | /* Return a pointer to a newly created DIE node. */ |
4067 | ||
4068 | static inline dw_die_ref | |
4069 | new_die (tag_value, parent_die) | |
4070 | register enum dwarf_tag tag_value; | |
4071 | register dw_die_ref parent_die; | |
4072 | { | |
4073 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
4074 | ||
4075 | die->die_tag = tag_value; | |
4076 | die->die_abbrev = 0; | |
4077 | die->die_offset = 0; | |
4078 | die->die_child = NULL; | |
4079 | die->die_parent = NULL; | |
4080 | die->die_sib = NULL; | |
3f76745e | 4081 | die->die_attr = NULL; |
3f76745e JM |
4082 | |
4083 | if (parent_die != NULL) | |
4084 | add_child_die (parent_die, die); | |
4085 | else | |
ef76d03b JW |
4086 | { |
4087 | limbo_die_node *limbo_node; | |
4088 | ||
4089 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4090 | limbo_node->die = die; | |
4091 | limbo_node->next = limbo_die_list; | |
4092 | limbo_die_list = limbo_node; | |
4093 | } | |
71dfc51f | 4094 | |
3f76745e JM |
4095 | return die; |
4096 | } | |
71dfc51f | 4097 | |
3f76745e | 4098 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4099 | |
3f76745e JM |
4100 | static inline dw_die_ref |
4101 | lookup_type_die (type) | |
4102 | register tree type; | |
4103 | { | |
4104 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
4105 | } | |
e90b62db | 4106 | |
3f76745e | 4107 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4108 | |
10a11b75 | 4109 | static inline void |
3f76745e JM |
4110 | equate_type_number_to_die (type, type_die) |
4111 | register tree type; | |
4112 | register dw_die_ref type_die; | |
4113 | { | |
4114 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4115 | } | |
71dfc51f | 4116 | |
3f76745e | 4117 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4118 | |
3f76745e JM |
4119 | static inline dw_die_ref |
4120 | lookup_decl_die (decl) | |
4121 | register tree decl; | |
4122 | { | |
4123 | register unsigned decl_id = DECL_UID (decl); | |
4124 | ||
4125 | return (decl_id < decl_die_table_in_use | |
4126 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4127 | } |
4128 | ||
3f76745e | 4129 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4130 | |
3f76745e JM |
4131 | static void |
4132 | equate_decl_number_to_die (decl, decl_die) | |
4133 | register tree decl; | |
4134 | register dw_die_ref decl_die; | |
a3f97cbb | 4135 | { |
3f76745e | 4136 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 4137 | register unsigned num_allocated; |
d291dd49 | 4138 | |
3f76745e | 4139 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4140 | { |
3f76745e JM |
4141 | num_allocated |
4142 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4143 | / DECL_DIE_TABLE_INCREMENT) | |
4144 | * DECL_DIE_TABLE_INCREMENT; | |
4145 | ||
4146 | decl_die_table | |
4147 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4148 | sizeof (dw_die_ref) * num_allocated); | |
4149 | ||
4150 | bzero ((char *) &decl_die_table[decl_die_table_allocated], | |
4151 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); | |
4152 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4153 | } |
71dfc51f | 4154 | |
3f76745e JM |
4155 | if (decl_id >= decl_die_table_in_use) |
4156 | decl_die_table_in_use = (decl_id + 1); | |
4157 | ||
4158 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb JW |
4159 | } |
4160 | ||
3f76745e JM |
4161 | /* Return a pointer to a newly allocated location description. Location |
4162 | descriptions are simple expression terms that can be strung | |
4163 | together to form more complicated location (address) descriptions. */ | |
71dfc51f | 4164 | |
3f76745e JM |
4165 | static inline dw_loc_descr_ref |
4166 | new_loc_descr (op, oprnd1, oprnd2) | |
4167 | register enum dwarf_location_atom op; | |
4168 | register unsigned long oprnd1; | |
4169 | register unsigned long oprnd2; | |
a3f97cbb | 4170 | { |
3f76745e JM |
4171 | register dw_loc_descr_ref descr |
4172 | = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node)); | |
71dfc51f | 4173 | |
3f76745e JM |
4174 | descr->dw_loc_next = NULL; |
4175 | descr->dw_loc_opc = op; | |
4176 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
4177 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
4178 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
4179 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 4180 | |
3f76745e | 4181 | return descr; |
a3f97cbb | 4182 | } |
71dfc51f | 4183 | |
3f76745e JM |
4184 | /* Add a location description term to a location description expression. */ |
4185 | ||
4186 | static inline void | |
4187 | add_loc_descr (list_head, descr) | |
4188 | register dw_loc_descr_ref *list_head; | |
4189 | register dw_loc_descr_ref descr; | |
a3f97cbb | 4190 | { |
3f76745e | 4191 | register dw_loc_descr_ref *d; |
71dfc51f | 4192 | |
3f76745e JM |
4193 | /* Find the end of the chain. */ |
4194 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
4195 | ; | |
71dfc51f | 4196 | |
3f76745e JM |
4197 | *d = descr; |
4198 | } | |
4199 | \f | |
4200 | /* Keep track of the number of spaces used to indent the | |
4201 | output of the debugging routines that print the structure of | |
4202 | the DIE internal representation. */ | |
4203 | static int print_indent; | |
71dfc51f | 4204 | |
3f76745e JM |
4205 | /* Indent the line the number of spaces given by print_indent. */ |
4206 | ||
4207 | static inline void | |
4208 | print_spaces (outfile) | |
4209 | FILE *outfile; | |
4210 | { | |
4211 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4212 | } |
4213 | ||
956d6950 | 4214 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4215 | This routine is a debugging aid only. */ |
71dfc51f | 4216 | |
a3f97cbb | 4217 | static void |
3f76745e JM |
4218 | print_die (die, outfile) |
4219 | dw_die_ref die; | |
4220 | FILE *outfile; | |
a3f97cbb | 4221 | { |
3f76745e JM |
4222 | register dw_attr_ref a; |
4223 | register dw_die_ref c; | |
71dfc51f | 4224 | |
3f76745e | 4225 | print_spaces (outfile); |
2d8b0f3a | 4226 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
4227 | die->die_offset, dwarf_tag_name (die->die_tag)); |
4228 | print_spaces (outfile); | |
2d8b0f3a JL |
4229 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
4230 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
4231 | |
4232 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 4233 | { |
3f76745e JM |
4234 | print_spaces (outfile); |
4235 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
4236 | ||
a96c67ec | 4237 | switch (AT_class (a)) |
3f76745e JM |
4238 | { |
4239 | case dw_val_class_addr: | |
4240 | fprintf (outfile, "address"); | |
4241 | break; | |
4242 | case dw_val_class_loc: | |
4243 | fprintf (outfile, "location descriptor"); | |
4244 | break; | |
4245 | case dw_val_class_const: | |
a96c67ec | 4246 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
4247 | break; |
4248 | case dw_val_class_unsigned_const: | |
a96c67ec | 4249 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
4250 | break; |
4251 | case dw_val_class_long_long: | |
2d8b0f3a | 4252 | fprintf (outfile, "constant (%lu,%lu)", |
3f76745e JM |
4253 | a->dw_attr_val.v.val_long_long.hi, |
4254 | a->dw_attr_val.v.val_long_long.low); | |
4255 | break; | |
4256 | case dw_val_class_float: | |
4257 | fprintf (outfile, "floating-point constant"); | |
4258 | break; | |
4259 | case dw_val_class_flag: | |
a96c67ec | 4260 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
4261 | break; |
4262 | case dw_val_class_die_ref: | |
a96c67ec JM |
4263 | if (AT_ref (a) != NULL) |
4264 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
3f76745e JM |
4265 | else |
4266 | fprintf (outfile, "die -> <null>"); | |
4267 | break; | |
4268 | case dw_val_class_lbl_id: | |
8b790721 | 4269 | case dw_val_class_lbl_offset: |
a96c67ec | 4270 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 4271 | break; |
3f76745e | 4272 | case dw_val_class_str: |
a96c67ec JM |
4273 | if (AT_string (a) != NULL) |
4274 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
4275 | else |
4276 | fprintf (outfile, "<null>"); | |
4277 | break; | |
e9a25f70 JL |
4278 | default: |
4279 | break; | |
3f76745e JM |
4280 | } |
4281 | ||
4282 | fprintf (outfile, "\n"); | |
4283 | } | |
4284 | ||
4285 | if (die->die_child != NULL) | |
4286 | { | |
4287 | print_indent += 4; | |
4288 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4289 | print_die (c, outfile); | |
71dfc51f | 4290 | |
3f76745e | 4291 | print_indent -= 4; |
a3f97cbb | 4292 | } |
a3f97cbb JW |
4293 | } |
4294 | ||
3f76745e JM |
4295 | /* Print the contents of the source code line number correspondence table. |
4296 | This routine is a debugging aid only. */ | |
71dfc51f | 4297 | |
3f76745e JM |
4298 | static void |
4299 | print_dwarf_line_table (outfile) | |
4300 | FILE *outfile; | |
a3f97cbb | 4301 | { |
3f76745e JM |
4302 | register unsigned i; |
4303 | register dw_line_info_ref line_info; | |
4304 | ||
4305 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
4306 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 4307 | { |
3f76745e JM |
4308 | line_info = &line_info_table[i]; |
4309 | fprintf (outfile, "%5d: ", i); | |
4310 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
2d8b0f3a | 4311 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 4312 | fprintf (outfile, "\n"); |
a3f97cbb | 4313 | } |
3f76745e JM |
4314 | |
4315 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
4316 | } |
4317 | ||
3f76745e JM |
4318 | /* Print the information collected for a given DIE. */ |
4319 | ||
4320 | void | |
4321 | debug_dwarf_die (die) | |
4322 | dw_die_ref die; | |
4323 | { | |
4324 | print_die (die, stderr); | |
4325 | } | |
4326 | ||
4327 | /* Print all DWARF information collected for the compilation unit. | |
4328 | This routine is a debugging aid only. */ | |
4329 | ||
4330 | void | |
4331 | debug_dwarf () | |
4332 | { | |
4333 | print_indent = 0; | |
4334 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
4335 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
4336 | print_dwarf_line_table (stderr); | |
3f76745e JM |
4337 | } |
4338 | \f | |
a96c67ec JM |
4339 | /* We build up the lists of children and attributes by pushing new ones |
4340 | onto the beginning of the list. Reverse the lists for DIE so that | |
4341 | they are in order of addition. */ | |
71dfc51f | 4342 | |
f37230f0 | 4343 | static void |
a96c67ec | 4344 | reverse_die_lists (die) |
3f76745e | 4345 | register dw_die_ref die; |
f37230f0 | 4346 | { |
a96c67ec JM |
4347 | register dw_die_ref c, cp, cn; |
4348 | register dw_attr_ref a, ap, an; | |
71dfc51f | 4349 | |
a96c67ec JM |
4350 | for (a = die->die_attr, ap = 0; a; a = an) |
4351 | { | |
4352 | an = a->dw_attr_next; | |
4353 | a->dw_attr_next = ap; | |
4354 | ap = a; | |
4355 | } | |
4356 | die->die_attr = ap; | |
71dfc51f | 4357 | |
a96c67ec JM |
4358 | for (c = die->die_child, cp = 0; c; c = cn) |
4359 | { | |
4360 | cn = c->die_sib; | |
4361 | c->die_sib = cp; | |
4362 | cp = c; | |
3f76745e | 4363 | } |
a96c67ec JM |
4364 | die->die_child = cp; |
4365 | } | |
4366 | ||
4367 | /* Traverse the DIE, reverse its lists of attributes and children, and | |
4368 | add a sibling attribute if it may have the effect of speeding up | |
4369 | access to siblings. To save some space, avoid generating sibling | |
4370 | attributes for DIE's without children. */ | |
4371 | ||
4372 | static void | |
4373 | add_sibling_attributes (die) | |
4374 | register dw_die_ref die; | |
4375 | { | |
4376 | register dw_die_ref c; | |
4377 | ||
4378 | reverse_die_lists (die); | |
4379 | ||
4380 | if (die != comp_unit_die && die->die_sib && die->die_child != NULL) | |
4381 | /* Add the sibling link to the front of the attribute list. */ | |
4382 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
3f76745e JM |
4383 | |
4384 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4385 | add_sibling_attributes (c); | |
a3f97cbb JW |
4386 | } |
4387 | ||
3f76745e JM |
4388 | /* The format of each DIE (and its attribute value pairs) |
4389 | is encoded in an abbreviation table. This routine builds the | |
4390 | abbreviation table and assigns a unique abbreviation id for | |
4391 | each abbreviation entry. The children of each die are visited | |
4392 | recursively. */ | |
71dfc51f | 4393 | |
a3f97cbb | 4394 | static void |
3f76745e JM |
4395 | build_abbrev_table (die) |
4396 | register dw_die_ref die; | |
a3f97cbb | 4397 | { |
3f76745e JM |
4398 | register unsigned long abbrev_id; |
4399 | register unsigned long n_alloc; | |
4400 | register dw_die_ref c; | |
4401 | register dw_attr_ref d_attr, a_attr; | |
a3f97cbb JW |
4402 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
4403 | { | |
4404 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4405 | |
3f76745e JM |
4406 | if (abbrev->die_tag == die->die_tag) |
4407 | { | |
4408 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
4409 | { | |
4410 | a_attr = abbrev->die_attr; | |
4411 | d_attr = die->die_attr; | |
71dfc51f | 4412 | |
3f76745e JM |
4413 | while (a_attr != NULL && d_attr != NULL) |
4414 | { | |
4415 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
a96c67ec | 4416 | || (value_format (a_attr) != value_format (d_attr))) |
3f76745e | 4417 | break; |
71dfc51f | 4418 | |
3f76745e JM |
4419 | a_attr = a_attr->dw_attr_next; |
4420 | d_attr = d_attr->dw_attr_next; | |
4421 | } | |
71dfc51f | 4422 | |
3f76745e JM |
4423 | if (a_attr == NULL && d_attr == NULL) |
4424 | break; | |
4425 | } | |
4426 | } | |
4427 | } | |
71dfc51f | 4428 | |
3f76745e JM |
4429 | if (abbrev_id >= abbrev_die_table_in_use) |
4430 | { | |
4431 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
a3f97cbb | 4432 | { |
3f76745e JM |
4433 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; |
4434 | abbrev_die_table | |
c760091a | 4435 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
966f5dff | 4436 | sizeof (dw_die_ref) * n_alloc); |
71dfc51f | 4437 | |
3f76745e JM |
4438 | bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated], |
4439 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); | |
4440 | abbrev_die_table_allocated = n_alloc; | |
a3f97cbb | 4441 | } |
71dfc51f | 4442 | |
3f76745e JM |
4443 | ++abbrev_die_table_in_use; |
4444 | abbrev_die_table[abbrev_id] = die; | |
a3f97cbb | 4445 | } |
3f76745e JM |
4446 | |
4447 | die->die_abbrev = abbrev_id; | |
4448 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4449 | build_abbrev_table (c); | |
a3f97cbb | 4450 | } |
3f76745e | 4451 | \f |
243e7835 JW |
4452 | /* Return the size of a string, including the null byte. |
4453 | ||
4454 | This used to treat backslashes as escapes, and hence they were not included | |
4455 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
4456 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
4457 | we must include them in the count. */ | |
a3f97cbb | 4458 | |
3f76745e JM |
4459 | static unsigned long |
4460 | size_of_string (str) | |
a96c67ec | 4461 | register const char *str; |
3f76745e | 4462 | { |
243e7835 | 4463 | return strlen (str) + 1; |
3f76745e JM |
4464 | } |
4465 | ||
4466 | /* Return the size of a location descriptor. */ | |
4467 | ||
4468 | static unsigned long | |
4469 | size_of_loc_descr (loc) | |
a3f97cbb JW |
4470 | register dw_loc_descr_ref loc; |
4471 | { | |
3f76745e | 4472 | register unsigned long size = 1; |
71dfc51f | 4473 | |
a3f97cbb JW |
4474 | switch (loc->dw_loc_opc) |
4475 | { | |
4476 | case DW_OP_addr: | |
a1a4189d | 4477 | size += DWARF2_ADDR_SIZE; |
a3f97cbb JW |
4478 | break; |
4479 | case DW_OP_const1u: | |
4480 | case DW_OP_const1s: | |
3f76745e | 4481 | size += 1; |
a3f97cbb JW |
4482 | break; |
4483 | case DW_OP_const2u: | |
4484 | case DW_OP_const2s: | |
3f76745e | 4485 | size += 2; |
a3f97cbb JW |
4486 | break; |
4487 | case DW_OP_const4u: | |
4488 | case DW_OP_const4s: | |
3f76745e | 4489 | size += 4; |
a3f97cbb JW |
4490 | break; |
4491 | case DW_OP_const8u: | |
4492 | case DW_OP_const8s: | |
3f76745e | 4493 | size += 8; |
a3f97cbb JW |
4494 | break; |
4495 | case DW_OP_constu: | |
3f76745e | 4496 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4497 | break; |
4498 | case DW_OP_consts: | |
3f76745e | 4499 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4500 | break; |
4501 | case DW_OP_pick: | |
3f76745e | 4502 | size += 1; |
a3f97cbb JW |
4503 | break; |
4504 | case DW_OP_plus_uconst: | |
3f76745e | 4505 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4506 | break; |
4507 | case DW_OP_skip: | |
4508 | case DW_OP_bra: | |
3f76745e | 4509 | size += 2; |
a3f97cbb JW |
4510 | break; |
4511 | case DW_OP_breg0: | |
4512 | case DW_OP_breg1: | |
4513 | case DW_OP_breg2: | |
4514 | case DW_OP_breg3: | |
4515 | case DW_OP_breg4: | |
4516 | case DW_OP_breg5: | |
4517 | case DW_OP_breg6: | |
4518 | case DW_OP_breg7: | |
4519 | case DW_OP_breg8: | |
4520 | case DW_OP_breg9: | |
4521 | case DW_OP_breg10: | |
4522 | case DW_OP_breg11: | |
4523 | case DW_OP_breg12: | |
4524 | case DW_OP_breg13: | |
4525 | case DW_OP_breg14: | |
4526 | case DW_OP_breg15: | |
4527 | case DW_OP_breg16: | |
4528 | case DW_OP_breg17: | |
4529 | case DW_OP_breg18: | |
4530 | case DW_OP_breg19: | |
4531 | case DW_OP_breg20: | |
4532 | case DW_OP_breg21: | |
4533 | case DW_OP_breg22: | |
4534 | case DW_OP_breg23: | |
4535 | case DW_OP_breg24: | |
4536 | case DW_OP_breg25: | |
4537 | case DW_OP_breg26: | |
4538 | case DW_OP_breg27: | |
4539 | case DW_OP_breg28: | |
4540 | case DW_OP_breg29: | |
4541 | case DW_OP_breg30: | |
4542 | case DW_OP_breg31: | |
3f76745e | 4543 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4544 | break; |
4545 | case DW_OP_regx: | |
3f76745e | 4546 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4547 | break; |
4548 | case DW_OP_fbreg: | |
3f76745e | 4549 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4550 | break; |
4551 | case DW_OP_bregx: | |
3f76745e JM |
4552 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
4553 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
a3f97cbb JW |
4554 | break; |
4555 | case DW_OP_piece: | |
3f76745e | 4556 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4557 | break; |
4558 | case DW_OP_deref_size: | |
4559 | case DW_OP_xderef_size: | |
3f76745e | 4560 | size += 1; |
a3f97cbb JW |
4561 | break; |
4562 | default: | |
4563 | break; | |
4564 | } | |
3f76745e JM |
4565 | |
4566 | return size; | |
a3f97cbb JW |
4567 | } |
4568 | ||
3f76745e | 4569 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 4570 | |
a3f97cbb | 4571 | static unsigned long |
3f76745e JM |
4572 | size_of_locs (loc) |
4573 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4574 | { |
3f76745e | 4575 | register unsigned long size = 0; |
71dfc51f | 4576 | |
3f76745e JM |
4577 | for (; loc != NULL; loc = loc->dw_loc_next) |
4578 | size += size_of_loc_descr (loc); | |
4579 | ||
4580 | return size; | |
4581 | } | |
4582 | ||
4583 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
4584 | ||
4585 | static int | |
4586 | constant_size (value) | |
4587 | long unsigned value; | |
4588 | { | |
4589 | int log; | |
4590 | ||
4591 | if (value == 0) | |
4592 | log = 0; | |
a3f97cbb | 4593 | else |
3f76745e | 4594 | log = floor_log2 (value); |
71dfc51f | 4595 | |
3f76745e JM |
4596 | log = log / 8; |
4597 | log = 1 << (floor_log2 (log) + 1); | |
4598 | ||
4599 | return log; | |
a3f97cbb JW |
4600 | } |
4601 | ||
3f76745e JM |
4602 | /* Return the size of a DIE, as it is represented in the |
4603 | .debug_info section. */ | |
71dfc51f | 4604 | |
3f76745e JM |
4605 | static unsigned long |
4606 | size_of_die (die) | |
a3f97cbb JW |
4607 | register dw_die_ref die; |
4608 | { | |
3f76745e | 4609 | register unsigned long size = 0; |
a3f97cbb | 4610 | register dw_attr_ref a; |
71dfc51f | 4611 | |
3f76745e | 4612 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
4613 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
4614 | { | |
a96c67ec | 4615 | switch (AT_class (a)) |
a3f97cbb JW |
4616 | { |
4617 | case dw_val_class_addr: | |
a1a4189d | 4618 | size += DWARF2_ADDR_SIZE; |
a3f97cbb JW |
4619 | break; |
4620 | case dw_val_class_loc: | |
3f76745e | 4621 | { |
a96c67ec | 4622 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 4623 | |
3f76745e JM |
4624 | /* Block length. */ |
4625 | size += constant_size (lsize); | |
4626 | size += lsize; | |
4627 | } | |
a3f97cbb JW |
4628 | break; |
4629 | case dw_val_class_const: | |
3f76745e | 4630 | size += 4; |
a3f97cbb JW |
4631 | break; |
4632 | case dw_val_class_unsigned_const: | |
a96c67ec | 4633 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 4634 | break; |
469ac993 | 4635 | case dw_val_class_long_long: |
3f76745e | 4636 | size += 1 + 8; /* block */ |
469ac993 JM |
4637 | break; |
4638 | case dw_val_class_float: | |
3f76745e | 4639 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
4640 | break; |
4641 | case dw_val_class_flag: | |
3f76745e | 4642 | size += 1; |
a3f97cbb JW |
4643 | break; |
4644 | case dw_val_class_die_ref: | |
3f76745e | 4645 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4646 | break; |
4647 | case dw_val_class_fde_ref: | |
3f76745e | 4648 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4649 | break; |
4650 | case dw_val_class_lbl_id: | |
a1a4189d | 4651 | size += DWARF2_ADDR_SIZE; |
3f76745e | 4652 | break; |
8b790721 | 4653 | case dw_val_class_lbl_offset: |
3f76745e JM |
4654 | size += DWARF_OFFSET_SIZE; |
4655 | break; | |
4656 | case dw_val_class_str: | |
a96c67ec | 4657 | size += size_of_string (AT_string (a)); |
3f76745e JM |
4658 | break; |
4659 | default: | |
4660 | abort (); | |
4661 | } | |
a3f97cbb | 4662 | } |
3f76745e JM |
4663 | |
4664 | return size; | |
a3f97cbb JW |
4665 | } |
4666 | ||
956d6950 | 4667 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
4668 | Visits the DIE's children recursively. Updates the global |
4669 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 4670 | current value of next_die_offset to update the die_offset |
3f76745e | 4671 | field in each DIE. */ |
71dfc51f | 4672 | |
a3f97cbb | 4673 | static void |
3f76745e JM |
4674 | calc_die_sizes (die) |
4675 | dw_die_ref die; | |
a3f97cbb | 4676 | { |
3f76745e JM |
4677 | register dw_die_ref c; |
4678 | die->die_offset = next_die_offset; | |
4679 | next_die_offset += size_of_die (die); | |
71dfc51f | 4680 | |
3f76745e JM |
4681 | for (c = die->die_child; c != NULL; c = c->die_sib) |
4682 | calc_die_sizes (c); | |
71dfc51f | 4683 | |
3f76745e JM |
4684 | if (die->die_child != NULL) |
4685 | /* Count the null byte used to terminate sibling lists. */ | |
4686 | next_die_offset += 1; | |
a3f97cbb JW |
4687 | } |
4688 | ||
3f76745e JM |
4689 | /* Return the size of the line information prolog generated for the |
4690 | compilation unit. */ | |
469ac993 | 4691 | |
3f76745e JM |
4692 | static unsigned long |
4693 | size_of_line_prolog () | |
a94dbf2c | 4694 | { |
3f76745e JM |
4695 | register unsigned long size; |
4696 | register unsigned long ft_index; | |
a94dbf2c | 4697 | |
3f76745e | 4698 | size = DWARF_LINE_PROLOG_HEADER_SIZE; |
469ac993 | 4699 | |
3f76745e JM |
4700 | /* Count the size of the table giving number of args for each |
4701 | standard opcode. */ | |
4702 | size += DWARF_LINE_OPCODE_BASE - 1; | |
71dfc51f | 4703 | |
3f76745e | 4704 | /* Include directory table is empty (at present). Count only the |
38e01259 | 4705 | null byte used to terminate the table. */ |
3f76745e | 4706 | size += 1; |
71dfc51f | 4707 | |
3f76745e JM |
4708 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
4709 | { | |
4710 | /* File name entry. */ | |
4711 | size += size_of_string (file_table[ft_index]); | |
a94dbf2c | 4712 | |
3f76745e JM |
4713 | /* Include directory index. */ |
4714 | size += size_of_uleb128 (0); | |
a94dbf2c | 4715 | |
3f76745e JM |
4716 | /* Modification time. */ |
4717 | size += size_of_uleb128 (0); | |
71dfc51f | 4718 | |
3f76745e JM |
4719 | /* File length in bytes. */ |
4720 | size += size_of_uleb128 (0); | |
a94dbf2c | 4721 | } |
71dfc51f | 4722 | |
3f76745e JM |
4723 | /* Count the file table terminator. */ |
4724 | size += 1; | |
4725 | return size; | |
a94dbf2c JM |
4726 | } |
4727 | ||
3f76745e JM |
4728 | /* Return the size of the .debug_pubnames table generated for the |
4729 | compilation unit. */ | |
a94dbf2c | 4730 | |
3f76745e JM |
4731 | static unsigned long |
4732 | size_of_pubnames () | |
a94dbf2c | 4733 | { |
3f76745e JM |
4734 | register unsigned long size; |
4735 | register unsigned i; | |
469ac993 | 4736 | |
3f76745e JM |
4737 | size = DWARF_PUBNAMES_HEADER_SIZE; |
4738 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 4739 | { |
3f76745e JM |
4740 | register pubname_ref p = &pubname_table[i]; |
4741 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
4742 | } |
4743 | ||
3f76745e JM |
4744 | size += DWARF_OFFSET_SIZE; |
4745 | return size; | |
a94dbf2c JM |
4746 | } |
4747 | ||
956d6950 | 4748 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 4749 | |
3f76745e JM |
4750 | static unsigned long |
4751 | size_of_aranges () | |
469ac993 | 4752 | { |
3f76745e | 4753 | register unsigned long size; |
469ac993 | 4754 | |
3f76745e | 4755 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 4756 | |
3f76745e | 4757 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
4758 | size += 2 * DWARF2_ADDR_SIZE; |
4759 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 4760 | |
3f76745e | 4761 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 4762 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
4763 | return size; |
4764 | } | |
4765 | \f | |
4766 | /* Select the encoding of an attribute value. */ | |
4767 | ||
4768 | static enum dwarf_form | |
a96c67ec JM |
4769 | value_format (a) |
4770 | dw_attr_ref a; | |
3f76745e | 4771 | { |
a96c67ec | 4772 | switch (a->dw_attr_val.val_class) |
469ac993 | 4773 | { |
3f76745e JM |
4774 | case dw_val_class_addr: |
4775 | return DW_FORM_addr; | |
4776 | case dw_val_class_loc: | |
a96c67ec | 4777 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 4778 | { |
3f76745e JM |
4779 | case 1: |
4780 | return DW_FORM_block1; | |
4781 | case 2: | |
4782 | return DW_FORM_block2; | |
469ac993 JM |
4783 | default: |
4784 | abort (); | |
4785 | } | |
3f76745e JM |
4786 | case dw_val_class_const: |
4787 | return DW_FORM_data4; | |
4788 | case dw_val_class_unsigned_const: | |
a96c67ec | 4789 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
4790 | { |
4791 | case 1: | |
4792 | return DW_FORM_data1; | |
4793 | case 2: | |
4794 | return DW_FORM_data2; | |
4795 | case 4: | |
4796 | return DW_FORM_data4; | |
4797 | case 8: | |
4798 | return DW_FORM_data8; | |
4799 | default: | |
4800 | abort (); | |
4801 | } | |
4802 | case dw_val_class_long_long: | |
4803 | return DW_FORM_block1; | |
4804 | case dw_val_class_float: | |
4805 | return DW_FORM_block1; | |
4806 | case dw_val_class_flag: | |
4807 | return DW_FORM_flag; | |
4808 | case dw_val_class_die_ref: | |
4809 | return DW_FORM_ref; | |
4810 | case dw_val_class_fde_ref: | |
4811 | return DW_FORM_data; | |
4812 | case dw_val_class_lbl_id: | |
4813 | return DW_FORM_addr; | |
8b790721 | 4814 | case dw_val_class_lbl_offset: |
3f76745e JM |
4815 | return DW_FORM_data; |
4816 | case dw_val_class_str: | |
4817 | return DW_FORM_string; | |
469ac993 JM |
4818 | default: |
4819 | abort (); | |
4820 | } | |
a94dbf2c JM |
4821 | } |
4822 | ||
3f76745e | 4823 | /* Output the encoding of an attribute value. */ |
469ac993 | 4824 | |
3f76745e | 4825 | static void |
a96c67ec JM |
4826 | output_value_format (a) |
4827 | dw_attr_ref a; | |
a94dbf2c | 4828 | { |
a96c67ec | 4829 | enum dwarf_form form = value_format (a); |
71dfc51f | 4830 | |
3f76745e | 4831 | output_uleb128 (form); |
c5cec899 | 4832 | if (flag_debug_asm) |
3f76745e | 4833 | fprintf (asm_out_file, " (%s)", dwarf_form_name (form)); |
141719a8 | 4834 | |
3f76745e JM |
4835 | fputc ('\n', asm_out_file); |
4836 | } | |
469ac993 | 4837 | |
3f76745e JM |
4838 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
4839 | table. */ | |
469ac993 | 4840 | |
3f76745e JM |
4841 | static void |
4842 | output_abbrev_section () | |
4843 | { | |
4844 | unsigned long abbrev_id; | |
71dfc51f | 4845 | |
3f76745e JM |
4846 | dw_attr_ref a_attr; |
4847 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
4848 | { | |
4849 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4850 | |
3f76745e | 4851 | output_uleb128 (abbrev_id); |
c5cec899 | 4852 | if (flag_debug_asm) |
3f76745e | 4853 | fprintf (asm_out_file, " (abbrev code)"); |
469ac993 | 4854 | |
3f76745e JM |
4855 | fputc ('\n', asm_out_file); |
4856 | output_uleb128 (abbrev->die_tag); | |
c5cec899 | 4857 | if (flag_debug_asm) |
3f76745e JM |
4858 | fprintf (asm_out_file, " (TAG: %s)", |
4859 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 4860 | |
3f76745e JM |
4861 | fputc ('\n', asm_out_file); |
4862 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, | |
4863 | abbrev->die_child != NULL ? DW_children_yes : DW_children_no); | |
469ac993 | 4864 | |
c5cec899 | 4865 | if (flag_debug_asm) |
3f76745e JM |
4866 | fprintf (asm_out_file, "\t%s %s", |
4867 | ASM_COMMENT_START, | |
4868 | (abbrev->die_child != NULL | |
4869 | ? "DW_children_yes" : "DW_children_no")); | |
4870 | ||
4871 | fputc ('\n', asm_out_file); | |
4872 | ||
4873 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
4874 | a_attr = a_attr->dw_attr_next) | |
4875 | { | |
4876 | output_uleb128 (a_attr->dw_attr); | |
c5cec899 | 4877 | if (flag_debug_asm) |
3f76745e JM |
4878 | fprintf (asm_out_file, " (%s)", |
4879 | dwarf_attr_name (a_attr->dw_attr)); | |
4880 | ||
4881 | fputc ('\n', asm_out_file); | |
a96c67ec | 4882 | output_value_format (a_attr); |
469ac993 | 4883 | } |
469ac993 | 4884 | |
3f76745e | 4885 | fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); |
469ac993 | 4886 | } |
81f374eb HPN |
4887 | |
4888 | /* Terminate the table. */ | |
4889 | fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP); | |
a94dbf2c JM |
4890 | } |
4891 | ||
3f76745e | 4892 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 4893 | |
3f76745e JM |
4894 | static void |
4895 | output_loc_operands (loc) | |
4896 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4897 | { |
3f76745e JM |
4898 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
4899 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
71dfc51f | 4900 | |
3f76745e | 4901 | switch (loc->dw_loc_opc) |
a3f97cbb | 4902 | { |
3f76745e JM |
4903 | case DW_OP_addr: |
4904 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); | |
4905 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4906 | break; |
3f76745e JM |
4907 | case DW_OP_const1u: |
4908 | case DW_OP_const1s: | |
4909 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
4910 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4911 | break; |
3f76745e JM |
4912 | case DW_OP_const2u: |
4913 | case DW_OP_const2s: | |
4914 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
4915 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4916 | break; |
3f76745e JM |
4917 | case DW_OP_const4u: |
4918 | case DW_OP_const4s: | |
4919 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); | |
4920 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4921 | break; |
3f76745e JM |
4922 | case DW_OP_const8u: |
4923 | case DW_OP_const8s: | |
4924 | abort (); | |
4925 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4926 | break; |
3f76745e JM |
4927 | case DW_OP_constu: |
4928 | output_uleb128 (val1->v.val_unsigned); | |
4929 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4930 | break; |
3f76745e JM |
4931 | case DW_OP_consts: |
4932 | output_sleb128 (val1->v.val_int); | |
4933 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4934 | break; |
3f76745e JM |
4935 | case DW_OP_pick: |
4936 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
4937 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4938 | break; |
3f76745e JM |
4939 | case DW_OP_plus_uconst: |
4940 | output_uleb128 (val1->v.val_unsigned); | |
4941 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4942 | break; |
3f76745e JM |
4943 | case DW_OP_skip: |
4944 | case DW_OP_bra: | |
4945 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
4946 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4947 | break; |
3f76745e JM |
4948 | case DW_OP_breg0: |
4949 | case DW_OP_breg1: | |
4950 | case DW_OP_breg2: | |
4951 | case DW_OP_breg3: | |
4952 | case DW_OP_breg4: | |
4953 | case DW_OP_breg5: | |
4954 | case DW_OP_breg6: | |
4955 | case DW_OP_breg7: | |
4956 | case DW_OP_breg8: | |
4957 | case DW_OP_breg9: | |
4958 | case DW_OP_breg10: | |
4959 | case DW_OP_breg11: | |
4960 | case DW_OP_breg12: | |
4961 | case DW_OP_breg13: | |
4962 | case DW_OP_breg14: | |
4963 | case DW_OP_breg15: | |
4964 | case DW_OP_breg16: | |
4965 | case DW_OP_breg17: | |
4966 | case DW_OP_breg18: | |
4967 | case DW_OP_breg19: | |
4968 | case DW_OP_breg20: | |
4969 | case DW_OP_breg21: | |
4970 | case DW_OP_breg22: | |
4971 | case DW_OP_breg23: | |
4972 | case DW_OP_breg24: | |
4973 | case DW_OP_breg25: | |
4974 | case DW_OP_breg26: | |
4975 | case DW_OP_breg27: | |
4976 | case DW_OP_breg28: | |
4977 | case DW_OP_breg29: | |
4978 | case DW_OP_breg30: | |
4979 | case DW_OP_breg31: | |
4980 | output_sleb128 (val1->v.val_int); | |
4981 | fputc ('\n', asm_out_file); | |
4982 | break; | |
4983 | case DW_OP_regx: | |
4984 | output_uleb128 (val1->v.val_unsigned); | |
4985 | fputc ('\n', asm_out_file); | |
4986 | break; | |
4987 | case DW_OP_fbreg: | |
4988 | output_sleb128 (val1->v.val_int); | |
4989 | fputc ('\n', asm_out_file); | |
4990 | break; | |
4991 | case DW_OP_bregx: | |
4992 | output_uleb128 (val1->v.val_unsigned); | |
4993 | fputc ('\n', asm_out_file); | |
4994 | output_sleb128 (val2->v.val_int); | |
4995 | fputc ('\n', asm_out_file); | |
4996 | break; | |
4997 | case DW_OP_piece: | |
4998 | output_uleb128 (val1->v.val_unsigned); | |
4999 | fputc ('\n', asm_out_file); | |
5000 | break; | |
5001 | case DW_OP_deref_size: | |
5002 | case DW_OP_xderef_size: | |
5003 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
5004 | fputc ('\n', asm_out_file); | |
a3f97cbb JW |
5005 | break; |
5006 | default: | |
5007 | break; | |
5008 | } | |
a3f97cbb JW |
5009 | } |
5010 | ||
3f76745e JM |
5011 | /* Output the DIE and its attributes. Called recursively to generate |
5012 | the definitions of each child DIE. */ | |
71dfc51f | 5013 | |
a3f97cbb | 5014 | static void |
3f76745e JM |
5015 | output_die (die) |
5016 | register dw_die_ref die; | |
a3f97cbb | 5017 | { |
3f76745e JM |
5018 | register dw_attr_ref a; |
5019 | register dw_die_ref c; | |
3f76745e JM |
5020 | register unsigned long size; |
5021 | register dw_loc_descr_ref loc; | |
a94dbf2c | 5022 | |
3f76745e | 5023 | output_uleb128 (die->die_abbrev); |
c5cec899 | 5024 | if (flag_debug_asm) |
2d8b0f3a | 5025 | fprintf (asm_out_file, " (DIE (0x%lx) %s)", |
3f76745e | 5026 | die->die_offset, dwarf_tag_name (die->die_tag)); |
a94dbf2c | 5027 | |
3f76745e | 5028 | fputc ('\n', asm_out_file); |
a94dbf2c | 5029 | |
3f76745e | 5030 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 5031 | { |
a96c67ec | 5032 | switch (AT_class (a)) |
3f76745e JM |
5033 | { |
5034 | case dw_val_class_addr: | |
a96c67ec | 5035 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a)); |
3f76745e | 5036 | break; |
a3f97cbb | 5037 | |
3f76745e | 5038 | case dw_val_class_loc: |
a96c67ec | 5039 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 5040 | |
3f76745e JM |
5041 | /* Output the block length for this list of location operations. */ |
5042 | switch (constant_size (size)) | |
5043 | { | |
5044 | case 1: | |
5045 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size); | |
5046 | break; | |
5047 | case 2: | |
5048 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
5049 | break; | |
5050 | default: | |
5051 | abort (); | |
5052 | } | |
71dfc51f | 5053 | |
c5cec899 | 5054 | if (flag_debug_asm) |
3f76745e JM |
5055 | fprintf (asm_out_file, "\t%s %s", |
5056 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
71dfc51f | 5057 | |
3f76745e | 5058 | fputc ('\n', asm_out_file); |
a96c67ec | 5059 | for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next) |
3f76745e JM |
5060 | { |
5061 | /* Output the opcode. */ | |
5062 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
c5cec899 | 5063 | if (flag_debug_asm) |
3f76745e JM |
5064 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
5065 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
71dfc51f | 5066 | |
3f76745e | 5067 | fputc ('\n', asm_out_file); |
71dfc51f | 5068 | |
3f76745e JM |
5069 | /* Output the operand(s) (if any). */ |
5070 | output_loc_operands (loc); | |
5071 | } | |
a3f97cbb | 5072 | break; |
3f76745e JM |
5073 | |
5074 | case dw_val_class_const: | |
a96c67ec | 5075 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a)); |
a3f97cbb | 5076 | break; |
3f76745e JM |
5077 | |
5078 | case dw_val_class_unsigned_const: | |
a96c67ec | 5079 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5080 | { |
5081 | case 1: | |
a96c67ec | 5082 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5083 | break; |
5084 | case 2: | |
a96c67ec | 5085 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5086 | break; |
5087 | case 4: | |
a96c67ec | 5088 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5089 | break; |
5090 | case 8: | |
5091 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5092 | a->dw_attr_val.v.val_long_long.hi, | |
5093 | a->dw_attr_val.v.val_long_long.low); | |
5094 | break; | |
5095 | default: | |
5096 | abort (); | |
5097 | } | |
a3f97cbb | 5098 | break; |
3f76745e JM |
5099 | |
5100 | case dw_val_class_long_long: | |
5101 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8); | |
c5cec899 | 5102 | if (flag_debug_asm) |
3f76745e JM |
5103 | fprintf (asm_out_file, "\t%s %s", |
5104 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5105 | ||
5106 | fputc ('\n', asm_out_file); | |
5107 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5108 | a->dw_attr_val.v.val_long_long.hi, | |
5109 | a->dw_attr_val.v.val_long_long.low); | |
5110 | ||
c5cec899 | 5111 | if (flag_debug_asm) |
3f76745e JM |
5112 | fprintf (asm_out_file, |
5113 | "\t%s long long constant", ASM_COMMENT_START); | |
5114 | ||
5115 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5116 | break; |
3f76745e JM |
5117 | |
5118 | case dw_val_class_float: | |
c84e2712 KG |
5119 | { |
5120 | register unsigned int i; | |
5121 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5122 | a->dw_attr_val.v.val_float.length * 4); | |
5123 | if (flag_debug_asm) | |
5124 | fprintf (asm_out_file, "\t%s %s", | |
5125 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5126 | ||
5127 | fputc ('\n', asm_out_file); | |
5128 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) | |
5129 | { | |
5130 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5131 | a->dw_attr_val.v.val_float.array[i]); | |
5132 | if (flag_debug_asm) | |
5133 | fprintf (asm_out_file, "\t%s fp constant word %u", | |
5134 | ASM_COMMENT_START, i); | |
5135 | ||
5136 | fputc ('\n', asm_out_file); | |
5137 | } | |
a3f97cbb | 5138 | break; |
c84e2712 | 5139 | } |
3f76745e JM |
5140 | |
5141 | case dw_val_class_flag: | |
a96c67ec | 5142 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a)); |
a3f97cbb | 5143 | break; |
3f76745e JM |
5144 | |
5145 | case dw_val_class_die_ref: | |
a96c67ec | 5146 | ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset); |
a3f97cbb | 5147 | break; |
3f76745e JM |
5148 | |
5149 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
5150 | { |
5151 | char l1[20]; | |
5152 | ASM_GENERATE_INTERNAL_LABEL | |
5153 | (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2); | |
5154 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1); | |
5155 | fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE); | |
5156 | } | |
a3f97cbb | 5157 | break; |
a3f97cbb | 5158 | |
3f76745e | 5159 | case dw_val_class_lbl_id: |
a96c67ec | 5160 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a)); |
3f76745e | 5161 | break; |
71dfc51f | 5162 | |
8b790721 | 5163 | case dw_val_class_lbl_offset: |
a96c67ec | 5164 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a)); |
3f76745e | 5165 | break; |
a3f97cbb | 5166 | |
3f76745e | 5167 | case dw_val_class_str: |
8d4e65a6 | 5168 | if (flag_debug_asm) |
a96c67ec | 5169 | ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a)); |
8d4e65a6 | 5170 | else |
a96c67ec JM |
5171 | ASM_OUTPUT_ASCII (asm_out_file, AT_string (a), |
5172 | (int) strlen (AT_string (a)) + 1); | |
3f76745e | 5173 | break; |
b2932ae5 | 5174 | |
3f76745e JM |
5175 | default: |
5176 | abort (); | |
5177 | } | |
a94dbf2c | 5178 | |
a96c67ec JM |
5179 | if (AT_class (a) != dw_val_class_loc |
5180 | && AT_class (a) != dw_val_class_long_long | |
5181 | && AT_class (a) != dw_val_class_float) | |
3f76745e | 5182 | { |
c5cec899 | 5183 | if (flag_debug_asm) |
3f76745e JM |
5184 | fprintf (asm_out_file, "\t%s %s", |
5185 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
b2932ae5 | 5186 | |
3f76745e JM |
5187 | fputc ('\n', asm_out_file); |
5188 | } | |
5189 | } | |
71dfc51f | 5190 | |
3f76745e JM |
5191 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5192 | output_die (c); | |
71dfc51f | 5193 | |
3f76745e | 5194 | if (die->die_child != NULL) |
7e23cb16 | 5195 | { |
3f76745e JM |
5196 | /* Add null byte to terminate sibling list. */ |
5197 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5198 | if (flag_debug_asm) |
2d8b0f3a | 5199 | fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx", |
3f76745e JM |
5200 | ASM_COMMENT_START, die->die_offset); |
5201 | ||
7e23cb16 JM |
5202 | fputc ('\n', asm_out_file); |
5203 | } | |
3f76745e | 5204 | } |
71dfc51f | 5205 | |
3f76745e JM |
5206 | /* Output the compilation unit that appears at the beginning of the |
5207 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 5208 | |
3f76745e JM |
5209 | static void |
5210 | output_compilation_unit_header () | |
5211 | { | |
5212 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE); | |
c5cec899 | 5213 | if (flag_debug_asm) |
3f76745e JM |
5214 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", |
5215 | ASM_COMMENT_START); | |
71dfc51f | 5216 | |
a3f97cbb | 5217 | fputc ('\n', asm_out_file); |
3f76745e | 5218 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
c5cec899 | 5219 | if (flag_debug_asm) |
3f76745e | 5220 | fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START); |
71dfc51f | 5221 | |
a3f97cbb | 5222 | fputc ('\n', asm_out_file); |
8b790721 | 5223 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label); |
c5cec899 | 5224 | if (flag_debug_asm) |
3f76745e JM |
5225 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", |
5226 | ASM_COMMENT_START); | |
71dfc51f | 5227 | |
a3f97cbb | 5228 | fputc ('\n', asm_out_file); |
a1a4189d | 5229 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE); |
c5cec899 | 5230 | if (flag_debug_asm) |
3f76745e | 5231 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START); |
71dfc51f | 5232 | |
a3f97cbb | 5233 | fputc ('\n', asm_out_file); |
a3f97cbb JW |
5234 | } |
5235 | ||
a1d7ffe3 JM |
5236 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
5237 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
5238 | argument list, and maybe the scope. */ | |
5239 | ||
d560ee52 | 5240 | static const char * |
a1d7ffe3 JM |
5241 | dwarf2_name (decl, scope) |
5242 | tree decl; | |
5243 | int scope; | |
5244 | { | |
5245 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
5246 | } | |
5247 | ||
d291dd49 | 5248 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 5249 | |
d291dd49 JM |
5250 | static void |
5251 | add_pubname (decl, die) | |
5252 | tree decl; | |
5253 | dw_die_ref die; | |
5254 | { | |
5255 | pubname_ref p; | |
5256 | ||
5257 | if (! TREE_PUBLIC (decl)) | |
5258 | return; | |
5259 | ||
5260 | if (pubname_table_in_use == pubname_table_allocated) | |
5261 | { | |
5262 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
5263 | pubname_table = (pubname_ref) xrealloc | |
5264 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
5265 | } | |
71dfc51f | 5266 | |
d291dd49 JM |
5267 | p = &pubname_table[pubname_table_in_use++]; |
5268 | p->die = die; | |
a1d7ffe3 JM |
5269 | |
5270 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
5271 | } |
5272 | ||
a3f97cbb JW |
5273 | /* Output the public names table used to speed up access to externally |
5274 | visible names. For now, only generate entries for externally | |
5275 | visible procedures. */ | |
71dfc51f | 5276 | |
a3f97cbb JW |
5277 | static void |
5278 | output_pubnames () | |
5279 | { | |
d291dd49 | 5280 | register unsigned i; |
71dfc51f RK |
5281 | register unsigned long pubnames_length = size_of_pubnames (); |
5282 | ||
5283 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length); | |
5284 | ||
c5cec899 | 5285 | if (flag_debug_asm) |
71dfc51f RK |
5286 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", |
5287 | ASM_COMMENT_START); | |
5288 | ||
a3f97cbb JW |
5289 | fputc ('\n', asm_out_file); |
5290 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
71dfc51f | 5291 | |
c5cec899 | 5292 | if (flag_debug_asm) |
71dfc51f RK |
5293 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5294 | ||
a3f97cbb | 5295 | fputc ('\n', asm_out_file); |
8b790721 | 5296 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label); |
c5cec899 | 5297 | if (flag_debug_asm) |
71dfc51f RK |
5298 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5299 | ASM_COMMENT_START); | |
5300 | ||
a3f97cbb | 5301 | fputc ('\n', asm_out_file); |
7e23cb16 | 5302 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset); |
c5cec899 | 5303 | if (flag_debug_asm) |
71dfc51f RK |
5304 | fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START); |
5305 | ||
a3f97cbb | 5306 | fputc ('\n', asm_out_file); |
d291dd49 | 5307 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 5308 | { |
d291dd49 | 5309 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 5310 | |
7e23cb16 | 5311 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset); |
c5cec899 | 5312 | if (flag_debug_asm) |
71dfc51f RK |
5313 | fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START); |
5314 | ||
d291dd49 JM |
5315 | fputc ('\n', asm_out_file); |
5316 | ||
c5cec899 | 5317 | if (flag_debug_asm) |
8d4e65a6 JL |
5318 | { |
5319 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
5320 | fprintf (asm_out_file, "%s external name", ASM_COMMENT_START); | |
5321 | } | |
5322 | else | |
5323 | { | |
c84e2712 KG |
5324 | ASM_OUTPUT_ASCII (asm_out_file, pub->name, |
5325 | (int) strlen (pub->name) + 1); | |
8d4e65a6 | 5326 | } |
71dfc51f | 5327 | |
d291dd49 | 5328 | fputc ('\n', asm_out_file); |
a3f97cbb | 5329 | } |
71dfc51f | 5330 | |
7e23cb16 | 5331 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); |
a3f97cbb JW |
5332 | fputc ('\n', asm_out_file); |
5333 | } | |
5334 | ||
d291dd49 | 5335 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 5336 | |
d291dd49 JM |
5337 | static void |
5338 | add_arange (decl, die) | |
5339 | tree decl; | |
5340 | dw_die_ref die; | |
5341 | { | |
5342 | if (! DECL_SECTION_NAME (decl)) | |
5343 | return; | |
5344 | ||
5345 | if (arange_table_in_use == arange_table_allocated) | |
5346 | { | |
5347 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
5348 | arange_table |
5349 | = (arange_ref) xrealloc (arange_table, | |
5350 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 5351 | } |
71dfc51f | 5352 | |
d291dd49 JM |
5353 | arange_table[arange_table_in_use++] = die; |
5354 | } | |
5355 | ||
a3f97cbb JW |
5356 | /* Output the information that goes into the .debug_aranges table. |
5357 | Namely, define the beginning and ending address range of the | |
5358 | text section generated for this compilation unit. */ | |
71dfc51f | 5359 | |
a3f97cbb JW |
5360 | static void |
5361 | output_aranges () | |
5362 | { | |
d291dd49 | 5363 | register unsigned i; |
71dfc51f RK |
5364 | register unsigned long aranges_length = size_of_aranges (); |
5365 | ||
5366 | ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length); | |
c5cec899 | 5367 | if (flag_debug_asm) |
71dfc51f RK |
5368 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", |
5369 | ASM_COMMENT_START); | |
5370 | ||
a3f97cbb JW |
5371 | fputc ('\n', asm_out_file); |
5372 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 5373 | if (flag_debug_asm) |
71dfc51f RK |
5374 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5375 | ||
a3f97cbb | 5376 | fputc ('\n', asm_out_file); |
8b790721 | 5377 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label); |
c5cec899 | 5378 | if (flag_debug_asm) |
71dfc51f RK |
5379 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5380 | ASM_COMMENT_START); | |
5381 | ||
a3f97cbb | 5382 | fputc ('\n', asm_out_file); |
a1a4189d | 5383 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE); |
c5cec899 | 5384 | if (flag_debug_asm) |
71dfc51f RK |
5385 | fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START); |
5386 | ||
a3f97cbb JW |
5387 | fputc ('\n', asm_out_file); |
5388 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5389 | if (flag_debug_asm) |
71dfc51f RK |
5390 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", |
5391 | ASM_COMMENT_START); | |
5392 | ||
a3f97cbb | 5393 | fputc ('\n', asm_out_file); |
71dfc51f | 5394 | |
262b6384 SC |
5395 | /* We need to align to twice the pointer size here. */ |
5396 | if (DWARF_ARANGES_PAD_SIZE) | |
5397 | { | |
5398 | /* Pad using a 2 bytes word so that padding is correct | |
5399 | for any pointer size. */ | |
5400 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); | |
5401 | for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2) | |
5402 | fprintf (asm_out_file, ",0"); | |
5403 | if (flag_debug_asm) | |
5404 | fprintf (asm_out_file, "\t%s Pad to %d byte boundary", | |
a1a4189d | 5405 | ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE); |
262b6384 | 5406 | } |
71dfc51f | 5407 | |
a3f97cbb | 5408 | fputc ('\n', asm_out_file); |
8b790721 | 5409 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label); |
c5cec899 | 5410 | if (flag_debug_asm) |
71dfc51f RK |
5411 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5412 | ||
a3f97cbb | 5413 | fputc ('\n', asm_out_file); |
71208e03 | 5414 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, |
8b790721 | 5415 | text_section_label); |
c5cec899 | 5416 | if (flag_debug_asm) |
71dfc51f RK |
5417 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5418 | ||
a3f97cbb | 5419 | fputc ('\n', asm_out_file); |
d291dd49 JM |
5420 | for (i = 0; i < arange_table_in_use; ++i) |
5421 | { | |
e689ae67 | 5422 | dw_die_ref die = arange_table[i]; |
71dfc51f | 5423 | |
e689ae67 JM |
5424 | if (die->die_tag == DW_TAG_subprogram) |
5425 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die)); | |
d291dd49 | 5426 | else |
a1d7ffe3 | 5427 | { |
e689ae67 JM |
5428 | /* A static variable; extract the symbol from DW_AT_location. |
5429 | Note that this code isn't currently hit, as we only emit | |
5430 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 5431 | |
e689ae67 JM |
5432 | dw_attr_ref a = get_AT (die, DW_AT_location); |
5433 | dw_loc_descr_ref loc; | |
a96c67ec | 5434 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
5435 | abort (); |
5436 | ||
a96c67ec | 5437 | loc = AT_loc (a); |
e689ae67 JM |
5438 | if (loc->dw_loc_opc != DW_OP_addr) |
5439 | abort (); | |
5440 | ||
1865dbb5 JM |
5441 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, |
5442 | loc->dw_loc_oprnd1.v.val_addr); | |
a1d7ffe3 | 5443 | } |
71dfc51f | 5444 | |
c5cec899 | 5445 | if (flag_debug_asm) |
71dfc51f RK |
5446 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5447 | ||
d291dd49 | 5448 | fputc ('\n', asm_out_file); |
e689ae67 JM |
5449 | if (die->die_tag == DW_TAG_subprogram) |
5450 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die), | |
5451 | get_AT_low_pc (die)); | |
d291dd49 | 5452 | else |
7e23cb16 | 5453 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, |
e689ae67 | 5454 | get_AT_unsigned (die, DW_AT_byte_size)); |
71dfc51f | 5455 | |
c5cec899 | 5456 | if (flag_debug_asm) |
71dfc51f RK |
5457 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5458 | ||
d291dd49 JM |
5459 | fputc ('\n', asm_out_file); |
5460 | } | |
71dfc51f | 5461 | |
a3f97cbb | 5462 | /* Output the terminator words. */ |
7e23cb16 | 5463 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb | 5464 | fputc ('\n', asm_out_file); |
7e23cb16 | 5465 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb JW |
5466 | fputc ('\n', asm_out_file); |
5467 | } | |
5468 | ||
5469 | /* Output the source line number correspondence information. This | |
14a774a9 | 5470 | information goes into the .debug_line section. */ |
71dfc51f | 5471 | |
a3f97cbb JW |
5472 | static void |
5473 | output_line_info () | |
5474 | { | |
a3f97cbb JW |
5475 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
5476 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5477 | register unsigned opc; | |
5478 | register unsigned n_op_args; | |
a3f97cbb JW |
5479 | register unsigned long ft_index; |
5480 | register unsigned long lt_index; | |
5481 | register unsigned long current_line; | |
5482 | register long line_offset; | |
5483 | register long line_delta; | |
5484 | register unsigned long current_file; | |
e90b62db | 5485 | register unsigned long function; |
71dfc51f | 5486 | |
14a774a9 | 5487 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART"); |
c5cec899 | 5488 | if (flag_debug_asm) |
71dfc51f RK |
5489 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", |
5490 | ASM_COMMENT_START); | |
5491 | ||
a3f97cbb | 5492 | fputc ('\n', asm_out_file); |
14a774a9 | 5493 | ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART"); |
a3f97cbb | 5494 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
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); |
7e23cb16 | 5499 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); |
c5cec899 | 5500 | if (flag_debug_asm) |
71dfc51f RK |
5501 | fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); |
5502 | ||
a3f97cbb JW |
5503 | fputc ('\n', asm_out_file); |
5504 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
c5cec899 | 5505 | if (flag_debug_asm) |
71dfc51f RK |
5506 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", |
5507 | ASM_COMMENT_START); | |
5508 | ||
a3f97cbb JW |
5509 | fputc ('\n', asm_out_file); |
5510 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
c5cec899 | 5511 | if (flag_debug_asm) |
71dfc51f RK |
5512 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", |
5513 | ASM_COMMENT_START); | |
5514 | ||
a3f97cbb JW |
5515 | fputc ('\n', asm_out_file); |
5516 | fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE); | |
c5cec899 | 5517 | if (flag_debug_asm) |
71dfc51f RK |
5518 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", |
5519 | ASM_COMMENT_START); | |
5520 | ||
a3f97cbb JW |
5521 | fputc ('\n', asm_out_file); |
5522 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE); | |
c5cec899 | 5523 | if (flag_debug_asm) |
71dfc51f RK |
5524 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", |
5525 | ASM_COMMENT_START); | |
5526 | ||
a3f97cbb JW |
5527 | fputc ('\n', asm_out_file); |
5528 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); | |
c5cec899 | 5529 | if (flag_debug_asm) |
71dfc51f RK |
5530 | fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START); |
5531 | ||
a3f97cbb JW |
5532 | fputc ('\n', asm_out_file); |
5533 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
5534 | { | |
5535 | switch (opc) | |
5536 | { | |
5537 | case DW_LNS_advance_pc: | |
5538 | case DW_LNS_advance_line: | |
5539 | case DW_LNS_set_file: | |
5540 | case DW_LNS_set_column: | |
5541 | case DW_LNS_fixed_advance_pc: | |
5542 | n_op_args = 1; | |
5543 | break; | |
5544 | default: | |
5545 | n_op_args = 0; | |
5546 | break; | |
5547 | } | |
5548 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
c5cec899 | 5549 | if (flag_debug_asm) |
71dfc51f RK |
5550 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", |
5551 | ASM_COMMENT_START, opc, n_op_args); | |
a3f97cbb JW |
5552 | fputc ('\n', asm_out_file); |
5553 | } | |
71dfc51f | 5554 | |
c5cec899 | 5555 | if (flag_debug_asm) |
71dfc51f RK |
5556 | fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START); |
5557 | ||
a3f97cbb JW |
5558 | /* Include directory table is empty, at present */ |
5559 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5560 | fputc ('\n', asm_out_file); | |
c5cec899 | 5561 | if (flag_debug_asm) |
71dfc51f RK |
5562 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); |
5563 | ||
a3f97cbb JW |
5564 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
5565 | { | |
c5cec899 | 5566 | if (flag_debug_asm) |
8d4e65a6 JL |
5567 | { |
5568 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
2d8b0f3a | 5569 | fprintf (asm_out_file, "%s File Entry: 0x%lx", |
8d4e65a6 JL |
5570 | ASM_COMMENT_START, ft_index); |
5571 | } | |
5572 | else | |
5573 | { | |
5574 | ASM_OUTPUT_ASCII (asm_out_file, | |
5575 | file_table[ft_index], | |
c84e2712 | 5576 | (int) strlen (file_table[ft_index]) + 1); |
8d4e65a6 | 5577 | } |
71dfc51f | 5578 | |
a3f97cbb | 5579 | fputc ('\n', asm_out_file); |
71dfc51f | 5580 | |
a3f97cbb JW |
5581 | /* Include directory index */ |
5582 | output_uleb128 (0); | |
5583 | fputc ('\n', asm_out_file); | |
71dfc51f | 5584 | |
a3f97cbb JW |
5585 | /* Modification time */ |
5586 | output_uleb128 (0); | |
5587 | fputc ('\n', asm_out_file); | |
71dfc51f | 5588 | |
a3f97cbb JW |
5589 | /* File length in bytes */ |
5590 | output_uleb128 (0); | |
5591 | fputc ('\n', asm_out_file); | |
5592 | } | |
71dfc51f | 5593 | |
a3f97cbb JW |
5594 | /* Terminate the file name table */ |
5595 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5596 | fputc ('\n', asm_out_file); | |
5597 | ||
2f22d404 JM |
5598 | /* We used to set the address register to the first location in the text |
5599 | section here, but that didn't accomplish anything since we already | |
5600 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
5601 | |
5602 | /* Generate the line number to PC correspondence table, encoded as | |
5603 | a series of state machine operations. */ | |
5604 | current_file = 1; | |
5605 | current_line = 1; | |
8b790721 | 5606 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
5607 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
5608 | { | |
2f22d404 JM |
5609 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
5610 | ||
10a11b75 JM |
5611 | #if 0 |
5612 | /* Disable this optimization for now; GDB wants to see two line notes | |
5613 | at the beginning of a function so it can find the end of the | |
5614 | prologue. */ | |
5615 | ||
2f22d404 JM |
5616 | /* Don't emit anything for redundant notes. Just updating the |
5617 | address doesn't accomplish anything, because we already assume | |
5618 | that anything after the last address is this line. */ | |
5619 | if (line_info->dw_line_num == current_line | |
5620 | && line_info->dw_file_num == current_file) | |
5621 | continue; | |
10a11b75 | 5622 | #endif |
71dfc51f | 5623 | |
f19a6894 JW |
5624 | /* Emit debug info for the address of the current line, choosing |
5625 | the encoding that uses the least amount of space. */ | |
5626 | /* ??? Unfortunately, we have little choice here currently, and must | |
5627 | always use the most general form. Gcc does not know the address | |
5628 | delta itself, so we can't use DW_LNS_advance_pc. There are no known | |
5629 | dwarf2 aware assemblers at this time, so we can't use any special | |
5630 | pseudo ops that would allow the assembler to optimally encode this for | |
5631 | us. Many ports do have length attributes which will give an upper | |
5632 | bound on the address range. We could perhaps use length attributes | |
5633 | to determine when it is safe to use DW_LNS_fixed_advance_pc. */ | |
5c90448c | 5634 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
5635 | if (0) |
5636 | { | |
5637 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
5638 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5639 | if (flag_debug_asm) |
f19a6894 JW |
5640 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5641 | ASM_COMMENT_START); | |
5642 | ||
5643 | fputc ('\n', asm_out_file); | |
5644 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
5645 | fputc ('\n', asm_out_file); | |
5646 | } | |
5647 | else | |
5648 | { | |
a1a4189d JB |
5649 | /* This can handle any delta. This takes |
5650 | 4+DWARF2_ADDR_SIZE bytes. */ | |
f19a6894 | 5651 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); |
c5cec899 | 5652 | if (flag_debug_asm) |
f19a6894 JW |
5653 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5654 | ASM_COMMENT_START); | |
5655 | fputc ('\n', asm_out_file); | |
a1a4189d | 5656 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
5657 | fputc ('\n', asm_out_file); |
5658 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5659 | fputc ('\n', asm_out_file); | |
5660 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5661 | fputc ('\n', asm_out_file); | |
5662 | } | |
5663 | strcpy (prev_line_label, line_label); | |
5664 | ||
5665 | /* Emit debug info for the source file of the current line, if | |
5666 | different from the previous line. */ | |
a3f97cbb JW |
5667 | if (line_info->dw_file_num != current_file) |
5668 | { | |
5669 | current_file = line_info->dw_file_num; | |
5670 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 5671 | if (flag_debug_asm) |
71dfc51f RK |
5672 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5673 | ||
a3f97cbb JW |
5674 | fputc ('\n', asm_out_file); |
5675 | output_uleb128 (current_file); | |
c5cec899 | 5676 | if (flag_debug_asm) |
b2932ae5 | 5677 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5678 | |
a3f97cbb JW |
5679 | fputc ('\n', asm_out_file); |
5680 | } | |
71dfc51f | 5681 | |
f19a6894 JW |
5682 | /* Emit debug info for the current line number, choosing the encoding |
5683 | that uses the least amount of space. */ | |
2f22d404 | 5684 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 5685 | { |
2f22d404 JM |
5686 | line_offset = line_info->dw_line_num - current_line; |
5687 | line_delta = line_offset - DWARF_LINE_BASE; | |
5688 | current_line = line_info->dw_line_num; | |
5689 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
5690 | { | |
5691 | /* This can handle deltas from -10 to 234, using the current | |
5692 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
5693 | takes 1 byte. */ | |
5694 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5695 | DWARF_LINE_OPCODE_BASE + line_delta); | |
5696 | if (flag_debug_asm) | |
5697 | fprintf (asm_out_file, | |
5698 | "\t%s line %ld", ASM_COMMENT_START, current_line); | |
71dfc51f | 5699 | |
2f22d404 JM |
5700 | fputc ('\n', asm_out_file); |
5701 | } | |
5702 | else | |
5703 | { | |
5704 | /* This can handle any delta. This takes at least 4 bytes, | |
5705 | depending on the value being encoded. */ | |
5706 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
5707 | if (flag_debug_asm) | |
5708 | fprintf (asm_out_file, "\t%s advance to line %ld", | |
5709 | ASM_COMMENT_START, current_line); | |
5710 | ||
5711 | fputc ('\n', asm_out_file); | |
5712 | output_sleb128 (line_offset); | |
5713 | fputc ('\n', asm_out_file); | |
5714 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5715 | if (flag_debug_asm) | |
5716 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
5717 | fputc ('\n', asm_out_file); | |
5718 | } | |
a94dbf2c JM |
5719 | } |
5720 | else | |
5721 | { | |
2f22d404 | 5722 | /* We still need to start a new row, so output a copy insn. */ |
a94dbf2c | 5723 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); |
2f22d404 JM |
5724 | if (flag_debug_asm) |
5725 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
a94dbf2c | 5726 | fputc ('\n', asm_out_file); |
a3f97cbb | 5727 | } |
a3f97cbb JW |
5728 | } |
5729 | ||
f19a6894 JW |
5730 | /* Emit debug info for the address of the end of the function. */ |
5731 | if (0) | |
5732 | { | |
5733 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5734 | if (flag_debug_asm) |
f19a6894 JW |
5735 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5736 | ASM_COMMENT_START); | |
71dfc51f | 5737 | |
f19a6894 JW |
5738 | fputc ('\n', asm_out_file); |
5739 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label); | |
5740 | fputc ('\n', asm_out_file); | |
5741 | } | |
5742 | else | |
5743 | { | |
5744 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5745 | if (flag_debug_asm) |
f19a6894 JW |
5746 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5747 | fputc ('\n', asm_out_file); | |
a1a4189d | 5748 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
5749 | fputc ('\n', asm_out_file); |
5750 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5751 | fputc ('\n', asm_out_file); | |
5752 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label); | |
5753 | fputc ('\n', asm_out_file); | |
5754 | } | |
bdb669cb | 5755 | |
a3f97cbb | 5756 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); |
c5cec899 | 5757 | if (flag_debug_asm) |
71dfc51f RK |
5758 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); |
5759 | ||
a3f97cbb JW |
5760 | fputc ('\n', asm_out_file); |
5761 | output_uleb128 (1); | |
5762 | fputc ('\n', asm_out_file); | |
5763 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5764 | fputc ('\n', asm_out_file); | |
e90b62db JM |
5765 | |
5766 | function = 0; | |
5767 | current_file = 1; | |
5768 | current_line = 1; | |
5769 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
5770 | { | |
5771 | register dw_separate_line_info_ref line_info | |
5772 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 5773 | |
10a11b75 | 5774 | #if 0 |
2f22d404 JM |
5775 | /* Don't emit anything for redundant notes. */ |
5776 | if (line_info->dw_line_num == current_line | |
5777 | && line_info->dw_file_num == current_file | |
5778 | && line_info->function == function) | |
5779 | goto cont; | |
10a11b75 | 5780 | #endif |
2f22d404 | 5781 | |
f19a6894 JW |
5782 | /* Emit debug info for the address of the current line. If this is |
5783 | a new function, or the first line of a function, then we need | |
5784 | to handle it differently. */ | |
5c90448c JM |
5785 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
5786 | lt_index); | |
e90b62db JM |
5787 | if (function != line_info->function) |
5788 | { | |
5789 | function = line_info->function; | |
71dfc51f | 5790 | |
e90b62db JM |
5791 | /* Set the address register to the first line in the function */ |
5792 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5793 | if (flag_debug_asm) |
e90b62db JM |
5794 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5795 | ASM_COMMENT_START); | |
71dfc51f | 5796 | |
e90b62db | 5797 | fputc ('\n', asm_out_file); |
a1a4189d | 5798 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
e90b62db JM |
5799 | fputc ('\n', asm_out_file); |
5800 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5801 | fputc ('\n', asm_out_file); | |
5802 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5803 | fputc ('\n', asm_out_file); | |
5804 | } | |
5805 | else | |
5806 | { | |
f19a6894 JW |
5807 | /* ??? See the DW_LNS_advance_pc comment above. */ |
5808 | if (0) | |
5809 | { | |
5810 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5811 | if (flag_debug_asm) |
f19a6894 JW |
5812 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5813 | ASM_COMMENT_START); | |
71dfc51f | 5814 | |
f19a6894 JW |
5815 | fputc ('\n', asm_out_file); |
5816 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5817 | prev_line_label); | |
5818 | fputc ('\n', asm_out_file); | |
5819 | } | |
5820 | else | |
5821 | { | |
5822 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5823 | if (flag_debug_asm) |
f19a6894 JW |
5824 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5825 | ASM_COMMENT_START); | |
5826 | fputc ('\n', asm_out_file); | |
a1a4189d | 5827 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
5828 | fputc ('\n', asm_out_file); |
5829 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5830 | fputc ('\n', asm_out_file); | |
5831 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5832 | fputc ('\n', asm_out_file); | |
5833 | } | |
e90b62db | 5834 | } |
f19a6894 | 5835 | strcpy (prev_line_label, line_label); |
71dfc51f | 5836 | |
f19a6894 JW |
5837 | /* Emit debug info for the source file of the current line, if |
5838 | different from the previous line. */ | |
e90b62db JM |
5839 | if (line_info->dw_file_num != current_file) |
5840 | { | |
5841 | current_file = line_info->dw_file_num; | |
5842 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 5843 | if (flag_debug_asm) |
71dfc51f RK |
5844 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5845 | ||
e90b62db JM |
5846 | fputc ('\n', asm_out_file); |
5847 | output_uleb128 (current_file); | |
c5cec899 | 5848 | if (flag_debug_asm) |
b2932ae5 | 5849 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5850 | |
e90b62db JM |
5851 | fputc ('\n', asm_out_file); |
5852 | } | |
71dfc51f | 5853 | |
f19a6894 JW |
5854 | /* Emit debug info for the current line number, choosing the encoding |
5855 | that uses the least amount of space. */ | |
e90b62db JM |
5856 | if (line_info->dw_line_num != current_line) |
5857 | { | |
5858 | line_offset = line_info->dw_line_num - current_line; | |
5859 | line_delta = line_offset - DWARF_LINE_BASE; | |
5860 | current_line = line_info->dw_line_num; | |
5861 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
5862 | { | |
5863 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5864 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 5865 | if (flag_debug_asm) |
71dfc51f | 5866 | fprintf (asm_out_file, |
2d8b0f3a | 5867 | "\t%s line %ld", ASM_COMMENT_START, current_line); |
71dfc51f | 5868 | |
e90b62db JM |
5869 | fputc ('\n', asm_out_file); |
5870 | } | |
5871 | else | |
5872 | { | |
5873 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
c5cec899 | 5874 | if (flag_debug_asm) |
2d8b0f3a | 5875 | fprintf (asm_out_file, "\t%s advance to line %ld", |
71dfc51f RK |
5876 | ASM_COMMENT_START, current_line); |
5877 | ||
e90b62db JM |
5878 | fputc ('\n', asm_out_file); |
5879 | output_sleb128 (line_offset); | |
5880 | fputc ('\n', asm_out_file); | |
5881 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
2f22d404 JM |
5882 | if (flag_debug_asm) |
5883 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
e90b62db JM |
5884 | fputc ('\n', asm_out_file); |
5885 | } | |
5886 | } | |
2f22d404 JM |
5887 | else |
5888 | { | |
5889 | /* We still need to start a new row, so output a copy insn. */ | |
5890 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5891 | if (flag_debug_asm) | |
5892 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
5893 | fputc ('\n', asm_out_file); | |
5894 | } | |
71dfc51f | 5895 | |
10a11b75 | 5896 | #if 0 |
2f22d404 | 5897 | cont: |
10a11b75 | 5898 | #endif |
e90b62db | 5899 | ++lt_index; |
e90b62db JM |
5900 | |
5901 | /* If we're done with a function, end its sequence. */ | |
5902 | if (lt_index == separate_line_info_table_in_use | |
5903 | || separate_line_info_table[lt_index].function != function) | |
5904 | { | |
5905 | current_file = 1; | |
5906 | current_line = 1; | |
71dfc51f | 5907 | |
f19a6894 | 5908 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 5909 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
5910 | if (0) |
5911 | { | |
5912 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 5913 | if (flag_debug_asm) |
f19a6894 JW |
5914 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
5915 | ASM_COMMENT_START); | |
5916 | ||
5917 | fputc ('\n', asm_out_file); | |
5918 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5919 | prev_line_label); | |
5920 | fputc ('\n', asm_out_file); | |
5921 | } | |
5922 | else | |
5923 | { | |
5924 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5925 | if (flag_debug_asm) |
f19a6894 JW |
5926 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
5927 | ASM_COMMENT_START); | |
5928 | fputc ('\n', asm_out_file); | |
a1a4189d | 5929 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
5930 | fputc ('\n', asm_out_file); |
5931 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5932 | fputc ('\n', asm_out_file); | |
5933 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5934 | fputc ('\n', asm_out_file); | |
5935 | } | |
e90b62db JM |
5936 | |
5937 | /* Output the marker for the end of this sequence. */ | |
5938 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 5939 | if (flag_debug_asm) |
e90b62db JM |
5940 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", |
5941 | ASM_COMMENT_START); | |
71dfc51f | 5942 | |
e90b62db JM |
5943 | fputc ('\n', asm_out_file); |
5944 | output_uleb128 (1); | |
5945 | fputc ('\n', asm_out_file); | |
5946 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5947 | fputc ('\n', asm_out_file); | |
5948 | } | |
5949 | } | |
f19f17e0 JM |
5950 | |
5951 | /* Output the marker for the end of the line number info. */ | |
5952 | ASM_OUTPUT_LABEL (asm_out_file, ".LTEND"); | |
a3f97cbb JW |
5953 | } |
5954 | \f | |
a3f97cbb JW |
5955 | /* Given a pointer to a tree node for some base type, return a pointer to |
5956 | a DIE that describes the given type. | |
5957 | ||
5958 | This routine must only be called for GCC type nodes that correspond to | |
5959 | Dwarf base (fundamental) types. */ | |
71dfc51f | 5960 | |
a3f97cbb JW |
5961 | static dw_die_ref |
5962 | base_type_die (type) | |
5963 | register tree type; | |
5964 | { | |
a9d38797 | 5965 | register dw_die_ref base_type_result; |
ec0ce6e2 | 5966 | register const char *type_name; |
a9d38797 | 5967 | register enum dwarf_type encoding; |
71dfc51f | 5968 | register tree name = TYPE_NAME (type); |
a3f97cbb | 5969 | |
a9d38797 JM |
5970 | if (TREE_CODE (type) == ERROR_MARK |
5971 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
5972 | return 0; |
5973 | ||
405f63da MM |
5974 | if (name) |
5975 | { | |
5976 | if (TREE_CODE (name) == TYPE_DECL) | |
5977 | name = DECL_NAME (name); | |
5978 | ||
5979 | type_name = IDENTIFIER_POINTER (name); | |
5980 | } | |
5981 | else | |
5982 | type_name = "__unknown__"; | |
a9d38797 | 5983 | |
a3f97cbb JW |
5984 | switch (TREE_CODE (type)) |
5985 | { | |
a3f97cbb | 5986 | case INTEGER_TYPE: |
a9d38797 | 5987 | /* Carefully distinguish the C character types, without messing |
a3f97cbb JW |
5988 | up if the language is not C. Note that we check only for the names |
5989 | that contain spaces; other names might occur by coincidence in other | |
5990 | languages. */ | |
a9d38797 JM |
5991 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
5992 | && (type == char_type_node | |
5993 | || ! strcmp (type_name, "signed char") | |
5994 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 5995 | { |
a9d38797 JM |
5996 | if (TREE_UNSIGNED (type)) |
5997 | encoding = DW_ATE_unsigned; | |
5998 | else | |
5999 | encoding = DW_ATE_signed; | |
6000 | break; | |
a3f97cbb | 6001 | } |
a9d38797 | 6002 | /* else fall through */ |
a3f97cbb | 6003 | |
a9d38797 JM |
6004 | case CHAR_TYPE: |
6005 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
6006 | if (TREE_UNSIGNED (type)) | |
6007 | encoding = DW_ATE_unsigned_char; | |
6008 | else | |
6009 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
6010 | break; |
6011 | ||
6012 | case REAL_TYPE: | |
a9d38797 | 6013 | encoding = DW_ATE_float; |
a3f97cbb JW |
6014 | break; |
6015 | ||
405f63da MM |
6016 | /* Dwarf2 doesn't know anything about complex ints, so use |
6017 | a user defined type for it. */ | |
a3f97cbb | 6018 | case COMPLEX_TYPE: |
405f63da MM |
6019 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
6020 | encoding = DW_ATE_complex_float; | |
6021 | else | |
6022 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
6023 | break; |
6024 | ||
6025 | case BOOLEAN_TYPE: | |
a9d38797 JM |
6026 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
6027 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
6028 | break; |
6029 | ||
6030 | default: | |
a9d38797 | 6031 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
6032 | } |
6033 | ||
a9d38797 | 6034 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
6035 | if (demangle_name_func) |
6036 | type_name = (*demangle_name_func) (type_name); | |
6037 | ||
a9d38797 JM |
6038 | add_AT_string (base_type_result, DW_AT_name, type_name); |
6039 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 6040 | int_size_in_bytes (type)); |
a9d38797 | 6041 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
6042 | |
6043 | return base_type_result; | |
6044 | } | |
6045 | ||
6046 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
6047 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
6048 | a given type is generally the same as the given type, except that if the | |
6049 | given type is a pointer or reference type, then the root type of the given | |
6050 | type is the root type of the "basis" type for the pointer or reference | |
6051 | type. (This definition of the "root" type is recursive.) Also, the root | |
6052 | type of a `const' qualified type or a `volatile' qualified type is the | |
6053 | root type of the given type without the qualifiers. */ | |
71dfc51f | 6054 | |
a3f97cbb JW |
6055 | static tree |
6056 | root_type (type) | |
6057 | register tree type; | |
6058 | { | |
6059 | if (TREE_CODE (type) == ERROR_MARK) | |
6060 | return error_mark_node; | |
6061 | ||
6062 | switch (TREE_CODE (type)) | |
6063 | { | |
6064 | case ERROR_MARK: | |
6065 | return error_mark_node; | |
6066 | ||
6067 | case POINTER_TYPE: | |
6068 | case REFERENCE_TYPE: | |
6069 | return type_main_variant (root_type (TREE_TYPE (type))); | |
6070 | ||
6071 | default: | |
6072 | return type_main_variant (type); | |
6073 | } | |
6074 | } | |
6075 | ||
6076 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
6077 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
6078 | |
6079 | static inline int | |
a3f97cbb JW |
6080 | is_base_type (type) |
6081 | register tree type; | |
6082 | { | |
6083 | switch (TREE_CODE (type)) | |
6084 | { | |
6085 | case ERROR_MARK: | |
6086 | case VOID_TYPE: | |
6087 | case INTEGER_TYPE: | |
6088 | case REAL_TYPE: | |
6089 | case COMPLEX_TYPE: | |
6090 | case BOOLEAN_TYPE: | |
6091 | case CHAR_TYPE: | |
6092 | return 1; | |
6093 | ||
6094 | case SET_TYPE: | |
6095 | case ARRAY_TYPE: | |
6096 | case RECORD_TYPE: | |
6097 | case UNION_TYPE: | |
6098 | case QUAL_UNION_TYPE: | |
6099 | case ENUMERAL_TYPE: | |
6100 | case FUNCTION_TYPE: | |
6101 | case METHOD_TYPE: | |
6102 | case POINTER_TYPE: | |
6103 | case REFERENCE_TYPE: | |
6104 | case FILE_TYPE: | |
6105 | case OFFSET_TYPE: | |
6106 | case LANG_TYPE: | |
6107 | return 0; | |
6108 | ||
6109 | default: | |
6110 | abort (); | |
6111 | } | |
71dfc51f | 6112 | |
a3f97cbb JW |
6113 | return 0; |
6114 | } | |
6115 | ||
6116 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
6117 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 6118 | |
a3f97cbb JW |
6119 | static dw_die_ref |
6120 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
6121 | register tree type; | |
6122 | register int is_const_type; | |
6123 | register int is_volatile_type; | |
6124 | register dw_die_ref context_die; | |
6125 | { | |
6126 | register enum tree_code code = TREE_CODE (type); | |
6127 | register dw_die_ref mod_type_die = NULL; | |
6128 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 6129 | register tree item_type = NULL; |
a3f97cbb JW |
6130 | |
6131 | if (code != ERROR_MARK) | |
6132 | { | |
a94dbf2c | 6133 | type = build_type_variant (type, is_const_type, is_volatile_type); |
bdb669cb JM |
6134 | |
6135 | mod_type_die = lookup_type_die (type); | |
6136 | if (mod_type_die) | |
6137 | return mod_type_die; | |
6138 | ||
a94dbf2c JM |
6139 | /* Handle C typedef types. */ |
6140 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
6141 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
6142 | { | |
6143 | tree dtype = TREE_TYPE (TYPE_NAME (type)); | |
6144 | if (type == dtype) | |
6145 | { | |
6146 | /* For a named type, use the typedef. */ | |
6147 | gen_type_die (type, context_die); | |
6148 | mod_type_die = lookup_type_die (type); | |
6149 | } | |
71dfc51f | 6150 | |
a94dbf2c JM |
6151 | else if (is_const_type < TYPE_READONLY (dtype) |
6152 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
6153 | /* cv-unqualified version of named type. Just use the unnamed | |
6154 | type to which it refers. */ | |
71dfc51f RK |
6155 | mod_type_die |
6156 | = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), | |
6157 | is_const_type, is_volatile_type, | |
6158 | context_die); | |
6159 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
6160 | } |
6161 | ||
6162 | if (mod_type_die) | |
6163 | /* OK */; | |
6164 | else if (is_const_type) | |
a3f97cbb | 6165 | { |
ab72d377 | 6166 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 6167 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
6168 | } |
6169 | else if (is_volatile_type) | |
6170 | { | |
ab72d377 | 6171 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 6172 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
6173 | } |
6174 | else if (code == POINTER_TYPE) | |
6175 | { | |
ab72d377 | 6176 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 6177 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6178 | #if 0 |
a3f97cbb | 6179 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6180 | #endif |
a3f97cbb | 6181 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6182 | } |
6183 | else if (code == REFERENCE_TYPE) | |
6184 | { | |
ab72d377 | 6185 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 6186 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 6187 | #if 0 |
a3f97cbb | 6188 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 6189 | #endif |
a3f97cbb | 6190 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
6191 | } |
6192 | else if (is_base_type (type)) | |
71dfc51f | 6193 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
6194 | else |
6195 | { | |
4b674448 JM |
6196 | gen_type_die (type, context_die); |
6197 | ||
a3f97cbb JW |
6198 | /* We have to get the type_main_variant here (and pass that to the |
6199 | `lookup_type_die' routine) because the ..._TYPE node we have | |
6200 | might simply be a *copy* of some original type node (where the | |
6201 | copy was created to help us keep track of typedef names) and | |
6202 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 6203 | ..._TYPE node. */ |
a3f97cbb | 6204 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
6205 | if (mod_type_die == NULL) |
6206 | abort (); | |
a3f97cbb JW |
6207 | } |
6208 | } | |
71dfc51f | 6209 | |
dfcf9891 JW |
6210 | equate_type_number_to_die (type, mod_type_die); |
6211 | if (item_type) | |
71dfc51f RK |
6212 | /* We must do this after the equate_type_number_to_die call, in case |
6213 | this is a recursive type. This ensures that the modified_type_die | |
6214 | recursion will terminate even if the type is recursive. Recursive | |
6215 | types are possible in Ada. */ | |
6216 | sub_die = modified_type_die (item_type, | |
6217 | TYPE_READONLY (item_type), | |
6218 | TYPE_VOLATILE (item_type), | |
6219 | context_die); | |
6220 | ||
a3f97cbb | 6221 | if (sub_die != NULL) |
71dfc51f RK |
6222 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
6223 | ||
a3f97cbb JW |
6224 | return mod_type_die; |
6225 | } | |
6226 | ||
a3f97cbb JW |
6227 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6228 | an enumerated type. */ | |
71dfc51f RK |
6229 | |
6230 | static inline int | |
a3f97cbb JW |
6231 | type_is_enum (type) |
6232 | register tree type; | |
6233 | { | |
6234 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
6235 | } | |
6236 | ||
a3f97cbb | 6237 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 6238 | |
a3f97cbb JW |
6239 | static dw_loc_descr_ref |
6240 | reg_loc_descriptor (rtl) | |
6241 | register rtx rtl; | |
6242 | { | |
6243 | register dw_loc_descr_ref loc_result = NULL; | |
6244 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 6245 | |
85066503 | 6246 | if (reg <= 31) |
71dfc51f | 6247 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 6248 | else |
71dfc51f RK |
6249 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
6250 | ||
a3f97cbb JW |
6251 | return loc_result; |
6252 | } | |
6253 | ||
6254 | /* Return a location descriptor that designates a base+offset location. */ | |
71dfc51f | 6255 | |
a3f97cbb JW |
6256 | static dw_loc_descr_ref |
6257 | based_loc_descr (reg, offset) | |
6258 | unsigned reg; | |
6259 | long int offset; | |
6260 | { | |
6261 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
6262 | /* For the "frame base", we use the frame pointer or stack pointer |
6263 | registers, since the RTL for local variables is relative to one of | |
6264 | them. */ | |
6265 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 6266 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 6267 | : STACK_POINTER_REGNUM); |
71dfc51f | 6268 | |
a3f97cbb | 6269 | if (reg == fp_reg) |
71dfc51f | 6270 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 6271 | else if (reg <= 31) |
71dfc51f | 6272 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 6273 | else |
71dfc51f RK |
6274 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
6275 | ||
a3f97cbb JW |
6276 | return loc_result; |
6277 | } | |
6278 | ||
6279 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
6280 | |
6281 | static inline int | |
a3f97cbb JW |
6282 | is_based_loc (rtl) |
6283 | register rtx rtl; | |
6284 | { | |
71dfc51f RK |
6285 | return (GET_CODE (rtl) == PLUS |
6286 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
6287 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
6288 | } |
6289 | ||
6290 | /* The following routine converts the RTL for a variable or parameter | |
6291 | (resident in memory) into an equivalent Dwarf representation of a | |
6292 | mechanism for getting the address of that same variable onto the top of a | |
6293 | hypothetical "address evaluation" stack. | |
71dfc51f | 6294 | |
a3f97cbb JW |
6295 | When creating memory location descriptors, we are effectively transforming |
6296 | the RTL for a memory-resident object into its Dwarf postfix expression | |
6297 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
6298 | it into Dwarf postfix code as it goes. |
6299 | ||
6300 | MODE is the mode of the memory reference, needed to handle some | |
6301 | autoincrement addressing modes. */ | |
71dfc51f | 6302 | |
a3f97cbb | 6303 | static dw_loc_descr_ref |
e60d4d7b | 6304 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 6305 | register rtx rtl; |
e60d4d7b | 6306 | enum machine_mode mode; |
a3f97cbb JW |
6307 | { |
6308 | dw_loc_descr_ref mem_loc_result = NULL; | |
6309 | /* Note that for a dynamically sized array, the location we will generate a | |
6310 | description of here will be the lowest numbered location which is | |
6311 | actually within the array. That's *not* necessarily the same as the | |
6312 | zeroth element of the array. */ | |
71dfc51f | 6313 | |
1865dbb5 JM |
6314 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
6315 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
6316 | #endif | |
6317 | ||
a3f97cbb JW |
6318 | switch (GET_CODE (rtl)) |
6319 | { | |
e60d4d7b JL |
6320 | case POST_INC: |
6321 | case POST_DEC: | |
6322 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we | |
6323 | just fall into the SUBREG code. */ | |
6324 | ||
6325 | /* ... fall through ... */ | |
6326 | ||
a3f97cbb JW |
6327 | case SUBREG: |
6328 | /* The case of a subreg may arise when we have a local (register) | |
6329 | variable or a formal (register) parameter which doesn't quite fill | |
6330 | up an entire register. For now, just assume that it is | |
6331 | legitimate to make the Dwarf info refer to the whole register which | |
6332 | contains the given subreg. */ | |
6333 | rtl = XEXP (rtl, 0); | |
71dfc51f RK |
6334 | |
6335 | /* ... fall through ... */ | |
a3f97cbb JW |
6336 | |
6337 | case REG: | |
6338 | /* Whenever a register number forms a part of the description of the | |
6339 | method for calculating the (dynamic) address of a memory resident | |
6340 | object, DWARF rules require the register number be referred to as | |
6341 | a "base register". This distinction is not based in any way upon | |
6342 | what category of register the hardware believes the given register | |
6343 | belongs to. This is strictly DWARF terminology we're dealing with | |
6344 | here. Note that in cases where the location of a memory-resident | |
6345 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
6346 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
6347 | may just be OP_BASEREG (basereg). This may look deceptively like | |
6348 | the object in question was allocated to a register (rather than in | |
6349 | memory) so DWARF consumers need to be aware of the subtle | |
6350 | distinction between OP_REG and OP_BASEREG. */ | |
6351 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
6352 | break; | |
6353 | ||
6354 | case MEM: | |
e60d4d7b | 6355 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
a3f97cbb JW |
6356 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); |
6357 | break; | |
6358 | ||
368f4cd6 NC |
6359 | case LABEL_REF: |
6360 | /* Some ports can transform a symbol ref into a label ref, because | |
6361 | the symbol ref is too far away and has to be dumped into a constant | |
6362 | pool. */ | |
a3f97cbb JW |
6363 | case CONST: |
6364 | case SYMBOL_REF: | |
6365 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
6366 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 6367 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
6368 | break; |
6369 | ||
e60d4d7b JL |
6370 | case PRE_INC: |
6371 | case PRE_DEC: | |
6372 | /* Turn these into a PLUS expression and fall into the PLUS code | |
6373 | below. */ | |
6374 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
6375 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
6376 | ? GET_MODE_UNIT_SIZE (mode) | |
6377 | : - GET_MODE_UNIT_SIZE (mode))); | |
6378 | ||
6379 | /* ... fall through ... */ | |
6380 | ||
a3f97cbb JW |
6381 | case PLUS: |
6382 | if (is_based_loc (rtl)) | |
71dfc51f RK |
6383 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
6384 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
6385 | else |
6386 | { | |
e60d4d7b JL |
6387 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), |
6388 | mode)); | |
6389 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), | |
6390 | mode)); | |
a3f97cbb JW |
6391 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0)); |
6392 | } | |
6393 | break; | |
6394 | ||
dd2478ae JW |
6395 | case MULT: |
6396 | /* If a pseudo-reg is optimized away, it is possible for it to | |
6397 | be replaced with a MEM containing a multiply. */ | |
e60d4d7b JL |
6398 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode)); |
6399 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
6400 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
6401 | break; | |
6402 | ||
a3f97cbb JW |
6403 | case CONST_INT: |
6404 | mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0); | |
6405 | break; | |
6406 | ||
6407 | default: | |
6408 | abort (); | |
6409 | } | |
71dfc51f | 6410 | |
a3f97cbb JW |
6411 | return mem_loc_result; |
6412 | } | |
6413 | ||
956d6950 | 6414 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
6415 | This is typically a complex variable. */ |
6416 | ||
6417 | static dw_loc_descr_ref | |
6418 | concat_loc_descriptor (x0, x1) | |
6419 | register rtx x0, x1; | |
6420 | { | |
6421 | dw_loc_descr_ref cc_loc_result = NULL; | |
6422 | ||
6423 | if (!is_pseudo_reg (x0) | |
6424 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
6425 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
6426 | add_loc_descr (&cc_loc_result, | |
6427 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
6428 | ||
6429 | if (!is_pseudo_reg (x1) | |
6430 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
6431 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
6432 | add_loc_descr (&cc_loc_result, | |
6433 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
6434 | ||
6435 | return cc_loc_result; | |
6436 | } | |
6437 | ||
a3f97cbb JW |
6438 | /* Output a proper Dwarf location descriptor for a variable or parameter |
6439 | which is either allocated in a register or in a memory location. For a | |
6440 | register, we just generate an OP_REG and the register number. For a | |
6441 | memory location we provide a Dwarf postfix expression describing how to | |
6442 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 6443 | |
a3f97cbb JW |
6444 | static dw_loc_descr_ref |
6445 | loc_descriptor (rtl) | |
6446 | register rtx rtl; | |
6447 | { | |
6448 | dw_loc_descr_ref loc_result = NULL; | |
6449 | switch (GET_CODE (rtl)) | |
6450 | { | |
6451 | case SUBREG: | |
a3f97cbb JW |
6452 | /* The case of a subreg may arise when we have a local (register) |
6453 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 6454 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
6455 | legitimate to make the Dwarf info refer to the whole register which |
6456 | contains the given subreg. */ | |
a3f97cbb | 6457 | rtl = XEXP (rtl, 0); |
71dfc51f RK |
6458 | |
6459 | /* ... fall through ... */ | |
a3f97cbb JW |
6460 | |
6461 | case REG: | |
5c90448c | 6462 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
6463 | break; |
6464 | ||
6465 | case MEM: | |
e60d4d7b | 6466 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
6467 | break; |
6468 | ||
4401bf24 JL |
6469 | case CONCAT: |
6470 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
6471 | break; | |
6472 | ||
a3f97cbb | 6473 | default: |
71dfc51f | 6474 | abort (); |
a3f97cbb | 6475 | } |
71dfc51f | 6476 | |
a3f97cbb JW |
6477 | return loc_result; |
6478 | } | |
6479 | ||
665f2503 | 6480 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 6481 | which is not less than the value itself. */ |
71dfc51f | 6482 | |
665f2503 | 6483 | static inline HOST_WIDE_INT |
a3f97cbb | 6484 | ceiling (value, boundary) |
665f2503 RK |
6485 | HOST_WIDE_INT value; |
6486 | unsigned int boundary; | |
a3f97cbb JW |
6487 | { |
6488 | return (((value + boundary - 1) / boundary) * boundary); | |
6489 | } | |
6490 | ||
6491 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
6492 | pointer to the declared type for the relevant field variable, or return | |
6493 | `integer_type_node' if the given node turns out to be an | |
6494 | ERROR_MARK node. */ | |
71dfc51f RK |
6495 | |
6496 | static inline tree | |
a3f97cbb JW |
6497 | field_type (decl) |
6498 | register tree decl; | |
6499 | { | |
6500 | register tree type; | |
6501 | ||
6502 | if (TREE_CODE (decl) == ERROR_MARK) | |
6503 | return integer_type_node; | |
6504 | ||
6505 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 6506 | if (type == NULL_TREE) |
a3f97cbb JW |
6507 | type = TREE_TYPE (decl); |
6508 | ||
6509 | return type; | |
6510 | } | |
6511 | ||
6512 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6513 | node, return the alignment in bits for the type, or else return | |
6514 | BITS_PER_WORD if the node actually turns out to be an | |
6515 | ERROR_MARK node. */ | |
71dfc51f RK |
6516 | |
6517 | static inline unsigned | |
a3f97cbb JW |
6518 | simple_type_align_in_bits (type) |
6519 | register tree type; | |
6520 | { | |
6521 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
6522 | } | |
6523 | ||
6524 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6525 | node, return the size in bits for the type if it is a constant, or else | |
6526 | return the alignment for the type if the type's size is not constant, or | |
6527 | else return BITS_PER_WORD if the type actually turns out to be an | |
6528 | ERROR_MARK node. */ | |
71dfc51f | 6529 | |
665f2503 | 6530 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
6531 | simple_type_size_in_bits (type) |
6532 | register tree type; | |
6533 | { | |
6534 | if (TREE_CODE (type) == ERROR_MARK) | |
6535 | return BITS_PER_WORD; | |
6536 | else | |
6537 | { | |
6538 | register tree type_size_tree = TYPE_SIZE (type); | |
6539 | ||
665f2503 | 6540 | if (! host_integerp (type_size_tree, 1)) |
a3f97cbb JW |
6541 | return TYPE_ALIGN (type); |
6542 | ||
665f2503 | 6543 | return tree_low_cst (type_size_tree, 1); |
a3f97cbb JW |
6544 | } |
6545 | } | |
6546 | ||
6547 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
6548 | return the byte offset of the lowest addressed byte of the "containing | |
6549 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
6550 | determine what that offset is, either because the argument turns out to | |
6551 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
6552 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 6553 | |
665f2503 | 6554 | static HOST_WIDE_INT |
a3f97cbb JW |
6555 | field_byte_offset (decl) |
6556 | register tree decl; | |
6557 | { | |
665f2503 RK |
6558 | unsigned int type_align_in_bytes; |
6559 | unsigned int type_align_in_bits; | |
6560 | unsigned HOST_WIDE_INT type_size_in_bits; | |
6561 | HOST_WIDE_INT object_offset_in_align_units; | |
6562 | HOST_WIDE_INT object_offset_in_bits; | |
6563 | HOST_WIDE_INT object_offset_in_bytes; | |
6564 | tree type; | |
6565 | tree field_size_tree; | |
6566 | HOST_WIDE_INT bitpos_int; | |
6567 | HOST_WIDE_INT deepest_bitpos; | |
6568 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
6569 | |
6570 | if (TREE_CODE (decl) == ERROR_MARK) | |
6571 | return 0; | |
6572 | ||
6573 | if (TREE_CODE (decl) != FIELD_DECL) | |
6574 | abort (); | |
6575 | ||
6576 | type = field_type (decl); | |
a3f97cbb JW |
6577 | field_size_tree = DECL_SIZE (decl); |
6578 | ||
50352c9c BK |
6579 | /* If there was an error, the size could be zero. */ |
6580 | if (! field_size_tree) | |
6581 | { | |
6582 | if (errorcount) | |
6583 | return 0; | |
665f2503 | 6584 | |
50352c9c BK |
6585 | abort (); |
6586 | } | |
6587 | ||
14a774a9 | 6588 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
6589 | for now, when we see such things, we simply return 0. Someday, we may |
6590 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 6591 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 6592 | return 0; |
14a774a9 | 6593 | |
665f2503 | 6594 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 6595 | |
14a774a9 | 6596 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
6597 | if (host_integerp (field_size_tree, 1)) |
6598 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
6599 | else |
6600 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
6601 | |
6602 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb JW |
6603 | type_align_in_bits = simple_type_align_in_bits (type); |
6604 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
6605 | ||
6606 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
6607 | the starting bit offset (relative to the start of the containing | |
6608 | structure type) of the hypothetical "containing object" for a bit- | |
6609 | field. Thus, when computing the byte offset value for the start of the | |
6610 | "containing object" of a bit-field, we must deduce this information on | |
6611 | our own. This can be rather tricky to do in some cases. For example, | |
6612 | handling the following structure type definition when compiling for an | |
6613 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
6614 | can be very tricky: | |
6615 | ||
6616 | struct S { int field1; long long field2:31; }; | |
6617 | ||
6618 | Fortunately, there is a simple rule-of-thumb which can be | |
6619 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
6620 | 8 bytes for the structure shown above. It decides to do this based upon | |
6621 | one simple rule for bit-field allocation. Quite simply, GCC allocates | |
6622 | each "containing object" for each bit-field at the first (i.e. lowest | |
6623 | addressed) legitimate alignment boundary (based upon the required | |
6624 | minimum alignment for the declared type of the field) which it can | |
6625 | possibly use, subject to the condition that there is still enough | |
6626 | available space remaining in the containing object (when allocated at | |
6627 | the selected point) to fully accommodate all of the bits of the | |
6628 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
6629 | 8 bytes for each object of the structure type shown above. When looking | |
6630 | for a place to allocate the "containing object" for `field2', the | |
6631 | compiler simply tries to allocate a 64-bit "containing object" at each | |
6632 | successive 32-bit boundary (starting at zero) until it finds a place to | |
6633 | allocate that 64- bit field such that at least 31 contiguous (and | |
6634 | previously unallocated) bits remain within that selected 64 bit field. | |
6635 | (As it turns out, for the example above, the compiler finds that it is | |
6636 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
6637 | within the structure type.) Here we attempt to work backwards from the | |
6638 | limited set of facts we're given, and we try to deduce from those facts, | |
6639 | where GCC must have believed that the containing object started (within | |
6640 | the structure type). The value we deduce is then used (by the callers of | |
6641 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
6642 | for fields (both bit-fields and, in the case of DW_AT_location, regular | |
6643 | fields as well). */ | |
6644 | ||
6645 | /* Figure out the bit-distance from the start of the structure to the | |
6646 | "deepest" bit of the bit-field. */ | |
6647 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
6648 | ||
6649 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
6650 | lowest addressed bit of the containing object must be. */ | |
6651 | object_offset_in_bits | |
6652 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
6653 | ||
6654 | /* Compute the offset of the containing object in "alignment units". */ | |
6655 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
6656 | ||
6657 | /* Compute the offset of the containing object in bytes. */ | |
6658 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
6659 | ||
6660 | return object_offset_in_bytes; | |
6661 | } | |
a3f97cbb | 6662 | \f |
71dfc51f RK |
6663 | /* The following routines define various Dwarf attributes and any data |
6664 | associated with them. */ | |
a3f97cbb | 6665 | |
ef76d03b | 6666 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 6667 | |
ef76d03b | 6668 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
6669 | whole parameters. Note that the location attributes for struct fields are |
6670 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 6671 | |
a3f97cbb | 6672 | static void |
ef76d03b | 6673 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 6674 | dw_die_ref die; |
ef76d03b | 6675 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
6676 | register rtx rtl; |
6677 | { | |
a3f97cbb JW |
6678 | /* Handle a special case. If we are about to output a location descriptor |
6679 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 6680 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
6681 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
6682 | Currently, in some rare cases, variables can have DECL_RTL values which | |
6683 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
6684 | elsewhere in the compiler. We treat such cases as if the variable(s) in | |
6a7a9f01 | 6685 | question had been optimized out of existence. */ |
a3f97cbb | 6686 | |
6a7a9f01 JM |
6687 | if (is_pseudo_reg (rtl) |
6688 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 6689 | && is_pseudo_reg (XEXP (rtl, 0))) |
bce8fed7 JL |
6690 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
6691 | references the internal argument pointer (a pseudo) in a function | |
6692 | where all references to the internal argument pointer were | |
6693 | eliminated via the optimizers. */ | |
6694 | || (GET_CODE (rtl) == MEM | |
6695 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
6696 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
6697 | || (GET_CODE (rtl) == CONCAT |
6698 | && is_pseudo_reg (XEXP (rtl, 0)) | |
6699 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 6700 | return; |
a3f97cbb | 6701 | |
6a7a9f01 | 6702 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
6703 | } |
6704 | ||
6705 | /* Attach the specialized form of location attribute used for data | |
6706 | members of struct and union types. In the special case of a | |
6707 | FIELD_DECL node which represents a bit-field, the "offset" part | |
6708 | of this special location descriptor must indicate the distance | |
6709 | in bytes from the lowest-addressed byte of the containing struct | |
6710 | or union type to the lowest-addressed byte of the "containing | |
6711 | object" for the bit-field. (See the `field_byte_offset' function | |
6712 | above).. For any given bit-field, the "containing object" is a | |
6713 | hypothetical object (of some integral or enum type) within which | |
6714 | the given bit-field lives. The type of this hypothetical | |
6715 | "containing object" is always the same as the declared type of | |
6716 | the individual bit-field itself (for GCC anyway... the DWARF | |
6717 | spec doesn't actually mandate this). Note that it is the size | |
6718 | (in bytes) of the hypothetical "containing object" which will | |
6719 | be given in the DW_AT_byte_size attribute for this bit-field. | |
6720 | (See the `byte_size_attribute' function below.) It is also used | |
6721 | when calculating the value of the DW_AT_bit_offset attribute. | |
6722 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 6723 | |
a3f97cbb JW |
6724 | static void |
6725 | add_data_member_location_attribute (die, decl) | |
6726 | register dw_die_ref die; | |
6727 | register tree decl; | |
6728 | { | |
61b32c02 | 6729 | register unsigned long offset; |
a3f97cbb JW |
6730 | register dw_loc_descr_ref loc_descr; |
6731 | register enum dwarf_location_atom op; | |
6732 | ||
61b32c02 | 6733 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 6734 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
6735 | else |
6736 | offset = field_byte_offset (decl); | |
6737 | ||
a3f97cbb JW |
6738 | /* The DWARF2 standard says that we should assume that the structure address |
6739 | is already on the stack, so we can specify a structure field address | |
6740 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 6741 | |
a3f97cbb JW |
6742 | #ifdef MIPS_DEBUGGING_INFO |
6743 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
6744 | correctly. It works only if we leave the offset on the stack. */ | |
6745 | op = DW_OP_constu; | |
6746 | #else | |
6747 | op = DW_OP_plus_uconst; | |
6748 | #endif | |
71dfc51f | 6749 | |
a3f97cbb JW |
6750 | loc_descr = new_loc_descr (op, offset, 0); |
6751 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
6752 | } | |
6753 | ||
6754 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
6755 | does not have a "location" either in memory or in a register. These | |
6756 | things can arise in GNU C when a constant is passed as an actual parameter | |
6757 | to an inlined function. They can also arise in C++ where declared | |
6758 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 6759 | |
a3f97cbb JW |
6760 | static void |
6761 | add_const_value_attribute (die, rtl) | |
6762 | register dw_die_ref die; | |
6763 | register rtx rtl; | |
6764 | { | |
6765 | switch (GET_CODE (rtl)) | |
6766 | { | |
6767 | case CONST_INT: | |
6768 | /* Note that a CONST_INT rtx could represent either an integer or a | |
6769 | floating-point constant. A CONST_INT is used whenever the constant | |
6770 | will fit into a single word. In all such cases, the original mode | |
6771 | of the constant value is wiped out, and the CONST_INT rtx is | |
6772 | assigned VOIDmode. */ | |
6773 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
6774 | break; | |
6775 | ||
6776 | case CONST_DOUBLE: | |
6777 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
6778 | floating-point constant. A CONST_DOUBLE is used whenever the | |
6779 | constant requires more than one word in order to be adequately | |
469ac993 JM |
6780 | represented. We output CONST_DOUBLEs as blocks. */ |
6781 | { | |
6782 | register enum machine_mode mode = GET_MODE (rtl); | |
6783 | ||
6784 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
6785 | { | |
71dfc51f RK |
6786 | register unsigned length = GET_MODE_SIZE (mode) / sizeof (long); |
6787 | long array[4]; | |
6788 | REAL_VALUE_TYPE rv; | |
469ac993 | 6789 | |
71dfc51f | 6790 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
6791 | switch (mode) |
6792 | { | |
6793 | case SFmode: | |
71dfc51f | 6794 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
6795 | break; |
6796 | ||
6797 | case DFmode: | |
71dfc51f | 6798 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
6799 | break; |
6800 | ||
6801 | case XFmode: | |
6802 | case TFmode: | |
71dfc51f | 6803 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
6804 | break; |
6805 | ||
6806 | default: | |
6807 | abort (); | |
6808 | } | |
6809 | ||
469ac993 JM |
6810 | add_AT_float (die, DW_AT_const_value, length, array); |
6811 | } | |
6812 | else | |
6813 | add_AT_long_long (die, DW_AT_const_value, | |
6814 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
6815 | } | |
a3f97cbb JW |
6816 | break; |
6817 | ||
6818 | case CONST_STRING: | |
6819 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
6820 | break; | |
6821 | ||
6822 | case SYMBOL_REF: | |
6823 | case LABEL_REF: | |
6824 | case CONST: | |
1865dbb5 | 6825 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
6826 | break; |
6827 | ||
6828 | case PLUS: | |
6829 | /* In cases where an inlined instance of an inline function is passed | |
6830 | the address of an `auto' variable (which is local to the caller) we | |
6831 | can get a situation where the DECL_RTL of the artificial local | |
6832 | variable (for the inlining) which acts as a stand-in for the | |
6833 | corresponding formal parameter (of the inline function) will look | |
6834 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
6835 | exactly a compile-time constant expression, but it isn't the address | |
6836 | of the (artificial) local variable either. Rather, it represents the | |
6837 | *value* which the artificial local variable always has during its | |
6838 | lifetime. We currently have no way to represent such quasi-constant | |
6a7a9f01 | 6839 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
6840 | break; |
6841 | ||
6842 | default: | |
6843 | /* No other kinds of rtx should be possible here. */ | |
6844 | abort (); | |
6845 | } | |
6846 | ||
6847 | } | |
6848 | ||
6849 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
6850 | data attribute for a variable or a parameter. We generate the | |
6851 | DW_AT_const_value attribute only in those cases where the given variable | |
6852 | or parameter does not have a true "location" either in memory or in a | |
6853 | register. This can happen (for example) when a constant is passed as an | |
6854 | actual argument in a call to an inline function. (It's possible that | |
6855 | these things can crop up in other ways also.) Note that one type of | |
6856 | constant value which can be passed into an inlined function is a constant | |
6857 | pointer. This can happen for example if an actual argument in an inlined | |
6858 | function call evaluates to a compile-time constant address. */ | |
71dfc51f | 6859 | |
a3f97cbb JW |
6860 | static void |
6861 | add_location_or_const_value_attribute (die, decl) | |
6862 | register dw_die_ref die; | |
6863 | register tree decl; | |
6864 | { | |
6865 | register rtx rtl; | |
6866 | register tree declared_type; | |
6867 | register tree passed_type; | |
6868 | ||
6869 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f RK |
6870 | return; |
6871 | ||
6872 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
6873 | abort (); | |
6874 | ||
a3f97cbb JW |
6875 | /* Here we have to decide where we are going to say the parameter "lives" |
6876 | (as far as the debugger is concerned). We only have a couple of | |
6877 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 6878 | |
a3f97cbb | 6879 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 6880 | activation of the function. If optimization is enabled however, this |
a3f97cbb JW |
6881 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
6882 | that the parameter doesn't really live anywhere (as far as the code | |
6883 | generation parts of GCC are concerned) during most of the function's | |
6884 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
6885 | referenced within the function. |
6886 | ||
6887 | We could just generate a location descriptor here for all non-NULL | |
6888 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
6889 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
6890 | where DECL_RTL is NULL or is a pseudo-reg. | |
6891 | ||
6892 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
6893 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
6894 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
6895 | we can be sure that the parameter was passed using the same type as it is | |
6896 | declared to have within the function, and that its DECL_INCOMING_RTL | |
6897 | points us to a place where a value of that type is passed. | |
6898 | ||
6899 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
6900 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
6901 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
6902 | type which is *different* from the type of the parameter itself. Thus, | |
6903 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
6904 | such cases, the debugger would end up (for example) trying to fetch a | |
6905 | `float' from a place which actually contains the first part of a | |
6906 | `double'. That would lead to really incorrect and confusing | |
6907 | output at debug-time. | |
6908 | ||
6909 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
6910 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
6911 | are a couple of exceptions however. On little-endian machines we can | |
6912 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
6913 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
6914 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
6915 | when (on a little-endian machine) a non-prototyped function has a | |
6916 | parameter declared to be of type `short' or `char'. In such cases, | |
6917 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
6918 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
6919 | passed `int' value. If the debugger then uses that address to fetch | |
6920 | a `short' or a `char' (on a little-endian machine) the result will be | |
6921 | the correct data, so we allow for such exceptional cases below. | |
6922 | ||
6923 | Note that our goal here is to describe the place where the given formal | |
6924 | parameter lives during most of the function's activation (i.e. between | |
6925 | the end of the prologue and the start of the epilogue). We'll do that | |
6926 | as best as we can. Note however that if the given formal parameter is | |
6927 | modified sometime during the execution of the function, then a stack | |
6928 | backtrace (at debug-time) will show the function as having been | |
6929 | called with the *new* value rather than the value which was | |
6930 | originally passed in. This happens rarely enough that it is not | |
6931 | a major problem, but it *is* a problem, and I'd like to fix it. | |
6932 | ||
6933 | A future version of dwarf2out.c may generate two additional | |
6934 | attributes for any given DW_TAG_formal_parameter DIE which will | |
6935 | describe the "passed type" and the "passed location" for the | |
6936 | given formal parameter in addition to the attributes we now | |
6937 | generate to indicate the "declared type" and the "active | |
6938 | location" for each parameter. This additional set of attributes | |
6939 | could be used by debuggers for stack backtraces. Separately, note | |
6940 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
6941 | NULL also. This happens (for example) for inlined-instances of | |
6942 | inline function formal parameters which are never referenced. | |
6943 | This really shouldn't be happening. All PARM_DECL nodes should | |
6944 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
6945 | doesn't currently generate these values for inlined instances of | |
6946 | inline function parameters, so when we see such cases, we are | |
956d6950 | 6947 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
6948 | gets fixed). */ |
6949 | ||
6950 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
6951 | rtl = DECL_RTL (decl); | |
6952 | ||
6953 | if (TREE_CODE (decl) == PARM_DECL) | |
6954 | { | |
6955 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
6956 | { | |
6957 | declared_type = type_main_variant (TREE_TYPE (decl)); | |
6958 | passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 6959 | |
71dfc51f | 6960 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
6961 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
6962 | all* cases where (rtl == NULL_RTX) just below. */ | |
6963 | if (declared_type == passed_type) | |
71dfc51f RK |
6964 | rtl = DECL_INCOMING_RTL (decl); |
6965 | else if (! BYTES_BIG_ENDIAN | |
6966 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
6967 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
6968 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
71dfc51f | 6969 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 6970 | } |
5a904a61 JW |
6971 | |
6972 | /* If the parm was passed in registers, but lives on the stack, then | |
6973 | make a big endian correction if the mode of the type of the | |
6974 | parameter is not the same as the mode of the rtl. */ | |
6975 | /* ??? This is the same series of checks that are made in dbxout.c before | |
6976 | we reach the big endian correction code there. It isn't clear if all | |
6977 | of these checks are necessary here, but keeping them all is the safe | |
6978 | thing to do. */ | |
6979 | else if (GET_CODE (rtl) == MEM | |
6980 | && XEXP (rtl, 0) != const0_rtx | |
6981 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
6982 | /* Not passed in memory. */ | |
6983 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
6984 | /* Not passed by invisible reference. */ | |
6985 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
6986 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
6987 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
6988 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
6989 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
6990 | #endif | |
6991 | ) | |
6992 | /* Big endian correction check. */ | |
6993 | && BYTES_BIG_ENDIAN | |
6994 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
6995 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
6996 | < UNITS_PER_WORD)) | |
6997 | { | |
6998 | int offset = (UNITS_PER_WORD | |
6999 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
7000 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
7001 | plus_constant (XEXP (rtl, 0), offset)); | |
7002 | } | |
a3f97cbb | 7003 | } |
71dfc51f | 7004 | |
61b32c02 JM |
7005 | if (rtl == NULL_RTX) |
7006 | return; | |
7007 | ||
1914f5da | 7008 | rtl = eliminate_regs (rtl, 0, NULL_RTX); |
6a7a9f01 | 7009 | #ifdef LEAF_REG_REMAP |
54ff41b7 | 7010 | if (current_function_uses_only_leaf_regs) |
5f52dcfe | 7011 | leaf_renumber_regs_insn (rtl); |
6a7a9f01 JM |
7012 | #endif |
7013 | ||
a3f97cbb JW |
7014 | switch (GET_CODE (rtl)) |
7015 | { | |
e9a25f70 JL |
7016 | case ADDRESSOF: |
7017 | /* The address of a variable that was optimized away; don't emit | |
7018 | anything. */ | |
7019 | break; | |
7020 | ||
a3f97cbb JW |
7021 | case CONST_INT: |
7022 | case CONST_DOUBLE: | |
7023 | case CONST_STRING: | |
7024 | case SYMBOL_REF: | |
7025 | case LABEL_REF: | |
7026 | case CONST: | |
7027 | case PLUS: | |
7028 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
7029 | add_const_value_attribute (die, rtl); | |
7030 | break; | |
7031 | ||
7032 | case MEM: | |
7033 | case REG: | |
7034 | case SUBREG: | |
4401bf24 | 7035 | case CONCAT: |
ef76d03b | 7036 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
7037 | break; |
7038 | ||
7039 | default: | |
71dfc51f | 7040 | abort (); |
a3f97cbb JW |
7041 | } |
7042 | } | |
7043 | ||
7044 | /* Generate an DW_AT_name attribute given some string value to be included as | |
7045 | the value of the attribute. */ | |
71dfc51f RK |
7046 | |
7047 | static inline void | |
a3f97cbb JW |
7048 | add_name_attribute (die, name_string) |
7049 | register dw_die_ref die; | |
d560ee52 | 7050 | register const char *name_string; |
a3f97cbb | 7051 | { |
71dfc51f | 7052 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
7053 | { |
7054 | if (demangle_name_func) | |
7055 | name_string = (*demangle_name_func) (name_string); | |
7056 | ||
7057 | add_AT_string (die, DW_AT_name, name_string); | |
7058 | } | |
a3f97cbb JW |
7059 | } |
7060 | ||
7061 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 7062 | a representation for that bound. */ |
71dfc51f | 7063 | |
a3f97cbb JW |
7064 | static void |
7065 | add_bound_info (subrange_die, bound_attr, bound) | |
7066 | register dw_die_ref subrange_die; | |
7067 | register enum dwarf_attribute bound_attr; | |
7068 | register tree bound; | |
7069 | { | |
ef76d03b JW |
7070 | /* If this is an Ada unconstrained array type, then don't emit any debug |
7071 | info because the array bounds are unknown. They are parameterized when | |
7072 | the type is instantiated. */ | |
7073 | if (contains_placeholder_p (bound)) | |
7074 | return; | |
7075 | ||
a3f97cbb JW |
7076 | switch (TREE_CODE (bound)) |
7077 | { | |
7078 | case ERROR_MARK: | |
7079 | return; | |
7080 | ||
7081 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
7082 | case INTEGER_CST: | |
665f2503 RK |
7083 | if (! host_integerp (bound, 0) |
7084 | || (bound_attr == DW_AT_lower_bound | |
7085 | && ((is_c_family () && integer_zerop (bound)) | |
7086 | || (is_fortran () && integer_onep (bound))))) | |
7087 | /* use the default */ | |
7088 | ; | |
141719a8 | 7089 | else |
665f2503 | 7090 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
7091 | break; |
7092 | ||
b1ccbc24 | 7093 | case CONVERT_EXPR: |
a3f97cbb | 7094 | case NOP_EXPR: |
b1ccbc24 RK |
7095 | case NON_LVALUE_EXPR: |
7096 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
7097 | break; | |
7098 | ||
a3f97cbb JW |
7099 | case SAVE_EXPR: |
7100 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
7101 | access the upper bound values may be bogus. If they refer to a |
7102 | register, they may only describe how to get at these values at the | |
7103 | points in the generated code right after they have just been | |
7104 | computed. Worse yet, in the typical case, the upper bound values | |
7105 | will not even *be* computed in the optimized code (though the | |
7106 | number of elements will), so these SAVE_EXPRs are entirely | |
7107 | bogus. In order to compensate for this fact, we check here to see | |
7108 | if optimization is enabled, and if so, we don't add an attribute | |
7109 | for the (unknown and unknowable) upper bound. This should not | |
7110 | cause too much trouble for existing (stupid?) debuggers because | |
7111 | they have to deal with empty upper bounds location descriptions | |
7112 | anyway in order to be able to deal with incomplete array types. | |
7113 | Of course an intelligent debugger (GDB?) should be able to | |
7114 | comprehend that a missing upper bound specification in a array | |
7115 | type used for a storage class `auto' local array variable | |
7116 | indicates that the upper bound is both unknown (at compile- time) | |
7117 | and unknowable (at run-time) due to optimization. | |
7118 | ||
7119 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
7120 | value there unless it was going to be used repeatedly in the | |
7121 | function, i.e. for cleanups. */ | |
1cfdcc15 JM |
7122 | if (! optimize || (SAVE_EXPR_RTL (bound) |
7123 | && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 7124 | { |
466446b0 JM |
7125 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
7126 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
7127 | register rtx loc = SAVE_EXPR_RTL (bound); |
7128 | ||
7129 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
7130 | it references an outer function's frame. */ | |
7131 | ||
7132 | if (GET_CODE (loc) == MEM) | |
7133 | { | |
7134 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
7135 | ||
7136 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 7137 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
7138 | } |
7139 | ||
466446b0 JM |
7140 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
7141 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 7142 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 7143 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 7144 | } |
71dfc51f RK |
7145 | |
7146 | /* Else leave out the attribute. */ | |
a3f97cbb | 7147 | break; |
3f76745e | 7148 | |
ef76d03b JW |
7149 | case MAX_EXPR: |
7150 | case VAR_DECL: | |
c85f7c16 | 7151 | case COMPONENT_REF: |
ef76d03b JW |
7152 | /* ??? These types of bounds can be created by the Ada front end, |
7153 | and it isn't clear how to emit debug info for them. */ | |
7154 | break; | |
7155 | ||
3f76745e JM |
7156 | default: |
7157 | abort (); | |
a3f97cbb JW |
7158 | } |
7159 | } | |
7160 | ||
7161 | /* Note that the block of subscript information for an array type also | |
7162 | includes information about the element type of type given array type. */ | |
71dfc51f | 7163 | |
a3f97cbb JW |
7164 | static void |
7165 | add_subscript_info (type_die, type) | |
7166 | register dw_die_ref type_die; | |
7167 | register tree type; | |
7168 | { | |
081f5e7e | 7169 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 7170 | register unsigned dimension_number; |
081f5e7e | 7171 | #endif |
a3f97cbb JW |
7172 | register tree lower, upper; |
7173 | register dw_die_ref subrange_die; | |
7174 | ||
7175 | /* The GNU compilers represent multidimensional array types as sequences of | |
7176 | one dimensional array types whose element types are themselves array | |
7177 | types. Here we squish that down, so that each multidimensional array | |
7178 | type gets only one array_type DIE in the Dwarf debugging info. The draft | |
7179 | Dwarf specification say that we are allowed to do this kind of | |
7180 | compression in C (because there is no difference between an array or | |
7181 | arrays and a multidimensional array in C) but for other source languages | |
7182 | (e.g. Ada) we probably shouldn't do this. */ | |
71dfc51f | 7183 | |
a3f97cbb JW |
7184 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7185 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7186 | We work around this by disabling this feature. See also | |
7187 | gen_array_type_die. */ | |
7188 | #ifndef MIPS_DEBUGGING_INFO | |
7189 | for (dimension_number = 0; | |
7190 | TREE_CODE (type) == ARRAY_TYPE; | |
7191 | type = TREE_TYPE (type), dimension_number++) | |
7192 | { | |
7193 | #endif | |
7194 | register tree domain = TYPE_DOMAIN (type); | |
7195 | ||
7196 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
7197 | and (in GNU C only) variable bounds. Handle all three forms | |
7198 | here. */ | |
7199 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
7200 | if (domain) | |
7201 | { | |
7202 | /* We have an array type with specified bounds. */ | |
7203 | lower = TYPE_MIN_VALUE (domain); | |
7204 | upper = TYPE_MAX_VALUE (domain); | |
7205 | ||
a9d38797 JM |
7206 | /* define the index type. */ |
7207 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
7208 | { |
7209 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
7210 | TREE_TYPE field. We can't emit debug info for this | |
7211 | because it is an unnamed integral type. */ | |
7212 | if (TREE_CODE (domain) == INTEGER_TYPE | |
7213 | && TYPE_NAME (domain) == NULL_TREE | |
7214 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
7215 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
7216 | ; | |
7217 | else | |
7218 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
7219 | type_die); | |
7220 | } | |
a9d38797 | 7221 | |
e1ee5cdc RH |
7222 | /* ??? If upper is NULL, the array has unspecified length, |
7223 | but it does have a lower bound. This happens with Fortran | |
7224 | dimension arr(N:*) | |
7225 | Since the debugger is definitely going to need to know N | |
7226 | to produce useful results, go ahead and output the lower | |
7227 | bound solo, and hope the debugger can cope. */ | |
7228 | ||
141719a8 | 7229 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
7230 | if (upper) |
7231 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
7232 | } |
7233 | else | |
71dfc51f | 7234 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
7235 | spec does not say how to handle this; let's just leave out the |
7236 | bounds. */ | |
2d8b0f3a JL |
7237 | {;} |
7238 | ||
71dfc51f | 7239 | |
a3f97cbb JW |
7240 | #ifndef MIPS_DEBUGGING_INFO |
7241 | } | |
7242 | #endif | |
7243 | } | |
7244 | ||
7245 | static void | |
7246 | add_byte_size_attribute (die, tree_node) | |
7247 | dw_die_ref die; | |
7248 | register tree tree_node; | |
7249 | { | |
7250 | register unsigned size; | |
7251 | ||
7252 | switch (TREE_CODE (tree_node)) | |
7253 | { | |
7254 | case ERROR_MARK: | |
7255 | size = 0; | |
7256 | break; | |
7257 | case ENUMERAL_TYPE: | |
7258 | case RECORD_TYPE: | |
7259 | case UNION_TYPE: | |
7260 | case QUAL_UNION_TYPE: | |
7261 | size = int_size_in_bytes (tree_node); | |
7262 | break; | |
7263 | case FIELD_DECL: | |
7264 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
7265 | generally given as the number of bytes normally allocated for an | |
7266 | object of the *declared* type of the member itself. This is true | |
7267 | even for bit-fields. */ | |
7268 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
7269 | break; | |
7270 | default: | |
7271 | abort (); | |
7272 | } | |
7273 | ||
7274 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
7275 | indicates that the byte size of the entity in question is variable. We | |
7276 | have no good way of expressing this fact in Dwarf at the present time, | |
7277 | so just let the -1 pass on through. */ | |
7278 | ||
7279 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
7280 | } | |
7281 | ||
7282 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
7283 | which specifies the distance in bits from the highest order bit of the | |
7284 | "containing object" for the bit-field to the highest order bit of the | |
7285 | bit-field itself. | |
7286 | ||
b2932ae5 JM |
7287 | For any given bit-field, the "containing object" is a hypothetical |
7288 | object (of some integral or enum type) within which the given bit-field | |
7289 | lives. The type of this hypothetical "containing object" is always the | |
7290 | same as the declared type of the individual bit-field itself. The | |
7291 | determination of the exact location of the "containing object" for a | |
7292 | bit-field is rather complicated. It's handled by the | |
7293 | `field_byte_offset' function (above). | |
a3f97cbb JW |
7294 | |
7295 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
7296 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
7297 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
7298 | |
7299 | static inline void | |
a3f97cbb JW |
7300 | add_bit_offset_attribute (die, decl) |
7301 | register dw_die_ref die; | |
7302 | register tree decl; | |
7303 | { | |
665f2503 RK |
7304 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
7305 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
7306 | HOST_WIDE_INT bitpos_int; | |
7307 | HOST_WIDE_INT highest_order_object_bit_offset; | |
7308 | HOST_WIDE_INT highest_order_field_bit_offset; | |
7309 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 7310 | |
3a88cbd1 JL |
7311 | /* Must be a field and a bit field. */ |
7312 | if (!type | |
7313 | || TREE_CODE (decl) != FIELD_DECL) | |
7314 | abort (); | |
a3f97cbb JW |
7315 | |
7316 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
7317 | encounter such things, just return without generating any attribute | |
665f2503 RK |
7318 | whatsoever. Likewise for variable or too large size. */ |
7319 | if (! host_integerp (bit_position (decl), 0) | |
7320 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
7321 | return; |
7322 | ||
665f2503 | 7323 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
7324 | |
7325 | /* Note that the bit offset is always the distance (in bits) from the | |
7326 | highest-order bit of the "containing object" to the highest-order bit of | |
7327 | the bit-field itself. Since the "high-order end" of any object or field | |
7328 | is different on big-endian and little-endian machines, the computation | |
7329 | below must take account of these differences. */ | |
7330 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
7331 | highest_order_field_bit_offset = bitpos_int; | |
7332 | ||
71dfc51f | 7333 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 7334 | { |
665f2503 | 7335 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
7336 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
7337 | } | |
71dfc51f RK |
7338 | |
7339 | bit_offset | |
7340 | = (! BYTES_BIG_ENDIAN | |
7341 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
7342 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
7343 | |
7344 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
7345 | } | |
7346 | ||
7347 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
7348 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
7349 | |
7350 | static inline void | |
a3f97cbb JW |
7351 | add_bit_size_attribute (die, decl) |
7352 | register dw_die_ref die; | |
7353 | register tree decl; | |
7354 | { | |
3a88cbd1 JL |
7355 | /* Must be a field and a bit field. */ |
7356 | if (TREE_CODE (decl) != FIELD_DECL | |
7357 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
7358 | abort (); | |
665f2503 RK |
7359 | |
7360 | if (host_integerp (DECL_SIZE (decl), 1)) | |
7361 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
7362 | } |
7363 | ||
88dad228 | 7364 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 7365 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
7366 | |
7367 | static inline void | |
a3f97cbb JW |
7368 | add_prototyped_attribute (die, func_type) |
7369 | register dw_die_ref die; | |
7370 | register tree func_type; | |
7371 | { | |
88dad228 JM |
7372 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
7373 | && TYPE_ARG_TYPES (func_type) != NULL) | |
7374 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
7375 | } |
7376 | ||
7377 | ||
7378 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found | |
7379 | by looking in either the type declaration or object declaration | |
7380 | equate table. */ | |
71dfc51f RK |
7381 | |
7382 | static inline void | |
a3f97cbb JW |
7383 | add_abstract_origin_attribute (die, origin) |
7384 | register dw_die_ref die; | |
7385 | register tree origin; | |
7386 | { | |
7387 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 7388 | |
d10b8e05 | 7389 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
7390 | { |
7391 | /* We may have gotten separated from the block for the inlined | |
7392 | function, if we're in an exception handler or some such; make | |
7393 | sure that the abstract function has been written out. | |
7394 | ||
7395 | Doing this for nested functions is wrong, however; functions are | |
7396 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
7397 | tree fn = origin; |
7398 | if (TYPE_P (fn)) | |
7399 | fn = TYPE_STUB_DECL (fn); | |
7400 | fn = decl_function_context (fn); | |
e40a1c67 JM |
7401 | if (fn) |
7402 | gen_abstract_function (fn); | |
7403 | } | |
44db1d9c | 7404 | |
2f939d94 | 7405 | if (DECL_P (origin)) |
71dfc51f | 7406 | origin_die = lookup_decl_die (origin); |
2f939d94 | 7407 | else if (TYPE_P (origin)) |
71dfc51f RK |
7408 | origin_die = lookup_type_die (origin); |
7409 | ||
bbc6ae08 | 7410 | if (origin_die == NULL) |
1ae8994f | 7411 | abort (); |
bbc6ae08 | 7412 | |
a3f97cbb JW |
7413 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
7414 | } | |
7415 | ||
bdb669cb JM |
7416 | /* We do not currently support the pure_virtual attribute. */ |
7417 | ||
71dfc51f | 7418 | static inline void |
a3f97cbb JW |
7419 | add_pure_or_virtual_attribute (die, func_decl) |
7420 | register dw_die_ref die; | |
7421 | register tree func_decl; | |
7422 | { | |
a94dbf2c | 7423 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 7424 | { |
bdb669cb | 7425 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
7426 | |
7427 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
7428 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
7429 | new_loc_descr (DW_OP_constu, | |
7430 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
7431 | 0)); | |
71dfc51f | 7432 | |
a94dbf2c JM |
7433 | /* GNU extension: Record what type this method came from originally. */ |
7434 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
7435 | add_AT_die_ref (die, DW_AT_containing_type, | |
7436 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
7437 | } |
7438 | } | |
7439 | \f | |
b2932ae5 | 7440 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 7441 | |
b2932ae5 JM |
7442 | static void |
7443 | add_src_coords_attributes (die, decl) | |
7444 | register dw_die_ref die; | |
7445 | register tree decl; | |
7446 | { | |
7447 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 7448 | |
b2932ae5 JM |
7449 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
7450 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
7451 | } | |
7452 | ||
a3f97cbb JW |
7453 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
7454 | given decl, but only if it actually has a name. */ | |
71dfc51f | 7455 | |
a3f97cbb JW |
7456 | static void |
7457 | add_name_and_src_coords_attributes (die, decl) | |
7458 | register dw_die_ref die; | |
7459 | register tree decl; | |
7460 | { | |
61b32c02 | 7461 | register tree decl_name; |
71dfc51f | 7462 | |
a1d7ffe3 | 7463 | decl_name = DECL_NAME (decl); |
71dfc51f | 7464 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 7465 | { |
a1d7ffe3 | 7466 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
7467 | if (! DECL_ARTIFICIAL (decl)) |
7468 | add_src_coords_attributes (die, decl); | |
e689ae67 | 7469 | |
a1d7ffe3 | 7470 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 7471 | && TREE_PUBLIC (decl) |
a1d7ffe3 JM |
7472 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) |
7473 | add_AT_string (die, DW_AT_MIPS_linkage_name, | |
7474 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
7475 | } |
7476 | } | |
7477 | ||
7478 | /* Push a new declaration scope. */ | |
71dfc51f | 7479 | |
a3f97cbb JW |
7480 | static void |
7481 | push_decl_scope (scope) | |
7482 | tree scope; | |
7483 | { | |
7484 | /* Make room in the decl_scope_table, if necessary. */ | |
7485 | if (decl_scope_table_allocated == decl_scope_depth) | |
7486 | { | |
7487 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 7488 | decl_scope_table |
777ad4c2 JM |
7489 | = (tree *) xrealloc (decl_scope_table, |
7490 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 7491 | } |
71dfc51f | 7492 | |
777ad4c2 | 7493 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 7494 | decl_scope_depth++; |
a3f97cbb JW |
7495 | } |
7496 | ||
777ad4c2 JM |
7497 | /* Pop a declaration scope. */ |
7498 | static inline void | |
7499 | pop_decl_scope () | |
7500 | { | |
7501 | if (decl_scope_depth <= 0) | |
7502 | abort (); | |
7503 | --decl_scope_depth; | |
7504 | } | |
7505 | ||
7506 | /* Return the DIE for the scope that immediately contains this type. | |
7507 | Non-named types get global scope. Named types nested in other | |
7508 | types get their containing scope if it's open, or global scope | |
7509 | otherwise. All other types (i.e. function-local named types) get | |
7510 | the current active scope. */ | |
71dfc51f | 7511 | |
a3f97cbb | 7512 | static dw_die_ref |
ab72d377 JM |
7513 | scope_die_for (t, context_die) |
7514 | register tree t; | |
a3f97cbb JW |
7515 | register dw_die_ref context_die; |
7516 | { | |
7517 | register dw_die_ref scope_die = NULL; | |
7518 | register tree containing_scope; | |
e3e7774e | 7519 | register int i; |
a3f97cbb | 7520 | |
777ad4c2 JM |
7521 | /* Non-types always go in the current scope. */ |
7522 | if (! TYPE_P (t)) | |
7523 | abort (); | |
7524 | ||
7525 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 7526 | |
2addbe1d JM |
7527 | /* Ignore namespaces for the moment. */ |
7528 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
7529 | containing_scope = NULL_TREE; | |
7530 | ||
5f2f160c JM |
7531 | /* Ignore function type "scopes" from the C frontend. They mean that |
7532 | a tagged type is local to a parmlist of a function declarator, but | |
7533 | that isn't useful to DWARF. */ | |
7534 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
7535 | containing_scope = NULL_TREE; | |
7536 | ||
71dfc51f RK |
7537 | if (containing_scope == NULL_TREE) |
7538 | scope_die = comp_unit_die; | |
777ad4c2 | 7539 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 7540 | { |
777ad4c2 JM |
7541 | /* For types, we can just look up the appropriate DIE. But |
7542 | first we check to see if we're in the middle of emitting it | |
7543 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
7544 | |
7545 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 7546 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
7547 | break; |
7548 | ||
7549 | if (i < 0) | |
7550 | { | |
348bb3c7 JM |
7551 | if (debug_info_level > DINFO_LEVEL_TERSE |
7552 | && !TREE_ASM_WRITTEN (containing_scope)) | |
7553 | abort (); | |
7554 | ||
7555 | /* If none of the current dies are suitable, we get file scope. */ | |
7556 | scope_die = comp_unit_die; | |
7557 | } | |
7558 | else | |
777ad4c2 | 7559 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 7560 | } |
a3f97cbb | 7561 | else |
777ad4c2 | 7562 | scope_die = context_die; |
71dfc51f | 7563 | |
a3f97cbb JW |
7564 | return scope_die; |
7565 | } | |
7566 | ||
777ad4c2 JM |
7567 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
7568 | ||
c6991660 | 7569 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
7570 | static inline int |
7571 | local_scope_p (context_die) | |
7572 | dw_die_ref context_die; | |
a3f97cbb | 7573 | { |
777ad4c2 JM |
7574 | for (; context_die; context_die = context_die->die_parent) |
7575 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
7576 | || context_die->die_tag == DW_TAG_subprogram) | |
7577 | return 1; | |
7578 | return 0; | |
a3f97cbb JW |
7579 | } |
7580 | ||
9765e357 JM |
7581 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
7582 | ||
c6991660 | 7583 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
7584 | static inline int |
7585 | class_scope_p (context_die) | |
7586 | dw_die_ref context_die; | |
7587 | { | |
7588 | return (context_die | |
7589 | && (context_die->die_tag == DW_TAG_structure_type | |
7590 | || context_die->die_tag == DW_TAG_union_type)); | |
7591 | } | |
7592 | ||
a3f97cbb JW |
7593 | /* Many forms of DIEs require a "type description" attribute. This |
7594 | routine locates the proper "type descriptor" die for the type given | |
7595 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 7596 | |
a3f97cbb JW |
7597 | static void |
7598 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
7599 | register dw_die_ref object_die; | |
7600 | register tree type; | |
7601 | register int decl_const; | |
7602 | register int decl_volatile; | |
7603 | register dw_die_ref context_die; | |
7604 | { | |
7605 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
7606 | register dw_die_ref type_die = NULL; |
7607 | ||
ef76d03b JW |
7608 | /* ??? If this type is an unnamed subrange type of an integral or |
7609 | floating-point type, use the inner type. This is because we have no | |
7610 | support for unnamed types in base_type_die. This can happen if this is | |
7611 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
7612 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
7613 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
7614 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
7615 | ||
a3f97cbb | 7616 | if (code == ERROR_MARK) |
b1ccbc24 | 7617 | return; |
a3f97cbb JW |
7618 | |
7619 | /* Handle a special case. For functions whose return type is void, we | |
7620 | generate *no* type attribute. (Note that no object may have type | |
7621 | `void', so this only applies to function return types). */ | |
7622 | if (code == VOID_TYPE) | |
b1ccbc24 | 7623 | return; |
a3f97cbb | 7624 | |
a3f97cbb JW |
7625 | type_die = modified_type_die (type, |
7626 | decl_const || TYPE_READONLY (type), | |
7627 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 7628 | context_die); |
a3f97cbb | 7629 | if (type_die != NULL) |
71dfc51f | 7630 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
7631 | } |
7632 | ||
7633 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
7634 | a pointer to the (string) tag name for the given type, or zero if the type | |
7635 | was declared without a tag. */ | |
71dfc51f | 7636 | |
a3f97cbb JW |
7637 | static char * |
7638 | type_tag (type) | |
7639 | register tree type; | |
7640 | { | |
7641 | register char *name = 0; | |
7642 | ||
7643 | if (TYPE_NAME (type) != 0) | |
7644 | { | |
7645 | register tree t = 0; | |
7646 | ||
7647 | /* Find the IDENTIFIER_NODE for the type name. */ | |
7648 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
7649 | t = TYPE_NAME (type); | |
bdb669cb | 7650 | |
a3f97cbb JW |
7651 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
7652 | a TYPE_DECL node, regardless of whether or not a `typedef' was | |
bdb669cb | 7653 | involved. */ |
a94dbf2c JM |
7654 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
7655 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 7656 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 7657 | |
a3f97cbb JW |
7658 | /* Now get the name as a string, or invent one. */ |
7659 | if (t != 0) | |
a94dbf2c | 7660 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 7661 | } |
71dfc51f | 7662 | |
a3f97cbb JW |
7663 | return (name == 0 || *name == '\0') ? 0 : name; |
7664 | } | |
7665 | ||
7666 | /* Return the type associated with a data member, make a special check | |
7667 | for bit field types. */ | |
71dfc51f RK |
7668 | |
7669 | static inline tree | |
a3f97cbb JW |
7670 | member_declared_type (member) |
7671 | register tree member; | |
7672 | { | |
71dfc51f RK |
7673 | return (DECL_BIT_FIELD_TYPE (member) |
7674 | ? DECL_BIT_FIELD_TYPE (member) | |
7675 | : TREE_TYPE (member)); | |
a3f97cbb JW |
7676 | } |
7677 | ||
d291dd49 | 7678 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 7679 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 7680 | |
487a6e06 | 7681 | #if 0 |
a3f97cbb | 7682 | static char * |
d291dd49 | 7683 | decl_start_label (decl) |
a3f97cbb JW |
7684 | register tree decl; |
7685 | { | |
7686 | rtx x; | |
7687 | char *fnname; | |
7688 | x = DECL_RTL (decl); | |
7689 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
7690 | abort (); |
7691 | ||
a3f97cbb JW |
7692 | x = XEXP (x, 0); |
7693 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
7694 | abort (); |
7695 | ||
a3f97cbb JW |
7696 | fnname = XSTR (x, 0); |
7697 | return fnname; | |
7698 | } | |
487a6e06 | 7699 | #endif |
a3f97cbb | 7700 | \f |
956d6950 | 7701 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 7702 | the compilation unit. Debugging information is collected by walking |
88dad228 | 7703 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
7704 | |
7705 | static void | |
7706 | gen_array_type_die (type, context_die) | |
7707 | register tree type; | |
7708 | register dw_die_ref context_die; | |
7709 | { | |
ab72d377 | 7710 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 7711 | register dw_die_ref array_die; |
a3f97cbb | 7712 | register tree element_type; |
bdb669cb | 7713 | |
a9d38797 JM |
7714 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
7715 | the inner array type comes before the outer array type. Thus we must | |
7716 | call gen_type_die before we call new_die. See below also. */ | |
7717 | #ifdef MIPS_DEBUGGING_INFO | |
7718 | gen_type_die (TREE_TYPE (type), context_die); | |
7719 | #endif | |
7720 | ||
7721 | array_die = new_die (DW_TAG_array_type, scope_die); | |
7722 | ||
a3f97cbb JW |
7723 | #if 0 |
7724 | /* We default the array ordering. SDB will probably do | |
7725 | the right things even if DW_AT_ordering is not present. It's not even | |
7726 | an issue until we start to get into multidimensional arrays anyway. If | |
7727 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
7728 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
7729 | and when we find out that we need to put these in, we will only do so | |
7730 | for multidimensional arrays. */ | |
7731 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
7732 | #endif | |
7733 | ||
a9d38797 | 7734 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
7735 | /* The SGI compilers handle arrays of unknown bound by setting |
7736 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
7737 | if (! TYPE_DOMAIN (type)) |
7738 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
7739 | else | |
7740 | #endif | |
7741 | add_subscript_info (array_die, type); | |
a3f97cbb | 7742 | |
14a774a9 | 7743 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
7744 | equate_type_number_to_die (type, array_die); |
7745 | ||
7746 | /* Add representation of the type of the elements of this array type. */ | |
7747 | element_type = TREE_TYPE (type); | |
71dfc51f | 7748 | |
a3f97cbb JW |
7749 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7750 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7751 | We work around this by disabling this feature. See also | |
7752 | add_subscript_info. */ | |
7753 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
7754 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
7755 | element_type = TREE_TYPE (element_type); | |
7756 | ||
a3f97cbb | 7757 | gen_type_die (element_type, context_die); |
a9d38797 | 7758 | #endif |
a3f97cbb JW |
7759 | |
7760 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
7761 | } | |
7762 | ||
7763 | static void | |
7764 | gen_set_type_die (type, context_die) | |
7765 | register tree type; | |
7766 | register dw_die_ref context_die; | |
7767 | { | |
71dfc51f RK |
7768 | register dw_die_ref type_die |
7769 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
7770 | ||
a3f97cbb | 7771 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
7772 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
7773 | } | |
7774 | ||
d6f4ec51 | 7775 | #if 0 |
a3f97cbb JW |
7776 | static void |
7777 | gen_entry_point_die (decl, context_die) | |
7778 | register tree decl; | |
7779 | register dw_die_ref context_die; | |
7780 | { | |
7781 | register tree origin = decl_ultimate_origin (decl); | |
7782 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
7783 | if (origin != NULL) | |
71dfc51f | 7784 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
7785 | else |
7786 | { | |
7787 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
7788 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
7789 | 0, 0, context_die); | |
7790 | } | |
71dfc51f | 7791 | |
a3f97cbb | 7792 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 7793 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 7794 | else |
71dfc51f | 7795 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 7796 | } |
d6f4ec51 | 7797 | #endif |
a3f97cbb | 7798 | |
8a8c3656 JM |
7799 | /* Remember a type in the incomplete_types_list. */ |
7800 | ||
7801 | static void | |
7802 | add_incomplete_type (type) | |
7803 | tree type; | |
7804 | { | |
7805 | if (incomplete_types == incomplete_types_allocated) | |
7806 | { | |
7807 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
7808 | incomplete_types_list | |
7809 | = (tree *) xrealloc (incomplete_types_list, | |
7810 | sizeof (tree) * incomplete_types_allocated); | |
7811 | } | |
7812 | ||
7813 | incomplete_types_list[incomplete_types++] = type; | |
7814 | } | |
7815 | ||
7816 | /* Walk through the list of incomplete types again, trying once more to | |
7817 | emit full debugging info for them. */ | |
7818 | ||
7819 | static void | |
7820 | retry_incomplete_types () | |
7821 | { | |
7822 | register tree type; | |
7823 | ||
7824 | while (incomplete_types) | |
7825 | { | |
7826 | --incomplete_types; | |
7827 | type = incomplete_types_list[incomplete_types]; | |
7828 | gen_type_die (type, comp_unit_die); | |
7829 | } | |
7830 | } | |
7831 | ||
a3f97cbb | 7832 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 7833 | |
a3f97cbb JW |
7834 | static void |
7835 | gen_inlined_enumeration_type_die (type, context_die) | |
7836 | register tree type; | |
7837 | register dw_die_ref context_die; | |
7838 | { | |
71dfc51f | 7839 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 7840 | context_die); |
bbc6ae08 NC |
7841 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
7842 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
7843 | add_abstract_origin_attribute (type_die, type); |
7844 | } | |
7845 | ||
7846 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 7847 | |
a3f97cbb JW |
7848 | static void |
7849 | gen_inlined_structure_type_die (type, context_die) | |
7850 | register tree type; | |
7851 | register dw_die_ref context_die; | |
7852 | { | |
777ad4c2 JM |
7853 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
7854 | ||
bbc6ae08 NC |
7855 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
7856 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
7857 | add_abstract_origin_attribute (type_die, type); |
7858 | } | |
7859 | ||
7860 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 7861 | |
a3f97cbb JW |
7862 | static void |
7863 | gen_inlined_union_type_die (type, context_die) | |
7864 | register tree type; | |
7865 | register dw_die_ref context_die; | |
7866 | { | |
777ad4c2 JM |
7867 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
7868 | ||
bbc6ae08 NC |
7869 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
7870 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
7871 | add_abstract_origin_attribute (type_die, type); |
7872 | } | |
7873 | ||
7874 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
7875 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
7876 | enumerated type name/value is listed as a child of the enumerated type |
7877 | DIE. */ | |
71dfc51f | 7878 | |
a3f97cbb | 7879 | static void |
273dbe67 | 7880 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 7881 | register tree type; |
a3f97cbb JW |
7882 | register dw_die_ref context_die; |
7883 | { | |
273dbe67 JM |
7884 | register dw_die_ref type_die = lookup_type_die (type); |
7885 | ||
a3f97cbb JW |
7886 | if (type_die == NULL) |
7887 | { | |
7888 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 7889 | scope_die_for (type, context_die)); |
a3f97cbb JW |
7890 | equate_type_number_to_die (type, type_die); |
7891 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 7892 | } |
273dbe67 JM |
7893 | else if (! TYPE_SIZE (type)) |
7894 | return; | |
7895 | else | |
7896 | remove_AT (type_die, DW_AT_declaration); | |
7897 | ||
7898 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
7899 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
7900 | attribute or the DW_AT_element_list attribute. */ | |
7901 | if (TYPE_SIZE (type)) | |
a3f97cbb | 7902 | { |
273dbe67 | 7903 | register tree link; |
71dfc51f | 7904 | |
a082c85a | 7905 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 7906 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 7907 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 7908 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 7909 | |
ef76d03b JW |
7910 | /* If the first reference to this type was as the return type of an |
7911 | inline function, then it may not have a parent. Fix this now. */ | |
7912 | if (type_die->die_parent == NULL) | |
7913 | add_child_die (scope_die_for (type, context_die), type_die); | |
7914 | ||
273dbe67 JM |
7915 | for (link = TYPE_FIELDS (type); |
7916 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 7917 | { |
273dbe67 | 7918 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 7919 | |
273dbe67 JM |
7920 | add_name_attribute (enum_die, |
7921 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
7922 | |
7923 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
7924 | { |
7925 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
7926 | add_AT_int (enum_die, DW_AT_const_value, | |
7927 | tree_low_cst (TREE_VALUE (link), 0)); | |
7928 | else | |
7929 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
7930 | tree_low_cst (TREE_VALUE (link), 0)); | |
7931 | } | |
a3f97cbb JW |
7932 | } |
7933 | } | |
273dbe67 JM |
7934 | else |
7935 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
7936 | } |
7937 | ||
7938 | ||
7939 | /* Generate a DIE to represent either a real live formal parameter decl or to | |
7940 | represent just the type of some formal parameter position in some function | |
7941 | type. | |
71dfc51f | 7942 | |
a3f97cbb JW |
7943 | Note that this routine is a bit unusual because its argument may be a |
7944 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
7945 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
7946 | node. If it's the former then this function is being called to output a | |
7947 | DIE to represent a formal parameter object (or some inlining thereof). If | |
7948 | it's the latter, then this function is only being called to output a | |
7949 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
7950 | argument type of some subprogram type. */ | |
71dfc51f | 7951 | |
a94dbf2c | 7952 | static dw_die_ref |
a3f97cbb JW |
7953 | gen_formal_parameter_die (node, context_die) |
7954 | register tree node; | |
7955 | register dw_die_ref context_die; | |
7956 | { | |
71dfc51f RK |
7957 | register dw_die_ref parm_die |
7958 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 7959 | register tree origin; |
71dfc51f | 7960 | |
a3f97cbb JW |
7961 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
7962 | { | |
a3f97cbb JW |
7963 | case 'd': |
7964 | origin = decl_ultimate_origin (node); | |
7965 | if (origin != NULL) | |
a94dbf2c | 7966 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
7967 | else |
7968 | { | |
7969 | add_name_and_src_coords_attributes (parm_die, node); | |
7970 | add_type_attribute (parm_die, TREE_TYPE (node), | |
7971 | TREE_READONLY (node), | |
7972 | TREE_THIS_VOLATILE (node), | |
7973 | context_die); | |
bdb669cb JM |
7974 | if (DECL_ARTIFICIAL (node)) |
7975 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 7976 | } |
71dfc51f | 7977 | |
141719a8 JM |
7978 | equate_decl_number_to_die (node, parm_die); |
7979 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 7980 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 7981 | |
a3f97cbb JW |
7982 | break; |
7983 | ||
a3f97cbb | 7984 | case 't': |
71dfc51f | 7985 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
7986 | add_type_attribute (parm_die, node, 0, 0, context_die); |
7987 | break; | |
7988 | ||
a3f97cbb JW |
7989 | default: |
7990 | abort (); | |
7991 | } | |
71dfc51f | 7992 | |
a94dbf2c | 7993 | return parm_die; |
a3f97cbb JW |
7994 | } |
7995 | ||
7996 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
7997 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 7998 | |
a3f97cbb JW |
7999 | static void |
8000 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 8001 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
8002 | register dw_die_ref context_die; |
8003 | { | |
487a6e06 | 8004 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
8005 | } |
8006 | ||
8007 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
8008 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
8009 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 8010 | those which appear as part of a function *definition*). */ |
71dfc51f | 8011 | |
a3f97cbb JW |
8012 | static void |
8013 | gen_formal_types_die (function_or_method_type, context_die) | |
8014 | register tree function_or_method_type; | |
8015 | register dw_die_ref context_die; | |
8016 | { | |
8017 | register tree link; | |
8018 | register tree formal_type = NULL; | |
8019 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
8020 | ||
bdb669cb | 8021 | #if 0 |
a3f97cbb JW |
8022 | /* In the case where we are generating a formal types list for a C++ |
8023 | non-static member function type, skip over the first thing on the | |
8024 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
8025 | `this pointer'. The debugger should be able to figure out (without | |
8026 | being explicitly told) that this non-static member function type takes a | |
8027 | `this pointer' and should be able to figure what the type of that hidden | |
8028 | parameter is from the DW_AT_member attribute of the parent | |
8029 | DW_TAG_subroutine_type DIE. */ | |
8030 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
8031 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 8032 | #endif |
a3f97cbb JW |
8033 | |
8034 | /* Make our first pass over the list of formal parameter types and output a | |
8035 | DW_TAG_formal_parameter DIE for each one. */ | |
8036 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
8037 | { | |
a94dbf2c JM |
8038 | register dw_die_ref parm_die; |
8039 | ||
a3f97cbb JW |
8040 | formal_type = TREE_VALUE (link); |
8041 | if (formal_type == void_type_node) | |
8042 | break; | |
8043 | ||
8044 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c JM |
8045 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
8046 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE | |
8047 | && link == first_parm_type) | |
8048 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
8049 | } |
8050 | ||
8051 | /* If this function type has an ellipsis, add a | |
8052 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
8053 | if (formal_type != void_type_node) | |
8054 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
8055 | ||
8056 | /* Make our second (and final) pass over the list of formal parameter types | |
8057 | and output DIEs to represent those types (as necessary). */ | |
8058 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
8059 | link; | |
8060 | link = TREE_CHAIN (link)) | |
8061 | { | |
8062 | formal_type = TREE_VALUE (link); | |
8063 | if (formal_type == void_type_node) | |
8064 | break; | |
8065 | ||
b50c02f9 | 8066 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
8067 | } |
8068 | } | |
8069 | ||
10a11b75 JM |
8070 | /* We want to generate the DIE for TYPE so that we can generate the |
8071 | die for MEMBER, which has been defined; we will need to refer back | |
8072 | to the member declaration nested within TYPE. If we're trying to | |
8073 | generate minimal debug info for TYPE, processing TYPE won't do the | |
8074 | trick; we need to attach the member declaration by hand. */ | |
8075 | ||
8076 | static void | |
8077 | gen_type_die_for_member (type, member, context_die) | |
8078 | tree type, member; | |
8079 | dw_die_ref context_die; | |
8080 | { | |
8081 | gen_type_die (type, context_die); | |
8082 | ||
8083 | /* If we're trying to avoid duplicate debug info, we may not have | |
8084 | emitted the member decl for this function. Emit it now. */ | |
8085 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
8086 | && ! lookup_decl_die (member)) | |
8087 | { | |
8088 | if (decl_ultimate_origin (member)) | |
8089 | abort (); | |
8090 | ||
8091 | push_decl_scope (type); | |
8092 | if (TREE_CODE (member) == FUNCTION_DECL) | |
8093 | gen_subprogram_die (member, lookup_type_die (type)); | |
8094 | else | |
8095 | gen_variable_die (member, lookup_type_die (type)); | |
8096 | pop_decl_scope (); | |
8097 | } | |
8098 | } | |
8099 | ||
8100 | /* Generate the DWARF2 info for the "abstract" instance | |
8101 | of a function which we may later generate inlined and/or | |
8102 | out-of-line instances of. */ | |
8103 | ||
8104 | static void | |
8105 | gen_abstract_function (decl) | |
8106 | tree decl; | |
8107 | { | |
8108 | register dw_die_ref old_die = lookup_decl_die (decl); | |
777ad4c2 | 8109 | tree save_fn; |
10a11b75 JM |
8110 | |
8111 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) | |
8112 | /* We've already generated the abstract instance. */ | |
8113 | return; | |
8114 | ||
777ad4c2 JM |
8115 | save_fn = current_function_decl; |
8116 | current_function_decl = decl; | |
8117 | ||
10a11b75 JM |
8118 | set_decl_abstract_flags (decl, 1); |
8119 | dwarf2out_decl (decl); | |
8120 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
8121 | |
8122 | current_function_decl = save_fn; | |
10a11b75 JM |
8123 | } |
8124 | ||
a3f97cbb JW |
8125 | /* Generate a DIE to represent a declared function (either file-scope or |
8126 | block-local). */ | |
71dfc51f | 8127 | |
a3f97cbb JW |
8128 | static void |
8129 | gen_subprogram_die (decl, context_die) | |
8130 | register tree decl; | |
8131 | register dw_die_ref context_die; | |
8132 | { | |
8133 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
8134 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 8135 | register dw_die_ref subr_die; |
b1ccbc24 | 8136 | register rtx fp_reg; |
a3f97cbb JW |
8137 | register tree fn_arg_types; |
8138 | register tree outer_scope; | |
a94dbf2c | 8139 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
8140 | register int declaration = (current_function_decl != decl |
8141 | || class_scope_p (context_die)); | |
a3f97cbb | 8142 | |
10a11b75 JM |
8143 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
8144 | be true, if we started to generate the abstract instance of an inline, | |
8145 | decided to output its containing class, and proceeded to emit the | |
8146 | declaration of the inline from the member list for the class. In that | |
8147 | case, `declaration' takes priority; we'll get back to the abstract | |
8148 | instance when we're done with the class. */ | |
8149 | ||
1cfdcc15 JM |
8150 | /* The class-scope declaration DIE must be the primary DIE. */ |
8151 | if (origin && declaration && class_scope_p (context_die)) | |
8152 | { | |
8153 | origin = NULL; | |
8154 | if (old_die) | |
8155 | abort (); | |
8156 | } | |
8157 | ||
a3f97cbb JW |
8158 | if (origin != NULL) |
8159 | { | |
777ad4c2 | 8160 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
8161 | abort (); |
8162 | ||
4b674448 | 8163 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
8164 | add_abstract_origin_attribute (subr_die, origin); |
8165 | } | |
4401bf24 JL |
8166 | else if (old_die && DECL_ABSTRACT (decl) |
8167 | && get_AT_unsigned (old_die, DW_AT_inline)) | |
8168 | { | |
8169 | /* This must be a redefinition of an extern inline function. | |
8170 | We can just reuse the old die here. */ | |
8171 | subr_die = old_die; | |
8172 | ||
8173 | /* Clear out the inlined attribute and parm types. */ | |
8174 | remove_AT (subr_die, DW_AT_inline); | |
8175 | remove_children (subr_die); | |
8176 | } | |
bdb669cb JM |
8177 | else if (old_die) |
8178 | { | |
4b674448 JM |
8179 | register unsigned file_index |
8180 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
a94dbf2c | 8181 | |
3a88cbd1 | 8182 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) |
b75ab88b NC |
8183 | { |
8184 | /* ??? This can happen if there is a bug in the program, for | |
8185 | instance, if it has duplicate function definitions. Ideally, | |
8186 | we should detect this case and ignore it. For now, if we have | |
8187 | already reported an error, any error at all, then assume that | |
8188 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
8189 | if (errorcount) |
8190 | return; | |
8191 | abort (); | |
8192 | } | |
4b674448 JM |
8193 | |
8194 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
8195 | maybe use the old DIE. We always want the DIE for this function |
8196 | that has the *_pc attributes to be under comp_unit_die so the | |
8197 | debugger can find it. For inlines, that is the concrete instance, | |
8198 | so we can use the old DIE here. For non-inline methods, we want a | |
8199 | specification DIE at toplevel, so we need a new DIE. For local | |
a96c67ec | 8200 | class methods, this doesn't apply; we just use the old DIE. */ |
a94dbf2c JM |
8201 | if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die |
8202 | || context_die == NULL) | |
a96c67ec JM |
8203 | && (DECL_ARTIFICIAL (decl) |
8204 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
8205 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
8206 | == (unsigned)DECL_SOURCE_LINE (decl))))) | |
bdb669cb | 8207 | { |
4b674448 JM |
8208 | subr_die = old_die; |
8209 | ||
8210 | /* Clear out the declaration attribute and the parm types. */ | |
8211 | remove_AT (subr_die, DW_AT_declaration); | |
8212 | remove_children (subr_die); | |
8213 | } | |
8214 | else | |
8215 | { | |
8216 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
8217 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
8218 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8219 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
8220 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
2618f955 | 8221 | != (unsigned)DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
8222 | add_AT_unsigned |
8223 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8224 | } | |
8225 | } | |
a3f97cbb JW |
8226 | else |
8227 | { | |
777ad4c2 | 8228 | subr_die = new_die (DW_TAG_subprogram, context_die); |
4edb7b60 | 8229 | |
273dbe67 JM |
8230 | if (TREE_PUBLIC (decl)) |
8231 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 8232 | |
a3f97cbb | 8233 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
8234 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8235 | { | |
8236 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 8237 | |
4927276d JM |
8238 | add_prototyped_attribute (subr_die, type); |
8239 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
8240 | } | |
71dfc51f | 8241 | |
a3f97cbb | 8242 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
8243 | if (DECL_ARTIFICIAL (decl)) |
8244 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
8245 | if (TREE_PROTECTED (decl)) |
8246 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
8247 | else if (TREE_PRIVATE (decl)) | |
8248 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8249 | } |
4edb7b60 | 8250 | |
a94dbf2c JM |
8251 | if (declaration) |
8252 | { | |
777ad4c2 JM |
8253 | if (! origin) |
8254 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
a94dbf2c JM |
8255 | |
8256 | /* The first time we see a member function, it is in the context of | |
8257 | the class to which it belongs. We make sure of this by emitting | |
8258 | the class first. The next time is the definition, which is | |
8259 | handled above. The two may come from the same source text. */ | |
777ad4c2 | 8260 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) |
a94dbf2c JM |
8261 | equate_decl_number_to_die (decl, subr_die); |
8262 | } | |
8263 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 8264 | { |
10a11b75 | 8265 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 8266 | { |
10a11b75 JM |
8267 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
8268 | inline functions, but not for extern inline functions. | |
8269 | We can't get this completely correct because information | |
8270 | about whether the function was declared inline is not | |
8271 | saved anywhere. */ | |
8272 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
8273 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
8274 | else | |
10a11b75 | 8275 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 8276 | } |
61b32c02 | 8277 | else |
10a11b75 | 8278 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 8279 | |
a3f97cbb JW |
8280 | equate_decl_number_to_die (decl, subr_die); |
8281 | } | |
8282 | else if (!DECL_EXTERNAL (decl)) | |
8283 | { | |
71dfc51f | 8284 | if (origin == NULL_TREE) |
ba7b35df | 8285 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 8286 | |
5c90448c JM |
8287 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
8288 | current_funcdef_number); | |
7d4440be | 8289 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
8290 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
8291 | current_funcdef_number); | |
a3f97cbb JW |
8292 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
8293 | ||
d291dd49 JM |
8294 | add_pubname (decl, subr_die); |
8295 | add_arange (decl, subr_die); | |
8296 | ||
a3f97cbb | 8297 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
8298 | /* Add a reference to the FDE for this routine. */ |
8299 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
8300 | #endif | |
8301 | ||
810429b7 JM |
8302 | /* Define the "frame base" location for this routine. We use the |
8303 | frame pointer or stack pointer registers, since the RTL for local | |
8304 | variables is relative to one of them. */ | |
b1ccbc24 RK |
8305 | fp_reg |
8306 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
8307 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 8308 | |
ef76d03b JW |
8309 | #if 0 |
8310 | /* ??? This fails for nested inline functions, because context_display | |
8311 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 8312 | if (current_function_needs_context) |
ef76d03b JW |
8313 | add_AT_location_description (subr_die, DW_AT_static_link, |
8314 | lookup_static_chain (decl)); | |
8315 | #endif | |
a3f97cbb JW |
8316 | } |
8317 | ||
8318 | /* Now output descriptions of the arguments for this function. This gets | |
8319 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list | |
8320 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing | |
8321 | `...' at the end of the formal parameter list. In order to find out if | |
8322 | there was a trailing ellipsis or not, we must instead look at the type | |
8323 | associated with the FUNCTION_DECL. This will be a node of type | |
8324 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
8325 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be | |
8326 | an ellipsis at the end. */ | |
71dfc51f | 8327 | |
a3f97cbb JW |
8328 | /* In the case where we are describing a mere function declaration, all we |
8329 | need to do here (and all we *can* do here) is to describe the *types* of | |
8330 | its formal parameters. */ | |
4927276d | 8331 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 8332 | ; |
4edb7b60 JM |
8333 | else if (declaration) |
8334 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
a3f97cbb JW |
8335 | else |
8336 | { | |
8337 | /* Generate DIEs to represent all known formal parameters */ | |
8338 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
8339 | register tree parm; | |
8340 | ||
8341 | /* When generating DIEs, generate the unspecified_parameters DIE | |
8342 | instead if we come across the arg "__builtin_va_alist" */ | |
8343 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
8344 | if (TREE_CODE (parm) == PARM_DECL) |
8345 | { | |
db3cf6fb MS |
8346 | if (DECL_NAME (parm) |
8347 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
8348 | "__builtin_va_alist")) | |
71dfc51f RK |
8349 | gen_unspecified_parameters_die (parm, subr_die); |
8350 | else | |
8351 | gen_decl_die (parm, subr_die); | |
8352 | } | |
a3f97cbb JW |
8353 | |
8354 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
8355 | There are 2 more cases to do this for: 1) the ansi ... declaration - | |
8356 | this is detectable when the end of the arg list is not a | |
8357 | void_type_node 2) an unprototyped function declaration (not a | |
8358 | definition). This just means that we have no info about the | |
8359 | parameters at all. */ | |
8360 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 8361 | if (fn_arg_types != NULL) |
a3f97cbb JW |
8362 | { |
8363 | /* this is the prototyped case, check for ... */ | |
8364 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 8365 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 8366 | } |
71dfc51f RK |
8367 | else if (DECL_INITIAL (decl) == NULL_TREE) |
8368 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
8369 | } |
8370 | ||
8371 | /* Output Dwarf info for all of the stuff within the body of the function | |
8372 | (if it has one - it may be just a declaration). */ | |
8373 | outer_scope = DECL_INITIAL (decl); | |
8374 | ||
d7248bff JM |
8375 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
8376 | node created to represent a function. This outermost BLOCK actually | |
8377 | represents the outermost binding contour for the function, i.e. the | |
8378 | contour in which the function's formal parameters and labels get | |
8379 | declared. Curiously, it appears that the front end doesn't actually | |
8380 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
8381 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
8382 | list for the function instead.) The BLOCK_VARS list for the | |
8383 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
8384 | the function however, and we output DWARF info for those in | |
8385 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
8386 | node representing the function's outermost pair of curly braces, and | |
8387 | any blocks used for the base and member initializers of a C++ | |
8388 | constructor function. */ | |
4edb7b60 | 8389 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
8390 | { |
8391 | current_function_has_inlines = 0; | |
8392 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 8393 | |
ce61cc73 | 8394 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
8395 | if (current_function_has_inlines) |
8396 | { | |
8397 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
8398 | if (! comp_unit_has_inlines) | |
8399 | { | |
8400 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
8401 | comp_unit_has_inlines = 1; | |
8402 | } | |
8403 | } | |
8404 | #endif | |
8405 | } | |
a3f97cbb JW |
8406 | } |
8407 | ||
8408 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 8409 | |
a3f97cbb JW |
8410 | static void |
8411 | gen_variable_die (decl, context_die) | |
8412 | register tree decl; | |
8413 | register dw_die_ref context_die; | |
8414 | { | |
8415 | register tree origin = decl_ultimate_origin (decl); | |
8416 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 8417 | |
bdb669cb | 8418 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
8419 | int declaration = (DECL_EXTERNAL (decl) |
8420 | || class_scope_p (context_die)); | |
4edb7b60 | 8421 | |
a3f97cbb | 8422 | if (origin != NULL) |
71dfc51f | 8423 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
8424 | /* Loop unrolling can create multiple blocks that refer to the same |
8425 | static variable, so we must test for the DW_AT_declaration flag. */ | |
8426 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
8427 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
8428 | sharing them. */ | |
8429 | else if (old_die && TREE_STATIC (decl) | |
8430 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 8431 | { |
e689ae67 | 8432 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
8433 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
8434 | if (DECL_NAME (decl)) | |
8435 | { | |
8436 | register unsigned file_index | |
8437 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 8438 | |
bdb669cb JM |
8439 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
8440 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 8441 | |
bdb669cb | 8442 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
2618f955 | 8443 | != (unsigned)DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
8444 | |
8445 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
8446 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
8447 | } |
8448 | } | |
a3f97cbb JW |
8449 | else |
8450 | { | |
8451 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
8452 | add_type_attribute (var_die, TREE_TYPE (decl), |
8453 | TREE_READONLY (decl), | |
8454 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 8455 | |
273dbe67 JM |
8456 | if (TREE_PUBLIC (decl)) |
8457 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 8458 | |
273dbe67 JM |
8459 | if (DECL_ARTIFICIAL (decl)) |
8460 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 8461 | |
a94dbf2c JM |
8462 | if (TREE_PROTECTED (decl)) |
8463 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8464 | |
a94dbf2c JM |
8465 | else if (TREE_PRIVATE (decl)) |
8466 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 8467 | } |
4edb7b60 JM |
8468 | |
8469 | if (declaration) | |
8470 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
8471 | ||
9765e357 | 8472 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
8473 | equate_decl_number_to_die (decl, var_die); |
8474 | ||
8475 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
8476 | { |
8477 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 8478 | add_pubname (decl, var_die); |
a3f97cbb JW |
8479 | } |
8480 | } | |
8481 | ||
8482 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 8483 | |
a3f97cbb JW |
8484 | static void |
8485 | gen_label_die (decl, context_die) | |
8486 | register tree decl; | |
8487 | register dw_die_ref context_die; | |
8488 | { | |
8489 | register tree origin = decl_ultimate_origin (decl); | |
8490 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
8491 | register rtx insn; | |
8492 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5c90448c | 8493 | char label2[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8494 | |
a3f97cbb | 8495 | if (origin != NULL) |
71dfc51f | 8496 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 8497 | else |
71dfc51f RK |
8498 | add_name_and_src_coords_attributes (lbl_die, decl); |
8499 | ||
a3f97cbb | 8500 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 8501 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
8502 | else |
8503 | { | |
8504 | insn = DECL_RTL (decl); | |
088e7160 NC |
8505 | |
8506 | /* Deleted labels are programmer specified labels which have been | |
8507 | eliminated because of various optimisations. We still emit them | |
8508 | here so that it is possible to put breakpoints on them. */ | |
8509 | if (GET_CODE (insn) == CODE_LABEL | |
8510 | || ((GET_CODE (insn) == NOTE | |
8511 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb JW |
8512 | { |
8513 | /* When optimization is enabled (via -O) some parts of the compiler | |
8514 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
8515 | represent source-level labels which were explicitly declared by | |
8516 | the user. This really shouldn't be happening though, so catch | |
8517 | it if it ever does happen. */ | |
8518 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
8519 | abort (); |
8520 | ||
5c90448c JM |
8521 | sprintf (label2, INSN_LABEL_FMT, current_funcdef_number); |
8522 | ASM_GENERATE_INTERNAL_LABEL (label, label2, | |
8523 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
8524 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
8525 | } | |
8526 | } | |
8527 | } | |
8528 | ||
8529 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 8530 | |
a3f97cbb | 8531 | static void |
d7248bff | 8532 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
8533 | register tree stmt; |
8534 | register dw_die_ref context_die; | |
d7248bff | 8535 | int depth; |
a3f97cbb JW |
8536 | { |
8537 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
8538 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
8539 | |
8540 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 8541 | { |
5c90448c | 8542 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 8543 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 8544 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
18c038b9 MM |
8545 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
8546 | BLOCK_NUMBER (stmt)); | |
a3f97cbb JW |
8547 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
8548 | } | |
71dfc51f | 8549 | |
d7248bff | 8550 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
8551 | } |
8552 | ||
8553 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 8554 | |
a3f97cbb | 8555 | static void |
d7248bff | 8556 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
8557 | register tree stmt; |
8558 | register dw_die_ref context_die; | |
d7248bff | 8559 | int depth; |
a3f97cbb | 8560 | { |
71dfc51f | 8561 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 8562 | { |
71dfc51f RK |
8563 | register dw_die_ref subr_die |
8564 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 8565 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 8566 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 8567 | |
10a11b75 JM |
8568 | /* Emit info for the abstract instance first, if we haven't yet. */ |
8569 | gen_abstract_function (decl); | |
8570 | ||
ab72d377 | 8571 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 8572 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 8573 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 8574 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
8575 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
8576 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 8577 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 8578 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 8579 | current_function_has_inlines = 1; |
a3f97cbb | 8580 | } |
a3f97cbb JW |
8581 | } |
8582 | ||
8583 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 8584 | |
a3f97cbb JW |
8585 | static void |
8586 | gen_field_die (decl, context_die) | |
8587 | register tree decl; | |
8588 | register dw_die_ref context_die; | |
8589 | { | |
8590 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 8591 | |
a3f97cbb | 8592 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
8593 | add_type_attribute (decl_die, member_declared_type (decl), |
8594 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
8595 | context_die); | |
71dfc51f | 8596 | |
a3f97cbb JW |
8597 | /* If this is a bit field... */ |
8598 | if (DECL_BIT_FIELD_TYPE (decl)) | |
8599 | { | |
8600 | add_byte_size_attribute (decl_die, decl); | |
8601 | add_bit_size_attribute (decl_die, decl); | |
8602 | add_bit_offset_attribute (decl_die, decl); | |
8603 | } | |
71dfc51f | 8604 | |
a94dbf2c JM |
8605 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
8606 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 8607 | |
273dbe67 JM |
8608 | if (DECL_ARTIFICIAL (decl)) |
8609 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 8610 | |
a94dbf2c JM |
8611 | if (TREE_PROTECTED (decl)) |
8612 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 8613 | |
a94dbf2c JM |
8614 | else if (TREE_PRIVATE (decl)) |
8615 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
8616 | } |
8617 | ||
ab72d377 JM |
8618 | #if 0 |
8619 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
8620 | Use modified_type_die instead. | |
a3f97cbb JW |
8621 | We keep this code here just in case these types of DIEs may be needed to |
8622 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8623 | static void | |
8624 | gen_pointer_type_die (type, context_die) | |
8625 | register tree type; | |
8626 | register dw_die_ref context_die; | |
8627 | { | |
71dfc51f RK |
8628 | register dw_die_ref ptr_die |
8629 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
8630 | ||
a3f97cbb | 8631 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8632 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8633 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
8634 | } |
8635 | ||
ab72d377 JM |
8636 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
8637 | Use modified_type_die instead. | |
a3f97cbb JW |
8638 | We keep this code here just in case these types of DIEs may be needed to |
8639 | represent certain things in other languages (e.g. Pascal) someday. */ | |
8640 | static void | |
8641 | gen_reference_type_die (type, context_die) | |
8642 | register tree type; | |
8643 | register dw_die_ref context_die; | |
8644 | { | |
71dfc51f RK |
8645 | register dw_die_ref ref_die |
8646 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
8647 | ||
a3f97cbb | 8648 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 8649 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 8650 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 8651 | } |
ab72d377 | 8652 | #endif |
a3f97cbb JW |
8653 | |
8654 | /* Generate a DIE for a pointer to a member type. */ | |
8655 | static void | |
8656 | gen_ptr_to_mbr_type_die (type, context_die) | |
8657 | register tree type; | |
8658 | register dw_die_ref context_die; | |
8659 | { | |
71dfc51f RK |
8660 | register dw_die_ref ptr_die |
8661 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
8662 | ||
a3f97cbb | 8663 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8664 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 8665 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
8666 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
8667 | } | |
8668 | ||
8669 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 8670 | |
a96c67ec JM |
8671 | static dw_die_ref |
8672 | gen_compile_unit_die (filename) | |
8673 | register const char *filename; | |
a3f97cbb | 8674 | { |
a96c67ec | 8675 | register dw_die_ref die; |
a3f97cbb | 8676 | char producer[250]; |
a3f97cbb | 8677 | char *wd = getpwd (); |
a96c67ec | 8678 | int language; |
a3f97cbb | 8679 | |
a96c67ec JM |
8680 | die = new_die (DW_TAG_compile_unit, NULL); |
8681 | add_name_attribute (die, filename); | |
bdb669cb | 8682 | |
a96c67ec JM |
8683 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
8684 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
8685 | |
8686 | sprintf (producer, "%s %s", language_string, version_string); | |
8687 | ||
8688 | #ifdef MIPS_DEBUGGING_INFO | |
8689 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
8690 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
8691 | not appear in the producer string, the debugger reaches the conclusion | |
8692 | that the object file is stripped and has no debugging information. | |
8693 | To get the MIPS/SGI debugger to believe that there is debugging | |
8694 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
8695 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8696 | strcat (producer, " -g"); | |
a3f97cbb JW |
8697 | #endif |
8698 | ||
a96c67ec | 8699 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 8700 | |
a3f97cbb | 8701 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 8702 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 8703 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 8704 | language = DW_LANG_Ada83; |
a9d38797 | 8705 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 8706 | language = DW_LANG_Fortran77; |
bc28c45b | 8707 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 8708 | language = DW_LANG_Pascal83; |
a3f97cbb | 8709 | else if (flag_traditional) |
a96c67ec | 8710 | language = DW_LANG_C; |
a3f97cbb | 8711 | else |
a96c67ec | 8712 | language = DW_LANG_C89; |
a9d38797 | 8713 | |
a96c67ec JM |
8714 | add_AT_unsigned (die, DW_AT_language, language); |
8715 | ||
8716 | return die; | |
a3f97cbb JW |
8717 | } |
8718 | ||
8719 | /* Generate a DIE for a string type. */ | |
71dfc51f | 8720 | |
a3f97cbb JW |
8721 | static void |
8722 | gen_string_type_die (type, context_die) | |
8723 | register tree type; | |
8724 | register dw_die_ref context_die; | |
8725 | { | |
71dfc51f RK |
8726 | register dw_die_ref type_die |
8727 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
8728 | ||
bdb669cb | 8729 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
8730 | |
8731 | /* Fudge the string length attribute for now. */ | |
71dfc51f | 8732 | |
a3f97cbb | 8733 | /* TODO: add string length info. |
71dfc51f | 8734 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
8735 | bound_representation (upper_bound, 0, 'u'); */ |
8736 | } | |
8737 | ||
61b32c02 | 8738 | /* Generate the DIE for a base class. */ |
71dfc51f | 8739 | |
61b32c02 JM |
8740 | static void |
8741 | gen_inheritance_die (binfo, context_die) | |
8742 | register tree binfo; | |
8743 | register dw_die_ref context_die; | |
8744 | { | |
8745 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 8746 | |
61b32c02 JM |
8747 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
8748 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 8749 | |
61b32c02 JM |
8750 | if (TREE_VIA_VIRTUAL (binfo)) |
8751 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
8752 | if (TREE_VIA_PUBLIC (binfo)) | |
8753 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
8754 | else if (TREE_VIA_PROTECTED (binfo)) | |
8755 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
8756 | } | |
8757 | ||
956d6950 | 8758 | /* Generate a DIE for a class member. */ |
71dfc51f | 8759 | |
a3f97cbb JW |
8760 | static void |
8761 | gen_member_die (type, context_die) | |
8762 | register tree type; | |
8763 | register dw_die_ref context_die; | |
8764 | { | |
61b32c02 | 8765 | register tree member; |
10a11b75 | 8766 | dw_die_ref child; |
71dfc51f | 8767 | |
a3f97cbb JW |
8768 | /* If this is not an incomplete type, output descriptions of each of its |
8769 | members. Note that as we output the DIEs necessary to represent the | |
8770 | members of this record or union type, we will also be trying to output | |
8771 | DIEs to represent the *types* of those members. However the `type' | |
8772 | function (above) will specifically avoid generating type DIEs for member | |
8773 | types *within* the list of member DIEs for this (containing) type execpt | |
8774 | for those types (of members) which are explicitly marked as also being | |
8775 | members of this (containing) type themselves. The g++ front- end can | |
8776 | force any given type to be treated as a member of some other | |
8777 | (containing) type by setting the TYPE_CONTEXT of the given (member) type | |
8778 | to point to the TREE node representing the appropriate (containing) | |
8779 | type. */ | |
8780 | ||
61b32c02 JM |
8781 | /* First output info about the base classes. */ |
8782 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 8783 | { |
61b32c02 JM |
8784 | register tree bases = TYPE_BINFO_BASETYPES (type); |
8785 | register int n_bases = TREE_VEC_LENGTH (bases); | |
8786 | register int i; | |
8787 | ||
8788 | for (i = 0; i < n_bases; i++) | |
8789 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
8790 | } |
8791 | ||
61b32c02 JM |
8792 | /* Now output info about the data members and type members. */ |
8793 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
8794 | { |
8795 | /* If we thought we were generating minimal debug info for TYPE | |
8796 | and then changed our minds, some of the member declarations | |
8797 | may have already been defined. Don't define them again, but | |
8798 | do put them in the right order. */ | |
8799 | ||
8800 | child = lookup_decl_die (member); | |
8801 | if (child) | |
8802 | splice_child_die (context_die, child); | |
8803 | else | |
8804 | gen_decl_die (member, context_die); | |
8805 | } | |
61b32c02 | 8806 | |
a3f97cbb | 8807 | /* Now output info about the function members (if any). */ |
61b32c02 | 8808 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 JM |
8809 | { |
8810 | child = lookup_decl_die (member); | |
8811 | if (child) | |
8812 | splice_child_die (context_die, child); | |
8813 | else | |
8814 | gen_decl_die (member, context_die); | |
8815 | } | |
a3f97cbb JW |
8816 | } |
8817 | ||
10a11b75 JM |
8818 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
8819 | is set, we pretend that the type was never defined, so we only get the | |
8820 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 8821 | |
a3f97cbb | 8822 | static void |
273dbe67 | 8823 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 8824 | register tree type; |
a3f97cbb JW |
8825 | register dw_die_ref context_die; |
8826 | { | |
273dbe67 | 8827 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
8828 | register dw_die_ref scope_die = 0; |
8829 | register int nested = 0; | |
10a11b75 | 8830 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
8831 | && (! TYPE_STUB_DECL (type) |
8832 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 8833 | |
10a11b75 | 8834 | if (type_die && ! complete) |
273dbe67 | 8835 | return; |
a082c85a | 8836 | |
71dfc51f | 8837 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 8838 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
8839 | nested = 1; |
8840 | ||
a94dbf2c | 8841 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
8842 | |
8843 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 8844 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 8845 | { |
273dbe67 | 8846 | register dw_die_ref old_die = type_die; |
71dfc51f | 8847 | |
a3f97cbb JW |
8848 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
8849 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 8850 | scope_die); |
a3f97cbb JW |
8851 | equate_type_number_to_die (type, type_die); |
8852 | add_name_attribute (type_die, type_tag (type)); | |
273dbe67 JM |
8853 | if (old_die) |
8854 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
a3f97cbb | 8855 | } |
4b674448 | 8856 | else |
273dbe67 | 8857 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
8858 | |
8859 | /* If this type has been completed, then give it a byte_size attribute and | |
8860 | then give a list of members. */ | |
2081603c | 8861 | if (complete) |
a3f97cbb JW |
8862 | { |
8863 | /* Prevent infinite recursion in cases where the type of some member of | |
8864 | this type is expressed in terms of this type itself. */ | |
8865 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 8866 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 8867 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 8868 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 8869 | |
ef76d03b JW |
8870 | /* If the first reference to this type was as the return type of an |
8871 | inline function, then it may not have a parent. Fix this now. */ | |
8872 | if (type_die->die_parent == NULL) | |
8873 | add_child_die (scope_die, type_die); | |
8874 | ||
273dbe67 JM |
8875 | push_decl_scope (type); |
8876 | gen_member_die (type, type_die); | |
8877 | pop_decl_scope (); | |
71dfc51f | 8878 | |
a94dbf2c JM |
8879 | /* GNU extension: Record what type our vtable lives in. */ |
8880 | if (TYPE_VFIELD (type)) | |
8881 | { | |
8882 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 8883 | |
de6e505e JM |
8884 | gen_type_die (vtype, context_die); |
8885 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
8886 | lookup_type_die (vtype)); | |
a94dbf2c | 8887 | } |
a3f97cbb | 8888 | } |
4b674448 | 8889 | else |
8a8c3656 JM |
8890 | { |
8891 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 8892 | |
9765e357 | 8893 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 8894 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 8895 | add_incomplete_type (type); |
8a8c3656 | 8896 | } |
a3f97cbb JW |
8897 | } |
8898 | ||
8899 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 8900 | |
a3f97cbb JW |
8901 | static void |
8902 | gen_subroutine_type_die (type, context_die) | |
8903 | register tree type; | |
8904 | register dw_die_ref context_die; | |
8905 | { | |
8906 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
8907 | register dw_die_ref subr_die |
8908 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
8909 | ||
a3f97cbb JW |
8910 | equate_type_number_to_die (type, subr_die); |
8911 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 8912 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 8913 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
8914 | } |
8915 | ||
8916 | /* Generate a DIE for a type definition */ | |
71dfc51f | 8917 | |
a3f97cbb JW |
8918 | static void |
8919 | gen_typedef_die (decl, context_die) | |
8920 | register tree decl; | |
8921 | register dw_die_ref context_die; | |
8922 | { | |
a3f97cbb | 8923 | register dw_die_ref type_die; |
a94dbf2c JM |
8924 | register tree origin; |
8925 | ||
8926 | if (TREE_ASM_WRITTEN (decl)) | |
8927 | return; | |
8928 | TREE_ASM_WRITTEN (decl) = 1; | |
8929 | ||
777ad4c2 | 8930 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 8931 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 8932 | if (origin != NULL) |
a94dbf2c | 8933 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
8934 | else |
8935 | { | |
a94dbf2c | 8936 | register tree type; |
a3f97cbb | 8937 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
8938 | if (DECL_ORIGINAL_TYPE (decl)) |
8939 | { | |
8940 | type = DECL_ORIGINAL_TYPE (decl); | |
8941 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
8942 | } | |
8943 | else | |
8944 | type = TREE_TYPE (decl); | |
8945 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
8946 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 8947 | } |
71dfc51f | 8948 | |
a3f97cbb | 8949 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 8950 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
8951 | } |
8952 | ||
8953 | /* Generate a type description DIE. */ | |
71dfc51f | 8954 | |
a3f97cbb JW |
8955 | static void |
8956 | gen_type_die (type, context_die) | |
8957 | register tree type; | |
8958 | register dw_die_ref context_die; | |
8959 | { | |
348bb3c7 JM |
8960 | int need_pop; |
8961 | ||
71dfc51f RK |
8962 | if (type == NULL_TREE || type == error_mark_node) |
8963 | return; | |
a3f97cbb | 8964 | |
38e01259 | 8965 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
8966 | this type (i.e. without any const or volatile qualifiers) so get the |
8967 | main variant (i.e. the unqualified version) of this type now. */ | |
8968 | type = type_main_variant (type); | |
8969 | ||
8970 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 8971 | return; |
a3f97cbb | 8972 | |
a94dbf2c JM |
8973 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
8974 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
8975 | { | |
8976 | TREE_ASM_WRITTEN (type) = 1; | |
8977 | gen_decl_die (TYPE_NAME (type), context_die); | |
8978 | return; | |
8979 | } | |
8980 | ||
a3f97cbb JW |
8981 | switch (TREE_CODE (type)) |
8982 | { | |
8983 | case ERROR_MARK: | |
8984 | break; | |
8985 | ||
8986 | case POINTER_TYPE: | |
8987 | case REFERENCE_TYPE: | |
956d6950 JL |
8988 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
8989 | ensures that the gen_type_die recursion will terminate even if the | |
8990 | type is recursive. Recursive types are possible in Ada. */ | |
8991 | /* ??? We could perhaps do this for all types before the switch | |
8992 | statement. */ | |
8993 | TREE_ASM_WRITTEN (type) = 1; | |
8994 | ||
a3f97cbb JW |
8995 | /* For these types, all that is required is that we output a DIE (or a |
8996 | set of DIEs) to represent the "basis" type. */ | |
8997 | gen_type_die (TREE_TYPE (type), context_die); | |
8998 | break; | |
8999 | ||
9000 | case OFFSET_TYPE: | |
71dfc51f RK |
9001 | /* This code is used for C++ pointer-to-data-member types. |
9002 | Output a description of the relevant class type. */ | |
a3f97cbb | 9003 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 9004 | |
a3f97cbb JW |
9005 | /* Output a description of the type of the object pointed to. */ |
9006 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 9007 | |
a3f97cbb JW |
9008 | /* Now output a DIE to represent this pointer-to-data-member type |
9009 | itself. */ | |
9010 | gen_ptr_to_mbr_type_die (type, context_die); | |
9011 | break; | |
9012 | ||
9013 | case SET_TYPE: | |
9014 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
9015 | gen_set_type_die (type, context_die); | |
9016 | break; | |
9017 | ||
9018 | case FILE_TYPE: | |
9019 | gen_type_die (TREE_TYPE (type), context_die); | |
9020 | abort (); /* No way to represent these in Dwarf yet! */ | |
9021 | break; | |
9022 | ||
9023 | case FUNCTION_TYPE: | |
9024 | /* Force out return type (in case it wasn't forced out already). */ | |
9025 | gen_type_die (TREE_TYPE (type), context_die); | |
9026 | gen_subroutine_type_die (type, context_die); | |
9027 | break; | |
9028 | ||
9029 | case METHOD_TYPE: | |
9030 | /* Force out return type (in case it wasn't forced out already). */ | |
9031 | gen_type_die (TREE_TYPE (type), context_die); | |
9032 | gen_subroutine_type_die (type, context_die); | |
9033 | break; | |
9034 | ||
9035 | case ARRAY_TYPE: | |
9036 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
9037 | { | |
9038 | gen_type_die (TREE_TYPE (type), context_die); | |
9039 | gen_string_type_die (type, context_die); | |
9040 | } | |
9041 | else | |
71dfc51f | 9042 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
9043 | break; |
9044 | ||
9045 | case ENUMERAL_TYPE: | |
9046 | case RECORD_TYPE: | |
9047 | case UNION_TYPE: | |
9048 | case QUAL_UNION_TYPE: | |
a082c85a | 9049 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
9050 | written out yet, writing it out will cover this one, too. |
9051 | This does not apply to instantiations of member class templates; | |
9052 | they need to be added to the containing class as they are | |
777ad4c2 | 9053 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
9054 | from multiple TUs, since we can't predict what set of template |
9055 | instantiations we'll get. */ | |
a082c85a | 9056 | if (TYPE_CONTEXT (type) |
5f2f160c | 9057 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 9058 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
9059 | { |
9060 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
9061 | ||
348bb3c7 | 9062 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
9063 | return; |
9064 | ||
9065 | /* If that failed, attach ourselves to the stub. */ | |
9066 | push_decl_scope (TYPE_CONTEXT (type)); | |
9067 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 9068 | need_pop = 1; |
a94dbf2c | 9069 | } |
348bb3c7 JM |
9070 | else |
9071 | need_pop = 0; | |
a94dbf2c JM |
9072 | |
9073 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 9074 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 9075 | else |
273dbe67 | 9076 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 9077 | |
348bb3c7 | 9078 | if (need_pop) |
a94dbf2c JM |
9079 | pop_decl_scope (); |
9080 | ||
4b674448 | 9081 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
9082 | it up if it is ever completed. gen_*_type_die will set it for us |
9083 | when appropriate. */ | |
9084 | return; | |
a3f97cbb JW |
9085 | |
9086 | case VOID_TYPE: | |
9087 | case INTEGER_TYPE: | |
9088 | case REAL_TYPE: | |
9089 | case COMPLEX_TYPE: | |
9090 | case BOOLEAN_TYPE: | |
9091 | case CHAR_TYPE: | |
9092 | /* No DIEs needed for fundamental types. */ | |
9093 | break; | |
9094 | ||
9095 | case LANG_TYPE: | |
9096 | /* No Dwarf representation currently defined. */ | |
9097 | break; | |
9098 | ||
9099 | default: | |
9100 | abort (); | |
9101 | } | |
9102 | ||
9103 | TREE_ASM_WRITTEN (type) = 1; | |
9104 | } | |
9105 | ||
9106 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 9107 | |
a3f97cbb JW |
9108 | static void |
9109 | gen_tagged_type_instantiation_die (type, context_die) | |
9110 | register tree type; | |
9111 | register dw_die_ref context_die; | |
9112 | { | |
71dfc51f RK |
9113 | if (type == NULL_TREE || type == error_mark_node) |
9114 | return; | |
a3f97cbb | 9115 | |
38e01259 | 9116 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
9117 | this type (i.e. without any const or volatile qualifiers) so make sure |
9118 | that we have the main variant (i.e. the unqualified version) of this | |
9119 | type now. */ | |
bbc6ae08 | 9120 | if (type != type_main_variant (type)) |
3a88cbd1 | 9121 | abort (); |
a3f97cbb | 9122 | |
203588e7 | 9123 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 NC |
9124 | an instance of an unresolved type. */ |
9125 | ||
a3f97cbb JW |
9126 | switch (TREE_CODE (type)) |
9127 | { | |
9128 | case ERROR_MARK: | |
9129 | break; | |
9130 | ||
9131 | case ENUMERAL_TYPE: | |
9132 | gen_inlined_enumeration_type_die (type, context_die); | |
9133 | break; | |
9134 | ||
9135 | case RECORD_TYPE: | |
9136 | gen_inlined_structure_type_die (type, context_die); | |
9137 | break; | |
9138 | ||
9139 | case UNION_TYPE: | |
9140 | case QUAL_UNION_TYPE: | |
9141 | gen_inlined_union_type_die (type, context_die); | |
9142 | break; | |
9143 | ||
9144 | default: | |
71dfc51f | 9145 | abort (); |
a3f97cbb JW |
9146 | } |
9147 | } | |
9148 | ||
9149 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
9150 | things which are local to the given block. */ | |
71dfc51f | 9151 | |
a3f97cbb | 9152 | static void |
d7248bff | 9153 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
9154 | register tree stmt; |
9155 | register dw_die_ref context_die; | |
d7248bff | 9156 | int depth; |
a3f97cbb JW |
9157 | { |
9158 | register int must_output_die = 0; | |
9159 | register tree origin; | |
9160 | register tree decl; | |
9161 | register enum tree_code origin_code; | |
9162 | ||
9163 | /* Ignore blocks never really used to make RTL. */ | |
9164 | ||
1e7f092a JM |
9165 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
9166 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 9167 | return; |
a3f97cbb JW |
9168 | |
9169 | /* Determine the "ultimate origin" of this block. This block may be an | |
9170 | inlined instance of an inlined instance of inline function, so we have | |
9171 | to trace all of the way back through the origin chain to find out what | |
9172 | sort of node actually served as the original seed for the creation of | |
9173 | the current block. */ | |
9174 | origin = block_ultimate_origin (stmt); | |
9175 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
9176 | ||
9177 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
9178 | block. */ | |
9179 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
9180 | /* The outer scopes for inlinings *must* always be represented. We |
9181 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
9182 | must_output_die = 1; | |
a3f97cbb JW |
9183 | else |
9184 | { | |
9185 | /* In the case where the current block represents an inlining of the | |
9186 | "body block" of an inline function, we must *NOT* output any DIE for | |
9187 | this block because we have already output a DIE to represent the | |
9188 | whole inlined function scope and the "body block" of any function | |
9189 | doesn't really represent a different scope according to ANSI C | |
9190 | rules. So we check here to make sure that this block does not | |
9191 | represent a "body block inlining" before trying to set the | |
9192 | `must_output_die' flag. */ | |
d7248bff | 9193 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
9194 | { |
9195 | /* Determine if this block directly contains any "significant" | |
9196 | local declarations which we will need to output DIEs for. */ | |
9197 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
9198 | /* We are not in terse mode so *any* local declaration counts |
9199 | as being a "significant" one. */ | |
9200 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 9201 | else |
71dfc51f RK |
9202 | /* We are in terse mode, so only local (nested) function |
9203 | definitions count as "significant" local declarations. */ | |
9204 | for (decl = BLOCK_VARS (stmt); | |
9205 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9206 | if (TREE_CODE (decl) == FUNCTION_DECL | |
9207 | && DECL_INITIAL (decl)) | |
a3f97cbb | 9208 | { |
71dfc51f RK |
9209 | must_output_die = 1; |
9210 | break; | |
a3f97cbb | 9211 | } |
a3f97cbb JW |
9212 | } |
9213 | } | |
9214 | ||
9215 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
9216 | DIE for any block which contains no significant local declarations at | |
9217 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
9218 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
9219 | that in terse mode, our definition of what constitutes a "significant" | |
9220 | local declaration gets restricted to include only inlined function | |
9221 | instances and local (nested) function definitions. */ | |
9222 | if (must_output_die) | |
9223 | { | |
9224 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 9225 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 9226 | else |
71dfc51f | 9227 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
9228 | } |
9229 | else | |
d7248bff | 9230 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
9231 | } |
9232 | ||
9233 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 9234 | all of its sub-blocks. */ |
71dfc51f | 9235 | |
a3f97cbb | 9236 | static void |
d7248bff | 9237 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
9238 | register tree stmt; |
9239 | register dw_die_ref context_die; | |
d7248bff | 9240 | int depth; |
a3f97cbb JW |
9241 | { |
9242 | register tree decl; | |
9243 | register tree subblocks; | |
71dfc51f | 9244 | |
a3f97cbb | 9245 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
9246 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
9247 | return; | |
9248 | ||
88dad228 JM |
9249 | /* Output the DIEs to represent all of the data objects and typedefs |
9250 | declared directly within this block but not within any nested | |
9251 | sub-blocks. Also, nested function and tag DIEs have been | |
9252 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
9253 | for (decl = BLOCK_VARS (stmt); |
9254 | decl != NULL; decl = TREE_CHAIN (decl)) | |
9255 | { | |
a94dbf2c JM |
9256 | register dw_die_ref die; |
9257 | ||
88dad228 | 9258 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 9259 | die = lookup_decl_die (decl); |
88dad228 | 9260 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
9261 | die = lookup_type_die (TREE_TYPE (decl)); |
9262 | else | |
9263 | die = NULL; | |
9264 | ||
71dfc51f | 9265 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 9266 | add_child_die (context_die, die); |
88dad228 JM |
9267 | else |
9268 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
9269 | } |
9270 | ||
9271 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
9272 | therein) of this block. */ | |
9273 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
9274 | subblocks != NULL; | |
9275 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 9276 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
9277 | } |
9278 | ||
a94dbf2c | 9279 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
9280 | |
9281 | static inline int | |
a94dbf2c JM |
9282 | is_redundant_typedef (decl) |
9283 | register tree decl; | |
9284 | { | |
9285 | if (TYPE_DECL_IS_STUB (decl)) | |
9286 | return 1; | |
71dfc51f | 9287 | |
a94dbf2c JM |
9288 | if (DECL_ARTIFICIAL (decl) |
9289 | && DECL_CONTEXT (decl) | |
9290 | && is_tagged_type (DECL_CONTEXT (decl)) | |
9291 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
9292 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
9293 | /* Also ignore the artificial member typedef for the class name. */ | |
9294 | return 1; | |
71dfc51f | 9295 | |
a94dbf2c JM |
9296 | return 0; |
9297 | } | |
9298 | ||
a3f97cbb | 9299 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 9300 | |
a3f97cbb JW |
9301 | static void |
9302 | gen_decl_die (decl, context_die) | |
9303 | register tree decl; | |
9304 | register dw_die_ref context_die; | |
9305 | { | |
9306 | register tree origin; | |
71dfc51f | 9307 | |
a3f97cbb | 9308 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 9309 | return; |
a3f97cbb | 9310 | |
fcd7f76b JM |
9311 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
9312 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 9313 | return; |
a3f97cbb | 9314 | |
a3f97cbb JW |
9315 | switch (TREE_CODE (decl)) |
9316 | { | |
9317 | case CONST_DECL: | |
9318 | /* The individual enumerators of an enum type get output when we output | |
9319 | the Dwarf representation of the relevant enum type itself. */ | |
9320 | break; | |
9321 | ||
9322 | case FUNCTION_DECL: | |
4edb7b60 JM |
9323 | /* Don't output any DIEs to represent mere function declarations, |
9324 | unless they are class members or explicit block externs. */ | |
9325 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 9326 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 9327 | break; |
bdb669cb | 9328 | |
1cfdcc15 JM |
9329 | /* If we're emitting an out-of-line copy of an inline function, |
9330 | emit info for the abstract instance and set up to refer to it. */ | |
9331 | if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) | |
9332 | && ! class_scope_p (context_die)) | |
9333 | { | |
9334 | gen_abstract_function (decl); | |
9335 | set_decl_origin_self (decl); | |
9336 | } | |
10a11b75 | 9337 | |
4927276d | 9338 | if (debug_info_level > DINFO_LEVEL_TERSE) |
a94dbf2c JM |
9339 | { |
9340 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
9341 | have described its return type. */ | |
9342 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
9343 | ||
2081603c JM |
9344 | /* And its virtual context. */ |
9345 | if (DECL_VINDEX (decl) != NULL_TREE) | |
9346 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
9347 | ||
a94dbf2c JM |
9348 | /* And its containing type. */ |
9349 | origin = decl_class_context (decl); | |
71dfc51f | 9350 | if (origin != NULL_TREE) |
10a11b75 | 9351 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 9352 | } |
a3f97cbb JW |
9353 | |
9354 | /* Now output a DIE to represent the function itself. */ | |
9355 | gen_subprogram_die (decl, context_die); | |
9356 | break; | |
9357 | ||
9358 | case TYPE_DECL: | |
9359 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 9360 | actual typedefs. */ |
a3f97cbb | 9361 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9362 | break; |
a3f97cbb | 9363 | |
5c90448c JM |
9364 | /* In the special case of a TYPE_DECL node representing the |
9365 | declaration of some type tag, if the given TYPE_DECL is marked as | |
a3f97cbb JW |
9366 | having been instantiated from some other (original) TYPE_DECL node |
9367 | (e.g. one which was generated within the original definition of an | |
9368 | inline function) we have to generate a special (abbreviated) | |
ef76d03b | 9369 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 9370 | DIE here. */ |
2081603c | 9371 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
9372 | { |
9373 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
9374 | break; | |
9375 | } | |
a3f97cbb | 9376 | |
a94dbf2c JM |
9377 | if (is_redundant_typedef (decl)) |
9378 | gen_type_die (TREE_TYPE (decl), context_die); | |
9379 | else | |
71dfc51f RK |
9380 | /* Output a DIE to represent the typedef itself. */ |
9381 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
9382 | break; |
9383 | ||
9384 | case LABEL_DECL: | |
9385 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 9386 | gen_label_die (decl, context_die); |
a3f97cbb JW |
9387 | break; |
9388 | ||
9389 | case VAR_DECL: | |
9390 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9391 | variable declarations or definitions. */ | |
9392 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9393 | break; |
a3f97cbb JW |
9394 | |
9395 | /* Output any DIEs that are needed to specify the type of this data | |
9396 | object. */ | |
9397 | gen_type_die (TREE_TYPE (decl), context_die); | |
9398 | ||
a94dbf2c JM |
9399 | /* And its containing type. */ |
9400 | origin = decl_class_context (decl); | |
71dfc51f | 9401 | if (origin != NULL_TREE) |
10a11b75 | 9402 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 9403 | |
a3f97cbb JW |
9404 | /* Now output the DIE to represent the data object itself. This gets |
9405 | complicated because of the possibility that the VAR_DECL really | |
9406 | represents an inlined instance of a formal parameter for an inline | |
9407 | function. */ | |
9408 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
9409 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
9410 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 9411 | else |
71dfc51f | 9412 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
9413 | break; |
9414 | ||
9415 | case FIELD_DECL: | |
a94dbf2c JM |
9416 | /* Ignore the nameless fields that are used to skip bits, but |
9417 | handle C++ anonymous unions. */ | |
71dfc51f RK |
9418 | if (DECL_NAME (decl) != NULL_TREE |
9419 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
9420 | { |
9421 | gen_type_die (member_declared_type (decl), context_die); | |
9422 | gen_field_die (decl, context_die); | |
9423 | } | |
9424 | break; | |
9425 | ||
9426 | case PARM_DECL: | |
9427 | gen_type_die (TREE_TYPE (decl), context_die); | |
9428 | gen_formal_parameter_die (decl, context_die); | |
9429 | break; | |
9430 | ||
348bb3c7 JM |
9431 | case NAMESPACE_DECL: |
9432 | /* Ignore for now. */ | |
9433 | break; | |
9434 | ||
a3f97cbb JW |
9435 | default: |
9436 | abort (); | |
9437 | } | |
a3f97cbb JW |
9438 | } |
9439 | \f | |
14a774a9 RK |
9440 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
9441 | ||
9442 | void | |
9443 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
9444 | const char *filename; |
9445 | const char *context_list; | |
14a774a9 RK |
9446 | { |
9447 | unsigned int file_index; | |
9448 | ||
9449 | if (filename != NULL) | |
9450 | { | |
9451 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
9452 | tree context_list_decl | |
9453 | = build_decl (LABEL_DECL, get_identifier (context_list), | |
9454 | void_type_node); | |
9455 | ||
9456 | TREE_PUBLIC (context_list_decl) = TRUE; | |
9457 | add_name_attribute (unit_die, context_list); | |
9458 | file_index = lookup_filename (filename); | |
9459 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); | |
9460 | add_pubname (context_list_decl, unit_die); | |
9461 | } | |
9462 | } | |
9463 | ||
71dfc51f RK |
9464 | /* Write the debugging output for DECL. */ |
9465 | ||
a3f97cbb | 9466 | void |
88dad228 | 9467 | dwarf2out_decl (decl) |
a3f97cbb | 9468 | register tree decl; |
a3f97cbb | 9469 | { |
88dad228 JM |
9470 | register dw_die_ref context_die = comp_unit_die; |
9471 | ||
a3f97cbb | 9472 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 9473 | return; |
a3f97cbb | 9474 | |
fcd7f76b | 9475 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 9476 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 9477 | return; |
a3f97cbb JW |
9478 | |
9479 | switch (TREE_CODE (decl)) | |
9480 | { | |
9481 | case FUNCTION_DECL: | |
9482 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a | |
9483 | builtin function. Explicit programmer-supplied declarations of | |
9484 | these same functions should NOT be ignored however. */ | |
9765e357 | 9485 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 9486 | return; |
a3f97cbb JW |
9487 | |
9488 | /* What we would really like to do here is to filter out all mere | |
9489 | file-scope declarations of file-scope functions which are never | |
9490 | referenced later within this translation unit (and keep all of ones | |
956d6950 | 9491 | that *are* referenced later on) but we aren't clairvoyant, so we have |
a3f97cbb JW |
9492 | no idea which functions will be referenced in the future (i.e. later |
9493 | on within the current translation unit). So here we just ignore all | |
9494 | file-scope function declarations which are not also definitions. If | |
956d6950 | 9495 | and when the debugger needs to know something about these functions, |
bbc6ae08 NC |
9496 | it will have to hunt around and find the DWARF information associated |
9497 | with the definition of the function. Note that we can't just check | |
a3f97cbb JW |
9498 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
9499 | definitions and which ones represent mere declarations. We have to | |
9500 | check `DECL_INITIAL' instead. That's because the C front-end | |
9501 | supports some weird semantics for "extern inline" function | |
9502 | definitions. These can get inlined within the current translation | |
9503 | unit (an thus, we need to generate DWARF info for their abstract | |
9504 | instances so that the DWARF info for the concrete inlined instances | |
9505 | can have something to refer to) but the compiler never generates any | |
9506 | out-of-lines instances of such things (despite the fact that they | |
9507 | *are* definitions). The important point is that the C front-end | |
9508 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 9509 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb JW |
9510 | plays some similar games for inline function definitions appearing |
9511 | within include files which also contain | |
9512 | `#pragma interface' pragmas. */ | |
9513 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 9514 | return; |
88dad228 | 9515 | |
9c6cd30e JM |
9516 | /* If we're a nested function, initially use a parent of NULL; if we're |
9517 | a plain function, this will be fixed up in decls_for_scope. If | |
9518 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 9519 | if (decl_function_context (decl)) |
9c6cd30e | 9520 | context_die = NULL; |
88dad228 | 9521 | |
a3f97cbb JW |
9522 | break; |
9523 | ||
9524 | case VAR_DECL: | |
9525 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object | |
9526 | declaration and if the declaration was never even referenced from | |
9527 | within this entire compilation unit. We suppress these DIEs in | |
9528 | order to save space in the .debug section (by eliminating entries | |
9529 | which are probably useless). Note that we must not suppress | |
9530 | block-local extern declarations (whether used or not) because that | |
9531 | would screw-up the debugger's name lookup mechanism and cause it to | |
9532 | miss things which really ought to be in scope at a given point. */ | |
9533 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 9534 | return; |
a3f97cbb JW |
9535 | |
9536 | /* If we are in terse mode, don't generate any DIEs to represent any | |
9537 | variable declarations or definitions. */ | |
9538 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 9539 | return; |
a3f97cbb JW |
9540 | break; |
9541 | ||
9542 | case TYPE_DECL: | |
57fb7689 JM |
9543 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
9544 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
9545 | return; | |
9546 | ||
a3f97cbb | 9547 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
9548 | normal built-in types for the language we are compiling. */ |
9549 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
9550 | { |
9551 | /* OK, we need to generate one for `bool' so GDB knows what type | |
9552 | comparisons have. */ | |
9553 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
9554 | == DW_LANG_C_plus_plus) | |
9555 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
9556 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 9557 | |
a94dbf2c JM |
9558 | return; |
9559 | } | |
a3f97cbb | 9560 | |
88dad228 | 9561 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 9562 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 9563 | return; |
88dad228 JM |
9564 | |
9565 | /* If we're a function-scope tag, initially use a parent of NULL; | |
9566 | this will be fixed up in decls_for_scope. */ | |
9567 | if (decl_function_context (decl)) | |
3f76745e | 9568 | context_die = NULL; |
88dad228 | 9569 | |
a3f97cbb JW |
9570 | break; |
9571 | ||
9572 | default: | |
9573 | return; | |
9574 | } | |
9575 | ||
88dad228 | 9576 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
9577 | } |
9578 | ||
9579 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
9580 | a lexical block. */ | |
71dfc51f | 9581 | |
a3f97cbb | 9582 | void |
9a666dda | 9583 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
9584 | register unsigned blocknum; |
9585 | { | |
a3f97cbb | 9586 | function_section (current_function_decl); |
5c90448c | 9587 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
9588 | } |
9589 | ||
9590 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
9591 | lexical block. */ | |
71dfc51f | 9592 | |
a3f97cbb | 9593 | void |
9a666dda | 9594 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
9595 | register unsigned blocknum; |
9596 | { | |
a3f97cbb | 9597 | function_section (current_function_decl); |
5c90448c | 9598 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
9599 | } |
9600 | ||
fcd7f76b JM |
9601 | /* We've decided not to emit any debugging information for BLOCK; make |
9602 | sure that we don't end up with orphans as a result. */ | |
9603 | ||
9604 | void | |
9605 | dwarf2out_ignore_block (block) | |
9606 | tree block; | |
9607 | { | |
9608 | tree decl; | |
9609 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
9610 | { | |
9611 | dw_die_ref die; | |
9612 | ||
9613 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
9614 | die = lookup_decl_die (decl); | |
9615 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) | |
9616 | die = lookup_type_die (TREE_TYPE (decl)); | |
9617 | else | |
9618 | die = NULL; | |
9619 | ||
9620 | /* Just give them a dummy value for parent so dwarf2out_finish | |
9621 | doesn't blow up; we would use add_child_die if we really | |
9622 | wanted to add them to comp_unit_die's children. */ | |
9623 | if (die && die->die_parent == 0) | |
9624 | die->die_parent = comp_unit_die; | |
9625 | } | |
9626 | } | |
9627 | ||
a3f97cbb JW |
9628 | /* Output a marker (i.e. a label) at a point in the assembly code which |
9629 | corresponds to a given source level label. */ | |
71dfc51f | 9630 | |
a3f97cbb | 9631 | void |
9a666dda | 9632 | dwarf2out_label (insn) |
a3f97cbb JW |
9633 | register rtx insn; |
9634 | { | |
9635 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 9636 | |
a3f97cbb JW |
9637 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9638 | { | |
9639 | function_section (current_function_decl); | |
5c90448c JM |
9640 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number); |
9641 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label, | |
9642 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
9643 | } |
9644 | } | |
9645 | ||
a3f97cbb | 9646 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 9647 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
9648 | just a unique number which is associated with only that one filename. |
9649 | We need such numbers for the sake of generating labels | |
9650 | (in the .debug_sfnames section) and references to those | |
9651 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
9652 | If the filename given as an argument is not found in our current list, | |
9653 | add it to the list and assign it the next available unique index number. | |
9654 | In order to speed up searches, we remember the index of the filename | |
9655 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 9656 | |
a3f97cbb JW |
9657 | static unsigned |
9658 | lookup_filename (file_name) | |
d560ee52 | 9659 | const char *file_name; |
a3f97cbb JW |
9660 | { |
9661 | static unsigned last_file_lookup_index = 0; | |
a3f97cbb JW |
9662 | register unsigned i; |
9663 | ||
9664 | /* Check to see if the file name that was searched on the previous call | |
9665 | matches this file name. If so, return the index. */ | |
9666 | if (last_file_lookup_index != 0) | |
71dfc51f RK |
9667 | if (strcmp (file_name, file_table[last_file_lookup_index]) == 0) |
9668 | return last_file_lookup_index; | |
a3f97cbb JW |
9669 | |
9670 | /* Didn't match the previous lookup, search the table */ | |
9671 | for (i = 1; i < file_table_in_use; ++i) | |
71dfc51f RK |
9672 | if (strcmp (file_name, file_table[i]) == 0) |
9673 | { | |
9674 | last_file_lookup_index = i; | |
9675 | return i; | |
9676 | } | |
a3f97cbb JW |
9677 | |
9678 | /* Prepare to add a new table entry by making sure there is enough space in | |
9679 | the table to do so. If not, expand the current table. */ | |
9680 | if (file_table_in_use == file_table_allocated) | |
9681 | { | |
9682 | file_table_allocated += FILE_TABLE_INCREMENT; | |
9683 | file_table | |
71dfc51f RK |
9684 | = (char **) xrealloc (file_table, |
9685 | file_table_allocated * sizeof (char *)); | |
a3f97cbb JW |
9686 | } |
9687 | ||
71dfc51f | 9688 | /* Add the new entry to the end of the filename table. */ |
a3f97cbb JW |
9689 | file_table[file_table_in_use] = xstrdup (file_name); |
9690 | last_file_lookup_index = file_table_in_use++; | |
71dfc51f | 9691 | |
a3f97cbb JW |
9692 | return last_file_lookup_index; |
9693 | } | |
9694 | ||
9695 | /* Output a label to mark the beginning of a source code line entry | |
9696 | and record information relating to this source line, in | |
9697 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 9698 | |
a3f97cbb | 9699 | void |
9a666dda | 9700 | dwarf2out_line (filename, line) |
d560ee52 | 9701 | register const char *filename; |
a3f97cbb JW |
9702 | register unsigned line; |
9703 | { | |
a3f97cbb JW |
9704 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
9705 | { | |
9706 | function_section (current_function_decl); | |
a3f97cbb | 9707 | |
b2244e22 JW |
9708 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
9709 | { | |
e2bef702 | 9710 | static const char *lastfile; |
b2244e22 JW |
9711 | |
9712 | /* Emit the .file and .loc directives understood by GNU as. */ | |
9713 | if (lastfile == 0 || strcmp (filename, lastfile)) | |
9714 | { | |
951a525f MM |
9715 | if (lastfile == 0) |
9716 | ggc_add_string_root ((char **) &lastfile, 1); | |
9717 | ||
b2244e22 JW |
9718 | fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename); |
9719 | lastfile = filename; | |
9720 | } | |
9721 | ||
9722 | fprintf (asm_out_file, "\t.loc 0 %d 0\n", line); | |
9723 | ||
9724 | /* Indicate that line number info exists. */ | |
9725 | ++line_info_table_in_use; | |
9726 | ||
9727 | /* Indicate that multiple line number tables exist. */ | |
9728 | if (DECL_SECTION_NAME (current_function_decl)) | |
9729 | ++separate_line_info_table_in_use; | |
9730 | } | |
9731 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 9732 | { |
e90b62db | 9733 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
9734 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
9735 | separate_line_info_table_in_use); | |
ac260b05 JM |
9736 | if (flag_debug_asm) |
9737 | fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line); | |
e90b62db JM |
9738 | fputc ('\n', asm_out_file); |
9739 | ||
9740 | /* expand the line info table if necessary */ | |
9741 | if (separate_line_info_table_in_use | |
9742 | == separate_line_info_table_allocated) | |
9743 | { | |
9744 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9745 | separate_line_info_table | |
71dfc51f RK |
9746 | = (dw_separate_line_info_ref) |
9747 | xrealloc (separate_line_info_table, | |
9748 | separate_line_info_table_allocated | |
9749 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 9750 | } |
71dfc51f RK |
9751 | |
9752 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9753 | line_info |
9754 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
9755 | line_info->dw_file_num = lookup_filename (filename); | |
9756 | line_info->dw_line_num = line; | |
9757 | line_info->function = current_funcdef_number; | |
9758 | } | |
9759 | else | |
9760 | { | |
9761 | register dw_line_info_ref line_info; | |
71dfc51f | 9762 | |
5c90448c JM |
9763 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
9764 | line_info_table_in_use); | |
ac260b05 JM |
9765 | if (flag_debug_asm) |
9766 | fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line); | |
e90b62db JM |
9767 | fputc ('\n', asm_out_file); |
9768 | ||
71dfc51f | 9769 | /* Expand the line info table if necessary. */ |
e90b62db JM |
9770 | if (line_info_table_in_use == line_info_table_allocated) |
9771 | { | |
9772 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9773 | line_info_table | |
71dfc51f RK |
9774 | = (dw_line_info_ref) |
9775 | xrealloc (line_info_table, | |
9776 | (line_info_table_allocated | |
9777 | * sizeof (dw_line_info_entry))); | |
e90b62db | 9778 | } |
71dfc51f RK |
9779 | |
9780 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9781 | line_info = &line_info_table[line_info_table_in_use++]; |
9782 | line_info->dw_file_num = lookup_filename (filename); | |
9783 | line_info->dw_line_num = line; | |
a3f97cbb | 9784 | } |
a3f97cbb JW |
9785 | } |
9786 | } | |
9787 | ||
9788 | /* Record the beginning of a new source file, for later output | |
9789 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 9790 | |
a3f97cbb | 9791 | void |
9a666dda | 9792 | dwarf2out_start_source_file (filename) |
d560ee52 | 9793 | register const char *filename ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9794 | { |
9795 | } | |
9796 | ||
9a666dda | 9797 | /* Record the end of a source file, for later output |
a3f97cbb | 9798 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 9799 | |
a3f97cbb | 9800 | void |
9a666dda | 9801 | dwarf2out_end_source_file () |
a3f97cbb JW |
9802 | { |
9803 | } | |
9804 | ||
9805 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9806 | the tail part of the directive line, i.e. the part which is past the | |
9807 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9808 | |
a3f97cbb | 9809 | void |
9a666dda | 9810 | dwarf2out_define (lineno, buffer) |
2618f955 | 9811 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 9812 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9813 | { |
9814 | static int initialized = 0; | |
9815 | if (!initialized) | |
9816 | { | |
9a666dda | 9817 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
9818 | initialized = 1; |
9819 | } | |
9820 | } | |
9821 | ||
9822 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9823 | the tail part of the directive line, i.e. the part which is past the | |
9824 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9825 | |
a3f97cbb | 9826 | void |
9a666dda | 9827 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 9828 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 9829 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9830 | { |
9831 | } | |
9832 | ||
9833 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 9834 | |
a3f97cbb | 9835 | void |
9a666dda | 9836 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb JW |
9837 | register FILE *asm_out_file; |
9838 | register char *main_input_filename; | |
9839 | { | |
a3f97cbb JW |
9840 | /* Remember the name of the primary input file. */ |
9841 | primary_filename = main_input_filename; | |
9842 | ||
9843 | /* Allocate the initial hunk of the file_table. */ | |
3de90026 | 9844 | file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
a3f97cbb | 9845 | file_table_allocated = FILE_TABLE_INCREMENT; |
71dfc51f RK |
9846 | |
9847 | /* Skip the first entry - file numbers begin at 1. */ | |
a3f97cbb JW |
9848 | file_table_in_use = 1; |
9849 | ||
a3f97cbb JW |
9850 | /* Allocate the initial hunk of the decl_die_table. */ |
9851 | decl_die_table | |
3de90026 | 9852 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
9853 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
9854 | decl_die_table_in_use = 0; | |
9855 | ||
9856 | /* Allocate the initial hunk of the decl_scope_table. */ | |
9857 | decl_scope_table | |
777ad4c2 | 9858 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
9859 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
9860 | decl_scope_depth = 0; | |
9861 | ||
9862 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
9863 | abbrev_die_table | |
3de90026 RH |
9864 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
9865 | sizeof (dw_die_ref)); | |
a3f97cbb | 9866 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 9867 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9868 | abbrev_die_table_in_use = 1; |
9869 | ||
9870 | /* Allocate the initial hunk of the line_info_table. */ | |
9871 | line_info_table | |
3de90026 RH |
9872 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
9873 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 9874 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 9875 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9876 | line_info_table_in_use = 1; |
9877 | ||
a3f97cbb JW |
9878 | /* Generate the initial DIE for the .debug section. Note that the (string) |
9879 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE | |
9880 | will (typically) be a relative pathname and that this pathname should be | |
9881 | taken as being relative to the directory from which the compiler was | |
9882 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 9883 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 9884 | |
1865dbb5 JM |
9885 | if (ggc_p) |
9886 | { | |
9887 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); | |
ef8288f7 | 9888 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); |
1865dbb5 JM |
9889 | } |
9890 | ||
5c90448c | 9891 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
8b790721 | 9892 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0); |
b366352b MM |
9893 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
9894 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
9895 | else | |
9896 | strcpy (text_section_label, stripattributes (TEXT_SECTION)); | |
8b790721 JM |
9897 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
9898 | DEBUG_INFO_SECTION_LABEL, 0); | |
9899 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, | |
9900 | DEBUG_LINE_SECTION_LABEL, 0); | |
9901 | ||
9902 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
9903 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); | |
b366352b | 9904 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
a96c67ec JM |
9905 | { |
9906 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
9907 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
9908 | } | |
8b790721 JM |
9909 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
9910 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); | |
9911 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
9912 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); | |
a3f97cbb JW |
9913 | } |
9914 | ||
9915 | /* Output stuff that dwarf requires at the end of every file, | |
9916 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 9917 | |
a3f97cbb | 9918 | void |
9a666dda | 9919 | dwarf2out_finish () |
a3f97cbb | 9920 | { |
ef76d03b JW |
9921 | limbo_die_node *node, *next_node; |
9922 | dw_die_ref die; | |
ef76d03b JW |
9923 | |
9924 | /* Traverse the limbo die list, and add parent/child links. The only | |
9925 | dies without parents that should be here are concrete instances of | |
9926 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
9927 | For concrete instances, we can get the parent die from the abstract | |
9928 | instance. */ | |
9929 | for (node = limbo_die_list; node; node = next_node) | |
9930 | { | |
9931 | next_node = node->next; | |
9932 | die = node->die; | |
9933 | ||
9934 | if (die->die_parent == NULL) | |
9935 | { | |
a96c67ec JM |
9936 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
9937 | if (origin) | |
9938 | add_child_die (origin->die_parent, die); | |
ef76d03b | 9939 | else if (die == comp_unit_die) |
a96c67ec | 9940 | ; |
ef76d03b JW |
9941 | else |
9942 | abort (); | |
9943 | } | |
9944 | free (node); | |
9945 | } | |
a96c67ec | 9946 | limbo_die_list = NULL; |
ef76d03b | 9947 | |
8a8c3656 JM |
9948 | /* Walk through the list of incomplete types again, trying once more to |
9949 | emit full debugging info for them. */ | |
9950 | retry_incomplete_types (); | |
9951 | ||
a96c67ec JM |
9952 | /* Traverse the DIE's, reverse their lists of attributes and children, |
9953 | and add add sibling attributes to those DIE's that have children. */ | |
a3f97cbb JW |
9954 | add_sibling_attributes (comp_unit_die); |
9955 | ||
9956 | /* Output a terminator label for the .text section. */ | |
9957 | fputc ('\n', asm_out_file); | |
9958 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
5c90448c | 9959 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 9960 | |
bdb669cb | 9961 | #if 0 |
a3f97cbb JW |
9962 | /* Output a terminator label for the .data section. */ |
9963 | fputc ('\n', asm_out_file); | |
9964 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
5c90448c | 9965 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
9966 | |
9967 | /* Output a terminator label for the .bss section. */ | |
9968 | fputc ('\n', asm_out_file); | |
9969 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
5c90448c | 9970 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 9971 | #endif |
a3f97cbb | 9972 | |
e90b62db JM |
9973 | /* Output the source line correspondence table. */ |
9974 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
9975 | { | |
b2244e22 JW |
9976 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
9977 | { | |
9978 | fputc ('\n', asm_out_file); | |
9979 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
9980 | output_line_info (); | |
9981 | } | |
e90b62db JM |
9982 | |
9983 | /* We can only use the low/high_pc attributes if all of the code | |
9984 | was in .text. */ | |
9985 | if (separate_line_info_table_in_use == 0) | |
9986 | { | |
8b790721 | 9987 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); |
5c90448c | 9988 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); |
e90b62db | 9989 | } |
71dfc51f | 9990 | |
8b790721 JM |
9991 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, |
9992 | debug_line_section_label); | |
e90b62db JM |
9993 | } |
9994 | ||
a96c67ec JM |
9995 | #if 0 /* unimplemented */ |
9996 | if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary) | |
9997 | add_AT_unsigned (die, DW_AT_macro_info, 0); | |
9998 | #endif | |
9999 | ||
a3f97cbb JW |
10000 | /* Output the abbreviation table. */ |
10001 | fputc ('\n', asm_out_file); | |
10002 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
10003 | build_abbrev_table (comp_unit_die); | |
10004 | output_abbrev_section (); | |
10005 | ||
a3f97cbb JW |
10006 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
10007 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
10008 | calc_die_sizes (comp_unit_die); | |
10009 | ||
a3f97cbb JW |
10010 | /* Output debugging information. */ |
10011 | fputc ('\n', asm_out_file); | |
c53aa195 | 10012 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
a3f97cbb JW |
10013 | output_compilation_unit_header (); |
10014 | output_die (comp_unit_die); | |
10015 | ||
d291dd49 JM |
10016 | if (pubname_table_in_use) |
10017 | { | |
10018 | /* Output public names table. */ | |
10019 | fputc ('\n', asm_out_file); | |
10020 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
10021 | output_pubnames (); | |
10022 | } | |
10023 | ||
e689ae67 JM |
10024 | /* We only put functions in the arange table, so don't write it out if |
10025 | we don't have any. */ | |
a3f97cbb JW |
10026 | if (fde_table_in_use) |
10027 | { | |
a3f97cbb JW |
10028 | /* Output the address range information. */ |
10029 | fputc ('\n', asm_out_file); | |
10030 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
10031 | output_aranges (); | |
10032 | } | |
10033 | } | |
9a666dda | 10034 | #endif /* DWARF2_DEBUGGING_INFO */ |