]>
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 | Emit .debug_line header even when there are no functions, since |
27 | the file numbers are used by .debug_info. Alternately, leave | |
28 | out locations for types and decls. | |
29 | Avoid talking about ctors and op= for PODs. | |
30 | Factor out common prologue sequences into multiple CIEs. */ | |
31 | ||
3f76745e JM |
32 | /* The first part of this file deals with the DWARF 2 frame unwind |
33 | information, which is also used by the GCC efficient exception handling | |
34 | mechanism. The second part, controlled only by an #ifdef | |
35 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
36 | information. */ | |
37 | ||
0021b564 | 38 | #include "config.h" |
670ee920 | 39 | #include "system.h" |
0021b564 | 40 | #include "defaults.h" |
a3f97cbb JW |
41 | #include "tree.h" |
42 | #include "flags.h" | |
43 | #include "rtl.h" | |
44 | #include "hard-reg-set.h" | |
45 | #include "regs.h" | |
46 | #include "insn-config.h" | |
47 | #include "reload.h" | |
48 | #include "output.h" | |
71dfc51f | 49 | #include "expr.h" |
3f76745e | 50 | #include "except.h" |
a7cc7f29 | 51 | #include "dwarf2.h" |
76ead72b | 52 | #include "dwarf2out.h" |
10f0ad3d | 53 | #include "toplev.h" |
1865dbb5 | 54 | #include "varray.h" |
951a525f | 55 | #include "ggc.h" |
881c6935 | 56 | #include "md5.h" |
57bed152 | 57 | #include "tm_p.h" |
a3f97cbb | 58 | |
0021b564 JM |
59 | /* Decide whether we want to emit frame unwind information for the current |
60 | translation unit. */ | |
61 | ||
62 | int | |
63 | dwarf2out_do_frame () | |
64 | { | |
65 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 | 66 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 67 | || DWARF2_FRAME_INFO |
9ec36da5 | 68 | #endif |
0021b564 | 69 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 70 | || flag_unwind_tables |
0021b564 JM |
71 | || (flag_exceptions && ! exceptions_via_longjmp) |
72 | #endif | |
73 | ); | |
74 | } | |
75 | ||
76 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
77 | ||
eaf95893 RK |
78 | /* How to start an assembler comment. */ |
79 | #ifndef ASM_COMMENT_START | |
80 | #define ASM_COMMENT_START ";#" | |
81 | #endif | |
82 | ||
a3f97cbb JW |
83 | typedef struct dw_cfi_struct *dw_cfi_ref; |
84 | typedef struct dw_fde_struct *dw_fde_ref; | |
85 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
86 | |
87 | /* Call frames are described using a sequence of Call Frame | |
88 | Information instructions. The register number, offset | |
89 | and address fields are provided as possible operands; | |
90 | their use is selected by the opcode field. */ | |
71dfc51f | 91 | |
a3f97cbb | 92 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
93 | { |
94 | unsigned long dw_cfi_reg_num; | |
95 | long int dw_cfi_offset; | |
d3e3972c | 96 | const char *dw_cfi_addr; |
7d9d8943 | 97 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 98 | } |
a3f97cbb JW |
99 | dw_cfi_oprnd; |
100 | ||
101 | typedef struct dw_cfi_struct | |
71dfc51f RK |
102 | { |
103 | dw_cfi_ref dw_cfi_next; | |
104 | enum dwarf_call_frame_info dw_cfi_opc; | |
105 | dw_cfi_oprnd dw_cfi_oprnd1; | |
106 | dw_cfi_oprnd dw_cfi_oprnd2; | |
107 | } | |
a3f97cbb JW |
108 | dw_cfi_node; |
109 | ||
7d9d8943 AM |
110 | /* This is how we define the location of the CFA. We use to handle it |
111 | as REG + OFFSET all the time, but now it can be more complex. | |
112 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 113 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
114 | of this structure. */ |
115 | typedef struct cfa_loc | |
116 | { | |
556273e0 | 117 | unsigned long reg; |
7d9d8943 AM |
118 | long offset; |
119 | long base_offset; | |
120 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
121 | } dw_cfa_location; | |
122 | ||
a3f97cbb | 123 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 124 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
125 | the beginning of the .debug_frame section. This used of a single |
126 | CIE obviates the need to keep track of multiple CIE's | |
127 | in the DWARF generation routines below. */ | |
71dfc51f | 128 | |
a3f97cbb | 129 | typedef struct dw_fde_struct |
71dfc51f | 130 | { |
d3e3972c KG |
131 | const char *dw_fde_begin; |
132 | const char *dw_fde_current_label; | |
133 | const char *dw_fde_end; | |
71dfc51f | 134 | dw_cfi_ref dw_fde_cfi; |
737faf14 | 135 | int nothrow; |
71dfc51f | 136 | } |
a3f97cbb JW |
137 | dw_fde_node; |
138 | ||
a3f97cbb JW |
139 | /* Maximum size (in bytes) of an artificially generated label. */ |
140 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
141 | ||
a1a4189d | 142 | /* The size of the target's pointer type. */ |
a3f97cbb | 143 | #ifndef PTR_SIZE |
a9d38797 | 144 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
145 | #endif |
146 | ||
a1a4189d JB |
147 | /* The size of addresses as they appear in the Dwarf 2 data. |
148 | Some architectures use word addresses to refer to code locations, | |
149 | but Dwarf 2 info always uses byte addresses. On such machines, | |
150 | Dwarf 2 addresses need to be larger than the architecture's | |
151 | pointers. */ | |
152 | #ifndef DWARF2_ADDR_SIZE | |
153 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
154 | #endif | |
155 | ||
7e23cb16 | 156 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
157 | relative to a debug info section, specified to be 4 bytes in the |
158 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 159 | as PTR_SIZE. */ |
71dfc51f | 160 | |
7e23cb16 JM |
161 | #ifndef DWARF_OFFSET_SIZE |
162 | #define DWARF_OFFSET_SIZE 4 | |
163 | #endif | |
164 | ||
9a666dda JM |
165 | #define DWARF_VERSION 2 |
166 | ||
7e23cb16 JM |
167 | /* Round SIZE up to the nearest BOUNDARY. */ |
168 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 169 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 170 | |
a3f97cbb | 171 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 172 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 173 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 174 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 175 | #else |
08cb3d38 | 176 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 177 | #endif |
27c35f4b | 178 | #endif /* not DWARF_CIE_DATA_ALIGNMENT */ |
a3f97cbb | 179 | |
3f76745e JM |
180 | /* A pointer to the base of a table that contains frame description |
181 | information for each routine. */ | |
182 | static dw_fde_ref fde_table; | |
a3f97cbb | 183 | |
3f76745e JM |
184 | /* Number of elements currently allocated for fde_table. */ |
185 | static unsigned fde_table_allocated; | |
a94dbf2c | 186 | |
3f76745e JM |
187 | /* Number of elements in fde_table currently in use. */ |
188 | static unsigned fde_table_in_use; | |
a3f97cbb | 189 | |
3f76745e JM |
190 | /* Size (in elements) of increments by which we may expand the |
191 | fde_table. */ | |
192 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 193 | |
a94dbf2c JM |
194 | /* A list of call frame insns for the CIE. */ |
195 | static dw_cfi_ref cie_cfi_head; | |
196 | ||
a3f97cbb JW |
197 | /* The number of the current function definition for which debugging |
198 | information is being generated. These numbers range from 1 up to the | |
199 | maximum number of function definitions contained within the current | |
200 | compilation unit. These numbers are used to create unique label id's | |
201 | unique to each function definition. */ | |
4f988ea2 | 202 | static unsigned current_funcdef_number = 0; |
a3f97cbb JW |
203 | |
204 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
205 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 206 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
207 | associated with the current function (body) definition. */ |
208 | static unsigned current_funcdef_fde; | |
209 | ||
a3f97cbb | 210 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 211 | |
83d2b3b9 KG |
212 | static char *stripattributes PARAMS ((const char *)); |
213 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
214 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
215 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
216 | static unsigned long size_of_uleb128 PARAMS ((unsigned long)); | |
217 | static unsigned long size_of_sleb128 PARAMS ((long)); | |
218 | static void output_uleb128 PARAMS ((unsigned long)); | |
219 | static void output_sleb128 PARAMS ((long)); | |
d3e3972c | 220 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
7d9d8943 AM |
221 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *)); |
222 | static void lookup_cfa PARAMS ((dw_cfa_location *)); | |
d3e3972c KG |
223 | static void reg_save PARAMS ((const char *, unsigned, |
224 | unsigned, long)); | |
83d2b3b9 | 225 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 226 | static long stack_adjust_offset PARAMS ((rtx)); |
83d2b3b9 KG |
227 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref)); |
228 | static void output_call_frame_info PARAMS ((int)); | |
83d2b3b9 | 229 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
d3e3972c | 230 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 231 | |
7d9d8943 AM |
232 | /* Support for complex CFA locations. */ |
233 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 234 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
235 | struct dw_loc_descr_struct *)); |
236 | static struct dw_loc_descr_struct *build_cfa_loc | |
237 | PARAMS ((dw_cfa_location *)); | |
238 | static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *)); | |
239 | ||
a3f97cbb JW |
240 | /* Definitions of defaults for assembler-dependent names of various |
241 | pseudo-ops and section names. | |
242 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
243 | assembler. */ | |
71dfc51f | 244 | |
0021b564 | 245 | #ifdef OBJECT_FORMAT_ELF |
a3f97cbb | 246 | #ifndef UNALIGNED_SHORT_ASM_OP |
0a3e1f45 | 247 | #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t" |
a3f97cbb JW |
248 | #endif |
249 | #ifndef UNALIGNED_INT_ASM_OP | |
0a3e1f45 | 250 | #define UNALIGNED_INT_ASM_OP "\t.4byte\t" |
a3f97cbb | 251 | #endif |
7e23cb16 | 252 | #ifndef UNALIGNED_DOUBLE_INT_ASM_OP |
0a3e1f45 | 253 | #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t" |
7e23cb16 | 254 | #endif |
0021b564 JM |
255 | #endif /* OBJECT_FORMAT_ELF */ |
256 | ||
a3f97cbb | 257 | #ifndef ASM_BYTE_OP |
0a3e1f45 | 258 | #define ASM_BYTE_OP "\t.byte\t" |
a3f97cbb JW |
259 | #endif |
260 | ||
7e23cb16 JM |
261 | /* Data and reference forms for relocatable data. */ |
262 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
263 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
264 | ||
a3f97cbb JW |
265 | /* Pseudo-op for defining a new section. */ |
266 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 267 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
268 | #endif |
269 | ||
270 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
271 | print the SECTION_ASM_OP and the section name. The default here works for | |
272 | almost all svr4 assemblers, except for the sparc, where the section name | |
273 | must be enclosed in double quotes. (See sparcv4.h). */ | |
274 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
275 | #ifdef PUSHSECTION_FORMAT |
276 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
277 | #else | |
e8638df0 | 278 | #define SECTION_FORMAT "%s%s\n" |
c53aa195 | 279 | #endif |
a3f97cbb JW |
280 | #endif |
281 | ||
a3f97cbb JW |
282 | #ifndef FRAME_SECTION |
283 | #define FRAME_SECTION ".debug_frame" | |
284 | #endif | |
a3f97cbb | 285 | |
5c90448c JM |
286 | #ifndef FUNC_BEGIN_LABEL |
287 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 288 | #endif |
5c90448c JM |
289 | #ifndef FUNC_END_LABEL |
290 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 291 | #endif |
a6ab3aad JM |
292 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
293 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 294 | #define CIE_LENGTH_LABEL "LLCIE" |
a6ab3aad JM |
295 | #define FDE_AFTER_SIZE_LABEL "LSFDE" |
296 | #define FDE_END_LABEL "LEFDE" | |
2ed2af28 | 297 | #define FDE_LENGTH_LABEL "LLFDE" |
881c6935 | 298 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 299 | |
a3f97cbb JW |
300 | /* Definitions of defaults for various types of primitive assembly language |
301 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 302 | but typically, that is unnecessary. */ |
71dfc51f | 303 | |
a3f97cbb JW |
304 | #ifndef ASM_OUTPUT_SECTION |
305 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
306 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
307 | #endif | |
308 | ||
0021b564 JM |
309 | #ifndef ASM_OUTPUT_DWARF_DATA1 |
310 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
e8638df0 | 311 | fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE)) |
0021b564 JM |
312 | #endif |
313 | ||
bb727b5a JM |
314 | #ifndef ASM_OUTPUT_DWARF_DELTA1 |
315 | #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \ | |
e8638df0 | 316 | do { fprintf ((FILE), "%s", ASM_BYTE_OP); \ |
bb727b5a JM |
317 | assemble_name (FILE, LABEL1); \ |
318 | fprintf (FILE, "-"); \ | |
319 | assemble_name (FILE, LABEL2); \ | |
320 | } while (0) | |
321 | #endif | |
322 | ||
0021b564 JM |
323 | #ifdef UNALIGNED_INT_ASM_OP |
324 | ||
325 | #ifndef UNALIGNED_OFFSET_ASM_OP | |
326 | #define UNALIGNED_OFFSET_ASM_OP \ | |
327 | (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
328 | #endif | |
329 | ||
330 | #ifndef UNALIGNED_WORD_ASM_OP | |
a1a4189d JB |
331 | #define UNALIGNED_WORD_ASM_OP \ |
332 | ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \ | |
333 | : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \ | |
334 | : UNALIGNED_INT_ASM_OP) | |
0021b564 JM |
335 | #endif |
336 | ||
a3f97cbb JW |
337 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
338 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
e8638df0 | 339 | do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \ |
a3f97cbb JW |
340 | assemble_name (FILE, LABEL1); \ |
341 | fprintf (FILE, "-"); \ | |
342 | assemble_name (FILE, LABEL2); \ | |
343 | } while (0) | |
344 | #endif | |
345 | ||
346 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
347 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
e8638df0 | 348 | do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \ |
a3f97cbb JW |
349 | assemble_name (FILE, LABEL1); \ |
350 | fprintf (FILE, "-"); \ | |
351 | assemble_name (FILE, LABEL2); \ | |
352 | } while (0) | |
353 | #endif | |
354 | ||
7e23cb16 JM |
355 | #ifndef ASM_OUTPUT_DWARF_DELTA |
356 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
e8638df0 | 357 | do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \ |
7e23cb16 JM |
358 | assemble_name (FILE, LABEL1); \ |
359 | fprintf (FILE, "-"); \ | |
360 | assemble_name (FILE, LABEL2); \ | |
361 | } while (0) | |
362 | #endif | |
363 | ||
364 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA | |
365 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
e8638df0 | 366 | do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \ |
7e23cb16 JM |
367 | assemble_name (FILE, LABEL1); \ |
368 | fprintf (FILE, "-"); \ | |
369 | assemble_name (FILE, LABEL2); \ | |
370 | } while (0) | |
371 | #endif | |
372 | ||
a3f97cbb JW |
373 | #ifndef ASM_OUTPUT_DWARF_ADDR |
374 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
e8638df0 | 375 | do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \ |
a3f97cbb JW |
376 | assemble_name (FILE, LABEL); \ |
377 | } while (0) | |
378 | #endif | |
379 | ||
380 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
1865dbb5 JM |
381 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ |
382 | do { \ | |
e8638df0 | 383 | fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \ |
1865dbb5 | 384 | output_addr_const ((FILE), (RTX)); \ |
1865dbb5 | 385 | } while (0) |
7e23cb16 JM |
386 | #endif |
387 | ||
7bb9fb0e JM |
388 | #ifndef ASM_OUTPUT_DWARF_OFFSET4 |
389 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ | |
e8638df0 | 390 | do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \ |
7bb9fb0e JM |
391 | assemble_name (FILE, LABEL); \ |
392 | } while (0) | |
393 | #endif | |
394 | ||
7e23cb16 JM |
395 | #ifndef ASM_OUTPUT_DWARF_OFFSET |
396 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ | |
e8638df0 | 397 | do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \ |
7e23cb16 JM |
398 | assemble_name (FILE, LABEL); \ |
399 | } while (0) | |
a3f97cbb JW |
400 | #endif |
401 | ||
a3f97cbb JW |
402 | #ifndef ASM_OUTPUT_DWARF_DATA2 |
403 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
e8638df0 | 404 | fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
405 | #endif |
406 | ||
407 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
408 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
e8638df0 | 409 | fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE)) |
a3f97cbb JW |
410 | #endif |
411 | ||
21217bd0 JW |
412 | #ifndef ASM_OUTPUT_DWARF_DATA8 |
413 | #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \ | |
e8638df0 | 414 | fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \ |
21217bd0 JW |
415 | (unsigned long) (VALUE)) |
416 | #endif | |
417 | ||
7e23cb16 JM |
418 | #ifndef ASM_OUTPUT_DWARF_DATA |
419 | #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \ | |
e8638df0 | 420 | fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \ |
32bd96ff | 421 | (unsigned long) (VALUE)) |
7e23cb16 JM |
422 | #endif |
423 | ||
424 | #ifndef ASM_OUTPUT_DWARF_ADDR_DATA | |
425 | #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \ | |
e8638df0 | 426 | fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \ |
32bd96ff | 427 | (unsigned long) (VALUE)) |
7e23cb16 JM |
428 | #endif |
429 | ||
21217bd0 JW |
430 | #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE |
431 | #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \ | |
a3f97cbb JW |
432 | do { \ |
433 | if (WORDS_BIG_ENDIAN) \ | |
434 | { \ | |
e8638df0 HPN |
435 | fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\ |
436 | fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\ | |
a3f97cbb JW |
437 | } \ |
438 | else \ | |
439 | { \ | |
e8638df0 HPN |
440 | fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \ |
441 | fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \ | |
a3f97cbb JW |
442 | } \ |
443 | } while (0) | |
444 | #endif | |
445 | ||
0021b564 JM |
446 | #else /* UNALIGNED_INT_ASM_OP */ |
447 | ||
448 | /* We don't have unaligned support, let's hope the normal output works for | |
e09bbb25 JM |
449 | .debug_frame. But we know it won't work for .debug_info. */ |
450 | ||
451 | #ifdef DWARF2_DEBUGGING_INFO | |
63bc1d05 | 452 | #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP. |
e09bbb25 | 453 | #endif |
0021b564 | 454 | |
0517872a | 455 | #ifndef ASM_OUTPUT_DWARF_ADDR |
0021b564 | 456 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ |
a1a4189d | 457 | assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1) |
0517872a JM |
458 | #endif |
459 | ||
460 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
461 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX) | |
462 | #endif | |
0021b564 | 463 | |
0517872a | 464 | #ifndef ASM_OUTPUT_DWARF_OFFSET4 |
7bb9fb0e | 465 | #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \ |
38a448ca | 466 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
0517872a | 467 | #endif |
7bb9fb0e | 468 | |
0517872a | 469 | #ifndef ASM_OUTPUT_DWARF_OFFSET |
0021b564 | 470 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ |
38a448ca | 471 | assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1) |
0517872a | 472 | #endif |
0021b564 | 473 | |
0517872a | 474 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
0021b564 | 475 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ |
38a448ca | 476 | assemble_integer (gen_rtx_MINUS (HImode, \ |
c5c76735 JL |
477 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
478 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 | 479 | 2, 1) |
0517872a | 480 | #endif |
556273e0 | 481 | |
0517872a | 482 | #ifndef ASM_OUTPUT_DWARF_DELTA4 |
0021b564 | 483 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ |
38a448ca | 484 | assemble_integer (gen_rtx_MINUS (SImode, \ |
c5c76735 JL |
485 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
486 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
0021b564 | 487 | 4, 1) |
0517872a | 488 | #endif |
0021b564 | 489 | |
0517872a | 490 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA |
0021b564 | 491 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ |
38a448ca | 492 | assemble_integer (gen_rtx_MINUS (Pmode, \ |
c5c76735 JL |
493 | gen_rtx_SYMBOL_REF (Pmode, LABEL1), \ |
494 | gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \ | |
a1a4189d | 495 | DWARF2_ADDR_SIZE, 1) |
0517872a | 496 | #endif |
0021b564 | 497 | |
0517872a | 498 | #ifndef ASM_OUTPUT_DWARF_DELTA |
0021b564 JM |
499 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ |
500 | ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2) | |
0517872a | 501 | #endif |
0021b564 | 502 | |
0517872a | 503 | #ifndef ASM_OUTPUT_DWARF_DATA2 |
e0e07bd1 JM |
504 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ |
505 | assemble_integer (GEN_INT (VALUE), 2, 1) | |
0517872a | 506 | #endif |
e0e07bd1 | 507 | |
0517872a | 508 | #ifndef ASM_OUTPUT_DWARF_DATA4 |
0021b564 JM |
509 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ |
510 | assemble_integer (GEN_INT (VALUE), 4, 1) | |
0517872a | 511 | #endif |
0021b564 JM |
512 | |
513 | #endif /* UNALIGNED_INT_ASM_OP */ | |
514 | ||
2ed2af28 PDM |
515 | #ifdef SET_ASM_OP |
516 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
517 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
518 | do { \ | |
e8638df0 | 519 | fprintf (FILE, "%s", SET_ASM_OP); \ |
7bb9fb0e JM |
520 | assemble_name (FILE, SY); \ |
521 | fputc (',', FILE); \ | |
522 | assemble_name (FILE, HI); \ | |
523 | fputc ('-', FILE); \ | |
524 | assemble_name (FILE, LO); \ | |
525 | } while (0) | |
2ed2af28 PDM |
526 | #endif |
527 | #endif /* SET_ASM_OP */ | |
528 | ||
a6ab3aad | 529 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing |
2ed2af28 | 530 | newline is produced. When flag_debug_asm is asserted, we add commentary |
a6ab3aad JM |
531 | at the end of the line, so we must avoid output of a newline here. */ |
532 | #ifndef ASM_OUTPUT_DWARF_STRING | |
533 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
534 | do { \ | |
535 | register int slen = strlen(P); \ | |
d560ee52 | 536 | register const char *p = (P); \ |
a6ab3aad JM |
537 | register int i; \ |
538 | fprintf (FILE, "\t.ascii \""); \ | |
539 | for (i = 0; i < slen; i++) \ | |
540 | { \ | |
541 | register int c = p[i]; \ | |
542 | if (c == '\"' || c == '\\') \ | |
543 | putc ('\\', FILE); \ | |
f3ad1f9c | 544 | if (ISPRINT(c)) \ |
a6ab3aad JM |
545 | putc (c, FILE); \ |
546 | else \ | |
547 | { \ | |
548 | fprintf (FILE, "\\%o", c); \ | |
549 | } \ | |
550 | } \ | |
551 | fprintf (FILE, "\\0\""); \ | |
552 | } \ | |
553 | while (0) | |
554 | #endif | |
555 | ||
c8cc5c4a | 556 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
557 | is the column for PC, or the first column after all of the hard |
558 | registers. */ | |
c8cc5c4a | 559 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
560 | #ifdef PC_REGNUM |
561 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
562 | #else | |
3073d01c | 563 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 564 | #endif |
c8cc5c4a JM |
565 | #endif |
566 | ||
567 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 568 | default, we just provide columns for all registers. */ |
c8cc5c4a | 569 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 570 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 571 | #endif |
3f76745e | 572 | |
0021b564 JM |
573 | /* Hook used by __throw. */ |
574 | ||
575 | rtx | |
576 | expand_builtin_dwarf_fp_regnum () | |
577 | { | |
578 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
579 | } | |
580 | ||
a6ab3aad JM |
581 | /* The offset from the incoming value of %sp to the top of the stack frame |
582 | for the current function. */ | |
583 | #ifndef INCOMING_FRAME_SP_OFFSET | |
584 | #define INCOMING_FRAME_SP_OFFSET 0 | |
585 | #endif | |
586 | ||
71dfc51f | 587 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 588 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
589 | |
590 | static inline char * | |
a3f97cbb | 591 | stripattributes (s) |
d560ee52 | 592 | const char *s; |
a3f97cbb | 593 | { |
bf20f341 | 594 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
595 | char *p = stripped; |
596 | ||
bf20f341 JW |
597 | *p++ = '*'; |
598 | ||
599 | while (*s && *s != ',') | |
600 | *p++ = *s++; | |
71dfc51f | 601 | |
a3f97cbb JW |
602 | *p = '\0'; |
603 | return stripped; | |
604 | } | |
605 | ||
d9d5c9de | 606 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 607 | |
d9d5c9de BS |
608 | void |
609 | expand_builtin_init_dwarf_reg_sizes (address) | |
610 | tree address; | |
2f3ca9e7 | 611 | { |
d9d5c9de BS |
612 | int i; |
613 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
614 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
615 | rtx mem = gen_rtx_MEM (mode, addr); | |
2f3ca9e7 | 616 | |
376e12ab | 617 | for (i = 0; i < DWARF_FRAME_REGISTERS; ++i) |
2f3ca9e7 | 618 | { |
e0e07bd1 | 619 | int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
d9d5c9de | 620 | int size = GET_MODE_SIZE (reg_raw_mode[i]); |
2f3ca9e7 | 621 | |
c699cee9 JM |
622 | if (offset < 0) |
623 | continue; | |
624 | ||
d9d5c9de BS |
625 | emit_move_insn (change_address (mem, mode, |
626 | plus_constant (addr, offset)), | |
627 | GEN_INT (size)); | |
2f3ca9e7 | 628 | } |
2f3ca9e7 JM |
629 | } |
630 | ||
3f76745e | 631 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 632 | |
d560ee52 | 633 | static const char * |
3f76745e JM |
634 | dwarf_cfi_name (cfi_opc) |
635 | register unsigned cfi_opc; | |
636 | { | |
637 | switch (cfi_opc) | |
638 | { | |
639 | case DW_CFA_advance_loc: | |
640 | return "DW_CFA_advance_loc"; | |
641 | case DW_CFA_offset: | |
642 | return "DW_CFA_offset"; | |
643 | case DW_CFA_restore: | |
644 | return "DW_CFA_restore"; | |
645 | case DW_CFA_nop: | |
646 | return "DW_CFA_nop"; | |
647 | case DW_CFA_set_loc: | |
648 | return "DW_CFA_set_loc"; | |
649 | case DW_CFA_advance_loc1: | |
650 | return "DW_CFA_advance_loc1"; | |
651 | case DW_CFA_advance_loc2: | |
652 | return "DW_CFA_advance_loc2"; | |
653 | case DW_CFA_advance_loc4: | |
654 | return "DW_CFA_advance_loc4"; | |
655 | case DW_CFA_offset_extended: | |
656 | return "DW_CFA_offset_extended"; | |
657 | case DW_CFA_restore_extended: | |
658 | return "DW_CFA_restore_extended"; | |
659 | case DW_CFA_undefined: | |
660 | return "DW_CFA_undefined"; | |
661 | case DW_CFA_same_value: | |
662 | return "DW_CFA_same_value"; | |
663 | case DW_CFA_register: | |
664 | return "DW_CFA_register"; | |
665 | case DW_CFA_remember_state: | |
666 | return "DW_CFA_remember_state"; | |
667 | case DW_CFA_restore_state: | |
668 | return "DW_CFA_restore_state"; | |
669 | case DW_CFA_def_cfa: | |
670 | return "DW_CFA_def_cfa"; | |
671 | case DW_CFA_def_cfa_register: | |
672 | return "DW_CFA_def_cfa_register"; | |
673 | case DW_CFA_def_cfa_offset: | |
674 | return "DW_CFA_def_cfa_offset"; | |
7d9d8943 AM |
675 | case DW_CFA_def_cfa_expression: |
676 | return "DW_CFA_def_cfa_expression"; | |
c53aa195 | 677 | |
3f76745e JM |
678 | /* SGI/MIPS specific */ |
679 | case DW_CFA_MIPS_advance_loc8: | |
680 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
681 | |
682 | /* GNU extensions */ | |
683 | case DW_CFA_GNU_window_save: | |
684 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
685 | case DW_CFA_GNU_args_size: |
686 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
687 | case DW_CFA_GNU_negative_offset_extended: |
688 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 689 | |
3f76745e JM |
690 | default: |
691 | return "DW_CFA_<unknown>"; | |
692 | } | |
693 | } | |
a3f97cbb | 694 | |
3f76745e | 695 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 696 | |
3f76745e JM |
697 | static inline dw_cfi_ref |
698 | new_cfi () | |
699 | { | |
700 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 701 | |
3f76745e JM |
702 | cfi->dw_cfi_next = NULL; |
703 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
704 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 705 | |
3f76745e JM |
706 | return cfi; |
707 | } | |
a3f97cbb | 708 | |
3f76745e | 709 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 710 | |
3f76745e JM |
711 | static inline void |
712 | add_cfi (list_head, cfi) | |
713 | register dw_cfi_ref *list_head; | |
714 | register dw_cfi_ref cfi; | |
715 | { | |
716 | register dw_cfi_ref *p; | |
a3f97cbb | 717 | |
3f76745e JM |
718 | /* Find the end of the chain. */ |
719 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
720 | ; | |
721 | ||
722 | *p = cfi; | |
a3f97cbb JW |
723 | } |
724 | ||
3f76745e | 725 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 726 | |
c53aa195 | 727 | char * |
3f76745e | 728 | dwarf2out_cfi_label () |
a3f97cbb | 729 | { |
3f76745e JM |
730 | static char label[20]; |
731 | static unsigned long label_num = 0; | |
556273e0 | 732 | |
3f76745e JM |
733 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
734 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
735 | ||
736 | return label; | |
a3f97cbb JW |
737 | } |
738 | ||
3f76745e JM |
739 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
740 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 741 | |
3f76745e JM |
742 | static void |
743 | add_fde_cfi (label, cfi) | |
d3e3972c | 744 | register const char *label; |
3f76745e | 745 | register dw_cfi_ref cfi; |
a3f97cbb | 746 | { |
3f76745e JM |
747 | if (label) |
748 | { | |
749 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 750 | |
3f76745e JM |
751 | if (*label == 0) |
752 | label = dwarf2out_cfi_label (); | |
71dfc51f | 753 | |
3f76745e JM |
754 | if (fde->dw_fde_current_label == NULL |
755 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
756 | { | |
757 | register dw_cfi_ref xcfi; | |
a3f97cbb | 758 | |
3f76745e | 759 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 760 | |
3f76745e JM |
761 | /* Set the location counter to the new label. */ |
762 | xcfi = new_cfi (); | |
763 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
764 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
765 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
766 | } | |
71dfc51f | 767 | |
3f76745e JM |
768 | add_cfi (&fde->dw_fde_cfi, cfi); |
769 | } | |
770 | ||
771 | else | |
772 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
773 | } |
774 | ||
3f76745e | 775 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 776 | |
3f76745e | 777 | static inline void |
7d9d8943 | 778 | lookup_cfa_1 (cfi, loc) |
3f76745e | 779 | register dw_cfi_ref cfi; |
7d9d8943 | 780 | register dw_cfa_location *loc; |
a3f97cbb | 781 | { |
3f76745e JM |
782 | switch (cfi->dw_cfi_opc) |
783 | { | |
784 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 785 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
786 | break; |
787 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 788 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
789 | break; |
790 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
791 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
792 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
793 | break; | |
794 | case DW_CFA_def_cfa_expression: | |
795 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 796 | break; |
e9a25f70 JL |
797 | default: |
798 | break; | |
3f76745e | 799 | } |
a3f97cbb JW |
800 | } |
801 | ||
3f76745e | 802 | /* Find the previous value for the CFA. */ |
71dfc51f | 803 | |
3f76745e | 804 | static void |
7d9d8943 AM |
805 | lookup_cfa (loc) |
806 | register dw_cfa_location *loc; | |
a3f97cbb | 807 | { |
3f76745e JM |
808 | register dw_cfi_ref cfi; |
809 | ||
7d9d8943 AM |
810 | loc->reg = (unsigned long) -1; |
811 | loc->offset = 0; | |
812 | loc->indirect = 0; | |
813 | loc->base_offset = 0; | |
3f76745e JM |
814 | |
815 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 816 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
817 | |
818 | if (fde_table_in_use) | |
a3f97cbb | 819 | { |
3f76745e JM |
820 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
821 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 822 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
823 | } |
824 | } | |
825 | ||
3f76745e | 826 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
7d9d8943 | 827 | dw_cfa_location cfa; |
71dfc51f | 828 | |
3f76745e JM |
829 | /* The register used for saving registers to the stack, and its offset |
830 | from the CFA. */ | |
7d9d8943 | 831 | dw_cfa_location cfa_store; |
3f76745e | 832 | |
0021b564 JM |
833 | /* The running total of the size of arguments pushed onto the stack. */ |
834 | static long args_size; | |
835 | ||
b57d9225 JM |
836 | /* The last args_size we actually output. */ |
837 | static long old_args_size; | |
838 | ||
3f76745e JM |
839 | /* Entry point to update the canonical frame address (CFA). |
840 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
841 | calculated from REG+OFFSET. */ | |
842 | ||
843 | void | |
844 | dwarf2out_def_cfa (label, reg, offset) | |
d3e3972c | 845 | register const char *label; |
7d9d8943 AM |
846 | unsigned reg; |
847 | long offset; | |
848 | { | |
849 | dw_cfa_location loc; | |
850 | loc.indirect = 0; | |
851 | loc.base_offset = 0; | |
852 | loc.reg = reg; | |
853 | loc.offset = offset; | |
854 | def_cfa_1 (label, &loc); | |
855 | } | |
856 | ||
857 | /* This routine does the actual work. The CFA is now calculated from | |
858 | the dw_cfa_location structure. */ | |
859 | static void | |
860 | def_cfa_1 (label, loc_p) | |
861 | register const char *label; | |
862 | dw_cfa_location *loc_p; | |
a3f97cbb | 863 | { |
3f76745e | 864 | register dw_cfi_ref cfi; |
7d9d8943 | 865 | dw_cfa_location old_cfa, loc; |
3f76745e | 866 | |
7d9d8943 AM |
867 | cfa = *loc_p; |
868 | loc = *loc_p; | |
5bef9b1f | 869 | |
7d9d8943 AM |
870 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
871 | cfa_store.offset = loc.offset; | |
3f76745e | 872 | |
7d9d8943 AM |
873 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
874 | lookup_cfa (&old_cfa); | |
875 | ||
876 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset && | |
877 | loc.indirect == old_cfa.indirect) | |
878 | { | |
e09bbb25 JM |
879 | if (loc.indirect == 0 |
880 | || loc.base_offset == old_cfa.base_offset) | |
7d9d8943 | 881 | return; |
7d9d8943 | 882 | } |
3f76745e JM |
883 | |
884 | cfi = new_cfi (); | |
885 | ||
e09bbb25 | 886 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 887 | { |
3f76745e | 888 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 889 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 890 | } |
a3f97cbb | 891 | |
3f76745e | 892 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 893 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 894 | && !loc.indirect) |
3f76745e JM |
895 | { |
896 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; | |
7d9d8943 | 897 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
898 | } |
899 | #endif | |
a3f97cbb | 900 | |
7d9d8943 | 901 | else if (loc.indirect == 0) |
3f76745e JM |
902 | { |
903 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
7d9d8943 AM |
904 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
905 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
906 | } | |
907 | else | |
908 | { | |
556273e0 | 909 | struct dw_loc_descr_struct *loc_list; |
7d9d8943 AM |
910 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
911 | loc_list = build_cfa_loc (&loc); | |
912 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 913 | } |
3f76745e JM |
914 | |
915 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
916 | } |
917 | ||
3f76745e JM |
918 | /* Add the CFI for saving a register. REG is the CFA column number. |
919 | LABEL is passed to add_fde_cfi. | |
920 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
921 | otherwise it is saved in SREG. */ | |
71dfc51f | 922 | |
3f76745e JM |
923 | static void |
924 | reg_save (label, reg, sreg, offset) | |
d3e3972c | 925 | register const char *label; |
3f76745e JM |
926 | register unsigned reg; |
927 | register unsigned sreg; | |
928 | register long offset; | |
a3f97cbb | 929 | { |
3f76745e JM |
930 | register dw_cfi_ref cfi = new_cfi (); |
931 | ||
932 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
933 | ||
85066503 MH |
934 | /* The following comparison is correct. -1 is used to indicate that |
935 | the value isn't a register number. */ | |
936 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 937 | { |
3f76745e JM |
938 | if (reg & ~0x3f) |
939 | /* The register number won't fit in 6 bits, so we have to use | |
940 | the long form. */ | |
941 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
942 | else | |
943 | cfi->dw_cfi_opc = DW_CFA_offset; | |
944 | ||
27c35f4b HPN |
945 | #ifdef ENABLE_CHECKING |
946 | { | |
947 | /* If we get an offset that is not a multiple of | |
948 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
949 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
950 | description. */ | |
951 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
952 | ||
953 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
954 | abort (); | |
955 | } | |
956 | #endif | |
3f76745e | 957 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 958 | if (offset < 0) |
3f388b42 GK |
959 | { |
960 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
961 | offset = -offset; | |
962 | } | |
3f76745e JM |
963 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
964 | } | |
2c849145 JM |
965 | else if (sreg == reg) |
966 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
967 | return; | |
3f76745e JM |
968 | else |
969 | { | |
970 | cfi->dw_cfi_opc = DW_CFA_register; | |
971 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
972 | } | |
973 | ||
974 | add_fde_cfi (label, cfi); | |
975 | } | |
976 | ||
c53aa195 JM |
977 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
978 | This CFI tells the unwinder that it needs to restore the window registers | |
979 | from the previous frame's window save area. | |
556273e0 | 980 | |
c53aa195 JM |
981 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
982 | assuming 0(cfa)) and what registers are in the window. */ | |
983 | ||
984 | void | |
985 | dwarf2out_window_save (label) | |
d3e3972c | 986 | register const char *label; |
c53aa195 JM |
987 | { |
988 | register dw_cfi_ref cfi = new_cfi (); | |
989 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
990 | add_fde_cfi (label, cfi); | |
991 | } | |
992 | ||
0021b564 JM |
993 | /* Add a CFI to update the running total of the size of arguments |
994 | pushed onto the stack. */ | |
995 | ||
996 | void | |
997 | dwarf2out_args_size (label, size) | |
d3e3972c | 998 | const char *label; |
0021b564 JM |
999 | long size; |
1000 | { | |
b57d9225 JM |
1001 | register dw_cfi_ref cfi; |
1002 | ||
1003 | if (size == old_args_size) | |
1004 | return; | |
1005 | old_args_size = size; | |
1006 | ||
1007 | cfi = new_cfi (); | |
0021b564 JM |
1008 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
1009 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
1010 | add_fde_cfi (label, cfi); | |
1011 | } | |
1012 | ||
c53aa195 JM |
1013 | /* Entry point for saving a register to the stack. REG is the GCC register |
1014 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
1015 | |
1016 | void | |
1017 | dwarf2out_reg_save (label, reg, offset) | |
d3e3972c | 1018 | register const char *label; |
3f76745e JM |
1019 | register unsigned reg; |
1020 | register long offset; | |
1021 | { | |
1022 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
1023 | } | |
1024 | ||
c53aa195 JM |
1025 | /* Entry point for saving the return address in the stack. |
1026 | LABEL and OFFSET are passed to reg_save. */ | |
1027 | ||
1028 | void | |
1029 | dwarf2out_return_save (label, offset) | |
d3e3972c | 1030 | register const char *label; |
c53aa195 JM |
1031 | register long offset; |
1032 | { | |
1033 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
1034 | } | |
1035 | ||
1036 | /* Entry point for saving the return address in a register. | |
1037 | LABEL and SREG are passed to reg_save. */ | |
1038 | ||
1039 | void | |
1040 | dwarf2out_return_reg (label, sreg) | |
d3e3972c | 1041 | register const char *label; |
c53aa195 JM |
1042 | register unsigned sreg; |
1043 | { | |
1044 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
1045 | } | |
1046 | ||
3f76745e JM |
1047 | /* Record the initial position of the return address. RTL is |
1048 | INCOMING_RETURN_ADDR_RTX. */ | |
1049 | ||
1050 | static void | |
1051 | initial_return_save (rtl) | |
1052 | register rtx rtl; | |
1053 | { | |
973838fd | 1054 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
1055 | long offset = 0; |
1056 | ||
1057 | switch (GET_CODE (rtl)) | |
1058 | { | |
1059 | case REG: | |
1060 | /* RA is in a register. */ | |
2c849145 | 1061 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e JM |
1062 | break; |
1063 | case MEM: | |
1064 | /* RA is on the stack. */ | |
1065 | rtl = XEXP (rtl, 0); | |
1066 | switch (GET_CODE (rtl)) | |
1067 | { | |
1068 | case REG: | |
3a88cbd1 JL |
1069 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
1070 | abort (); | |
3f76745e JM |
1071 | offset = 0; |
1072 | break; | |
1073 | case PLUS: | |
3a88cbd1 JL |
1074 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1075 | abort (); | |
3f76745e JM |
1076 | offset = INTVAL (XEXP (rtl, 1)); |
1077 | break; | |
1078 | case MINUS: | |
3a88cbd1 JL |
1079 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
1080 | abort (); | |
3f76745e JM |
1081 | offset = -INTVAL (XEXP (rtl, 1)); |
1082 | break; | |
1083 | default: | |
1084 | abort (); | |
1085 | } | |
1086 | break; | |
c53aa195 JM |
1087 | case PLUS: |
1088 | /* The return address is at some offset from any value we can | |
1089 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
1090 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
1091 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
1092 | abort (); | |
c53aa195 JM |
1093 | initial_return_save (XEXP (rtl, 0)); |
1094 | return; | |
a3f97cbb | 1095 | default: |
3f76745e | 1096 | abort (); |
a3f97cbb | 1097 | } |
3f76745e | 1098 | |
7d9d8943 | 1099 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
1100 | } |
1101 | ||
1ba5ae8f AH |
1102 | /* Given a SET, calculate the amount of stack adjustment it |
1103 | contains. */ | |
1104 | ||
5e640c56 AH |
1105 | static long |
1106 | stack_adjust_offset (pattern) | |
1ba5ae8f AH |
1107 | rtx pattern; |
1108 | { | |
1109 | rtx src = SET_SRC (pattern); | |
1110 | rtx dest = SET_DEST (pattern); | |
1111 | long offset = 0; | |
1112 | enum rtx_code code; | |
1113 | ||
1114 | if (dest == stack_pointer_rtx) | |
1115 | { | |
1116 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
1117 | code = GET_CODE (src); | |
1118 | if (! (code == PLUS || code == MINUS) | |
1119 | || XEXP (src, 0) != stack_pointer_rtx | |
1120 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1121 | return 0; | |
1122 | ||
1123 | offset = INTVAL (XEXP (src, 1)); | |
1124 | } | |
1125 | else if (GET_CODE (dest) == MEM) | |
1126 | { | |
1127 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1128 | src = XEXP (dest, 0); | |
1129 | code = GET_CODE (src); | |
1130 | ||
1131 | if (! (code == PRE_DEC || code == PRE_INC) | |
1132 | || XEXP (src, 0) != stack_pointer_rtx) | |
1133 | return 0; | |
1134 | ||
1135 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1136 | } | |
1137 | else | |
1138 | return 0; | |
1139 | ||
1140 | if (code == PLUS || code == PRE_INC) | |
1141 | offset = -offset; | |
1142 | ||
1143 | return offset; | |
1144 | } | |
1145 | ||
0021b564 JM |
1146 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1147 | make a note of it if it does. EH uses this information to find out how | |
1148 | much extra space it needs to pop off the stack. */ | |
1149 | ||
1150 | static void | |
1151 | dwarf2out_stack_adjust (insn) | |
1152 | rtx insn; | |
1153 | { | |
0021b564 | 1154 | long offset; |
d3e3972c | 1155 | const char *label; |
0021b564 | 1156 | |
b57d9225 JM |
1157 | if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN) |
1158 | { | |
1159 | /* Extract the size of the args from the CALL rtx itself. */ | |
1160 | ||
1161 | insn = PATTERN (insn); | |
1162 | if (GET_CODE (insn) == PARALLEL) | |
1163 | insn = XVECEXP (insn, 0, 0); | |
1164 | if (GET_CODE (insn) == SET) | |
1165 | insn = SET_SRC (insn); | |
3db35af4 MM |
1166 | if (GET_CODE (insn) != CALL) |
1167 | abort (); | |
b57d9225 JM |
1168 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1169 | return; | |
1170 | } | |
1171 | ||
1172 | /* If only calls can throw, and we have a frame pointer, | |
1173 | save up adjustments until we see the CALL_INSN. */ | |
1174 | else if (! asynchronous_exceptions | |
7d9d8943 | 1175 | && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1176 | return; |
1177 | ||
6020d360 | 1178 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1179 | { |
6020d360 JM |
1180 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1181 | the compiler will have already emitted a stack adjustment, but | |
1182 | doesn't bother for calls to noreturn functions. */ | |
1183 | #ifdef STACK_GROWS_DOWNWARD | |
1184 | offset = -args_size; | |
1185 | #else | |
1186 | offset = args_size; | |
1187 | #endif | |
0021b564 | 1188 | } |
6020d360 | 1189 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 1190 | { |
1ba5ae8f AH |
1191 | offset = stack_adjust_offset (PATTERN (insn)); |
1192 | } | |
1193 | else if (GET_CODE (PATTERN (insn)) == PARALLEL | |
1194 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1195 | { | |
1196 | /* There may be stack adjustments inside compound insns. Search | |
1197 | for them. */ | |
1198 | int j; | |
0021b564 | 1199 | |
1ba5ae8f AH |
1200 | offset = 0; |
1201 | for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--) | |
6020d360 | 1202 | { |
1ba5ae8f AH |
1203 | rtx pattern = XVECEXP (PATTERN (insn), 0, j); |
1204 | if (GET_CODE (pattern) == SET) | |
1205 | offset += stack_adjust_offset (pattern); | |
6020d360 | 1206 | } |
0021b564 JM |
1207 | } |
1208 | else | |
1209 | return; | |
1ba5ae8f | 1210 | |
6020d360 JM |
1211 | if (offset == 0) |
1212 | return; | |
1213 | ||
7d9d8943 AM |
1214 | if (cfa.reg == STACK_POINTER_REGNUM) |
1215 | cfa.offset += offset; | |
0021b564 JM |
1216 | |
1217 | #ifndef STACK_GROWS_DOWNWARD | |
1218 | offset = -offset; | |
1219 | #endif | |
1220 | args_size += offset; | |
1221 | if (args_size < 0) | |
1222 | args_size = 0; | |
1223 | ||
1224 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1225 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1226 | dwarf2out_args_size (label, args_size); |
1227 | } | |
1228 | ||
b664de3a AM |
1229 | /* A temporary register used in adjusting SP or setting up the store_reg. */ |
1230 | static unsigned cfa_temp_reg; | |
1231 | ||
1232 | /* A temporary value used in adjusting SP or setting up the store_reg. */ | |
1233 | static long cfa_temp_value; | |
1234 | ||
1235 | /* Record call frame debugging information for an expression, which either | |
1236 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
556273e0 | 1237 | register to the stack. */ |
b664de3a AM |
1238 | |
1239 | static void | |
1240 | dwarf2out_frame_debug_expr (expr, label) | |
1241 | rtx expr; | |
d3e3972c | 1242 | const char *label; |
b664de3a AM |
1243 | { |
1244 | rtx src, dest; | |
1245 | long offset; | |
556273e0 KH |
1246 | |
1247 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1248 | the PARALLEL independently. The first element is always processed if | |
1249 | it is a SET. This is for backward compatability. Other elements | |
1250 | are processed only if they are SETs and the RTX_FRAME_RELATED_P | |
1251 | flag is set in them. */ | |
b664de3a | 1252 | |
79d13342 NC |
1253 | if (GET_CODE (expr) == PARALLEL |
1254 | || GET_CODE (expr) == SEQUENCE) | |
556273e0 | 1255 | { |
b664de3a AM |
1256 | int par_index; |
1257 | int limit = XVECLEN (expr, 0); | |
1258 | ||
1259 | for (par_index = 0; par_index < limit; par_index++) | |
556273e0 KH |
1260 | { |
1261 | rtx x = XVECEXP (expr, 0, par_index); | |
1262 | ||
1263 | if (GET_CODE (x) == SET && | |
b664de3a | 1264 | (RTX_FRAME_RELATED_P (x) || par_index == 0)) |
2618f955 | 1265 | dwarf2out_frame_debug_expr (x, label); |
556273e0 | 1266 | } |
b664de3a AM |
1267 | return; |
1268 | } | |
556273e0 | 1269 | |
b664de3a AM |
1270 | if (GET_CODE (expr) != SET) |
1271 | abort (); | |
1272 | ||
1273 | src = SET_SRC (expr); | |
1274 | dest = SET_DEST (expr); | |
1275 | ||
1276 | switch (GET_CODE (dest)) | |
1277 | { | |
1278 | case REG: | |
1279 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
1280 | relative to the current CFA register. */ | |
1281 | switch (GET_CODE (src)) | |
556273e0 KH |
1282 | { |
1283 | /* Setting FP from SP. */ | |
1284 | case REG: | |
1285 | if (cfa.reg == (unsigned) REGNO (src)) | |
1286 | /* OK. */ | |
1287 | ; | |
626d1efd | 1288 | else |
556273e0 | 1289 | abort (); |
2c849145 JM |
1290 | |
1291 | /* We used to require that dest be either SP or FP, but the | |
1292 | ARM copies SP to a temporary register, and from there to | |
1293 | FP. So we just rely on the backends to only set | |
1294 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 KH |
1295 | cfa.reg = REGNO (dest); |
1296 | break; | |
b664de3a | 1297 | |
556273e0 KH |
1298 | case PLUS: |
1299 | case MINUS: | |
1300 | if (dest == stack_pointer_rtx) | |
1301 | { | |
2618f955 MM |
1302 | /* Adjusting SP. */ |
1303 | switch (GET_CODE (XEXP (src, 1))) | |
1304 | { | |
1305 | case CONST_INT: | |
1306 | offset = INTVAL (XEXP (src, 1)); | |
1307 | break; | |
1308 | case REG: | |
1309 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg) | |
1310 | abort (); | |
1311 | offset = cfa_temp_value; | |
1312 | break; | |
1313 | default: | |
1314 | abort (); | |
1315 | } | |
1316 | ||
1317 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1318 | { | |
1319 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1320 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1321 | abort (); |
7d9d8943 | 1322 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 MM |
1323 | } |
1324 | else if (XEXP (src, 0) != stack_pointer_rtx) | |
1325 | abort (); | |
1326 | ||
1327 | if (GET_CODE (src) == PLUS) | |
1328 | offset = -offset; | |
7d9d8943 AM |
1329 | if (cfa.reg == STACK_POINTER_REGNUM) |
1330 | cfa.offset += offset; | |
1331 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1332 | cfa_store.offset += offset; | |
556273e0 KH |
1333 | } |
1334 | else if (dest == hard_frame_pointer_rtx) | |
1335 | { | |
2618f955 MM |
1336 | /* Either setting the FP from an offset of the SP, |
1337 | or adjusting the FP */ | |
2c849145 | 1338 | if (! frame_pointer_needed) |
2618f955 MM |
1339 | abort (); |
1340 | ||
2c849145 | 1341 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1342 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1343 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1344 | { | |
2618f955 MM |
1345 | offset = INTVAL (XEXP (src, 1)); |
1346 | if (GET_CODE (src) == PLUS) | |
1347 | offset = -offset; | |
7d9d8943 AM |
1348 | cfa.offset += offset; |
1349 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1350 | } |
556273e0 KH |
1351 | else |
1352 | abort (); | |
1353 | } | |
1354 | else | |
1355 | { | |
2618f955 MM |
1356 | if (GET_CODE (src) != PLUS |
1357 | || XEXP (src, 1) != stack_pointer_rtx) | |
1358 | abort (); | |
1359 | if (GET_CODE (XEXP (src, 0)) != REG | |
1360 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg) | |
1361 | abort (); | |
7d9d8943 | 1362 | if (cfa.reg != STACK_POINTER_REGNUM) |
2618f955 | 1363 | abort (); |
7d9d8943 AM |
1364 | cfa_store.reg = REGNO (dest); |
1365 | cfa_store.offset = cfa.offset - cfa_temp_value; | |
556273e0 KH |
1366 | } |
1367 | break; | |
b664de3a | 1368 | |
556273e0 KH |
1369 | case CONST_INT: |
1370 | cfa_temp_reg = REGNO (dest); | |
1371 | cfa_temp_value = INTVAL (src); | |
1372 | break; | |
b664de3a | 1373 | |
556273e0 KH |
1374 | case IOR: |
1375 | if (GET_CODE (XEXP (src, 0)) != REG | |
2618f955 MM |
1376 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg |
1377 | || (unsigned) REGNO (dest) != cfa_temp_reg | |
1378 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
556273e0 KH |
1379 | abort (); |
1380 | cfa_temp_value |= INTVAL (XEXP (src, 1)); | |
1381 | break; | |
b664de3a | 1382 | |
556273e0 KH |
1383 | default: |
1384 | abort (); | |
1385 | } | |
7d9d8943 | 1386 | def_cfa_1 (label, &cfa); |
2618f955 | 1387 | break; |
b664de3a | 1388 | |
ab577d8a MM |
1389 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, which |
1390 | will fill in all of the bits. */ | |
1391 | case HIGH: | |
1392 | break; | |
1393 | ||
1394 | case LO_SUM: | |
1395 | cfa_temp_reg = REGNO (dest); | |
1396 | cfa_temp_value = INTVAL (XEXP (src, 1)); | |
1397 | break; | |
1398 | ||
2618f955 | 1399 | case MEM: |
2618f955 MM |
1400 | if (GET_CODE (src) != REG) |
1401 | abort (); | |
7d9d8943 | 1402 | |
7d9d8943 AM |
1403 | /* Saving a register to the stack. Make sure dest is relative to the |
1404 | CFA register. */ | |
2618f955 MM |
1405 | switch (GET_CODE (XEXP (dest, 0))) |
1406 | { | |
1407 | /* With a push. */ | |
1408 | case PRE_INC: | |
1409 | case PRE_DEC: | |
1410 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1411 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1412 | offset = -offset; | |
b664de3a | 1413 | |
2618f955 | 1414 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1415 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1416 | abort (); |
7d9d8943 AM |
1417 | cfa_store.offset += offset; |
1418 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1419 | cfa.offset = cfa_store.offset; | |
b664de3a | 1420 | |
7d9d8943 | 1421 | offset = -cfa_store.offset; |
2618f955 | 1422 | break; |
b664de3a | 1423 | |
2618f955 MM |
1424 | /* With an offset. */ |
1425 | case PLUS: | |
1426 | case MINUS: | |
1427 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); | |
1428 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1429 | offset = -offset; | |
b664de3a | 1430 | |
7d9d8943 | 1431 | if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
2618f955 | 1432 | abort (); |
7d9d8943 | 1433 | offset -= cfa_store.offset; |
2618f955 MM |
1434 | break; |
1435 | ||
1436 | /* Without an offset. */ | |
1437 | case REG: | |
7d9d8943 | 1438 | if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0))) |
556273e0 | 1439 | abort (); |
7d9d8943 | 1440 | offset = -cfa_store.offset; |
2618f955 MM |
1441 | break; |
1442 | ||
1443 | default: | |
1444 | abort (); | |
1445 | } | |
e09bbb25 | 1446 | |
556273e0 | 1447 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1448 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1449 | && (unsigned) REGNO (src) == cfa.reg) | |
1450 | { | |
1451 | /* We're storing the current CFA reg into the stack. */ | |
1452 | ||
1453 | if (cfa.offset == 0) | |
1454 | { | |
1455 | /* If the source register is exactly the CFA, assume | |
1456 | we're saving SP like any other register; this happens | |
1457 | on the ARM. */ | |
1458 | ||
1459 | def_cfa_1 (label, &cfa); | |
1460 | dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset); | |
1461 | break; | |
1462 | } | |
1463 | else | |
1464 | { | |
1465 | /* Otherwise, we'll need to look in the stack to | |
1466 | calculate the CFA. */ | |
1467 | ||
1468 | rtx x = XEXP (dest, 0); | |
1469 | if (GET_CODE (x) != REG) | |
1470 | x = XEXP (x, 0); | |
1471 | if (GET_CODE (x) != REG) | |
1472 | abort (); | |
1473 | cfa.reg = (unsigned) REGNO (x); | |
1474 | cfa.base_offset = offset; | |
1475 | cfa.indirect = 1; | |
1476 | def_cfa_1 (label, &cfa); | |
1477 | break; | |
1478 | } | |
1479 | } | |
1480 | ||
7d9d8943 | 1481 | def_cfa_1 (label, &cfa); |
2618f955 MM |
1482 | dwarf2out_reg_save (label, REGNO (src), offset); |
1483 | break; | |
1484 | ||
1485 | default: | |
1486 | abort (); | |
1487 | } | |
b664de3a AM |
1488 | } |
1489 | ||
3f76745e JM |
1490 | /* Record call frame debugging information for INSN, which either |
1491 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1492 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1493 | |
3f76745e JM |
1494 | void |
1495 | dwarf2out_frame_debug (insn) | |
1496 | rtx insn; | |
a3f97cbb | 1497 | { |
d3e3972c | 1498 | const char *label; |
b664de3a | 1499 | rtx src; |
3f76745e JM |
1500 | |
1501 | if (insn == NULL_RTX) | |
a3f97cbb | 1502 | { |
3f76745e | 1503 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1504 | lookup_cfa (&cfa); |
1505 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1506 | abort (); |
7d9d8943 AM |
1507 | cfa.reg = STACK_POINTER_REGNUM; |
1508 | cfa_store = cfa; | |
3f76745e JM |
1509 | cfa_temp_reg = -1; |
1510 | cfa_temp_value = 0; | |
1511 | return; | |
1512 | } | |
1513 | ||
0021b564 JM |
1514 | if (! RTX_FRAME_RELATED_P (insn)) |
1515 | { | |
6020d360 | 1516 | dwarf2out_stack_adjust (insn); |
0021b564 JM |
1517 | return; |
1518 | } | |
1519 | ||
3f76745e | 1520 | label = dwarf2out_cfi_label (); |
556273e0 | 1521 | |
07ebc930 RH |
1522 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1523 | if (src) | |
1524 | insn = XEXP (src, 0); | |
556273e0 | 1525 | else |
07ebc930 RH |
1526 | insn = PATTERN (insn); |
1527 | ||
b664de3a | 1528 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1529 | } |
1530 | ||
1531 | /* Return the size of an unsigned LEB128 quantity. */ | |
1532 | ||
1533 | static inline unsigned long | |
1534 | size_of_uleb128 (value) | |
1535 | register unsigned long value; | |
1536 | { | |
1537 | register unsigned long size = 0; | |
1538 | register unsigned byte; | |
1539 | ||
1540 | do | |
1541 | { | |
1542 | byte = (value & 0x7f); | |
1543 | value >>= 7; | |
1544 | size += 1; | |
1545 | } | |
1546 | while (value != 0); | |
1547 | ||
1548 | return size; | |
1549 | } | |
1550 | ||
1551 | /* Return the size of a signed LEB128 quantity. */ | |
1552 | ||
1553 | static inline unsigned long | |
1554 | size_of_sleb128 (value) | |
1555 | register long value; | |
1556 | { | |
1557 | register unsigned long size = 0; | |
1558 | register unsigned byte; | |
1559 | ||
1560 | do | |
1561 | { | |
1562 | byte = (value & 0x7f); | |
1563 | value >>= 7; | |
1564 | size += 1; | |
1565 | } | |
1566 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
1567 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1568 | ||
1569 | return size; | |
1570 | } | |
1571 | ||
3f76745e JM |
1572 | /* Output an unsigned LEB128 quantity. */ |
1573 | ||
1574 | static void | |
1575 | output_uleb128 (value) | |
1576 | register unsigned long value; | |
1577 | { | |
1578 | unsigned long save_value = value; | |
1579 | ||
e8638df0 | 1580 | fprintf (asm_out_file, "%s", ASM_BYTE_OP); |
3f76745e JM |
1581 | do |
1582 | { | |
1583 | register unsigned byte = (value & 0x7f); | |
1584 | value >>= 7; | |
1585 | if (value != 0) | |
1586 | /* More bytes to follow. */ | |
1587 | byte |= 0x80; | |
1588 | ||
1589 | fprintf (asm_out_file, "0x%x", byte); | |
1590 | if (value != 0) | |
1591 | fprintf (asm_out_file, ","); | |
1592 | } | |
1593 | while (value != 0); | |
1594 | ||
c5cec899 | 1595 | if (flag_debug_asm) |
2d8b0f3a | 1596 | fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value); |
3f76745e JM |
1597 | } |
1598 | ||
1599 | /* Output an signed LEB128 quantity. */ | |
1600 | ||
1601 | static void | |
1602 | output_sleb128 (value) | |
1603 | register long value; | |
1604 | { | |
1605 | register int more; | |
1606 | register unsigned byte; | |
1607 | long save_value = value; | |
1608 | ||
e8638df0 | 1609 | fprintf (asm_out_file, "%s", ASM_BYTE_OP); |
3f76745e JM |
1610 | do |
1611 | { | |
1612 | byte = (value & 0x7f); | |
1613 | /* arithmetic shift */ | |
1614 | value >>= 7; | |
1615 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
1616 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1617 | if (more) | |
1618 | byte |= 0x80; | |
1619 | ||
1620 | fprintf (asm_out_file, "0x%x", byte); | |
1621 | if (more) | |
1622 | fprintf (asm_out_file, ","); | |
1623 | } | |
1624 | ||
1625 | while (more); | |
c5cec899 | 1626 | if (flag_debug_asm) |
2d8b0f3a | 1627 | fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value); |
3f76745e JM |
1628 | } |
1629 | ||
1630 | /* Output a Call Frame Information opcode and its operand(s). */ | |
1631 | ||
1632 | static void | |
1633 | output_cfi (cfi, fde) | |
1634 | register dw_cfi_ref cfi; | |
1635 | register dw_fde_ref fde; | |
1636 | { | |
1637 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1638 | { | |
1639 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1640 | cfi->dw_cfi_opc | |
1641 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
c5cec899 | 1642 | if (flag_debug_asm) |
2d8b0f3a | 1643 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx", |
3f76745e JM |
1644 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset); |
1645 | fputc ('\n', asm_out_file); | |
1646 | } | |
1647 | ||
1648 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
1649 | { | |
1650 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1651 | cfi->dw_cfi_opc | |
1652 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1653 | if (flag_debug_asm) |
2d8b0f3a | 1654 | fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx", |
3f76745e JM |
1655 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1656 | ||
1657 | fputc ('\n', asm_out_file); | |
1658 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1659 | fputc ('\n', asm_out_file); | |
1660 | } | |
1661 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1662 | { | |
1663 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1664 | cfi->dw_cfi_opc | |
1665 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
c5cec899 | 1666 | if (flag_debug_asm) |
2d8b0f3a | 1667 | fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx", |
3f76745e JM |
1668 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); |
1669 | ||
1670 | fputc ('\n', asm_out_file); | |
1671 | } | |
1672 | else | |
1673 | { | |
1674 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
c5cec899 | 1675 | if (flag_debug_asm) |
3f76745e JM |
1676 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, |
1677 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
1678 | ||
1679 | fputc ('\n', asm_out_file); | |
1680 | switch (cfi->dw_cfi_opc) | |
1681 | { | |
1682 | case DW_CFA_set_loc: | |
556273e0 KH |
1683 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr); |
1684 | fputc ('\n', asm_out_file); | |
3f76745e JM |
1685 | break; |
1686 | case DW_CFA_advance_loc1: | |
bb727b5a JM |
1687 | ASM_OUTPUT_DWARF_DELTA1 (asm_out_file, |
1688 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1689 | fde->dw_fde_current_label); | |
1690 | fputc ('\n', asm_out_file); | |
1691 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e JM |
1692 | break; |
1693 | case DW_CFA_advance_loc2: | |
556273e0 | 1694 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, |
3f76745e JM |
1695 | cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1696 | fde->dw_fde_current_label); | |
1697 | fputc ('\n', asm_out_file); | |
1698 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1699 | break; | |
1700 | case DW_CFA_advance_loc4: | |
556273e0 | 1701 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, |
3f76745e JM |
1702 | cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1703 | fde->dw_fde_current_label); | |
556273e0 | 1704 | fputc ('\n', asm_out_file); |
3f76745e JM |
1705 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1706 | break; | |
1707 | #ifdef MIPS_DEBUGGING_INFO | |
1708 | case DW_CFA_MIPS_advance_loc8: | |
1709 | /* TODO: not currently implemented. */ | |
1710 | abort (); | |
1711 | break; | |
1712 | #endif | |
1713 | case DW_CFA_offset_extended: | |
3f388b42 | 1714 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e JM |
1715 | case DW_CFA_def_cfa: |
1716 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
556273e0 | 1717 | fputc ('\n', asm_out_file); |
3f76745e | 1718 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); |
556273e0 | 1719 | fputc ('\n', asm_out_file); |
3f76745e JM |
1720 | break; |
1721 | case DW_CFA_restore_extended: | |
1722 | case DW_CFA_undefined: | |
1723 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
556273e0 | 1724 | fputc ('\n', asm_out_file); |
3f76745e JM |
1725 | break; |
1726 | case DW_CFA_same_value: | |
1727 | case DW_CFA_def_cfa_register: | |
1728 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
556273e0 | 1729 | fputc ('\n', asm_out_file); |
3f76745e JM |
1730 | break; |
1731 | case DW_CFA_register: | |
1732 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
556273e0 | 1733 | fputc ('\n', asm_out_file); |
3f76745e | 1734 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num); |
556273e0 | 1735 | fputc ('\n', asm_out_file); |
3f76745e JM |
1736 | break; |
1737 | case DW_CFA_def_cfa_offset: | |
1738 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
556273e0 | 1739 | fputc ('\n', asm_out_file); |
3f76745e | 1740 | break; |
c53aa195 JM |
1741 | case DW_CFA_GNU_window_save: |
1742 | break; | |
0021b564 JM |
1743 | case DW_CFA_GNU_args_size: |
1744 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
556273e0 | 1745 | fputc ('\n', asm_out_file); |
0021b564 | 1746 | break; |
7d9d8943 AM |
1747 | case DW_CFA_def_cfa_expression: |
1748 | output_cfa_loc (cfi); | |
1749 | break; | |
3f76745e JM |
1750 | default: |
1751 | break; | |
1752 | } | |
556273e0 | 1753 | } |
3f76745e JM |
1754 | } |
1755 | ||
1756 | /* Output the call frame information used to used to record information | |
1757 | that relates to calculating the frame pointer, and records the | |
1758 | location of saved registers. */ | |
1759 | ||
1760 | static void | |
1761 | output_call_frame_info (for_eh) | |
1762 | int for_eh; | |
1763 | { | |
2d8b0f3a | 1764 | register unsigned long i; |
3f76745e | 1765 | register dw_fde_ref fde; |
3f76745e | 1766 | register dw_cfi_ref cfi; |
a6ab3aad | 1767 | char l1[20], l2[20]; |
2ed2af28 PDM |
1768 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1769 | char ld[20]; | |
1770 | #endif | |
a6ab3aad JM |
1771 | |
1772 | /* Do we want to include a pointer to the exception table? */ | |
1773 | int eh_ptr = for_eh && exception_table_p (); | |
3f76745e | 1774 | |
737faf14 JM |
1775 | /* If we don't have any functions we'll want to unwind out of, don't |
1776 | emit any EH unwind information. */ | |
1777 | if (for_eh) | |
1778 | { | |
1779 | for (i = 0; i < fde_table_in_use; ++i) | |
1780 | if (! fde_table[i].nothrow) | |
1781 | goto found; | |
1782 | return; | |
1783 | found:; | |
1784 | } | |
1785 | ||
3f76745e | 1786 | fputc ('\n', asm_out_file); |
e9e30253 | 1787 | |
aa0c1401 JL |
1788 | /* We're going to be generating comments, so turn on app. */ |
1789 | if (flag_debug_asm) | |
1790 | app_enable (); | |
956d6950 | 1791 | |
3f76745e JM |
1792 | if (for_eh) |
1793 | { | |
1794 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1795 | EH_FRAME_SECTION (); |
3f76745e | 1796 | #else |
496651db | 1797 | tree label = get_file_function_name ('F'); |
0021b564 | 1798 | |
3167de5b | 1799 | force_data_section (); |
a1a4189d | 1800 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
0021b564 JM |
1801 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1802 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1803 | #endif |
1804 | assemble_label ("__FRAME_BEGIN__"); | |
1805 | } | |
1806 | else | |
1807 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
1808 | ||
556273e0 | 1809 | /* Output the CIE. */ |
a6ab3aad JM |
1810 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1811 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2ed2af28 PDM |
1812 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1813 | ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh); | |
1814 | if (for_eh) | |
7bb9fb0e | 1815 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1816 | else |
1817 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1818 | #else | |
267c09ab JM |
1819 | if (for_eh) |
1820 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1821 | else | |
1822 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1823 | #endif |
c5cec899 | 1824 | if (flag_debug_asm) |
3f76745e JM |
1825 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", |
1826 | ASM_COMMENT_START); | |
1827 | ||
1828 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1829 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1830 | ||
d84e64d4 JM |
1831 | if (for_eh) |
1832 | /* Now that the CIE pointer is PC-relative for EH, | |
1833 | use 0 to identify the CIE. */ | |
1834 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
1835 | else | |
1836 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1837 | ||
c5cec899 | 1838 | if (flag_debug_asm) |
3f76745e JM |
1839 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START); |
1840 | ||
1841 | fputc ('\n', asm_out_file); | |
d84e64d4 | 1842 | if (! for_eh && DWARF_OFFSET_SIZE == 8) |
3f76745e JM |
1843 | { |
1844 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1845 | fputc ('\n', asm_out_file); | |
1846 | } | |
1847 | ||
1848 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
c5cec899 | 1849 | if (flag_debug_asm) |
3f76745e JM |
1850 | fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START); |
1851 | ||
1852 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1853 | if (eh_ptr) |
1854 | { | |
d84e64d4 JM |
1855 | /* The CIE contains a pointer to the exception region info for the |
1856 | frame. Make the augmentation string three bytes (including the | |
1857 | trailing null) so the pointer is 4-byte aligned. The Solaris ld | |
1858 | can't handle unaligned relocs. */ | |
c5cec899 | 1859 | if (flag_debug_asm) |
8d4e65a6 JL |
1860 | { |
1861 | ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh"); | |
1862 | fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START); | |
1863 | } | |
1864 | else | |
1865 | { | |
c2c85462 | 1866 | ASM_OUTPUT_ASCII (asm_out_file, "eh", 3); |
8d4e65a6 | 1867 | } |
d84e64d4 JM |
1868 | fputc ('\n', asm_out_file); |
1869 | ||
1870 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__"); | |
1871 | if (flag_debug_asm) | |
1872 | fprintf (asm_out_file, "\t%s pointer to exception region info", | |
1873 | ASM_COMMENT_START); | |
a6ab3aad JM |
1874 | } |
1875 | else | |
1876 | { | |
1877 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 1878 | if (flag_debug_asm) |
a6ab3aad JM |
1879 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", |
1880 | ASM_COMMENT_START); | |
1881 | } | |
3f76745e JM |
1882 | |
1883 | fputc ('\n', asm_out_file); | |
1884 | output_uleb128 (1); | |
c5cec899 | 1885 | if (flag_debug_asm) |
3f76745e JM |
1886 | fprintf (asm_out_file, " (CIE Code Alignment Factor)"); |
1887 | ||
1888 | fputc ('\n', asm_out_file); | |
1889 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
c5cec899 | 1890 | if (flag_debug_asm) |
3f76745e JM |
1891 | fprintf (asm_out_file, " (CIE Data Alignment Factor)"); |
1892 | ||
1893 | fputc ('\n', asm_out_file); | |
1894 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN); | |
c5cec899 | 1895 | if (flag_debug_asm) |
3f76745e JM |
1896 | fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START); |
1897 | ||
1898 | fputc ('\n', asm_out_file); | |
1899 | ||
1900 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1901 | output_cfi (cfi, NULL); | |
1902 | ||
1903 | /* Pad the CIE out to an address sized boundary. */ | |
a1a4189d | 1904 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
a6ab3aad | 1905 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
2ed2af28 PDM |
1906 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1907 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1908 | if (flag_debug_asm) |
1909 | fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START); | |
1910 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1911 | #endif |
3f76745e JM |
1912 | |
1913 | /* Loop through all of the FDE's. */ | |
1914 | for (i = 0; i < fde_table_in_use; ++i) | |
1915 | { | |
1916 | fde = &fde_table[i]; | |
3f76745e | 1917 | |
737faf14 JM |
1918 | /* Don't emit EH unwind info for leaf functions. */ |
1919 | if (for_eh && fde->nothrow) | |
1920 | continue; | |
1921 | ||
556273e0 KH |
1922 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1923 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2ed2af28 | 1924 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
556273e0 | 1925 | ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2); |
2ed2af28 | 1926 | if (for_eh) |
7bb9fb0e | 1927 | ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld); |
2ed2af28 PDM |
1928 | else |
1929 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld); | |
1930 | #else | |
267c09ab JM |
1931 | if (for_eh) |
1932 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1); | |
1933 | else | |
1934 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
2ed2af28 | 1935 | #endif |
c5cec899 | 1936 | if (flag_debug_asm) |
3f76745e | 1937 | fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START); |
3f76745e | 1938 | fputc ('\n', asm_out_file); |
a6ab3aad JM |
1939 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1940 | ||
eef906d6 JW |
1941 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1942 | emits a target dependent sized offset when for_eh is not true. | |
1943 | This inconsistency may confuse gdb. The only case where we need a | |
1944 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1945 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1946 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1947 | If the for_eh case is changed, then the struct in frame.c has | |
1948 | to be adjusted appropriately. */ | |
3f76745e | 1949 | if (for_eh) |
21af493b | 1950 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__"); |
3f76745e JM |
1951 | else |
1952 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION)); | |
c5cec899 | 1953 | if (flag_debug_asm) |
3f76745e JM |
1954 | fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START); |
1955 | ||
1956 | fputc ('\n', asm_out_file); | |
1957 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
c5cec899 | 1958 | if (flag_debug_asm) |
3f76745e JM |
1959 | fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START); |
1960 | ||
1961 | fputc ('\n', asm_out_file); | |
1962 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, | |
1963 | fde->dw_fde_end, fde->dw_fde_begin); | |
c5cec899 | 1964 | if (flag_debug_asm) |
3f76745e JM |
1965 | fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START); |
1966 | ||
1967 | fputc ('\n', asm_out_file); | |
1968 | ||
1969 | /* Loop through the Call Frame Instructions associated with | |
1970 | this FDE. */ | |
1971 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1972 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1973 | output_cfi (cfi, fde); | |
1974 | ||
a6ab3aad | 1975 | /* Pad the FDE out to an address sized boundary. */ |
a1a4189d | 1976 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE)); |
a6ab3aad | 1977 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
2ed2af28 PDM |
1978 | #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL |
1979 | ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1); | |
7bb9fb0e JM |
1980 | if (flag_debug_asm) |
1981 | fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START); | |
1982 | fputc ('\n', asm_out_file); | |
2ed2af28 | 1983 | #endif |
3f76745e JM |
1984 | } |
1985 | #ifndef EH_FRAME_SECTION | |
1986 | if (for_eh) | |
1987 | { | |
1988 | /* Emit terminating zero for table. */ | |
267c09ab | 1989 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
3f76745e JM |
1990 | fputc ('\n', asm_out_file); |
1991 | } | |
1992 | #endif | |
a6ab3aad JM |
1993 | #ifdef MIPS_DEBUGGING_INFO |
1994 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1995 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1996 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1997 | #endif | |
aa0c1401 JL |
1998 | |
1999 | /* Turn off app to make assembly quicker. */ | |
2000 | if (flag_debug_asm) | |
2001 | app_disable (); | |
a6ab3aad JM |
2002 | } |
2003 | ||
3f76745e JM |
2004 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2005 | the prologue. */ | |
2006 | ||
2007 | void | |
2008 | dwarf2out_begin_prologue () | |
2009 | { | |
2010 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2011 | register dw_fde_ref fde; | |
2012 | ||
4f988ea2 JM |
2013 | ++current_funcdef_number; |
2014 | ||
3f76745e JM |
2015 | function_section (current_function_decl); |
2016 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2017 | current_funcdef_number); | |
2018 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
00262c8a | 2019 | current_function_func_begin_label = get_identifier (label); |
3f76745e JM |
2020 | |
2021 | /* Expand the fde table if necessary. */ | |
2022 | if (fde_table_in_use == fde_table_allocated) | |
2023 | { | |
2024 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2025 | fde_table | |
2026 | = (dw_fde_ref) xrealloc (fde_table, | |
2027 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2028 | } |
3f76745e JM |
2029 | |
2030 | /* Record the FDE associated with this function. */ | |
2031 | current_funcdef_fde = fde_table_in_use; | |
2032 | ||
2033 | /* Add the new FDE at the end of the fde_table. */ | |
2034 | fde = &fde_table[fde_table_in_use++]; | |
2035 | fde->dw_fde_begin = xstrdup (label); | |
2036 | fde->dw_fde_current_label = NULL; | |
2037 | fde->dw_fde_end = NULL; | |
2038 | fde->dw_fde_cfi = NULL; | |
fb13d4d0 | 2039 | fde->nothrow = current_function_nothrow; |
737faf14 | 2040 | |
b57d9225 | 2041 | args_size = old_args_size = 0; |
3f76745e JM |
2042 | } |
2043 | ||
2044 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2045 | for a function definition. This gets called *after* the epilogue code has | |
2046 | been generated. */ | |
2047 | ||
2048 | void | |
2049 | dwarf2out_end_epilogue () | |
2050 | { | |
2051 | dw_fde_ref fde; | |
2052 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2053 | ||
2054 | /* Output a label to mark the endpoint of the code generated for this | |
2055 | function. */ | |
2056 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
2057 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2058 | fde = &fde_table[fde_table_in_use - 1]; | |
2059 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2060 | } |
2061 | ||
2062 | void | |
2063 | dwarf2out_frame_init () | |
2064 | { | |
2065 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2066 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2067 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2068 | fde_table_in_use = 0; | |
2069 | ||
2070 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2071 | sake of lookup_cfa. */ | |
2072 | ||
a6ab3aad | 2073 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2074 | /* On entry, the Canonical Frame Address is at SP. */ |
2075 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2076 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2077 | #endif |
2078 | } | |
2079 | ||
2080 | void | |
2081 | dwarf2out_frame_finish () | |
2082 | { | |
3f76745e | 2083 | /* Output call frame information. */ |
a6ab3aad | 2084 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
2085 | if (write_symbols == DWARF2_DEBUG) |
2086 | output_call_frame_info (0); | |
14a774a9 | 2087 | if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp)) |
3f76745e | 2088 | output_call_frame_info (1); |
a6ab3aad JM |
2089 | #else |
2090 | if (write_symbols == DWARF2_DEBUG | |
14a774a9 | 2091 | || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp)) |
556273e0 | 2092 | output_call_frame_info (1); |
a6ab3aad | 2093 | #endif |
556273e0 | 2094 | } |
7d9d8943 AM |
2095 | \f |
2096 | /* And now, the subset of the debugging information support code necessary | |
2097 | for emitting location expressions. */ | |
3f76745e | 2098 | |
7d9d8943 AM |
2099 | typedef struct dw_val_struct *dw_val_ref; |
2100 | typedef struct die_struct *dw_die_ref; | |
2101 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
3f76745e JM |
2102 | |
2103 | /* Each DIE may have a series of attribute/value pairs. Values | |
2104 | can take on several forms. The forms that are used in this | |
2105 | implementation are listed below. */ | |
2106 | ||
2107 | typedef enum | |
2108 | { | |
2109 | dw_val_class_addr, | |
2110 | dw_val_class_loc, | |
2111 | dw_val_class_const, | |
2112 | dw_val_class_unsigned_const, | |
2113 | dw_val_class_long_long, | |
2114 | dw_val_class_float, | |
2115 | dw_val_class_flag, | |
2116 | dw_val_class_die_ref, | |
2117 | dw_val_class_fde_ref, | |
2118 | dw_val_class_lbl_id, | |
8b790721 | 2119 | dw_val_class_lbl_offset, |
3f76745e | 2120 | dw_val_class_str |
a3f97cbb | 2121 | } |
3f76745e | 2122 | dw_val_class; |
a3f97cbb | 2123 | |
3f76745e | 2124 | /* Describe a double word constant value. */ |
21217bd0 | 2125 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2126 | |
2127 | typedef struct dw_long_long_struct | |
a3f97cbb | 2128 | { |
3f76745e JM |
2129 | unsigned long hi; |
2130 | unsigned long low; | |
2131 | } | |
2132 | dw_long_long_const; | |
2133 | ||
2134 | /* Describe a floating point constant value. */ | |
2135 | ||
2136 | typedef struct dw_fp_struct | |
2137 | { | |
2138 | long *array; | |
2139 | unsigned length; | |
2140 | } | |
2141 | dw_float_const; | |
2142 | ||
956d6950 | 2143 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2144 | represented internally. */ |
2145 | ||
2146 | typedef struct dw_val_struct | |
2147 | { | |
2148 | dw_val_class val_class; | |
2149 | union | |
a3f97cbb | 2150 | { |
1865dbb5 | 2151 | rtx val_addr; |
3f76745e JM |
2152 | dw_loc_descr_ref val_loc; |
2153 | long int val_int; | |
2154 | long unsigned val_unsigned; | |
2155 | dw_long_long_const val_long_long; | |
2156 | dw_float_const val_float; | |
881c6935 JM |
2157 | struct { |
2158 | dw_die_ref die; | |
2159 | int external; | |
2160 | } val_die_ref; | |
3f76745e JM |
2161 | unsigned val_fde_index; |
2162 | char *val_str; | |
2163 | char *val_lbl_id; | |
3f76745e | 2164 | unsigned char val_flag; |
a3f97cbb | 2165 | } |
3f76745e JM |
2166 | v; |
2167 | } | |
2168 | dw_val_node; | |
2169 | ||
2170 | /* Locations in memory are described using a sequence of stack machine | |
2171 | operations. */ | |
2172 | ||
2173 | typedef struct dw_loc_descr_struct | |
2174 | { | |
2175 | dw_loc_descr_ref dw_loc_next; | |
2176 | enum dwarf_location_atom dw_loc_opc; | |
2177 | dw_val_node dw_loc_oprnd1; | |
2178 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2179 | int dw_loc_addr; |
3f76745e JM |
2180 | } |
2181 | dw_loc_descr_node; | |
2182 | ||
7d9d8943 AM |
2183 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2184 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2185 | unsigned long, | |
2186 | unsigned long)); | |
2187 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2188 | dw_loc_descr_ref)); | |
2189 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2190 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2191 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2192 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2193 | |
7d9d8943 | 2194 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2195 | |
7d9d8943 AM |
2196 | static const char * |
2197 | dwarf_stack_op_name (op) | |
2198 | register unsigned op; | |
ef76d03b | 2199 | { |
7d9d8943 AM |
2200 | switch (op) |
2201 | { | |
2202 | case DW_OP_addr: | |
2203 | return "DW_OP_addr"; | |
2204 | case DW_OP_deref: | |
2205 | return "DW_OP_deref"; | |
2206 | case DW_OP_const1u: | |
2207 | return "DW_OP_const1u"; | |
2208 | case DW_OP_const1s: | |
2209 | return "DW_OP_const1s"; | |
2210 | case DW_OP_const2u: | |
2211 | return "DW_OP_const2u"; | |
2212 | case DW_OP_const2s: | |
2213 | return "DW_OP_const2s"; | |
2214 | case DW_OP_const4u: | |
2215 | return "DW_OP_const4u"; | |
2216 | case DW_OP_const4s: | |
2217 | return "DW_OP_const4s"; | |
2218 | case DW_OP_const8u: | |
2219 | return "DW_OP_const8u"; | |
2220 | case DW_OP_const8s: | |
2221 | return "DW_OP_const8s"; | |
2222 | case DW_OP_constu: | |
2223 | return "DW_OP_constu"; | |
2224 | case DW_OP_consts: | |
2225 | return "DW_OP_consts"; | |
2226 | case DW_OP_dup: | |
2227 | return "DW_OP_dup"; | |
2228 | case DW_OP_drop: | |
2229 | return "DW_OP_drop"; | |
2230 | case DW_OP_over: | |
2231 | return "DW_OP_over"; | |
2232 | case DW_OP_pick: | |
2233 | return "DW_OP_pick"; | |
2234 | case DW_OP_swap: | |
2235 | return "DW_OP_swap"; | |
2236 | case DW_OP_rot: | |
2237 | return "DW_OP_rot"; | |
2238 | case DW_OP_xderef: | |
2239 | return "DW_OP_xderef"; | |
2240 | case DW_OP_abs: | |
2241 | return "DW_OP_abs"; | |
2242 | case DW_OP_and: | |
2243 | return "DW_OP_and"; | |
2244 | case DW_OP_div: | |
2245 | return "DW_OP_div"; | |
2246 | case DW_OP_minus: | |
2247 | return "DW_OP_minus"; | |
2248 | case DW_OP_mod: | |
2249 | return "DW_OP_mod"; | |
2250 | case DW_OP_mul: | |
2251 | return "DW_OP_mul"; | |
2252 | case DW_OP_neg: | |
2253 | return "DW_OP_neg"; | |
2254 | case DW_OP_not: | |
2255 | return "DW_OP_not"; | |
2256 | case DW_OP_or: | |
2257 | return "DW_OP_or"; | |
2258 | case DW_OP_plus: | |
2259 | return "DW_OP_plus"; | |
2260 | case DW_OP_plus_uconst: | |
2261 | return "DW_OP_plus_uconst"; | |
2262 | case DW_OP_shl: | |
2263 | return "DW_OP_shl"; | |
2264 | case DW_OP_shr: | |
2265 | return "DW_OP_shr"; | |
2266 | case DW_OP_shra: | |
2267 | return "DW_OP_shra"; | |
2268 | case DW_OP_xor: | |
2269 | return "DW_OP_xor"; | |
2270 | case DW_OP_bra: | |
2271 | return "DW_OP_bra"; | |
2272 | case DW_OP_eq: | |
2273 | return "DW_OP_eq"; | |
2274 | case DW_OP_ge: | |
2275 | return "DW_OP_ge"; | |
2276 | case DW_OP_gt: | |
2277 | return "DW_OP_gt"; | |
2278 | case DW_OP_le: | |
2279 | return "DW_OP_le"; | |
2280 | case DW_OP_lt: | |
2281 | return "DW_OP_lt"; | |
2282 | case DW_OP_ne: | |
2283 | return "DW_OP_ne"; | |
2284 | case DW_OP_skip: | |
2285 | return "DW_OP_skip"; | |
2286 | case DW_OP_lit0: | |
2287 | return "DW_OP_lit0"; | |
2288 | case DW_OP_lit1: | |
2289 | return "DW_OP_lit1"; | |
2290 | case DW_OP_lit2: | |
2291 | return "DW_OP_lit2"; | |
2292 | case DW_OP_lit3: | |
2293 | return "DW_OP_lit3"; | |
2294 | case DW_OP_lit4: | |
2295 | return "DW_OP_lit4"; | |
2296 | case DW_OP_lit5: | |
2297 | return "DW_OP_lit5"; | |
2298 | case DW_OP_lit6: | |
2299 | return "DW_OP_lit6"; | |
2300 | case DW_OP_lit7: | |
2301 | return "DW_OP_lit7"; | |
2302 | case DW_OP_lit8: | |
2303 | return "DW_OP_lit8"; | |
2304 | case DW_OP_lit9: | |
2305 | return "DW_OP_lit9"; | |
2306 | case DW_OP_lit10: | |
2307 | return "DW_OP_lit10"; | |
2308 | case DW_OP_lit11: | |
2309 | return "DW_OP_lit11"; | |
2310 | case DW_OP_lit12: | |
2311 | return "DW_OP_lit12"; | |
2312 | case DW_OP_lit13: | |
2313 | return "DW_OP_lit13"; | |
2314 | case DW_OP_lit14: | |
2315 | return "DW_OP_lit14"; | |
2316 | case DW_OP_lit15: | |
2317 | return "DW_OP_lit15"; | |
2318 | case DW_OP_lit16: | |
2319 | return "DW_OP_lit16"; | |
2320 | case DW_OP_lit17: | |
2321 | return "DW_OP_lit17"; | |
2322 | case DW_OP_lit18: | |
2323 | return "DW_OP_lit18"; | |
2324 | case DW_OP_lit19: | |
2325 | return "DW_OP_lit19"; | |
2326 | case DW_OP_lit20: | |
2327 | return "DW_OP_lit20"; | |
2328 | case DW_OP_lit21: | |
2329 | return "DW_OP_lit21"; | |
2330 | case DW_OP_lit22: | |
2331 | return "DW_OP_lit22"; | |
2332 | case DW_OP_lit23: | |
2333 | return "DW_OP_lit23"; | |
2334 | case DW_OP_lit24: | |
2335 | return "DW_OP_lit24"; | |
2336 | case DW_OP_lit25: | |
2337 | return "DW_OP_lit25"; | |
2338 | case DW_OP_lit26: | |
2339 | return "DW_OP_lit26"; | |
2340 | case DW_OP_lit27: | |
2341 | return "DW_OP_lit27"; | |
2342 | case DW_OP_lit28: | |
2343 | return "DW_OP_lit28"; | |
2344 | case DW_OP_lit29: | |
2345 | return "DW_OP_lit29"; | |
2346 | case DW_OP_lit30: | |
2347 | return "DW_OP_lit30"; | |
2348 | case DW_OP_lit31: | |
2349 | return "DW_OP_lit31"; | |
2350 | case DW_OP_reg0: | |
2351 | return "DW_OP_reg0"; | |
2352 | case DW_OP_reg1: | |
2353 | return "DW_OP_reg1"; | |
2354 | case DW_OP_reg2: | |
2355 | return "DW_OP_reg2"; | |
2356 | case DW_OP_reg3: | |
2357 | return "DW_OP_reg3"; | |
2358 | case DW_OP_reg4: | |
2359 | return "DW_OP_reg4"; | |
2360 | case DW_OP_reg5: | |
2361 | return "DW_OP_reg5"; | |
2362 | case DW_OP_reg6: | |
2363 | return "DW_OP_reg6"; | |
2364 | case DW_OP_reg7: | |
2365 | return "DW_OP_reg7"; | |
2366 | case DW_OP_reg8: | |
2367 | return "DW_OP_reg8"; | |
2368 | case DW_OP_reg9: | |
2369 | return "DW_OP_reg9"; | |
2370 | case DW_OP_reg10: | |
2371 | return "DW_OP_reg10"; | |
2372 | case DW_OP_reg11: | |
2373 | return "DW_OP_reg11"; | |
2374 | case DW_OP_reg12: | |
2375 | return "DW_OP_reg12"; | |
2376 | case DW_OP_reg13: | |
2377 | return "DW_OP_reg13"; | |
2378 | case DW_OP_reg14: | |
2379 | return "DW_OP_reg14"; | |
2380 | case DW_OP_reg15: | |
2381 | return "DW_OP_reg15"; | |
2382 | case DW_OP_reg16: | |
2383 | return "DW_OP_reg16"; | |
2384 | case DW_OP_reg17: | |
2385 | return "DW_OP_reg17"; | |
2386 | case DW_OP_reg18: | |
2387 | return "DW_OP_reg18"; | |
2388 | case DW_OP_reg19: | |
2389 | return "DW_OP_reg19"; | |
2390 | case DW_OP_reg20: | |
2391 | return "DW_OP_reg20"; | |
2392 | case DW_OP_reg21: | |
2393 | return "DW_OP_reg21"; | |
2394 | case DW_OP_reg22: | |
2395 | return "DW_OP_reg22"; | |
2396 | case DW_OP_reg23: | |
2397 | return "DW_OP_reg23"; | |
2398 | case DW_OP_reg24: | |
2399 | return "DW_OP_reg24"; | |
2400 | case DW_OP_reg25: | |
2401 | return "DW_OP_reg25"; | |
2402 | case DW_OP_reg26: | |
2403 | return "DW_OP_reg26"; | |
2404 | case DW_OP_reg27: | |
2405 | return "DW_OP_reg27"; | |
2406 | case DW_OP_reg28: | |
2407 | return "DW_OP_reg28"; | |
2408 | case DW_OP_reg29: | |
2409 | return "DW_OP_reg29"; | |
2410 | case DW_OP_reg30: | |
2411 | return "DW_OP_reg30"; | |
2412 | case DW_OP_reg31: | |
2413 | return "DW_OP_reg31"; | |
2414 | case DW_OP_breg0: | |
2415 | return "DW_OP_breg0"; | |
2416 | case DW_OP_breg1: | |
2417 | return "DW_OP_breg1"; | |
2418 | case DW_OP_breg2: | |
2419 | return "DW_OP_breg2"; | |
2420 | case DW_OP_breg3: | |
2421 | return "DW_OP_breg3"; | |
2422 | case DW_OP_breg4: | |
2423 | return "DW_OP_breg4"; | |
2424 | case DW_OP_breg5: | |
2425 | return "DW_OP_breg5"; | |
2426 | case DW_OP_breg6: | |
2427 | return "DW_OP_breg6"; | |
2428 | case DW_OP_breg7: | |
2429 | return "DW_OP_breg7"; | |
2430 | case DW_OP_breg8: | |
2431 | return "DW_OP_breg8"; | |
2432 | case DW_OP_breg9: | |
2433 | return "DW_OP_breg9"; | |
2434 | case DW_OP_breg10: | |
2435 | return "DW_OP_breg10"; | |
2436 | case DW_OP_breg11: | |
2437 | return "DW_OP_breg11"; | |
2438 | case DW_OP_breg12: | |
2439 | return "DW_OP_breg12"; | |
2440 | case DW_OP_breg13: | |
2441 | return "DW_OP_breg13"; | |
2442 | case DW_OP_breg14: | |
2443 | return "DW_OP_breg14"; | |
2444 | case DW_OP_breg15: | |
2445 | return "DW_OP_breg15"; | |
2446 | case DW_OP_breg16: | |
2447 | return "DW_OP_breg16"; | |
2448 | case DW_OP_breg17: | |
2449 | return "DW_OP_breg17"; | |
2450 | case DW_OP_breg18: | |
2451 | return "DW_OP_breg18"; | |
2452 | case DW_OP_breg19: | |
2453 | return "DW_OP_breg19"; | |
2454 | case DW_OP_breg20: | |
2455 | return "DW_OP_breg20"; | |
2456 | case DW_OP_breg21: | |
2457 | return "DW_OP_breg21"; | |
2458 | case DW_OP_breg22: | |
2459 | return "DW_OP_breg22"; | |
2460 | case DW_OP_breg23: | |
2461 | return "DW_OP_breg23"; | |
2462 | case DW_OP_breg24: | |
2463 | return "DW_OP_breg24"; | |
2464 | case DW_OP_breg25: | |
2465 | return "DW_OP_breg25"; | |
2466 | case DW_OP_breg26: | |
2467 | return "DW_OP_breg26"; | |
2468 | case DW_OP_breg27: | |
2469 | return "DW_OP_breg27"; | |
2470 | case DW_OP_breg28: | |
2471 | return "DW_OP_breg28"; | |
2472 | case DW_OP_breg29: | |
2473 | return "DW_OP_breg29"; | |
2474 | case DW_OP_breg30: | |
2475 | return "DW_OP_breg30"; | |
2476 | case DW_OP_breg31: | |
2477 | return "DW_OP_breg31"; | |
2478 | case DW_OP_regx: | |
2479 | return "DW_OP_regx"; | |
2480 | case DW_OP_fbreg: | |
2481 | return "DW_OP_fbreg"; | |
2482 | case DW_OP_bregx: | |
2483 | return "DW_OP_bregx"; | |
2484 | case DW_OP_piece: | |
2485 | return "DW_OP_piece"; | |
2486 | case DW_OP_deref_size: | |
2487 | return "DW_OP_deref_size"; | |
2488 | case DW_OP_xderef_size: | |
2489 | return "DW_OP_xderef_size"; | |
2490 | case DW_OP_nop: | |
2491 | return "DW_OP_nop"; | |
3f76745e | 2492 | default: |
7d9d8943 | 2493 | return "OP_<unknown>"; |
3f76745e | 2494 | } |
bdb669cb | 2495 | } |
a3f97cbb | 2496 | |
7d9d8943 AM |
2497 | /* Return a pointer to a newly allocated location description. Location |
2498 | descriptions are simple expression terms that can be strung | |
2499 | together to form more complicated location (address) descriptions. */ | |
2500 | ||
2501 | static inline dw_loc_descr_ref | |
2502 | new_loc_descr (op, oprnd1, oprnd2) | |
2503 | register enum dwarf_location_atom op; | |
2504 | register unsigned long oprnd1; | |
2505 | register unsigned long oprnd2; | |
4b674448 | 2506 | { |
5de0e8d4 JM |
2507 | /* Use xcalloc here so we clear out all of the long_long constant in |
2508 | the union. */ | |
7d9d8943 | 2509 | register dw_loc_descr_ref descr |
5de0e8d4 | 2510 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2511 | |
7d9d8943 AM |
2512 | descr->dw_loc_opc = op; |
2513 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2514 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2515 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2516 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2517 | |
7d9d8943 AM |
2518 | return descr; |
2519 | } | |
2520 | ||
2521 | /* Add a location description term to a location description expression. */ | |
2522 | ||
2523 | static inline void | |
2524 | add_loc_descr (list_head, descr) | |
2525 | register dw_loc_descr_ref *list_head; | |
2526 | register dw_loc_descr_ref descr; | |
2527 | { | |
2528 | register dw_loc_descr_ref *d; | |
2529 | ||
2530 | /* Find the end of the chain. */ | |
2531 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2532 | ; | |
2533 | ||
2534 | *d = descr; | |
2535 | } | |
2536 | ||
2537 | /* Return the size of a location descriptor. */ | |
2538 | ||
2539 | static unsigned long | |
2540 | size_of_loc_descr (loc) | |
2541 | register dw_loc_descr_ref loc; | |
2542 | { | |
2543 | register unsigned long size = 1; | |
2544 | ||
2545 | switch (loc->dw_loc_opc) | |
2546 | { | |
2547 | case DW_OP_addr: | |
2548 | size += DWARF2_ADDR_SIZE; | |
2549 | break; | |
2550 | case DW_OP_const1u: | |
2551 | case DW_OP_const1s: | |
2552 | size += 1; | |
2553 | break; | |
2554 | case DW_OP_const2u: | |
2555 | case DW_OP_const2s: | |
2556 | size += 2; | |
2557 | break; | |
2558 | case DW_OP_const4u: | |
2559 | case DW_OP_const4s: | |
2560 | size += 4; | |
2561 | break; | |
2562 | case DW_OP_const8u: | |
2563 | case DW_OP_const8s: | |
2564 | size += 8; | |
2565 | break; | |
2566 | case DW_OP_constu: | |
2567 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2568 | break; | |
2569 | case DW_OP_consts: | |
2570 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2571 | break; | |
2572 | case DW_OP_pick: | |
2573 | size += 1; | |
2574 | break; | |
2575 | case DW_OP_plus_uconst: | |
2576 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2577 | break; | |
2578 | case DW_OP_skip: | |
2579 | case DW_OP_bra: | |
2580 | size += 2; | |
2581 | break; | |
2582 | case DW_OP_breg0: | |
2583 | case DW_OP_breg1: | |
2584 | case DW_OP_breg2: | |
2585 | case DW_OP_breg3: | |
2586 | case DW_OP_breg4: | |
2587 | case DW_OP_breg5: | |
2588 | case DW_OP_breg6: | |
2589 | case DW_OP_breg7: | |
2590 | case DW_OP_breg8: | |
2591 | case DW_OP_breg9: | |
2592 | case DW_OP_breg10: | |
2593 | case DW_OP_breg11: | |
2594 | case DW_OP_breg12: | |
2595 | case DW_OP_breg13: | |
2596 | case DW_OP_breg14: | |
2597 | case DW_OP_breg15: | |
2598 | case DW_OP_breg16: | |
2599 | case DW_OP_breg17: | |
2600 | case DW_OP_breg18: | |
2601 | case DW_OP_breg19: | |
2602 | case DW_OP_breg20: | |
2603 | case DW_OP_breg21: | |
2604 | case DW_OP_breg22: | |
2605 | case DW_OP_breg23: | |
2606 | case DW_OP_breg24: | |
2607 | case DW_OP_breg25: | |
2608 | case DW_OP_breg26: | |
2609 | case DW_OP_breg27: | |
2610 | case DW_OP_breg28: | |
2611 | case DW_OP_breg29: | |
2612 | case DW_OP_breg30: | |
2613 | case DW_OP_breg31: | |
2614 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2615 | break; | |
2616 | case DW_OP_regx: | |
2617 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2618 | break; | |
2619 | case DW_OP_fbreg: | |
2620 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2621 | break; | |
2622 | case DW_OP_bregx: | |
2623 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2624 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2625 | break; | |
2626 | case DW_OP_piece: | |
2627 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2628 | break; | |
2629 | case DW_OP_deref_size: | |
2630 | case DW_OP_xderef_size: | |
2631 | size += 1; | |
2632 | break; | |
3f76745e | 2633 | default: |
7d9d8943 | 2634 | break; |
4b674448 | 2635 | } |
7d9d8943 AM |
2636 | |
2637 | return size; | |
4b674448 JM |
2638 | } |
2639 | ||
7d9d8943 | 2640 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2641 | |
7d9d8943 AM |
2642 | static unsigned long |
2643 | size_of_locs (loc) | |
2644 | register dw_loc_descr_ref loc; | |
4b674448 | 2645 | { |
7d9d8943 AM |
2646 | register unsigned long size = 0; |
2647 | ||
2648 | for (; loc != NULL; loc = loc->dw_loc_next) | |
d8041cc8 RH |
2649 | { |
2650 | loc->dw_loc_addr = size; | |
2651 | size += size_of_loc_descr (loc); | |
2652 | } | |
7d9d8943 AM |
2653 | |
2654 | return size; | |
4b674448 JM |
2655 | } |
2656 | ||
7d9d8943 | 2657 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2658 | |
7d9d8943 AM |
2659 | static void |
2660 | output_loc_operands (loc) | |
2661 | register dw_loc_descr_ref loc; | |
a3f97cbb | 2662 | { |
7d9d8943 AM |
2663 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2664 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
2665 | ||
2666 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2667 | { |
0517872a | 2668 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2669 | case DW_OP_addr: |
7d9d8943 AM |
2670 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); |
2671 | fputc ('\n', asm_out_file); | |
2672 | break; | |
3f76745e | 2673 | case DW_OP_const2u: |
3f76745e | 2674 | case DW_OP_const2s: |
7d9d8943 AM |
2675 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); |
2676 | fputc ('\n', asm_out_file); | |
2677 | break; | |
3f76745e | 2678 | case DW_OP_const4u: |
3f76745e | 2679 | case DW_OP_const4s: |
7d9d8943 AM |
2680 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); |
2681 | fputc ('\n', asm_out_file); | |
2682 | break; | |
3f76745e | 2683 | case DW_OP_const8u: |
3f76745e | 2684 | case DW_OP_const8s: |
7d9d8943 AM |
2685 | abort (); |
2686 | fputc ('\n', asm_out_file); | |
2687 | break; | |
0517872a JM |
2688 | case DW_OP_skip: |
2689 | case DW_OP_bra: | |
d8041cc8 RH |
2690 | { |
2691 | int offset; | |
2692 | ||
2693 | if (val1->val_class == dw_val_class_loc) | |
2694 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2695 | else | |
2696 | abort (); | |
2697 | ||
2698 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset); | |
2699 | fputc ('\n', asm_out_file); | |
2700 | } | |
0517872a | 2701 | break; |
3139472f JM |
2702 | #else |
2703 | case DW_OP_addr: | |
2704 | case DW_OP_const2u: | |
2705 | case DW_OP_const2s: | |
2706 | case DW_OP_const4u: | |
2707 | case DW_OP_const4s: | |
2708 | case DW_OP_const8u: | |
2709 | case DW_OP_const8s: | |
2710 | case DW_OP_skip: | |
2711 | case DW_OP_bra: | |
2712 | /* We currently don't make any attempt to make sure these are | |
2713 | aligned properly like we do for the main unwind info, so | |
2714 | don't support emitting things larger than a byte if we're | |
2715 | only doing unwinding. */ | |
2716 | abort (); | |
0517872a JM |
2717 | #endif |
2718 | case DW_OP_const1u: | |
2719 | case DW_OP_const1s: | |
2720 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
2721 | fputc ('\n', asm_out_file); | |
2722 | break; | |
3f76745e | 2723 | case DW_OP_constu: |
7d9d8943 AM |
2724 | output_uleb128 (val1->v.val_unsigned); |
2725 | fputc ('\n', asm_out_file); | |
2726 | break; | |
3f76745e | 2727 | case DW_OP_consts: |
7d9d8943 AM |
2728 | output_sleb128 (val1->v.val_int); |
2729 | fputc ('\n', asm_out_file); | |
2730 | break; | |
2731 | case DW_OP_pick: | |
2732 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
2733 | fputc ('\n', asm_out_file); | |
2734 | break; | |
2735 | case DW_OP_plus_uconst: | |
2736 | output_uleb128 (val1->v.val_unsigned); | |
2737 | fputc ('\n', asm_out_file); | |
2738 | break; | |
3f76745e | 2739 | case DW_OP_breg0: |
3f76745e | 2740 | case DW_OP_breg1: |
3f76745e | 2741 | case DW_OP_breg2: |
3f76745e | 2742 | case DW_OP_breg3: |
3f76745e | 2743 | case DW_OP_breg4: |
3f76745e | 2744 | case DW_OP_breg5: |
3f76745e | 2745 | case DW_OP_breg6: |
3f76745e | 2746 | case DW_OP_breg7: |
3f76745e | 2747 | case DW_OP_breg8: |
3f76745e | 2748 | case DW_OP_breg9: |
3f76745e | 2749 | case DW_OP_breg10: |
3f76745e | 2750 | case DW_OP_breg11: |
3f76745e | 2751 | case DW_OP_breg12: |
3f76745e | 2752 | case DW_OP_breg13: |
3f76745e | 2753 | case DW_OP_breg14: |
3f76745e | 2754 | case DW_OP_breg15: |
3f76745e | 2755 | case DW_OP_breg16: |
3f76745e | 2756 | case DW_OP_breg17: |
3f76745e | 2757 | case DW_OP_breg18: |
3f76745e | 2758 | case DW_OP_breg19: |
3f76745e | 2759 | case DW_OP_breg20: |
3f76745e | 2760 | case DW_OP_breg21: |
3f76745e | 2761 | case DW_OP_breg22: |
3f76745e | 2762 | case DW_OP_breg23: |
3f76745e | 2763 | case DW_OP_breg24: |
3f76745e | 2764 | case DW_OP_breg25: |
3f76745e | 2765 | case DW_OP_breg26: |
3f76745e | 2766 | case DW_OP_breg27: |
3f76745e | 2767 | case DW_OP_breg28: |
3f76745e | 2768 | case DW_OP_breg29: |
3f76745e | 2769 | case DW_OP_breg30: |
3f76745e | 2770 | case DW_OP_breg31: |
7d9d8943 AM |
2771 | output_sleb128 (val1->v.val_int); |
2772 | fputc ('\n', asm_out_file); | |
2773 | break; | |
3f76745e | 2774 | case DW_OP_regx: |
7d9d8943 AM |
2775 | output_uleb128 (val1->v.val_unsigned); |
2776 | fputc ('\n', asm_out_file); | |
2777 | break; | |
3f76745e | 2778 | case DW_OP_fbreg: |
7d9d8943 AM |
2779 | output_sleb128 (val1->v.val_int); |
2780 | fputc ('\n', asm_out_file); | |
2781 | break; | |
3f76745e | 2782 | case DW_OP_bregx: |
7d9d8943 AM |
2783 | output_uleb128 (val1->v.val_unsigned); |
2784 | fputc ('\n', asm_out_file); | |
2785 | output_sleb128 (val2->v.val_int); | |
2786 | fputc ('\n', asm_out_file); | |
2787 | break; | |
3f76745e | 2788 | case DW_OP_piece: |
7d9d8943 AM |
2789 | output_uleb128 (val1->v.val_unsigned); |
2790 | fputc ('\n', asm_out_file); | |
2791 | break; | |
3f76745e | 2792 | case DW_OP_deref_size: |
3f76745e | 2793 | case DW_OP_xderef_size: |
7d9d8943 AM |
2794 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); |
2795 | fputc ('\n', asm_out_file); | |
2796 | break; | |
2797 | default: | |
3139472f JM |
2798 | /* Other codes have no operands. */ |
2799 | break; | |
7d9d8943 AM |
2800 | } |
2801 | } | |
2802 | ||
2803 | /* Output a sequence of location operations. */ | |
2804 | ||
2805 | static void | |
2806 | output_loc_sequence (loc) | |
2807 | dw_loc_descr_ref loc; | |
2808 | { | |
2809 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2810 | { | |
2811 | /* Output the opcode. */ | |
2812 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
2813 | if (flag_debug_asm) | |
2814 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, | |
2815 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
2816 | ||
2817 | fputc ('\n', asm_out_file); | |
2818 | ||
2819 | /* Output the operand(s) (if any). */ | |
2820 | output_loc_operands (loc); | |
2821 | } | |
2822 | } | |
2823 | ||
2824 | /* This routine will generate the correct assembly data for a location | |
2825 | description based on a cfi entry with a complex address. */ | |
2826 | ||
2827 | static void | |
2828 | output_cfa_loc (cfi) | |
2829 | dw_cfi_ref cfi; | |
2830 | { | |
2831 | dw_loc_descr_ref loc; | |
2832 | unsigned long size; | |
2833 | ||
2834 | /* Output the size of the block. */ | |
2835 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2836 | size = size_of_locs (loc); | |
2837 | output_uleb128 (size); | |
2838 | fputc ('\n', asm_out_file); | |
2839 | ||
2840 | /* Now output the operations themselves. */ | |
2841 | output_loc_sequence (loc); | |
2842 | } | |
2843 | ||
556273e0 KH |
2844 | /* This function builds a dwarf location descriptor seqeunce from |
2845 | a dw_cfa_location. */ | |
7d9d8943 AM |
2846 | |
2847 | static struct dw_loc_descr_struct * | |
2848 | build_cfa_loc (cfa) | |
2849 | dw_cfa_location *cfa; | |
2850 | { | |
2851 | struct dw_loc_descr_struct *head, *tmp; | |
2852 | ||
2853 | if (cfa->indirect == 0) | |
2854 | abort (); | |
2855 | ||
2856 | if (cfa->base_offset) | |
f299afab HPN |
2857 | { |
2858 | if (cfa->reg <= 31) | |
2859 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2860 | else | |
2861 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2862 | } | |
2863 | else if (cfa->reg <= 31) | |
7d9d8943 | 2864 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2865 | else |
2866 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
7d9d8943 AM |
2867 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2868 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2869 | add_loc_descr (&head, tmp); | |
2870 | if (cfa->offset != 0) | |
2871 | { | |
2872 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2873 | add_loc_descr (&head, tmp); | |
2874 | } | |
2875 | return head; | |
2876 | } | |
2877 | ||
556273e0 | 2878 | /* This function fills in aa dw_cfa_location structure from a |
7d9d8943 AM |
2879 | dwarf location descriptor sequence. */ |
2880 | ||
2881 | static void | |
2882 | get_cfa_from_loc_descr (cfa, loc) | |
2883 | dw_cfa_location *cfa; | |
556273e0 | 2884 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2885 | { |
556273e0 | 2886 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2887 | cfa->offset = 0; |
2888 | cfa->base_offset = 0; | |
2889 | cfa->indirect = 0; | |
2890 | cfa->reg = -1; | |
2891 | ||
2892 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2893 | { | |
2894 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2895 | switch (op) | |
556273e0 | 2896 | { |
7d9d8943 AM |
2897 | case DW_OP_reg0: |
2898 | case DW_OP_reg1: | |
2899 | case DW_OP_reg2: | |
2900 | case DW_OP_reg3: | |
2901 | case DW_OP_reg4: | |
2902 | case DW_OP_reg5: | |
2903 | case DW_OP_reg6: | |
2904 | case DW_OP_reg7: | |
2905 | case DW_OP_reg8: | |
2906 | case DW_OP_reg9: | |
2907 | case DW_OP_reg10: | |
2908 | case DW_OP_reg11: | |
2909 | case DW_OP_reg12: | |
2910 | case DW_OP_reg13: | |
2911 | case DW_OP_reg14: | |
2912 | case DW_OP_reg15: | |
2913 | case DW_OP_reg16: | |
2914 | case DW_OP_reg17: | |
2915 | case DW_OP_reg18: | |
2916 | case DW_OP_reg19: | |
2917 | case DW_OP_reg20: | |
2918 | case DW_OP_reg21: | |
2919 | case DW_OP_reg22: | |
2920 | case DW_OP_reg23: | |
2921 | case DW_OP_reg24: | |
2922 | case DW_OP_reg25: | |
2923 | case DW_OP_reg26: | |
2924 | case DW_OP_reg27: | |
2925 | case DW_OP_reg28: | |
2926 | case DW_OP_reg29: | |
2927 | case DW_OP_reg30: | |
2928 | case DW_OP_reg31: | |
2929 | cfa->reg = op - DW_OP_reg0; | |
2930 | break; | |
2931 | case DW_OP_regx: | |
2932 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2933 | break; | |
2934 | case DW_OP_breg0: | |
2935 | case DW_OP_breg1: | |
2936 | case DW_OP_breg2: | |
2937 | case DW_OP_breg3: | |
2938 | case DW_OP_breg4: | |
2939 | case DW_OP_breg5: | |
2940 | case DW_OP_breg6: | |
2941 | case DW_OP_breg7: | |
2942 | case DW_OP_breg8: | |
2943 | case DW_OP_breg9: | |
2944 | case DW_OP_breg10: | |
2945 | case DW_OP_breg11: | |
2946 | case DW_OP_breg12: | |
2947 | case DW_OP_breg13: | |
2948 | case DW_OP_breg14: | |
2949 | case DW_OP_breg15: | |
2950 | case DW_OP_breg16: | |
2951 | case DW_OP_breg17: | |
2952 | case DW_OP_breg18: | |
2953 | case DW_OP_breg19: | |
2954 | case DW_OP_breg20: | |
2955 | case DW_OP_breg21: | |
2956 | case DW_OP_breg22: | |
2957 | case DW_OP_breg23: | |
2958 | case DW_OP_breg24: | |
2959 | case DW_OP_breg25: | |
2960 | case DW_OP_breg26: | |
2961 | case DW_OP_breg27: | |
2962 | case DW_OP_breg28: | |
2963 | case DW_OP_breg29: | |
2964 | case DW_OP_breg30: | |
2965 | case DW_OP_breg31: | |
2966 | cfa->reg = op - DW_OP_breg0; | |
2967 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
2968 | break; | |
2969 | case DW_OP_bregx: | |
2970 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2971 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
2972 | break; | |
2973 | case DW_OP_deref: | |
2974 | cfa->indirect = 1; | |
2975 | break; | |
2976 | case DW_OP_plus_uconst: | |
556273e0 | 2977 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
2978 | break; |
2979 | default: | |
2980 | fatal ("DW_LOC_OP %s not implememnted yet.\n", | |
2981 | dwarf_stack_op_name (ptr->dw_loc_opc)); | |
2982 | } | |
2983 | } | |
2984 | } | |
2985 | #endif /* .debug_frame support */ | |
2986 | \f | |
2987 | /* And now, the support for symbolic debugging information. */ | |
2988 | #ifdef DWARF2_DEBUGGING_INFO | |
2989 | ||
2990 | /* NOTE: In the comments in this file, many references are made to | |
2991 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
2992 | throughout the remainder of this file. */ | |
2993 | ||
2994 | /* An internal representation of the DWARF output is built, and then | |
2995 | walked to generate the DWARF debugging info. The walk of the internal | |
2996 | representation is done after the entire program has been compiled. | |
2997 | The types below are used to describe the internal representation. */ | |
2998 | ||
2999 | /* Various DIE's use offsets relative to the beginning of the | |
3000 | .debug_info section to refer to each other. */ | |
3001 | ||
3002 | typedef long int dw_offset; | |
3003 | ||
3004 | /* Define typedefs here to avoid circular dependencies. */ | |
3005 | ||
3006 | typedef struct dw_attr_struct *dw_attr_ref; | |
3007 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3008 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3009 | typedef struct pubname_struct *pubname_ref; | |
3010 | typedef dw_die_ref *arange_ref; | |
3011 | ||
3012 | /* Each entry in the line_info_table maintains the file and | |
3013 | line number associated with the label generated for that | |
3014 | entry. The label gives the PC value associated with | |
3015 | the line number entry. */ | |
3016 | ||
3017 | typedef struct dw_line_info_struct | |
3018 | { | |
3019 | unsigned long dw_file_num; | |
3020 | unsigned long dw_line_num; | |
3021 | } | |
3022 | dw_line_info_entry; | |
3023 | ||
3024 | /* Line information for functions in separate sections; each one gets its | |
3025 | own sequence. */ | |
3026 | typedef struct dw_separate_line_info_struct | |
3027 | { | |
3028 | unsigned long dw_file_num; | |
3029 | unsigned long dw_line_num; | |
3030 | unsigned long function; | |
3031 | } | |
3032 | dw_separate_line_info_entry; | |
3033 | ||
3034 | /* Each DIE attribute has a field specifying the attribute kind, | |
3035 | a link to the next attribute in the chain, and an attribute value. | |
3036 | Attributes are typically linked below the DIE they modify. */ | |
3037 | ||
3038 | typedef struct dw_attr_struct | |
3039 | { | |
3040 | enum dwarf_attribute dw_attr; | |
3041 | dw_attr_ref dw_attr_next; | |
3042 | dw_val_node dw_attr_val; | |
3043 | } | |
3044 | dw_attr_node; | |
3045 | ||
3046 | /* The Debugging Information Entry (DIE) structure */ | |
3047 | ||
3048 | typedef struct die_struct | |
3049 | { | |
3050 | enum dwarf_tag die_tag; | |
881c6935 | 3051 | char *die_symbol; |
7d9d8943 AM |
3052 | dw_attr_ref die_attr; |
3053 | dw_die_ref die_parent; | |
3054 | dw_die_ref die_child; | |
3055 | dw_die_ref die_sib; | |
3056 | dw_offset die_offset; | |
3057 | unsigned long die_abbrev; | |
1bfb5f8f | 3058 | int die_mark; |
7d9d8943 AM |
3059 | } |
3060 | die_node; | |
3061 | ||
3062 | /* The pubname structure */ | |
3063 | ||
3064 | typedef struct pubname_struct | |
3065 | { | |
3066 | dw_die_ref die; | |
556273e0 | 3067 | char *name; |
7d9d8943 AM |
3068 | } |
3069 | pubname_entry; | |
3070 | ||
3071 | /* The limbo die list structure. */ | |
3072 | typedef struct limbo_die_struct | |
3073 | { | |
3074 | dw_die_ref die; | |
3075 | struct limbo_die_struct *next; | |
3076 | } | |
3077 | limbo_die_node; | |
3078 | ||
3079 | /* How to start an assembler comment. */ | |
3080 | #ifndef ASM_COMMENT_START | |
3081 | #define ASM_COMMENT_START ";#" | |
3082 | #endif | |
3083 | ||
3084 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3085 | implicitly generated for a tagged type. | |
3086 | ||
3087 | Note that unlike the gcc front end (which generates a NULL named | |
3088 | TYPE_DECL node for each complete tagged type, each array type, and | |
3089 | each function type node created) the g++ front end generates a | |
3090 | _named_ TYPE_DECL node for each tagged type node created. | |
3091 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3092 | generate a DW_TAG_typedef DIE for them. */ | |
3093 | ||
3094 | #define TYPE_DECL_IS_STUB(decl) \ | |
3095 | (DECL_NAME (decl) == NULL_TREE \ | |
3096 | || (DECL_ARTIFICIAL (decl) \ | |
3097 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3098 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3099 | /* This is necessary for stub decls that \ | |
3100 | appear in nested inline functions. */ \ | |
3101 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3102 | && (decl_ultimate_origin (decl) \ | |
3103 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3104 | ||
3105 | /* Information concerning the compilation unit's programming | |
3106 | language, and compiler version. */ | |
3107 | ||
3108 | extern int flag_traditional; | |
3109 | ||
3110 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3111 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3112 | ||
3113 | /* Fixed size portion of debugging line information prolog. */ | |
3114 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3115 | ||
3116 | /* Fixed size portion of public names info. */ | |
3117 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3118 | ||
3119 | /* Fixed size portion of the address range info. */ | |
3120 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3121 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3122 | - DWARF_OFFSET_SIZE) | |
3123 | ||
3124 | /* Size of padding portion in the address range info. It must be | |
3125 | aligned to twice the pointer size. */ | |
3126 | #define DWARF_ARANGES_PAD_SIZE \ | |
3127 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3128 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3129 | ||
3130 | /* The default is to have gcc emit the line number tables. */ | |
3131 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO | |
3132 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 | |
3133 | #endif | |
3134 | ||
3135 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3136 | In this implementation of DWARF, this field is used for information | |
3137 | purposes only. Since GCC generates assembly language, we have | |
3138 | no a priori knowledge of how many instruction bytes are generated | |
3139 | for each source line, and therefore can use only the DW_LNE_set_address | |
3140 | and DW_LNS_fixed_advance_pc line information commands. */ | |
3141 | ||
3142 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
3143 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3144 | #endif | |
3145 | ||
3146 | /* Minimum line offset in a special line info. opcode. | |
3147 | This value was chosen to give a reasonable range of values. */ | |
3148 | #define DWARF_LINE_BASE -10 | |
3149 | ||
3150 | /* First special line opcde - leave room for the standard opcodes. */ | |
3151 | #define DWARF_LINE_OPCODE_BASE 10 | |
3152 | ||
3153 | /* Range of line offsets in a special line info. opcode. */ | |
3154 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3155 | ||
3156 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3157 | In the present implementation, we do not mark any lines as | |
3158 | the beginning of a source statement, because that information | |
3159 | is not made available by the GCC front-end. */ | |
3160 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3161 | ||
3162 | /* This location is used by calc_die_sizes() to keep track | |
3163 | the offset of each DIE within the .debug_info section. */ | |
3164 | static unsigned long next_die_offset; | |
3165 | ||
3166 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3167 | static dw_die_ref comp_unit_die; | |
3168 | ||
3169 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3170 | static limbo_die_node *limbo_die_list = 0; | |
3171 | ||
3172 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
3173 | static char **file_table; | |
3174 | ||
3175 | /* Total number of entries in the table (i.e. array) pointed to by | |
3176 | `file_table'. This is the *total* and includes both used and unused | |
3177 | slots. */ | |
3178 | static unsigned file_table_allocated; | |
3179 | ||
3180 | /* Number of entries in the file_table which are actually in use. */ | |
3181 | static unsigned file_table_in_use; | |
3182 | ||
3183 | /* Size (in elements) of increments by which we may expand the filename | |
3184 | table. */ | |
3185 | #define FILE_TABLE_INCREMENT 64 | |
3186 | ||
3187 | /* Local pointer to the name of the main input file. Initialized in | |
3188 | dwarf2out_init. */ | |
3189 | static const char *primary_filename; | |
3190 | ||
3191 | /* A pointer to the base of a table of references to DIE's that describe | |
3192 | declarations. The table is indexed by DECL_UID() which is a unique | |
3193 | number identifying each decl. */ | |
3194 | static dw_die_ref *decl_die_table; | |
3195 | ||
3196 | /* Number of elements currently allocated for the decl_die_table. */ | |
3197 | static unsigned decl_die_table_allocated; | |
3198 | ||
3199 | /* Number of elements in decl_die_table currently in use. */ | |
3200 | static unsigned decl_die_table_in_use; | |
3201 | ||
3202 | /* Size (in elements) of increments by which we may expand the | |
3203 | decl_die_table. */ | |
3204 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3205 | ||
3206 | /* A pointer to the base of a table of references to declaration | |
3207 | scopes. This table is a display which tracks the nesting | |
3208 | of declaration scopes at the current scope and containing | |
3209 | scopes. This table is used to find the proper place to | |
3210 | define type declaration DIE's. */ | |
3211 | static tree *decl_scope_table; | |
3212 | ||
3213 | /* Number of elements currently allocated for the decl_scope_table. */ | |
3214 | static int decl_scope_table_allocated; | |
3215 | ||
3216 | /* Current level of nesting of declaration scopes. */ | |
3217 | static int decl_scope_depth; | |
3218 | ||
3219 | /* Size (in elements) of increments by which we may expand the | |
3220 | decl_scope_table. */ | |
3221 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
3222 | ||
3223 | /* A pointer to the base of a list of references to DIE's that | |
3224 | are uniquely identified by their tag, presence/absence of | |
3225 | children DIE's, and list of attribute/value pairs. */ | |
3226 | static dw_die_ref *abbrev_die_table; | |
3227 | ||
3228 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3229 | static unsigned abbrev_die_table_allocated; | |
3230 | ||
3231 | /* Number of elements in type_die_table currently in use. */ | |
3232 | static unsigned abbrev_die_table_in_use; | |
3233 | ||
3234 | /* Size (in elements) of increments by which we may expand the | |
3235 | abbrev_die_table. */ | |
3236 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3237 | ||
3238 | /* A pointer to the base of a table that contains line information | |
3239 | for each source code line in .text in the compilation unit. */ | |
3240 | static dw_line_info_ref line_info_table; | |
3241 | ||
3242 | /* Number of elements currently allocated for line_info_table. */ | |
3243 | static unsigned line_info_table_allocated; | |
3244 | ||
3245 | /* Number of elements in separate_line_info_table currently in use. */ | |
3246 | static unsigned separate_line_info_table_in_use; | |
3247 | ||
3248 | /* A pointer to the base of a table that contains line information | |
3249 | for each source code line outside of .text in the compilation unit. */ | |
3250 | static dw_separate_line_info_ref separate_line_info_table; | |
3251 | ||
3252 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3253 | static unsigned separate_line_info_table_allocated; | |
3254 | ||
3255 | /* Number of elements in line_info_table currently in use. */ | |
3256 | static unsigned line_info_table_in_use; | |
3257 | ||
3258 | /* Size (in elements) of increments by which we may expand the | |
3259 | line_info_table. */ | |
3260 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3261 | ||
3262 | /* A pointer to the base of a table that contains a list of publicly | |
3263 | accessible names. */ | |
3264 | static pubname_ref pubname_table; | |
3265 | ||
3266 | /* Number of elements currently allocated for pubname_table. */ | |
3267 | static unsigned pubname_table_allocated; | |
3268 | ||
3269 | /* Number of elements in pubname_table currently in use. */ | |
3270 | static unsigned pubname_table_in_use; | |
3271 | ||
3272 | /* Size (in elements) of increments by which we may expand the | |
3273 | pubname_table. */ | |
3274 | #define PUBNAME_TABLE_INCREMENT 64 | |
3275 | ||
3276 | /* A pointer to the base of a table that contains a list of publicly | |
3277 | accessible names. */ | |
3278 | static arange_ref arange_table; | |
3279 | ||
3280 | /* Number of elements currently allocated for arange_table. */ | |
3281 | static unsigned arange_table_allocated; | |
3282 | ||
3283 | /* Number of elements in arange_table currently in use. */ | |
3284 | static unsigned arange_table_in_use; | |
3285 | ||
3286 | /* Size (in elements) of increments by which we may expand the | |
3287 | arange_table. */ | |
3288 | #define ARANGE_TABLE_INCREMENT 64 | |
3289 | ||
3290 | /* A pointer to the base of a list of incomplete types which might be | |
3291 | completed at some later time. */ | |
3292 | ||
3293 | static tree *incomplete_types_list; | |
3294 | ||
3295 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
3296 | static unsigned incomplete_types_allocated; | |
3297 | ||
3298 | /* Number of elements of incomplete_types_list currently in use. */ | |
3299 | static unsigned incomplete_types; | |
3300 | ||
3301 | /* Size (in elements) of increments by which we may expand the incomplete | |
3302 | types list. Actually, a single hunk of space of this size should | |
3303 | be enough for most typical programs. */ | |
3304 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
3305 | ||
3306 | /* Record whether the function being analyzed contains inlined functions. */ | |
3307 | static int current_function_has_inlines; | |
3308 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3309 | static int comp_unit_has_inlines; | |
3310 | #endif | |
3311 | ||
3312 | /* Array of RTXes referenced by the debugging information, which therefore | |
3313 | must be kept around forever. We do this rather than perform GC on | |
3314 | the dwarf info because almost all of the dwarf info lives forever, and | |
3315 | it's easier to support non-GC frontends this way. */ | |
3316 | static varray_type used_rtx_varray; | |
3317 | ||
3318 | /* Forward declarations for functions defined in this file. */ | |
3319 | ||
3320 | static int is_pseudo_reg PARAMS ((rtx)); | |
3321 | static tree type_main_variant PARAMS ((tree)); | |
3322 | static int is_tagged_type PARAMS ((tree)); | |
3323 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3324 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3325 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3326 | #if 0 | |
3327 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3328 | #endif | |
3329 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3330 | static tree block_ultimate_origin PARAMS ((tree)); | |
3331 | static tree decl_class_context PARAMS ((tree)); | |
3332 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
3333 | static void add_AT_flag PARAMS ((dw_die_ref, | |
3334 | enum dwarf_attribute, | |
3335 | unsigned)); | |
3336 | static void add_AT_int PARAMS ((dw_die_ref, | |
3337 | enum dwarf_attribute, long)); | |
3338 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
3339 | enum dwarf_attribute, | |
3340 | unsigned long)); | |
3341 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
3342 | enum dwarf_attribute, | |
3343 | unsigned long, | |
3344 | unsigned long)); | |
3345 | static void add_AT_float PARAMS ((dw_die_ref, | |
3346 | enum dwarf_attribute, | |
3347 | unsigned, long *)); | |
3348 | static void add_AT_string PARAMS ((dw_die_ref, | |
3349 | enum dwarf_attribute, | |
3350 | const char *)); | |
3351 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
3352 | enum dwarf_attribute, | |
3353 | dw_die_ref)); | |
3354 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
3355 | enum dwarf_attribute, | |
3356 | unsigned)); | |
3357 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3358 | enum dwarf_attribute, | |
3359 | dw_loc_descr_ref)); | |
3360 | static void add_AT_addr PARAMS ((dw_die_ref, | |
3361 | enum dwarf_attribute, | |
3362 | rtx)); | |
3363 | static void add_AT_lbl_id PARAMS ((dw_die_ref, | |
3364 | enum dwarf_attribute, | |
3365 | const char *)); | |
3366 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3367 | enum dwarf_attribute, | |
3368 | const char *)); | |
3369 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, | |
3370 | enum dwarf_attribute)); | |
3371 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3372 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3373 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3374 | enum dwarf_attribute)); | |
3375 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3376 | enum dwarf_attribute)); | |
3377 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3378 | enum dwarf_attribute)); | |
3379 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3380 | enum dwarf_attribute)); | |
3381 | static int is_c_family PARAMS ((void)); | |
28985b81 | 3382 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3383 | static int is_fortran PARAMS ((void)); |
3384 | static void remove_AT PARAMS ((dw_die_ref, | |
3385 | enum dwarf_attribute)); | |
3386 | static void remove_children PARAMS ((dw_die_ref)); | |
3387 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
3388 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
3389 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
3390 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3391 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3392 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3393 | static void print_spaces PARAMS ((FILE *)); | |
3394 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3395 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3396 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3397 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3398 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3399 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
3400 | static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *)); | |
3401 | static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *)); | |
3402 | static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *)); | |
3403 | static void compute_section_prefix PARAMS ((dw_die_ref)); | |
3404 | static int is_type_die PARAMS ((dw_die_ref)); | |
3405 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3406 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
3407 | static char *gen_internal_sym PARAMS ((void)); | |
3408 | static void assign_symbol_names PARAMS ((dw_die_ref)); | |
3409 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3410 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3411 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
3412 | static unsigned long size_of_string PARAMS ((const char *)); | |
3413 | static int constant_size PARAMS ((long unsigned)); | |
3414 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3415 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3416 | static void mark_dies PARAMS ((dw_die_ref)); |
3417 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3418 | static unsigned long size_of_line_prolog PARAMS ((void)); |
3419 | static unsigned long size_of_pubnames PARAMS ((void)); | |
3420 | static unsigned long size_of_aranges PARAMS ((void)); | |
3421 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3422 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3423 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 JM |
3424 | static void output_die_symbol PARAMS ((dw_die_ref)); |
3425 | static void output_symbolic_ref PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3426 | static void output_die PARAMS ((dw_die_ref)); |
3427 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3428 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3429 | static const char *dwarf2_name PARAMS ((tree, int)); |
3430 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3431 | static void output_pubnames PARAMS ((void)); | |
3432 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3433 | static void output_aranges PARAMS ((void)); | |
3434 | static void output_line_info PARAMS ((void)); | |
3435 | static dw_die_ref base_type_die PARAMS ((tree)); | |
3436 | static tree root_type PARAMS ((tree)); | |
3437 | static int is_base_type PARAMS ((tree)); | |
3438 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3439 | static int type_is_enum PARAMS ((tree)); | |
3440 | static unsigned int reg_number PARAMS ((rtx)); | |
3441 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3442 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3443 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3444 | static int is_based_loc PARAMS ((rtx)); | |
3445 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3446 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3447 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3448 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3449 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3450 | static tree field_type PARAMS ((tree)); | |
3451 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
3452 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); | |
3453 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3454 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3455 | enum dwarf_attribute, rtx)); | |
3456 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3457 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3458 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3459 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3460 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3461 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3462 | static void add_bound_info PARAMS ((dw_die_ref, | |
3463 | enum dwarf_attribute, tree)); | |
3464 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3465 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3466 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3467 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3468 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3469 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3470 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3471 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3472 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3473 | static void push_decl_scope PARAMS ((tree)); | |
3474 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
3475 | static void pop_decl_scope PARAMS ((void)); | |
3476 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
3477 | dw_die_ref)); | |
3478 | static const char *type_tag PARAMS ((tree)); | |
3479 | static tree member_declared_type PARAMS ((tree)); | |
3480 | #if 0 | |
3481 | static const char *decl_start_label PARAMS ((tree)); | |
3482 | #endif | |
3483 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3484 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3485 | #if 0 | |
3486 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3487 | #endif | |
3488 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3489 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3490 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3491 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3492 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3493 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3494 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3495 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3496 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3497 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3498 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3499 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3500 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3501 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3502 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3503 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3504 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3505 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3506 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3507 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3508 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3509 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3510 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3511 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3512 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3513 | static int is_redundant_typedef PARAMS ((tree)); | |
3514 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
3515 | static unsigned lookup_filename PARAMS ((const char *)); | |
3516 | static void add_incomplete_type PARAMS ((tree)); | |
3517 | static void retry_incomplete_types PARAMS ((void)); | |
3518 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
3519 | static void gen_abstract_function PARAMS ((tree)); | |
3520 | static rtx save_rtx PARAMS ((rtx)); | |
3521 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
7d9d8943 AM |
3522 | |
3523 | /* Section names used to hold DWARF debugging information. */ | |
3524 | #ifndef DEBUG_INFO_SECTION | |
3525 | #define DEBUG_INFO_SECTION ".debug_info" | |
3526 | #endif | |
3527 | #ifndef ABBREV_SECTION | |
3528 | #define ABBREV_SECTION ".debug_abbrev" | |
3529 | #endif | |
3530 | #ifndef ARANGES_SECTION | |
3531 | #define ARANGES_SECTION ".debug_aranges" | |
3532 | #endif | |
3533 | #ifndef DW_MACINFO_SECTION | |
3534 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
3535 | #endif | |
3536 | #ifndef DEBUG_LINE_SECTION | |
3537 | #define DEBUG_LINE_SECTION ".debug_line" | |
3538 | #endif | |
3539 | #ifndef LOC_SECTION | |
3540 | #define LOC_SECTION ".debug_loc" | |
3541 | #endif | |
3542 | #ifndef PUBNAMES_SECTION | |
3543 | #define PUBNAMES_SECTION ".debug_pubnames" | |
3544 | #endif | |
3545 | #ifndef STR_SECTION | |
3546 | #define STR_SECTION ".debug_str" | |
3547 | #endif | |
3548 | ||
3549 | /* Standard ELF section names for compiled code and data. */ | |
3550 | #ifndef TEXT_SECTION | |
3551 | #define TEXT_SECTION ".text" | |
3552 | #endif | |
3553 | #ifndef DATA_SECTION | |
3554 | #define DATA_SECTION ".data" | |
3555 | #endif | |
3556 | #ifndef BSS_SECTION | |
3557 | #define BSS_SECTION ".bss" | |
3558 | #endif | |
3559 | ||
3560 | /* Labels we insert at beginning sections we can reference instead of | |
556273e0 | 3561 | the section names themselves. */ |
7d9d8943 AM |
3562 | |
3563 | #ifndef TEXT_SECTION_LABEL | |
3564 | #define TEXT_SECTION_LABEL "Ltext" | |
3565 | #endif | |
3566 | #ifndef DEBUG_LINE_SECTION_LABEL | |
3567 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" | |
3568 | #endif | |
3569 | #ifndef DEBUG_INFO_SECTION_LABEL | |
3570 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" | |
3571 | #endif | |
3572 | #ifndef ABBREV_SECTION_LABEL | |
3573 | #define ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
3574 | #endif | |
3575 | ||
7d9d8943 AM |
3576 | /* Definitions of defaults for formats and names of various special |
3577 | (artificial) labels which may be generated within this file (when the -g | |
3578 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3579 | If necessary, these may be overridden from within the tm.h file, but | |
3580 | typically, overriding these defaults is unnecessary. */ | |
3581 | ||
3582 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3583 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3584 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3585 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3586 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3587 | ||
3588 | #ifndef TEXT_END_LABEL | |
3589 | #define TEXT_END_LABEL "Letext" | |
3590 | #endif | |
3591 | #ifndef DATA_END_LABEL | |
3592 | #define DATA_END_LABEL "Ledata" | |
3593 | #endif | |
3594 | #ifndef BSS_END_LABEL | |
3595 | #define BSS_END_LABEL "Lebss" | |
3596 | #endif | |
3597 | #ifndef INSN_LABEL_FMT | |
3598 | #define INSN_LABEL_FMT "LI%u_" | |
3599 | #endif | |
3600 | #ifndef BLOCK_BEGIN_LABEL | |
3601 | #define BLOCK_BEGIN_LABEL "LBB" | |
3602 | #endif | |
3603 | #ifndef BLOCK_END_LABEL | |
3604 | #define BLOCK_END_LABEL "LBE" | |
3605 | #endif | |
3606 | #ifndef BODY_BEGIN_LABEL | |
3607 | #define BODY_BEGIN_LABEL "Lbb" | |
3608 | #endif | |
3609 | #ifndef BODY_END_LABEL | |
3610 | #define BODY_END_LABEL "Lbe" | |
3611 | #endif | |
3612 | #ifndef LINE_CODE_LABEL | |
3613 | #define LINE_CODE_LABEL "LM" | |
3614 | #endif | |
3615 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3616 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3617 | #endif | |
3618 | \f | |
3619 | /* We allow a language front-end to designate a function that is to be | |
3620 | called to "demangle" any name before it it put into a DIE. */ | |
3621 | ||
3622 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3623 | ||
3624 | void | |
3625 | dwarf2out_set_demangle_name_func (func) | |
3626 | const char *(*func) PARAMS ((const char *)); | |
3627 | { | |
3628 | demangle_name_func = func; | |
3629 | } | |
3630 | \f | |
3631 | /* Return an rtx like ORIG which lives forever. If we're doing GC, | |
3632 | that means adding it to used_rtx_varray. If not, that means making | |
3633 | a copy on the permanent_obstack. */ | |
3634 | ||
3635 | static rtx | |
3636 | save_rtx (orig) | |
3637 | register rtx orig; | |
3638 | { | |
1f8f4a0b | 3639 | VARRAY_PUSH_RTX (used_rtx_varray, orig); |
7d9d8943 AM |
3640 | |
3641 | return orig; | |
3642 | } | |
3643 | ||
3644 | /* Test if rtl node points to a pseudo register. */ | |
3645 | ||
3646 | static inline int | |
3647 | is_pseudo_reg (rtl) | |
3648 | register rtx rtl; | |
3649 | { | |
3650 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3651 | || (GET_CODE (rtl) == SUBREG | |
3652 | && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)); | |
3653 | } | |
3654 | ||
3655 | /* Return a reference to a type, with its const and volatile qualifiers | |
3656 | removed. */ | |
3657 | ||
3658 | static inline tree | |
3659 | type_main_variant (type) | |
3660 | register tree type; | |
3661 | { | |
3662 | type = TYPE_MAIN_VARIANT (type); | |
3663 | ||
556273e0 | 3664 | /* There really should be only one main variant among any group of variants |
7d9d8943 AM |
3665 | of a given type (and all of the MAIN_VARIANT values for all members of |
3666 | the group should point to that one type) but sometimes the C front-end | |
3667 | messes this up for array types, so we work around that bug here. */ | |
3668 | ||
3669 | if (TREE_CODE (type) == ARRAY_TYPE) | |
3670 | while (type != TYPE_MAIN_VARIANT (type)) | |
3671 | type = TYPE_MAIN_VARIANT (type); | |
3672 | ||
3673 | return type; | |
3674 | } | |
3675 | ||
3676 | /* Return non-zero if the given type node represents a tagged type. */ | |
3677 | ||
3678 | static inline int | |
3679 | is_tagged_type (type) | |
3680 | register tree type; | |
3681 | { | |
3682 | register enum tree_code code = TREE_CODE (type); | |
3683 | ||
3684 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3685 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3686 | } | |
3687 | ||
3688 | /* Convert a DIE tag into its string name. */ | |
3689 | ||
3690 | static const char * | |
3691 | dwarf_tag_name (tag) | |
3692 | register unsigned tag; | |
3693 | { | |
3694 | switch (tag) | |
3695 | { | |
3696 | case DW_TAG_padding: | |
3697 | return "DW_TAG_padding"; | |
3698 | case DW_TAG_array_type: | |
3699 | return "DW_TAG_array_type"; | |
3700 | case DW_TAG_class_type: | |
3701 | return "DW_TAG_class_type"; | |
3702 | case DW_TAG_entry_point: | |
3703 | return "DW_TAG_entry_point"; | |
3704 | case DW_TAG_enumeration_type: | |
3705 | return "DW_TAG_enumeration_type"; | |
3706 | case DW_TAG_formal_parameter: | |
3707 | return "DW_TAG_formal_parameter"; | |
3708 | case DW_TAG_imported_declaration: | |
3709 | return "DW_TAG_imported_declaration"; | |
3710 | case DW_TAG_label: | |
3711 | return "DW_TAG_label"; | |
3712 | case DW_TAG_lexical_block: | |
3713 | return "DW_TAG_lexical_block"; | |
3714 | case DW_TAG_member: | |
3715 | return "DW_TAG_member"; | |
3716 | case DW_TAG_pointer_type: | |
3717 | return "DW_TAG_pointer_type"; | |
3718 | case DW_TAG_reference_type: | |
3719 | return "DW_TAG_reference_type"; | |
3720 | case DW_TAG_compile_unit: | |
3721 | return "DW_TAG_compile_unit"; | |
3722 | case DW_TAG_string_type: | |
3723 | return "DW_TAG_string_type"; | |
3724 | case DW_TAG_structure_type: | |
3725 | return "DW_TAG_structure_type"; | |
3726 | case DW_TAG_subroutine_type: | |
3727 | return "DW_TAG_subroutine_type"; | |
3728 | case DW_TAG_typedef: | |
3729 | return "DW_TAG_typedef"; | |
3730 | case DW_TAG_union_type: | |
3731 | return "DW_TAG_union_type"; | |
3732 | case DW_TAG_unspecified_parameters: | |
3733 | return "DW_TAG_unspecified_parameters"; | |
3734 | case DW_TAG_variant: | |
3735 | return "DW_TAG_variant"; | |
3736 | case DW_TAG_common_block: | |
3737 | return "DW_TAG_common_block"; | |
3738 | case DW_TAG_common_inclusion: | |
3739 | return "DW_TAG_common_inclusion"; | |
3740 | case DW_TAG_inheritance: | |
3741 | return "DW_TAG_inheritance"; | |
3742 | case DW_TAG_inlined_subroutine: | |
3743 | return "DW_TAG_inlined_subroutine"; | |
3744 | case DW_TAG_module: | |
3745 | return "DW_TAG_module"; | |
3746 | case DW_TAG_ptr_to_member_type: | |
3747 | return "DW_TAG_ptr_to_member_type"; | |
3748 | case DW_TAG_set_type: | |
3749 | return "DW_TAG_set_type"; | |
3750 | case DW_TAG_subrange_type: | |
3751 | return "DW_TAG_subrange_type"; | |
3752 | case DW_TAG_with_stmt: | |
3753 | return "DW_TAG_with_stmt"; | |
3754 | case DW_TAG_access_declaration: | |
3755 | return "DW_TAG_access_declaration"; | |
3756 | case DW_TAG_base_type: | |
3757 | return "DW_TAG_base_type"; | |
3758 | case DW_TAG_catch_block: | |
3759 | return "DW_TAG_catch_block"; | |
3760 | case DW_TAG_const_type: | |
3761 | return "DW_TAG_const_type"; | |
3762 | case DW_TAG_constant: | |
3763 | return "DW_TAG_constant"; | |
3764 | case DW_TAG_enumerator: | |
3765 | return "DW_TAG_enumerator"; | |
3766 | case DW_TAG_file_type: | |
3767 | return "DW_TAG_file_type"; | |
3768 | case DW_TAG_friend: | |
3769 | return "DW_TAG_friend"; | |
3770 | case DW_TAG_namelist: | |
3771 | return "DW_TAG_namelist"; | |
3772 | case DW_TAG_namelist_item: | |
3773 | return "DW_TAG_namelist_item"; | |
3774 | case DW_TAG_packed_type: | |
3775 | return "DW_TAG_packed_type"; | |
3776 | case DW_TAG_subprogram: | |
3777 | return "DW_TAG_subprogram"; | |
3778 | case DW_TAG_template_type_param: | |
3779 | return "DW_TAG_template_type_param"; | |
3780 | case DW_TAG_template_value_param: | |
3781 | return "DW_TAG_template_value_param"; | |
3782 | case DW_TAG_thrown_type: | |
3783 | return "DW_TAG_thrown_type"; | |
3784 | case DW_TAG_try_block: | |
3785 | return "DW_TAG_try_block"; | |
3786 | case DW_TAG_variant_part: | |
3787 | return "DW_TAG_variant_part"; | |
3788 | case DW_TAG_variable: | |
3789 | return "DW_TAG_variable"; | |
3790 | case DW_TAG_volatile_type: | |
3791 | return "DW_TAG_volatile_type"; | |
3792 | case DW_TAG_MIPS_loop: | |
3793 | return "DW_TAG_MIPS_loop"; | |
3794 | case DW_TAG_format_label: | |
3795 | return "DW_TAG_format_label"; | |
3796 | case DW_TAG_function_template: | |
3797 | return "DW_TAG_function_template"; | |
3798 | case DW_TAG_class_template: | |
3799 | return "DW_TAG_class_template"; | |
881c6935 JM |
3800 | case DW_TAG_GNU_BINCL: |
3801 | return "DW_TAG_GNU_BINCL"; | |
3802 | case DW_TAG_GNU_EINCL: | |
3803 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3804 | default: |
3805 | return "DW_TAG_<unknown>"; | |
3806 | } | |
3807 | } | |
3808 | ||
3809 | /* Convert a DWARF attribute code into its string name. */ | |
3810 | ||
3811 | static const char * | |
3812 | dwarf_attr_name (attr) | |
3813 | register unsigned attr; | |
3814 | { | |
3815 | switch (attr) | |
3816 | { | |
3817 | case DW_AT_sibling: | |
3818 | return "DW_AT_sibling"; | |
3819 | case DW_AT_location: | |
3820 | return "DW_AT_location"; | |
3821 | case DW_AT_name: | |
3822 | return "DW_AT_name"; | |
3823 | case DW_AT_ordering: | |
3824 | return "DW_AT_ordering"; | |
3825 | case DW_AT_subscr_data: | |
3826 | return "DW_AT_subscr_data"; | |
3827 | case DW_AT_byte_size: | |
3828 | return "DW_AT_byte_size"; | |
3829 | case DW_AT_bit_offset: | |
3830 | return "DW_AT_bit_offset"; | |
3831 | case DW_AT_bit_size: | |
3832 | return "DW_AT_bit_size"; | |
3833 | case DW_AT_element_list: | |
3834 | return "DW_AT_element_list"; | |
3835 | case DW_AT_stmt_list: | |
3836 | return "DW_AT_stmt_list"; | |
3837 | case DW_AT_low_pc: | |
3838 | return "DW_AT_low_pc"; | |
3839 | case DW_AT_high_pc: | |
3840 | return "DW_AT_high_pc"; | |
3841 | case DW_AT_language: | |
3842 | return "DW_AT_language"; | |
3843 | case DW_AT_member: | |
3844 | return "DW_AT_member"; | |
3845 | case DW_AT_discr: | |
3846 | return "DW_AT_discr"; | |
3847 | case DW_AT_discr_value: | |
3848 | return "DW_AT_discr_value"; | |
3849 | case DW_AT_visibility: | |
3850 | return "DW_AT_visibility"; | |
3851 | case DW_AT_import: | |
3852 | return "DW_AT_import"; | |
3853 | case DW_AT_string_length: | |
3854 | return "DW_AT_string_length"; | |
3855 | case DW_AT_common_reference: | |
3856 | return "DW_AT_common_reference"; | |
3857 | case DW_AT_comp_dir: | |
3858 | return "DW_AT_comp_dir"; | |
3859 | case DW_AT_const_value: | |
3860 | return "DW_AT_const_value"; | |
3861 | case DW_AT_containing_type: | |
3862 | return "DW_AT_containing_type"; | |
3863 | case DW_AT_default_value: | |
3864 | return "DW_AT_default_value"; | |
3865 | case DW_AT_inline: | |
3866 | return "DW_AT_inline"; | |
3867 | case DW_AT_is_optional: | |
3868 | return "DW_AT_is_optional"; | |
3869 | case DW_AT_lower_bound: | |
3870 | return "DW_AT_lower_bound"; | |
3871 | case DW_AT_producer: | |
3872 | return "DW_AT_producer"; | |
3873 | case DW_AT_prototyped: | |
3874 | return "DW_AT_prototyped"; | |
3875 | case DW_AT_return_addr: | |
3876 | return "DW_AT_return_addr"; | |
3877 | case DW_AT_start_scope: | |
3878 | return "DW_AT_start_scope"; | |
3879 | case DW_AT_stride_size: | |
3880 | return "DW_AT_stride_size"; | |
3881 | case DW_AT_upper_bound: | |
3882 | return "DW_AT_upper_bound"; | |
3883 | case DW_AT_abstract_origin: | |
3884 | return "DW_AT_abstract_origin"; | |
3885 | case DW_AT_accessibility: | |
3886 | return "DW_AT_accessibility"; | |
3887 | case DW_AT_address_class: | |
3888 | return "DW_AT_address_class"; | |
3889 | case DW_AT_artificial: | |
3890 | return "DW_AT_artificial"; | |
3891 | case DW_AT_base_types: | |
3892 | return "DW_AT_base_types"; | |
3893 | case DW_AT_calling_convention: | |
3894 | return "DW_AT_calling_convention"; | |
3895 | case DW_AT_count: | |
3896 | return "DW_AT_count"; | |
3897 | case DW_AT_data_member_location: | |
3898 | return "DW_AT_data_member_location"; | |
3899 | case DW_AT_decl_column: | |
3900 | return "DW_AT_decl_column"; | |
3901 | case DW_AT_decl_file: | |
3902 | return "DW_AT_decl_file"; | |
3903 | case DW_AT_decl_line: | |
3904 | return "DW_AT_decl_line"; | |
3905 | case DW_AT_declaration: | |
3906 | return "DW_AT_declaration"; | |
3907 | case DW_AT_discr_list: | |
3908 | return "DW_AT_discr_list"; | |
3909 | case DW_AT_encoding: | |
3910 | return "DW_AT_encoding"; | |
3911 | case DW_AT_external: | |
3912 | return "DW_AT_external"; | |
3913 | case DW_AT_frame_base: | |
3914 | return "DW_AT_frame_base"; | |
3915 | case DW_AT_friend: | |
3916 | return "DW_AT_friend"; | |
3917 | case DW_AT_identifier_case: | |
3918 | return "DW_AT_identifier_case"; | |
3919 | case DW_AT_macro_info: | |
3920 | return "DW_AT_macro_info"; | |
3921 | case DW_AT_namelist_items: | |
3922 | return "DW_AT_namelist_items"; | |
3923 | case DW_AT_priority: | |
3924 | return "DW_AT_priority"; | |
3925 | case DW_AT_segment: | |
3926 | return "DW_AT_segment"; | |
3927 | case DW_AT_specification: | |
3928 | return "DW_AT_specification"; | |
3929 | case DW_AT_static_link: | |
3930 | return "DW_AT_static_link"; | |
3931 | case DW_AT_type: | |
3932 | return "DW_AT_type"; | |
3933 | case DW_AT_use_location: | |
3934 | return "DW_AT_use_location"; | |
3935 | case DW_AT_variable_parameter: | |
3936 | return "DW_AT_variable_parameter"; | |
3937 | case DW_AT_virtuality: | |
3938 | return "DW_AT_virtuality"; | |
3939 | case DW_AT_vtable_elem_location: | |
3940 | return "DW_AT_vtable_elem_location"; | |
3941 | ||
3942 | case DW_AT_MIPS_fde: | |
3943 | return "DW_AT_MIPS_fde"; | |
3944 | case DW_AT_MIPS_loop_begin: | |
3945 | return "DW_AT_MIPS_loop_begin"; | |
3946 | case DW_AT_MIPS_tail_loop_begin: | |
3947 | return "DW_AT_MIPS_tail_loop_begin"; | |
3948 | case DW_AT_MIPS_epilog_begin: | |
3949 | return "DW_AT_MIPS_epilog_begin"; | |
3950 | case DW_AT_MIPS_loop_unroll_factor: | |
3951 | return "DW_AT_MIPS_loop_unroll_factor"; | |
3952 | case DW_AT_MIPS_software_pipeline_depth: | |
3953 | return "DW_AT_MIPS_software_pipeline_depth"; | |
3954 | case DW_AT_MIPS_linkage_name: | |
3955 | return "DW_AT_MIPS_linkage_name"; | |
3956 | case DW_AT_MIPS_stride: | |
3957 | return "DW_AT_MIPS_stride"; | |
3958 | case DW_AT_MIPS_abstract_name: | |
3959 | return "DW_AT_MIPS_abstract_name"; | |
3960 | case DW_AT_MIPS_clone_origin: | |
3961 | return "DW_AT_MIPS_clone_origin"; | |
3962 | case DW_AT_MIPS_has_inlines: | |
3963 | return "DW_AT_MIPS_has_inlines"; | |
3964 | ||
3965 | case DW_AT_sf_names: | |
3966 | return "DW_AT_sf_names"; | |
3967 | case DW_AT_src_info: | |
3968 | return "DW_AT_src_info"; | |
3969 | case DW_AT_mac_info: | |
3970 | return "DW_AT_mac_info"; | |
3971 | case DW_AT_src_coords: | |
3972 | return "DW_AT_src_coords"; | |
3973 | case DW_AT_body_begin: | |
3974 | return "DW_AT_body_begin"; | |
3975 | case DW_AT_body_end: | |
3976 | return "DW_AT_body_end"; | |
3977 | default: | |
3978 | return "DW_AT_<unknown>"; | |
3979 | } | |
3980 | } | |
3981 | ||
3982 | /* Convert a DWARF value form code into its string name. */ | |
3983 | ||
3984 | static const char * | |
3985 | dwarf_form_name (form) | |
3986 | register unsigned form; | |
3987 | { | |
3988 | switch (form) | |
3989 | { | |
3990 | case DW_FORM_addr: | |
3991 | return "DW_FORM_addr"; | |
3992 | case DW_FORM_block2: | |
3993 | return "DW_FORM_block2"; | |
3994 | case DW_FORM_block4: | |
3995 | return "DW_FORM_block4"; | |
3996 | case DW_FORM_data2: | |
3997 | return "DW_FORM_data2"; | |
3998 | case DW_FORM_data4: | |
3999 | return "DW_FORM_data4"; | |
4000 | case DW_FORM_data8: | |
4001 | return "DW_FORM_data8"; | |
4002 | case DW_FORM_string: | |
4003 | return "DW_FORM_string"; | |
4004 | case DW_FORM_block: | |
4005 | return "DW_FORM_block"; | |
4006 | case DW_FORM_block1: | |
4007 | return "DW_FORM_block1"; | |
4008 | case DW_FORM_data1: | |
4009 | return "DW_FORM_data1"; | |
4010 | case DW_FORM_flag: | |
4011 | return "DW_FORM_flag"; | |
4012 | case DW_FORM_sdata: | |
4013 | return "DW_FORM_sdata"; | |
4014 | case DW_FORM_strp: | |
4015 | return "DW_FORM_strp"; | |
4016 | case DW_FORM_udata: | |
4017 | return "DW_FORM_udata"; | |
4018 | case DW_FORM_ref_addr: | |
4019 | return "DW_FORM_ref_addr"; | |
4020 | case DW_FORM_ref1: | |
4021 | return "DW_FORM_ref1"; | |
4022 | case DW_FORM_ref2: | |
4023 | return "DW_FORM_ref2"; | |
4024 | case DW_FORM_ref4: | |
4025 | return "DW_FORM_ref4"; | |
4026 | case DW_FORM_ref8: | |
4027 | return "DW_FORM_ref8"; | |
4028 | case DW_FORM_ref_udata: | |
4029 | return "DW_FORM_ref_udata"; | |
4030 | case DW_FORM_indirect: | |
4031 | return "DW_FORM_indirect"; | |
3f76745e | 4032 | default: |
7d9d8943 | 4033 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4034 | } |
4035 | } | |
4036 | ||
3f76745e | 4037 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4038 | |
487a6e06 | 4039 | #if 0 |
d560ee52 | 4040 | static const char * |
3f76745e JM |
4041 | dwarf_type_encoding_name (enc) |
4042 | register unsigned enc; | |
a3f97cbb | 4043 | { |
3f76745e | 4044 | switch (enc) |
a3f97cbb | 4045 | { |
3f76745e JM |
4046 | case DW_ATE_address: |
4047 | return "DW_ATE_address"; | |
4048 | case DW_ATE_boolean: | |
4049 | return "DW_ATE_boolean"; | |
4050 | case DW_ATE_complex_float: | |
4051 | return "DW_ATE_complex_float"; | |
4052 | case DW_ATE_float: | |
4053 | return "DW_ATE_float"; | |
4054 | case DW_ATE_signed: | |
4055 | return "DW_ATE_signed"; | |
4056 | case DW_ATE_signed_char: | |
4057 | return "DW_ATE_signed_char"; | |
4058 | case DW_ATE_unsigned: | |
4059 | return "DW_ATE_unsigned"; | |
4060 | case DW_ATE_unsigned_char: | |
4061 | return "DW_ATE_unsigned_char"; | |
4062 | default: | |
4063 | return "DW_ATE_<unknown>"; | |
4064 | } | |
a3f97cbb | 4065 | } |
487a6e06 | 4066 | #endif |
3f76745e JM |
4067 | \f |
4068 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4069 | instance of an inlined instance of a decl which is local to an inline | |
4070 | function, so we have to trace all of the way back through the origin chain | |
4071 | to find out what sort of node actually served as the original seed for the | |
4072 | given block. */ | |
a3f97cbb | 4073 | |
3f76745e JM |
4074 | static tree |
4075 | decl_ultimate_origin (decl) | |
4076 | register tree decl; | |
a3f97cbb | 4077 | { |
10a11b75 JM |
4078 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4079 | nodes in the function to point to themselves; ignore that if | |
4080 | we're trying to output the abstract instance of this function. */ | |
4081 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4082 | return NULL_TREE; | |
4083 | ||
556273e0 | 4084 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4085 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4086 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4087 | most distant ancestor, this should never happen. */ | |
4088 | abort (); | |
4089 | #endif | |
3f76745e | 4090 | |
02e24c7a | 4091 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4092 | } |
4093 | ||
3f76745e JM |
4094 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4095 | instance of an inlined instance of a block which is local to an inline | |
4096 | function, so we have to trace all of the way back through the origin chain | |
4097 | to find out what sort of node actually served as the original seed for the | |
4098 | given block. */ | |
71dfc51f | 4099 | |
3f76745e JM |
4100 | static tree |
4101 | block_ultimate_origin (block) | |
4102 | register tree block; | |
a3f97cbb | 4103 | { |
3f76745e | 4104 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4105 | |
10a11b75 JM |
4106 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4107 | nodes in the function to point to themselves; ignore that if | |
4108 | we're trying to output the abstract instance of this function. */ | |
4109 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4110 | return NULL_TREE; | |
4111 | ||
3f76745e JM |
4112 | if (immediate_origin == NULL_TREE) |
4113 | return NULL_TREE; | |
4114 | else | |
4115 | { | |
4116 | register tree ret_val; | |
4117 | register tree lookahead = immediate_origin; | |
71dfc51f | 4118 | |
3f76745e JM |
4119 | do |
4120 | { | |
4121 | ret_val = lookahead; | |
4122 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
4123 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
4124 | : NULL; | |
4125 | } | |
4126 | while (lookahead != NULL && lookahead != ret_val); | |
4127 | ||
4128 | return ret_val; | |
4129 | } | |
a3f97cbb JW |
4130 | } |
4131 | ||
3f76745e JM |
4132 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4133 | of a virtual function may refer to a base class, so we check the 'this' | |
4134 | parameter. */ | |
71dfc51f | 4135 | |
3f76745e JM |
4136 | static tree |
4137 | decl_class_context (decl) | |
4138 | tree decl; | |
a3f97cbb | 4139 | { |
3f76745e | 4140 | tree context = NULL_TREE; |
71dfc51f | 4141 | |
3f76745e JM |
4142 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4143 | context = DECL_CONTEXT (decl); | |
4144 | else | |
4145 | context = TYPE_MAIN_VARIANT | |
4146 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4147 | |
2f939d94 | 4148 | if (context && !TYPE_P (context)) |
3f76745e JM |
4149 | context = NULL_TREE; |
4150 | ||
4151 | return context; | |
a3f97cbb JW |
4152 | } |
4153 | \f | |
a96c67ec | 4154 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4155 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4156 | |
4157 | static inline void | |
3f76745e JM |
4158 | add_dwarf_attr (die, attr) |
4159 | register dw_die_ref die; | |
4160 | register dw_attr_ref attr; | |
a3f97cbb | 4161 | { |
3f76745e | 4162 | if (die != NULL && attr != NULL) |
a3f97cbb | 4163 | { |
a96c67ec JM |
4164 | attr->dw_attr_next = die->die_attr; |
4165 | die->die_attr = attr; | |
a3f97cbb JW |
4166 | } |
4167 | } | |
4168 | ||
c6991660 | 4169 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4170 | static inline dw_val_class |
4171 | AT_class (a) | |
4172 | dw_attr_ref a; | |
4173 | { | |
4174 | return a->dw_attr_val.val_class; | |
4175 | } | |
4176 | ||
3f76745e | 4177 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4178 | |
3f76745e JM |
4179 | static inline void |
4180 | add_AT_flag (die, attr_kind, flag) | |
4181 | register dw_die_ref die; | |
4182 | register enum dwarf_attribute attr_kind; | |
4183 | register unsigned flag; | |
a3f97cbb | 4184 | { |
3f76745e | 4185 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4186 | |
3f76745e JM |
4187 | attr->dw_attr_next = NULL; |
4188 | attr->dw_attr = attr_kind; | |
4189 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4190 | attr->dw_attr_val.v.val_flag = flag; | |
4191 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4192 | } |
4193 | ||
c6991660 | 4194 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4195 | static inline unsigned |
4196 | AT_flag (a) | |
4197 | register dw_attr_ref a; | |
4198 | { | |
4199 | if (a && AT_class (a) == dw_val_class_flag) | |
4200 | return a->dw_attr_val.v.val_flag; | |
4201 | ||
40e8cc95 | 4202 | abort (); |
a96c67ec JM |
4203 | } |
4204 | ||
3f76745e | 4205 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4206 | |
3f76745e JM |
4207 | static inline void |
4208 | add_AT_int (die, attr_kind, int_val) | |
4209 | register dw_die_ref die; | |
4210 | register enum dwarf_attribute attr_kind; | |
4211 | register long int int_val; | |
a3f97cbb | 4212 | { |
3f76745e JM |
4213 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4214 | ||
4215 | attr->dw_attr_next = NULL; | |
4216 | attr->dw_attr = attr_kind; | |
4217 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4218 | attr->dw_attr_val.v.val_int = int_val; | |
4219 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4220 | } |
4221 | ||
c6991660 | 4222 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4223 | static inline long int |
4224 | AT_int (a) | |
4225 | register dw_attr_ref a; | |
4226 | { | |
4227 | if (a && AT_class (a) == dw_val_class_const) | |
4228 | return a->dw_attr_val.v.val_int; | |
4229 | ||
40e8cc95 | 4230 | abort (); |
a96c67ec JM |
4231 | } |
4232 | ||
3f76745e | 4233 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4234 | |
3f76745e JM |
4235 | static inline void |
4236 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
4237 | register dw_die_ref die; | |
4238 | register enum dwarf_attribute attr_kind; | |
4239 | register unsigned long unsigned_val; | |
a3f97cbb | 4240 | { |
3f76745e JM |
4241 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4242 | ||
4243 | attr->dw_attr_next = NULL; | |
4244 | attr->dw_attr = attr_kind; | |
4245 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4246 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4247 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4248 | } |
71dfc51f | 4249 | |
c6991660 | 4250 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4251 | static inline unsigned long |
4252 | AT_unsigned (a) | |
4253 | register dw_attr_ref a; | |
4254 | { | |
4255 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4256 | return a->dw_attr_val.v.val_unsigned; | |
4257 | ||
40e8cc95 | 4258 | abort (); |
a96c67ec JM |
4259 | } |
4260 | ||
3f76745e JM |
4261 | /* Add an unsigned double integer attribute value to a DIE. */ |
4262 | ||
4263 | static inline void | |
4264 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 4265 | register dw_die_ref die; |
3f76745e JM |
4266 | register enum dwarf_attribute attr_kind; |
4267 | register unsigned long val_hi; | |
4268 | register unsigned long val_low; | |
a3f97cbb | 4269 | { |
3f76745e | 4270 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4271 | |
3f76745e JM |
4272 | attr->dw_attr_next = NULL; |
4273 | attr->dw_attr = attr_kind; | |
4274 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4275 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4276 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4277 | add_dwarf_attr (die, attr); | |
4278 | } | |
71dfc51f | 4279 | |
3f76745e | 4280 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4281 | |
3f76745e JM |
4282 | static inline void |
4283 | add_AT_float (die, attr_kind, length, array) | |
4284 | register dw_die_ref die; | |
4285 | register enum dwarf_attribute attr_kind; | |
4286 | register unsigned length; | |
4287 | register long *array; | |
4288 | { | |
4289 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4290 | ||
4291 | attr->dw_attr_next = NULL; | |
4292 | attr->dw_attr = attr_kind; | |
4293 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4294 | attr->dw_attr_val.v.val_float.length = length; | |
4295 | attr->dw_attr_val.v.val_float.array = array; | |
4296 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4297 | } |
4298 | ||
3f76745e | 4299 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4300 | |
3f76745e JM |
4301 | static inline void |
4302 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 4303 | register dw_die_ref die; |
3f76745e | 4304 | register enum dwarf_attribute attr_kind; |
d560ee52 | 4305 | register const char *str; |
a3f97cbb | 4306 | { |
3f76745e | 4307 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4308 | |
3f76745e JM |
4309 | attr->dw_attr_next = NULL; |
4310 | attr->dw_attr = attr_kind; | |
4311 | attr->dw_attr_val.val_class = dw_val_class_str; | |
4312 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
4313 | add_dwarf_attr (die, attr); | |
4314 | } | |
71dfc51f | 4315 | |
c6991660 | 4316 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4317 | static inline const char * |
4318 | AT_string (a) | |
4319 | register dw_attr_ref a; | |
4320 | { | |
4321 | if (a && AT_class (a) == dw_val_class_str) | |
4322 | return a->dw_attr_val.v.val_str; | |
4323 | ||
40e8cc95 | 4324 | abort (); |
a96c67ec JM |
4325 | } |
4326 | ||
3f76745e | 4327 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4328 | |
3f76745e JM |
4329 | static inline void |
4330 | add_AT_die_ref (die, attr_kind, targ_die) | |
4331 | register dw_die_ref die; | |
4332 | register enum dwarf_attribute attr_kind; | |
4333 | register dw_die_ref targ_die; | |
4334 | { | |
4335 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4336 | |
3f76745e JM |
4337 | attr->dw_attr_next = NULL; |
4338 | attr->dw_attr = attr_kind; | |
4339 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4340 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4341 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4342 | add_dwarf_attr (die, attr); |
4343 | } | |
b1ccbc24 | 4344 | |
c6991660 | 4345 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4346 | static inline dw_die_ref |
4347 | AT_ref (a) | |
4348 | register dw_attr_ref a; | |
4349 | { | |
4350 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4351 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4352 | |
40e8cc95 | 4353 | abort (); |
a96c67ec JM |
4354 | } |
4355 | ||
881c6935 JM |
4356 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); |
4357 | static inline int | |
4358 | AT_ref_external (a) | |
4359 | register dw_attr_ref a; | |
4360 | { | |
4361 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4362 | return a->dw_attr_val.v.val_die_ref.external; | |
4363 | ||
4364 | return 0; | |
4365 | } | |
4366 | ||
4367 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
4368 | static inline void | |
4369 | set_AT_ref_external (a, i) | |
4370 | register dw_attr_ref a; | |
4371 | int i; | |
4372 | { | |
4373 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4374 | a->dw_attr_val.v.val_die_ref.external = i; | |
4375 | else | |
4376 | abort (); | |
4377 | } | |
4378 | ||
3f76745e | 4379 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4380 | |
3f76745e JM |
4381 | static inline void |
4382 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
4383 | register dw_die_ref die; | |
4384 | register enum dwarf_attribute attr_kind; | |
4385 | register unsigned targ_fde; | |
4386 | { | |
4387 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 4388 | |
3f76745e JM |
4389 | attr->dw_attr_next = NULL; |
4390 | attr->dw_attr = attr_kind; | |
4391 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4392 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4393 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4394 | } |
71dfc51f | 4395 | |
3f76745e | 4396 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4397 | |
3f76745e JM |
4398 | static inline void |
4399 | add_AT_loc (die, attr_kind, loc) | |
4400 | register dw_die_ref die; | |
4401 | register enum dwarf_attribute attr_kind; | |
4402 | register dw_loc_descr_ref loc; | |
4403 | { | |
4404 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4405 | |
3f76745e JM |
4406 | attr->dw_attr_next = NULL; |
4407 | attr->dw_attr = attr_kind; | |
4408 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4409 | attr->dw_attr_val.v.val_loc = loc; | |
4410 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4411 | } |
4412 | ||
c6991660 | 4413 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4414 | static inline dw_loc_descr_ref |
4415 | AT_loc (a) | |
4416 | register dw_attr_ref a; | |
4417 | { | |
4418 | if (a && AT_class (a) == dw_val_class_loc) | |
4419 | return a->dw_attr_val.v.val_loc; | |
4420 | ||
40e8cc95 | 4421 | abort (); |
a96c67ec JM |
4422 | } |
4423 | ||
3f76745e | 4424 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4425 | |
3f76745e JM |
4426 | static inline void |
4427 | add_AT_addr (die, attr_kind, addr) | |
4428 | register dw_die_ref die; | |
4429 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 4430 | rtx addr; |
a3f97cbb | 4431 | { |
3f76745e | 4432 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4433 | |
3f76745e JM |
4434 | attr->dw_attr_next = NULL; |
4435 | attr->dw_attr = attr_kind; | |
4436 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4437 | attr->dw_attr_val.v.val_addr = addr; | |
4438 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4439 | } |
4440 | ||
c6991660 | 4441 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 4442 | static inline rtx |
a96c67ec JM |
4443 | AT_addr (a) |
4444 | register dw_attr_ref a; | |
4445 | { | |
4446 | if (a && AT_class (a) == dw_val_class_addr) | |
4447 | return a->dw_attr_val.v.val_addr; | |
4448 | ||
40e8cc95 | 4449 | abort (); |
a96c67ec JM |
4450 | } |
4451 | ||
3f76745e | 4452 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4453 | |
3f76745e JM |
4454 | static inline void |
4455 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
4456 | register dw_die_ref die; | |
4457 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4458 | register const char *lbl_id; |
a3f97cbb | 4459 | { |
3f76745e | 4460 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4461 | |
3f76745e JM |
4462 | attr->dw_attr_next = NULL; |
4463 | attr->dw_attr = attr_kind; | |
4464 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4465 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4466 | add_dwarf_attr (die, attr); | |
4467 | } | |
71dfc51f | 4468 | |
3f76745e JM |
4469 | /* Add a section offset attribute value to a DIE. */ |
4470 | ||
4471 | static inline void | |
8b790721 | 4472 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
4473 | register dw_die_ref die; |
4474 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4475 | register const char *label; |
3f76745e JM |
4476 | { |
4477 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4478 | |
3f76745e JM |
4479 | attr->dw_attr_next = NULL; |
4480 | attr->dw_attr = attr_kind; | |
8b790721 | 4481 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4482 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4483 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4484 | } |
4485 | ||
c6991660 | 4486 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4487 | static inline const char * |
4488 | AT_lbl (a) | |
4489 | register dw_attr_ref a; | |
a3f97cbb | 4490 | { |
a96c67ec JM |
4491 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4492 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4493 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4494 | |
40e8cc95 | 4495 | abort (); |
a3f97cbb JW |
4496 | } |
4497 | ||
3f76745e | 4498 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4499 | |
3f76745e JM |
4500 | static inline dw_attr_ref |
4501 | get_AT (die, attr_kind) | |
4502 | register dw_die_ref die; | |
4503 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 4504 | { |
3f76745e JM |
4505 | register dw_attr_ref a; |
4506 | register dw_die_ref spec = NULL; | |
556273e0 | 4507 | |
3f76745e JM |
4508 | if (die != NULL) |
4509 | { | |
4510 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
4511 | { | |
4512 | if (a->dw_attr == attr_kind) | |
4513 | return a; | |
71dfc51f | 4514 | |
3f76745e JM |
4515 | if (a->dw_attr == DW_AT_specification |
4516 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 4517 | spec = AT_ref (a); |
3f76745e | 4518 | } |
71dfc51f | 4519 | |
3f76745e JM |
4520 | if (spec) |
4521 | return get_AT (spec, attr_kind); | |
4522 | } | |
4523 | ||
4524 | return NULL; | |
f37230f0 JM |
4525 | } |
4526 | ||
3f76745e JM |
4527 | /* Return the "low pc" attribute value, typically associated with |
4528 | a subprogram DIE. Return null if the "low pc" attribute is | |
4529 | either not prsent, or if it cannot be represented as an | |
4530 | assembler label identifier. */ | |
71dfc51f | 4531 | |
a96c67ec | 4532 | static inline const char * |
3f76745e JM |
4533 | get_AT_low_pc (die) |
4534 | register dw_die_ref die; | |
7e23cb16 | 4535 | { |
3f76745e | 4536 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
40e8cc95 | 4537 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4538 | } |
4539 | ||
3f76745e JM |
4540 | /* Return the "high pc" attribute value, typically associated with |
4541 | a subprogram DIE. Return null if the "high pc" attribute is | |
4542 | either not prsent, or if it cannot be represented as an | |
4543 | assembler label identifier. */ | |
71dfc51f | 4544 | |
a96c67ec | 4545 | static inline const char * |
3f76745e | 4546 | get_AT_hi_pc (die) |
a3f97cbb JW |
4547 | register dw_die_ref die; |
4548 | { | |
3f76745e | 4549 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
40e8cc95 | 4550 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4551 | } |
4552 | ||
4553 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4554 | NULL if it is not present. */ | |
71dfc51f | 4555 | |
a96c67ec | 4556 | static inline const char * |
3f76745e JM |
4557 | get_AT_string (die, attr_kind) |
4558 | register dw_die_ref die; | |
4559 | register enum dwarf_attribute attr_kind; | |
4560 | { | |
4561 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4562 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4563 | } |
4564 | ||
3f76745e JM |
4565 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4566 | if it is not present. */ | |
71dfc51f | 4567 | |
3f76745e JM |
4568 | static inline int |
4569 | get_AT_flag (die, attr_kind) | |
4570 | register dw_die_ref die; | |
4571 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4572 | { |
3f76745e | 4573 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4574 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4575 | } |
4576 | ||
3f76745e JM |
4577 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4578 | if it is not present. */ | |
71dfc51f | 4579 | |
3f76745e JM |
4580 | static inline unsigned |
4581 | get_AT_unsigned (die, attr_kind) | |
4582 | register dw_die_ref die; | |
4583 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4584 | { |
3f76745e | 4585 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4586 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4587 | } |
71dfc51f | 4588 | |
a96c67ec JM |
4589 | static inline dw_die_ref |
4590 | get_AT_ref (die, attr_kind) | |
4591 | dw_die_ref die; | |
4592 | register enum dwarf_attribute attr_kind; | |
4593 | { | |
4594 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4595 | return a ? AT_ref (a) : NULL; |
3f76745e | 4596 | } |
71dfc51f | 4597 | |
3f76745e JM |
4598 | static inline int |
4599 | is_c_family () | |
4600 | { | |
4601 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4602 | |
3f76745e JM |
4603 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4604 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4605 | } |
71dfc51f | 4606 | |
3f76745e JM |
4607 | static inline int |
4608 | is_fortran () | |
4609 | { | |
4610 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4611 | |
3f76745e | 4612 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4613 | } |
71dfc51f | 4614 | |
28985b81 AG |
4615 | static inline int |
4616 | is_java () | |
4617 | { | |
4618 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
4619 | ||
4620 | return (lang == DW_LANG_Java); | |
4621 | } | |
4622 | ||
10a11b75 | 4623 | /* Free up the memory used by A. */ |
71dfc51f | 4624 | |
c6991660 | 4625 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4626 | static inline void |
10a11b75 JM |
4627 | free_AT (a) |
4628 | dw_attr_ref a; | |
4629 | { | |
4630 | switch (AT_class (a)) | |
4631 | { | |
10a11b75 JM |
4632 | case dw_val_class_str: |
4633 | case dw_val_class_lbl_id: | |
4634 | case dw_val_class_lbl_offset: | |
4635 | free (a->dw_attr_val.v.val_str); | |
4636 | break; | |
4637 | ||
3724ec07 WC |
4638 | case dw_val_class_float: |
4639 | free (a->dw_attr_val.v.val_float.array); | |
4640 | break; | |
4641 | ||
10a11b75 JM |
4642 | default: |
4643 | break; | |
4644 | } | |
4645 | ||
4646 | free (a); | |
556273e0 | 4647 | } |
10a11b75 JM |
4648 | |
4649 | /* Remove the specified attribute if present. */ | |
4650 | ||
4651 | static void | |
3f76745e JM |
4652 | remove_AT (die, attr_kind) |
4653 | register dw_die_ref die; | |
4654 | register enum dwarf_attribute attr_kind; | |
4655 | { | |
a96c67ec | 4656 | register dw_attr_ref *p; |
6d649d26 | 4657 | register dw_attr_ref removed = NULL; |
a3f97cbb | 4658 | |
3f76745e JM |
4659 | if (die != NULL) |
4660 | { | |
a96c67ec JM |
4661 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4662 | if ((*p)->dw_attr == attr_kind) | |
4663 | { | |
4664 | removed = *p; | |
4665 | *p = (*p)->dw_attr_next; | |
4666 | break; | |
4667 | } | |
71dfc51f | 4668 | |
a96c67ec | 4669 | if (removed != 0) |
10a11b75 JM |
4670 | free_AT (removed); |
4671 | } | |
4672 | } | |
71dfc51f | 4673 | |
10a11b75 | 4674 | /* Free up the memory used by DIE. */ |
71dfc51f | 4675 | |
c6991660 | 4676 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
4677 | static inline void |
4678 | free_die (die) | |
4679 | dw_die_ref die; | |
4680 | { | |
4681 | remove_children (die); | |
4682 | free (die); | |
3f76745e | 4683 | } |
71dfc51f | 4684 | |
3f76745e | 4685 | /* Discard the children of this DIE. */ |
71dfc51f | 4686 | |
10a11b75 | 4687 | static void |
3f76745e JM |
4688 | remove_children (die) |
4689 | register dw_die_ref die; | |
4690 | { | |
4691 | register dw_die_ref child_die = die->die_child; | |
4692 | ||
4693 | die->die_child = NULL; | |
3f76745e JM |
4694 | |
4695 | while (child_die != NULL) | |
a3f97cbb | 4696 | { |
3f76745e JM |
4697 | register dw_die_ref tmp_die = child_die; |
4698 | register dw_attr_ref a; | |
71dfc51f | 4699 | |
3f76745e | 4700 | child_die = child_die->die_sib; |
556273e0 KH |
4701 | |
4702 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4703 | { |
3f76745e | 4704 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4705 | |
3f76745e | 4706 | a = a->dw_attr_next; |
10a11b75 | 4707 | free_AT (tmp_a); |
a3f97cbb | 4708 | } |
71dfc51f | 4709 | |
10a11b75 | 4710 | free_die (tmp_die); |
3f76745e JM |
4711 | } |
4712 | } | |
71dfc51f | 4713 | |
a96c67ec | 4714 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4715 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 4716 | |
3f76745e JM |
4717 | static inline void |
4718 | add_child_die (die, child_die) | |
4719 | register dw_die_ref die; | |
4720 | register dw_die_ref child_die; | |
4721 | { | |
4722 | if (die != NULL && child_die != NULL) | |
e90b62db | 4723 | { |
3a88cbd1 JL |
4724 | if (die == child_die) |
4725 | abort (); | |
3f76745e | 4726 | child_die->die_parent = die; |
a96c67ec JM |
4727 | child_die->die_sib = die->die_child; |
4728 | die->die_child = child_die; | |
3f76745e JM |
4729 | } |
4730 | } | |
4731 | ||
2081603c JM |
4732 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4733 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4734 | |
4735 | static void | |
4736 | splice_child_die (parent, child) | |
4737 | dw_die_ref parent, child; | |
4738 | { | |
4739 | dw_die_ref *p; | |
4740 | ||
4741 | /* We want the declaration DIE from inside the class, not the | |
4742 | specification DIE at toplevel. */ | |
4743 | if (child->die_parent != parent) | |
2081603c JM |
4744 | { |
4745 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4746 | if (tmp) | |
4747 | child = tmp; | |
4748 | } | |
10a11b75 | 4749 | |
2081603c JM |
4750 | if (child->die_parent != parent |
4751 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4752 | abort (); |
4753 | ||
5de0e8d4 | 4754 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
4755 | if (*p == child) |
4756 | { | |
4757 | *p = child->die_sib; | |
4758 | break; | |
4759 | } | |
4760 | ||
4761 | child->die_sib = parent->die_child; | |
4762 | parent->die_child = child; | |
4763 | } | |
4764 | ||
3f76745e JM |
4765 | /* Return a pointer to a newly created DIE node. */ |
4766 | ||
4767 | static inline dw_die_ref | |
4768 | new_die (tag_value, parent_die) | |
4769 | register enum dwarf_tag tag_value; | |
4770 | register dw_die_ref parent_die; | |
4771 | { | |
4772 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
4773 | ||
4774 | die->die_tag = tag_value; | |
4775 | die->die_abbrev = 0; | |
4776 | die->die_offset = 0; | |
4777 | die->die_child = NULL; | |
4778 | die->die_parent = NULL; | |
4779 | die->die_sib = NULL; | |
3f76745e | 4780 | die->die_attr = NULL; |
881c6935 | 4781 | die->die_symbol = NULL; |
3f76745e JM |
4782 | |
4783 | if (parent_die != NULL) | |
4784 | add_child_die (parent_die, die); | |
4785 | else | |
ef76d03b JW |
4786 | { |
4787 | limbo_die_node *limbo_node; | |
4788 | ||
4789 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4790 | limbo_node->die = die; | |
4791 | limbo_node->next = limbo_die_list; | |
4792 | limbo_die_list = limbo_node; | |
4793 | } | |
71dfc51f | 4794 | |
3f76745e JM |
4795 | return die; |
4796 | } | |
71dfc51f | 4797 | |
3f76745e | 4798 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4799 | |
3f76745e JM |
4800 | static inline dw_die_ref |
4801 | lookup_type_die (type) | |
4802 | register tree type; | |
4803 | { | |
4061f623 BS |
4804 | if (TREE_CODE (type) == VECTOR_TYPE) |
4805 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
3f76745e JM |
4806 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
4807 | } | |
e90b62db | 4808 | |
3f76745e | 4809 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4810 | |
10a11b75 | 4811 | static inline void |
3f76745e JM |
4812 | equate_type_number_to_die (type, type_die) |
4813 | register tree type; | |
4814 | register dw_die_ref type_die; | |
4815 | { | |
4816 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4817 | } | |
71dfc51f | 4818 | |
3f76745e | 4819 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4820 | |
3f76745e JM |
4821 | static inline dw_die_ref |
4822 | lookup_decl_die (decl) | |
4823 | register tree decl; | |
4824 | { | |
4825 | register unsigned decl_id = DECL_UID (decl); | |
4826 | ||
4827 | return (decl_id < decl_die_table_in_use | |
4828 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4829 | } |
4830 | ||
3f76745e | 4831 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4832 | |
3f76745e JM |
4833 | static void |
4834 | equate_decl_number_to_die (decl, decl_die) | |
4835 | register tree decl; | |
4836 | register dw_die_ref decl_die; | |
a3f97cbb | 4837 | { |
3f76745e | 4838 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 4839 | register unsigned num_allocated; |
d291dd49 | 4840 | |
3f76745e | 4841 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4842 | { |
3f76745e JM |
4843 | num_allocated |
4844 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4845 | / DECL_DIE_TABLE_INCREMENT) | |
4846 | * DECL_DIE_TABLE_INCREMENT; | |
4847 | ||
4848 | decl_die_table | |
4849 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4850 | sizeof (dw_die_ref) * num_allocated); | |
4851 | ||
961192e1 | 4852 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
4853 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
4854 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4855 | } |
71dfc51f | 4856 | |
3f76745e JM |
4857 | if (decl_id >= decl_die_table_in_use) |
4858 | decl_die_table_in_use = (decl_id + 1); | |
4859 | ||
4860 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 4861 | } |
3f76745e JM |
4862 | \f |
4863 | /* Keep track of the number of spaces used to indent the | |
4864 | output of the debugging routines that print the structure of | |
4865 | the DIE internal representation. */ | |
4866 | static int print_indent; | |
71dfc51f | 4867 | |
3f76745e JM |
4868 | /* Indent the line the number of spaces given by print_indent. */ |
4869 | ||
4870 | static inline void | |
4871 | print_spaces (outfile) | |
4872 | FILE *outfile; | |
4873 | { | |
4874 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4875 | } |
4876 | ||
956d6950 | 4877 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4878 | This routine is a debugging aid only. */ |
71dfc51f | 4879 | |
a3f97cbb | 4880 | static void |
3f76745e JM |
4881 | print_die (die, outfile) |
4882 | dw_die_ref die; | |
4883 | FILE *outfile; | |
a3f97cbb | 4884 | { |
3f76745e JM |
4885 | register dw_attr_ref a; |
4886 | register dw_die_ref c; | |
71dfc51f | 4887 | |
3f76745e | 4888 | print_spaces (outfile); |
2d8b0f3a | 4889 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
4890 | die->die_offset, dwarf_tag_name (die->die_tag)); |
4891 | print_spaces (outfile); | |
2d8b0f3a JL |
4892 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
4893 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
4894 | |
4895 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 4896 | { |
3f76745e JM |
4897 | print_spaces (outfile); |
4898 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
4899 | ||
a96c67ec | 4900 | switch (AT_class (a)) |
3f76745e JM |
4901 | { |
4902 | case dw_val_class_addr: | |
4903 | fprintf (outfile, "address"); | |
4904 | break; | |
4905 | case dw_val_class_loc: | |
4906 | fprintf (outfile, "location descriptor"); | |
4907 | break; | |
4908 | case dw_val_class_const: | |
a96c67ec | 4909 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
4910 | break; |
4911 | case dw_val_class_unsigned_const: | |
a96c67ec | 4912 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
4913 | break; |
4914 | case dw_val_class_long_long: | |
2d8b0f3a | 4915 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
4916 | a->dw_attr_val.v.val_long_long.hi, |
4917 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
4918 | break; |
4919 | case dw_val_class_float: | |
4920 | fprintf (outfile, "floating-point constant"); | |
4921 | break; | |
4922 | case dw_val_class_flag: | |
a96c67ec | 4923 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
4924 | break; |
4925 | case dw_val_class_die_ref: | |
a96c67ec | 4926 | if (AT_ref (a) != NULL) |
881c6935 | 4927 | { |
1bfb5f8f | 4928 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
4929 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
4930 | else | |
4931 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
4932 | } | |
3f76745e JM |
4933 | else |
4934 | fprintf (outfile, "die -> <null>"); | |
4935 | break; | |
4936 | case dw_val_class_lbl_id: | |
8b790721 | 4937 | case dw_val_class_lbl_offset: |
a96c67ec | 4938 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 4939 | break; |
3f76745e | 4940 | case dw_val_class_str: |
a96c67ec JM |
4941 | if (AT_string (a) != NULL) |
4942 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
4943 | else |
4944 | fprintf (outfile, "<null>"); | |
4945 | break; | |
e9a25f70 JL |
4946 | default: |
4947 | break; | |
3f76745e JM |
4948 | } |
4949 | ||
4950 | fprintf (outfile, "\n"); | |
4951 | } | |
4952 | ||
4953 | if (die->die_child != NULL) | |
4954 | { | |
4955 | print_indent += 4; | |
4956 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
4957 | print_die (c, outfile); | |
71dfc51f | 4958 | |
3f76745e | 4959 | print_indent -= 4; |
a3f97cbb | 4960 | } |
881c6935 JM |
4961 | if (print_indent == 0) |
4962 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
4963 | } |
4964 | ||
3f76745e JM |
4965 | /* Print the contents of the source code line number correspondence table. |
4966 | This routine is a debugging aid only. */ | |
71dfc51f | 4967 | |
3f76745e JM |
4968 | static void |
4969 | print_dwarf_line_table (outfile) | |
4970 | FILE *outfile; | |
a3f97cbb | 4971 | { |
3f76745e JM |
4972 | register unsigned i; |
4973 | register dw_line_info_ref line_info; | |
4974 | ||
4975 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
4976 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 4977 | { |
3f76745e JM |
4978 | line_info = &line_info_table[i]; |
4979 | fprintf (outfile, "%5d: ", i); | |
4980 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
2d8b0f3a | 4981 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 4982 | fprintf (outfile, "\n"); |
a3f97cbb | 4983 | } |
3f76745e JM |
4984 | |
4985 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
4986 | } |
4987 | ||
3f76745e JM |
4988 | /* Print the information collected for a given DIE. */ |
4989 | ||
4990 | void | |
4991 | debug_dwarf_die (die) | |
4992 | dw_die_ref die; | |
4993 | { | |
4994 | print_die (die, stderr); | |
4995 | } | |
4996 | ||
4997 | /* Print all DWARF information collected for the compilation unit. | |
4998 | This routine is a debugging aid only. */ | |
4999 | ||
5000 | void | |
5001 | debug_dwarf () | |
5002 | { | |
5003 | print_indent = 0; | |
5004 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5005 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5006 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5007 | } |
5008 | \f | |
a96c67ec JM |
5009 | /* We build up the lists of children and attributes by pushing new ones |
5010 | onto the beginning of the list. Reverse the lists for DIE so that | |
5011 | they are in order of addition. */ | |
71dfc51f | 5012 | |
f37230f0 | 5013 | static void |
a96c67ec | 5014 | reverse_die_lists (die) |
3f76745e | 5015 | register dw_die_ref die; |
f37230f0 | 5016 | { |
a96c67ec JM |
5017 | register dw_die_ref c, cp, cn; |
5018 | register dw_attr_ref a, ap, an; | |
71dfc51f | 5019 | |
a96c67ec | 5020 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5021 | { |
5022 | an = a->dw_attr_next; | |
5023 | a->dw_attr_next = ap; | |
5024 | ap = a; | |
a3f97cbb | 5025 | } |
7d9d8943 | 5026 | die->die_attr = ap; |
3f76745e | 5027 | |
7d9d8943 AM |
5028 | for (c = die->die_child, cp = 0; c; c = cn) |
5029 | { | |
5030 | cn = c->die_sib; | |
5031 | c->die_sib = cp; | |
5032 | cp = c; | |
5033 | } | |
5034 | die->die_child = cp; | |
a3f97cbb JW |
5035 | } |
5036 | ||
881c6935 JM |
5037 | /* reverse_die_lists only reverses the single die you pass it. Since |
5038 | we used to reverse all dies in add_sibling_attributes, which runs | |
5039 | through all the dies, it would reverse all the dies. Now, however, | |
5040 | since we don't call reverse_die_lists in add_sibling_attributes, we | |
5041 | need a routine to recursively reverse all the dies. This is that | |
5042 | routine. */ | |
71dfc51f | 5043 | |
7d9d8943 | 5044 | static void |
881c6935 | 5045 | reverse_all_dies (die) |
7d9d8943 | 5046 | register dw_die_ref die; |
a3f97cbb | 5047 | { |
7d9d8943 | 5048 | register dw_die_ref c; |
71dfc51f | 5049 | |
7d9d8943 | 5050 | reverse_die_lists (die); |
3f76745e | 5051 | |
881c6935 JM |
5052 | for (c = die->die_child; c; c = c->die_sib) |
5053 | reverse_all_dies (c); | |
5054 | } | |
5055 | ||
5056 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is | |
5057 | the CU for the enclosing include file, if any. BINCL_DIE is the | |
5058 | DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this | |
5059 | include file. */ | |
5060 | ||
5061 | static dw_die_ref | |
5062 | push_new_compile_unit (old_unit, bincl_die) | |
5063 | dw_die_ref old_unit, bincl_die; | |
5064 | { | |
5065 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5066 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
5067 | new_unit->die_sib = old_unit; | |
5068 | return new_unit; | |
5069 | } | |
5070 | ||
5071 | /* Close an include-file CU and reopen the enclosing one. */ | |
5072 | ||
5073 | static dw_die_ref | |
5074 | pop_compile_unit (old_unit) | |
5075 | dw_die_ref old_unit; | |
5076 | { | |
5077 | dw_die_ref new_unit = old_unit->die_sib; | |
5078 | old_unit->die_sib = NULL; | |
5079 | return new_unit; | |
5080 | } | |
5081 | ||
5082 | #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) | |
5083 | #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
5084 | ||
5085 | /* Calculate the checksum of a location expression. */ | |
5086 | ||
5087 | static inline void | |
5088 | loc_checksum (loc, ctx) | |
5089 | dw_loc_descr_ref loc; | |
5090 | struct md5_ctx *ctx; | |
5091 | { | |
5092 | PROCESS (loc->dw_loc_opc); | |
5093 | PROCESS (loc->dw_loc_oprnd1); | |
5094 | PROCESS (loc->dw_loc_oprnd2); | |
5095 | } | |
5096 | ||
5097 | /* Calculate the checksum of an attribute. */ | |
5098 | ||
5099 | static void | |
5100 | attr_checksum (at, ctx) | |
5101 | dw_attr_ref at; | |
5102 | struct md5_ctx *ctx; | |
5103 | { | |
5104 | dw_loc_descr_ref loc; | |
5105 | rtx r; | |
5106 | ||
5107 | PROCESS (at->dw_attr); | |
5108 | ||
5109 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5110 | if (at->dw_attr == DW_AT_decl_file |
5111 | /* Or that this was compiled with a different compiler snapshot; if | |
5112 | the output is the same, that's what matters. */ | |
5113 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5114 | return; |
5115 | ||
5116 | switch (AT_class (at)) | |
5117 | { | |
5118 | case dw_val_class_const: | |
5119 | PROCESS (at->dw_attr_val.v.val_int); | |
5120 | break; | |
5121 | case dw_val_class_unsigned_const: | |
5122 | PROCESS (at->dw_attr_val.v.val_unsigned); | |
5123 | break; | |
5124 | case dw_val_class_long_long: | |
5125 | PROCESS (at->dw_attr_val.v.val_long_long); | |
5126 | break; | |
5127 | case dw_val_class_float: | |
5128 | PROCESS (at->dw_attr_val.v.val_float); | |
5129 | break; | |
5130 | case dw_val_class_flag: | |
5131 | PROCESS (at->dw_attr_val.v.val_flag); | |
5132 | break; | |
5133 | ||
5134 | case dw_val_class_str: | |
5135 | PROCESS_STRING (AT_string (at)); | |
5136 | break; | |
5137 | case dw_val_class_addr: | |
5138 | r = AT_addr (at); | |
5139 | switch (GET_CODE (r)) | |
5140 | { | |
5141 | case SYMBOL_REF: | |
5142 | PROCESS_STRING (XSTR (r, 0)); | |
5143 | break; | |
5144 | ||
5145 | default: | |
5146 | abort (); | |
5147 | } | |
5148 | break; | |
5149 | ||
5150 | case dw_val_class_loc: | |
5151 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5152 | loc_checksum (loc, ctx); | |
5153 | break; | |
5154 | ||
5155 | case dw_val_class_die_ref: | |
5156 | if (AT_ref (at)->die_offset) | |
5157 | PROCESS (AT_ref (at)->die_offset); | |
5158 | /* FIXME else use target die name or something. */ | |
5159 | ||
5160 | case dw_val_class_fde_ref: | |
5161 | case dw_val_class_lbl_id: | |
5162 | case dw_val_class_lbl_offset: | |
5163 | ||
5164 | default: | |
5165 | break; | |
5166 | } | |
5167 | } | |
5168 | ||
5169 | /* Calculate the checksum of a DIE. */ | |
5170 | ||
5171 | static void | |
5172 | die_checksum (die, ctx) | |
5173 | dw_die_ref die; | |
5174 | struct md5_ctx *ctx; | |
5175 | { | |
5176 | dw_die_ref c; | |
5177 | dw_attr_ref a; | |
5178 | ||
5179 | PROCESS (die->die_tag); | |
5180 | ||
5181 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5182 | attr_checksum (a, ctx); | |
5183 | ||
5184 | for (c = die->die_child; c; c = c->die_sib) | |
5185 | die_checksum (c, ctx); | |
5186 | } | |
5187 | ||
5188 | #undef PROCESS | |
5189 | #undef PROCESS_STRING | |
5190 | ||
5191 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5192 | info section. */ | |
5193 | static char *comdat_symbol_id; | |
5194 | ||
5195 | /* The index of the current symbol within the current comdat CU. */ | |
5196 | static unsigned int comdat_symbol_number; | |
5197 | ||
5198 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5199 | children, and set comdat_symbol_id accordingly. */ | |
5200 | ||
5201 | static void | |
5202 | compute_section_prefix (unit_die) | |
5203 | dw_die_ref unit_die; | |
5204 | { | |
5205 | char *p, *name; | |
5206 | int i; | |
5207 | unsigned char checksum[16]; | |
5208 | struct md5_ctx ctx; | |
5209 | ||
5210 | md5_init_ctx (&ctx); | |
5211 | die_checksum (unit_die, &ctx); | |
5212 | md5_finish_ctx (&ctx, checksum); | |
5213 | ||
5214 | p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name)); | |
5215 | name = (char *) alloca (strlen (p) + 64); | |
5216 | sprintf (name, "%s.", p); | |
5217 | ||
5218 | clean_symbol_name (name); | |
5219 | ||
5220 | p = name + strlen (name); | |
5221 | for (i = 0; i < 4; ++i) | |
5222 | { | |
5223 | sprintf (p, "%.2x", checksum[i]); | |
5224 | p += 2; | |
5225 | } | |
5226 | ||
5227 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5228 | comdat_symbol_number = 0; | |
5229 | } | |
5230 | ||
5231 | /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */ | |
5232 | ||
5233 | static int | |
5234 | is_type_die (die) | |
5235 | dw_die_ref die; | |
5236 | { | |
5237 | switch (die->die_tag) | |
5238 | { | |
5239 | case DW_TAG_array_type: | |
5240 | case DW_TAG_class_type: | |
5241 | case DW_TAG_enumeration_type: | |
5242 | case DW_TAG_pointer_type: | |
5243 | case DW_TAG_reference_type: | |
5244 | case DW_TAG_string_type: | |
5245 | case DW_TAG_structure_type: | |
5246 | case DW_TAG_subroutine_type: | |
5247 | case DW_TAG_union_type: | |
5248 | case DW_TAG_ptr_to_member_type: | |
5249 | case DW_TAG_set_type: | |
5250 | case DW_TAG_subrange_type: | |
5251 | case DW_TAG_base_type: | |
5252 | case DW_TAG_const_type: | |
5253 | case DW_TAG_file_type: | |
5254 | case DW_TAG_packed_type: | |
5255 | case DW_TAG_volatile_type: | |
5256 | return 1; | |
5257 | default: | |
5258 | return 0; | |
5259 | } | |
5260 | } | |
5261 | ||
5262 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5263 | Basically, we want to choose the bits that are likely to be shared between | |
5264 | compilations (types) and leave out the bits that are specific to individual | |
5265 | compilations (functions). */ | |
5266 | ||
5267 | static int | |
5268 | is_comdat_die (c) | |
5269 | dw_die_ref c; | |
5270 | { | |
5271 | #if 1 | |
5272 | /* I think we want to leave base types and __vtbl_ptr_type in the | |
5273 | main CU, as we do for stabs. The advantage is a greater | |
5274 | likelihood of sharing between objects that don't include headers | |
5275 | in the same order (and therefore would put the base types in a | |
5276 | different comdat). jason 8/28/00 */ | |
5277 | if (c->die_tag == DW_TAG_base_type) | |
5278 | return 0; | |
5279 | ||
5280 | if (c->die_tag == DW_TAG_pointer_type | |
5281 | || c->die_tag == DW_TAG_reference_type | |
5282 | || c->die_tag == DW_TAG_const_type | |
5283 | || c->die_tag == DW_TAG_volatile_type) | |
5284 | { | |
5285 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
5286 | return t ? is_comdat_die (t) : 0; | |
5287 | } | |
5288 | #endif | |
5289 | ||
5290 | return is_type_die (c); | |
5291 | } | |
5292 | ||
5293 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5294 | compilation unit. */ | |
5295 | ||
5296 | static int | |
5297 | is_symbol_die (c) | |
5298 | dw_die_ref c; | |
5299 | { | |
5300 | if (is_type_die (c)) | |
5301 | return 1; | |
5302 | if (get_AT (c, DW_AT_declaration) | |
5303 | && ! get_AT (c, DW_AT_specification)) | |
5304 | return 1; | |
5305 | return 0; | |
5306 | } | |
5307 | ||
5308 | static char * | |
5309 | gen_internal_sym () | |
5310 | { | |
5311 | char buf[256]; | |
5312 | static int label_num; | |
5313 | ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++); | |
5314 | return xstrdup (buf); | |
5315 | } | |
5316 | ||
5317 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5318 | ||
5319 | static void | |
5320 | assign_symbol_names (die) | |
5321 | register dw_die_ref die; | |
5322 | { | |
5323 | register dw_die_ref c; | |
5324 | ||
5325 | if (is_symbol_die (die)) | |
5326 | { | |
5327 | if (comdat_symbol_id) | |
5328 | { | |
5329 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
5330 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, | |
5331 | comdat_symbol_id, comdat_symbol_number++); | |
5332 | die->die_symbol = xstrdup (p); | |
5333 | } | |
5334 | else | |
5335 | die->die_symbol = gen_internal_sym (); | |
5336 | } | |
5337 | ||
5338 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5339 | assign_symbol_names (c); | |
5340 | } | |
5341 | ||
5342 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5343 | additional compilation units for each of the include files we see | |
5344 | bracketed by BINCL/EINCL. */ | |
5345 | ||
5346 | static void | |
5347 | break_out_includes (die) | |
5348 | register dw_die_ref die; | |
5349 | { | |
5350 | dw_die_ref *ptr; | |
5351 | register dw_die_ref unit = NULL; | |
5352 | limbo_die_node *node; | |
5353 | ||
5354 | for (ptr = &(die->die_child); *ptr; ) | |
5355 | { | |
5356 | register dw_die_ref c = *ptr; | |
5357 | ||
5358 | if (c->die_tag == DW_TAG_GNU_BINCL | |
5359 | || c->die_tag == DW_TAG_GNU_EINCL | |
5360 | || (unit && is_comdat_die (c))) | |
5361 | { | |
5362 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5363 | *ptr = c->die_sib; | |
5364 | ||
5365 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5366 | { | |
5367 | unit = push_new_compile_unit (unit, c); | |
5368 | free_die (c); | |
5369 | } | |
5370 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5371 | { | |
5372 | unit = pop_compile_unit (unit); | |
5373 | free_die (c); | |
5374 | } | |
5375 | else | |
5376 | add_child_die (unit, c); | |
5377 | } | |
5378 | else | |
5379 | { | |
5380 | /* Leave this DIE in the main CU. */ | |
5381 | ptr = &(c->die_sib); | |
5382 | continue; | |
5383 | } | |
5384 | } | |
5385 | ||
5386 | #if 0 | |
5387 | /* We can only use this in debugging, since the frontend doesn't check | |
5388 | to make sure that we leave every include file we enter. */ | |
5389 | if (unit != NULL) | |
5390 | abort (); | |
5391 | #endif | |
5392 | ||
5393 | assign_symbol_names (die); | |
5394 | for (node = limbo_die_list; node; node = node->next) | |
5395 | { | |
5396 | compute_section_prefix (node->die); | |
5397 | assign_symbol_names (node->die); | |
5398 | } | |
5399 | } | |
5400 | ||
5401 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5402 | effect of speeding up access to siblings. To save some space, | |
5403 | avoid generating sibling attributes for DIE's without children. */ | |
5404 | ||
5405 | static void | |
5406 | add_sibling_attributes (die) | |
5407 | register dw_die_ref die; | |
5408 | { | |
5409 | register dw_die_ref c; | |
5410 | ||
5411 | if (die->die_tag != DW_TAG_compile_unit | |
5412 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5413 | /* Add the sibling link to the front of the attribute list. */ |
5414 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5415 | ||
5416 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5417 | add_sibling_attributes (c); | |
5418 | } | |
5419 | ||
5420 | /* The format of each DIE (and its attribute value pairs) | |
5421 | is encoded in an abbreviation table. This routine builds the | |
5422 | abbreviation table and assigns a unique abbreviation id for | |
5423 | each abbreviation entry. The children of each die are visited | |
5424 | recursively. */ | |
5425 | ||
5426 | static void | |
5427 | build_abbrev_table (die) | |
5428 | register dw_die_ref die; | |
5429 | { | |
5430 | register unsigned long abbrev_id; | |
5431 | register unsigned long n_alloc; | |
5432 | register dw_die_ref c; | |
5433 | register dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5434 | |
5435 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5436 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 JM |
5437 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
5438 | { | |
5439 | if (AT_class (d_attr) == dw_val_class_die_ref | |
1bfb5f8f | 5440 | && AT_ref (d_attr)->die_mark == 0) |
881c6935 JM |
5441 | { |
5442 | if (AT_ref (d_attr)->die_symbol == 0) | |
5443 | abort (); | |
5444 | set_AT_ref_external (d_attr, 1); | |
5445 | } | |
5446 | } | |
5447 | ||
7d9d8943 AM |
5448 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5449 | { | |
5450 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
5451 | ||
5452 | if (abbrev->die_tag == die->die_tag) | |
5453 | { | |
5454 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5455 | { | |
5456 | a_attr = abbrev->die_attr; | |
5457 | d_attr = die->die_attr; | |
5458 | ||
5459 | while (a_attr != NULL && d_attr != NULL) | |
5460 | { | |
5461 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5462 | || (value_format (a_attr) != value_format (d_attr))) | |
5463 | break; | |
5464 | ||
5465 | a_attr = a_attr->dw_attr_next; | |
5466 | d_attr = d_attr->dw_attr_next; | |
5467 | } | |
5468 | ||
5469 | if (a_attr == NULL && d_attr == NULL) | |
5470 | break; | |
5471 | } | |
5472 | } | |
5473 | } | |
5474 | ||
5475 | if (abbrev_id >= abbrev_die_table_in_use) | |
5476 | { | |
5477 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5478 | { | |
5479 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5480 | abbrev_die_table |
7d9d8943 AM |
5481 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5482 | sizeof (dw_die_ref) * n_alloc); | |
5483 | ||
961192e1 | 5484 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5485 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5486 | abbrev_die_table_allocated = n_alloc; | |
5487 | } | |
5488 | ||
5489 | ++abbrev_die_table_in_use; | |
5490 | abbrev_die_table[abbrev_id] = die; | |
5491 | } | |
5492 | ||
5493 | die->die_abbrev = abbrev_id; | |
5494 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5495 | build_abbrev_table (c); | |
5496 | } | |
5497 | \f | |
5498 | /* Return the size of a string, including the null byte. | |
5499 | ||
5500 | This used to treat backslashes as escapes, and hence they were not included | |
5501 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
5502 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
5503 | we must include them in the count. */ | |
5504 | ||
5505 | static unsigned long | |
5506 | size_of_string (str) | |
5507 | register const char *str; | |
5508 | { | |
5509 | return strlen (str) + 1; | |
3f76745e JM |
5510 | } |
5511 | ||
5512 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
5513 | ||
5514 | static int | |
5515 | constant_size (value) | |
5516 | long unsigned value; | |
5517 | { | |
5518 | int log; | |
5519 | ||
5520 | if (value == 0) | |
5521 | log = 0; | |
a3f97cbb | 5522 | else |
3f76745e | 5523 | log = floor_log2 (value); |
71dfc51f | 5524 | |
3f76745e JM |
5525 | log = log / 8; |
5526 | log = 1 << (floor_log2 (log) + 1); | |
5527 | ||
5528 | return log; | |
a3f97cbb JW |
5529 | } |
5530 | ||
3f76745e JM |
5531 | /* Return the size of a DIE, as it is represented in the |
5532 | .debug_info section. */ | |
71dfc51f | 5533 | |
3f76745e JM |
5534 | static unsigned long |
5535 | size_of_die (die) | |
a3f97cbb JW |
5536 | register dw_die_ref die; |
5537 | { | |
3f76745e | 5538 | register unsigned long size = 0; |
a3f97cbb | 5539 | register dw_attr_ref a; |
71dfc51f | 5540 | |
3f76745e | 5541 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5542 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5543 | { | |
a96c67ec | 5544 | switch (AT_class (a)) |
a3f97cbb JW |
5545 | { |
5546 | case dw_val_class_addr: | |
a1a4189d | 5547 | size += DWARF2_ADDR_SIZE; |
a3f97cbb JW |
5548 | break; |
5549 | case dw_val_class_loc: | |
3f76745e | 5550 | { |
a96c67ec | 5551 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5552 | |
3f76745e JM |
5553 | /* Block length. */ |
5554 | size += constant_size (lsize); | |
5555 | size += lsize; | |
5556 | } | |
a3f97cbb JW |
5557 | break; |
5558 | case dw_val_class_const: | |
25dd13ec | 5559 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5560 | break; |
5561 | case dw_val_class_unsigned_const: | |
a96c67ec | 5562 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5563 | break; |
469ac993 | 5564 | case dw_val_class_long_long: |
3f76745e | 5565 | size += 1 + 8; /* block */ |
469ac993 JM |
5566 | break; |
5567 | case dw_val_class_float: | |
3f76745e | 5568 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5569 | break; |
5570 | case dw_val_class_flag: | |
3f76745e | 5571 | size += 1; |
a3f97cbb JW |
5572 | break; |
5573 | case dw_val_class_die_ref: | |
3f76745e | 5574 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5575 | break; |
5576 | case dw_val_class_fde_ref: | |
3f76745e | 5577 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5578 | break; |
5579 | case dw_val_class_lbl_id: | |
a1a4189d | 5580 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5581 | break; |
8b790721 | 5582 | case dw_val_class_lbl_offset: |
3f76745e JM |
5583 | size += DWARF_OFFSET_SIZE; |
5584 | break; | |
5585 | case dw_val_class_str: | |
a96c67ec | 5586 | size += size_of_string (AT_string (a)); |
3f76745e JM |
5587 | break; |
5588 | default: | |
5589 | abort (); | |
5590 | } | |
a3f97cbb | 5591 | } |
3f76745e JM |
5592 | |
5593 | return size; | |
a3f97cbb JW |
5594 | } |
5595 | ||
956d6950 | 5596 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
5597 | Visits the DIE's children recursively. Updates the global |
5598 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 5599 | current value of next_die_offset to update the die_offset |
3f76745e | 5600 | field in each DIE. */ |
71dfc51f | 5601 | |
a3f97cbb | 5602 | static void |
3f76745e JM |
5603 | calc_die_sizes (die) |
5604 | dw_die_ref die; | |
a3f97cbb | 5605 | { |
3f76745e JM |
5606 | register dw_die_ref c; |
5607 | die->die_offset = next_die_offset; | |
5608 | next_die_offset += size_of_die (die); | |
71dfc51f | 5609 | |
3f76745e JM |
5610 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5611 | calc_die_sizes (c); | |
71dfc51f | 5612 | |
3f76745e JM |
5613 | if (die->die_child != NULL) |
5614 | /* Count the null byte used to terminate sibling lists. */ | |
5615 | next_die_offset += 1; | |
a3f97cbb JW |
5616 | } |
5617 | ||
1bfb5f8f | 5618 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5619 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5620 | DIEs in the same CU will be marked. We used to clear out the offset |
5621 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5622 | |
5623 | static void | |
1bfb5f8f | 5624 | mark_dies (die) |
881c6935 JM |
5625 | dw_die_ref die; |
5626 | { | |
5627 | register dw_die_ref c; | |
1bfb5f8f JM |
5628 | die->die_mark = 1; |
5629 | for (c = die->die_child; c; c = c->die_sib) | |
5630 | mark_dies (c); | |
5631 | } | |
5632 | ||
5633 | /* Clear the marks for a die and its children. */ | |
5634 | ||
5635 | static void | |
5636 | unmark_dies (die) | |
5637 | dw_die_ref die; | |
5638 | { | |
5639 | register dw_die_ref c; | |
5640 | die->die_mark = 0; | |
881c6935 | 5641 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5642 | unmark_dies (c); |
881c6935 JM |
5643 | } |
5644 | ||
3f76745e JM |
5645 | /* Return the size of the line information prolog generated for the |
5646 | compilation unit. */ | |
469ac993 | 5647 | |
3f76745e JM |
5648 | static unsigned long |
5649 | size_of_line_prolog () | |
a94dbf2c | 5650 | { |
3f76745e JM |
5651 | register unsigned long size; |
5652 | register unsigned long ft_index; | |
a94dbf2c | 5653 | |
3f76745e | 5654 | size = DWARF_LINE_PROLOG_HEADER_SIZE; |
469ac993 | 5655 | |
3f76745e JM |
5656 | /* Count the size of the table giving number of args for each |
5657 | standard opcode. */ | |
5658 | size += DWARF_LINE_OPCODE_BASE - 1; | |
71dfc51f | 5659 | |
3f76745e | 5660 | /* Include directory table is empty (at present). Count only the |
38e01259 | 5661 | null byte used to terminate the table. */ |
3f76745e | 5662 | size += 1; |
71dfc51f | 5663 | |
3f76745e JM |
5664 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
5665 | { | |
5666 | /* File name entry. */ | |
5667 | size += size_of_string (file_table[ft_index]); | |
a94dbf2c | 5668 | |
3f76745e JM |
5669 | /* Include directory index. */ |
5670 | size += size_of_uleb128 (0); | |
a94dbf2c | 5671 | |
3f76745e JM |
5672 | /* Modification time. */ |
5673 | size += size_of_uleb128 (0); | |
71dfc51f | 5674 | |
3f76745e JM |
5675 | /* File length in bytes. */ |
5676 | size += size_of_uleb128 (0); | |
a94dbf2c | 5677 | } |
71dfc51f | 5678 | |
3f76745e JM |
5679 | /* Count the file table terminator. */ |
5680 | size += 1; | |
5681 | return size; | |
a94dbf2c JM |
5682 | } |
5683 | ||
3f76745e JM |
5684 | /* Return the size of the .debug_pubnames table generated for the |
5685 | compilation unit. */ | |
a94dbf2c | 5686 | |
3f76745e JM |
5687 | static unsigned long |
5688 | size_of_pubnames () | |
a94dbf2c | 5689 | { |
3f76745e JM |
5690 | register unsigned long size; |
5691 | register unsigned i; | |
469ac993 | 5692 | |
3f76745e JM |
5693 | size = DWARF_PUBNAMES_HEADER_SIZE; |
5694 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 5695 | { |
3f76745e JM |
5696 | register pubname_ref p = &pubname_table[i]; |
5697 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
5698 | } |
5699 | ||
3f76745e JM |
5700 | size += DWARF_OFFSET_SIZE; |
5701 | return size; | |
a94dbf2c JM |
5702 | } |
5703 | ||
956d6950 | 5704 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5705 | |
3f76745e JM |
5706 | static unsigned long |
5707 | size_of_aranges () | |
469ac993 | 5708 | { |
3f76745e | 5709 | register unsigned long size; |
469ac993 | 5710 | |
3f76745e | 5711 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5712 | |
3f76745e | 5713 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5714 | size += 2 * DWARF2_ADDR_SIZE; |
5715 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5716 | |
3f76745e | 5717 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5718 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5719 | return size; |
5720 | } | |
5721 | \f | |
5722 | /* Select the encoding of an attribute value. */ | |
5723 | ||
5724 | static enum dwarf_form | |
a96c67ec JM |
5725 | value_format (a) |
5726 | dw_attr_ref a; | |
3f76745e | 5727 | { |
a96c67ec | 5728 | switch (a->dw_attr_val.val_class) |
469ac993 | 5729 | { |
3f76745e JM |
5730 | case dw_val_class_addr: |
5731 | return DW_FORM_addr; | |
5732 | case dw_val_class_loc: | |
a96c67ec | 5733 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 5734 | { |
3f76745e JM |
5735 | case 1: |
5736 | return DW_FORM_block1; | |
5737 | case 2: | |
5738 | return DW_FORM_block2; | |
469ac993 JM |
5739 | default: |
5740 | abort (); | |
5741 | } | |
3f76745e | 5742 | case dw_val_class_const: |
25dd13ec | 5743 | return DW_FORM_sdata; |
3f76745e | 5744 | case dw_val_class_unsigned_const: |
a96c67ec | 5745 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5746 | { |
5747 | case 1: | |
5748 | return DW_FORM_data1; | |
5749 | case 2: | |
5750 | return DW_FORM_data2; | |
5751 | case 4: | |
5752 | return DW_FORM_data4; | |
5753 | case 8: | |
5754 | return DW_FORM_data8; | |
5755 | default: | |
5756 | abort (); | |
5757 | } | |
5758 | case dw_val_class_long_long: | |
5759 | return DW_FORM_block1; | |
5760 | case dw_val_class_float: | |
5761 | return DW_FORM_block1; | |
5762 | case dw_val_class_flag: | |
5763 | return DW_FORM_flag; | |
5764 | case dw_val_class_die_ref: | |
881c6935 JM |
5765 | if (AT_ref_external (a)) |
5766 | return DW_FORM_ref_addr; | |
5767 | else | |
5768 | return DW_FORM_ref; | |
3f76745e JM |
5769 | case dw_val_class_fde_ref: |
5770 | return DW_FORM_data; | |
5771 | case dw_val_class_lbl_id: | |
5772 | return DW_FORM_addr; | |
8b790721 | 5773 | case dw_val_class_lbl_offset: |
3f76745e JM |
5774 | return DW_FORM_data; |
5775 | case dw_val_class_str: | |
5776 | return DW_FORM_string; | |
469ac993 JM |
5777 | default: |
5778 | abort (); | |
5779 | } | |
a94dbf2c JM |
5780 | } |
5781 | ||
3f76745e | 5782 | /* Output the encoding of an attribute value. */ |
469ac993 | 5783 | |
3f76745e | 5784 | static void |
a96c67ec JM |
5785 | output_value_format (a) |
5786 | dw_attr_ref a; | |
a94dbf2c | 5787 | { |
a96c67ec | 5788 | enum dwarf_form form = value_format (a); |
71dfc51f | 5789 | |
3f76745e | 5790 | output_uleb128 (form); |
c5cec899 | 5791 | if (flag_debug_asm) |
3f76745e | 5792 | fprintf (asm_out_file, " (%s)", dwarf_form_name (form)); |
141719a8 | 5793 | |
3f76745e JM |
5794 | fputc ('\n', asm_out_file); |
5795 | } | |
469ac993 | 5796 | |
3f76745e JM |
5797 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5798 | table. */ | |
469ac993 | 5799 | |
3f76745e JM |
5800 | static void |
5801 | output_abbrev_section () | |
5802 | { | |
5803 | unsigned long abbrev_id; | |
71dfc51f | 5804 | |
3f76745e JM |
5805 | dw_attr_ref a_attr; |
5806 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5807 | { | |
5808 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 5809 | |
3f76745e | 5810 | output_uleb128 (abbrev_id); |
c5cec899 | 5811 | if (flag_debug_asm) |
3f76745e | 5812 | fprintf (asm_out_file, " (abbrev code)"); |
469ac993 | 5813 | |
3f76745e JM |
5814 | fputc ('\n', asm_out_file); |
5815 | output_uleb128 (abbrev->die_tag); | |
c5cec899 | 5816 | if (flag_debug_asm) |
3f76745e JM |
5817 | fprintf (asm_out_file, " (TAG: %s)", |
5818 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 5819 | |
3f76745e | 5820 | fputc ('\n', asm_out_file); |
e8638df0 | 5821 | fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, |
3f76745e | 5822 | abbrev->die_child != NULL ? DW_children_yes : DW_children_no); |
469ac993 | 5823 | |
c5cec899 | 5824 | if (flag_debug_asm) |
3f76745e JM |
5825 | fprintf (asm_out_file, "\t%s %s", |
5826 | ASM_COMMENT_START, | |
5827 | (abbrev->die_child != NULL | |
5828 | ? "DW_children_yes" : "DW_children_no")); | |
5829 | ||
5830 | fputc ('\n', asm_out_file); | |
5831 | ||
5832 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
5833 | a_attr = a_attr->dw_attr_next) | |
5834 | { | |
5835 | output_uleb128 (a_attr->dw_attr); | |
c5cec899 | 5836 | if (flag_debug_asm) |
3f76745e JM |
5837 | fprintf (asm_out_file, " (%s)", |
5838 | dwarf_attr_name (a_attr->dw_attr)); | |
5839 | ||
5840 | fputc ('\n', asm_out_file); | |
a96c67ec | 5841 | output_value_format (a_attr); |
469ac993 | 5842 | } |
469ac993 | 5843 | |
e8638df0 | 5844 | fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP); |
469ac993 | 5845 | } |
81f374eb HPN |
5846 | |
5847 | /* Terminate the table. */ | |
e8638df0 | 5848 | fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP); |
a94dbf2c JM |
5849 | } |
5850 | ||
881c6935 JM |
5851 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
5852 | ||
5853 | static inline void | |
5854 | output_die_symbol (die) | |
5855 | register dw_die_ref die; | |
5856 | { | |
5857 | char *sym = die->die_symbol; | |
5858 | ||
5859 | if (sym == 0) | |
5860 | return; | |
5861 | ||
5862 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
5863 | /* We make these global, not weak; if the target doesn't support | |
5864 | .linkonce, it doesn't support combining the sections, so debugging | |
5865 | will break. */ | |
5866 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
5867 | ASM_OUTPUT_LABEL (asm_out_file, sym); | |
5868 | } | |
5869 | ||
5870 | /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */ | |
5871 | ||
5872 | static inline void | |
5873 | output_symbolic_ref (target_die) | |
5874 | dw_die_ref target_die; | |
5875 | { | |
5876 | char *sym = target_die->die_symbol; | |
5877 | ||
5878 | if (sym == 0) | |
5879 | abort (); | |
5880 | ||
5881 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym); | |
5882 | } | |
5883 | ||
3f76745e JM |
5884 | /* Output the DIE and its attributes. Called recursively to generate |
5885 | the definitions of each child DIE. */ | |
71dfc51f | 5886 | |
a3f97cbb | 5887 | static void |
3f76745e JM |
5888 | output_die (die) |
5889 | register dw_die_ref die; | |
a3f97cbb | 5890 | { |
3f76745e JM |
5891 | register dw_attr_ref a; |
5892 | register dw_die_ref c; | |
3f76745e | 5893 | register unsigned long size; |
a94dbf2c | 5894 | |
881c6935 JM |
5895 | /* If someone in another CU might refer to us, set up a symbol for |
5896 | them to point to. */ | |
5897 | if (die->die_symbol) | |
5898 | output_die_symbol (die); | |
5899 | ||
3f76745e | 5900 | output_uleb128 (die->die_abbrev); |
c5cec899 | 5901 | if (flag_debug_asm) |
2d8b0f3a | 5902 | fprintf (asm_out_file, " (DIE (0x%lx) %s)", |
3f76745e | 5903 | die->die_offset, dwarf_tag_name (die->die_tag)); |
a94dbf2c | 5904 | |
3f76745e | 5905 | fputc ('\n', asm_out_file); |
a94dbf2c | 5906 | |
3f76745e | 5907 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 5908 | { |
a96c67ec | 5909 | switch (AT_class (a)) |
3f76745e JM |
5910 | { |
5911 | case dw_val_class_addr: | |
a96c67ec | 5912 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a)); |
3f76745e | 5913 | break; |
a3f97cbb | 5914 | |
3f76745e | 5915 | case dw_val_class_loc: |
a96c67ec | 5916 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 5917 | |
3f76745e JM |
5918 | /* Output the block length for this list of location operations. */ |
5919 | switch (constant_size (size)) | |
5920 | { | |
5921 | case 1: | |
5922 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size); | |
5923 | break; | |
5924 | case 2: | |
5925 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
5926 | break; | |
5927 | default: | |
5928 | abort (); | |
5929 | } | |
71dfc51f | 5930 | |
c5cec899 | 5931 | if (flag_debug_asm) |
3f76745e JM |
5932 | fprintf (asm_out_file, "\t%s %s", |
5933 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
71dfc51f | 5934 | |
3f76745e | 5935 | fputc ('\n', asm_out_file); |
71dfc51f | 5936 | |
7d9d8943 | 5937 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 5938 | break; |
3f76745e JM |
5939 | |
5940 | case dw_val_class_const: | |
25dd13ec JW |
5941 | /* ??? It would be slightly more efficient to use a scheme like is |
5942 | used for unsigned constants below, but gdb 4.x does not sign | |
5943 | extend. Gdb 5.x does sign extend. */ | |
5944 | output_sleb128 (AT_int (a)); | |
a3f97cbb | 5945 | break; |
3f76745e JM |
5946 | |
5947 | case dw_val_class_unsigned_const: | |
a96c67ec | 5948 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5949 | { |
5950 | case 1: | |
a96c67ec | 5951 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5952 | break; |
5953 | case 2: | |
a96c67ec | 5954 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5955 | break; |
5956 | case 4: | |
a96c67ec | 5957 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5958 | break; |
5959 | case 8: | |
21217bd0 | 5960 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a)); |
3f76745e JM |
5961 | break; |
5962 | default: | |
5963 | abort (); | |
5964 | } | |
a3f97cbb | 5965 | break; |
3f76745e JM |
5966 | |
5967 | case dw_val_class_long_long: | |
5968 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8); | |
c5cec899 | 5969 | if (flag_debug_asm) |
3f76745e | 5970 | fprintf (asm_out_file, "\t%s %s", |
556273e0 | 5971 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); |
3f76745e JM |
5972 | |
5973 | fputc ('\n', asm_out_file); | |
21217bd0 JW |
5974 | ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file, |
5975 | a->dw_attr_val.v.val_long_long.hi, | |
5976 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e | 5977 | |
c5cec899 | 5978 | if (flag_debug_asm) |
3f76745e JM |
5979 | fprintf (asm_out_file, |
5980 | "\t%s long long constant", ASM_COMMENT_START); | |
556273e0 | 5981 | |
3f76745e | 5982 | fputc ('\n', asm_out_file); |
a3f97cbb | 5983 | break; |
3f76745e JM |
5984 | |
5985 | case dw_val_class_float: | |
c84e2712 KG |
5986 | { |
5987 | register unsigned int i; | |
5988 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5989 | a->dw_attr_val.v.val_float.length * 4); | |
5990 | if (flag_debug_asm) | |
5991 | fprintf (asm_out_file, "\t%s %s", | |
5992 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
5993 | ||
5994 | fputc ('\n', asm_out_file); | |
5995 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) | |
5996 | { | |
5997 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
5998 | a->dw_attr_val.v.val_float.array[i]); | |
5999 | if (flag_debug_asm) | |
6000 | fprintf (asm_out_file, "\t%s fp constant word %u", | |
6001 | ASM_COMMENT_START, i); | |
6002 | ||
6003 | fputc ('\n', asm_out_file); | |
6004 | } | |
556273e0 | 6005 | break; |
c84e2712 | 6006 | } |
3f76745e JM |
6007 | |
6008 | case dw_val_class_flag: | |
a96c67ec | 6009 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a)); |
a3f97cbb | 6010 | break; |
3f76745e JM |
6011 | |
6012 | case dw_val_class_die_ref: | |
881c6935 JM |
6013 | if (AT_ref_external (a)) |
6014 | output_symbolic_ref (AT_ref (a)); | |
6015 | else | |
6016 | ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset); | |
a3f97cbb | 6017 | break; |
3f76745e JM |
6018 | |
6019 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6020 | { |
6021 | char l1[20]; | |
6022 | ASM_GENERATE_INTERNAL_LABEL | |
6023 | (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2); | |
6024 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1); | |
6025 | fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE); | |
6026 | } | |
a3f97cbb | 6027 | break; |
a3f97cbb | 6028 | |
3f76745e | 6029 | case dw_val_class_lbl_id: |
a96c67ec | 6030 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a)); |
3f76745e | 6031 | break; |
71dfc51f | 6032 | |
8b790721 | 6033 | case dw_val_class_lbl_offset: |
a96c67ec | 6034 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a)); |
3f76745e | 6035 | break; |
a3f97cbb | 6036 | |
3f76745e | 6037 | case dw_val_class_str: |
8d4e65a6 | 6038 | if (flag_debug_asm) |
a96c67ec | 6039 | ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a)); |
8d4e65a6 | 6040 | else |
a96c67ec JM |
6041 | ASM_OUTPUT_ASCII (asm_out_file, AT_string (a), |
6042 | (int) strlen (AT_string (a)) + 1); | |
3f76745e | 6043 | break; |
b2932ae5 | 6044 | |
3f76745e JM |
6045 | default: |
6046 | abort (); | |
6047 | } | |
a94dbf2c | 6048 | |
a96c67ec JM |
6049 | if (AT_class (a) != dw_val_class_loc |
6050 | && AT_class (a) != dw_val_class_long_long | |
6051 | && AT_class (a) != dw_val_class_float) | |
3f76745e | 6052 | { |
c5cec899 | 6053 | if (flag_debug_asm) |
3f76745e JM |
6054 | fprintf (asm_out_file, "\t%s %s", |
6055 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
b2932ae5 | 6056 | |
3f76745e JM |
6057 | fputc ('\n', asm_out_file); |
6058 | } | |
6059 | } | |
71dfc51f | 6060 | |
3f76745e JM |
6061 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6062 | output_die (c); | |
71dfc51f | 6063 | |
3f76745e | 6064 | if (die->die_child != NULL) |
7e23cb16 | 6065 | { |
556273e0 | 6066 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6067 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); |
c5cec899 | 6068 | if (flag_debug_asm) |
2d8b0f3a | 6069 | fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx", |
3f76745e JM |
6070 | ASM_COMMENT_START, die->die_offset); |
6071 | ||
7e23cb16 JM |
6072 | fputc ('\n', asm_out_file); |
6073 | } | |
3f76745e | 6074 | } |
71dfc51f | 6075 | |
3f76745e JM |
6076 | /* Output the compilation unit that appears at the beginning of the |
6077 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6078 | |
3f76745e JM |
6079 | static void |
6080 | output_compilation_unit_header () | |
6081 | { | |
6082 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE); | |
c5cec899 | 6083 | if (flag_debug_asm) |
3f76745e JM |
6084 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", |
6085 | ASM_COMMENT_START); | |
71dfc51f | 6086 | |
a3f97cbb | 6087 | fputc ('\n', asm_out_file); |
3f76745e | 6088 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
c5cec899 | 6089 | if (flag_debug_asm) |
3f76745e | 6090 | fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START); |
71dfc51f | 6091 | |
a3f97cbb | 6092 | fputc ('\n', asm_out_file); |
8b790721 | 6093 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label); |
c5cec899 | 6094 | if (flag_debug_asm) |
3f76745e JM |
6095 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", |
6096 | ASM_COMMENT_START); | |
71dfc51f | 6097 | |
a3f97cbb | 6098 | fputc ('\n', asm_out_file); |
a1a4189d | 6099 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE); |
c5cec899 | 6100 | if (flag_debug_asm) |
3f76745e | 6101 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START); |
71dfc51f | 6102 | |
a3f97cbb | 6103 | fputc ('\n', asm_out_file); |
a3f97cbb JW |
6104 | } |
6105 | ||
881c6935 JM |
6106 | /* Output the compilation unit DIE and its children. */ |
6107 | ||
6108 | static void | |
6109 | output_comp_unit (die) | |
6110 | dw_die_ref die; | |
6111 | { | |
6112 | char *secname; | |
6113 | ||
6114 | if (die->die_child == 0) | |
6115 | return; | |
6116 | ||
1bfb5f8f JM |
6117 | /* Mark all the DIEs in this CU so we know which get local refs. */ |
6118 | mark_dies (die); | |
6119 | ||
6120 | build_abbrev_table (die); | |
6121 | ||
881c6935 JM |
6122 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
6123 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
6124 | calc_die_sizes (die); | |
6125 | ||
881c6935 JM |
6126 | if (die->die_symbol) |
6127 | { | |
6128 | secname = (char *) alloca (strlen (die->die_symbol) + 24); | |
6129 | sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol); | |
6130 | die->die_symbol = NULL; | |
6131 | } | |
6132 | else | |
6133 | secname = (char *) DEBUG_INFO_SECTION; | |
6134 | ||
6135 | /* Output debugging information. */ | |
6136 | fputc ('\n', asm_out_file); | |
6137 | ASM_OUTPUT_SECTION (asm_out_file, secname); | |
6138 | output_compilation_unit_header (); | |
6139 | output_die (die); | |
6140 | ||
1bfb5f8f JM |
6141 | /* Leave the marks on the main CU, so we can check them in |
6142 | output_pubnames. */ | |
881c6935 | 6143 | if (die->die_symbol) |
1bfb5f8f | 6144 | unmark_dies (die); |
881c6935 JM |
6145 | } |
6146 | ||
a1d7ffe3 JM |
6147 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6148 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6149 | argument list, and maybe the scope. */ | |
6150 | ||
d560ee52 | 6151 | static const char * |
a1d7ffe3 JM |
6152 | dwarf2_name (decl, scope) |
6153 | tree decl; | |
6154 | int scope; | |
6155 | { | |
6156 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6157 | } | |
6158 | ||
d291dd49 | 6159 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6160 | |
d291dd49 JM |
6161 | static void |
6162 | add_pubname (decl, die) | |
6163 | tree decl; | |
6164 | dw_die_ref die; | |
6165 | { | |
6166 | pubname_ref p; | |
6167 | ||
6168 | if (! TREE_PUBLIC (decl)) | |
6169 | return; | |
6170 | ||
6171 | if (pubname_table_in_use == pubname_table_allocated) | |
6172 | { | |
6173 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
6174 | pubname_table = (pubname_ref) xrealloc | |
6175 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
6176 | } | |
71dfc51f | 6177 | |
d291dd49 JM |
6178 | p = &pubname_table[pubname_table_in_use++]; |
6179 | p->die = die; | |
a1d7ffe3 JM |
6180 | |
6181 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
6182 | } |
6183 | ||
a3f97cbb JW |
6184 | /* Output the public names table used to speed up access to externally |
6185 | visible names. For now, only generate entries for externally | |
6186 | visible procedures. */ | |
71dfc51f | 6187 | |
a3f97cbb JW |
6188 | static void |
6189 | output_pubnames () | |
6190 | { | |
d291dd49 | 6191 | register unsigned i; |
71dfc51f RK |
6192 | register unsigned long pubnames_length = size_of_pubnames (); |
6193 | ||
6194 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length); | |
6195 | ||
c5cec899 | 6196 | if (flag_debug_asm) |
71dfc51f RK |
6197 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", |
6198 | ASM_COMMENT_START); | |
6199 | ||
a3f97cbb JW |
6200 | fputc ('\n', asm_out_file); |
6201 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
71dfc51f | 6202 | |
c5cec899 | 6203 | if (flag_debug_asm) |
71dfc51f RK |
6204 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
6205 | ||
a3f97cbb | 6206 | fputc ('\n', asm_out_file); |
8b790721 | 6207 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label); |
c5cec899 | 6208 | if (flag_debug_asm) |
71dfc51f RK |
6209 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
6210 | ASM_COMMENT_START); | |
6211 | ||
a3f97cbb | 6212 | fputc ('\n', asm_out_file); |
7e23cb16 | 6213 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset); |
c5cec899 | 6214 | if (flag_debug_asm) |
71dfc51f RK |
6215 | fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START); |
6216 | ||
a3f97cbb | 6217 | fputc ('\n', asm_out_file); |
d291dd49 | 6218 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 6219 | { |
d291dd49 | 6220 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6221 | |
881c6935 | 6222 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6223 | if (pub->die->die_mark == 0) |
881c6935 JM |
6224 | abort (); |
6225 | ||
7e23cb16 | 6226 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset); |
c5cec899 | 6227 | if (flag_debug_asm) |
71dfc51f RK |
6228 | fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START); |
6229 | ||
d291dd49 JM |
6230 | fputc ('\n', asm_out_file); |
6231 | ||
c5cec899 | 6232 | if (flag_debug_asm) |
8d4e65a6 JL |
6233 | { |
6234 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
6235 | fprintf (asm_out_file, "%s external name", ASM_COMMENT_START); | |
6236 | } | |
6237 | else | |
6238 | { | |
c84e2712 KG |
6239 | ASM_OUTPUT_ASCII (asm_out_file, pub->name, |
6240 | (int) strlen (pub->name) + 1); | |
8d4e65a6 | 6241 | } |
71dfc51f | 6242 | |
d291dd49 | 6243 | fputc ('\n', asm_out_file); |
a3f97cbb | 6244 | } |
71dfc51f | 6245 | |
7e23cb16 | 6246 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); |
a3f97cbb JW |
6247 | fputc ('\n', asm_out_file); |
6248 | } | |
6249 | ||
d291dd49 | 6250 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6251 | |
d291dd49 JM |
6252 | static void |
6253 | add_arange (decl, die) | |
6254 | tree decl; | |
6255 | dw_die_ref die; | |
6256 | { | |
6257 | if (! DECL_SECTION_NAME (decl)) | |
6258 | return; | |
6259 | ||
6260 | if (arange_table_in_use == arange_table_allocated) | |
6261 | { | |
6262 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
6263 | arange_table |
6264 | = (arange_ref) xrealloc (arange_table, | |
6265 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6266 | } |
71dfc51f | 6267 | |
d291dd49 JM |
6268 | arange_table[arange_table_in_use++] = die; |
6269 | } | |
6270 | ||
a3f97cbb JW |
6271 | /* Output the information that goes into the .debug_aranges table. |
6272 | Namely, define the beginning and ending address range of the | |
6273 | text section generated for this compilation unit. */ | |
71dfc51f | 6274 | |
a3f97cbb JW |
6275 | static void |
6276 | output_aranges () | |
6277 | { | |
d291dd49 | 6278 | register unsigned i; |
71dfc51f RK |
6279 | register unsigned long aranges_length = size_of_aranges (); |
6280 | ||
6281 | ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length); | |
c5cec899 | 6282 | if (flag_debug_asm) |
71dfc51f RK |
6283 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", |
6284 | ASM_COMMENT_START); | |
6285 | ||
a3f97cbb JW |
6286 | fputc ('\n', asm_out_file); |
6287 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
c5cec899 | 6288 | if (flag_debug_asm) |
71dfc51f RK |
6289 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
6290 | ||
a3f97cbb | 6291 | fputc ('\n', asm_out_file); |
8b790721 | 6292 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label); |
c5cec899 | 6293 | if (flag_debug_asm) |
71dfc51f RK |
6294 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
6295 | ASM_COMMENT_START); | |
6296 | ||
a3f97cbb | 6297 | fputc ('\n', asm_out_file); |
a1a4189d | 6298 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE); |
c5cec899 | 6299 | if (flag_debug_asm) |
71dfc51f RK |
6300 | fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START); |
6301 | ||
a3f97cbb JW |
6302 | fputc ('\n', asm_out_file); |
6303 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6304 | if (flag_debug_asm) |
71dfc51f RK |
6305 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", |
6306 | ASM_COMMENT_START); | |
6307 | ||
a3f97cbb | 6308 | fputc ('\n', asm_out_file); |
71dfc51f | 6309 | |
262b6384 SC |
6310 | /* We need to align to twice the pointer size here. */ |
6311 | if (DWARF_ARANGES_PAD_SIZE) | |
6312 | { | |
6313 | /* Pad using a 2 bytes word so that padding is correct | |
6314 | for any pointer size. */ | |
6315 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); | |
6316 | for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2) | |
556273e0 | 6317 | fprintf (asm_out_file, ",0"); |
262b6384 | 6318 | if (flag_debug_asm) |
556273e0 KH |
6319 | fprintf (asm_out_file, "\t%s Pad to %d byte boundary", |
6320 | ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE); | |
262b6384 | 6321 | } |
71dfc51f | 6322 | |
a3f97cbb | 6323 | fputc ('\n', asm_out_file); |
8b790721 | 6324 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label); |
c5cec899 | 6325 | if (flag_debug_asm) |
71dfc51f RK |
6326 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
6327 | ||
a3f97cbb | 6328 | fputc ('\n', asm_out_file); |
71208e03 | 6329 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, |
8b790721 | 6330 | text_section_label); |
c5cec899 | 6331 | if (flag_debug_asm) |
71dfc51f RK |
6332 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
6333 | ||
a3f97cbb | 6334 | fputc ('\n', asm_out_file); |
d291dd49 JM |
6335 | for (i = 0; i < arange_table_in_use; ++i) |
6336 | { | |
e689ae67 | 6337 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6338 | |
881c6935 | 6339 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6340 | if (die->die_mark == 0) |
881c6935 JM |
6341 | abort (); |
6342 | ||
e689ae67 JM |
6343 | if (die->die_tag == DW_TAG_subprogram) |
6344 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die)); | |
d291dd49 | 6345 | else |
a1d7ffe3 | 6346 | { |
e689ae67 JM |
6347 | /* A static variable; extract the symbol from DW_AT_location. |
6348 | Note that this code isn't currently hit, as we only emit | |
6349 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 6350 | |
e689ae67 JM |
6351 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6352 | dw_loc_descr_ref loc; | |
a96c67ec | 6353 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6354 | abort (); |
6355 | ||
a96c67ec | 6356 | loc = AT_loc (a); |
e689ae67 JM |
6357 | if (loc->dw_loc_opc != DW_OP_addr) |
6358 | abort (); | |
6359 | ||
1865dbb5 JM |
6360 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, |
6361 | loc->dw_loc_oprnd1.v.val_addr); | |
a1d7ffe3 | 6362 | } |
71dfc51f | 6363 | |
c5cec899 | 6364 | if (flag_debug_asm) |
71dfc51f RK |
6365 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
6366 | ||
d291dd49 | 6367 | fputc ('\n', asm_out_file); |
e689ae67 JM |
6368 | if (die->die_tag == DW_TAG_subprogram) |
6369 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die), | |
6370 | get_AT_low_pc (die)); | |
d291dd49 | 6371 | else |
7e23cb16 | 6372 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, |
e689ae67 | 6373 | get_AT_unsigned (die, DW_AT_byte_size)); |
71dfc51f | 6374 | |
c5cec899 | 6375 | if (flag_debug_asm) |
71dfc51f RK |
6376 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
6377 | ||
d291dd49 JM |
6378 | fputc ('\n', asm_out_file); |
6379 | } | |
71dfc51f | 6380 | |
a3f97cbb | 6381 | /* Output the terminator words. */ |
7e23cb16 | 6382 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb | 6383 | fputc ('\n', asm_out_file); |
7e23cb16 | 6384 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb JW |
6385 | fputc ('\n', asm_out_file); |
6386 | } | |
6387 | ||
6388 | /* Output the source line number correspondence information. This | |
14a774a9 | 6389 | information goes into the .debug_line section. */ |
71dfc51f | 6390 | |
a3f97cbb JW |
6391 | static void |
6392 | output_line_info () | |
6393 | { | |
a3f97cbb JW |
6394 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6395 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6396 | register unsigned opc; | |
6397 | register unsigned n_op_args; | |
a3f97cbb JW |
6398 | register unsigned long ft_index; |
6399 | register unsigned long lt_index; | |
6400 | register unsigned long current_line; | |
6401 | register long line_offset; | |
6402 | register long line_delta; | |
6403 | register unsigned long current_file; | |
e90b62db | 6404 | register unsigned long function; |
71dfc51f | 6405 | |
14a774a9 | 6406 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART"); |
c5cec899 | 6407 | if (flag_debug_asm) |
71dfc51f RK |
6408 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", |
6409 | ASM_COMMENT_START); | |
6410 | ||
a3f97cbb | 6411 | fputc ('\n', asm_out_file); |
14a774a9 | 6412 | ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART"); |
a3f97cbb | 6413 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
c5cec899 | 6414 | if (flag_debug_asm) |
71dfc51f RK |
6415 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
6416 | ||
a3f97cbb | 6417 | fputc ('\n', asm_out_file); |
7e23cb16 | 6418 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); |
c5cec899 | 6419 | if (flag_debug_asm) |
71dfc51f RK |
6420 | fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); |
6421 | ||
a3f97cbb JW |
6422 | fputc ('\n', asm_out_file); |
6423 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
c5cec899 | 6424 | if (flag_debug_asm) |
71dfc51f RK |
6425 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", |
6426 | ASM_COMMENT_START); | |
6427 | ||
a3f97cbb JW |
6428 | fputc ('\n', asm_out_file); |
6429 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
c5cec899 | 6430 | if (flag_debug_asm) |
71dfc51f RK |
6431 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", |
6432 | ASM_COMMENT_START); | |
6433 | ||
a3f97cbb | 6434 | fputc ('\n', asm_out_file); |
e8638df0 | 6435 | fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE); |
c5cec899 | 6436 | if (flag_debug_asm) |
71dfc51f RK |
6437 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", |
6438 | ASM_COMMENT_START); | |
6439 | ||
a3f97cbb | 6440 | fputc ('\n', asm_out_file); |
e8638df0 | 6441 | fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE); |
c5cec899 | 6442 | if (flag_debug_asm) |
71dfc51f RK |
6443 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", |
6444 | ASM_COMMENT_START); | |
6445 | ||
a3f97cbb | 6446 | fputc ('\n', asm_out_file); |
e8638df0 | 6447 | fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); |
c5cec899 | 6448 | if (flag_debug_asm) |
71dfc51f RK |
6449 | fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START); |
6450 | ||
a3f97cbb JW |
6451 | fputc ('\n', asm_out_file); |
6452 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
6453 | { | |
6454 | switch (opc) | |
6455 | { | |
6456 | case DW_LNS_advance_pc: | |
6457 | case DW_LNS_advance_line: | |
6458 | case DW_LNS_set_file: | |
6459 | case DW_LNS_set_column: | |
6460 | case DW_LNS_fixed_advance_pc: | |
6461 | n_op_args = 1; | |
6462 | break; | |
6463 | default: | |
6464 | n_op_args = 0; | |
6465 | break; | |
6466 | } | |
6467 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
c5cec899 | 6468 | if (flag_debug_asm) |
71dfc51f RK |
6469 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", |
6470 | ASM_COMMENT_START, opc, n_op_args); | |
a3f97cbb JW |
6471 | fputc ('\n', asm_out_file); |
6472 | } | |
71dfc51f | 6473 | |
c5cec899 | 6474 | if (flag_debug_asm) |
71dfc51f RK |
6475 | fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START); |
6476 | ||
a3f97cbb JW |
6477 | /* Include directory table is empty, at present */ |
6478 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
6479 | fputc ('\n', asm_out_file); | |
c5cec899 | 6480 | if (flag_debug_asm) |
71dfc51f RK |
6481 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); |
6482 | ||
a3f97cbb JW |
6483 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
6484 | { | |
c5cec899 | 6485 | if (flag_debug_asm) |
8d4e65a6 JL |
6486 | { |
6487 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
2d8b0f3a | 6488 | fprintf (asm_out_file, "%s File Entry: 0x%lx", |
8d4e65a6 JL |
6489 | ASM_COMMENT_START, ft_index); |
6490 | } | |
6491 | else | |
6492 | { | |
6493 | ASM_OUTPUT_ASCII (asm_out_file, | |
6494 | file_table[ft_index], | |
c84e2712 | 6495 | (int) strlen (file_table[ft_index]) + 1); |
8d4e65a6 | 6496 | } |
71dfc51f | 6497 | |
a3f97cbb | 6498 | fputc ('\n', asm_out_file); |
71dfc51f | 6499 | |
a3f97cbb JW |
6500 | /* Include directory index */ |
6501 | output_uleb128 (0); | |
6502 | fputc ('\n', asm_out_file); | |
71dfc51f | 6503 | |
a3f97cbb JW |
6504 | /* Modification time */ |
6505 | output_uleb128 (0); | |
6506 | fputc ('\n', asm_out_file); | |
71dfc51f | 6507 | |
a3f97cbb JW |
6508 | /* File length in bytes */ |
6509 | output_uleb128 (0); | |
6510 | fputc ('\n', asm_out_file); | |
6511 | } | |
71dfc51f | 6512 | |
a3f97cbb JW |
6513 | /* Terminate the file name table */ |
6514 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
6515 | fputc ('\n', asm_out_file); | |
6516 | ||
2f22d404 JM |
6517 | /* We used to set the address register to the first location in the text |
6518 | section here, but that didn't accomplish anything since we already | |
6519 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
6520 | |
6521 | /* Generate the line number to PC correspondence table, encoded as | |
6522 | a series of state machine operations. */ | |
6523 | current_file = 1; | |
6524 | current_line = 1; | |
8b790721 | 6525 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
6526 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
6527 | { | |
2f22d404 JM |
6528 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
6529 | ||
10a11b75 JM |
6530 | #if 0 |
6531 | /* Disable this optimization for now; GDB wants to see two line notes | |
6532 | at the beginning of a function so it can find the end of the | |
6533 | prologue. */ | |
6534 | ||
2f22d404 JM |
6535 | /* Don't emit anything for redundant notes. Just updating the |
6536 | address doesn't accomplish anything, because we already assume | |
6537 | that anything after the last address is this line. */ | |
6538 | if (line_info->dw_line_num == current_line | |
6539 | && line_info->dw_file_num == current_file) | |
6540 | continue; | |
10a11b75 | 6541 | #endif |
71dfc51f | 6542 | |
f19a6894 JW |
6543 | /* Emit debug info for the address of the current line, choosing |
6544 | the encoding that uses the least amount of space. */ | |
6545 | /* ??? Unfortunately, we have little choice here currently, and must | |
6546 | always use the most general form. Gcc does not know the address | |
6547 | delta itself, so we can't use DW_LNS_advance_pc. There are no known | |
6548 | dwarf2 aware assemblers at this time, so we can't use any special | |
6549 | pseudo ops that would allow the assembler to optimally encode this for | |
6550 | us. Many ports do have length attributes which will give an upper | |
6551 | bound on the address range. We could perhaps use length attributes | |
6552 | to determine when it is safe to use DW_LNS_fixed_advance_pc. */ | |
5c90448c | 6553 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
6554 | if (0) |
6555 | { | |
6556 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
6557 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 6558 | if (flag_debug_asm) |
f19a6894 JW |
6559 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
6560 | ASM_COMMENT_START); | |
6561 | ||
6562 | fputc ('\n', asm_out_file); | |
6563 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
6564 | fputc ('\n', asm_out_file); | |
6565 | } | |
6566 | else | |
6567 | { | |
a1a4189d JB |
6568 | /* This can handle any delta. This takes |
6569 | 4+DWARF2_ADDR_SIZE bytes. */ | |
f19a6894 | 6570 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); |
c5cec899 | 6571 | if (flag_debug_asm) |
f19a6894 JW |
6572 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6573 | ASM_COMMENT_START); | |
6574 | fputc ('\n', asm_out_file); | |
a1a4189d | 6575 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
6576 | fputc ('\n', asm_out_file); |
6577 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6578 | fputc ('\n', asm_out_file); | |
6579 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6580 | fputc ('\n', asm_out_file); | |
6581 | } | |
6582 | strcpy (prev_line_label, line_label); | |
6583 | ||
6584 | /* Emit debug info for the source file of the current line, if | |
6585 | different from the previous line. */ | |
a3f97cbb JW |
6586 | if (line_info->dw_file_num != current_file) |
6587 | { | |
6588 | current_file = line_info->dw_file_num; | |
6589 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 6590 | if (flag_debug_asm) |
71dfc51f RK |
6591 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
6592 | ||
a3f97cbb JW |
6593 | fputc ('\n', asm_out_file); |
6594 | output_uleb128 (current_file); | |
c5cec899 | 6595 | if (flag_debug_asm) |
b2932ae5 | 6596 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 6597 | |
a3f97cbb JW |
6598 | fputc ('\n', asm_out_file); |
6599 | } | |
71dfc51f | 6600 | |
f19a6894 JW |
6601 | /* Emit debug info for the current line number, choosing the encoding |
6602 | that uses the least amount of space. */ | |
2f22d404 | 6603 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 6604 | { |
2f22d404 JM |
6605 | line_offset = line_info->dw_line_num - current_line; |
6606 | line_delta = line_offset - DWARF_LINE_BASE; | |
6607 | current_line = line_info->dw_line_num; | |
6608 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6609 | { | |
6610 | /* This can handle deltas from -10 to 234, using the current | |
6611 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
6612 | takes 1 byte. */ | |
6613 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
6614 | DWARF_LINE_OPCODE_BASE + line_delta); | |
6615 | if (flag_debug_asm) | |
6616 | fprintf (asm_out_file, | |
6617 | "\t%s line %ld", ASM_COMMENT_START, current_line); | |
71dfc51f | 6618 | |
2f22d404 JM |
6619 | fputc ('\n', asm_out_file); |
6620 | } | |
6621 | else | |
6622 | { | |
6623 | /* This can handle any delta. This takes at least 4 bytes, | |
6624 | depending on the value being encoded. */ | |
6625 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
6626 | if (flag_debug_asm) | |
6627 | fprintf (asm_out_file, "\t%s advance to line %ld", | |
6628 | ASM_COMMENT_START, current_line); | |
6629 | ||
6630 | fputc ('\n', asm_out_file); | |
6631 | output_sleb128 (line_offset); | |
6632 | fputc ('\n', asm_out_file); | |
6633 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
6634 | if (flag_debug_asm) | |
6635 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
6636 | fputc ('\n', asm_out_file); | |
6637 | } | |
a94dbf2c JM |
6638 | } |
6639 | else | |
6640 | { | |
2f22d404 | 6641 | /* We still need to start a new row, so output a copy insn. */ |
a94dbf2c | 6642 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); |
2f22d404 JM |
6643 | if (flag_debug_asm) |
6644 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
a94dbf2c | 6645 | fputc ('\n', asm_out_file); |
a3f97cbb | 6646 | } |
a3f97cbb JW |
6647 | } |
6648 | ||
f19a6894 JW |
6649 | /* Emit debug info for the address of the end of the function. */ |
6650 | if (0) | |
6651 | { | |
6652 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 6653 | if (flag_debug_asm) |
f19a6894 JW |
6654 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
6655 | ASM_COMMENT_START); | |
71dfc51f | 6656 | |
f19a6894 JW |
6657 | fputc ('\n', asm_out_file); |
6658 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label); | |
6659 | fputc ('\n', asm_out_file); | |
6660 | } | |
6661 | else | |
6662 | { | |
6663 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6664 | if (flag_debug_asm) |
f19a6894 JW |
6665 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
6666 | fputc ('\n', asm_out_file); | |
a1a4189d | 6667 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
6668 | fputc ('\n', asm_out_file); |
6669 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6670 | fputc ('\n', asm_out_file); | |
6671 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label); | |
6672 | fputc ('\n', asm_out_file); | |
6673 | } | |
bdb669cb | 6674 | |
a3f97cbb | 6675 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); |
c5cec899 | 6676 | if (flag_debug_asm) |
71dfc51f RK |
6677 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); |
6678 | ||
a3f97cbb JW |
6679 | fputc ('\n', asm_out_file); |
6680 | output_uleb128 (1); | |
6681 | fputc ('\n', asm_out_file); | |
6682 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
6683 | fputc ('\n', asm_out_file); | |
e90b62db JM |
6684 | |
6685 | function = 0; | |
6686 | current_file = 1; | |
6687 | current_line = 1; | |
556273e0 | 6688 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db JM |
6689 | { |
6690 | register dw_separate_line_info_ref line_info | |
6691 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 6692 | |
10a11b75 | 6693 | #if 0 |
2f22d404 JM |
6694 | /* Don't emit anything for redundant notes. */ |
6695 | if (line_info->dw_line_num == current_line | |
6696 | && line_info->dw_file_num == current_file | |
6697 | && line_info->function == function) | |
6698 | goto cont; | |
10a11b75 | 6699 | #endif |
2f22d404 | 6700 | |
f19a6894 JW |
6701 | /* Emit debug info for the address of the current line. If this is |
6702 | a new function, or the first line of a function, then we need | |
6703 | to handle it differently. */ | |
5c90448c JM |
6704 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
6705 | lt_index); | |
e90b62db JM |
6706 | if (function != line_info->function) |
6707 | { | |
6708 | function = line_info->function; | |
71dfc51f | 6709 | |
e90b62db JM |
6710 | /* Set the address register to the first line in the function */ |
6711 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6712 | if (flag_debug_asm) |
e90b62db JM |
6713 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6714 | ASM_COMMENT_START); | |
71dfc51f | 6715 | |
e90b62db | 6716 | fputc ('\n', asm_out_file); |
a1a4189d | 6717 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
e90b62db JM |
6718 | fputc ('\n', asm_out_file); |
6719 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6720 | fputc ('\n', asm_out_file); | |
6721 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6722 | fputc ('\n', asm_out_file); | |
6723 | } | |
6724 | else | |
6725 | { | |
f19a6894 JW |
6726 | /* ??? See the DW_LNS_advance_pc comment above. */ |
6727 | if (0) | |
6728 | { | |
6729 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 6730 | if (flag_debug_asm) |
f19a6894 JW |
6731 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
6732 | ASM_COMMENT_START); | |
71dfc51f | 6733 | |
f19a6894 JW |
6734 | fputc ('\n', asm_out_file); |
6735 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
6736 | prev_line_label); | |
6737 | fputc ('\n', asm_out_file); | |
6738 | } | |
6739 | else | |
6740 | { | |
6741 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6742 | if (flag_debug_asm) |
f19a6894 JW |
6743 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6744 | ASM_COMMENT_START); | |
6745 | fputc ('\n', asm_out_file); | |
a1a4189d | 6746 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
6747 | fputc ('\n', asm_out_file); |
6748 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6749 | fputc ('\n', asm_out_file); | |
6750 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6751 | fputc ('\n', asm_out_file); | |
6752 | } | |
e90b62db | 6753 | } |
f19a6894 | 6754 | strcpy (prev_line_label, line_label); |
71dfc51f | 6755 | |
f19a6894 JW |
6756 | /* Emit debug info for the source file of the current line, if |
6757 | different from the previous line. */ | |
e90b62db JM |
6758 | if (line_info->dw_file_num != current_file) |
6759 | { | |
6760 | current_file = line_info->dw_file_num; | |
6761 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
c5cec899 | 6762 | if (flag_debug_asm) |
71dfc51f RK |
6763 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
6764 | ||
e90b62db JM |
6765 | fputc ('\n', asm_out_file); |
6766 | output_uleb128 (current_file); | |
c5cec899 | 6767 | if (flag_debug_asm) |
b2932ae5 | 6768 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 6769 | |
e90b62db JM |
6770 | fputc ('\n', asm_out_file); |
6771 | } | |
71dfc51f | 6772 | |
f19a6894 JW |
6773 | /* Emit debug info for the current line number, choosing the encoding |
6774 | that uses the least amount of space. */ | |
e90b62db JM |
6775 | if (line_info->dw_line_num != current_line) |
6776 | { | |
6777 | line_offset = line_info->dw_line_num - current_line; | |
6778 | line_delta = line_offset - DWARF_LINE_BASE; | |
6779 | current_line = line_info->dw_line_num; | |
6780 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6781 | { | |
6782 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
6783 | DWARF_LINE_OPCODE_BASE + line_delta); | |
c5cec899 | 6784 | if (flag_debug_asm) |
71dfc51f | 6785 | fprintf (asm_out_file, |
2d8b0f3a | 6786 | "\t%s line %ld", ASM_COMMENT_START, current_line); |
71dfc51f | 6787 | |
e90b62db JM |
6788 | fputc ('\n', asm_out_file); |
6789 | } | |
6790 | else | |
6791 | { | |
6792 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
c5cec899 | 6793 | if (flag_debug_asm) |
2d8b0f3a | 6794 | fprintf (asm_out_file, "\t%s advance to line %ld", |
71dfc51f RK |
6795 | ASM_COMMENT_START, current_line); |
6796 | ||
e90b62db JM |
6797 | fputc ('\n', asm_out_file); |
6798 | output_sleb128 (line_offset); | |
6799 | fputc ('\n', asm_out_file); | |
6800 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
2f22d404 JM |
6801 | if (flag_debug_asm) |
6802 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
e90b62db JM |
6803 | fputc ('\n', asm_out_file); |
6804 | } | |
6805 | } | |
2f22d404 JM |
6806 | else |
6807 | { | |
6808 | /* We still need to start a new row, so output a copy insn. */ | |
6809 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
6810 | if (flag_debug_asm) | |
6811 | fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START); | |
6812 | fputc ('\n', asm_out_file); | |
6813 | } | |
71dfc51f | 6814 | |
10a11b75 | 6815 | #if 0 |
2f22d404 | 6816 | cont: |
10a11b75 | 6817 | #endif |
e90b62db | 6818 | ++lt_index; |
e90b62db JM |
6819 | |
6820 | /* If we're done with a function, end its sequence. */ | |
6821 | if (lt_index == separate_line_info_table_in_use | |
6822 | || separate_line_info_table[lt_index].function != function) | |
6823 | { | |
6824 | current_file = 1; | |
6825 | current_line = 1; | |
71dfc51f | 6826 | |
f19a6894 | 6827 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 6828 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
6829 | if (0) |
6830 | { | |
6831 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
c5cec899 | 6832 | if (flag_debug_asm) |
f19a6894 JW |
6833 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", |
6834 | ASM_COMMENT_START); | |
6835 | ||
6836 | fputc ('\n', asm_out_file); | |
6837 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
6838 | prev_line_label); | |
6839 | fputc ('\n', asm_out_file); | |
6840 | } | |
6841 | else | |
6842 | { | |
6843 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6844 | if (flag_debug_asm) |
f19a6894 JW |
6845 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", |
6846 | ASM_COMMENT_START); | |
6847 | fputc ('\n', asm_out_file); | |
a1a4189d | 6848 | output_uleb128 (1 + DWARF2_ADDR_SIZE); |
f19a6894 JW |
6849 | fputc ('\n', asm_out_file); |
6850 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
6851 | fputc ('\n', asm_out_file); | |
6852 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
6853 | fputc ('\n', asm_out_file); | |
6854 | } | |
e90b62db JM |
6855 | |
6856 | /* Output the marker for the end of this sequence. */ | |
6857 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
c5cec899 | 6858 | if (flag_debug_asm) |
e90b62db JM |
6859 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", |
6860 | ASM_COMMENT_START); | |
71dfc51f | 6861 | |
e90b62db JM |
6862 | fputc ('\n', asm_out_file); |
6863 | output_uleb128 (1); | |
6864 | fputc ('\n', asm_out_file); | |
6865 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
6866 | fputc ('\n', asm_out_file); | |
6867 | } | |
6868 | } | |
f19f17e0 JM |
6869 | |
6870 | /* Output the marker for the end of the line number info. */ | |
6871 | ASM_OUTPUT_LABEL (asm_out_file, ".LTEND"); | |
a3f97cbb JW |
6872 | } |
6873 | \f | |
a3f97cbb JW |
6874 | /* Given a pointer to a tree node for some base type, return a pointer to |
6875 | a DIE that describes the given type. | |
6876 | ||
6877 | This routine must only be called for GCC type nodes that correspond to | |
6878 | Dwarf base (fundamental) types. */ | |
71dfc51f | 6879 | |
a3f97cbb JW |
6880 | static dw_die_ref |
6881 | base_type_die (type) | |
6882 | register tree type; | |
6883 | { | |
a9d38797 | 6884 | register dw_die_ref base_type_result; |
ec0ce6e2 | 6885 | register const char *type_name; |
a9d38797 | 6886 | register enum dwarf_type encoding; |
71dfc51f | 6887 | register tree name = TYPE_NAME (type); |
a3f97cbb | 6888 | |
a9d38797 JM |
6889 | if (TREE_CODE (type) == ERROR_MARK |
6890 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
6891 | return 0; |
6892 | ||
405f63da MM |
6893 | if (name) |
6894 | { | |
6895 | if (TREE_CODE (name) == TYPE_DECL) | |
6896 | name = DECL_NAME (name); | |
6897 | ||
6898 | type_name = IDENTIFIER_POINTER (name); | |
6899 | } | |
6900 | else | |
6901 | type_name = "__unknown__"; | |
a9d38797 | 6902 | |
a3f97cbb JW |
6903 | switch (TREE_CODE (type)) |
6904 | { | |
a3f97cbb | 6905 | case INTEGER_TYPE: |
a9d38797 | 6906 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 6907 | up if the language is not C. Note that we check only for the names |
556273e0 | 6908 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 6909 | languages. */ |
a9d38797 JM |
6910 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
6911 | && (type == char_type_node | |
6912 | || ! strcmp (type_name, "signed char") | |
6913 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 6914 | { |
a9d38797 JM |
6915 | if (TREE_UNSIGNED (type)) |
6916 | encoding = DW_ATE_unsigned; | |
6917 | else | |
6918 | encoding = DW_ATE_signed; | |
6919 | break; | |
a3f97cbb | 6920 | } |
556273e0 | 6921 | /* else fall through. */ |
a3f97cbb | 6922 | |
a9d38797 JM |
6923 | case CHAR_TYPE: |
6924 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
6925 | if (TREE_UNSIGNED (type)) | |
6926 | encoding = DW_ATE_unsigned_char; | |
6927 | else | |
6928 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
6929 | break; |
6930 | ||
6931 | case REAL_TYPE: | |
a9d38797 | 6932 | encoding = DW_ATE_float; |
a3f97cbb JW |
6933 | break; |
6934 | ||
405f63da MM |
6935 | /* Dwarf2 doesn't know anything about complex ints, so use |
6936 | a user defined type for it. */ | |
a3f97cbb | 6937 | case COMPLEX_TYPE: |
405f63da MM |
6938 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
6939 | encoding = DW_ATE_complex_float; | |
6940 | else | |
6941 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
6942 | break; |
6943 | ||
6944 | case BOOLEAN_TYPE: | |
a9d38797 JM |
6945 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
6946 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
6947 | break; |
6948 | ||
6949 | default: | |
a9d38797 | 6950 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
6951 | } |
6952 | ||
a9d38797 | 6953 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
6954 | if (demangle_name_func) |
6955 | type_name = (*demangle_name_func) (type_name); | |
6956 | ||
a9d38797 JM |
6957 | add_AT_string (base_type_result, DW_AT_name, type_name); |
6958 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 6959 | int_size_in_bytes (type)); |
a9d38797 | 6960 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
6961 | |
6962 | return base_type_result; | |
6963 | } | |
6964 | ||
6965 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
6966 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
6967 | a given type is generally the same as the given type, except that if the | |
6968 | given type is a pointer or reference type, then the root type of the given | |
6969 | type is the root type of the "basis" type for the pointer or reference | |
6970 | type. (This definition of the "root" type is recursive.) Also, the root | |
6971 | type of a `const' qualified type or a `volatile' qualified type is the | |
6972 | root type of the given type without the qualifiers. */ | |
71dfc51f | 6973 | |
a3f97cbb JW |
6974 | static tree |
6975 | root_type (type) | |
6976 | register tree type; | |
6977 | { | |
6978 | if (TREE_CODE (type) == ERROR_MARK) | |
6979 | return error_mark_node; | |
6980 | ||
6981 | switch (TREE_CODE (type)) | |
6982 | { | |
6983 | case ERROR_MARK: | |
6984 | return error_mark_node; | |
6985 | ||
6986 | case POINTER_TYPE: | |
6987 | case REFERENCE_TYPE: | |
6988 | return type_main_variant (root_type (TREE_TYPE (type))); | |
6989 | ||
6990 | default: | |
6991 | return type_main_variant (type); | |
6992 | } | |
6993 | } | |
6994 | ||
6995 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
6996 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
6997 | |
6998 | static inline int | |
a3f97cbb JW |
6999 | is_base_type (type) |
7000 | register tree type; | |
7001 | { | |
7002 | switch (TREE_CODE (type)) | |
7003 | { | |
7004 | case ERROR_MARK: | |
7005 | case VOID_TYPE: | |
7006 | case INTEGER_TYPE: | |
7007 | case REAL_TYPE: | |
7008 | case COMPLEX_TYPE: | |
7009 | case BOOLEAN_TYPE: | |
7010 | case CHAR_TYPE: | |
7011 | return 1; | |
7012 | ||
7013 | case SET_TYPE: | |
7014 | case ARRAY_TYPE: | |
7015 | case RECORD_TYPE: | |
7016 | case UNION_TYPE: | |
7017 | case QUAL_UNION_TYPE: | |
7018 | case ENUMERAL_TYPE: | |
7019 | case FUNCTION_TYPE: | |
7020 | case METHOD_TYPE: | |
7021 | case POINTER_TYPE: | |
7022 | case REFERENCE_TYPE: | |
7023 | case FILE_TYPE: | |
7024 | case OFFSET_TYPE: | |
7025 | case LANG_TYPE: | |
7026 | return 0; | |
7027 | ||
7028 | default: | |
7029 | abort (); | |
7030 | } | |
71dfc51f | 7031 | |
a3f97cbb JW |
7032 | return 0; |
7033 | } | |
7034 | ||
7035 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7036 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7037 | |
a3f97cbb JW |
7038 | static dw_die_ref |
7039 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
7040 | register tree type; | |
7041 | register int is_const_type; | |
7042 | register int is_volatile_type; | |
7043 | register dw_die_ref context_die; | |
7044 | { | |
7045 | register enum tree_code code = TREE_CODE (type); | |
7046 | register dw_die_ref mod_type_die = NULL; | |
7047 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 7048 | register tree item_type = NULL; |
a3f97cbb JW |
7049 | |
7050 | if (code != ERROR_MARK) | |
7051 | { | |
a94dbf2c | 7052 | type = build_type_variant (type, is_const_type, is_volatile_type); |
bdb669cb JM |
7053 | |
7054 | mod_type_die = lookup_type_die (type); | |
7055 | if (mod_type_die) | |
7056 | return mod_type_die; | |
7057 | ||
556273e0 | 7058 | /* Handle C typedef types. */ |
a94dbf2c JM |
7059 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
7060 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
7061 | { | |
7062 | tree dtype = TREE_TYPE (TYPE_NAME (type)); | |
7063 | if (type == dtype) | |
7064 | { | |
7065 | /* For a named type, use the typedef. */ | |
7066 | gen_type_die (type, context_die); | |
7067 | mod_type_die = lookup_type_die (type); | |
7068 | } | |
71dfc51f | 7069 | |
a94dbf2c JM |
7070 | else if (is_const_type < TYPE_READONLY (dtype) |
7071 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7072 | /* cv-unqualified version of named type. Just use the unnamed | |
7073 | type to which it refers. */ | |
71dfc51f RK |
7074 | mod_type_die |
7075 | = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), | |
7076 | is_const_type, is_volatile_type, | |
7077 | context_die); | |
7078 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
7079 | } |
7080 | ||
7081 | if (mod_type_die) | |
556273e0 KH |
7082 | /* OK. */ |
7083 | ; | |
a94dbf2c | 7084 | else if (is_const_type) |
a3f97cbb | 7085 | { |
ab72d377 | 7086 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 7087 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7088 | } |
7089 | else if (is_volatile_type) | |
7090 | { | |
ab72d377 | 7091 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 7092 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7093 | } |
7094 | else if (code == POINTER_TYPE) | |
7095 | { | |
ab72d377 | 7096 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 7097 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7098 | #if 0 |
a3f97cbb | 7099 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7100 | #endif |
a3f97cbb | 7101 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7102 | } |
7103 | else if (code == REFERENCE_TYPE) | |
7104 | { | |
ab72d377 | 7105 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 7106 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7107 | #if 0 |
a3f97cbb | 7108 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7109 | #endif |
a3f97cbb | 7110 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7111 | } |
7112 | else if (is_base_type (type)) | |
71dfc51f | 7113 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7114 | else |
7115 | { | |
4b674448 JM |
7116 | gen_type_die (type, context_die); |
7117 | ||
a3f97cbb JW |
7118 | /* We have to get the type_main_variant here (and pass that to the |
7119 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7120 | might simply be a *copy* of some original type node (where the | |
7121 | copy was created to help us keep track of typedef names) and | |
7122 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7123 | ..._TYPE node. */ |
a3f97cbb | 7124 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7125 | if (mod_type_die == NULL) |
7126 | abort (); | |
a3f97cbb JW |
7127 | } |
7128 | } | |
71dfc51f | 7129 | |
dfcf9891 JW |
7130 | equate_type_number_to_die (type, mod_type_die); |
7131 | if (item_type) | |
71dfc51f RK |
7132 | /* We must do this after the equate_type_number_to_die call, in case |
7133 | this is a recursive type. This ensures that the modified_type_die | |
7134 | recursion will terminate even if the type is recursive. Recursive | |
7135 | types are possible in Ada. */ | |
7136 | sub_die = modified_type_die (item_type, | |
7137 | TYPE_READONLY (item_type), | |
7138 | TYPE_VOLATILE (item_type), | |
7139 | context_die); | |
7140 | ||
a3f97cbb | 7141 | if (sub_die != NULL) |
71dfc51f RK |
7142 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7143 | ||
a3f97cbb JW |
7144 | return mod_type_die; |
7145 | } | |
7146 | ||
a3f97cbb JW |
7147 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
7148 | an enumerated type. */ | |
71dfc51f RK |
7149 | |
7150 | static inline int | |
a3f97cbb JW |
7151 | type_is_enum (type) |
7152 | register tree type; | |
7153 | { | |
7154 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7155 | } | |
7156 | ||
7d9d8943 AM |
7157 | /* Return the register number described by a given RTL node. */ |
7158 | ||
7159 | static unsigned int | |
7160 | reg_number (rtl) | |
7161 | register rtx rtl; | |
7162 | { | |
7163 | register unsigned regno = REGNO (rtl); | |
7164 | ||
7165 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7166 | { | |
7167 | warning ("internal regno botch: regno = %d\n", regno); | |
7168 | regno = 0; | |
7169 | } | |
7170 | ||
7171 | regno = DBX_REGISTER_NUMBER (regno); | |
7172 | return regno; | |
7173 | } | |
7174 | ||
a3f97cbb | 7175 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 7176 | |
a3f97cbb JW |
7177 | static dw_loc_descr_ref |
7178 | reg_loc_descriptor (rtl) | |
7179 | register rtx rtl; | |
7180 | { | |
7181 | register dw_loc_descr_ref loc_result = NULL; | |
7182 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 7183 | |
85066503 | 7184 | if (reg <= 31) |
71dfc51f | 7185 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7186 | else |
71dfc51f RK |
7187 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7188 | ||
a3f97cbb JW |
7189 | return loc_result; |
7190 | } | |
7191 | ||
d8041cc8 RH |
7192 | /* Return a location descriptor that designates a constant. */ |
7193 | ||
7194 | static dw_loc_descr_ref | |
7195 | int_loc_descriptor (i) | |
7196 | HOST_WIDE_INT i; | |
7197 | { | |
7198 | enum dwarf_location_atom op; | |
7199 | ||
7200 | /* Pick the smallest representation of a constant, rather than just | |
7201 | defaulting to the LEB encoding. */ | |
7202 | if (i >= 0) | |
7203 | { | |
7204 | if (i <= 31) | |
7205 | op = DW_OP_lit0 + i; | |
7206 | else if (i <= 0xff) | |
7207 | op = DW_OP_const1u; | |
7208 | else if (i <= 0xffff) | |
7209 | op = DW_OP_const2u; | |
7210 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7211 | || i <= 0xffffffff) | |
7212 | op = DW_OP_const4u; | |
7213 | else | |
7214 | op = DW_OP_constu; | |
7215 | } | |
7216 | else | |
7217 | { | |
7218 | if (i >= -0x80) | |
7219 | op = DW_OP_const1s; | |
7220 | else if (i >= -0x8000) | |
7221 | op = DW_OP_const2s; | |
7222 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7223 | || i >= -0x80000000) | |
7224 | op = DW_OP_const4s; | |
7225 | else | |
7226 | op = DW_OP_consts; | |
7227 | } | |
7228 | ||
7229 | return new_loc_descr (op, i, 0); | |
7230 | } | |
7231 | ||
a3f97cbb | 7232 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7233 | |
a3f97cbb JW |
7234 | static dw_loc_descr_ref |
7235 | based_loc_descr (reg, offset) | |
7236 | unsigned reg; | |
7237 | long int offset; | |
7238 | { | |
7239 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
7240 | /* For the "frame base", we use the frame pointer or stack pointer |
7241 | registers, since the RTL for local variables is relative to one of | |
7242 | them. */ | |
7243 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 7244 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 7245 | : STACK_POINTER_REGNUM); |
71dfc51f | 7246 | |
a3f97cbb | 7247 | if (reg == fp_reg) |
71dfc51f | 7248 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7249 | else if (reg <= 31) |
71dfc51f | 7250 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7251 | else |
71dfc51f RK |
7252 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7253 | ||
a3f97cbb JW |
7254 | return loc_result; |
7255 | } | |
7256 | ||
7257 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7258 | |
7259 | static inline int | |
a3f97cbb JW |
7260 | is_based_loc (rtl) |
7261 | register rtx rtl; | |
7262 | { | |
71dfc51f RK |
7263 | return (GET_CODE (rtl) == PLUS |
7264 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7265 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7266 | } |
7267 | ||
7268 | /* The following routine converts the RTL for a variable or parameter | |
7269 | (resident in memory) into an equivalent Dwarf representation of a | |
7270 | mechanism for getting the address of that same variable onto the top of a | |
7271 | hypothetical "address evaluation" stack. | |
71dfc51f | 7272 | |
a3f97cbb JW |
7273 | When creating memory location descriptors, we are effectively transforming |
7274 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7275 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7276 | it into Dwarf postfix code as it goes. |
7277 | ||
7278 | MODE is the mode of the memory reference, needed to handle some | |
7279 | autoincrement addressing modes. */ | |
71dfc51f | 7280 | |
a3f97cbb | 7281 | static dw_loc_descr_ref |
e60d4d7b | 7282 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 7283 | register rtx rtl; |
e60d4d7b | 7284 | enum machine_mode mode; |
a3f97cbb JW |
7285 | { |
7286 | dw_loc_descr_ref mem_loc_result = NULL; | |
556273e0 | 7287 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7288 | description of here will be the lowest numbered location which is |
7289 | actually within the array. That's *not* necessarily the same as the | |
7290 | zeroth element of the array. */ | |
71dfc51f | 7291 | |
1865dbb5 JM |
7292 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7293 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7294 | #endif | |
7295 | ||
a3f97cbb JW |
7296 | switch (GET_CODE (rtl)) |
7297 | { | |
e60d4d7b JL |
7298 | case POST_INC: |
7299 | case POST_DEC: | |
7300 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we | |
7301 | just fall into the SUBREG code. */ | |
7302 | ||
556273e0 | 7303 | /* Fall through. */ |
e60d4d7b | 7304 | |
a3f97cbb JW |
7305 | case SUBREG: |
7306 | /* The case of a subreg may arise when we have a local (register) | |
7307 | variable or a formal (register) parameter which doesn't quite fill | |
7308 | up an entire register. For now, just assume that it is | |
7309 | legitimate to make the Dwarf info refer to the whole register which | |
7310 | contains the given subreg. */ | |
7311 | rtl = XEXP (rtl, 0); | |
71dfc51f | 7312 | |
556273e0 | 7313 | /* Fall through. */ |
a3f97cbb JW |
7314 | |
7315 | case REG: | |
7316 | /* Whenever a register number forms a part of the description of the | |
7317 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7318 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7319 | a "base register". This distinction is not based in any way upon |
7320 | what category of register the hardware believes the given register | |
7321 | belongs to. This is strictly DWARF terminology we're dealing with | |
7322 | here. Note that in cases where the location of a memory-resident | |
7323 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7324 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7325 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7326 | the object in question was allocated to a register (rather than in | |
7327 | memory) so DWARF consumers need to be aware of the subtle | |
7328 | distinction between OP_REG and OP_BASEREG. */ | |
7329 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
7330 | break; | |
7331 | ||
7332 | case MEM: | |
d8041cc8 RH |
7333 | { |
7334 | dw_loc_descr_ref deref; | |
7335 | ||
7336 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); | |
7337 | ||
7338 | if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE) | |
7339 | deref = new_loc_descr (DW_OP_deref, 0, 0); | |
7340 | else | |
7341 | deref = new_loc_descr (DW_OP_deref_size, GET_MODE_SIZE (mode), 0); | |
7342 | ||
7343 | add_loc_descr (&mem_loc_result, deref); | |
7344 | } | |
a3f97cbb JW |
7345 | break; |
7346 | ||
d8041cc8 RH |
7347 | case LABEL_REF: |
7348 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7349 | the symbol ref is too far away and has to be dumped into a constant |
7350 | pool. */ | |
a3f97cbb JW |
7351 | case CONST: |
7352 | case SYMBOL_REF: | |
7353 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
7354 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 7355 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
7356 | break; |
7357 | ||
e60d4d7b JL |
7358 | case PRE_INC: |
7359 | case PRE_DEC: | |
7360 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7361 | below. */ | |
7362 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7363 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7364 | ? GET_MODE_UNIT_SIZE (mode) |
7365 | : -GET_MODE_UNIT_SIZE (mode))); | |
7366 | ||
7367 | /* Fall through. */ | |
e60d4d7b | 7368 | |
a3f97cbb JW |
7369 | case PLUS: |
7370 | if (is_based_loc (rtl)) | |
71dfc51f RK |
7371 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7372 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7373 | else |
7374 | { | |
d8041cc8 RH |
7375 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
7376 | ||
7377 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7378 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
7379 | { | |
7380 | add_loc_descr (&mem_loc_result, | |
7381 | new_loc_descr (DW_OP_plus_uconst, | |
7382 | INTVAL (XEXP (rtl, 1)), 0)); | |
7383 | } | |
7384 | else | |
7385 | { | |
7386 | add_loc_descr (&mem_loc_result, | |
7387 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7388 | add_loc_descr (&mem_loc_result, | |
7389 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7390 | } | |
a3f97cbb JW |
7391 | } |
7392 | break; | |
7393 | ||
dd2478ae JW |
7394 | case MULT: |
7395 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7396 | be replaced with a MEM containing a multiply. */ | |
d8041cc8 RH |
7397 | add_loc_descr (&mem_loc_result, |
7398 | mem_loc_descriptor (XEXP (rtl, 0), mode)); | |
7399 | add_loc_descr (&mem_loc_result, | |
7400 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
7401 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
7402 | break; | |
7403 | ||
a3f97cbb | 7404 | case CONST_INT: |
d8041cc8 | 7405 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7406 | break; |
7407 | ||
7408 | default: | |
7409 | abort (); | |
7410 | } | |
71dfc51f | 7411 | |
a3f97cbb JW |
7412 | return mem_loc_result; |
7413 | } | |
7414 | ||
956d6950 | 7415 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7416 | This is typically a complex variable. */ |
7417 | ||
7418 | static dw_loc_descr_ref | |
7419 | concat_loc_descriptor (x0, x1) | |
7420 | register rtx x0, x1; | |
7421 | { | |
7422 | dw_loc_descr_ref cc_loc_result = NULL; | |
7423 | ||
7424 | if (!is_pseudo_reg (x0) | |
7425 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
7426 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
7427 | add_loc_descr (&cc_loc_result, | |
7428 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
7429 | ||
7430 | if (!is_pseudo_reg (x1) | |
7431 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
7432 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
7433 | add_loc_descr (&cc_loc_result, | |
7434 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
7435 | ||
7436 | return cc_loc_result; | |
7437 | } | |
7438 | ||
a3f97cbb JW |
7439 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7440 | which is either allocated in a register or in a memory location. For a | |
7441 | register, we just generate an OP_REG and the register number. For a | |
7442 | memory location we provide a Dwarf postfix expression describing how to | |
7443 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 7444 | |
a3f97cbb JW |
7445 | static dw_loc_descr_ref |
7446 | loc_descriptor (rtl) | |
7447 | register rtx rtl; | |
7448 | { | |
7449 | dw_loc_descr_ref loc_result = NULL; | |
7450 | switch (GET_CODE (rtl)) | |
7451 | { | |
7452 | case SUBREG: | |
a3f97cbb JW |
7453 | /* The case of a subreg may arise when we have a local (register) |
7454 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7455 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7456 | legitimate to make the Dwarf info refer to the whole register which |
7457 | contains the given subreg. */ | |
a3f97cbb | 7458 | rtl = XEXP (rtl, 0); |
71dfc51f | 7459 | |
556273e0 | 7460 | /* Fall through. */ |
a3f97cbb JW |
7461 | |
7462 | case REG: | |
5c90448c | 7463 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7464 | break; |
7465 | ||
7466 | case MEM: | |
e60d4d7b | 7467 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7468 | break; |
7469 | ||
4401bf24 JL |
7470 | case CONCAT: |
7471 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7472 | break; | |
7473 | ||
a3f97cbb | 7474 | default: |
71dfc51f | 7475 | abort (); |
a3f97cbb | 7476 | } |
71dfc51f | 7477 | |
a3f97cbb JW |
7478 | return loc_result; |
7479 | } | |
7480 | ||
d8041cc8 RH |
7481 | /* Similar, but generate the descriptor from trees instead of rtl. |
7482 | This comes up particularly with variable length arrays. */ | |
7483 | ||
7484 | static dw_loc_descr_ref | |
7485 | loc_descriptor_from_tree (loc, addressp) | |
7486 | tree loc; | |
7487 | int addressp; | |
7488 | { | |
7489 | dw_loc_descr_ref ret = NULL; | |
7490 | int indirect_size = 0; | |
7491 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); | |
7492 | enum dwarf_location_atom op; | |
7493 | ||
7494 | /* ??? Most of the time we do not take proper care for sign/zero | |
7495 | extending the values properly. Hopefully this won't be a real | |
7496 | problem... */ | |
7497 | ||
7498 | switch (TREE_CODE (loc)) | |
7499 | { | |
7500 | case ERROR_MARK: | |
7501 | break; | |
7502 | ||
7503 | case VAR_DECL: | |
7504 | case PARM_DECL: | |
7505 | { | |
7506 | rtx rtl = rtl_for_decl_location (loc); | |
7507 | enum machine_mode mode = DECL_MODE (loc); | |
7508 | ||
a97c9600 RH |
7509 | if (rtl == NULL_RTX) |
7510 | break; | |
7511 | else if (CONSTANT_P (rtl)) | |
d8041cc8 RH |
7512 | { |
7513 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
7514 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
7515 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
7516 | indirect_size = GET_MODE_SIZE (mode); | |
7517 | } | |
7518 | else | |
7519 | { | |
7520 | if (GET_CODE (rtl) == MEM) | |
7521 | { | |
7522 | indirect_size = GET_MODE_SIZE (mode); | |
7523 | rtl = XEXP (rtl, 0); | |
7524 | } | |
7525 | ret = mem_loc_descriptor (rtl, mode); | |
7526 | } | |
7527 | } | |
7528 | break; | |
7529 | ||
7530 | case INDIRECT_REF: | |
7531 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7532 | indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc))); | |
7533 | break; | |
7534 | ||
7535 | case COMPONENT_REF: | |
7536 | case BIT_FIELD_REF: | |
7537 | case ARRAY_REF: | |
7538 | { | |
7539 | tree obj, offset; | |
7540 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
7541 | enum machine_mode mode; | |
7542 | int volatilep; | |
7543 | unsigned int alignment; | |
7544 | ||
7545 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
7546 | &unsignedp, &volatilep, &alignment); | |
7547 | ret = loc_descriptor_from_tree (obj, 1); | |
7548 | ||
7549 | if (offset != NULL_TREE) | |
7550 | { | |
7551 | /* Variable offset. */ | |
7552 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
7553 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7554 | } | |
7555 | ||
7556 | if (addressp) | |
7557 | { | |
7558 | /* We cannot address anything not on a unit boundary. */ | |
7559 | if (bitpos % BITS_PER_UNIT != 0) | |
7560 | abort (); | |
7561 | } | |
7562 | else | |
7563 | { | |
7564 | if (bitpos % BITS_PER_UNIT != 0 | |
7565 | || bitsize % BITS_PER_UNIT != 0) | |
7566 | { | |
7567 | /* ??? We could handle this by loading and shifting etc. | |
7568 | Wait until someone needs it before expending the effort. */ | |
7569 | abort (); | |
7570 | } | |
7571 | ||
7572 | indirect_size = bitsize / BITS_PER_UNIT; | |
7573 | } | |
7574 | ||
7575 | bytepos = bitpos / BITS_PER_UNIT; | |
7576 | if (bytepos > 0) | |
7577 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
7578 | else if (bytepos < 0) | |
7579 | { | |
7580 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
7581 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7582 | } | |
7583 | break; | |
7584 | } | |
7585 | ||
7586 | case INTEGER_CST: | |
7587 | if (host_integerp (loc, 0)) | |
7588 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
7589 | break; | |
7590 | break; | |
7591 | ||
7592 | case BIT_AND_EXPR: | |
7593 | op = DW_OP_and; | |
7594 | goto do_binop; | |
7595 | case BIT_XOR_EXPR: | |
7596 | op = DW_OP_xor; | |
7597 | goto do_binop; | |
7598 | case BIT_IOR_EXPR: | |
7599 | op = DW_OP_or; | |
7600 | goto do_binop; | |
7601 | case TRUNC_DIV_EXPR: | |
7602 | op = DW_OP_div; | |
7603 | goto do_binop; | |
7604 | case MINUS_EXPR: | |
7605 | op = DW_OP_minus; | |
7606 | goto do_binop; | |
7607 | case TRUNC_MOD_EXPR: | |
7608 | op = DW_OP_mod; | |
7609 | goto do_binop; | |
7610 | case MULT_EXPR: | |
7611 | op = DW_OP_mul; | |
7612 | goto do_binop; | |
7613 | case LSHIFT_EXPR: | |
7614 | op = DW_OP_shl; | |
7615 | goto do_binop; | |
7616 | case RSHIFT_EXPR: | |
7617 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
7618 | goto do_binop; | |
7619 | case PLUS_EXPR: | |
7620 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
7621 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
7622 | { | |
7623 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7624 | add_loc_descr (&ret, | |
7625 | new_loc_descr (DW_OP_plus_uconst, | |
7626 | tree_low_cst (TREE_OPERAND (loc, 1), | |
7627 | 0), | |
7628 | 0)); | |
7629 | break; | |
7630 | } | |
7631 | op = DW_OP_plus; | |
7632 | goto do_binop; | |
7633 | case LE_EXPR: | |
7634 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7635 | break; | |
7636 | op = DW_OP_le; | |
7637 | goto do_binop; | |
7638 | case GE_EXPR: | |
7639 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7640 | break; | |
7641 | op = DW_OP_ge; | |
7642 | goto do_binop; | |
7643 | case LT_EXPR: | |
7644 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7645 | break; | |
7646 | op = DW_OP_lt; | |
7647 | goto do_binop; | |
7648 | case GT_EXPR: | |
7649 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7650 | break; | |
7651 | op = DW_OP_gt; | |
7652 | goto do_binop; | |
7653 | case EQ_EXPR: | |
7654 | op = DW_OP_eq; | |
7655 | goto do_binop; | |
7656 | case NE_EXPR: | |
7657 | op = DW_OP_ne; | |
7658 | goto do_binop; | |
7659 | ||
7660 | do_binop: | |
7661 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7662 | add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0)); | |
7663 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7664 | break; | |
7665 | ||
7666 | case BIT_NOT_EXPR: | |
7667 | op = DW_OP_not; | |
7668 | goto do_unop; | |
7669 | case ABS_EXPR: | |
7670 | op = DW_OP_abs; | |
7671 | goto do_unop; | |
7672 | case NEGATE_EXPR: | |
7673 | op = DW_OP_neg; | |
7674 | goto do_unop; | |
7675 | ||
7676 | do_unop: | |
7677 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7678 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7679 | break; | |
7680 | ||
7681 | case MAX_EXPR: | |
7682 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
7683 | build (LT_EXPR, integer_type_node, | |
7684 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
7685 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
7686 | /* FALLTHRU */ | |
7687 | ||
7688 | case COND_EXPR: | |
7689 | { | |
7690 | dw_loc_descr_ref bra_node, jump_node, tmp; | |
7691 | ||
7692 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7693 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); | |
7694 | add_loc_descr (&ret, bra_node); | |
7695 | ||
7696 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
7697 | add_loc_descr (&ret, tmp); | |
7698 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); | |
7699 | add_loc_descr (&ret, jump_node); | |
7700 | ||
7701 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
7702 | add_loc_descr (&ret, tmp); | |
7703 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7704 | bra_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7705 | ||
7706 | /* ??? Need a node to point the skip at. Use a nop. */ | |
7707 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
7708 | add_loc_descr (&ret, tmp); | |
7709 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7710 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7711 | } | |
7712 | break; | |
7713 | ||
7714 | default: | |
7715 | abort (); | |
7716 | } | |
7717 | ||
7718 | /* If we can't fill the request for an address, die. */ | |
7719 | if (addressp && indirect_size == 0) | |
7720 | abort (); | |
7721 | ||
7722 | /* If we've got an address and don't want one, dereference. */ | |
7723 | if (!addressp && indirect_size > 0) | |
7724 | { | |
7725 | if (indirect_size > DWARF2_ADDR_SIZE) | |
7726 | abort (); | |
7727 | if (indirect_size == DWARF2_ADDR_SIZE) | |
7728 | op = DW_OP_deref; | |
7729 | else | |
7730 | op = DW_OP_deref_size; | |
7731 | add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0)); | |
7732 | } | |
7733 | ||
7734 | return ret; | |
7735 | } | |
7736 | ||
665f2503 | 7737 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 7738 | which is not less than the value itself. */ |
71dfc51f | 7739 | |
665f2503 | 7740 | static inline HOST_WIDE_INT |
a3f97cbb | 7741 | ceiling (value, boundary) |
665f2503 RK |
7742 | HOST_WIDE_INT value; |
7743 | unsigned int boundary; | |
a3f97cbb JW |
7744 | { |
7745 | return (((value + boundary - 1) / boundary) * boundary); | |
7746 | } | |
7747 | ||
7748 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
7749 | pointer to the declared type for the relevant field variable, or return | |
7750 | `integer_type_node' if the given node turns out to be an | |
7751 | ERROR_MARK node. */ | |
71dfc51f RK |
7752 | |
7753 | static inline tree | |
a3f97cbb JW |
7754 | field_type (decl) |
7755 | register tree decl; | |
7756 | { | |
7757 | register tree type; | |
7758 | ||
7759 | if (TREE_CODE (decl) == ERROR_MARK) | |
7760 | return integer_type_node; | |
7761 | ||
7762 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 7763 | if (type == NULL_TREE) |
a3f97cbb JW |
7764 | type = TREE_TYPE (decl); |
7765 | ||
7766 | return type; | |
7767 | } | |
7768 | ||
7769 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
7770 | node, return the alignment in bits for the type, or else return | |
7771 | BITS_PER_WORD if the node actually turns out to be an | |
7772 | ERROR_MARK node. */ | |
71dfc51f RK |
7773 | |
7774 | static inline unsigned | |
a3f97cbb JW |
7775 | simple_type_align_in_bits (type) |
7776 | register tree type; | |
7777 | { | |
7778 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
7779 | } | |
7780 | ||
7781 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
7782 | node, return the size in bits for the type if it is a constant, or else | |
7783 | return the alignment for the type if the type's size is not constant, or | |
7784 | else return BITS_PER_WORD if the type actually turns out to be an | |
7785 | ERROR_MARK node. */ | |
71dfc51f | 7786 | |
665f2503 | 7787 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
7788 | simple_type_size_in_bits (type) |
7789 | register tree type; | |
7790 | { | |
7791 | if (TREE_CODE (type) == ERROR_MARK) | |
7792 | return BITS_PER_WORD; | |
7793 | else | |
7794 | { | |
7795 | register tree type_size_tree = TYPE_SIZE (type); | |
7796 | ||
665f2503 | 7797 | if (! host_integerp (type_size_tree, 1)) |
a3f97cbb JW |
7798 | return TYPE_ALIGN (type); |
7799 | ||
665f2503 | 7800 | return tree_low_cst (type_size_tree, 1); |
a3f97cbb JW |
7801 | } |
7802 | } | |
7803 | ||
7804 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
7805 | return the byte offset of the lowest addressed byte of the "containing | |
7806 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
7807 | determine what that offset is, either because the argument turns out to | |
7808 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
7809 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 7810 | |
665f2503 | 7811 | static HOST_WIDE_INT |
a3f97cbb JW |
7812 | field_byte_offset (decl) |
7813 | register tree decl; | |
7814 | { | |
665f2503 RK |
7815 | unsigned int type_align_in_bytes; |
7816 | unsigned int type_align_in_bits; | |
7817 | unsigned HOST_WIDE_INT type_size_in_bits; | |
7818 | HOST_WIDE_INT object_offset_in_align_units; | |
7819 | HOST_WIDE_INT object_offset_in_bits; | |
7820 | HOST_WIDE_INT object_offset_in_bytes; | |
7821 | tree type; | |
7822 | tree field_size_tree; | |
7823 | HOST_WIDE_INT bitpos_int; | |
7824 | HOST_WIDE_INT deepest_bitpos; | |
7825 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
7826 | |
7827 | if (TREE_CODE (decl) == ERROR_MARK) | |
7828 | return 0; | |
7829 | ||
7830 | if (TREE_CODE (decl) != FIELD_DECL) | |
7831 | abort (); | |
7832 | ||
7833 | type = field_type (decl); | |
a3f97cbb JW |
7834 | field_size_tree = DECL_SIZE (decl); |
7835 | ||
50352c9c BK |
7836 | /* If there was an error, the size could be zero. */ |
7837 | if (! field_size_tree) | |
7838 | { | |
7839 | if (errorcount) | |
7840 | return 0; | |
665f2503 | 7841 | |
50352c9c BK |
7842 | abort (); |
7843 | } | |
7844 | ||
556273e0 | 7845 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
7846 | for now, when we see such things, we simply return 0. Someday, we may |
7847 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 7848 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 7849 | return 0; |
14a774a9 | 7850 | |
665f2503 | 7851 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 7852 | |
14a774a9 | 7853 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
7854 | if (host_integerp (field_size_tree, 1)) |
7855 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
7856 | else |
7857 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
7858 | |
7859 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb JW |
7860 | type_align_in_bits = simple_type_align_in_bits (type); |
7861 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
7862 | ||
7863 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
7864 | the starting bit offset (relative to the start of the containing | |
7865 | structure type) of the hypothetical "containing object" for a bit- | |
7866 | field. Thus, when computing the byte offset value for the start of the | |
556273e0 | 7867 | "containing object" of a bit-field, we must deduce this information on |
a3f97cbb JW |
7868 | our own. This can be rather tricky to do in some cases. For example, |
7869 | handling the following structure type definition when compiling for an | |
7870 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
7871 | can be very tricky: | |
7872 | ||
7873 | struct S { int field1; long long field2:31; }; | |
7874 | ||
7875 | Fortunately, there is a simple rule-of-thumb which can be | |
7876 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
556273e0 | 7877 | 8 bytes for the structure shown above. It decides to do this based upon |
a3f97cbb JW |
7878 | one simple rule for bit-field allocation. Quite simply, GCC allocates |
7879 | each "containing object" for each bit-field at the first (i.e. lowest | |
7880 | addressed) legitimate alignment boundary (based upon the required | |
7881 | minimum alignment for the declared type of the field) which it can | |
7882 | possibly use, subject to the condition that there is still enough | |
7883 | available space remaining in the containing object (when allocated at | |
7884 | the selected point) to fully accommodate all of the bits of the | |
7885 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
7886 | 8 bytes for each object of the structure type shown above. When looking | |
7887 | for a place to allocate the "containing object" for `field2', the | |
7888 | compiler simply tries to allocate a 64-bit "containing object" at each | |
7889 | successive 32-bit boundary (starting at zero) until it finds a place to | |
7890 | allocate that 64- bit field such that at least 31 contiguous (and | |
7891 | previously unallocated) bits remain within that selected 64 bit field. | |
7892 | (As it turns out, for the example above, the compiler finds that it is | |
7893 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
7894 | within the structure type.) Here we attempt to work backwards from the | |
556273e0 | 7895 | limited set of facts we're given, and we try to deduce from those facts, |
a3f97cbb | 7896 | where GCC must have believed that the containing object started (within |
556273e0 KH |
7897 | the structure type). The value we deduce is then used (by the callers of |
7898 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
a3f97cbb JW |
7899 | for fields (both bit-fields and, in the case of DW_AT_location, regular |
7900 | fields as well). */ | |
7901 | ||
7902 | /* Figure out the bit-distance from the start of the structure to the | |
7903 | "deepest" bit of the bit-field. */ | |
7904 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
7905 | ||
7906 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
7907 | lowest addressed bit of the containing object must be. */ | |
7908 | object_offset_in_bits | |
7909 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
7910 | ||
7911 | /* Compute the offset of the containing object in "alignment units". */ | |
7912 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
7913 | ||
7914 | /* Compute the offset of the containing object in bytes. */ | |
7915 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
7916 | ||
7917 | return object_offset_in_bytes; | |
7918 | } | |
a3f97cbb | 7919 | \f |
71dfc51f RK |
7920 | /* The following routines define various Dwarf attributes and any data |
7921 | associated with them. */ | |
a3f97cbb | 7922 | |
ef76d03b | 7923 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 7924 | |
ef76d03b | 7925 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
7926 | whole parameters. Note that the location attributes for struct fields are |
7927 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 7928 | |
a3f97cbb | 7929 | static void |
ef76d03b | 7930 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 7931 | dw_die_ref die; |
ef76d03b | 7932 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
7933 | register rtx rtl; |
7934 | { | |
a3f97cbb JW |
7935 | /* Handle a special case. If we are about to output a location descriptor |
7936 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 7937 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
7938 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
7939 | Currently, in some rare cases, variables can have DECL_RTL values which | |
7940 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
556273e0 | 7941 | elsewhere in the compiler. We treat such cases as if the variable(s) in |
6a7a9f01 | 7942 | question had been optimized out of existence. */ |
a3f97cbb | 7943 | |
6a7a9f01 JM |
7944 | if (is_pseudo_reg (rtl) |
7945 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 7946 | && is_pseudo_reg (XEXP (rtl, 0))) |
556273e0 | 7947 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
bce8fed7 JL |
7948 | references the internal argument pointer (a pseudo) in a function |
7949 | where all references to the internal argument pointer were | |
7950 | eliminated via the optimizers. */ | |
7951 | || (GET_CODE (rtl) == MEM | |
7952 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
7953 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
7954 | || (GET_CODE (rtl) == CONCAT |
7955 | && is_pseudo_reg (XEXP (rtl, 0)) | |
7956 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 7957 | return; |
a3f97cbb | 7958 | |
6a7a9f01 | 7959 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
7960 | } |
7961 | ||
7962 | /* Attach the specialized form of location attribute used for data | |
7963 | members of struct and union types. In the special case of a | |
7964 | FIELD_DECL node which represents a bit-field, the "offset" part | |
7965 | of this special location descriptor must indicate the distance | |
7966 | in bytes from the lowest-addressed byte of the containing struct | |
7967 | or union type to the lowest-addressed byte of the "containing | |
7968 | object" for the bit-field. (See the `field_byte_offset' function | |
7969 | above).. For any given bit-field, the "containing object" is a | |
7970 | hypothetical object (of some integral or enum type) within which | |
7971 | the given bit-field lives. The type of this hypothetical | |
7972 | "containing object" is always the same as the declared type of | |
7973 | the individual bit-field itself (for GCC anyway... the DWARF | |
7974 | spec doesn't actually mandate this). Note that it is the size | |
7975 | (in bytes) of the hypothetical "containing object" which will | |
7976 | be given in the DW_AT_byte_size attribute for this bit-field. | |
7977 | (See the `byte_size_attribute' function below.) It is also used | |
7978 | when calculating the value of the DW_AT_bit_offset attribute. | |
7979 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 7980 | |
a3f97cbb JW |
7981 | static void |
7982 | add_data_member_location_attribute (die, decl) | |
7983 | register dw_die_ref die; | |
7984 | register tree decl; | |
7985 | { | |
61b32c02 | 7986 | register unsigned long offset; |
a3f97cbb JW |
7987 | register dw_loc_descr_ref loc_descr; |
7988 | register enum dwarf_location_atom op; | |
7989 | ||
61b32c02 | 7990 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 7991 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
7992 | else |
7993 | offset = field_byte_offset (decl); | |
7994 | ||
a3f97cbb JW |
7995 | /* The DWARF2 standard says that we should assume that the structure address |
7996 | is already on the stack, so we can specify a structure field address | |
7997 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 7998 | |
a3f97cbb JW |
7999 | #ifdef MIPS_DEBUGGING_INFO |
8000 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
8001 | correctly. It works only if we leave the offset on the stack. */ | |
8002 | op = DW_OP_constu; | |
8003 | #else | |
8004 | op = DW_OP_plus_uconst; | |
8005 | #endif | |
71dfc51f | 8006 | |
a3f97cbb JW |
8007 | loc_descr = new_loc_descr (op, offset, 0); |
8008 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
8009 | } | |
8010 | ||
8011 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8012 | does not have a "location" either in memory or in a register. These | |
8013 | things can arise in GNU C when a constant is passed as an actual parameter | |
8014 | to an inlined function. They can also arise in C++ where declared | |
8015 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8016 | |
a3f97cbb JW |
8017 | static void |
8018 | add_const_value_attribute (die, rtl) | |
8019 | register dw_die_ref die; | |
8020 | register rtx rtl; | |
8021 | { | |
8022 | switch (GET_CODE (rtl)) | |
8023 | { | |
8024 | case CONST_INT: | |
8025 | /* Note that a CONST_INT rtx could represent either an integer or a | |
8026 | floating-point constant. A CONST_INT is used whenever the constant | |
8027 | will fit into a single word. In all such cases, the original mode | |
8028 | of the constant value is wiped out, and the CONST_INT rtx is | |
8029 | assigned VOIDmode. */ | |
8030 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
8031 | break; | |
8032 | ||
8033 | case CONST_DOUBLE: | |
8034 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8035 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8036 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8037 | represented. We output CONST_DOUBLEs as blocks. */ |
8038 | { | |
8039 | register enum machine_mode mode = GET_MODE (rtl); | |
8040 | ||
8041 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8042 | { | |
e389897b | 8043 | register unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8044 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8045 | REAL_VALUE_TYPE rv; |
469ac993 | 8046 | |
71dfc51f | 8047 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8048 | switch (mode) |
8049 | { | |
8050 | case SFmode: | |
71dfc51f | 8051 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8052 | break; |
8053 | ||
8054 | case DFmode: | |
71dfc51f | 8055 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8056 | break; |
8057 | ||
8058 | case XFmode: | |
8059 | case TFmode: | |
71dfc51f | 8060 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8061 | break; |
8062 | ||
8063 | default: | |
8064 | abort (); | |
8065 | } | |
8066 | ||
469ac993 JM |
8067 | add_AT_float (die, DW_AT_const_value, length, array); |
8068 | } | |
8069 | else | |
8070 | add_AT_long_long (die, DW_AT_const_value, | |
8071 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8072 | } | |
a3f97cbb JW |
8073 | break; |
8074 | ||
8075 | case CONST_STRING: | |
8076 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8077 | break; | |
8078 | ||
8079 | case SYMBOL_REF: | |
8080 | case LABEL_REF: | |
8081 | case CONST: | |
1865dbb5 | 8082 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
8083 | break; |
8084 | ||
8085 | case PLUS: | |
8086 | /* In cases where an inlined instance of an inline function is passed | |
8087 | the address of an `auto' variable (which is local to the caller) we | |
8088 | can get a situation where the DECL_RTL of the artificial local | |
8089 | variable (for the inlining) which acts as a stand-in for the | |
8090 | corresponding formal parameter (of the inline function) will look | |
8091 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8092 | exactly a compile-time constant expression, but it isn't the address |
8093 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8094 | *value* which the artificial local variable always has during its |
556273e0 | 8095 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8096 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8097 | break; |
8098 | ||
8099 | default: | |
8100 | /* No other kinds of rtx should be possible here. */ | |
8101 | abort (); | |
8102 | } | |
8103 | ||
8104 | } | |
8105 | ||
d8041cc8 RH |
8106 | static rtx |
8107 | rtl_for_decl_location (decl) | |
8108 | tree decl; | |
a3f97cbb JW |
8109 | { |
8110 | register rtx rtl; | |
71dfc51f | 8111 | |
a3f97cbb JW |
8112 | /* Here we have to decide where we are going to say the parameter "lives" |
8113 | (as far as the debugger is concerned). We only have a couple of | |
8114 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8115 | |
556273e0 | 8116 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8117 | activation of the function. If optimization is enabled however, this |
556273e0 | 8118 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8119 | that the parameter doesn't really live anywhere (as far as the code |
8120 | generation parts of GCC are concerned) during most of the function's | |
8121 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8122 | referenced within the function. |
8123 | ||
8124 | We could just generate a location descriptor here for all non-NULL | |
8125 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8126 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8127 | where DECL_RTL is NULL or is a pseudo-reg. | |
8128 | ||
8129 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8130 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8131 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8132 | we can be sure that the parameter was passed using the same type as it is | |
8133 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8134 | points us to a place where a value of that type is passed. | |
8135 | ||
8136 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8137 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8138 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8139 | type which is *different* from the type of the parameter itself. Thus, | |
8140 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8141 | such cases, the debugger would end up (for example) trying to fetch a | |
8142 | `float' from a place which actually contains the first part of a | |
8143 | `double'. That would lead to really incorrect and confusing | |
8144 | output at debug-time. | |
8145 | ||
8146 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8147 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8148 | are a couple of exceptions however. On little-endian machines we can | |
8149 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8150 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8151 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8152 | when (on a little-endian machine) a non-prototyped function has a | |
8153 | parameter declared to be of type `short' or `char'. In such cases, | |
8154 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8155 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8156 | passed `int' value. If the debugger then uses that address to fetch | |
8157 | a `short' or a `char' (on a little-endian machine) the result will be | |
8158 | the correct data, so we allow for such exceptional cases below. | |
8159 | ||
8160 | Note that our goal here is to describe the place where the given formal | |
8161 | parameter lives during most of the function's activation (i.e. between | |
8162 | the end of the prologue and the start of the epilogue). We'll do that | |
8163 | as best as we can. Note however that if the given formal parameter is | |
8164 | modified sometime during the execution of the function, then a stack | |
8165 | backtrace (at debug-time) will show the function as having been | |
8166 | called with the *new* value rather than the value which was | |
8167 | originally passed in. This happens rarely enough that it is not | |
8168 | a major problem, but it *is* a problem, and I'd like to fix it. | |
8169 | ||
8170 | A future version of dwarf2out.c may generate two additional | |
8171 | attributes for any given DW_TAG_formal_parameter DIE which will | |
8172 | describe the "passed type" and the "passed location" for the | |
8173 | given formal parameter in addition to the attributes we now | |
8174 | generate to indicate the "declared type" and the "active | |
8175 | location" for each parameter. This additional set of attributes | |
8176 | could be used by debuggers for stack backtraces. Separately, note | |
8177 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
8178 | NULL also. This happens (for example) for inlined-instances of | |
8179 | inline function formal parameters which are never referenced. | |
8180 | This really shouldn't be happening. All PARM_DECL nodes should | |
8181 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
8182 | doesn't currently generate these values for inlined instances of | |
8183 | inline function parameters, so when we see such cases, we are | |
956d6950 | 8184 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
8185 | gets fixed). */ |
8186 | ||
8187 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
8188 | rtl = DECL_RTL (decl); | |
8189 | ||
8190 | if (TREE_CODE (decl) == PARM_DECL) | |
8191 | { | |
8192 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8193 | { | |
d8041cc8 RH |
8194 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8195 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8196 | |
71dfc51f | 8197 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
8198 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
8199 | all* cases where (rtl == NULL_RTX) just below. */ | |
8200 | if (declared_type == passed_type) | |
71dfc51f RK |
8201 | rtl = DECL_INCOMING_RTL (decl); |
8202 | else if (! BYTES_BIG_ENDIAN | |
8203 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8204 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8205 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8206 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8207 | } |
5a904a61 JW |
8208 | |
8209 | /* If the parm was passed in registers, but lives on the stack, then | |
8210 | make a big endian correction if the mode of the type of the | |
8211 | parameter is not the same as the mode of the rtl. */ | |
8212 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8213 | we reach the big endian correction code there. It isn't clear if all | |
8214 | of these checks are necessary here, but keeping them all is the safe | |
8215 | thing to do. */ | |
8216 | else if (GET_CODE (rtl) == MEM | |
8217 | && XEXP (rtl, 0) != const0_rtx | |
8218 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8219 | /* Not passed in memory. */ | |
8220 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8221 | /* Not passed by invisible reference. */ | |
8222 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8223 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8224 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8225 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8226 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8227 | #endif | |
8228 | ) | |
8229 | /* Big endian correction check. */ | |
8230 | && BYTES_BIG_ENDIAN | |
8231 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8232 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8233 | < UNITS_PER_WORD)) | |
8234 | { | |
8235 | int offset = (UNITS_PER_WORD | |
8236 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
8237 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
8238 | plus_constant (XEXP (rtl, 0), offset)); | |
8239 | } | |
a3f97cbb | 8240 | } |
71dfc51f | 8241 | |
d8041cc8 RH |
8242 | if (rtl != NULL_RTX) |
8243 | { | |
8244 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8245 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8246 | if (current_function_uses_only_leaf_regs) |
8247 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8248 | #endif |
d8041cc8 RH |
8249 | } |
8250 | ||
8251 | return rtl; | |
8252 | } | |
8253 | ||
8254 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8255 | data attribute for a variable or a parameter. We generate the | |
8256 | DW_AT_const_value attribute only in those cases where the given variable | |
8257 | or parameter does not have a true "location" either in memory or in a | |
8258 | register. This can happen (for example) when a constant is passed as an | |
8259 | actual argument in a call to an inline function. (It's possible that | |
8260 | these things can crop up in other ways also.) Note that one type of | |
8261 | constant value which can be passed into an inlined function is a constant | |
8262 | pointer. This can happen for example if an actual argument in an inlined | |
8263 | function call evaluates to a compile-time constant address. */ | |
8264 | ||
8265 | static void | |
8266 | add_location_or_const_value_attribute (die, decl) | |
8267 | register dw_die_ref die; | |
8268 | register tree decl; | |
8269 | { | |
8270 | register rtx rtl; | |
8271 | ||
8272 | if (TREE_CODE (decl) == ERROR_MARK) | |
8273 | return; | |
8274 | ||
8275 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
8276 | abort (); | |
8277 | ||
8278 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8279 | if (rtl == NULL_RTX) |
8280 | return; | |
6a7a9f01 | 8281 | |
a3f97cbb JW |
8282 | switch (GET_CODE (rtl)) |
8283 | { | |
e9a25f70 JL |
8284 | case ADDRESSOF: |
8285 | /* The address of a variable that was optimized away; don't emit | |
8286 | anything. */ | |
8287 | break; | |
8288 | ||
a3f97cbb JW |
8289 | case CONST_INT: |
8290 | case CONST_DOUBLE: | |
8291 | case CONST_STRING: | |
8292 | case SYMBOL_REF: | |
8293 | case LABEL_REF: | |
8294 | case CONST: | |
8295 | case PLUS: | |
8296 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8297 | add_const_value_attribute (die, rtl); | |
8298 | break; | |
8299 | ||
8300 | case MEM: | |
8301 | case REG: | |
8302 | case SUBREG: | |
4401bf24 | 8303 | case CONCAT: |
ef76d03b | 8304 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8305 | break; |
8306 | ||
8307 | default: | |
71dfc51f | 8308 | abort (); |
a3f97cbb JW |
8309 | } |
8310 | } | |
8311 | ||
1bfb5f8f JM |
8312 | /* If we don't have a copy of this variable in memory for some reason (such |
8313 | as a C++ member constant that doesn't have an out-of-line definition), | |
8314 | we should tell the debugger about the constant value. */ | |
8315 | ||
8316 | static void | |
8317 | tree_add_const_value_attribute (var_die, decl) | |
8318 | dw_die_ref var_die; | |
8319 | tree decl; | |
8320 | { | |
8321 | tree init = DECL_INITIAL (decl); | |
8322 | tree type = TREE_TYPE (decl); | |
8323 | ||
8324 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8325 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8326 | /* OK */; | |
8327 | else | |
8328 | return; | |
8329 | ||
8330 | switch (TREE_CODE (type)) | |
8331 | { | |
8332 | case INTEGER_TYPE: | |
8333 | if (host_integerp (init, 0)) | |
8334 | add_AT_unsigned (var_die, DW_AT_const_value, | |
8335 | TREE_INT_CST_LOW (init)); | |
8336 | else | |
8337 | add_AT_long_long (var_die, DW_AT_const_value, | |
8338 | TREE_INT_CST_HIGH (init), | |
8339 | TREE_INT_CST_LOW (init)); | |
8340 | break; | |
8341 | ||
8342 | default:; | |
8343 | } | |
8344 | } | |
8345 | ||
a3f97cbb JW |
8346 | /* Generate an DW_AT_name attribute given some string value to be included as |
8347 | the value of the attribute. */ | |
71dfc51f RK |
8348 | |
8349 | static inline void | |
a3f97cbb JW |
8350 | add_name_attribute (die, name_string) |
8351 | register dw_die_ref die; | |
d560ee52 | 8352 | register const char *name_string; |
a3f97cbb | 8353 | { |
71dfc51f | 8354 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8355 | { |
8356 | if (demangle_name_func) | |
8357 | name_string = (*demangle_name_func) (name_string); | |
8358 | ||
8359 | add_AT_string (die, DW_AT_name, name_string); | |
8360 | } | |
a3f97cbb JW |
8361 | } |
8362 | ||
8363 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8364 | a representation for that bound. */ |
71dfc51f | 8365 | |
a3f97cbb JW |
8366 | static void |
8367 | add_bound_info (subrange_die, bound_attr, bound) | |
8368 | register dw_die_ref subrange_die; | |
8369 | register enum dwarf_attribute bound_attr; | |
8370 | register tree bound; | |
8371 | { | |
ef76d03b JW |
8372 | /* If this is an Ada unconstrained array type, then don't emit any debug |
8373 | info because the array bounds are unknown. They are parameterized when | |
8374 | the type is instantiated. */ | |
8375 | if (contains_placeholder_p (bound)) | |
8376 | return; | |
8377 | ||
a3f97cbb JW |
8378 | switch (TREE_CODE (bound)) |
8379 | { | |
8380 | case ERROR_MARK: | |
8381 | return; | |
8382 | ||
8383 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
8384 | case INTEGER_CST: | |
665f2503 RK |
8385 | if (! host_integerp (bound, 0) |
8386 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 8387 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
8388 | || (is_fortran () && integer_onep (bound))))) |
8389 | /* use the default */ | |
8390 | ; | |
141719a8 | 8391 | else |
665f2503 | 8392 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
8393 | break; |
8394 | ||
b1ccbc24 | 8395 | case CONVERT_EXPR: |
a3f97cbb | 8396 | case NOP_EXPR: |
b1ccbc24 RK |
8397 | case NON_LVALUE_EXPR: |
8398 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
8399 | break; | |
556273e0 | 8400 | |
a3f97cbb JW |
8401 | case SAVE_EXPR: |
8402 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
8403 | access the upper bound values may be bogus. If they refer to a |
8404 | register, they may only describe how to get at these values at the | |
8405 | points in the generated code right after they have just been | |
8406 | computed. Worse yet, in the typical case, the upper bound values | |
8407 | will not even *be* computed in the optimized code (though the | |
8408 | number of elements will), so these SAVE_EXPRs are entirely | |
8409 | bogus. In order to compensate for this fact, we check here to see | |
8410 | if optimization is enabled, and if so, we don't add an attribute | |
8411 | for the (unknown and unknowable) upper bound. This should not | |
8412 | cause too much trouble for existing (stupid?) debuggers because | |
8413 | they have to deal with empty upper bounds location descriptions | |
8414 | anyway in order to be able to deal with incomplete array types. | |
8415 | Of course an intelligent debugger (GDB?) should be able to | |
8416 | comprehend that a missing upper bound specification in a array | |
8417 | type used for a storage class `auto' local array variable | |
8418 | indicates that the upper bound is both unknown (at compile- time) | |
8419 | and unknowable (at run-time) due to optimization. | |
8420 | ||
8421 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
8422 | value there unless it was going to be used repeatedly in the | |
8423 | function, i.e. for cleanups. */ | |
1cfdcc15 JM |
8424 | if (! optimize || (SAVE_EXPR_RTL (bound) |
8425 | && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 8426 | { |
466446b0 JM |
8427 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
8428 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
8429 | register rtx loc = SAVE_EXPR_RTL (bound); |
8430 | ||
8431 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
8432 | it references an outer function's frame. */ | |
8433 | ||
8434 | if (GET_CODE (loc) == MEM) | |
8435 | { | |
8436 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
8437 | ||
8438 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 8439 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
8440 | } |
8441 | ||
466446b0 JM |
8442 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
8443 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 8444 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 8445 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 8446 | } |
71dfc51f RK |
8447 | |
8448 | /* Else leave out the attribute. */ | |
a3f97cbb | 8449 | break; |
3f76745e | 8450 | |
ef76d03b | 8451 | case VAR_DECL: |
d8041cc8 RH |
8452 | case PARM_DECL: |
8453 | { | |
8454 | dw_die_ref decl_die = lookup_decl_die (bound); | |
8455 | ||
8456 | /* ??? Can this happen, or should the variable have been bound | |
8457 | first? Probably it can, since I imagine that we try to create | |
8458 | the types of parameters in the order in which they exist in | |
8459 | the list, and won't have created a forward reference to a | |
8460 | later parameter. */ | |
8461 | if (decl_die != NULL) | |
8462 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8463 | break; | |
8464 | } | |
ef76d03b | 8465 | |
3f76745e | 8466 | default: |
d8041cc8 RH |
8467 | { |
8468 | /* Otherwise try to create a stack operation procedure to | |
8469 | evaluate the value of the array bound. */ | |
8470 | ||
8471 | dw_die_ref ctx, decl_die; | |
8472 | dw_loc_descr_ref loc; | |
8473 | ||
8474 | loc = loc_descriptor_from_tree (bound, 0); | |
8475 | if (loc == NULL) | |
8476 | break; | |
8477 | ||
8478 | ctx = lookup_decl_die (current_function_decl); | |
8479 | ||
8480 | decl_die = new_die (DW_TAG_variable, ctx); | |
8481 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
8482 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
8483 | add_AT_loc (decl_die, DW_AT_location, loc); | |
8484 | ||
8485 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8486 | break; | |
8487 | } | |
a3f97cbb JW |
8488 | } |
8489 | } | |
8490 | ||
8491 | /* Note that the block of subscript information for an array type also | |
8492 | includes information about the element type of type given array type. */ | |
71dfc51f | 8493 | |
a3f97cbb JW |
8494 | static void |
8495 | add_subscript_info (type_die, type) | |
8496 | register dw_die_ref type_die; | |
8497 | register tree type; | |
8498 | { | |
081f5e7e | 8499 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 8500 | register unsigned dimension_number; |
081f5e7e | 8501 | #endif |
a3f97cbb JW |
8502 | register tree lower, upper; |
8503 | register dw_die_ref subrange_die; | |
8504 | ||
556273e0 | 8505 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
8506 | one dimensional array types whose element types are themselves array |
8507 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 8508 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
8509 | Dwarf specification say that we are allowed to do this kind of |
8510 | compression in C (because there is no difference between an array or | |
556273e0 | 8511 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 8512 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 8513 | |
a3f97cbb JW |
8514 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
8515 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
8516 | We work around this by disabling this feature. See also | |
8517 | gen_array_type_die. */ | |
8518 | #ifndef MIPS_DEBUGGING_INFO | |
8519 | for (dimension_number = 0; | |
8520 | TREE_CODE (type) == ARRAY_TYPE; | |
8521 | type = TREE_TYPE (type), dimension_number++) | |
8522 | { | |
8523 | #endif | |
8524 | register tree domain = TYPE_DOMAIN (type); | |
8525 | ||
8526 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 8527 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb JW |
8528 | here. */ |
8529 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
8530 | if (domain) | |
8531 | { | |
8532 | /* We have an array type with specified bounds. */ | |
8533 | lower = TYPE_MIN_VALUE (domain); | |
8534 | upper = TYPE_MAX_VALUE (domain); | |
8535 | ||
a9d38797 JM |
8536 | /* define the index type. */ |
8537 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
8538 | { |
8539 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
8540 | TREE_TYPE field. We can't emit debug info for this | |
8541 | because it is an unnamed integral type. */ | |
8542 | if (TREE_CODE (domain) == INTEGER_TYPE | |
8543 | && TYPE_NAME (domain) == NULL_TREE | |
8544 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
8545 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 8546 | ; |
ef76d03b JW |
8547 | else |
8548 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
8549 | type_die); | |
8550 | } | |
a9d38797 | 8551 | |
e1ee5cdc RH |
8552 | /* ??? If upper is NULL, the array has unspecified length, |
8553 | but it does have a lower bound. This happens with Fortran | |
8554 | dimension arr(N:*) | |
8555 | Since the debugger is definitely going to need to know N | |
8556 | to produce useful results, go ahead and output the lower | |
8557 | bound solo, and hope the debugger can cope. */ | |
8558 | ||
141719a8 | 8559 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
8560 | if (upper) |
8561 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
8562 | } |
8563 | else | |
71dfc51f | 8564 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
8565 | spec does not say how to handle this; let's just leave out the |
8566 | bounds. */ | |
e49a1d2e | 8567 | {;} |
71dfc51f | 8568 | |
a3f97cbb JW |
8569 | #ifndef MIPS_DEBUGGING_INFO |
8570 | } | |
8571 | #endif | |
8572 | } | |
8573 | ||
8574 | static void | |
8575 | add_byte_size_attribute (die, tree_node) | |
8576 | dw_die_ref die; | |
8577 | register tree tree_node; | |
8578 | { | |
8579 | register unsigned size; | |
8580 | ||
8581 | switch (TREE_CODE (tree_node)) | |
8582 | { | |
8583 | case ERROR_MARK: | |
8584 | size = 0; | |
8585 | break; | |
8586 | case ENUMERAL_TYPE: | |
8587 | case RECORD_TYPE: | |
8588 | case UNION_TYPE: | |
8589 | case QUAL_UNION_TYPE: | |
8590 | size = int_size_in_bytes (tree_node); | |
8591 | break; | |
8592 | case FIELD_DECL: | |
8593 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
8594 | generally given as the number of bytes normally allocated for an | |
8595 | object of the *declared* type of the member itself. This is true | |
8596 | even for bit-fields. */ | |
8597 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
8598 | break; | |
8599 | default: | |
8600 | abort (); | |
8601 | } | |
8602 | ||
8603 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
8604 | indicates that the byte size of the entity in question is variable. We | |
8605 | have no good way of expressing this fact in Dwarf at the present time, | |
8606 | so just let the -1 pass on through. */ | |
8607 | ||
8608 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
8609 | } | |
8610 | ||
8611 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
8612 | which specifies the distance in bits from the highest order bit of the | |
8613 | "containing object" for the bit-field to the highest order bit of the | |
8614 | bit-field itself. | |
8615 | ||
b2932ae5 JM |
8616 | For any given bit-field, the "containing object" is a hypothetical |
8617 | object (of some integral or enum type) within which the given bit-field | |
8618 | lives. The type of this hypothetical "containing object" is always the | |
8619 | same as the declared type of the individual bit-field itself. The | |
8620 | determination of the exact location of the "containing object" for a | |
8621 | bit-field is rather complicated. It's handled by the | |
8622 | `field_byte_offset' function (above). | |
a3f97cbb JW |
8623 | |
8624 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
8625 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
8626 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
8627 | |
8628 | static inline void | |
a3f97cbb JW |
8629 | add_bit_offset_attribute (die, decl) |
8630 | register dw_die_ref die; | |
8631 | register tree decl; | |
8632 | { | |
665f2503 RK |
8633 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
8634 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
8635 | HOST_WIDE_INT bitpos_int; | |
8636 | HOST_WIDE_INT highest_order_object_bit_offset; | |
8637 | HOST_WIDE_INT highest_order_field_bit_offset; | |
8638 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 8639 | |
3a88cbd1 JL |
8640 | /* Must be a field and a bit field. */ |
8641 | if (!type | |
8642 | || TREE_CODE (decl) != FIELD_DECL) | |
8643 | abort (); | |
a3f97cbb JW |
8644 | |
8645 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
8646 | encounter such things, just return without generating any attribute | |
665f2503 RK |
8647 | whatsoever. Likewise for variable or too large size. */ |
8648 | if (! host_integerp (bit_position (decl), 0) | |
8649 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
8650 | return; |
8651 | ||
665f2503 | 8652 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
8653 | |
8654 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
8655 | highest-order bit of the "containing object" to the highest-order bit of |
8656 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
8657 | is different on big-endian and little-endian machines, the computation |
8658 | below must take account of these differences. */ | |
8659 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
8660 | highest_order_field_bit_offset = bitpos_int; | |
8661 | ||
71dfc51f | 8662 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 8663 | { |
665f2503 | 8664 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
8665 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
8666 | } | |
71dfc51f RK |
8667 | |
8668 | bit_offset | |
8669 | = (! BYTES_BIG_ENDIAN | |
8670 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
8671 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
8672 | |
8673 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
8674 | } | |
8675 | ||
8676 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
8677 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
8678 | |
8679 | static inline void | |
a3f97cbb JW |
8680 | add_bit_size_attribute (die, decl) |
8681 | register dw_die_ref die; | |
8682 | register tree decl; | |
8683 | { | |
3a88cbd1 JL |
8684 | /* Must be a field and a bit field. */ |
8685 | if (TREE_CODE (decl) != FIELD_DECL | |
8686 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
8687 | abort (); | |
665f2503 RK |
8688 | |
8689 | if (host_integerp (DECL_SIZE (decl), 1)) | |
8690 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
8691 | } |
8692 | ||
88dad228 | 8693 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 8694 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
8695 | |
8696 | static inline void | |
a3f97cbb JW |
8697 | add_prototyped_attribute (die, func_type) |
8698 | register dw_die_ref die; | |
8699 | register tree func_type; | |
8700 | { | |
88dad228 JM |
8701 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
8702 | && TYPE_ARG_TYPES (func_type) != NULL) | |
8703 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
8704 | } |
8705 | ||
a3f97cbb JW |
8706 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
8707 | by looking in either the type declaration or object declaration | |
8708 | equate table. */ | |
71dfc51f RK |
8709 | |
8710 | static inline void | |
a3f97cbb JW |
8711 | add_abstract_origin_attribute (die, origin) |
8712 | register dw_die_ref die; | |
8713 | register tree origin; | |
8714 | { | |
8715 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 8716 | |
d10b8e05 | 8717 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
8718 | { |
8719 | /* We may have gotten separated from the block for the inlined | |
8720 | function, if we're in an exception handler or some such; make | |
8721 | sure that the abstract function has been written out. | |
8722 | ||
8723 | Doing this for nested functions is wrong, however; functions are | |
8724 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
8725 | tree fn = origin; |
8726 | if (TYPE_P (fn)) | |
8727 | fn = TYPE_STUB_DECL (fn); | |
8728 | fn = decl_function_context (fn); | |
e40a1c67 JM |
8729 | if (fn) |
8730 | gen_abstract_function (fn); | |
8731 | } | |
44db1d9c | 8732 | |
2f939d94 | 8733 | if (DECL_P (origin)) |
71dfc51f | 8734 | origin_die = lookup_decl_die (origin); |
2f939d94 | 8735 | else if (TYPE_P (origin)) |
71dfc51f RK |
8736 | origin_die = lookup_type_die (origin); |
8737 | ||
bbc6ae08 | 8738 | if (origin_die == NULL) |
1ae8994f | 8739 | abort (); |
556273e0 | 8740 | |
a3f97cbb JW |
8741 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
8742 | } | |
8743 | ||
bdb669cb JM |
8744 | /* We do not currently support the pure_virtual attribute. */ |
8745 | ||
71dfc51f | 8746 | static inline void |
a3f97cbb JW |
8747 | add_pure_or_virtual_attribute (die, func_decl) |
8748 | register dw_die_ref die; | |
8749 | register tree func_decl; | |
8750 | { | |
a94dbf2c | 8751 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 8752 | { |
bdb669cb | 8753 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
8754 | |
8755 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
8756 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
8757 | new_loc_descr (DW_OP_constu, | |
8758 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
8759 | 0)); | |
71dfc51f | 8760 | |
a94dbf2c JM |
8761 | /* GNU extension: Record what type this method came from originally. */ |
8762 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
8763 | add_AT_die_ref (die, DW_AT_containing_type, | |
8764 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
8765 | } |
8766 | } | |
8767 | \f | |
b2932ae5 | 8768 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 8769 | |
b2932ae5 JM |
8770 | static void |
8771 | add_src_coords_attributes (die, decl) | |
8772 | register dw_die_ref die; | |
8773 | register tree decl; | |
8774 | { | |
8775 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 8776 | |
b2932ae5 JM |
8777 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
8778 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8779 | } | |
8780 | ||
a3f97cbb JW |
8781 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
8782 | given decl, but only if it actually has a name. */ | |
71dfc51f | 8783 | |
a3f97cbb JW |
8784 | static void |
8785 | add_name_and_src_coords_attributes (die, decl) | |
8786 | register dw_die_ref die; | |
8787 | register tree decl; | |
8788 | { | |
61b32c02 | 8789 | register tree decl_name; |
71dfc51f | 8790 | |
556273e0 | 8791 | decl_name = DECL_NAME (decl); |
71dfc51f | 8792 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 8793 | { |
a1d7ffe3 | 8794 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
8795 | if (! DECL_ARTIFICIAL (decl)) |
8796 | add_src_coords_attributes (die, decl); | |
e689ae67 | 8797 | |
a1d7ffe3 | 8798 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 8799 | && TREE_PUBLIC (decl) |
a1d7ffe3 JM |
8800 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) |
8801 | add_AT_string (die, DW_AT_MIPS_linkage_name, | |
8802 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
8803 | } |
8804 | } | |
8805 | ||
556273e0 | 8806 | /* Push a new declaration scope. */ |
71dfc51f | 8807 | |
a3f97cbb JW |
8808 | static void |
8809 | push_decl_scope (scope) | |
8810 | tree scope; | |
8811 | { | |
8812 | /* Make room in the decl_scope_table, if necessary. */ | |
8813 | if (decl_scope_table_allocated == decl_scope_depth) | |
8814 | { | |
8815 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 8816 | decl_scope_table |
777ad4c2 JM |
8817 | = (tree *) xrealloc (decl_scope_table, |
8818 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 8819 | } |
71dfc51f | 8820 | |
777ad4c2 | 8821 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 8822 | decl_scope_depth++; |
a3f97cbb JW |
8823 | } |
8824 | ||
777ad4c2 JM |
8825 | /* Pop a declaration scope. */ |
8826 | static inline void | |
8827 | pop_decl_scope () | |
8828 | { | |
8829 | if (decl_scope_depth <= 0) | |
8830 | abort (); | |
8831 | --decl_scope_depth; | |
8832 | } | |
8833 | ||
8834 | /* Return the DIE for the scope that immediately contains this type. | |
8835 | Non-named types get global scope. Named types nested in other | |
8836 | types get their containing scope if it's open, or global scope | |
8837 | otherwise. All other types (i.e. function-local named types) get | |
8838 | the current active scope. */ | |
71dfc51f | 8839 | |
a3f97cbb | 8840 | static dw_die_ref |
ab72d377 | 8841 | scope_die_for (t, context_die) |
556273e0 KH |
8842 | register tree t; |
8843 | register dw_die_ref context_die; | |
a3f97cbb JW |
8844 | { |
8845 | register dw_die_ref scope_die = NULL; | |
8846 | register tree containing_scope; | |
e3e7774e | 8847 | register int i; |
a3f97cbb | 8848 | |
777ad4c2 JM |
8849 | /* Non-types always go in the current scope. */ |
8850 | if (! TYPE_P (t)) | |
8851 | abort (); | |
8852 | ||
8853 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 8854 | |
2addbe1d JM |
8855 | /* Ignore namespaces for the moment. */ |
8856 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
8857 | containing_scope = NULL_TREE; | |
8858 | ||
5f2f160c JM |
8859 | /* Ignore function type "scopes" from the C frontend. They mean that |
8860 | a tagged type is local to a parmlist of a function declarator, but | |
8861 | that isn't useful to DWARF. */ | |
8862 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
8863 | containing_scope = NULL_TREE; | |
8864 | ||
71dfc51f RK |
8865 | if (containing_scope == NULL_TREE) |
8866 | scope_die = comp_unit_die; | |
777ad4c2 | 8867 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 8868 | { |
777ad4c2 JM |
8869 | /* For types, we can just look up the appropriate DIE. But |
8870 | first we check to see if we're in the middle of emitting it | |
8871 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
8872 | |
8873 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 8874 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
8875 | break; |
8876 | ||
8877 | if (i < 0) | |
8878 | { | |
348bb3c7 JM |
8879 | if (debug_info_level > DINFO_LEVEL_TERSE |
8880 | && !TREE_ASM_WRITTEN (containing_scope)) | |
8881 | abort (); | |
8882 | ||
8883 | /* If none of the current dies are suitable, we get file scope. */ | |
8884 | scope_die = comp_unit_die; | |
8885 | } | |
8886 | else | |
777ad4c2 | 8887 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 8888 | } |
a3f97cbb | 8889 | else |
777ad4c2 | 8890 | scope_die = context_die; |
71dfc51f | 8891 | |
a3f97cbb JW |
8892 | return scope_die; |
8893 | } | |
8894 | ||
777ad4c2 JM |
8895 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
8896 | ||
c6991660 | 8897 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
8898 | static inline int |
8899 | local_scope_p (context_die) | |
8900 | dw_die_ref context_die; | |
a3f97cbb | 8901 | { |
777ad4c2 JM |
8902 | for (; context_die; context_die = context_die->die_parent) |
8903 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
8904 | || context_die->die_tag == DW_TAG_subprogram) | |
8905 | return 1; | |
8906 | return 0; | |
a3f97cbb JW |
8907 | } |
8908 | ||
9765e357 JM |
8909 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
8910 | ||
c6991660 | 8911 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
8912 | static inline int |
8913 | class_scope_p (context_die) | |
8914 | dw_die_ref context_die; | |
8915 | { | |
8916 | return (context_die | |
8917 | && (context_die->die_tag == DW_TAG_structure_type | |
8918 | || context_die->die_tag == DW_TAG_union_type)); | |
8919 | } | |
8920 | ||
a3f97cbb JW |
8921 | /* Many forms of DIEs require a "type description" attribute. This |
8922 | routine locates the proper "type descriptor" die for the type given | |
8923 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 8924 | |
a3f97cbb JW |
8925 | static void |
8926 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
8927 | register dw_die_ref object_die; | |
8928 | register tree type; | |
8929 | register int decl_const; | |
8930 | register int decl_volatile; | |
8931 | register dw_die_ref context_die; | |
8932 | { | |
8933 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
8934 | register dw_die_ref type_die = NULL; |
8935 | ||
ef76d03b JW |
8936 | /* ??? If this type is an unnamed subrange type of an integral or |
8937 | floating-point type, use the inner type. This is because we have no | |
8938 | support for unnamed types in base_type_die. This can happen if this is | |
8939 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
8940 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
8941 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
8942 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
8943 | ||
a3f97cbb | 8944 | if (code == ERROR_MARK) |
b1ccbc24 | 8945 | return; |
a3f97cbb JW |
8946 | |
8947 | /* Handle a special case. For functions whose return type is void, we | |
8948 | generate *no* type attribute. (Note that no object may have type | |
8949 | `void', so this only applies to function return types). */ | |
8950 | if (code == VOID_TYPE) | |
b1ccbc24 | 8951 | return; |
a3f97cbb | 8952 | |
a3f97cbb JW |
8953 | type_die = modified_type_die (type, |
8954 | decl_const || TYPE_READONLY (type), | |
8955 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 8956 | context_die); |
a3f97cbb | 8957 | if (type_die != NULL) |
71dfc51f | 8958 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
8959 | } |
8960 | ||
8961 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
8962 | a pointer to the (string) tag name for the given type, or zero if the type | |
8963 | was declared without a tag. */ | |
71dfc51f | 8964 | |
d3e3972c | 8965 | static const char * |
a3f97cbb JW |
8966 | type_tag (type) |
8967 | register tree type; | |
8968 | { | |
d3e3972c | 8969 | register const char *name = 0; |
a3f97cbb JW |
8970 | |
8971 | if (TYPE_NAME (type) != 0) | |
8972 | { | |
8973 | register tree t = 0; | |
8974 | ||
8975 | /* Find the IDENTIFIER_NODE for the type name. */ | |
8976 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
8977 | t = TYPE_NAME (type); | |
bdb669cb | 8978 | |
556273e0 | 8979 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 8980 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 8981 | involved. */ |
a94dbf2c JM |
8982 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
8983 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 8984 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 8985 | |
a3f97cbb JW |
8986 | /* Now get the name as a string, or invent one. */ |
8987 | if (t != 0) | |
a94dbf2c | 8988 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 8989 | } |
71dfc51f | 8990 | |
a3f97cbb JW |
8991 | return (name == 0 || *name == '\0') ? 0 : name; |
8992 | } | |
8993 | ||
8994 | /* Return the type associated with a data member, make a special check | |
8995 | for bit field types. */ | |
71dfc51f RK |
8996 | |
8997 | static inline tree | |
a3f97cbb JW |
8998 | member_declared_type (member) |
8999 | register tree member; | |
9000 | { | |
71dfc51f RK |
9001 | return (DECL_BIT_FIELD_TYPE (member) |
9002 | ? DECL_BIT_FIELD_TYPE (member) | |
9003 | : TREE_TYPE (member)); | |
a3f97cbb JW |
9004 | } |
9005 | ||
d291dd49 | 9006 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9007 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9008 | |
487a6e06 | 9009 | #if 0 |
d3e3972c | 9010 | static const char * |
d291dd49 | 9011 | decl_start_label (decl) |
a3f97cbb JW |
9012 | register tree decl; |
9013 | { | |
9014 | rtx x; | |
d3e3972c | 9015 | const char *fnname; |
a3f97cbb JW |
9016 | x = DECL_RTL (decl); |
9017 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9018 | abort (); |
9019 | ||
a3f97cbb JW |
9020 | x = XEXP (x, 0); |
9021 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9022 | abort (); |
9023 | ||
a3f97cbb JW |
9024 | fnname = XSTR (x, 0); |
9025 | return fnname; | |
9026 | } | |
487a6e06 | 9027 | #endif |
a3f97cbb | 9028 | \f |
956d6950 | 9029 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9030 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9031 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9032 | |
9033 | static void | |
9034 | gen_array_type_die (type, context_die) | |
9035 | register tree type; | |
9036 | register dw_die_ref context_die; | |
9037 | { | |
ab72d377 | 9038 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 9039 | register dw_die_ref array_die; |
a3f97cbb | 9040 | register tree element_type; |
bdb669cb | 9041 | |
a9d38797 JM |
9042 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9043 | the inner array type comes before the outer array type. Thus we must | |
9044 | call gen_type_die before we call new_die. See below also. */ | |
9045 | #ifdef MIPS_DEBUGGING_INFO | |
9046 | gen_type_die (TREE_TYPE (type), context_die); | |
9047 | #endif | |
9048 | ||
9049 | array_die = new_die (DW_TAG_array_type, scope_die); | |
9050 | ||
a3f97cbb JW |
9051 | #if 0 |
9052 | /* We default the array ordering. SDB will probably do | |
9053 | the right things even if DW_AT_ordering is not present. It's not even | |
9054 | an issue until we start to get into multidimensional arrays anyway. If | |
9055 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9056 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9057 | and when we find out that we need to put these in, we will only do so | |
9058 | for multidimensional arrays. */ | |
9059 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9060 | #endif | |
9061 | ||
a9d38797 | 9062 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9063 | /* The SGI compilers handle arrays of unknown bound by setting |
9064 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9065 | if (! TYPE_DOMAIN (type)) |
9066 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9067 | else | |
9068 | #endif | |
9069 | add_subscript_info (array_die, type); | |
a3f97cbb | 9070 | |
14a774a9 | 9071 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9072 | equate_type_number_to_die (type, array_die); |
9073 | ||
9074 | /* Add representation of the type of the elements of this array type. */ | |
9075 | element_type = TREE_TYPE (type); | |
71dfc51f | 9076 | |
a3f97cbb JW |
9077 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9078 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9079 | We work around this by disabling this feature. See also | |
9080 | add_subscript_info. */ | |
9081 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9082 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9083 | element_type = TREE_TYPE (element_type); | |
9084 | ||
a3f97cbb | 9085 | gen_type_die (element_type, context_die); |
a9d38797 | 9086 | #endif |
a3f97cbb JW |
9087 | |
9088 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9089 | } | |
9090 | ||
9091 | static void | |
9092 | gen_set_type_die (type, context_die) | |
9093 | register tree type; | |
9094 | register dw_die_ref context_die; | |
9095 | { | |
71dfc51f RK |
9096 | register dw_die_ref type_die |
9097 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
9098 | ||
a3f97cbb | 9099 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9100 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9101 | } | |
9102 | ||
d6f4ec51 | 9103 | #if 0 |
a3f97cbb JW |
9104 | static void |
9105 | gen_entry_point_die (decl, context_die) | |
9106 | register tree decl; | |
9107 | register dw_die_ref context_die; | |
9108 | { | |
9109 | register tree origin = decl_ultimate_origin (decl); | |
9110 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
9111 | if (origin != NULL) | |
71dfc51f | 9112 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9113 | else |
9114 | { | |
9115 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9116 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9117 | 0, 0, context_die); | |
9118 | } | |
71dfc51f | 9119 | |
a3f97cbb | 9120 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9121 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9122 | else |
71dfc51f | 9123 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9124 | } |
d6f4ec51 | 9125 | #endif |
a3f97cbb | 9126 | |
8a8c3656 JM |
9127 | /* Remember a type in the incomplete_types_list. */ |
9128 | ||
9129 | static void | |
9130 | add_incomplete_type (type) | |
9131 | tree type; | |
9132 | { | |
9133 | if (incomplete_types == incomplete_types_allocated) | |
9134 | { | |
9135 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
9136 | incomplete_types_list | |
9137 | = (tree *) xrealloc (incomplete_types_list, | |
9138 | sizeof (tree) * incomplete_types_allocated); | |
9139 | } | |
9140 | ||
9141 | incomplete_types_list[incomplete_types++] = type; | |
9142 | } | |
9143 | ||
9144 | /* Walk through the list of incomplete types again, trying once more to | |
9145 | emit full debugging info for them. */ | |
9146 | ||
9147 | static void | |
9148 | retry_incomplete_types () | |
9149 | { | |
9150 | register tree type; | |
9151 | ||
9152 | while (incomplete_types) | |
9153 | { | |
9154 | --incomplete_types; | |
9155 | type = incomplete_types_list[incomplete_types]; | |
9156 | gen_type_die (type, comp_unit_die); | |
9157 | } | |
9158 | } | |
9159 | ||
a3f97cbb | 9160 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9161 | |
a3f97cbb JW |
9162 | static void |
9163 | gen_inlined_enumeration_type_die (type, context_die) | |
9164 | register tree type; | |
9165 | register dw_die_ref context_die; | |
9166 | { | |
71dfc51f | 9167 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 9168 | context_die); |
bbc6ae08 NC |
9169 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9170 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9171 | add_abstract_origin_attribute (type_die, type); |
9172 | } | |
9173 | ||
9174 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9175 | |
a3f97cbb JW |
9176 | static void |
9177 | gen_inlined_structure_type_die (type, context_die) | |
9178 | register tree type; | |
9179 | register dw_die_ref context_die; | |
9180 | { | |
777ad4c2 JM |
9181 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
9182 | ||
bbc6ae08 NC |
9183 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9184 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9185 | add_abstract_origin_attribute (type_die, type); |
9186 | } | |
9187 | ||
9188 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9189 | |
a3f97cbb JW |
9190 | static void |
9191 | gen_inlined_union_type_die (type, context_die) | |
9192 | register tree type; | |
9193 | register dw_die_ref context_die; | |
9194 | { | |
777ad4c2 JM |
9195 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
9196 | ||
bbc6ae08 NC |
9197 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9198 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9199 | add_abstract_origin_attribute (type_die, type); |
9200 | } | |
9201 | ||
9202 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9203 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9204 | enumerated type name/value is listed as a child of the enumerated type |
9205 | DIE. */ | |
71dfc51f | 9206 | |
a3f97cbb | 9207 | static void |
273dbe67 | 9208 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 9209 | register tree type; |
a3f97cbb JW |
9210 | register dw_die_ref context_die; |
9211 | { | |
273dbe67 JM |
9212 | register dw_die_ref type_die = lookup_type_die (type); |
9213 | ||
a3f97cbb JW |
9214 | if (type_die == NULL) |
9215 | { | |
9216 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 9217 | scope_die_for (type, context_die)); |
a3f97cbb JW |
9218 | equate_type_number_to_die (type, type_die); |
9219 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9220 | } |
273dbe67 JM |
9221 | else if (! TYPE_SIZE (type)) |
9222 | return; | |
9223 | else | |
9224 | remove_AT (type_die, DW_AT_declaration); | |
9225 | ||
9226 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9227 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9228 | attribute or the DW_AT_element_list attribute. */ | |
9229 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9230 | { |
273dbe67 | 9231 | register tree link; |
71dfc51f | 9232 | |
a082c85a | 9233 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9234 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9235 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9236 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9237 | |
ef76d03b JW |
9238 | /* If the first reference to this type was as the return type of an |
9239 | inline function, then it may not have a parent. Fix this now. */ | |
9240 | if (type_die->die_parent == NULL) | |
9241 | add_child_die (scope_die_for (type, context_die), type_die); | |
9242 | ||
273dbe67 JM |
9243 | for (link = TYPE_FIELDS (type); |
9244 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9245 | { |
273dbe67 | 9246 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 9247 | |
273dbe67 JM |
9248 | add_name_attribute (enum_die, |
9249 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9250 | |
9251 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9252 | { |
9253 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9254 | add_AT_int (enum_die, DW_AT_const_value, | |
9255 | tree_low_cst (TREE_VALUE (link), 0)); | |
9256 | else | |
9257 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9258 | tree_low_cst (TREE_VALUE (link), 0)); | |
9259 | } | |
a3f97cbb JW |
9260 | } |
9261 | } | |
273dbe67 JM |
9262 | else |
9263 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9264 | } |
9265 | ||
a3f97cbb JW |
9266 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9267 | represent just the type of some formal parameter position in some function | |
9268 | type. | |
71dfc51f | 9269 | |
a3f97cbb JW |
9270 | Note that this routine is a bit unusual because its argument may be a |
9271 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9272 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9273 | node. If it's the former then this function is being called to output a | |
9274 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9275 | it's the latter, then this function is only being called to output a | |
9276 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9277 | argument type of some subprogram type. */ | |
71dfc51f | 9278 | |
a94dbf2c | 9279 | static dw_die_ref |
a3f97cbb JW |
9280 | gen_formal_parameter_die (node, context_die) |
9281 | register tree node; | |
9282 | register dw_die_ref context_die; | |
9283 | { | |
71dfc51f RK |
9284 | register dw_die_ref parm_die |
9285 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 9286 | register tree origin; |
71dfc51f | 9287 | |
a3f97cbb JW |
9288 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9289 | { | |
a3f97cbb JW |
9290 | case 'd': |
9291 | origin = decl_ultimate_origin (node); | |
9292 | if (origin != NULL) | |
a94dbf2c | 9293 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9294 | else |
9295 | { | |
9296 | add_name_and_src_coords_attributes (parm_die, node); | |
9297 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9298 | TREE_READONLY (node), | |
9299 | TREE_THIS_VOLATILE (node), | |
9300 | context_die); | |
bdb669cb JM |
9301 | if (DECL_ARTIFICIAL (node)) |
9302 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9303 | } |
71dfc51f | 9304 | |
141719a8 JM |
9305 | equate_decl_number_to_die (node, parm_die); |
9306 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9307 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9308 | |
a3f97cbb JW |
9309 | break; |
9310 | ||
a3f97cbb | 9311 | case 't': |
71dfc51f | 9312 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9313 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9314 | break; | |
9315 | ||
a3f97cbb JW |
9316 | default: |
9317 | abort (); | |
9318 | } | |
71dfc51f | 9319 | |
a94dbf2c | 9320 | return parm_die; |
a3f97cbb JW |
9321 | } |
9322 | ||
9323 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9324 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9325 | |
a3f97cbb JW |
9326 | static void |
9327 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 9328 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9329 | register dw_die_ref context_die; |
9330 | { | |
487a6e06 | 9331 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
9332 | } |
9333 | ||
9334 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9335 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9336 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9337 | those which appear as part of a function *definition*). */ |
71dfc51f | 9338 | |
a3f97cbb JW |
9339 | static void |
9340 | gen_formal_types_die (function_or_method_type, context_die) | |
9341 | register tree function_or_method_type; | |
9342 | register dw_die_ref context_die; | |
9343 | { | |
9344 | register tree link; | |
9345 | register tree formal_type = NULL; | |
9346 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
9347 | ||
bdb669cb | 9348 | #if 0 |
a3f97cbb JW |
9349 | /* In the case where we are generating a formal types list for a C++ |
9350 | non-static member function type, skip over the first thing on the | |
9351 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
9352 | `this pointer'. The debugger should be able to figure out (without | |
556273e0 KH |
9353 | being explicitly told) that this non-static member function type takes a |
9354 | `this pointer' and should be able to figure what the type of that hidden | |
a3f97cbb JW |
9355 | parameter is from the DW_AT_member attribute of the parent |
9356 | DW_TAG_subroutine_type DIE. */ | |
9357 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
9358 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 9359 | #endif |
a3f97cbb | 9360 | |
556273e0 | 9361 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb JW |
9362 | DW_TAG_formal_parameter DIE for each one. */ |
9363 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
9364 | { | |
a94dbf2c | 9365 | register dw_die_ref parm_die; |
556273e0 | 9366 | |
a3f97cbb JW |
9367 | formal_type = TREE_VALUE (link); |
9368 | if (formal_type == void_type_node) | |
9369 | break; | |
9370 | ||
9371 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c JM |
9372 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
9373 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE | |
9374 | && link == first_parm_type) | |
9375 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
9376 | } |
9377 | ||
9378 | /* If this function type has an ellipsis, add a | |
9379 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9380 | if (formal_type != void_type_node) | |
9381 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9382 | ||
556273e0 | 9383 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9384 | and output DIEs to represent those types (as necessary). */ |
9385 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
9386 | link; | |
9387 | link = TREE_CHAIN (link)) | |
9388 | { | |
9389 | formal_type = TREE_VALUE (link); | |
9390 | if (formal_type == void_type_node) | |
9391 | break; | |
9392 | ||
b50c02f9 | 9393 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
9394 | } |
9395 | } | |
9396 | ||
10a11b75 JM |
9397 | /* We want to generate the DIE for TYPE so that we can generate the |
9398 | die for MEMBER, which has been defined; we will need to refer back | |
9399 | to the member declaration nested within TYPE. If we're trying to | |
9400 | generate minimal debug info for TYPE, processing TYPE won't do the | |
9401 | trick; we need to attach the member declaration by hand. */ | |
9402 | ||
9403 | static void | |
9404 | gen_type_die_for_member (type, member, context_die) | |
9405 | tree type, member; | |
9406 | dw_die_ref context_die; | |
9407 | { | |
9408 | gen_type_die (type, context_die); | |
9409 | ||
9410 | /* If we're trying to avoid duplicate debug info, we may not have | |
9411 | emitted the member decl for this function. Emit it now. */ | |
9412 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
9413 | && ! lookup_decl_die (member)) | |
9414 | { | |
9415 | if (decl_ultimate_origin (member)) | |
9416 | abort (); | |
9417 | ||
9418 | push_decl_scope (type); | |
9419 | if (TREE_CODE (member) == FUNCTION_DECL) | |
9420 | gen_subprogram_die (member, lookup_type_die (type)); | |
9421 | else | |
9422 | gen_variable_die (member, lookup_type_die (type)); | |
9423 | pop_decl_scope (); | |
9424 | } | |
9425 | } | |
9426 | ||
9427 | /* Generate the DWARF2 info for the "abstract" instance | |
9428 | of a function which we may later generate inlined and/or | |
9429 | out-of-line instances of. */ | |
9430 | ||
9431 | static void | |
9432 | gen_abstract_function (decl) | |
9433 | tree decl; | |
9434 | { | |
9435 | register dw_die_ref old_die = lookup_decl_die (decl); | |
777ad4c2 | 9436 | tree save_fn; |
10a11b75 JM |
9437 | |
9438 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) | |
9439 | /* We've already generated the abstract instance. */ | |
9440 | return; | |
9441 | ||
777ad4c2 JM |
9442 | save_fn = current_function_decl; |
9443 | current_function_decl = decl; | |
9444 | ||
10a11b75 JM |
9445 | set_decl_abstract_flags (decl, 1); |
9446 | dwarf2out_decl (decl); | |
9447 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
9448 | |
9449 | current_function_decl = save_fn; | |
10a11b75 JM |
9450 | } |
9451 | ||
a3f97cbb JW |
9452 | /* Generate a DIE to represent a declared function (either file-scope or |
9453 | block-local). */ | |
71dfc51f | 9454 | |
a3f97cbb JW |
9455 | static void |
9456 | gen_subprogram_die (decl, context_die) | |
9457 | register tree decl; | |
9458 | register dw_die_ref context_die; | |
9459 | { | |
9460 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9461 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 9462 | register dw_die_ref subr_die; |
b1ccbc24 | 9463 | register rtx fp_reg; |
a3f97cbb JW |
9464 | register tree fn_arg_types; |
9465 | register tree outer_scope; | |
a94dbf2c | 9466 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9467 | register int declaration = (current_function_decl != decl |
9468 | || class_scope_p (context_die)); | |
a3f97cbb | 9469 | |
10a11b75 JM |
9470 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
9471 | be true, if we started to generate the abstract instance of an inline, | |
9472 | decided to output its containing class, and proceeded to emit the | |
9473 | declaration of the inline from the member list for the class. In that | |
9474 | case, `declaration' takes priority; we'll get back to the abstract | |
9475 | instance when we're done with the class. */ | |
9476 | ||
1cfdcc15 JM |
9477 | /* The class-scope declaration DIE must be the primary DIE. */ |
9478 | if (origin && declaration && class_scope_p (context_die)) | |
9479 | { | |
9480 | origin = NULL; | |
9481 | if (old_die) | |
9482 | abort (); | |
9483 | } | |
9484 | ||
a3f97cbb JW |
9485 | if (origin != NULL) |
9486 | { | |
777ad4c2 | 9487 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
9488 | abort (); |
9489 | ||
8d8238b6 JM |
9490 | /* Fixup die_parent for the abstract instance of a nested |
9491 | inline function. */ | |
9492 | if (old_die && old_die->die_parent == NULL) | |
9493 | add_child_die (context_die, old_die); | |
9494 | ||
4b674448 | 9495 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
9496 | add_abstract_origin_attribute (subr_die, origin); |
9497 | } | |
4401bf24 JL |
9498 | else if (old_die && DECL_ABSTRACT (decl) |
9499 | && get_AT_unsigned (old_die, DW_AT_inline)) | |
9500 | { | |
9501 | /* This must be a redefinition of an extern inline function. | |
9502 | We can just reuse the old die here. */ | |
9503 | subr_die = old_die; | |
9504 | ||
9505 | /* Clear out the inlined attribute and parm types. */ | |
9506 | remove_AT (subr_die, DW_AT_inline); | |
9507 | remove_children (subr_die); | |
9508 | } | |
bdb669cb JM |
9509 | else if (old_die) |
9510 | { | |
4b674448 JM |
9511 | register unsigned file_index |
9512 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
a94dbf2c | 9513 | |
3a88cbd1 | 9514 | if (get_AT_flag (old_die, DW_AT_declaration) != 1) |
b75ab88b NC |
9515 | { |
9516 | /* ??? This can happen if there is a bug in the program, for | |
9517 | instance, if it has duplicate function definitions. Ideally, | |
9518 | we should detect this case and ignore it. For now, if we have | |
9519 | already reported an error, any error at all, then assume that | |
9520 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
9521 | if (errorcount) |
9522 | return; | |
9523 | abort (); | |
9524 | } | |
4b674448 JM |
9525 | |
9526 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
9527 | maybe use the old DIE. We always want the DIE for this function |
9528 | that has the *_pc attributes to be under comp_unit_die so the | |
9529 | debugger can find it. For inlines, that is the concrete instance, | |
9530 | so we can use the old DIE here. For non-inline methods, we want a | |
9531 | specification DIE at toplevel, so we need a new DIE. For local | |
a96c67ec | 9532 | class methods, this doesn't apply; we just use the old DIE. */ |
a94dbf2c JM |
9533 | if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die |
9534 | || context_die == NULL) | |
a96c67ec JM |
9535 | && (DECL_ARTIFICIAL (decl) |
9536 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
9537 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9538 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 9539 | { |
4b674448 JM |
9540 | subr_die = old_die; |
9541 | ||
9542 | /* Clear out the declaration attribute and the parm types. */ | |
9543 | remove_AT (subr_die, DW_AT_declaration); | |
9544 | remove_children (subr_die); | |
9545 | } | |
9546 | else | |
9547 | { | |
9548 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
9549 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
9550 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9551 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
9552 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9553 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
9554 | add_AT_unsigned |
9555 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9556 | } | |
9557 | } | |
a3f97cbb JW |
9558 | else |
9559 | { | |
777ad4c2 | 9560 | subr_die = new_die (DW_TAG_subprogram, context_die); |
556273e0 | 9561 | |
273dbe67 JM |
9562 | if (TREE_PUBLIC (decl)) |
9563 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 9564 | |
a3f97cbb | 9565 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
9566 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9567 | { | |
9568 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 9569 | |
4927276d JM |
9570 | add_prototyped_attribute (subr_die, type); |
9571 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
9572 | } | |
71dfc51f | 9573 | |
a3f97cbb | 9574 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
9575 | if (DECL_ARTIFICIAL (decl)) |
9576 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
9577 | if (TREE_PROTECTED (decl)) |
9578 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
9579 | else if (TREE_PRIVATE (decl)) | |
9580 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9581 | } |
4edb7b60 | 9582 | |
a94dbf2c JM |
9583 | if (declaration) |
9584 | { | |
777ad4c2 JM |
9585 | if (! origin) |
9586 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
a94dbf2c JM |
9587 | |
9588 | /* The first time we see a member function, it is in the context of | |
9589 | the class to which it belongs. We make sure of this by emitting | |
9590 | the class first. The next time is the definition, which is | |
9591 | handled above. The two may come from the same source text. */ | |
777ad4c2 | 9592 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) |
a94dbf2c JM |
9593 | equate_decl_number_to_die (decl, subr_die); |
9594 | } | |
9595 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 9596 | { |
10a11b75 | 9597 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 9598 | { |
10a11b75 JM |
9599 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
9600 | inline functions, but not for extern inline functions. | |
9601 | We can't get this completely correct because information | |
9602 | about whether the function was declared inline is not | |
9603 | saved anywhere. */ | |
9604 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
9605 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
9606 | else | |
10a11b75 | 9607 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 9608 | } |
61b32c02 | 9609 | else |
10a11b75 | 9610 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 9611 | |
a3f97cbb JW |
9612 | equate_decl_number_to_die (decl, subr_die); |
9613 | } | |
9614 | else if (!DECL_EXTERNAL (decl)) | |
9615 | { | |
71dfc51f | 9616 | if (origin == NULL_TREE) |
ba7b35df | 9617 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 9618 | |
5c90448c JM |
9619 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
9620 | current_funcdef_number); | |
7d4440be | 9621 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
9622 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
9623 | current_funcdef_number); | |
a3f97cbb JW |
9624 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
9625 | ||
d291dd49 JM |
9626 | add_pubname (decl, subr_die); |
9627 | add_arange (decl, subr_die); | |
9628 | ||
a3f97cbb | 9629 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
9630 | /* Add a reference to the FDE for this routine. */ |
9631 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
9632 | #endif | |
9633 | ||
810429b7 JM |
9634 | /* Define the "frame base" location for this routine. We use the |
9635 | frame pointer or stack pointer registers, since the RTL for local | |
9636 | variables is relative to one of them. */ | |
b1ccbc24 RK |
9637 | fp_reg |
9638 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
9639 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 9640 | |
ef76d03b JW |
9641 | #if 0 |
9642 | /* ??? This fails for nested inline functions, because context_display | |
9643 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 9644 | if (current_function_needs_context) |
ef76d03b JW |
9645 | add_AT_location_description (subr_die, DW_AT_static_link, |
9646 | lookup_static_chain (decl)); | |
9647 | #endif | |
a3f97cbb JW |
9648 | } |
9649 | ||
9650 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 9651 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
9652 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
9653 | `...' at the end of the formal parameter list. In order to find out if | |
9654 | there was a trailing ellipsis or not, we must instead look at the type | |
9655 | associated with the FUNCTION_DECL. This will be a node of type | |
9656 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 9657 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 9658 | an ellipsis at the end. */ |
71dfc51f | 9659 | |
a3f97cbb | 9660 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 9661 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 9662 | its formal parameters. */ |
4927276d | 9663 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 9664 | ; |
4edb7b60 JM |
9665 | else if (declaration) |
9666 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
a3f97cbb JW |
9667 | else |
9668 | { | |
9669 | /* Generate DIEs to represent all known formal parameters */ | |
9670 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
9671 | register tree parm; | |
9672 | ||
9673 | /* When generating DIEs, generate the unspecified_parameters DIE | |
9674 | instead if we come across the arg "__builtin_va_alist" */ | |
9675 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
9676 | if (TREE_CODE (parm) == PARM_DECL) |
9677 | { | |
db3cf6fb MS |
9678 | if (DECL_NAME (parm) |
9679 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
9680 | "__builtin_va_alist")) | |
71dfc51f RK |
9681 | gen_unspecified_parameters_die (parm, subr_die); |
9682 | else | |
9683 | gen_decl_die (parm, subr_die); | |
9684 | } | |
a3f97cbb JW |
9685 | |
9686 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
556273e0 | 9687 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
9688 | this is detectable when the end of the arg list is not a |
9689 | void_type_node 2) an unprototyped function declaration (not a | |
9690 | definition). This just means that we have no info about the | |
9691 | parameters at all. */ | |
9692 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 9693 | if (fn_arg_types != NULL) |
a3f97cbb JW |
9694 | { |
9695 | /* this is the prototyped case, check for ... */ | |
9696 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 9697 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 9698 | } |
71dfc51f RK |
9699 | else if (DECL_INITIAL (decl) == NULL_TREE) |
9700 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
9701 | } |
9702 | ||
9703 | /* Output Dwarf info for all of the stuff within the body of the function | |
9704 | (if it has one - it may be just a declaration). */ | |
9705 | outer_scope = DECL_INITIAL (decl); | |
9706 | ||
d7248bff JM |
9707 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
9708 | node created to represent a function. This outermost BLOCK actually | |
9709 | represents the outermost binding contour for the function, i.e. the | |
9710 | contour in which the function's formal parameters and labels get | |
9711 | declared. Curiously, it appears that the front end doesn't actually | |
9712 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
9713 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
9714 | list for the function instead.) The BLOCK_VARS list for the | |
9715 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
9716 | the function however, and we output DWARF info for those in | |
9717 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
9718 | node representing the function's outermost pair of curly braces, and | |
9719 | any blocks used for the base and member initializers of a C++ | |
9720 | constructor function. */ | |
4edb7b60 | 9721 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
9722 | { |
9723 | current_function_has_inlines = 0; | |
9724 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 9725 | |
ce61cc73 | 9726 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
9727 | if (current_function_has_inlines) |
9728 | { | |
9729 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
9730 | if (! comp_unit_has_inlines) | |
9731 | { | |
9732 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
9733 | comp_unit_has_inlines = 1; | |
9734 | } | |
9735 | } | |
9736 | #endif | |
9737 | } | |
a3f97cbb JW |
9738 | } |
9739 | ||
9740 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 9741 | |
a3f97cbb JW |
9742 | static void |
9743 | gen_variable_die (decl, context_die) | |
9744 | register tree decl; | |
9745 | register dw_die_ref context_die; | |
9746 | { | |
9747 | register tree origin = decl_ultimate_origin (decl); | |
9748 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 9749 | |
bdb669cb | 9750 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9751 | int declaration = (DECL_EXTERNAL (decl) |
9752 | || class_scope_p (context_die)); | |
4edb7b60 | 9753 | |
a3f97cbb | 9754 | if (origin != NULL) |
71dfc51f | 9755 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
9756 | /* Loop unrolling can create multiple blocks that refer to the same |
9757 | static variable, so we must test for the DW_AT_declaration flag. */ | |
9758 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
9759 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
9760 | sharing them. */ | |
9761 | else if (old_die && TREE_STATIC (decl) | |
9762 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 9763 | { |
e689ae67 | 9764 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
9765 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
9766 | if (DECL_NAME (decl)) | |
9767 | { | |
9768 | register unsigned file_index | |
9769 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 9770 | |
bdb669cb JM |
9771 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9772 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 9773 | |
bdb669cb | 9774 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 9775 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
9776 | |
9777 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
9778 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
9779 | } |
9780 | } | |
a3f97cbb JW |
9781 | else |
9782 | { | |
9783 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
9784 | add_type_attribute (var_die, TREE_TYPE (decl), |
9785 | TREE_READONLY (decl), | |
9786 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 9787 | |
273dbe67 JM |
9788 | if (TREE_PUBLIC (decl)) |
9789 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 9790 | |
273dbe67 JM |
9791 | if (DECL_ARTIFICIAL (decl)) |
9792 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 9793 | |
a94dbf2c JM |
9794 | if (TREE_PROTECTED (decl)) |
9795 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 9796 | |
a94dbf2c JM |
9797 | else if (TREE_PRIVATE (decl)) |
9798 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9799 | } |
4edb7b60 JM |
9800 | |
9801 | if (declaration) | |
9802 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 9803 | |
9765e357 | 9804 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
9805 | equate_decl_number_to_die (decl, var_die); |
9806 | ||
9807 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
9808 | { |
9809 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 9810 | add_pubname (decl, var_die); |
a3f97cbb | 9811 | } |
1bfb5f8f JM |
9812 | else |
9813 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
9814 | } |
9815 | ||
9816 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 9817 | |
a3f97cbb JW |
9818 | static void |
9819 | gen_label_die (decl, context_die) | |
9820 | register tree decl; | |
9821 | register dw_die_ref context_die; | |
9822 | { | |
9823 | register tree origin = decl_ultimate_origin (decl); | |
9824 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
9825 | register rtx insn; | |
9826 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5c90448c | 9827 | char label2[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 9828 | |
a3f97cbb | 9829 | if (origin != NULL) |
71dfc51f | 9830 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 9831 | else |
71dfc51f RK |
9832 | add_name_and_src_coords_attributes (lbl_die, decl); |
9833 | ||
a3f97cbb | 9834 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9835 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
9836 | else |
9837 | { | |
9838 | insn = DECL_RTL (decl); | |
088e7160 NC |
9839 | |
9840 | /* Deleted labels are programmer specified labels which have been | |
9841 | eliminated because of various optimisations. We still emit them | |
9842 | here so that it is possible to put breakpoints on them. */ | |
9843 | if (GET_CODE (insn) == CODE_LABEL | |
9844 | || ((GET_CODE (insn) == NOTE | |
9845 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 9846 | { |
556273e0 KH |
9847 | /* When optimization is enabled (via -O) some parts of the compiler |
9848 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
9849 | represent source-level labels which were explicitly declared by |
9850 | the user. This really shouldn't be happening though, so catch | |
9851 | it if it ever does happen. */ | |
9852 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
9853 | abort (); |
9854 | ||
5c90448c JM |
9855 | sprintf (label2, INSN_LABEL_FMT, current_funcdef_number); |
9856 | ASM_GENERATE_INTERNAL_LABEL (label, label2, | |
9857 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
9858 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
9859 | } | |
9860 | } | |
9861 | } | |
9862 | ||
9863 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 9864 | |
a3f97cbb | 9865 | static void |
d7248bff | 9866 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
9867 | register tree stmt; |
9868 | register dw_die_ref context_die; | |
d7248bff | 9869 | int depth; |
a3f97cbb JW |
9870 | { |
9871 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
9872 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
9873 | |
9874 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 9875 | { |
5c90448c | 9876 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 9877 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 9878 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
18c038b9 MM |
9879 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
9880 | BLOCK_NUMBER (stmt)); | |
a3f97cbb JW |
9881 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
9882 | } | |
71dfc51f | 9883 | |
d7248bff | 9884 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
9885 | } |
9886 | ||
9887 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 9888 | |
a3f97cbb | 9889 | static void |
d7248bff | 9890 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
9891 | register tree stmt; |
9892 | register dw_die_ref context_die; | |
d7248bff | 9893 | int depth; |
a3f97cbb | 9894 | { |
71dfc51f | 9895 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 9896 | { |
71dfc51f RK |
9897 | register dw_die_ref subr_die |
9898 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 9899 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 9900 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 9901 | |
10a11b75 JM |
9902 | /* Emit info for the abstract instance first, if we haven't yet. */ |
9903 | gen_abstract_function (decl); | |
9904 | ||
ab72d377 | 9905 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 9906 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 9907 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 9908 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
9909 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
9910 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 9911 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 9912 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 9913 | current_function_has_inlines = 1; |
a3f97cbb | 9914 | } |
a3f97cbb JW |
9915 | } |
9916 | ||
9917 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 9918 | |
a3f97cbb JW |
9919 | static void |
9920 | gen_field_die (decl, context_die) | |
9921 | register tree decl; | |
9922 | register dw_die_ref context_die; | |
9923 | { | |
9924 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 9925 | |
a3f97cbb | 9926 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
9927 | add_type_attribute (decl_die, member_declared_type (decl), |
9928 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
9929 | context_die); | |
71dfc51f | 9930 | |
a3f97cbb JW |
9931 | /* If this is a bit field... */ |
9932 | if (DECL_BIT_FIELD_TYPE (decl)) | |
9933 | { | |
9934 | add_byte_size_attribute (decl_die, decl); | |
9935 | add_bit_size_attribute (decl_die, decl); | |
9936 | add_bit_offset_attribute (decl_die, decl); | |
9937 | } | |
71dfc51f | 9938 | |
a94dbf2c JM |
9939 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
9940 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 9941 | |
273dbe67 JM |
9942 | if (DECL_ARTIFICIAL (decl)) |
9943 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 9944 | |
a94dbf2c JM |
9945 | if (TREE_PROTECTED (decl)) |
9946 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 9947 | |
a94dbf2c JM |
9948 | else if (TREE_PRIVATE (decl)) |
9949 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
9950 | } |
9951 | ||
ab72d377 JM |
9952 | #if 0 |
9953 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
9954 | Use modified_type_die instead. | |
a3f97cbb JW |
9955 | We keep this code here just in case these types of DIEs may be needed to |
9956 | represent certain things in other languages (e.g. Pascal) someday. */ | |
9957 | static void | |
9958 | gen_pointer_type_die (type, context_die) | |
9959 | register tree type; | |
9960 | register dw_die_ref context_die; | |
9961 | { | |
71dfc51f RK |
9962 | register dw_die_ref ptr_die |
9963 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
9964 | ||
a3f97cbb | 9965 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 9966 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 9967 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
9968 | } |
9969 | ||
ab72d377 JM |
9970 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
9971 | Use modified_type_die instead. | |
a3f97cbb JW |
9972 | We keep this code here just in case these types of DIEs may be needed to |
9973 | represent certain things in other languages (e.g. Pascal) someday. */ | |
9974 | static void | |
9975 | gen_reference_type_die (type, context_die) | |
9976 | register tree type; | |
9977 | register dw_die_ref context_die; | |
9978 | { | |
71dfc51f RK |
9979 | register dw_die_ref ref_die |
9980 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
9981 | ||
a3f97cbb | 9982 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 9983 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 9984 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 9985 | } |
ab72d377 | 9986 | #endif |
a3f97cbb JW |
9987 | |
9988 | /* Generate a DIE for a pointer to a member type. */ | |
9989 | static void | |
9990 | gen_ptr_to_mbr_type_die (type, context_die) | |
9991 | register tree type; | |
9992 | register dw_die_ref context_die; | |
9993 | { | |
71dfc51f RK |
9994 | register dw_die_ref ptr_die |
9995 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
9996 | ||
a3f97cbb | 9997 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 9998 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 9999 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10000 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10001 | } | |
10002 | ||
10003 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10004 | |
a96c67ec JM |
10005 | static dw_die_ref |
10006 | gen_compile_unit_die (filename) | |
10007 | register const char *filename; | |
a3f97cbb | 10008 | { |
a96c67ec | 10009 | register dw_die_ref die; |
a3f97cbb | 10010 | char producer[250]; |
d3e3972c | 10011 | const char *wd = getpwd (); |
a96c67ec | 10012 | int language; |
a3f97cbb | 10013 | |
a96c67ec JM |
10014 | die = new_die (DW_TAG_compile_unit, NULL); |
10015 | add_name_attribute (die, filename); | |
bdb669cb | 10016 | |
a96c67ec JM |
10017 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10018 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10019 | |
10020 | sprintf (producer, "%s %s", language_string, version_string); | |
10021 | ||
10022 | #ifdef MIPS_DEBUGGING_INFO | |
10023 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10024 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10025 | not appear in the producer string, the debugger reaches the conclusion | |
10026 | that the object file is stripped and has no debugging information. | |
10027 | To get the MIPS/SGI debugger to believe that there is debugging | |
10028 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10029 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10030 | strcat (producer, " -g"); | |
a3f97cbb JW |
10031 | #endif |
10032 | ||
a96c67ec | 10033 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10034 | |
a3f97cbb | 10035 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10036 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10037 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10038 | language = DW_LANG_Ada83; |
a9d38797 | 10039 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10040 | language = DW_LANG_Fortran77; |
bc28c45b | 10041 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10042 | language = DW_LANG_Pascal83; |
28985b81 AG |
10043 | else if (strcmp (language_string, "GNU Java") == 0) |
10044 | language = DW_LANG_Java; | |
a3f97cbb | 10045 | else if (flag_traditional) |
a96c67ec | 10046 | language = DW_LANG_C; |
a3f97cbb | 10047 | else |
a96c67ec | 10048 | language = DW_LANG_C89; |
a9d38797 | 10049 | |
a96c67ec JM |
10050 | add_AT_unsigned (die, DW_AT_language, language); |
10051 | ||
10052 | return die; | |
a3f97cbb JW |
10053 | } |
10054 | ||
10055 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10056 | |
a3f97cbb JW |
10057 | static void |
10058 | gen_string_type_die (type, context_die) | |
10059 | register tree type; | |
10060 | register dw_die_ref context_die; | |
10061 | { | |
71dfc51f RK |
10062 | register dw_die_ref type_die |
10063 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
10064 | ||
bdb669cb | 10065 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10066 | |
10067 | /* Fudge the string length attribute for now. */ | |
556273e0 | 10068 | |
a3f97cbb | 10069 | /* TODO: add string length info. |
71dfc51f | 10070 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
10071 | bound_representation (upper_bound, 0, 'u'); */ |
10072 | } | |
10073 | ||
61b32c02 | 10074 | /* Generate the DIE for a base class. */ |
71dfc51f | 10075 | |
61b32c02 JM |
10076 | static void |
10077 | gen_inheritance_die (binfo, context_die) | |
10078 | register tree binfo; | |
10079 | register dw_die_ref context_die; | |
10080 | { | |
10081 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 10082 | |
61b32c02 JM |
10083 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10084 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10085 | |
61b32c02 JM |
10086 | if (TREE_VIA_VIRTUAL (binfo)) |
10087 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
10088 | if (TREE_VIA_PUBLIC (binfo)) | |
10089 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10090 | else if (TREE_VIA_PROTECTED (binfo)) | |
10091 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10092 | } | |
10093 | ||
956d6950 | 10094 | /* Generate a DIE for a class member. */ |
71dfc51f | 10095 | |
a3f97cbb JW |
10096 | static void |
10097 | gen_member_die (type, context_die) | |
10098 | register tree type; | |
10099 | register dw_die_ref context_die; | |
10100 | { | |
61b32c02 | 10101 | register tree member; |
10a11b75 | 10102 | dw_die_ref child; |
71dfc51f | 10103 | |
a3f97cbb JW |
10104 | /* If this is not an incomplete type, output descriptions of each of its |
10105 | members. Note that as we output the DIEs necessary to represent the | |
10106 | members of this record or union type, we will also be trying to output | |
10107 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 KH |
10108 | function (above) will specifically avoid generating type DIEs for member |
10109 | types *within* the list of member DIEs for this (containing) type execpt | |
a3f97cbb JW |
10110 | for those types (of members) which are explicitly marked as also being |
10111 | members of this (containing) type themselves. The g++ front- end can | |
10112 | force any given type to be treated as a member of some other | |
556273e0 | 10113 | (containing) type by setting the TYPE_CONTEXT of the given (member) type |
a3f97cbb JW |
10114 | to point to the TREE node representing the appropriate (containing) |
10115 | type. */ | |
10116 | ||
61b32c02 JM |
10117 | /* First output info about the base classes. */ |
10118 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10119 | { |
61b32c02 JM |
10120 | register tree bases = TYPE_BINFO_BASETYPES (type); |
10121 | register int n_bases = TREE_VEC_LENGTH (bases); | |
10122 | register int i; | |
10123 | ||
10124 | for (i = 0; i < n_bases; i++) | |
10125 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10126 | } |
10127 | ||
61b32c02 JM |
10128 | /* Now output info about the data members and type members. */ |
10129 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10130 | { |
10131 | /* If we thought we were generating minimal debug info for TYPE | |
10132 | and then changed our minds, some of the member declarations | |
10133 | may have already been defined. Don't define them again, but | |
10134 | do put them in the right order. */ | |
10135 | ||
10136 | child = lookup_decl_die (member); | |
10137 | if (child) | |
10138 | splice_child_die (context_die, child); | |
10139 | else | |
10140 | gen_decl_die (member, context_die); | |
10141 | } | |
61b32c02 | 10142 | |
a3f97cbb | 10143 | /* Now output info about the function members (if any). */ |
61b32c02 | 10144 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 JM |
10145 | { |
10146 | child = lookup_decl_die (member); | |
10147 | if (child) | |
10148 | splice_child_die (context_die, child); | |
10149 | else | |
10150 | gen_decl_die (member, context_die); | |
10151 | } | |
a3f97cbb JW |
10152 | } |
10153 | ||
10a11b75 JM |
10154 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10155 | is set, we pretend that the type was never defined, so we only get the | |
10156 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10157 | |
a3f97cbb | 10158 | static void |
273dbe67 | 10159 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 10160 | register tree type; |
a3f97cbb JW |
10161 | register dw_die_ref context_die; |
10162 | { | |
273dbe67 | 10163 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
10164 | register dw_die_ref scope_die = 0; |
10165 | register int nested = 0; | |
10a11b75 | 10166 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10167 | && (! TYPE_STUB_DECL (type) |
10168 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10169 | |
10a11b75 | 10170 | if (type_die && ! complete) |
273dbe67 | 10171 | return; |
a082c85a | 10172 | |
71dfc51f | 10173 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10174 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10175 | nested = 1; |
10176 | ||
a94dbf2c | 10177 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10178 | |
10179 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10180 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10181 | { |
273dbe67 | 10182 | register dw_die_ref old_die = type_die; |
71dfc51f | 10183 | |
a3f97cbb JW |
10184 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10185 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 10186 | scope_die); |
a3f97cbb | 10187 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10188 | if (old_die) |
10189 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10190 | else |
10191 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10192 | } |
4b674448 | 10193 | else |
273dbe67 | 10194 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10195 | |
10196 | /* If this type has been completed, then give it a byte_size attribute and | |
10197 | then give a list of members. */ | |
2081603c | 10198 | if (complete) |
a3f97cbb | 10199 | { |
556273e0 | 10200 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10201 | this type is expressed in terms of this type itself. */ |
10202 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10203 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10204 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10205 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10206 | |
ef76d03b JW |
10207 | /* If the first reference to this type was as the return type of an |
10208 | inline function, then it may not have a parent. Fix this now. */ | |
10209 | if (type_die->die_parent == NULL) | |
10210 | add_child_die (scope_die, type_die); | |
10211 | ||
273dbe67 JM |
10212 | push_decl_scope (type); |
10213 | gen_member_die (type, type_die); | |
10214 | pop_decl_scope (); | |
71dfc51f | 10215 | |
a94dbf2c JM |
10216 | /* GNU extension: Record what type our vtable lives in. */ |
10217 | if (TYPE_VFIELD (type)) | |
10218 | { | |
10219 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10220 | |
de6e505e JM |
10221 | gen_type_die (vtype, context_die); |
10222 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10223 | lookup_type_die (vtype)); | |
a94dbf2c | 10224 | } |
a3f97cbb | 10225 | } |
4b674448 | 10226 | else |
8a8c3656 JM |
10227 | { |
10228 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10229 | |
9765e357 | 10230 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 10231 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 10232 | add_incomplete_type (type); |
8a8c3656 | 10233 | } |
a3f97cbb JW |
10234 | } |
10235 | ||
10236 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10237 | |
a3f97cbb JW |
10238 | static void |
10239 | gen_subroutine_type_die (type, context_die) | |
10240 | register tree type; | |
10241 | register dw_die_ref context_die; | |
10242 | { | |
10243 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
10244 | register dw_die_ref subr_die |
10245 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
10246 | ||
a3f97cbb JW |
10247 | equate_type_number_to_die (type, subr_die); |
10248 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10249 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10250 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10251 | } |
10252 | ||
10253 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10254 | |
a3f97cbb JW |
10255 | static void |
10256 | gen_typedef_die (decl, context_die) | |
10257 | register tree decl; | |
10258 | register dw_die_ref context_die; | |
10259 | { | |
a3f97cbb | 10260 | register dw_die_ref type_die; |
a94dbf2c JM |
10261 | register tree origin; |
10262 | ||
10263 | if (TREE_ASM_WRITTEN (decl)) | |
10264 | return; | |
10265 | TREE_ASM_WRITTEN (decl) = 1; | |
10266 | ||
777ad4c2 | 10267 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 10268 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10269 | if (origin != NULL) |
a94dbf2c | 10270 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10271 | else |
10272 | { | |
a94dbf2c | 10273 | register tree type; |
a3f97cbb | 10274 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10275 | if (DECL_ORIGINAL_TYPE (decl)) |
10276 | { | |
10277 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10278 | |
10279 | if (type == TREE_TYPE (decl)) | |
10280 | abort (); | |
10281 | else | |
10282 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10283 | } |
10284 | else | |
10285 | type = TREE_TYPE (decl); | |
10286 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
10287 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10288 | } |
71dfc51f | 10289 | |
a3f97cbb | 10290 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10291 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10292 | } |
10293 | ||
10294 | /* Generate a type description DIE. */ | |
71dfc51f | 10295 | |
a3f97cbb JW |
10296 | static void |
10297 | gen_type_die (type, context_die) | |
10298 | register tree type; | |
10299 | register dw_die_ref context_die; | |
10300 | { | |
348bb3c7 JM |
10301 | int need_pop; |
10302 | ||
71dfc51f RK |
10303 | if (type == NULL_TREE || type == error_mark_node) |
10304 | return; | |
a3f97cbb | 10305 | |
38e01259 | 10306 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10307 | this type (i.e. without any const or volatile qualifiers) so get the |
10308 | main variant (i.e. the unqualified version) of this type now. */ | |
10309 | type = type_main_variant (type); | |
10310 | ||
10311 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10312 | return; |
a3f97cbb | 10313 | |
a94dbf2c JM |
10314 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10315 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10316 | { |
a94dbf2c JM |
10317 | TREE_ASM_WRITTEN (type) = 1; |
10318 | gen_decl_die (TYPE_NAME (type), context_die); | |
10319 | return; | |
10320 | } | |
10321 | ||
a3f97cbb JW |
10322 | switch (TREE_CODE (type)) |
10323 | { | |
10324 | case ERROR_MARK: | |
10325 | break; | |
10326 | ||
10327 | case POINTER_TYPE: | |
10328 | case REFERENCE_TYPE: | |
956d6950 JL |
10329 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10330 | ensures that the gen_type_die recursion will terminate even if the | |
10331 | type is recursive. Recursive types are possible in Ada. */ | |
10332 | /* ??? We could perhaps do this for all types before the switch | |
10333 | statement. */ | |
10334 | TREE_ASM_WRITTEN (type) = 1; | |
10335 | ||
a3f97cbb JW |
10336 | /* For these types, all that is required is that we output a DIE (or a |
10337 | set of DIEs) to represent the "basis" type. */ | |
10338 | gen_type_die (TREE_TYPE (type), context_die); | |
10339 | break; | |
10340 | ||
10341 | case OFFSET_TYPE: | |
556273e0 | 10342 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10343 | Output a description of the relevant class type. */ |
a3f97cbb | 10344 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10345 | |
a3f97cbb JW |
10346 | /* Output a description of the type of the object pointed to. */ |
10347 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10348 | |
a3f97cbb JW |
10349 | /* Now output a DIE to represent this pointer-to-data-member type |
10350 | itself. */ | |
10351 | gen_ptr_to_mbr_type_die (type, context_die); | |
10352 | break; | |
10353 | ||
10354 | case SET_TYPE: | |
10355 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10356 | gen_set_type_die (type, context_die); | |
10357 | break; | |
10358 | ||
10359 | case FILE_TYPE: | |
10360 | gen_type_die (TREE_TYPE (type), context_die); | |
10361 | abort (); /* No way to represent these in Dwarf yet! */ | |
10362 | break; | |
10363 | ||
10364 | case FUNCTION_TYPE: | |
10365 | /* Force out return type (in case it wasn't forced out already). */ | |
10366 | gen_type_die (TREE_TYPE (type), context_die); | |
10367 | gen_subroutine_type_die (type, context_die); | |
10368 | break; | |
10369 | ||
10370 | case METHOD_TYPE: | |
10371 | /* Force out return type (in case it wasn't forced out already). */ | |
10372 | gen_type_die (TREE_TYPE (type), context_die); | |
10373 | gen_subroutine_type_die (type, context_die); | |
10374 | break; | |
10375 | ||
10376 | case ARRAY_TYPE: | |
10377 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
10378 | { | |
10379 | gen_type_die (TREE_TYPE (type), context_die); | |
10380 | gen_string_type_die (type, context_die); | |
10381 | } | |
10382 | else | |
71dfc51f | 10383 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
10384 | break; |
10385 | ||
4061f623 BS |
10386 | case VECTOR_TYPE: |
10387 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
10388 | break; | |
10389 | ||
a3f97cbb JW |
10390 | case ENUMERAL_TYPE: |
10391 | case RECORD_TYPE: | |
10392 | case UNION_TYPE: | |
10393 | case QUAL_UNION_TYPE: | |
a082c85a | 10394 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
10395 | written out yet, writing it out will cover this one, too. |
10396 | This does not apply to instantiations of member class templates; | |
10397 | they need to be added to the containing class as they are | |
777ad4c2 | 10398 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
10399 | from multiple TUs, since we can't predict what set of template |
10400 | instantiations we'll get. */ | |
a082c85a | 10401 | if (TYPE_CONTEXT (type) |
5f2f160c | 10402 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 10403 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
10404 | { |
10405 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
10406 | ||
348bb3c7 | 10407 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
10408 | return; |
10409 | ||
10410 | /* If that failed, attach ourselves to the stub. */ | |
10411 | push_decl_scope (TYPE_CONTEXT (type)); | |
10412 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 10413 | need_pop = 1; |
a94dbf2c | 10414 | } |
348bb3c7 JM |
10415 | else |
10416 | need_pop = 0; | |
a94dbf2c JM |
10417 | |
10418 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 10419 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 10420 | else |
273dbe67 | 10421 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 10422 | |
348bb3c7 | 10423 | if (need_pop) |
a94dbf2c JM |
10424 | pop_decl_scope (); |
10425 | ||
4b674448 | 10426 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
10427 | it up if it is ever completed. gen_*_type_die will set it for us |
10428 | when appropriate. */ | |
10429 | return; | |
a3f97cbb JW |
10430 | |
10431 | case VOID_TYPE: | |
10432 | case INTEGER_TYPE: | |
10433 | case REAL_TYPE: | |
10434 | case COMPLEX_TYPE: | |
10435 | case BOOLEAN_TYPE: | |
10436 | case CHAR_TYPE: | |
10437 | /* No DIEs needed for fundamental types. */ | |
10438 | break; | |
10439 | ||
10440 | case LANG_TYPE: | |
10441 | /* No Dwarf representation currently defined. */ | |
10442 | break; | |
10443 | ||
10444 | default: | |
10445 | abort (); | |
10446 | } | |
10447 | ||
10448 | TREE_ASM_WRITTEN (type) = 1; | |
10449 | } | |
10450 | ||
10451 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 10452 | |
a3f97cbb JW |
10453 | static void |
10454 | gen_tagged_type_instantiation_die (type, context_die) | |
10455 | register tree type; | |
10456 | register dw_die_ref context_die; | |
10457 | { | |
71dfc51f RK |
10458 | if (type == NULL_TREE || type == error_mark_node) |
10459 | return; | |
a3f97cbb | 10460 | |
38e01259 | 10461 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10462 | this type (i.e. without any const or volatile qualifiers) so make sure |
10463 | that we have the main variant (i.e. the unqualified version) of this | |
10464 | type now. */ | |
bbc6ae08 | 10465 | if (type != type_main_variant (type)) |
3a88cbd1 | 10466 | abort (); |
a3f97cbb | 10467 | |
203588e7 | 10468 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 10469 | an instance of an unresolved type. */ |
556273e0 | 10470 | |
a3f97cbb JW |
10471 | switch (TREE_CODE (type)) |
10472 | { | |
10473 | case ERROR_MARK: | |
10474 | break; | |
10475 | ||
10476 | case ENUMERAL_TYPE: | |
10477 | gen_inlined_enumeration_type_die (type, context_die); | |
10478 | break; | |
10479 | ||
10480 | case RECORD_TYPE: | |
10481 | gen_inlined_structure_type_die (type, context_die); | |
10482 | break; | |
10483 | ||
10484 | case UNION_TYPE: | |
10485 | case QUAL_UNION_TYPE: | |
10486 | gen_inlined_union_type_die (type, context_die); | |
10487 | break; | |
10488 | ||
10489 | default: | |
71dfc51f | 10490 | abort (); |
a3f97cbb JW |
10491 | } |
10492 | } | |
10493 | ||
10494 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
10495 | things which are local to the given block. */ | |
71dfc51f | 10496 | |
a3f97cbb | 10497 | static void |
d7248bff | 10498 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10499 | register tree stmt; |
10500 | register dw_die_ref context_die; | |
d7248bff | 10501 | int depth; |
a3f97cbb JW |
10502 | { |
10503 | register int must_output_die = 0; | |
10504 | register tree origin; | |
10505 | register tree decl; | |
10506 | register enum tree_code origin_code; | |
10507 | ||
10508 | /* Ignore blocks never really used to make RTL. */ | |
10509 | ||
1e7f092a JM |
10510 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
10511 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 10512 | return; |
a3f97cbb JW |
10513 | |
10514 | /* Determine the "ultimate origin" of this block. This block may be an | |
10515 | inlined instance of an inlined instance of inline function, so we have | |
10516 | to trace all of the way back through the origin chain to find out what | |
10517 | sort of node actually served as the original seed for the creation of | |
10518 | the current block. */ | |
10519 | origin = block_ultimate_origin (stmt); | |
10520 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
10521 | ||
10522 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
10523 | block. */ | |
10524 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
10525 | /* The outer scopes for inlinings *must* always be represented. We |
10526 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
10527 | must_output_die = 1; | |
a3f97cbb JW |
10528 | else |
10529 | { | |
10530 | /* In the case where the current block represents an inlining of the | |
556273e0 | 10531 | "body block" of an inline function, we must *NOT* output any DIE for |
a3f97cbb JW |
10532 | this block because we have already output a DIE to represent the |
10533 | whole inlined function scope and the "body block" of any function | |
10534 | doesn't really represent a different scope according to ANSI C | |
10535 | rules. So we check here to make sure that this block does not | |
10536 | represent a "body block inlining" before trying to set the | |
10537 | `must_output_die' flag. */ | |
d7248bff | 10538 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
10539 | { |
10540 | /* Determine if this block directly contains any "significant" | |
10541 | local declarations which we will need to output DIEs for. */ | |
10542 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
10543 | /* We are not in terse mode so *any* local declaration counts |
10544 | as being a "significant" one. */ | |
10545 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 10546 | else |
71dfc51f RK |
10547 | /* We are in terse mode, so only local (nested) function |
10548 | definitions count as "significant" local declarations. */ | |
10549 | for (decl = BLOCK_VARS (stmt); | |
10550 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10551 | if (TREE_CODE (decl) == FUNCTION_DECL | |
10552 | && DECL_INITIAL (decl)) | |
a3f97cbb | 10553 | { |
71dfc51f RK |
10554 | must_output_die = 1; |
10555 | break; | |
a3f97cbb | 10556 | } |
a3f97cbb JW |
10557 | } |
10558 | } | |
10559 | ||
10560 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
10561 | DIE for any block which contains no significant local declarations at | |
10562 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
10563 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
10564 | that in terse mode, our definition of what constitutes a "significant" | |
10565 | local declaration gets restricted to include only inlined function | |
10566 | instances and local (nested) function definitions. */ | |
10567 | if (must_output_die) | |
10568 | { | |
10569 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 10570 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 10571 | else |
71dfc51f | 10572 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
10573 | } |
10574 | else | |
d7248bff | 10575 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
10576 | } |
10577 | ||
10578 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 10579 | all of its sub-blocks. */ |
71dfc51f | 10580 | |
a3f97cbb | 10581 | static void |
d7248bff | 10582 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
10583 | register tree stmt; |
10584 | register dw_die_ref context_die; | |
d7248bff | 10585 | int depth; |
a3f97cbb JW |
10586 | { |
10587 | register tree decl; | |
10588 | register tree subblocks; | |
71dfc51f | 10589 | |
a3f97cbb | 10590 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
10591 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
10592 | return; | |
10593 | ||
88dad228 JM |
10594 | /* Output the DIEs to represent all of the data objects and typedefs |
10595 | declared directly within this block but not within any nested | |
10596 | sub-blocks. Also, nested function and tag DIEs have been | |
10597 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
10598 | for (decl = BLOCK_VARS (stmt); |
10599 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10600 | { | |
a94dbf2c JM |
10601 | register dw_die_ref die; |
10602 | ||
88dad228 | 10603 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 10604 | die = lookup_decl_die (decl); |
88dad228 | 10605 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
10606 | die = lookup_type_die (TREE_TYPE (decl)); |
10607 | else | |
10608 | die = NULL; | |
10609 | ||
71dfc51f | 10610 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 10611 | add_child_die (context_die, die); |
88dad228 JM |
10612 | else |
10613 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
10614 | } |
10615 | ||
10616 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
10617 | therein) of this block. */ | |
10618 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
10619 | subblocks != NULL; | |
10620 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 10621 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
10622 | } |
10623 | ||
a94dbf2c | 10624 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
10625 | |
10626 | static inline int | |
a94dbf2c JM |
10627 | is_redundant_typedef (decl) |
10628 | register tree decl; | |
10629 | { | |
10630 | if (TYPE_DECL_IS_STUB (decl)) | |
10631 | return 1; | |
71dfc51f | 10632 | |
a94dbf2c JM |
10633 | if (DECL_ARTIFICIAL (decl) |
10634 | && DECL_CONTEXT (decl) | |
10635 | && is_tagged_type (DECL_CONTEXT (decl)) | |
10636 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
10637 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
10638 | /* Also ignore the artificial member typedef for the class name. */ | |
10639 | return 1; | |
71dfc51f | 10640 | |
a94dbf2c JM |
10641 | return 0; |
10642 | } | |
10643 | ||
a3f97cbb | 10644 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 10645 | |
a3f97cbb JW |
10646 | static void |
10647 | gen_decl_die (decl, context_die) | |
10648 | register tree decl; | |
10649 | register dw_die_ref context_die; | |
10650 | { | |
10651 | register tree origin; | |
71dfc51f | 10652 | |
a3f97cbb | 10653 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 10654 | return; |
a3f97cbb | 10655 | |
fcd7f76b JM |
10656 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
10657 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 10658 | return; |
a3f97cbb | 10659 | |
a3f97cbb JW |
10660 | switch (TREE_CODE (decl)) |
10661 | { | |
10662 | case CONST_DECL: | |
556273e0 | 10663 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
10664 | the Dwarf representation of the relevant enum type itself. */ |
10665 | break; | |
10666 | ||
10667 | case FUNCTION_DECL: | |
4edb7b60 JM |
10668 | /* Don't output any DIEs to represent mere function declarations, |
10669 | unless they are class members or explicit block externs. */ | |
10670 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 10671 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 10672 | break; |
bdb669cb | 10673 | |
1cfdcc15 JM |
10674 | /* If we're emitting an out-of-line copy of an inline function, |
10675 | emit info for the abstract instance and set up to refer to it. */ | |
10676 | if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) | |
fb41a106 JW |
10677 | && ! class_scope_p (context_die) |
10678 | /* gen_abstract_function won't emit a die if this is just a | |
10679 | declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
10680 | that case, because that works only if we have a die. */ | |
10681 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 JM |
10682 | { |
10683 | gen_abstract_function (decl); | |
10684 | set_decl_origin_self (decl); | |
10685 | } | |
10a11b75 | 10686 | |
4927276d | 10687 | if (debug_info_level > DINFO_LEVEL_TERSE) |
a94dbf2c JM |
10688 | { |
10689 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
10690 | have described its return type. */ | |
10691 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
10692 | ||
2081603c JM |
10693 | /* And its virtual context. */ |
10694 | if (DECL_VINDEX (decl) != NULL_TREE) | |
10695 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
10696 | ||
a94dbf2c JM |
10697 | /* And its containing type. */ |
10698 | origin = decl_class_context (decl); | |
71dfc51f | 10699 | if (origin != NULL_TREE) |
10a11b75 | 10700 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10701 | } |
a3f97cbb JW |
10702 | |
10703 | /* Now output a DIE to represent the function itself. */ | |
10704 | gen_subprogram_die (decl, context_die); | |
10705 | break; | |
10706 | ||
10707 | case TYPE_DECL: | |
10708 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 10709 | actual typedefs. */ |
a3f97cbb | 10710 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 10711 | break; |
a3f97cbb | 10712 | |
556273e0 | 10713 | /* In the special case of a TYPE_DECL node representing the |
5c90448c | 10714 | declaration of some type tag, if the given TYPE_DECL is marked as |
a3f97cbb JW |
10715 | having been instantiated from some other (original) TYPE_DECL node |
10716 | (e.g. one which was generated within the original definition of an | |
10717 | inline function) we have to generate a special (abbreviated) | |
556273e0 | 10718 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 10719 | DIE here. */ |
2081603c | 10720 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
10721 | { |
10722 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
10723 | break; | |
10724 | } | |
a3f97cbb | 10725 | |
a94dbf2c JM |
10726 | if (is_redundant_typedef (decl)) |
10727 | gen_type_die (TREE_TYPE (decl), context_die); | |
10728 | else | |
71dfc51f RK |
10729 | /* Output a DIE to represent the typedef itself. */ |
10730 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
10731 | break; |
10732 | ||
10733 | case LABEL_DECL: | |
10734 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 10735 | gen_label_die (decl, context_die); |
a3f97cbb JW |
10736 | break; |
10737 | ||
10738 | case VAR_DECL: | |
10739 | /* If we are in terse mode, don't generate any DIEs to represent any | |
10740 | variable declarations or definitions. */ | |
10741 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 10742 | break; |
a3f97cbb JW |
10743 | |
10744 | /* Output any DIEs that are needed to specify the type of this data | |
10745 | object. */ | |
10746 | gen_type_die (TREE_TYPE (decl), context_die); | |
10747 | ||
a94dbf2c JM |
10748 | /* And its containing type. */ |
10749 | origin = decl_class_context (decl); | |
71dfc51f | 10750 | if (origin != NULL_TREE) |
10a11b75 | 10751 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10752 | |
a3f97cbb JW |
10753 | /* Now output the DIE to represent the data object itself. This gets |
10754 | complicated because of the possibility that the VAR_DECL really | |
10755 | represents an inlined instance of a formal parameter for an inline | |
10756 | function. */ | |
10757 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
10758 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
10759 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 10760 | else |
71dfc51f | 10761 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
10762 | break; |
10763 | ||
10764 | case FIELD_DECL: | |
a94dbf2c JM |
10765 | /* Ignore the nameless fields that are used to skip bits, but |
10766 | handle C++ anonymous unions. */ | |
71dfc51f RK |
10767 | if (DECL_NAME (decl) != NULL_TREE |
10768 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
10769 | { |
10770 | gen_type_die (member_declared_type (decl), context_die); | |
10771 | gen_field_die (decl, context_die); | |
10772 | } | |
10773 | break; | |
10774 | ||
10775 | case PARM_DECL: | |
10776 | gen_type_die (TREE_TYPE (decl), context_die); | |
10777 | gen_formal_parameter_die (decl, context_die); | |
10778 | break; | |
10779 | ||
348bb3c7 JM |
10780 | case NAMESPACE_DECL: |
10781 | /* Ignore for now. */ | |
10782 | break; | |
10783 | ||
a3f97cbb JW |
10784 | default: |
10785 | abort (); | |
10786 | } | |
a3f97cbb JW |
10787 | } |
10788 | \f | |
14a774a9 RK |
10789 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
10790 | ||
10791 | void | |
10792 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
10793 | const char *filename; |
10794 | const char *context_list; | |
14a774a9 RK |
10795 | { |
10796 | unsigned int file_index; | |
10797 | ||
10798 | if (filename != NULL) | |
10799 | { | |
10800 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
556273e0 | 10801 | tree context_list_decl |
14a774a9 RK |
10802 | = build_decl (LABEL_DECL, get_identifier (context_list), |
10803 | void_type_node); | |
10804 | ||
10805 | TREE_PUBLIC (context_list_decl) = TRUE; | |
10806 | add_name_attribute (unit_die, context_list); | |
10807 | file_index = lookup_filename (filename); | |
10808 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); | |
10809 | add_pubname (context_list_decl, unit_die); | |
10810 | } | |
10811 | } | |
10812 | ||
71dfc51f RK |
10813 | /* Write the debugging output for DECL. */ |
10814 | ||
a3f97cbb | 10815 | void |
88dad228 | 10816 | dwarf2out_decl (decl) |
a3f97cbb | 10817 | register tree decl; |
a3f97cbb | 10818 | { |
88dad228 JM |
10819 | register dw_die_ref context_die = comp_unit_die; |
10820 | ||
a3f97cbb | 10821 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 10822 | return; |
a3f97cbb | 10823 | |
fcd7f76b | 10824 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 10825 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 10826 | return; |
a3f97cbb JW |
10827 | |
10828 | switch (TREE_CODE (decl)) | |
10829 | { | |
10830 | case FUNCTION_DECL: | |
556273e0 | 10831 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
10832 | builtin function. Explicit programmer-supplied declarations of |
10833 | these same functions should NOT be ignored however. */ | |
9765e357 | 10834 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 10835 | return; |
a3f97cbb JW |
10836 | |
10837 | /* What we would really like to do here is to filter out all mere | |
10838 | file-scope declarations of file-scope functions which are never | |
10839 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
10840 | that *are* referenced later on) but we aren't clairvoyant, so we have |
10841 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 10842 | on within the current translation unit). So here we just ignore all |
556273e0 | 10843 | file-scope function declarations which are not also definitions. If |
956d6950 | 10844 | and when the debugger needs to know something about these functions, |
556273e0 | 10845 | it will have to hunt around and find the DWARF information associated |
bbc6ae08 | 10846 | with the definition of the function. Note that we can't just check |
a3f97cbb JW |
10847 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
10848 | definitions and which ones represent mere declarations. We have to | |
10849 | check `DECL_INITIAL' instead. That's because the C front-end | |
10850 | supports some weird semantics for "extern inline" function | |
10851 | definitions. These can get inlined within the current translation | |
10852 | unit (an thus, we need to generate DWARF info for their abstract | |
10853 | instances so that the DWARF info for the concrete inlined instances | |
556273e0 | 10854 | can have something to refer to) but the compiler never generates any |
a3f97cbb JW |
10855 | out-of-lines instances of such things (despite the fact that they |
10856 | *are* definitions). The important point is that the C front-end | |
10857 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 10858 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb | 10859 | plays some similar games for inline function definitions appearing |
556273e0 | 10860 | within include files which also contain |
a3f97cbb JW |
10861 | `#pragma interface' pragmas. */ |
10862 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 10863 | return; |
88dad228 | 10864 | |
9c6cd30e JM |
10865 | /* If we're a nested function, initially use a parent of NULL; if we're |
10866 | a plain function, this will be fixed up in decls_for_scope. If | |
10867 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 10868 | if (decl_function_context (decl)) |
9c6cd30e | 10869 | context_die = NULL; |
88dad228 | 10870 | |
a3f97cbb JW |
10871 | break; |
10872 | ||
10873 | case VAR_DECL: | |
556273e0 | 10874 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
10875 | declaration and if the declaration was never even referenced from |
10876 | within this entire compilation unit. We suppress these DIEs in | |
10877 | order to save space in the .debug section (by eliminating entries | |
10878 | which are probably useless). Note that we must not suppress | |
10879 | block-local extern declarations (whether used or not) because that | |
10880 | would screw-up the debugger's name lookup mechanism and cause it to | |
10881 | miss things which really ought to be in scope at a given point. */ | |
10882 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 10883 | return; |
a3f97cbb JW |
10884 | |
10885 | /* If we are in terse mode, don't generate any DIEs to represent any | |
10886 | variable declarations or definitions. */ | |
10887 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 10888 | return; |
a3f97cbb JW |
10889 | break; |
10890 | ||
10891 | case TYPE_DECL: | |
57fb7689 JM |
10892 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
10893 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
10894 | return; | |
10895 | ||
a3f97cbb | 10896 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
10897 | normal built-in types for the language we are compiling. */ |
10898 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
10899 | { |
10900 | /* OK, we need to generate one for `bool' so GDB knows what type | |
10901 | comparisons have. */ | |
10902 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
10903 | == DW_LANG_C_plus_plus) | |
10904 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
10905 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 10906 | |
a94dbf2c JM |
10907 | return; |
10908 | } | |
a3f97cbb | 10909 | |
88dad228 | 10910 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 10911 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 10912 | return; |
88dad228 JM |
10913 | |
10914 | /* If we're a function-scope tag, initially use a parent of NULL; | |
10915 | this will be fixed up in decls_for_scope. */ | |
10916 | if (decl_function_context (decl)) | |
3f76745e | 10917 | context_die = NULL; |
88dad228 | 10918 | |
a3f97cbb JW |
10919 | break; |
10920 | ||
10921 | default: | |
10922 | return; | |
10923 | } | |
10924 | ||
88dad228 | 10925 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
10926 | } |
10927 | ||
10928 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
10929 | a lexical block. */ | |
71dfc51f | 10930 | |
a3f97cbb | 10931 | void |
9a666dda | 10932 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
10933 | register unsigned blocknum; |
10934 | { | |
a3f97cbb | 10935 | function_section (current_function_decl); |
8215347e | 10936 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
10937 | } |
10938 | ||
10939 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
10940 | lexical block. */ | |
71dfc51f | 10941 | |
a3f97cbb | 10942 | void |
9a666dda | 10943 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
10944 | register unsigned blocknum; |
10945 | { | |
a3f97cbb | 10946 | function_section (current_function_decl); |
8215347e | 10947 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
10948 | } |
10949 | ||
64b59a80 JM |
10950 | /* Returns nonzero if it is appropriate not to emit any debugging |
10951 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 10952 | |
64b59a80 JM |
10953 | Don't allow this for blocks with nested functions or local classes |
10954 | as we would end up with orphans, and in the presence of scheduling | |
10955 | we may end up calling them anyway. */ | |
10956 | ||
10957 | int | |
fcd7f76b JM |
10958 | dwarf2out_ignore_block (block) |
10959 | tree block; | |
10960 | { | |
10961 | tree decl; | |
10962 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
64b59a80 JM |
10963 | if (TREE_CODE (decl) == FUNCTION_DECL |
10964 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
10965 | return 0; | |
10966 | return 1; | |
fcd7f76b JM |
10967 | } |
10968 | ||
a3f97cbb JW |
10969 | /* Output a marker (i.e. a label) at a point in the assembly code which |
10970 | corresponds to a given source level label. */ | |
71dfc51f | 10971 | |
a3f97cbb | 10972 | void |
9a666dda | 10973 | dwarf2out_label (insn) |
a3f97cbb JW |
10974 | register rtx insn; |
10975 | { | |
10976 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 10977 | |
a3f97cbb JW |
10978 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
10979 | { | |
10980 | function_section (current_function_decl); | |
5c90448c | 10981 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number); |
8215347e | 10982 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, label, |
5c90448c | 10983 | (unsigned) INSN_UID (insn)); |
a3f97cbb JW |
10984 | } |
10985 | } | |
10986 | ||
a3f97cbb | 10987 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 10988 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
10989 | just a unique number which is associated with only that one filename. |
10990 | We need such numbers for the sake of generating labels | |
10991 | (in the .debug_sfnames section) and references to those | |
10992 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
10993 | If the filename given as an argument is not found in our current list, | |
10994 | add it to the list and assign it the next available unique index number. | |
10995 | In order to speed up searches, we remember the index of the filename | |
10996 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 10997 | |
a3f97cbb JW |
10998 | static unsigned |
10999 | lookup_filename (file_name) | |
d560ee52 | 11000 | const char *file_name; |
a3f97cbb JW |
11001 | { |
11002 | static unsigned last_file_lookup_index = 0; | |
a3f97cbb JW |
11003 | register unsigned i; |
11004 | ||
11005 | /* Check to see if the file name that was searched on the previous call | |
11006 | matches this file name. If so, return the index. */ | |
11007 | if (last_file_lookup_index != 0) | |
71dfc51f RK |
11008 | if (strcmp (file_name, file_table[last_file_lookup_index]) == 0) |
11009 | return last_file_lookup_index; | |
a3f97cbb JW |
11010 | |
11011 | /* Didn't match the previous lookup, search the table */ | |
11012 | for (i = 1; i < file_table_in_use; ++i) | |
71dfc51f RK |
11013 | if (strcmp (file_name, file_table[i]) == 0) |
11014 | { | |
11015 | last_file_lookup_index = i; | |
11016 | return i; | |
11017 | } | |
a3f97cbb | 11018 | |
556273e0 | 11019 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb JW |
11020 | the table to do so. If not, expand the current table. */ |
11021 | if (file_table_in_use == file_table_allocated) | |
11022 | { | |
11023 | file_table_allocated += FILE_TABLE_INCREMENT; | |
11024 | file_table | |
71dfc51f RK |
11025 | = (char **) xrealloc (file_table, |
11026 | file_table_allocated * sizeof (char *)); | |
a3f97cbb JW |
11027 | } |
11028 | ||
71dfc51f | 11029 | /* Add the new entry to the end of the filename table. */ |
a3f97cbb JW |
11030 | file_table[file_table_in_use] = xstrdup (file_name); |
11031 | last_file_lookup_index = file_table_in_use++; | |
71dfc51f | 11032 | |
a3f97cbb JW |
11033 | return last_file_lookup_index; |
11034 | } | |
11035 | ||
11036 | /* Output a label to mark the beginning of a source code line entry | |
11037 | and record information relating to this source line, in | |
11038 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11039 | |
a3f97cbb | 11040 | void |
9a666dda | 11041 | dwarf2out_line (filename, line) |
d560ee52 | 11042 | register const char *filename; |
a3f97cbb JW |
11043 | register unsigned line; |
11044 | { | |
a3f97cbb JW |
11045 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11046 | { | |
11047 | function_section (current_function_decl); | |
a3f97cbb | 11048 | |
b2244e22 JW |
11049 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11050 | { | |
e2bef702 | 11051 | static const char *lastfile; |
b2244e22 JW |
11052 | |
11053 | /* Emit the .file and .loc directives understood by GNU as. */ | |
11054 | if (lastfile == 0 || strcmp (filename, lastfile)) | |
11055 | { | |
951a525f MM |
11056 | if (lastfile == 0) |
11057 | ggc_add_string_root ((char **) &lastfile, 1); | |
11058 | ||
b2244e22 JW |
11059 | fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename); |
11060 | lastfile = filename; | |
11061 | } | |
11062 | ||
11063 | fprintf (asm_out_file, "\t.loc 0 %d 0\n", line); | |
11064 | ||
11065 | /* Indicate that line number info exists. */ | |
11066 | ++line_info_table_in_use; | |
11067 | ||
11068 | /* Indicate that multiple line number tables exist. */ | |
11069 | if (DECL_SECTION_NAME (current_function_decl)) | |
11070 | ++separate_line_info_table_in_use; | |
11071 | } | |
11072 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11073 | { |
e90b62db | 11074 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
11075 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11076 | separate_line_info_table_in_use); | |
ac260b05 JM |
11077 | if (flag_debug_asm) |
11078 | fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line); | |
e90b62db JM |
11079 | fputc ('\n', asm_out_file); |
11080 | ||
11081 | /* expand the line info table if necessary */ | |
11082 | if (separate_line_info_table_in_use | |
11083 | == separate_line_info_table_allocated) | |
11084 | { | |
11085 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11086 | separate_line_info_table | |
71dfc51f RK |
11087 | = (dw_separate_line_info_ref) |
11088 | xrealloc (separate_line_info_table, | |
11089 | separate_line_info_table_allocated | |
11090 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11091 | } |
71dfc51f RK |
11092 | |
11093 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11094 | line_info |
11095 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
11096 | line_info->dw_file_num = lookup_filename (filename); | |
11097 | line_info->dw_line_num = line; | |
11098 | line_info->function = current_funcdef_number; | |
11099 | } | |
11100 | else | |
11101 | { | |
11102 | register dw_line_info_ref line_info; | |
71dfc51f | 11103 | |
5c90448c JM |
11104 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11105 | line_info_table_in_use); | |
ac260b05 JM |
11106 | if (flag_debug_asm) |
11107 | fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line); | |
e90b62db JM |
11108 | fputc ('\n', asm_out_file); |
11109 | ||
71dfc51f | 11110 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11111 | if (line_info_table_in_use == line_info_table_allocated) |
11112 | { | |
11113 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11114 | line_info_table | |
71dfc51f RK |
11115 | = (dw_line_info_ref) |
11116 | xrealloc (line_info_table, | |
11117 | (line_info_table_allocated | |
11118 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11119 | } |
71dfc51f RK |
11120 | |
11121 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11122 | line_info = &line_info_table[line_info_table_in_use++]; |
11123 | line_info->dw_file_num = lookup_filename (filename); | |
11124 | line_info->dw_line_num = line; | |
a3f97cbb | 11125 | } |
a3f97cbb JW |
11126 | } |
11127 | } | |
11128 | ||
11129 | /* Record the beginning of a new source file, for later output | |
11130 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 11131 | |
a3f97cbb | 11132 | void |
9a666dda | 11133 | dwarf2out_start_source_file (filename) |
d560ee52 | 11134 | register const char *filename ATTRIBUTE_UNUSED; |
a3f97cbb | 11135 | { |
881c6935 JM |
11136 | if (flag_eliminate_dwarf2_dups) |
11137 | { | |
11138 | /* Record the beginning of the file for break_out_includes. */ | |
11139 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die); | |
11140 | add_AT_string (bincl_die, DW_AT_name, filename); | |
11141 | } | |
a3f97cbb JW |
11142 | } |
11143 | ||
9a666dda | 11144 | /* Record the end of a source file, for later output |
a3f97cbb | 11145 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 11146 | |
a3f97cbb | 11147 | void |
9a666dda | 11148 | dwarf2out_end_source_file () |
a3f97cbb | 11149 | { |
881c6935 JM |
11150 | if (flag_eliminate_dwarf2_dups) |
11151 | { | |
11152 | /* Record the end of the file for break_out_includes. */ | |
11153 | new_die (DW_TAG_GNU_EINCL, comp_unit_die); | |
11154 | } | |
a3f97cbb JW |
11155 | } |
11156 | ||
11157 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
11158 | the tail part of the directive line, i.e. the part which is past the | |
11159 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11160 | |
a3f97cbb | 11161 | void |
9a666dda | 11162 | dwarf2out_define (lineno, buffer) |
2618f955 | 11163 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11164 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11165 | { |
11166 | static int initialized = 0; | |
11167 | if (!initialized) | |
11168 | { | |
9a666dda | 11169 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
11170 | initialized = 1; |
11171 | } | |
11172 | } | |
11173 | ||
11174 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
11175 | the tail part of the directive line, i.e. the part which is past the | |
11176 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11177 | |
a3f97cbb | 11178 | void |
9a666dda | 11179 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 11180 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11181 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11182 | { |
11183 | } | |
11184 | ||
11185 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11186 | |
a3f97cbb | 11187 | void |
9a666dda | 11188 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb | 11189 | register FILE *asm_out_file; |
d3e3972c | 11190 | register const char *main_input_filename; |
a3f97cbb | 11191 | { |
a3f97cbb JW |
11192 | /* Remember the name of the primary input file. */ |
11193 | primary_filename = main_input_filename; | |
11194 | ||
11195 | /* Allocate the initial hunk of the file_table. */ | |
3de90026 | 11196 | file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
a3f97cbb | 11197 | file_table_allocated = FILE_TABLE_INCREMENT; |
71dfc51f RK |
11198 | |
11199 | /* Skip the first entry - file numbers begin at 1. */ | |
a3f97cbb JW |
11200 | file_table_in_use = 1; |
11201 | ||
a3f97cbb JW |
11202 | /* Allocate the initial hunk of the decl_die_table. */ |
11203 | decl_die_table | |
3de90026 | 11204 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11205 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11206 | decl_die_table_in_use = 0; | |
11207 | ||
11208 | /* Allocate the initial hunk of the decl_scope_table. */ | |
11209 | decl_scope_table | |
777ad4c2 | 11210 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
11211 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
11212 | decl_scope_depth = 0; | |
11213 | ||
11214 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11215 | abbrev_die_table | |
3de90026 RH |
11216 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11217 | sizeof (dw_die_ref)); | |
a3f97cbb | 11218 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11219 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11220 | abbrev_die_table_in_use = 1; |
11221 | ||
11222 | /* Allocate the initial hunk of the line_info_table. */ | |
11223 | line_info_table | |
3de90026 RH |
11224 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11225 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11226 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 11227 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11228 | line_info_table_in_use = 1; |
11229 | ||
556273e0 | 11230 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11231 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11232 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11233 | taken as being relative to the directory from which the compiler was |
11234 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11235 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11236 | |
1f8f4a0b MM |
11237 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11238 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11239 | |
5c90448c | 11240 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
8b790721 | 11241 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0); |
b366352b MM |
11242 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11243 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11244 | else | |
11245 | strcpy (text_section_label, stripattributes (TEXT_SECTION)); | |
556273e0 | 11246 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11247 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11248 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 JM |
11249 | DEBUG_LINE_SECTION_LABEL, 0); |
11250 | ||
11251 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
11252 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); | |
b366352b | 11253 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
a96c67ec JM |
11254 | { |
11255 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
11256 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11257 | } | |
8b790721 JM |
11258 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
11259 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); | |
11260 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
11261 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); | |
a3f97cbb JW |
11262 | } |
11263 | ||
11264 | /* Output stuff that dwarf requires at the end of every file, | |
11265 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 11266 | |
a3f97cbb | 11267 | void |
9a666dda | 11268 | dwarf2out_finish () |
a3f97cbb | 11269 | { |
ef76d03b JW |
11270 | limbo_die_node *node, *next_node; |
11271 | dw_die_ref die; | |
ef76d03b JW |
11272 | |
11273 | /* Traverse the limbo die list, and add parent/child links. The only | |
11274 | dies without parents that should be here are concrete instances of | |
11275 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
11276 | For concrete instances, we can get the parent die from the abstract | |
11277 | instance. */ | |
11278 | for (node = limbo_die_list; node; node = next_node) | |
11279 | { | |
11280 | next_node = node->next; | |
11281 | die = node->die; | |
11282 | ||
11283 | if (die->die_parent == NULL) | |
11284 | { | |
a96c67ec JM |
11285 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
11286 | if (origin) | |
11287 | add_child_die (origin->die_parent, die); | |
ef76d03b | 11288 | else if (die == comp_unit_die) |
a96c67ec | 11289 | ; |
ef76d03b JW |
11290 | else |
11291 | abort (); | |
11292 | } | |
11293 | free (node); | |
11294 | } | |
a96c67ec | 11295 | limbo_die_list = NULL; |
ef76d03b | 11296 | |
8a8c3656 JM |
11297 | /* Walk through the list of incomplete types again, trying once more to |
11298 | emit full debugging info for them. */ | |
11299 | retry_incomplete_types (); | |
11300 | ||
881c6935 JM |
11301 | /* We need to reverse all the dies before break_out_includes, or |
11302 | we'll see the end of an include file before the beginning. */ | |
11303 | reverse_all_dies (comp_unit_die); | |
11304 | ||
11305 | /* Generate separate CUs for each of the include files we've seen. | |
11306 | They will go into limbo_die_list. */ | |
5f632b5e JM |
11307 | if (flag_eliminate_dwarf2_dups) |
11308 | break_out_includes (comp_unit_die); | |
881c6935 JM |
11309 | |
11310 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
11311 | that have children. */ | |
a3f97cbb | 11312 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
11313 | for (node = limbo_die_list; node; node = node->next) |
11314 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
11315 | |
11316 | /* Output a terminator label for the .text section. */ | |
11317 | fputc ('\n', asm_out_file); | |
11318 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
5c90448c | 11319 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 11320 | |
bdb669cb | 11321 | #if 0 |
a3f97cbb JW |
11322 | /* Output a terminator label for the .data section. */ |
11323 | fputc ('\n', asm_out_file); | |
11324 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
5c90448c | 11325 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
11326 | |
11327 | /* Output a terminator label for the .bss section. */ | |
11328 | fputc ('\n', asm_out_file); | |
11329 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
5c90448c | 11330 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 11331 | #endif |
a3f97cbb | 11332 | |
e90b62db JM |
11333 | /* Output the source line correspondence table. */ |
11334 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
11335 | { | |
b2244e22 JW |
11336 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
11337 | { | |
11338 | fputc ('\n', asm_out_file); | |
11339 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
11340 | output_line_info (); | |
11341 | } | |
e90b62db JM |
11342 | |
11343 | /* We can only use the low/high_pc attributes if all of the code | |
11344 | was in .text. */ | |
11345 | if (separate_line_info_table_in_use == 0) | |
11346 | { | |
8b790721 | 11347 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); |
5c90448c | 11348 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); |
e90b62db | 11349 | } |
71dfc51f | 11350 | |
8b790721 JM |
11351 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, |
11352 | debug_line_section_label); | |
e90b62db JM |
11353 | } |
11354 | ||
a96c67ec JM |
11355 | #if 0 /* unimplemented */ |
11356 | if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary) | |
11357 | add_AT_unsigned (die, DW_AT_macro_info, 0); | |
11358 | #endif | |
11359 | ||
881c6935 JM |
11360 | /* Output all of the compilation units. We put the main one last so that |
11361 | the offsets are available to output_pubnames. */ | |
11362 | for (node = limbo_die_list; node; node = node->next) | |
11363 | output_comp_unit (node->die); | |
11364 | output_comp_unit (comp_unit_die); | |
11365 | ||
a3f97cbb JW |
11366 | /* Output the abbreviation table. */ |
11367 | fputc ('\n', asm_out_file); | |
11368 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
a3f97cbb JW |
11369 | output_abbrev_section (); |
11370 | ||
d291dd49 JM |
11371 | if (pubname_table_in_use) |
11372 | { | |
11373 | /* Output public names table. */ | |
11374 | fputc ('\n', asm_out_file); | |
11375 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
11376 | output_pubnames (); | |
11377 | } | |
11378 | ||
e689ae67 JM |
11379 | /* We only put functions in the arange table, so don't write it out if |
11380 | we don't have any. */ | |
a3f97cbb JW |
11381 | if (fde_table_in_use) |
11382 | { | |
a3f97cbb JW |
11383 | /* Output the address range information. */ |
11384 | fputc ('\n', asm_out_file); | |
11385 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
11386 | output_aranges (); | |
11387 | } | |
11388 | } | |
9a666dda | 11389 | #endif /* DWARF2_DEBUGGING_INFO */ |