]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
1917ef85 | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
06ceef4e | 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" |
a3f97cbb JW |
40 | #include "tree.h" |
41 | #include "flags.h" | |
42 | #include "rtl.h" | |
43 | #include "hard-reg-set.h" | |
44 | #include "regs.h" | |
45 | #include "insn-config.h" | |
46 | #include "reload.h" | |
52a11cbf | 47 | #include "function.h" |
a3f97cbb | 48 | #include "output.h" |
71dfc51f | 49 | #include "expr.h" |
3f76745e | 50 | #include "except.h" |
a7cc7f29 | 51 | #include "dwarf2.h" |
76ead72b | 52 | #include "dwarf2out.h" |
2e4b9b8c | 53 | #include "dwarf2asm.h" |
10f0ad3d | 54 | #include "toplev.h" |
1865dbb5 | 55 | #include "varray.h" |
951a525f | 56 | #include "ggc.h" |
881c6935 | 57 | #include "md5.h" |
57bed152 | 58 | #include "tm_p.h" |
a3f97cbb | 59 | |
770ca8c6 JO |
60 | /* DWARF2 Abbreviation Glossary: |
61 | CFA = Canonical Frame Address | |
00a42e21 JM |
62 | a fixed address on the stack which identifies a call frame. |
63 | We define it to be the value of SP just before the call insn. | |
64 | The CFA register and offset, which may change during the course | |
65 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
66 | CFI = Call Frame Instruction |
67 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
68 | CIE = Common Information Entry |
69 | information describing information common to one or more FDEs | |
70 | DIE = Debugging Information Entry | |
71 | FDE = Frame Description Entry | |
72 | information describing the stack call frame, in particular, | |
73 | how to restore registers | |
74 | ||
75 | DW_CFA_... = DWARF2 CFA call frame instruction | |
76 | DW_TAG_... = DWARF2 DIE tag */ | |
77 | ||
0021b564 JM |
78 | /* Decide whether we want to emit frame unwind information for the current |
79 | translation unit. */ | |
80 | ||
81 | int | |
82 | dwarf2out_do_frame () | |
83 | { | |
84 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 | 85 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 86 | || DWARF2_FRAME_INFO |
9ec36da5 | 87 | #endif |
0021b564 | 88 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 89 | || flag_unwind_tables |
531073e7 | 90 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
91 | #endif |
92 | ); | |
93 | } | |
94 | ||
b1e6ab03 RH |
95 | /* The number of the current function definition for which debugging |
96 | information is being generated. These numbers range from 1 up to the | |
97 | maximum number of function definitions contained within the current | |
98 | compilation unit. These numbers are used to create unique label id's | |
99 | unique to each function definition. */ | |
100 | unsigned current_funcdef_number = 0; | |
101 | ||
0021b564 JM |
102 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
103 | ||
eaf95893 RK |
104 | /* How to start an assembler comment. */ |
105 | #ifndef ASM_COMMENT_START | |
106 | #define ASM_COMMENT_START ";#" | |
107 | #endif | |
108 | ||
a3f97cbb JW |
109 | typedef struct dw_cfi_struct *dw_cfi_ref; |
110 | typedef struct dw_fde_struct *dw_fde_ref; | |
111 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
112 | |
113 | /* Call frames are described using a sequence of Call Frame | |
114 | Information instructions. The register number, offset | |
115 | and address fields are provided as possible operands; | |
116 | their use is selected by the opcode field. */ | |
71dfc51f | 117 | |
a3f97cbb | 118 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
119 | { |
120 | unsigned long dw_cfi_reg_num; | |
121 | long int dw_cfi_offset; | |
d3e3972c | 122 | const char *dw_cfi_addr; |
7d9d8943 | 123 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 124 | } |
a3f97cbb JW |
125 | dw_cfi_oprnd; |
126 | ||
127 | typedef struct dw_cfi_struct | |
71dfc51f RK |
128 | { |
129 | dw_cfi_ref dw_cfi_next; | |
130 | enum dwarf_call_frame_info dw_cfi_opc; | |
131 | dw_cfi_oprnd dw_cfi_oprnd1; | |
132 | dw_cfi_oprnd dw_cfi_oprnd2; | |
133 | } | |
a3f97cbb JW |
134 | dw_cfi_node; |
135 | ||
7d9d8943 AM |
136 | /* This is how we define the location of the CFA. We use to handle it |
137 | as REG + OFFSET all the time, but now it can be more complex. | |
138 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 139 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
140 | of this structure. */ |
141 | typedef struct cfa_loc | |
142 | { | |
556273e0 | 143 | unsigned long reg; |
7d9d8943 AM |
144 | long offset; |
145 | long base_offset; | |
146 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
147 | } dw_cfa_location; | |
148 | ||
a3f97cbb | 149 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 150 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
151 | the beginning of the .debug_frame section. This used of a single |
152 | CIE obviates the need to keep track of multiple CIE's | |
153 | in the DWARF generation routines below. */ | |
71dfc51f | 154 | |
a3f97cbb | 155 | typedef struct dw_fde_struct |
71dfc51f | 156 | { |
d3e3972c KG |
157 | const char *dw_fde_begin; |
158 | const char *dw_fde_current_label; | |
159 | const char *dw_fde_end; | |
71dfc51f | 160 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
161 | unsigned funcdef_number; |
162 | unsigned nothrow : 1; | |
163 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 164 | } |
a3f97cbb JW |
165 | dw_fde_node; |
166 | ||
a3f97cbb JW |
167 | /* Maximum size (in bytes) of an artificially generated label. */ |
168 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
169 | ||
a1a4189d | 170 | /* The size of the target's pointer type. */ |
a3f97cbb | 171 | #ifndef PTR_SIZE |
a9d38797 | 172 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
173 | #endif |
174 | ||
a1a4189d JB |
175 | /* The size of addresses as they appear in the Dwarf 2 data. |
176 | Some architectures use word addresses to refer to code locations, | |
177 | but Dwarf 2 info always uses byte addresses. On such machines, | |
178 | Dwarf 2 addresses need to be larger than the architecture's | |
179 | pointers. */ | |
180 | #ifndef DWARF2_ADDR_SIZE | |
181 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
182 | #endif | |
183 | ||
7e23cb16 | 184 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
185 | relative to a debug info section, specified to be 4 bytes in the |
186 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 187 | as PTR_SIZE. */ |
71dfc51f | 188 | |
7e23cb16 JM |
189 | #ifndef DWARF_OFFSET_SIZE |
190 | #define DWARF_OFFSET_SIZE 4 | |
191 | #endif | |
192 | ||
9a666dda JM |
193 | #define DWARF_VERSION 2 |
194 | ||
7e23cb16 JM |
195 | /* Round SIZE up to the nearest BOUNDARY. */ |
196 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 197 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 198 | |
a3f97cbb | 199 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 200 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 201 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 202 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 203 | #else |
08cb3d38 | 204 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 205 | #endif |
27c35f4b | 206 | #endif /* not DWARF_CIE_DATA_ALIGNMENT */ |
a3f97cbb | 207 | |
3f76745e JM |
208 | /* A pointer to the base of a table that contains frame description |
209 | information for each routine. */ | |
210 | static dw_fde_ref fde_table; | |
a3f97cbb | 211 | |
3f76745e JM |
212 | /* Number of elements currently allocated for fde_table. */ |
213 | static unsigned fde_table_allocated; | |
a94dbf2c | 214 | |
3f76745e JM |
215 | /* Number of elements in fde_table currently in use. */ |
216 | static unsigned fde_table_in_use; | |
a3f97cbb | 217 | |
3f76745e JM |
218 | /* Size (in elements) of increments by which we may expand the |
219 | fde_table. */ | |
220 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 221 | |
a94dbf2c JM |
222 | /* A list of call frame insns for the CIE. */ |
223 | static dw_cfi_ref cie_cfi_head; | |
224 | ||
a3f97cbb JW |
225 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
226 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 227 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
228 | associated with the current function (body) definition. */ |
229 | static unsigned current_funcdef_fde; | |
230 | ||
a3f97cbb | 231 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 232 | |
83d2b3b9 KG |
233 | static char *stripattributes PARAMS ((const char *)); |
234 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
235 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
236 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 237 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
7d9d8943 AM |
238 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *)); |
239 | static void lookup_cfa PARAMS ((dw_cfa_location *)); | |
d3e3972c KG |
240 | static void reg_save PARAMS ((const char *, unsigned, |
241 | unsigned, long)); | |
83d2b3b9 | 242 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 243 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 244 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 245 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 246 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
247 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
248 | static void flush_queued_reg_saves PARAMS ((void)); | |
249 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 250 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 251 | |
7d9d8943 AM |
252 | /* Support for complex CFA locations. */ |
253 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 254 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
255 | struct dw_loc_descr_struct *)); |
256 | static struct dw_loc_descr_struct *build_cfa_loc | |
257 | PARAMS ((dw_cfa_location *)); | |
258 | static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *)); | |
259 | ||
2e4b9b8c RH |
260 | /* How to start an assembler comment. */ |
261 | #ifndef ASM_COMMENT_START | |
262 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
263 | #endif |
264 | ||
7e23cb16 JM |
265 | /* Data and reference forms for relocatable data. */ |
266 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
267 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
268 | ||
a3f97cbb JW |
269 | /* Pseudo-op for defining a new section. */ |
270 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 271 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
272 | #endif |
273 | ||
274 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
275 | print the SECTION_ASM_OP and the section name. The default here works for | |
276 | almost all svr4 assemblers, except for the sparc, where the section name | |
277 | must be enclosed in double quotes. (See sparcv4.h). */ | |
278 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
279 | #ifdef PUSHSECTION_FORMAT |
280 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
281 | #else | |
e8638df0 | 282 | #define SECTION_FORMAT "%s%s\n" |
c53aa195 | 283 | #endif |
a3f97cbb JW |
284 | #endif |
285 | ||
cf2fe500 RH |
286 | #ifndef DEBUG_FRAME_SECTION |
287 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 288 | #endif |
a3f97cbb | 289 | |
5c90448c JM |
290 | #ifndef FUNC_BEGIN_LABEL |
291 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 292 | #endif |
5c90448c JM |
293 | #ifndef FUNC_END_LABEL |
294 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 295 | #endif |
a6ab3aad JM |
296 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
297 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 298 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
299 | #define FDE_LABEL "LSFDE" |
300 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 301 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 302 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
303 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
304 | #define LINE_NUMBER_END_LABEL "LELT" | |
305 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
306 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 307 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 308 | |
a3f97cbb JW |
309 | /* Definitions of defaults for various types of primitive assembly language |
310 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 311 | but typically, that is unnecessary. */ |
71dfc51f | 312 | |
a3f97cbb JW |
313 | #ifndef ASM_OUTPUT_SECTION |
314 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
315 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
316 | #endif | |
317 | ||
2ed2af28 PDM |
318 | #ifdef SET_ASM_OP |
319 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
320 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
321 | do { \ | |
e8638df0 | 322 | fprintf (FILE, "%s", SET_ASM_OP); \ |
7bb9fb0e JM |
323 | assemble_name (FILE, SY); \ |
324 | fputc (',', FILE); \ | |
325 | assemble_name (FILE, HI); \ | |
326 | fputc ('-', FILE); \ | |
327 | assemble_name (FILE, LO); \ | |
328 | } while (0) | |
2ed2af28 PDM |
329 | #endif |
330 | #endif /* SET_ASM_OP */ | |
331 | ||
c8cc5c4a | 332 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
333 | is the column for PC, or the first column after all of the hard |
334 | registers. */ | |
c8cc5c4a | 335 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
336 | #ifdef PC_REGNUM |
337 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
338 | #else | |
3073d01c | 339 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 340 | #endif |
c8cc5c4a JM |
341 | #endif |
342 | ||
343 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 344 | default, we just provide columns for all registers. */ |
c8cc5c4a | 345 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 346 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 347 | #endif |
3f76745e | 348 | |
0021b564 JM |
349 | /* Hook used by __throw. */ |
350 | ||
351 | rtx | |
352 | expand_builtin_dwarf_fp_regnum () | |
353 | { | |
354 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
355 | } | |
356 | ||
a6ab3aad JM |
357 | /* The offset from the incoming value of %sp to the top of the stack frame |
358 | for the current function. */ | |
359 | #ifndef INCOMING_FRAME_SP_OFFSET | |
360 | #define INCOMING_FRAME_SP_OFFSET 0 | |
361 | #endif | |
362 | ||
71dfc51f | 363 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 364 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
365 | |
366 | static inline char * | |
a3f97cbb | 367 | stripattributes (s) |
d560ee52 | 368 | const char *s; |
a3f97cbb | 369 | { |
bf20f341 | 370 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
371 | char *p = stripped; |
372 | ||
bf20f341 JW |
373 | *p++ = '*'; |
374 | ||
375 | while (*s && *s != ',') | |
376 | *p++ = *s++; | |
71dfc51f | 377 | |
a3f97cbb JW |
378 | *p = '\0'; |
379 | return stripped; | |
380 | } | |
381 | ||
d9d5c9de | 382 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 383 | |
d9d5c9de BS |
384 | void |
385 | expand_builtin_init_dwarf_reg_sizes (address) | |
386 | tree address; | |
2f3ca9e7 | 387 | { |
d9d5c9de BS |
388 | int i; |
389 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
390 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
391 | rtx mem = gen_rtx_MEM (mode, addr); | |
2f3ca9e7 | 392 | |
376e12ab | 393 | for (i = 0; i < DWARF_FRAME_REGISTERS; ++i) |
2f3ca9e7 | 394 | { |
e0e07bd1 | 395 | int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
d9d5c9de | 396 | int size = GET_MODE_SIZE (reg_raw_mode[i]); |
2f3ca9e7 | 397 | |
c699cee9 JM |
398 | if (offset < 0) |
399 | continue; | |
400 | ||
d9d5c9de BS |
401 | emit_move_insn (change_address (mem, mode, |
402 | plus_constant (addr, offset)), | |
403 | GEN_INT (size)); | |
2f3ca9e7 | 404 | } |
2f3ca9e7 JM |
405 | } |
406 | ||
3f76745e | 407 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 408 | |
d560ee52 | 409 | static const char * |
3f76745e JM |
410 | dwarf_cfi_name (cfi_opc) |
411 | register unsigned cfi_opc; | |
412 | { | |
413 | switch (cfi_opc) | |
414 | { | |
415 | case DW_CFA_advance_loc: | |
416 | return "DW_CFA_advance_loc"; | |
417 | case DW_CFA_offset: | |
418 | return "DW_CFA_offset"; | |
419 | case DW_CFA_restore: | |
420 | return "DW_CFA_restore"; | |
421 | case DW_CFA_nop: | |
422 | return "DW_CFA_nop"; | |
423 | case DW_CFA_set_loc: | |
424 | return "DW_CFA_set_loc"; | |
425 | case DW_CFA_advance_loc1: | |
426 | return "DW_CFA_advance_loc1"; | |
427 | case DW_CFA_advance_loc2: | |
428 | return "DW_CFA_advance_loc2"; | |
429 | case DW_CFA_advance_loc4: | |
430 | return "DW_CFA_advance_loc4"; | |
431 | case DW_CFA_offset_extended: | |
432 | return "DW_CFA_offset_extended"; | |
433 | case DW_CFA_restore_extended: | |
434 | return "DW_CFA_restore_extended"; | |
435 | case DW_CFA_undefined: | |
436 | return "DW_CFA_undefined"; | |
437 | case DW_CFA_same_value: | |
438 | return "DW_CFA_same_value"; | |
439 | case DW_CFA_register: | |
440 | return "DW_CFA_register"; | |
441 | case DW_CFA_remember_state: | |
442 | return "DW_CFA_remember_state"; | |
443 | case DW_CFA_restore_state: | |
444 | return "DW_CFA_restore_state"; | |
445 | case DW_CFA_def_cfa: | |
446 | return "DW_CFA_def_cfa"; | |
447 | case DW_CFA_def_cfa_register: | |
448 | return "DW_CFA_def_cfa_register"; | |
449 | case DW_CFA_def_cfa_offset: | |
450 | return "DW_CFA_def_cfa_offset"; | |
7d9d8943 AM |
451 | case DW_CFA_def_cfa_expression: |
452 | return "DW_CFA_def_cfa_expression"; | |
c53aa195 | 453 | |
3f76745e JM |
454 | /* SGI/MIPS specific */ |
455 | case DW_CFA_MIPS_advance_loc8: | |
456 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
457 | |
458 | /* GNU extensions */ | |
459 | case DW_CFA_GNU_window_save: | |
460 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
461 | case DW_CFA_GNU_args_size: |
462 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
463 | case DW_CFA_GNU_negative_offset_extended: |
464 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 465 | |
3f76745e JM |
466 | default: |
467 | return "DW_CFA_<unknown>"; | |
468 | } | |
469 | } | |
a3f97cbb | 470 | |
3f76745e | 471 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 472 | |
3f76745e JM |
473 | static inline dw_cfi_ref |
474 | new_cfi () | |
475 | { | |
476 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 477 | |
3f76745e JM |
478 | cfi->dw_cfi_next = NULL; |
479 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
480 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 481 | |
3f76745e JM |
482 | return cfi; |
483 | } | |
a3f97cbb | 484 | |
3f76745e | 485 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 486 | |
3f76745e JM |
487 | static inline void |
488 | add_cfi (list_head, cfi) | |
489 | register dw_cfi_ref *list_head; | |
490 | register dw_cfi_ref cfi; | |
491 | { | |
492 | register dw_cfi_ref *p; | |
a3f97cbb | 493 | |
3f76745e JM |
494 | /* Find the end of the chain. */ |
495 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
496 | ; | |
497 | ||
498 | *p = cfi; | |
a3f97cbb JW |
499 | } |
500 | ||
3f76745e | 501 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 502 | |
c53aa195 | 503 | char * |
3f76745e | 504 | dwarf2out_cfi_label () |
a3f97cbb | 505 | { |
3f76745e JM |
506 | static char label[20]; |
507 | static unsigned long label_num = 0; | |
556273e0 | 508 | |
3f76745e JM |
509 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
510 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
511 | ||
512 | return label; | |
a3f97cbb JW |
513 | } |
514 | ||
3f76745e JM |
515 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
516 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 517 | |
3f76745e JM |
518 | static void |
519 | add_fde_cfi (label, cfi) | |
d3e3972c | 520 | register const char *label; |
3f76745e | 521 | register dw_cfi_ref cfi; |
a3f97cbb | 522 | { |
3f76745e JM |
523 | if (label) |
524 | { | |
525 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 526 | |
3f76745e JM |
527 | if (*label == 0) |
528 | label = dwarf2out_cfi_label (); | |
71dfc51f | 529 | |
3f76745e JM |
530 | if (fde->dw_fde_current_label == NULL |
531 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
532 | { | |
533 | register dw_cfi_ref xcfi; | |
a3f97cbb | 534 | |
3f76745e | 535 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 536 | |
3f76745e JM |
537 | /* Set the location counter to the new label. */ |
538 | xcfi = new_cfi (); | |
539 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
540 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
541 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
542 | } | |
71dfc51f | 543 | |
3f76745e JM |
544 | add_cfi (&fde->dw_fde_cfi, cfi); |
545 | } | |
546 | ||
547 | else | |
548 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
549 | } |
550 | ||
3f76745e | 551 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 552 | |
3f76745e | 553 | static inline void |
7d9d8943 | 554 | lookup_cfa_1 (cfi, loc) |
3f76745e | 555 | register dw_cfi_ref cfi; |
7d9d8943 | 556 | register dw_cfa_location *loc; |
a3f97cbb | 557 | { |
3f76745e JM |
558 | switch (cfi->dw_cfi_opc) |
559 | { | |
560 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 561 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
562 | break; |
563 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 564 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
565 | break; |
566 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
567 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
568 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
569 | break; | |
570 | case DW_CFA_def_cfa_expression: | |
571 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 572 | break; |
e9a25f70 JL |
573 | default: |
574 | break; | |
3f76745e | 575 | } |
a3f97cbb JW |
576 | } |
577 | ||
3f76745e | 578 | /* Find the previous value for the CFA. */ |
71dfc51f | 579 | |
3f76745e | 580 | static void |
7d9d8943 AM |
581 | lookup_cfa (loc) |
582 | register dw_cfa_location *loc; | |
a3f97cbb | 583 | { |
3f76745e JM |
584 | register dw_cfi_ref cfi; |
585 | ||
7d9d8943 AM |
586 | loc->reg = (unsigned long) -1; |
587 | loc->offset = 0; | |
588 | loc->indirect = 0; | |
589 | loc->base_offset = 0; | |
3f76745e JM |
590 | |
591 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 592 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
593 | |
594 | if (fde_table_in_use) | |
a3f97cbb | 595 | { |
3f76745e JM |
596 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
597 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 598 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
599 | } |
600 | } | |
601 | ||
3f76745e | 602 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 603 | static dw_cfa_location cfa; |
71dfc51f | 604 | |
3f76745e JM |
605 | /* The register used for saving registers to the stack, and its offset |
606 | from the CFA. */ | |
fbfa55b0 | 607 | static dw_cfa_location cfa_store; |
3f76745e | 608 | |
0021b564 JM |
609 | /* The running total of the size of arguments pushed onto the stack. */ |
610 | static long args_size; | |
611 | ||
b57d9225 JM |
612 | /* The last args_size we actually output. */ |
613 | static long old_args_size; | |
614 | ||
3f76745e JM |
615 | /* Entry point to update the canonical frame address (CFA). |
616 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
617 | calculated from REG+OFFSET. */ | |
618 | ||
619 | void | |
620 | dwarf2out_def_cfa (label, reg, offset) | |
d3e3972c | 621 | register const char *label; |
7d9d8943 AM |
622 | unsigned reg; |
623 | long offset; | |
624 | { | |
625 | dw_cfa_location loc; | |
626 | loc.indirect = 0; | |
627 | loc.base_offset = 0; | |
628 | loc.reg = reg; | |
629 | loc.offset = offset; | |
630 | def_cfa_1 (label, &loc); | |
631 | } | |
632 | ||
770ca8c6 | 633 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 AM |
634 | the dw_cfa_location structure. */ |
635 | static void | |
636 | def_cfa_1 (label, loc_p) | |
637 | register const char *label; | |
638 | dw_cfa_location *loc_p; | |
a3f97cbb | 639 | { |
3f76745e | 640 | register dw_cfi_ref cfi; |
7d9d8943 | 641 | dw_cfa_location old_cfa, loc; |
3f76745e | 642 | |
7d9d8943 AM |
643 | cfa = *loc_p; |
644 | loc = *loc_p; | |
5bef9b1f | 645 | |
7d9d8943 AM |
646 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
647 | cfa_store.offset = loc.offset; | |
3f76745e | 648 | |
7d9d8943 AM |
649 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
650 | lookup_cfa (&old_cfa); | |
651 | ||
652 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset && | |
653 | loc.indirect == old_cfa.indirect) | |
654 | { | |
e09bbb25 JM |
655 | if (loc.indirect == 0 |
656 | || loc.base_offset == old_cfa.base_offset) | |
770ca8c6 JO |
657 | /* Nothing changed so no need to issue any call frame |
658 | instructions. */ | |
7d9d8943 | 659 | return; |
7d9d8943 | 660 | } |
3f76745e JM |
661 | |
662 | cfi = new_cfi (); | |
663 | ||
e09bbb25 | 664 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 665 | { |
770ca8c6 JO |
666 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
667 | indicating the CFA register did not change but the offset | |
668 | did. */ | |
3f76745e | 669 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 670 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 671 | } |
a3f97cbb | 672 | |
3f76745e | 673 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 674 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 675 | && !loc.indirect) |
3f76745e | 676 | { |
770ca8c6 JO |
677 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
678 | indicating the CFA register has changed to <register> but the | |
679 | offset has not changed. */ | |
3f76745e | 680 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 681 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
682 | } |
683 | #endif | |
a3f97cbb | 684 | |
7d9d8943 | 685 | else if (loc.indirect == 0) |
3f76745e | 686 | { |
770ca8c6 JO |
687 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
688 | indicating the CFA register has changed to <register> with | |
689 | the specified offset. */ | |
3f76745e | 690 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
691 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
692 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
693 | } | |
694 | else | |
695 | { | |
770ca8c6 JO |
696 | /* Construct a DW_CFA_def_cfa_expression instruction to |
697 | calculate the CFA using a full location expression since no | |
698 | register-offset pair is available. */ | |
556273e0 | 699 | struct dw_loc_descr_struct *loc_list; |
7d9d8943 AM |
700 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
701 | loc_list = build_cfa_loc (&loc); | |
702 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 703 | } |
3f76745e JM |
704 | |
705 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
706 | } |
707 | ||
3f76745e JM |
708 | /* Add the CFI for saving a register. REG is the CFA column number. |
709 | LABEL is passed to add_fde_cfi. | |
710 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
711 | otherwise it is saved in SREG. */ | |
71dfc51f | 712 | |
3f76745e JM |
713 | static void |
714 | reg_save (label, reg, sreg, offset) | |
d3e3972c | 715 | register const char *label; |
3f76745e JM |
716 | register unsigned reg; |
717 | register unsigned sreg; | |
718 | register long offset; | |
a3f97cbb | 719 | { |
3f76745e JM |
720 | register dw_cfi_ref cfi = new_cfi (); |
721 | ||
722 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
723 | ||
85066503 MH |
724 | /* The following comparison is correct. -1 is used to indicate that |
725 | the value isn't a register number. */ | |
726 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 727 | { |
3f76745e JM |
728 | if (reg & ~0x3f) |
729 | /* The register number won't fit in 6 bits, so we have to use | |
730 | the long form. */ | |
731 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
732 | else | |
733 | cfi->dw_cfi_opc = DW_CFA_offset; | |
734 | ||
27c35f4b HPN |
735 | #ifdef ENABLE_CHECKING |
736 | { | |
737 | /* If we get an offset that is not a multiple of | |
738 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
739 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
740 | description. */ | |
741 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
742 | ||
743 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
744 | abort (); | |
745 | } | |
746 | #endif | |
3f76745e | 747 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 748 | if (offset < 0) |
3f388b42 GK |
749 | { |
750 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
751 | offset = -offset; | |
752 | } | |
3f76745e JM |
753 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
754 | } | |
2c849145 JM |
755 | else if (sreg == reg) |
756 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
757 | return; | |
3f76745e JM |
758 | else |
759 | { | |
760 | cfi->dw_cfi_opc = DW_CFA_register; | |
761 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
762 | } | |
763 | ||
764 | add_fde_cfi (label, cfi); | |
765 | } | |
766 | ||
c53aa195 JM |
767 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
768 | This CFI tells the unwinder that it needs to restore the window registers | |
769 | from the previous frame's window save area. | |
556273e0 | 770 | |
c53aa195 JM |
771 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
772 | assuming 0(cfa)) and what registers are in the window. */ | |
773 | ||
774 | void | |
775 | dwarf2out_window_save (label) | |
d3e3972c | 776 | register const char *label; |
c53aa195 JM |
777 | { |
778 | register dw_cfi_ref cfi = new_cfi (); | |
779 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
780 | add_fde_cfi (label, cfi); | |
781 | } | |
782 | ||
0021b564 JM |
783 | /* Add a CFI to update the running total of the size of arguments |
784 | pushed onto the stack. */ | |
785 | ||
786 | void | |
787 | dwarf2out_args_size (label, size) | |
d3e3972c | 788 | const char *label; |
0021b564 JM |
789 | long size; |
790 | { | |
b57d9225 JM |
791 | register dw_cfi_ref cfi; |
792 | ||
793 | if (size == old_args_size) | |
794 | return; | |
795 | old_args_size = size; | |
796 | ||
797 | cfi = new_cfi (); | |
0021b564 JM |
798 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
799 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
800 | add_fde_cfi (label, cfi); | |
801 | } | |
802 | ||
c53aa195 JM |
803 | /* Entry point for saving a register to the stack. REG is the GCC register |
804 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
805 | |
806 | void | |
807 | dwarf2out_reg_save (label, reg, offset) | |
d3e3972c | 808 | register const char *label; |
3f76745e JM |
809 | register unsigned reg; |
810 | register long offset; | |
811 | { | |
812 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
813 | } | |
814 | ||
c53aa195 JM |
815 | /* Entry point for saving the return address in the stack. |
816 | LABEL and OFFSET are passed to reg_save. */ | |
817 | ||
818 | void | |
819 | dwarf2out_return_save (label, offset) | |
d3e3972c | 820 | register const char *label; |
c53aa195 JM |
821 | register long offset; |
822 | { | |
823 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
824 | } | |
825 | ||
826 | /* Entry point for saving the return address in a register. | |
827 | LABEL and SREG are passed to reg_save. */ | |
828 | ||
829 | void | |
830 | dwarf2out_return_reg (label, sreg) | |
d3e3972c | 831 | register const char *label; |
c53aa195 JM |
832 | register unsigned sreg; |
833 | { | |
834 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
835 | } | |
836 | ||
3f76745e JM |
837 | /* Record the initial position of the return address. RTL is |
838 | INCOMING_RETURN_ADDR_RTX. */ | |
839 | ||
840 | static void | |
841 | initial_return_save (rtl) | |
842 | register rtx rtl; | |
843 | { | |
973838fd | 844 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
845 | long offset = 0; |
846 | ||
847 | switch (GET_CODE (rtl)) | |
848 | { | |
849 | case REG: | |
850 | /* RA is in a register. */ | |
2c849145 | 851 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e JM |
852 | break; |
853 | case MEM: | |
854 | /* RA is on the stack. */ | |
855 | rtl = XEXP (rtl, 0); | |
856 | switch (GET_CODE (rtl)) | |
857 | { | |
858 | case REG: | |
3a88cbd1 JL |
859 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
860 | abort (); | |
3f76745e JM |
861 | offset = 0; |
862 | break; | |
863 | case PLUS: | |
3a88cbd1 JL |
864 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
865 | abort (); | |
3f76745e JM |
866 | offset = INTVAL (XEXP (rtl, 1)); |
867 | break; | |
868 | case MINUS: | |
3a88cbd1 JL |
869 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
870 | abort (); | |
3f76745e JM |
871 | offset = -INTVAL (XEXP (rtl, 1)); |
872 | break; | |
873 | default: | |
874 | abort (); | |
875 | } | |
876 | break; | |
c53aa195 JM |
877 | case PLUS: |
878 | /* The return address is at some offset from any value we can | |
879 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
880 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
881 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
882 | abort (); | |
c53aa195 JM |
883 | initial_return_save (XEXP (rtl, 0)); |
884 | return; | |
a3f97cbb | 885 | default: |
3f76745e | 886 | abort (); |
a3f97cbb | 887 | } |
3f76745e | 888 | |
7d9d8943 | 889 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
890 | } |
891 | ||
1ba5ae8f AH |
892 | /* Given a SET, calculate the amount of stack adjustment it |
893 | contains. */ | |
894 | ||
5e640c56 AH |
895 | static long |
896 | stack_adjust_offset (pattern) | |
1ba5ae8f AH |
897 | rtx pattern; |
898 | { | |
899 | rtx src = SET_SRC (pattern); | |
900 | rtx dest = SET_DEST (pattern); | |
901 | long offset = 0; | |
902 | enum rtx_code code; | |
903 | ||
904 | if (dest == stack_pointer_rtx) | |
905 | { | |
906 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
907 | code = GET_CODE (src); | |
908 | if (! (code == PLUS || code == MINUS) | |
909 | || XEXP (src, 0) != stack_pointer_rtx | |
910 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
911 | return 0; | |
912 | ||
913 | offset = INTVAL (XEXP (src, 1)); | |
914 | } | |
915 | else if (GET_CODE (dest) == MEM) | |
916 | { | |
917 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
918 | src = XEXP (dest, 0); | |
919 | code = GET_CODE (src); | |
920 | ||
e2134eea JH |
921 | if (! (code == PRE_DEC || code == PRE_INC |
922 | || code == PRE_MODIFY) | |
1ba5ae8f AH |
923 | || XEXP (src, 0) != stack_pointer_rtx) |
924 | return 0; | |
925 | ||
e2134eea JH |
926 | if (code == PRE_MODIFY) |
927 | { | |
928 | rtx val = XEXP (XEXP (src, 1), 1); | |
929 | /* We handle only adjustments by constant amount. */ | |
930 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
931 | GET_CODE (val) != CONST_INT) | |
932 | abort(); | |
933 | offset = -INTVAL (val); | |
934 | } | |
935 | else offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1ba5ae8f AH |
936 | } |
937 | else | |
938 | return 0; | |
939 | ||
940 | if (code == PLUS || code == PRE_INC) | |
941 | offset = -offset; | |
942 | ||
943 | return offset; | |
944 | } | |
945 | ||
0021b564 JM |
946 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
947 | make a note of it if it does. EH uses this information to find out how | |
948 | much extra space it needs to pop off the stack. */ | |
949 | ||
950 | static void | |
951 | dwarf2out_stack_adjust (insn) | |
952 | rtx insn; | |
953 | { | |
0021b564 | 954 | long offset; |
d3e3972c | 955 | const char *label; |
0021b564 | 956 | |
c1e9f663 | 957 | if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
958 | { |
959 | /* Extract the size of the args from the CALL rtx itself. */ | |
960 | ||
961 | insn = PATTERN (insn); | |
962 | if (GET_CODE (insn) == PARALLEL) | |
963 | insn = XVECEXP (insn, 0, 0); | |
964 | if (GET_CODE (insn) == SET) | |
965 | insn = SET_SRC (insn); | |
3db35af4 MM |
966 | if (GET_CODE (insn) != CALL) |
967 | abort (); | |
b57d9225 JM |
968 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
969 | return; | |
970 | } | |
971 | ||
972 | /* If only calls can throw, and we have a frame pointer, | |
973 | save up adjustments until we see the CALL_INSN. */ | |
c1e9f663 | 974 | else if (! flag_non_call_exceptions |
7d9d8943 | 975 | && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
976 | return; |
977 | ||
6020d360 | 978 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 979 | { |
6020d360 JM |
980 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
981 | the compiler will have already emitted a stack adjustment, but | |
982 | doesn't bother for calls to noreturn functions. */ | |
983 | #ifdef STACK_GROWS_DOWNWARD | |
984 | offset = -args_size; | |
985 | #else | |
986 | offset = args_size; | |
987 | #endif | |
0021b564 | 988 | } |
6020d360 | 989 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 990 | { |
1ba5ae8f AH |
991 | offset = stack_adjust_offset (PATTERN (insn)); |
992 | } | |
993 | else if (GET_CODE (PATTERN (insn)) == PARALLEL | |
994 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
995 | { | |
996 | /* There may be stack adjustments inside compound insns. Search | |
997 | for them. */ | |
998 | int j; | |
0021b564 | 999 | |
1ba5ae8f AH |
1000 | offset = 0; |
1001 | for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--) | |
6020d360 | 1002 | { |
1ba5ae8f AH |
1003 | rtx pattern = XVECEXP (PATTERN (insn), 0, j); |
1004 | if (GET_CODE (pattern) == SET) | |
1005 | offset += stack_adjust_offset (pattern); | |
6020d360 | 1006 | } |
0021b564 JM |
1007 | } |
1008 | else | |
1009 | return; | |
0b34cf1e | 1010 | |
6020d360 JM |
1011 | if (offset == 0) |
1012 | return; | |
1013 | ||
7d9d8943 AM |
1014 | if (cfa.reg == STACK_POINTER_REGNUM) |
1015 | cfa.offset += offset; | |
0021b564 JM |
1016 | |
1017 | #ifndef STACK_GROWS_DOWNWARD | |
1018 | offset = -offset; | |
1019 | #endif | |
1020 | args_size += offset; | |
1021 | if (args_size < 0) | |
1022 | args_size = 0; | |
1023 | ||
1024 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1025 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1026 | dwarf2out_args_size (label, args_size); |
1027 | } | |
1028 | ||
fbfa55b0 RH |
1029 | /* We delay emitting a register save until either (a) we reach the end |
1030 | of the prologue or (b) the register is clobbered. This clusters | |
1031 | register saves so that there are fewer pc advances. */ | |
1032 | ||
1033 | struct queued_reg_save | |
1034 | { | |
1035 | struct queued_reg_save *next; | |
1036 | rtx reg; | |
1037 | long cfa_offset; | |
1038 | }; | |
1039 | ||
1040 | static struct queued_reg_save *queued_reg_saves; | |
1041 | static const char *last_reg_save_label; | |
1042 | ||
1043 | static void | |
1044 | queue_reg_save (label, reg, offset) | |
1045 | const char *label; | |
1046 | rtx reg; | |
1047 | long offset; | |
1048 | { | |
1049 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1050 | ||
1051 | q->next = queued_reg_saves; | |
1052 | q->reg = reg; | |
1053 | q->cfa_offset = offset; | |
1054 | queued_reg_saves = q; | |
1055 | ||
1056 | last_reg_save_label = label; | |
1057 | } | |
1058 | ||
1059 | static void | |
1060 | flush_queued_reg_saves () | |
1061 | { | |
1062 | struct queued_reg_save *q, *next; | |
1063 | ||
1064 | for (q = queued_reg_saves; q ; q = next) | |
1065 | { | |
1066 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1067 | next = q->next; | |
1068 | free (q); | |
1069 | } | |
1070 | ||
1071 | queued_reg_saves = NULL; | |
1072 | last_reg_save_label = NULL; | |
1073 | } | |
1074 | ||
1075 | static bool | |
1076 | clobbers_queued_reg_save (insn) | |
1077 | rtx insn; | |
1078 | { | |
1079 | struct queued_reg_save *q; | |
1080 | ||
1081 | for (q = queued_reg_saves; q ; q = q->next) | |
1082 | if (modified_in_p (q->reg, insn)) | |
1083 | return true; | |
1084 | ||
1085 | return false; | |
1086 | } | |
1087 | ||
1088 | ||
770ca8c6 JO |
1089 | /* A temporary register holding an integral value used in adjusting SP |
1090 | or setting up the store_reg. The "offset" field holds the integer | |
1091 | value, not an offset. */ | |
fbfa55b0 | 1092 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1093 | |
1094 | /* Record call frame debugging information for an expression EXPR, | |
1095 | which either sets SP or FP (adjusting how we calculate the frame | |
1096 | address) or saves a register to the stack. LABEL indicates the | |
1097 | address of EXPR. | |
1098 | ||
1099 | This function encodes a state machine mapping rtxes to actions on | |
1100 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1101 | users need not read the source code. | |
1102 | ||
a401107d JO |
1103 | The High-Level Picture |
1104 | ||
1105 | Changes in the register we use to calculate the CFA: Currently we | |
1106 | assume that if you copy the CFA register into another register, we | |
1107 | should take the other one as the new CFA register; this seems to | |
1108 | work pretty well. If it's wrong for some target, it's simple | |
1109 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1110 | ||
1111 | Changes in the register we use for saving registers to the stack: | |
1112 | This is usually SP, but not always. Again, we deduce that if you | |
1113 | copy SP into another register (and SP is not the CFA register), | |
1114 | then the new register is the one we will be using for register | |
1115 | saves. This also seems to work. | |
1116 | ||
1117 | Register saves: There's not much guesswork about this one; if | |
1118 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1119 | register save, and the register used to calculate the destination | |
1120 | had better be the one we think we're using for this purpose. | |
1121 | ||
1122 | Except: If the register being saved is the CFA register, and the | |
1123 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1124 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1125 | the intent is to save the value of SP from the previous frame. | |
1126 | ||
770ca8c6 JO |
1127 | Invariants / Summaries of Rules |
1128 | ||
a401107d JO |
1129 | cfa current rule for calculating the CFA. It usually |
1130 | consists of a register and an offset. | |
770ca8c6 JO |
1131 | cfa_store register used by prologue code to save things to the stack |
1132 | cfa_store.offset is the offset from the value of | |
1133 | cfa_store.reg to the actual CFA | |
1134 | cfa_temp register holding an integral value. cfa_temp.offset | |
1135 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1136 | stack pointer. cfa_temp is also used like cfa_store, |
1137 | to track stores to the stack via fp or a temp reg. | |
770ca8c6 JO |
1138 | |
1139 | Rules 1- 4: Setting a register's value to cfa.reg or an expression | |
1140 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1141 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1142 | cfa_temp.offset. | |
770ca8c6 JO |
1143 | |
1144 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1145 | expression yielding a constant. This sets cfa_temp.reg | |
1146 | and cfa_temp.offset. | |
1147 | ||
1148 | Rule 5: Create a new register cfa_store used to save items to the | |
1149 | stack. | |
1150 | ||
19ec6a36 | 1151 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1152 | difference of the original location and cfa_store's |
19ec6a36 | 1153 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1154 | |
1155 | The Rules | |
1156 | ||
1157 | "{a,b}" indicates a choice of a xor b. | |
1158 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1159 | ||
1160 | Rule 1: | |
1161 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1162 | effects: cfa.reg = <reg1> |
770ca8c6 | 1163 | cfa.offset unchanged |
19ec6a36 AM |
1164 | cfa_temp.reg = <reg1> |
1165 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1166 | |
1167 | Rule 2: | |
19ec6a36 | 1168 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg})) |
770ca8c6 JO |
1169 | effects: cfa.reg = sp if fp used |
1170 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1171 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1172 | if cfa_store.reg==sp | |
1173 | ||
1174 | Rule 3: | |
19ec6a36 | 1175 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1176 | effects: cfa.reg = fp |
1177 | cfa_offset += +/- <const_int> | |
1178 | ||
1179 | Rule 4: | |
19ec6a36 | 1180 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1181 | constraints: <reg1> != fp |
1182 | <reg1> != sp | |
1183 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1184 | cfa_temp.reg = <reg1> |
1185 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1186 | |
1187 | Rule 5: | |
1188 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1189 | constraints: <reg1> != fp | |
1190 | <reg1> != sp | |
1191 | effects: cfa_store.reg = <reg1> | |
1192 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1193 | ||
1194 | Rule 6: | |
1195 | (set <reg> <const_int>) | |
1196 | effects: cfa_temp.reg = <reg> | |
1197 | cfa_temp.offset = <const_int> | |
1198 | ||
1199 | Rule 7: | |
1200 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1201 | effects: cfa_temp.reg = <reg1> | |
1202 | cfa_temp.offset |= <const_int> | |
1203 | ||
1204 | Rule 8: | |
1205 | (set <reg> (high <exp>)) | |
1206 | effects: none | |
1207 | ||
1208 | Rule 9: | |
1209 | (set <reg> (lo_sum <exp> <const_int>)) | |
1210 | effects: cfa_temp.reg = <reg> | |
1211 | cfa_temp.offset = <const_int> | |
1212 | ||
1213 | Rule 10: | |
1214 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1215 | effects: cfa_store.offset -= <const_int> | |
1216 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1217 | cfa.reg = sp |
19ec6a36 | 1218 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1219 | |
1220 | Rule 11: | |
1221 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1222 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1223 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1224 | cfa.reg = sp |
19ec6a36 | 1225 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1226 | |
1227 | Rule 12: | |
19ec6a36 AM |
1228 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>) |
1229 | effects: cfa.reg = <reg1> | |
1230 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1231 | |
1232 | Rule 13: | |
19ec6a36 AM |
1233 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1234 | effects: cfa.reg = <reg1> | |
1235 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1236 | ||
1237 | Rule 14: | |
1238 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1239 | effects: cfa.reg = <reg1> | |
1240 | cfa.base_offset = -cfa_temp.offset | |
1241 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1242 | |
1243 | static void | |
1244 | dwarf2out_frame_debug_expr (expr, label) | |
1245 | rtx expr; | |
d3e3972c | 1246 | const char *label; |
b664de3a AM |
1247 | { |
1248 | rtx src, dest; | |
1249 | long offset; | |
556273e0 KH |
1250 | |
1251 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1252 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1253 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1254 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1255 | flag is set in them. */ | |
b664de3a | 1256 | |
79d13342 NC |
1257 | if (GET_CODE (expr) == PARALLEL |
1258 | || GET_CODE (expr) == SEQUENCE) | |
556273e0 | 1259 | { |
b664de3a AM |
1260 | int par_index; |
1261 | int limit = XVECLEN (expr, 0); | |
1262 | ||
1263 | for (par_index = 0; par_index < limit; par_index++) | |
556273e0 KH |
1264 | { |
1265 | rtx x = XVECEXP (expr, 0, par_index); | |
1266 | ||
1267 | if (GET_CODE (x) == SET && | |
b664de3a | 1268 | (RTX_FRAME_RELATED_P (x) || par_index == 0)) |
2618f955 | 1269 | dwarf2out_frame_debug_expr (x, label); |
556273e0 | 1270 | } |
b664de3a AM |
1271 | return; |
1272 | } | |
556273e0 | 1273 | |
b664de3a AM |
1274 | if (GET_CODE (expr) != SET) |
1275 | abort (); | |
1276 | ||
1277 | src = SET_SRC (expr); | |
1278 | dest = SET_DEST (expr); | |
1279 | ||
1280 | switch (GET_CODE (dest)) | |
1281 | { | |
1282 | case REG: | |
770ca8c6 | 1283 | /* Rule 1 */ |
b664de3a AM |
1284 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1285 | relative to the current CFA register. */ | |
1286 | switch (GET_CODE (src)) | |
556273e0 KH |
1287 | { |
1288 | /* Setting FP from SP. */ | |
1289 | case REG: | |
1290 | if (cfa.reg == (unsigned) REGNO (src)) | |
1291 | /* OK. */ | |
1292 | ; | |
626d1efd | 1293 | else |
556273e0 | 1294 | abort (); |
2c849145 JM |
1295 | |
1296 | /* We used to require that dest be either SP or FP, but the | |
1297 | ARM copies SP to a temporary register, and from there to | |
1298 | FP. So we just rely on the backends to only set | |
1299 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1300 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1301 | cfa_temp.reg = cfa.reg; |
1302 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1303 | break; |
b664de3a | 1304 | |
556273e0 KH |
1305 | case PLUS: |
1306 | case MINUS: | |
19ec6a36 | 1307 | case LO_SUM: |
556273e0 KH |
1308 | if (dest == stack_pointer_rtx) |
1309 | { | |
770ca8c6 | 1310 | /* Rule 2 */ |
2618f955 MM |
1311 | /* Adjusting SP. */ |
1312 | switch (GET_CODE (XEXP (src, 1))) | |
1313 | { | |
1314 | case CONST_INT: | |
1315 | offset = INTVAL (XEXP (src, 1)); | |
1316 | break; | |
1317 | case REG: | |
770ca8c6 | 1318 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1319 | abort (); |
770ca8c6 | 1320 | offset = cfa_temp.offset; |
2618f955 MM |
1321 | break; |
1322 | default: | |
1323 | abort (); | |
1324 | } | |
1325 | ||
1326 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1327 | { | |
1328 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1329 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1330 | abort (); |
7d9d8943 | 1331 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1332 | } |
19ec6a36 AM |
1333 | else if (GET_CODE (src) == LO_SUM) |
1334 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1335 | ; | |
2618f955 MM |
1336 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1337 | abort (); | |
1338 | ||
19ec6a36 | 1339 | if (GET_CODE (src) != MINUS) |
2618f955 | 1340 | offset = -offset; |
7d9d8943 AM |
1341 | if (cfa.reg == STACK_POINTER_REGNUM) |
1342 | cfa.offset += offset; | |
1343 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1344 | cfa_store.offset += offset; | |
556273e0 KH |
1345 | } |
1346 | else if (dest == hard_frame_pointer_rtx) | |
1347 | { | |
770ca8c6 | 1348 | /* Rule 3 */ |
2618f955 MM |
1349 | /* Either setting the FP from an offset of the SP, |
1350 | or adjusting the FP */ | |
2c849145 | 1351 | if (! frame_pointer_needed) |
2618f955 MM |
1352 | abort (); |
1353 | ||
2c849145 | 1354 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1355 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1356 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1357 | { | |
2618f955 | 1358 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1359 | if (GET_CODE (src) != MINUS) |
2618f955 | 1360 | offset = -offset; |
7d9d8943 AM |
1361 | cfa.offset += offset; |
1362 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1363 | } |
556273e0 KH |
1364 | else |
1365 | abort (); | |
1366 | } | |
1367 | else | |
1368 | { | |
19ec6a36 | 1369 | if (GET_CODE (src) == MINUS) |
2618f955 | 1370 | abort (); |
b53ef1a2 | 1371 | |
770ca8c6 | 1372 | /* Rule 4 */ |
b53ef1a2 NC |
1373 | if (GET_CODE (XEXP (src, 0)) == REG |
1374 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1375 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1376 | { |
1377 | /* Setting a temporary CFA register that will be copied | |
1378 | into the FP later on. */ | |
19ec6a36 | 1379 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1380 | cfa.offset += offset; |
1381 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1382 | /* Or used to save regs to the stack. */ |
1383 | cfa_temp.reg = cfa.reg; | |
1384 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1385 | } |
770ca8c6 | 1386 | /* Rule 5 */ |
19ec6a36 AM |
1387 | else if (GET_CODE (XEXP (src, 0)) == REG |
1388 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1389 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1390 | { |
00a42e21 JM |
1391 | /* Setting a scratch register that we will use instead |
1392 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1393 | if (cfa.reg != STACK_POINTER_REGNUM) |
1394 | abort (); | |
1395 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1396 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1397 | } |
19ec6a36 AM |
1398 | /* Rule 9 */ |
1399 | else if (GET_CODE (src) == LO_SUM | |
1400 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1401 | { | |
1402 | cfa_temp.reg = REGNO (dest); | |
1403 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1404 | } | |
1405 | else | |
1406 | abort (); | |
556273e0 KH |
1407 | } |
1408 | break; | |
b664de3a | 1409 | |
770ca8c6 | 1410 | /* Rule 6 */ |
556273e0 | 1411 | case CONST_INT: |
770ca8c6 JO |
1412 | cfa_temp.reg = REGNO (dest); |
1413 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1414 | break; |
b664de3a | 1415 | |
770ca8c6 | 1416 | /* Rule 7 */ |
556273e0 KH |
1417 | case IOR: |
1418 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1419 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1420 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1421 | abort (); |
770ca8c6 JO |
1422 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1423 | cfa_temp.reg = REGNO (dest); | |
1424 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1425 | break; |
b664de3a | 1426 | |
9ae21d2a AM |
1427 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1428 | which will fill in all of the bits. */ | |
1429 | /* Rule 8 */ | |
1430 | case HIGH: | |
1431 | break; | |
1432 | ||
556273e0 KH |
1433 | default: |
1434 | abort (); | |
1435 | } | |
7d9d8943 | 1436 | def_cfa_1 (label, &cfa); |
2618f955 | 1437 | break; |
b664de3a | 1438 | |
2618f955 | 1439 | case MEM: |
2618f955 MM |
1440 | if (GET_CODE (src) != REG) |
1441 | abort (); | |
7d9d8943 | 1442 | |
7d9d8943 AM |
1443 | /* Saving a register to the stack. Make sure dest is relative to the |
1444 | CFA register. */ | |
2618f955 MM |
1445 | switch (GET_CODE (XEXP (dest, 0))) |
1446 | { | |
770ca8c6 | 1447 | /* Rule 10 */ |
2618f955 | 1448 | /* With a push. */ |
e2134eea JH |
1449 | case PRE_MODIFY: |
1450 | /* We can't handle variable size modifications. */ | |
1451 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
1452 | abort(); | |
1453 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); | |
1454 | ||
1455 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1456 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1457 | abort (); | |
1458 | cfa_store.offset += offset; | |
1459 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1460 | cfa.offset = cfa_store.offset; | |
1461 | ||
1462 | offset = -cfa_store.offset; | |
1463 | break; | |
770ca8c6 | 1464 | /* Rule 11 */ |
2618f955 MM |
1465 | case PRE_INC: |
1466 | case PRE_DEC: | |
1467 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1468 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1469 | offset = -offset; | |
b664de3a | 1470 | |
2618f955 | 1471 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1472 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1473 | abort (); |
7d9d8943 AM |
1474 | cfa_store.offset += offset; |
1475 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1476 | cfa.offset = cfa_store.offset; | |
b664de3a | 1477 | |
7d9d8943 | 1478 | offset = -cfa_store.offset; |
2618f955 | 1479 | break; |
b664de3a | 1480 | |
770ca8c6 | 1481 | /* Rule 12 */ |
2618f955 MM |
1482 | /* With an offset. */ |
1483 | case PLUS: | |
1484 | case MINUS: | |
19ec6a36 | 1485 | case LO_SUM: |
770ca8c6 JO |
1486 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1487 | abort (); | |
2618f955 MM |
1488 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1489 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1490 | offset = -offset; | |
b664de3a | 1491 | |
19ec6a36 AM |
1492 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1493 | offset -= cfa_store.offset; | |
1494 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1495 | offset -= cfa_temp.offset; | |
1496 | else | |
2618f955 | 1497 | abort (); |
2618f955 MM |
1498 | break; |
1499 | ||
770ca8c6 | 1500 | /* Rule 13 */ |
2618f955 MM |
1501 | /* Without an offset. */ |
1502 | case REG: | |
19ec6a36 AM |
1503 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1504 | offset = -cfa_store.offset; | |
1505 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1506 | offset = -cfa_temp.offset; | |
1507 | else | |
556273e0 | 1508 | abort (); |
19ec6a36 AM |
1509 | break; |
1510 | ||
1511 | /* Rule 14 */ | |
1512 | case POST_INC: | |
1513 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1514 | abort (); | |
1515 | offset = -cfa_temp.offset; | |
1516 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1517 | break; |
1518 | ||
1519 | default: | |
1520 | abort (); | |
1521 | } | |
e09bbb25 | 1522 | |
556273e0 | 1523 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1524 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1525 | && (unsigned) REGNO (src) == cfa.reg) | |
1526 | { | |
1527 | /* We're storing the current CFA reg into the stack. */ | |
1528 | ||
1529 | if (cfa.offset == 0) | |
1530 | { | |
1531 | /* If the source register is exactly the CFA, assume | |
1532 | we're saving SP like any other register; this happens | |
1533 | on the ARM. */ | |
1534 | ||
1535 | def_cfa_1 (label, &cfa); | |
fbfa55b0 | 1536 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1537 | break; |
1538 | } | |
1539 | else | |
1540 | { | |
1541 | /* Otherwise, we'll need to look in the stack to | |
1542 | calculate the CFA. */ | |
1543 | ||
1544 | rtx x = XEXP (dest, 0); | |
1545 | if (GET_CODE (x) != REG) | |
1546 | x = XEXP (x, 0); | |
1547 | if (GET_CODE (x) != REG) | |
1548 | abort (); | |
1549 | cfa.reg = (unsigned) REGNO (x); | |
1550 | cfa.base_offset = offset; | |
1551 | cfa.indirect = 1; | |
1552 | def_cfa_1 (label, &cfa); | |
1553 | break; | |
1554 | } | |
1555 | } | |
1556 | ||
7d9d8943 | 1557 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1558 | queue_reg_save (label, src, offset); |
2618f955 MM |
1559 | break; |
1560 | ||
1561 | default: | |
1562 | abort (); | |
1563 | } | |
b664de3a AM |
1564 | } |
1565 | ||
3f76745e JM |
1566 | /* Record call frame debugging information for INSN, which either |
1567 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1568 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1569 | |
3f76745e JM |
1570 | void |
1571 | dwarf2out_frame_debug (insn) | |
1572 | rtx insn; | |
a3f97cbb | 1573 | { |
d3e3972c | 1574 | const char *label; |
b664de3a | 1575 | rtx src; |
3f76745e JM |
1576 | |
1577 | if (insn == NULL_RTX) | |
a3f97cbb | 1578 | { |
fbfa55b0 RH |
1579 | /* Flush any queued register saves. */ |
1580 | flush_queued_reg_saves (); | |
1581 | ||
3f76745e | 1582 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1583 | lookup_cfa (&cfa); |
1584 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1585 | abort (); |
7d9d8943 AM |
1586 | cfa.reg = STACK_POINTER_REGNUM; |
1587 | cfa_store = cfa; | |
770ca8c6 JO |
1588 | cfa_temp.reg = -1; |
1589 | cfa_temp.offset = 0; | |
3f76745e JM |
1590 | return; |
1591 | } | |
1592 | ||
fbfa55b0 RH |
1593 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1594 | flush_queued_reg_saves (); | |
1595 | ||
0021b564 JM |
1596 | if (! RTX_FRAME_RELATED_P (insn)) |
1597 | { | |
fbfa55b0 RH |
1598 | if (!ACCUMULATE_OUTGOING_ARGS) |
1599 | dwarf2out_stack_adjust (insn); | |
0021b564 JM |
1600 | return; |
1601 | } | |
1602 | ||
3f76745e | 1603 | label = dwarf2out_cfi_label (); |
556273e0 | 1604 | |
07ebc930 RH |
1605 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1606 | if (src) | |
1607 | insn = XEXP (src, 0); | |
556273e0 | 1608 | else |
07ebc930 RH |
1609 | insn = PATTERN (insn); |
1610 | ||
b664de3a | 1611 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1612 | } |
1613 | ||
3f76745e JM |
1614 | /* Output a Call Frame Information opcode and its operand(s). */ |
1615 | ||
1616 | static void | |
12f0b96b | 1617 | output_cfi (cfi, fde, for_eh) |
3f76745e JM |
1618 | register dw_cfi_ref cfi; |
1619 | register dw_fde_ref fde; | |
12f0b96b | 1620 | int for_eh; |
3f76745e JM |
1621 | { |
1622 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1623 | { | |
2e4b9b8c RH |
1624 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1625 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1626 | "DW_CFA_advance_loc 0x%lx", | |
1627 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e | 1628 | } |
3f76745e JM |
1629 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1630 | { | |
2e4b9b8c RH |
1631 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1632 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1633 | "DW_CFA_offset, column 0x%lx", | |
1634 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1635 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1636 | } |
1637 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1638 | { | |
2e4b9b8c RH |
1639 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1640 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1641 | "DW_CFA_restore, column 0x%lx", | |
1642 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1643 | } |
1644 | else | |
1645 | { | |
2e4b9b8c RH |
1646 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1647 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1648 | |
3f76745e JM |
1649 | switch (cfi->dw_cfi_opc) |
1650 | { | |
1651 | case DW_CFA_set_loc: | |
e1f9550a RH |
1652 | if (for_eh) |
1653 | dw2_asm_output_encoded_addr_rtx ( | |
1654 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1655 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1656 | NULL); | |
1657 | else | |
1658 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1659 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e JM |
1660 | break; |
1661 | case DW_CFA_advance_loc1: | |
2e4b9b8c RH |
1662 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1663 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1664 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e JM |
1665 | break; |
1666 | case DW_CFA_advance_loc2: | |
2e4b9b8c RH |
1667 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1668 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1669 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1670 | break; | |
1671 | case DW_CFA_advance_loc4: | |
2e4b9b8c RH |
1672 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1673 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1674 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1675 | break; | |
3f76745e | 1676 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1677 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1678 | fde->dw_fde_current_label, NULL); | |
1679 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1680 | break; |
3f76745e | 1681 | case DW_CFA_offset_extended: |
3f388b42 | 1682 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e | 1683 | case DW_CFA_def_cfa: |
2e4b9b8c RH |
1684 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1685 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1686 | break; |
1687 | case DW_CFA_restore_extended: | |
1688 | case DW_CFA_undefined: | |
3f76745e JM |
1689 | case DW_CFA_same_value: |
1690 | case DW_CFA_def_cfa_register: | |
2e4b9b8c | 1691 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
3f76745e JM |
1692 | break; |
1693 | case DW_CFA_register: | |
2e4b9b8c RH |
1694 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1695 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL); | |
3f76745e JM |
1696 | break; |
1697 | case DW_CFA_def_cfa_offset: | |
2e4b9b8c RH |
1698 | case DW_CFA_GNU_args_size: |
1699 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1700 | break; |
c53aa195 JM |
1701 | case DW_CFA_GNU_window_save: |
1702 | break; | |
7d9d8943 AM |
1703 | case DW_CFA_def_cfa_expression: |
1704 | output_cfa_loc (cfi); | |
1705 | break; | |
3f76745e JM |
1706 | default: |
1707 | break; | |
1708 | } | |
556273e0 | 1709 | } |
3f76745e JM |
1710 | } |
1711 | ||
1712 | /* Output the call frame information used to used to record information | |
1713 | that relates to calculating the frame pointer, and records the | |
1714 | location of saved registers. */ | |
1715 | ||
1716 | static void | |
1717 | output_call_frame_info (for_eh) | |
1718 | int for_eh; | |
1719 | { | |
2d8b0f3a | 1720 | register unsigned long i; |
3f76745e | 1721 | register dw_fde_ref fde; |
3f76745e | 1722 | register dw_cfi_ref cfi; |
a6ab3aad | 1723 | char l1[20], l2[20]; |
52a11cbf RH |
1724 | int any_lsda_needed = 0; |
1725 | char augmentation[6]; | |
e1f9550a RH |
1726 | int augmentation_size; |
1727 | int fde_encoding = DW_EH_PE_absptr; | |
1728 | int per_encoding = DW_EH_PE_absptr; | |
1729 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1730 | |
737faf14 JM |
1731 | /* If we don't have any functions we'll want to unwind out of, don't |
1732 | emit any EH unwind information. */ | |
1733 | if (for_eh) | |
1734 | { | |
52a11cbf | 1735 | int any_eh_needed = 0; |
737faf14 | 1736 | for (i = 0; i < fde_table_in_use; ++i) |
52a11cbf RH |
1737 | if (fde_table[i].uses_eh_lsda) |
1738 | any_eh_needed = any_lsda_needed = 1; | |
1739 | else if (! fde_table[i].nothrow) | |
1740 | any_eh_needed = 1; | |
1741 | ||
1742 | if (! any_eh_needed) | |
1743 | return; | |
737faf14 JM |
1744 | } |
1745 | ||
aa0c1401 JL |
1746 | /* We're going to be generating comments, so turn on app. */ |
1747 | if (flag_debug_asm) | |
1748 | app_enable (); | |
956d6950 | 1749 | |
3f76745e JM |
1750 | if (for_eh) |
1751 | { | |
1752 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1753 | EH_FRAME_SECTION (); |
3f76745e | 1754 | #else |
496651db | 1755 | tree label = get_file_function_name ('F'); |
0021b564 | 1756 | |
3167de5b | 1757 | force_data_section (); |
12f0b96b | 1758 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
0021b564 JM |
1759 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1760 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1761 | #endif |
1762 | assemble_label ("__FRAME_BEGIN__"); | |
1763 | } | |
1764 | else | |
cf2fe500 | 1765 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION); |
3f76745e | 1766 | |
556273e0 | 1767 | /* Output the CIE. */ |
a6ab3aad JM |
1768 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1769 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1770 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1771 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1772 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1773 | ||
2e4b9b8c RH |
1774 | /* Now that the CIE pointer is PC-relative for EH, |
1775 | use 0 to identify the CIE. */ | |
1776 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1777 | (for_eh ? 0 : DW_CIE_ID), | |
1778 | "CIE Identifier Tag"); | |
3f76745e | 1779 | |
2e4b9b8c | 1780 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1781 | |
52a11cbf | 1782 | augmentation[0] = 0; |
e1f9550a | 1783 | augmentation_size = 0; |
52a11cbf | 1784 | if (for_eh) |
a6ab3aad | 1785 | { |
e1f9550a RH |
1786 | char *p; |
1787 | ||
52a11cbf RH |
1788 | /* Augmentation: |
1789 | z Indicates that a uleb128 is present to size the | |
1790 | augmentation section. | |
e1f9550a RH |
1791 | L Indicates the encoding (and thus presence) of |
1792 | an LSDA pointer in the FDE augmentation. | |
1793 | R Indicates a non-default pointer encoding for | |
1794 | FDE code pointers. | |
1795 | P Indicates the presence of an encoding + language | |
1796 | personality routine in the CIE augmentation. */ | |
1797 | ||
1798 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1799 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1800 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1801 | ||
1802 | p = augmentation + 1; | |
1803 | if (eh_personality_libfunc) | |
1804 | { | |
1805 | *p++ = 'P'; | |
1806 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1807 | } | |
52a11cbf | 1808 | if (any_lsda_needed) |
e1f9550a RH |
1809 | { |
1810 | *p++ = 'L'; | |
1811 | augmentation_size += 1; | |
1812 | } | |
1813 | if (fde_encoding != DW_EH_PE_absptr) | |
1814 | { | |
1815 | *p++ = 'R'; | |
1816 | augmentation_size += 1; | |
1817 | } | |
1818 | if (p > augmentation + 1) | |
1819 | { | |
1820 | augmentation[0] = 'z'; | |
1821 | *p = '\0'; | |
1822 | } | |
099c8b17 RH |
1823 | |
1824 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1825 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1826 | { | |
1827 | int offset = ( 4 /* Length */ | |
1828 | + 4 /* CIE Id */ | |
1829 | + 1 /* CIE version */ | |
1830 | + strlen (augmentation) + 1 /* Augmentation */ | |
1831 | + size_of_uleb128 (1) /* Code alignment */ | |
1832 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1833 | + 1 /* RA column */ | |
1834 | + 1 /* Augmentation size */ | |
1835 | + 1 /* Personality encoding */ ); | |
1836 | int pad = -offset & (PTR_SIZE - 1); | |
1837 | ||
1838 | augmentation_size += pad; | |
1839 | ||
1840 | /* Augmentations should be small, so there's scarce need to | |
1841 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1842 | if (size_of_uleb128 (augmentation_size) != 1) | |
1843 | abort (); | |
1844 | } | |
a6ab3aad | 1845 | } |
52a11cbf | 1846 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
3f76745e | 1847 | |
2e4b9b8c | 1848 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
3f76745e | 1849 | |
2e4b9b8c RH |
1850 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1851 | "CIE Data Alignment Factor"); | |
3f76745e | 1852 | |
2e4b9b8c | 1853 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1854 | |
52a11cbf RH |
1855 | if (augmentation[0]) |
1856 | { | |
e1f9550a | 1857 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1858 | if (eh_personality_libfunc) |
e1f9550a RH |
1859 | { |
1860 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1861 | eh_data_format_name (per_encoding)); | |
1862 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1863 | eh_personality_libfunc, NULL); | |
1864 | } | |
1865 | if (any_lsda_needed) | |
1866 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1867 | eh_data_format_name (lsda_encoding)); | |
1868 | if (fde_encoding != DW_EH_PE_absptr) | |
1869 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1870 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1871 | } |
1872 | ||
3f76745e | 1873 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1874 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1875 | |
1876 | /* Pad the CIE out to an address sized boundary. */ | |
12f0b96b AM |
1877 | ASM_OUTPUT_ALIGN (asm_out_file, |
1878 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); | |
a6ab3aad | 1879 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1880 | |
1881 | /* Loop through all of the FDE's. */ | |
1882 | for (i = 0; i < fde_table_in_use; ++i) | |
1883 | { | |
1884 | fde = &fde_table[i]; | |
3f76745e | 1885 | |
52a11cbf RH |
1886 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
1887 | if (for_eh && fde->nothrow && ! fde->uses_eh_lsda) | |
737faf14 JM |
1888 | continue; |
1889 | ||
2e4b9b8c | 1890 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1891 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1892 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1893 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1894 | "FDE Length"); | |
a6ab3aad JM |
1895 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1896 | ||
eef906d6 JW |
1897 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1898 | emits a target dependent sized offset when for_eh is not true. | |
1899 | This inconsistency may confuse gdb. The only case where we need a | |
1900 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1901 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1902 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1903 | If the for_eh case is changed, then the struct in frame.c has | |
1904 | to be adjusted appropriately. */ | |
3f76745e | 1905 | if (for_eh) |
2e4b9b8c | 1906 | dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset"); |
3f76745e | 1907 | else |
2e4b9b8c | 1908 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, |
cf2fe500 | 1909 | stripattributes (DEBUG_FRAME_SECTION), |
2e4b9b8c | 1910 | "FDE CIE offset"); |
3f76745e | 1911 | |
e1f9550a RH |
1912 | if (for_eh) |
1913 | { | |
1914 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1915 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1916 | "FDE initial location"); | |
1917 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
1918 | fde->dw_fde_end, fde->dw_fde_begin, | |
1919 | "FDE address range"); | |
1920 | } | |
1921 | else | |
1922 | { | |
1923 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
1924 | "FDE initial location"); | |
1925 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
1926 | fde->dw_fde_end, fde->dw_fde_begin, | |
1927 | "FDE address range"); | |
1928 | } | |
3f76745e | 1929 | |
52a11cbf RH |
1930 | if (augmentation[0]) |
1931 | { | |
e1f9550a | 1932 | if (any_lsda_needed) |
52a11cbf | 1933 | { |
099c8b17 RH |
1934 | int size = size_of_encoded_value (lsda_encoding); |
1935 | ||
1936 | if (lsda_encoding == DW_EH_PE_aligned) | |
1937 | { | |
1938 | int offset = ( 4 /* Length */ | |
1939 | + 4 /* CIE offset */ | |
1940 | + 2 * size_of_encoded_value (fde_encoding) | |
1941 | + 1 /* Augmentation size */ ); | |
1942 | int pad = -offset & (PTR_SIZE - 1); | |
1943 | ||
1944 | size += pad; | |
1945 | if (size_of_uleb128 (size) != 1) | |
1946 | abort (); | |
1947 | } | |
1948 | ||
1949 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
1950 | |
1951 | if (fde->uses_eh_lsda) | |
1952 | { | |
1953 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
1954 | fde->funcdef_number); | |
1955 | dw2_asm_output_encoded_addr_rtx ( | |
1956 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
1957 | "Language Specific Data Area"); | |
1958 | } | |
1959 | else | |
099c8b17 RH |
1960 | { |
1961 | if (lsda_encoding == DW_EH_PE_aligned) | |
1962 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1963 | dw2_asm_output_data (size_of_encoded_value (lsda_encoding), | |
1964 | 0, "Language Specific Data Area (none)"); | |
1965 | } | |
52a11cbf RH |
1966 | } |
1967 | else | |
e1f9550a | 1968 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
1969 | } |
1970 | ||
3f76745e JM |
1971 | /* Loop through the Call Frame Instructions associated with |
1972 | this FDE. */ | |
1973 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1974 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 1975 | output_cfi (cfi, fde, for_eh); |
3f76745e | 1976 | |
a6ab3aad | 1977 | /* Pad the FDE out to an address sized boundary. */ |
12f0b96b | 1978 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 1979 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 1980 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 1981 | } |
2e4b9b8c | 1982 | |
3f76745e JM |
1983 | #ifndef EH_FRAME_SECTION |
1984 | if (for_eh) | |
2e4b9b8c | 1985 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 1986 | #endif |
a6ab3aad JM |
1987 | #ifdef MIPS_DEBUGGING_INFO |
1988 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1989 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1990 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1991 | #endif | |
aa0c1401 JL |
1992 | |
1993 | /* Turn off app to make assembly quicker. */ | |
1994 | if (flag_debug_asm) | |
1995 | app_disable (); | |
a6ab3aad JM |
1996 | } |
1997 | ||
3f76745e JM |
1998 | /* Output a marker (i.e. a label) for the beginning of a function, before |
1999 | the prologue. */ | |
2000 | ||
2001 | void | |
2002 | dwarf2out_begin_prologue () | |
2003 | { | |
2004 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2005 | register dw_fde_ref fde; | |
2006 | ||
2a1ee410 RH |
2007 | current_function_func_begin_label = 0; |
2008 | ||
2009 | #ifdef IA64_UNWIND_INFO | |
2010 | /* ??? current_function_func_begin_label is also used by except.c | |
2011 | for call-site information. We must emit this label if it might | |
2012 | be used. */ | |
2013 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2014 | && ! dwarf2out_do_frame ()) | |
2015 | return; | |
2016 | #else | |
2017 | if (! dwarf2out_do_frame ()) | |
2018 | return; | |
2019 | #endif | |
2020 | ||
4f988ea2 JM |
2021 | ++current_funcdef_number; |
2022 | ||
3f76745e JM |
2023 | function_section (current_function_decl); |
2024 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2025 | current_funcdef_number); | |
2a1ee410 RH |
2026 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2027 | current_funcdef_number); | |
00262c8a | 2028 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2029 | |
2a1ee410 RH |
2030 | #ifdef IA64_UNWIND_INFO |
2031 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2032 | if (! dwarf2out_do_frame ()) | |
2033 | return; | |
2034 | #endif | |
2035 | ||
3f76745e JM |
2036 | /* Expand the fde table if necessary. */ |
2037 | if (fde_table_in_use == fde_table_allocated) | |
2038 | { | |
2039 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2040 | fde_table | |
2041 | = (dw_fde_ref) xrealloc (fde_table, | |
2042 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2043 | } |
3f76745e JM |
2044 | |
2045 | /* Record the FDE associated with this function. */ | |
2046 | current_funcdef_fde = fde_table_in_use; | |
2047 | ||
2048 | /* Add the new FDE at the end of the fde_table. */ | |
2049 | fde = &fde_table[fde_table_in_use++]; | |
2050 | fde->dw_fde_begin = xstrdup (label); | |
2051 | fde->dw_fde_current_label = NULL; | |
2052 | fde->dw_fde_end = NULL; | |
2053 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2054 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2055 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2056 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2057 | |
b57d9225 | 2058 | args_size = old_args_size = 0; |
3f76745e JM |
2059 | } |
2060 | ||
2061 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2062 | for a function definition. This gets called *after* the epilogue code has | |
2063 | been generated. */ | |
2064 | ||
2065 | void | |
2066 | dwarf2out_end_epilogue () | |
2067 | { | |
2068 | dw_fde_ref fde; | |
2069 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2070 | ||
2071 | /* Output a label to mark the endpoint of the code generated for this | |
2072 | function. */ | |
2073 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
2074 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2075 | fde = &fde_table[fde_table_in_use - 1]; | |
2076 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2077 | } |
2078 | ||
2079 | void | |
2080 | dwarf2out_frame_init () | |
2081 | { | |
2082 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2083 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2084 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2085 | fde_table_in_use = 0; | |
2086 | ||
2087 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2088 | sake of lookup_cfa. */ | |
2089 | ||
a6ab3aad | 2090 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2091 | /* On entry, the Canonical Frame Address is at SP. */ |
2092 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2093 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2094 | #endif |
2095 | } | |
2096 | ||
2097 | void | |
2098 | dwarf2out_frame_finish () | |
2099 | { | |
3f76745e | 2100 | /* Output call frame information. */ |
a6ab3aad | 2101 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
2102 | if (write_symbols == DWARF2_DEBUG) |
2103 | output_call_frame_info (0); | |
531073e7 | 2104 | if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)) |
3f76745e | 2105 | output_call_frame_info (1); |
a6ab3aad JM |
2106 | #else |
2107 | if (write_symbols == DWARF2_DEBUG | |
531073e7 | 2108 | || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)) |
556273e0 | 2109 | output_call_frame_info (1); |
a6ab3aad | 2110 | #endif |
556273e0 | 2111 | } |
7d9d8943 AM |
2112 | \f |
2113 | /* And now, the subset of the debugging information support code necessary | |
2114 | for emitting location expressions. */ | |
3f76745e | 2115 | |
7d9d8943 AM |
2116 | typedef struct dw_val_struct *dw_val_ref; |
2117 | typedef struct die_struct *dw_die_ref; | |
2118 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2119 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2120 | |
2121 | /* Each DIE may have a series of attribute/value pairs. Values | |
2122 | can take on several forms. The forms that are used in this | |
2123 | implementation are listed below. */ | |
2124 | ||
2125 | typedef enum | |
2126 | { | |
2127 | dw_val_class_addr, | |
2128 | dw_val_class_loc, | |
63e46568 | 2129 | dw_val_class_loc_list, |
3f76745e JM |
2130 | dw_val_class_const, |
2131 | dw_val_class_unsigned_const, | |
2132 | dw_val_class_long_long, | |
2133 | dw_val_class_float, | |
2134 | dw_val_class_flag, | |
2135 | dw_val_class_die_ref, | |
2136 | dw_val_class_fde_ref, | |
2137 | dw_val_class_lbl_id, | |
8b790721 | 2138 | dw_val_class_lbl_offset, |
3f76745e | 2139 | dw_val_class_str |
a3f97cbb | 2140 | } |
3f76745e | 2141 | dw_val_class; |
a3f97cbb | 2142 | |
3f76745e | 2143 | /* Describe a double word constant value. */ |
21217bd0 | 2144 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2145 | |
2146 | typedef struct dw_long_long_struct | |
a3f97cbb | 2147 | { |
3f76745e JM |
2148 | unsigned long hi; |
2149 | unsigned long low; | |
2150 | } | |
2151 | dw_long_long_const; | |
2152 | ||
2153 | /* Describe a floating point constant value. */ | |
2154 | ||
2155 | typedef struct dw_fp_struct | |
2156 | { | |
2157 | long *array; | |
2158 | unsigned length; | |
2159 | } | |
2160 | dw_float_const; | |
2161 | ||
956d6950 | 2162 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2163 | represented internally. */ |
2164 | ||
2165 | typedef struct dw_val_struct | |
2166 | { | |
2167 | dw_val_class val_class; | |
2168 | union | |
a3f97cbb | 2169 | { |
1865dbb5 | 2170 | rtx val_addr; |
63e46568 | 2171 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2172 | dw_loc_descr_ref val_loc; |
2173 | long int val_int; | |
2174 | long unsigned val_unsigned; | |
2175 | dw_long_long_const val_long_long; | |
2176 | dw_float_const val_float; | |
881c6935 JM |
2177 | struct { |
2178 | dw_die_ref die; | |
2179 | int external; | |
2180 | } val_die_ref; | |
3f76745e JM |
2181 | unsigned val_fde_index; |
2182 | char *val_str; | |
2183 | char *val_lbl_id; | |
3f76745e | 2184 | unsigned char val_flag; |
a3f97cbb | 2185 | } |
3f76745e JM |
2186 | v; |
2187 | } | |
2188 | dw_val_node; | |
2189 | ||
2190 | /* Locations in memory are described using a sequence of stack machine | |
2191 | operations. */ | |
2192 | ||
2193 | typedef struct dw_loc_descr_struct | |
2194 | { | |
2195 | dw_loc_descr_ref dw_loc_next; | |
2196 | enum dwarf_location_atom dw_loc_opc; | |
2197 | dw_val_node dw_loc_oprnd1; | |
2198 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2199 | int dw_loc_addr; |
3f76745e JM |
2200 | } |
2201 | dw_loc_descr_node; | |
2202 | ||
63e46568 DB |
2203 | /* Location lists are ranges + location descriptions for that range, |
2204 | so you can track variables that are in different places over | |
2205 | their entire life. */ | |
2206 | typedef struct dw_loc_list_struct | |
2207 | { | |
2208 | dw_loc_list_ref dw_loc_next; | |
2209 | const char *begin; /* Label for begin address of range */ | |
2210 | const char *end; /* Label for end address of range */ | |
2211 | char *ll_symbol; /* Label for beginning of location list. Only on head of list */ | |
2212 | const char *section; /* Section this loclist is relative to */ | |
2213 | dw_loc_descr_ref expr; | |
2214 | } dw_loc_list_node; | |
2215 | ||
7d9d8943 AM |
2216 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2217 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2218 | unsigned long, | |
2219 | unsigned long)); | |
2220 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2221 | dw_loc_descr_ref)); | |
2222 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2223 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2224 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2225 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2226 | |
63e46568 DB |
2227 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
2228 | const char *, const char *, | |
2229 | const char *, unsigned)); | |
2230 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
2231 | dw_loc_descr_ref, | |
2232 | const char *, const char *, const char *)); | |
2233 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
2234 | static char *gen_internal_sym PARAMS ((const char *)); | |
7d9d8943 | 2235 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2236 | |
7d9d8943 AM |
2237 | static const char * |
2238 | dwarf_stack_op_name (op) | |
2239 | register unsigned op; | |
ef76d03b | 2240 | { |
7d9d8943 AM |
2241 | switch (op) |
2242 | { | |
2243 | case DW_OP_addr: | |
2244 | return "DW_OP_addr"; | |
2245 | case DW_OP_deref: | |
2246 | return "DW_OP_deref"; | |
2247 | case DW_OP_const1u: | |
2248 | return "DW_OP_const1u"; | |
2249 | case DW_OP_const1s: | |
2250 | return "DW_OP_const1s"; | |
2251 | case DW_OP_const2u: | |
2252 | return "DW_OP_const2u"; | |
2253 | case DW_OP_const2s: | |
2254 | return "DW_OP_const2s"; | |
2255 | case DW_OP_const4u: | |
2256 | return "DW_OP_const4u"; | |
2257 | case DW_OP_const4s: | |
2258 | return "DW_OP_const4s"; | |
2259 | case DW_OP_const8u: | |
2260 | return "DW_OP_const8u"; | |
2261 | case DW_OP_const8s: | |
2262 | return "DW_OP_const8s"; | |
2263 | case DW_OP_constu: | |
2264 | return "DW_OP_constu"; | |
2265 | case DW_OP_consts: | |
2266 | return "DW_OP_consts"; | |
2267 | case DW_OP_dup: | |
2268 | return "DW_OP_dup"; | |
2269 | case DW_OP_drop: | |
2270 | return "DW_OP_drop"; | |
2271 | case DW_OP_over: | |
2272 | return "DW_OP_over"; | |
2273 | case DW_OP_pick: | |
2274 | return "DW_OP_pick"; | |
2275 | case DW_OP_swap: | |
2276 | return "DW_OP_swap"; | |
2277 | case DW_OP_rot: | |
2278 | return "DW_OP_rot"; | |
2279 | case DW_OP_xderef: | |
2280 | return "DW_OP_xderef"; | |
2281 | case DW_OP_abs: | |
2282 | return "DW_OP_abs"; | |
2283 | case DW_OP_and: | |
2284 | return "DW_OP_and"; | |
2285 | case DW_OP_div: | |
2286 | return "DW_OP_div"; | |
2287 | case DW_OP_minus: | |
2288 | return "DW_OP_minus"; | |
2289 | case DW_OP_mod: | |
2290 | return "DW_OP_mod"; | |
2291 | case DW_OP_mul: | |
2292 | return "DW_OP_mul"; | |
2293 | case DW_OP_neg: | |
2294 | return "DW_OP_neg"; | |
2295 | case DW_OP_not: | |
2296 | return "DW_OP_not"; | |
2297 | case DW_OP_or: | |
2298 | return "DW_OP_or"; | |
2299 | case DW_OP_plus: | |
2300 | return "DW_OP_plus"; | |
2301 | case DW_OP_plus_uconst: | |
2302 | return "DW_OP_plus_uconst"; | |
2303 | case DW_OP_shl: | |
2304 | return "DW_OP_shl"; | |
2305 | case DW_OP_shr: | |
2306 | return "DW_OP_shr"; | |
2307 | case DW_OP_shra: | |
2308 | return "DW_OP_shra"; | |
2309 | case DW_OP_xor: | |
2310 | return "DW_OP_xor"; | |
2311 | case DW_OP_bra: | |
2312 | return "DW_OP_bra"; | |
2313 | case DW_OP_eq: | |
2314 | return "DW_OP_eq"; | |
2315 | case DW_OP_ge: | |
2316 | return "DW_OP_ge"; | |
2317 | case DW_OP_gt: | |
2318 | return "DW_OP_gt"; | |
2319 | case DW_OP_le: | |
2320 | return "DW_OP_le"; | |
2321 | case DW_OP_lt: | |
2322 | return "DW_OP_lt"; | |
2323 | case DW_OP_ne: | |
2324 | return "DW_OP_ne"; | |
2325 | case DW_OP_skip: | |
2326 | return "DW_OP_skip"; | |
2327 | case DW_OP_lit0: | |
2328 | return "DW_OP_lit0"; | |
2329 | case DW_OP_lit1: | |
2330 | return "DW_OP_lit1"; | |
2331 | case DW_OP_lit2: | |
2332 | return "DW_OP_lit2"; | |
2333 | case DW_OP_lit3: | |
2334 | return "DW_OP_lit3"; | |
2335 | case DW_OP_lit4: | |
2336 | return "DW_OP_lit4"; | |
2337 | case DW_OP_lit5: | |
2338 | return "DW_OP_lit5"; | |
2339 | case DW_OP_lit6: | |
2340 | return "DW_OP_lit6"; | |
2341 | case DW_OP_lit7: | |
2342 | return "DW_OP_lit7"; | |
2343 | case DW_OP_lit8: | |
2344 | return "DW_OP_lit8"; | |
2345 | case DW_OP_lit9: | |
2346 | return "DW_OP_lit9"; | |
2347 | case DW_OP_lit10: | |
2348 | return "DW_OP_lit10"; | |
2349 | case DW_OP_lit11: | |
2350 | return "DW_OP_lit11"; | |
2351 | case DW_OP_lit12: | |
2352 | return "DW_OP_lit12"; | |
2353 | case DW_OP_lit13: | |
2354 | return "DW_OP_lit13"; | |
2355 | case DW_OP_lit14: | |
2356 | return "DW_OP_lit14"; | |
2357 | case DW_OP_lit15: | |
2358 | return "DW_OP_lit15"; | |
2359 | case DW_OP_lit16: | |
2360 | return "DW_OP_lit16"; | |
2361 | case DW_OP_lit17: | |
2362 | return "DW_OP_lit17"; | |
2363 | case DW_OP_lit18: | |
2364 | return "DW_OP_lit18"; | |
2365 | case DW_OP_lit19: | |
2366 | return "DW_OP_lit19"; | |
2367 | case DW_OP_lit20: | |
2368 | return "DW_OP_lit20"; | |
2369 | case DW_OP_lit21: | |
2370 | return "DW_OP_lit21"; | |
2371 | case DW_OP_lit22: | |
2372 | return "DW_OP_lit22"; | |
2373 | case DW_OP_lit23: | |
2374 | return "DW_OP_lit23"; | |
2375 | case DW_OP_lit24: | |
2376 | return "DW_OP_lit24"; | |
2377 | case DW_OP_lit25: | |
2378 | return "DW_OP_lit25"; | |
2379 | case DW_OP_lit26: | |
2380 | return "DW_OP_lit26"; | |
2381 | case DW_OP_lit27: | |
2382 | return "DW_OP_lit27"; | |
2383 | case DW_OP_lit28: | |
2384 | return "DW_OP_lit28"; | |
2385 | case DW_OP_lit29: | |
2386 | return "DW_OP_lit29"; | |
2387 | case DW_OP_lit30: | |
2388 | return "DW_OP_lit30"; | |
2389 | case DW_OP_lit31: | |
2390 | return "DW_OP_lit31"; | |
2391 | case DW_OP_reg0: | |
2392 | return "DW_OP_reg0"; | |
2393 | case DW_OP_reg1: | |
2394 | return "DW_OP_reg1"; | |
2395 | case DW_OP_reg2: | |
2396 | return "DW_OP_reg2"; | |
2397 | case DW_OP_reg3: | |
2398 | return "DW_OP_reg3"; | |
2399 | case DW_OP_reg4: | |
2400 | return "DW_OP_reg4"; | |
2401 | case DW_OP_reg5: | |
2402 | return "DW_OP_reg5"; | |
2403 | case DW_OP_reg6: | |
2404 | return "DW_OP_reg6"; | |
2405 | case DW_OP_reg7: | |
2406 | return "DW_OP_reg7"; | |
2407 | case DW_OP_reg8: | |
2408 | return "DW_OP_reg8"; | |
2409 | case DW_OP_reg9: | |
2410 | return "DW_OP_reg9"; | |
2411 | case DW_OP_reg10: | |
2412 | return "DW_OP_reg10"; | |
2413 | case DW_OP_reg11: | |
2414 | return "DW_OP_reg11"; | |
2415 | case DW_OP_reg12: | |
2416 | return "DW_OP_reg12"; | |
2417 | case DW_OP_reg13: | |
2418 | return "DW_OP_reg13"; | |
2419 | case DW_OP_reg14: | |
2420 | return "DW_OP_reg14"; | |
2421 | case DW_OP_reg15: | |
2422 | return "DW_OP_reg15"; | |
2423 | case DW_OP_reg16: | |
2424 | return "DW_OP_reg16"; | |
2425 | case DW_OP_reg17: | |
2426 | return "DW_OP_reg17"; | |
2427 | case DW_OP_reg18: | |
2428 | return "DW_OP_reg18"; | |
2429 | case DW_OP_reg19: | |
2430 | return "DW_OP_reg19"; | |
2431 | case DW_OP_reg20: | |
2432 | return "DW_OP_reg20"; | |
2433 | case DW_OP_reg21: | |
2434 | return "DW_OP_reg21"; | |
2435 | case DW_OP_reg22: | |
2436 | return "DW_OP_reg22"; | |
2437 | case DW_OP_reg23: | |
2438 | return "DW_OP_reg23"; | |
2439 | case DW_OP_reg24: | |
2440 | return "DW_OP_reg24"; | |
2441 | case DW_OP_reg25: | |
2442 | return "DW_OP_reg25"; | |
2443 | case DW_OP_reg26: | |
2444 | return "DW_OP_reg26"; | |
2445 | case DW_OP_reg27: | |
2446 | return "DW_OP_reg27"; | |
2447 | case DW_OP_reg28: | |
2448 | return "DW_OP_reg28"; | |
2449 | case DW_OP_reg29: | |
2450 | return "DW_OP_reg29"; | |
2451 | case DW_OP_reg30: | |
2452 | return "DW_OP_reg30"; | |
2453 | case DW_OP_reg31: | |
2454 | return "DW_OP_reg31"; | |
2455 | case DW_OP_breg0: | |
2456 | return "DW_OP_breg0"; | |
2457 | case DW_OP_breg1: | |
2458 | return "DW_OP_breg1"; | |
2459 | case DW_OP_breg2: | |
2460 | return "DW_OP_breg2"; | |
2461 | case DW_OP_breg3: | |
2462 | return "DW_OP_breg3"; | |
2463 | case DW_OP_breg4: | |
2464 | return "DW_OP_breg4"; | |
2465 | case DW_OP_breg5: | |
2466 | return "DW_OP_breg5"; | |
2467 | case DW_OP_breg6: | |
2468 | return "DW_OP_breg6"; | |
2469 | case DW_OP_breg7: | |
2470 | return "DW_OP_breg7"; | |
2471 | case DW_OP_breg8: | |
2472 | return "DW_OP_breg8"; | |
2473 | case DW_OP_breg9: | |
2474 | return "DW_OP_breg9"; | |
2475 | case DW_OP_breg10: | |
2476 | return "DW_OP_breg10"; | |
2477 | case DW_OP_breg11: | |
2478 | return "DW_OP_breg11"; | |
2479 | case DW_OP_breg12: | |
2480 | return "DW_OP_breg12"; | |
2481 | case DW_OP_breg13: | |
2482 | return "DW_OP_breg13"; | |
2483 | case DW_OP_breg14: | |
2484 | return "DW_OP_breg14"; | |
2485 | case DW_OP_breg15: | |
2486 | return "DW_OP_breg15"; | |
2487 | case DW_OP_breg16: | |
2488 | return "DW_OP_breg16"; | |
2489 | case DW_OP_breg17: | |
2490 | return "DW_OP_breg17"; | |
2491 | case DW_OP_breg18: | |
2492 | return "DW_OP_breg18"; | |
2493 | case DW_OP_breg19: | |
2494 | return "DW_OP_breg19"; | |
2495 | case DW_OP_breg20: | |
2496 | return "DW_OP_breg20"; | |
2497 | case DW_OP_breg21: | |
2498 | return "DW_OP_breg21"; | |
2499 | case DW_OP_breg22: | |
2500 | return "DW_OP_breg22"; | |
2501 | case DW_OP_breg23: | |
2502 | return "DW_OP_breg23"; | |
2503 | case DW_OP_breg24: | |
2504 | return "DW_OP_breg24"; | |
2505 | case DW_OP_breg25: | |
2506 | return "DW_OP_breg25"; | |
2507 | case DW_OP_breg26: | |
2508 | return "DW_OP_breg26"; | |
2509 | case DW_OP_breg27: | |
2510 | return "DW_OP_breg27"; | |
2511 | case DW_OP_breg28: | |
2512 | return "DW_OP_breg28"; | |
2513 | case DW_OP_breg29: | |
2514 | return "DW_OP_breg29"; | |
2515 | case DW_OP_breg30: | |
2516 | return "DW_OP_breg30"; | |
2517 | case DW_OP_breg31: | |
2518 | return "DW_OP_breg31"; | |
2519 | case DW_OP_regx: | |
2520 | return "DW_OP_regx"; | |
2521 | case DW_OP_fbreg: | |
2522 | return "DW_OP_fbreg"; | |
2523 | case DW_OP_bregx: | |
2524 | return "DW_OP_bregx"; | |
2525 | case DW_OP_piece: | |
2526 | return "DW_OP_piece"; | |
2527 | case DW_OP_deref_size: | |
2528 | return "DW_OP_deref_size"; | |
2529 | case DW_OP_xderef_size: | |
2530 | return "DW_OP_xderef_size"; | |
2531 | case DW_OP_nop: | |
2532 | return "DW_OP_nop"; | |
3f76745e | 2533 | default: |
7d9d8943 | 2534 | return "OP_<unknown>"; |
3f76745e | 2535 | } |
bdb669cb | 2536 | } |
a3f97cbb | 2537 | |
7d9d8943 AM |
2538 | /* Return a pointer to a newly allocated location description. Location |
2539 | descriptions are simple expression terms that can be strung | |
2540 | together to form more complicated location (address) descriptions. */ | |
2541 | ||
2542 | static inline dw_loc_descr_ref | |
2543 | new_loc_descr (op, oprnd1, oprnd2) | |
2544 | register enum dwarf_location_atom op; | |
2545 | register unsigned long oprnd1; | |
2546 | register unsigned long oprnd2; | |
4b674448 | 2547 | { |
5de0e8d4 JM |
2548 | /* Use xcalloc here so we clear out all of the long_long constant in |
2549 | the union. */ | |
7d9d8943 | 2550 | register dw_loc_descr_ref descr |
5de0e8d4 | 2551 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2552 | |
7d9d8943 AM |
2553 | descr->dw_loc_opc = op; |
2554 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2555 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2556 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2557 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2558 | |
7d9d8943 AM |
2559 | return descr; |
2560 | } | |
2561 | ||
63e46568 DB |
2562 | /* Return a new location list, given the begin and end range, and the |
2563 | expression. gensym tells us whether to generate a new internal | |
2564 | symbol for this location list node, which is done for the head of | |
2565 | the list only. */ | |
2566 | static inline dw_loc_list_ref | |
2567 | new_loc_list (expr, begin, end, section, gensym) | |
2568 | register dw_loc_descr_ref expr; | |
2569 | register const char *begin; | |
2570 | register const char *end; | |
2571 | register const char *section; | |
2572 | register unsigned gensym; | |
2573 | { | |
2574 | register dw_loc_list_ref retlist | |
2575 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); | |
2576 | retlist->begin = begin; | |
2577 | retlist->end = end; | |
2578 | retlist->expr = expr; | |
2579 | retlist->section = section; | |
2580 | if (gensym) | |
2581 | retlist->ll_symbol = gen_internal_sym ("LLST"); | |
2582 | return retlist; | |
2583 | } | |
2584 | ||
7d9d8943 AM |
2585 | /* Add a location description term to a location description expression. */ |
2586 | ||
2587 | static inline void | |
2588 | add_loc_descr (list_head, descr) | |
2589 | register dw_loc_descr_ref *list_head; | |
2590 | register dw_loc_descr_ref descr; | |
2591 | { | |
2592 | register dw_loc_descr_ref *d; | |
2593 | ||
2594 | /* Find the end of the chain. */ | |
2595 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2596 | ; | |
2597 | ||
2598 | *d = descr; | |
2599 | } | |
2600 | ||
63e46568 DB |
2601 | /* Add a location description expression to a location list */ |
2602 | static inline void | |
2603 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
2604 | register dw_loc_list_ref *list_head; | |
2605 | register dw_loc_descr_ref descr; | |
2606 | register const char *begin; | |
2607 | register const char *end; | |
2608 | register const char *section; | |
2609 | { | |
2610 | register dw_loc_list_ref *d; | |
2611 | ||
2612 | /* Find the end of the chain. */ | |
2613 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2614 | ; | |
2615 | /* Add a new location list node to the list */ | |
2616 | *d = new_loc_list (descr, begin, end, section, 0); | |
2617 | } | |
2618 | ||
7d9d8943 AM |
2619 | /* Return the size of a location descriptor. */ |
2620 | ||
2621 | static unsigned long | |
2622 | size_of_loc_descr (loc) | |
2623 | register dw_loc_descr_ref loc; | |
2624 | { | |
2625 | register unsigned long size = 1; | |
2626 | ||
2627 | switch (loc->dw_loc_opc) | |
2628 | { | |
2629 | case DW_OP_addr: | |
2630 | size += DWARF2_ADDR_SIZE; | |
2631 | break; | |
2632 | case DW_OP_const1u: | |
2633 | case DW_OP_const1s: | |
2634 | size += 1; | |
2635 | break; | |
2636 | case DW_OP_const2u: | |
2637 | case DW_OP_const2s: | |
2638 | size += 2; | |
2639 | break; | |
2640 | case DW_OP_const4u: | |
2641 | case DW_OP_const4s: | |
2642 | size += 4; | |
2643 | break; | |
2644 | case DW_OP_const8u: | |
2645 | case DW_OP_const8s: | |
2646 | size += 8; | |
2647 | break; | |
2648 | case DW_OP_constu: | |
2649 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2650 | break; | |
2651 | case DW_OP_consts: | |
2652 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2653 | break; | |
2654 | case DW_OP_pick: | |
2655 | size += 1; | |
2656 | break; | |
2657 | case DW_OP_plus_uconst: | |
2658 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2659 | break; | |
2660 | case DW_OP_skip: | |
2661 | case DW_OP_bra: | |
2662 | size += 2; | |
2663 | break; | |
2664 | case DW_OP_breg0: | |
2665 | case DW_OP_breg1: | |
2666 | case DW_OP_breg2: | |
2667 | case DW_OP_breg3: | |
2668 | case DW_OP_breg4: | |
2669 | case DW_OP_breg5: | |
2670 | case DW_OP_breg6: | |
2671 | case DW_OP_breg7: | |
2672 | case DW_OP_breg8: | |
2673 | case DW_OP_breg9: | |
2674 | case DW_OP_breg10: | |
2675 | case DW_OP_breg11: | |
2676 | case DW_OP_breg12: | |
2677 | case DW_OP_breg13: | |
2678 | case DW_OP_breg14: | |
2679 | case DW_OP_breg15: | |
2680 | case DW_OP_breg16: | |
2681 | case DW_OP_breg17: | |
2682 | case DW_OP_breg18: | |
2683 | case DW_OP_breg19: | |
2684 | case DW_OP_breg20: | |
2685 | case DW_OP_breg21: | |
2686 | case DW_OP_breg22: | |
2687 | case DW_OP_breg23: | |
2688 | case DW_OP_breg24: | |
2689 | case DW_OP_breg25: | |
2690 | case DW_OP_breg26: | |
2691 | case DW_OP_breg27: | |
2692 | case DW_OP_breg28: | |
2693 | case DW_OP_breg29: | |
2694 | case DW_OP_breg30: | |
2695 | case DW_OP_breg31: | |
2696 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2697 | break; | |
2698 | case DW_OP_regx: | |
2699 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2700 | break; | |
2701 | case DW_OP_fbreg: | |
2702 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2703 | break; | |
2704 | case DW_OP_bregx: | |
2705 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2706 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2707 | break; | |
2708 | case DW_OP_piece: | |
2709 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2710 | break; | |
2711 | case DW_OP_deref_size: | |
2712 | case DW_OP_xderef_size: | |
2713 | size += 1; | |
2714 | break; | |
3f76745e | 2715 | default: |
7d9d8943 | 2716 | break; |
4b674448 | 2717 | } |
7d9d8943 AM |
2718 | |
2719 | return size; | |
4b674448 JM |
2720 | } |
2721 | ||
7d9d8943 | 2722 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2723 | |
7d9d8943 AM |
2724 | static unsigned long |
2725 | size_of_locs (loc) | |
2726 | register dw_loc_descr_ref loc; | |
4b674448 | 2727 | { |
7d9d8943 AM |
2728 | register unsigned long size = 0; |
2729 | ||
2730 | for (; loc != NULL; loc = loc->dw_loc_next) | |
d8041cc8 RH |
2731 | { |
2732 | loc->dw_loc_addr = size; | |
2733 | size += size_of_loc_descr (loc); | |
2734 | } | |
7d9d8943 AM |
2735 | |
2736 | return size; | |
4b674448 JM |
2737 | } |
2738 | ||
7d9d8943 | 2739 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2740 | |
7d9d8943 AM |
2741 | static void |
2742 | output_loc_operands (loc) | |
2743 | register dw_loc_descr_ref loc; | |
a3f97cbb | 2744 | { |
7d9d8943 AM |
2745 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2746 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
2747 | ||
2748 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2749 | { |
0517872a | 2750 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2751 | case DW_OP_addr: |
2e4b9b8c | 2752 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2753 | break; |
3f76745e | 2754 | case DW_OP_const2u: |
3f76745e | 2755 | case DW_OP_const2s: |
2e4b9b8c | 2756 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2757 | break; |
3f76745e | 2758 | case DW_OP_const4u: |
3f76745e | 2759 | case DW_OP_const4s: |
2e4b9b8c | 2760 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2761 | break; |
3f76745e | 2762 | case DW_OP_const8u: |
3f76745e | 2763 | case DW_OP_const8s: |
2e4b9b8c RH |
2764 | if (HOST_BITS_PER_LONG < 64) |
2765 | abort (); | |
2766 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2767 | break; |
0517872a JM |
2768 | case DW_OP_skip: |
2769 | case DW_OP_bra: | |
d8041cc8 RH |
2770 | { |
2771 | int offset; | |
2772 | ||
2773 | if (val1->val_class == dw_val_class_loc) | |
2774 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2775 | else | |
2776 | abort (); | |
2777 | ||
2e4b9b8c | 2778 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2779 | } |
0517872a | 2780 | break; |
3139472f JM |
2781 | #else |
2782 | case DW_OP_addr: | |
2783 | case DW_OP_const2u: | |
2784 | case DW_OP_const2s: | |
2785 | case DW_OP_const4u: | |
2786 | case DW_OP_const4s: | |
2787 | case DW_OP_const8u: | |
2788 | case DW_OP_const8s: | |
2789 | case DW_OP_skip: | |
2790 | case DW_OP_bra: | |
2791 | /* We currently don't make any attempt to make sure these are | |
2792 | aligned properly like we do for the main unwind info, so | |
2793 | don't support emitting things larger than a byte if we're | |
2794 | only doing unwinding. */ | |
2795 | abort (); | |
0517872a JM |
2796 | #endif |
2797 | case DW_OP_const1u: | |
2798 | case DW_OP_const1s: | |
2e4b9b8c | 2799 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2800 | break; |
3f76745e | 2801 | case DW_OP_constu: |
2e4b9b8c | 2802 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2803 | break; |
3f76745e | 2804 | case DW_OP_consts: |
2e4b9b8c | 2805 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2806 | break; |
2807 | case DW_OP_pick: | |
2e4b9b8c | 2808 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2809 | break; |
2810 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2811 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2812 | break; |
3f76745e | 2813 | case DW_OP_breg0: |
3f76745e | 2814 | case DW_OP_breg1: |
3f76745e | 2815 | case DW_OP_breg2: |
3f76745e | 2816 | case DW_OP_breg3: |
3f76745e | 2817 | case DW_OP_breg4: |
3f76745e | 2818 | case DW_OP_breg5: |
3f76745e | 2819 | case DW_OP_breg6: |
3f76745e | 2820 | case DW_OP_breg7: |
3f76745e | 2821 | case DW_OP_breg8: |
3f76745e | 2822 | case DW_OP_breg9: |
3f76745e | 2823 | case DW_OP_breg10: |
3f76745e | 2824 | case DW_OP_breg11: |
3f76745e | 2825 | case DW_OP_breg12: |
3f76745e | 2826 | case DW_OP_breg13: |
3f76745e | 2827 | case DW_OP_breg14: |
3f76745e | 2828 | case DW_OP_breg15: |
3f76745e | 2829 | case DW_OP_breg16: |
3f76745e | 2830 | case DW_OP_breg17: |
3f76745e | 2831 | case DW_OP_breg18: |
3f76745e | 2832 | case DW_OP_breg19: |
3f76745e | 2833 | case DW_OP_breg20: |
3f76745e | 2834 | case DW_OP_breg21: |
3f76745e | 2835 | case DW_OP_breg22: |
3f76745e | 2836 | case DW_OP_breg23: |
3f76745e | 2837 | case DW_OP_breg24: |
3f76745e | 2838 | case DW_OP_breg25: |
3f76745e | 2839 | case DW_OP_breg26: |
3f76745e | 2840 | case DW_OP_breg27: |
3f76745e | 2841 | case DW_OP_breg28: |
3f76745e | 2842 | case DW_OP_breg29: |
3f76745e | 2843 | case DW_OP_breg30: |
3f76745e | 2844 | case DW_OP_breg31: |
2e4b9b8c | 2845 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2846 | break; |
3f76745e | 2847 | case DW_OP_regx: |
2e4b9b8c | 2848 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2849 | break; |
3f76745e | 2850 | case DW_OP_fbreg: |
2e4b9b8c | 2851 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2852 | break; |
3f76745e | 2853 | case DW_OP_bregx: |
2e4b9b8c RH |
2854 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2855 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2856 | break; |
3f76745e | 2857 | case DW_OP_piece: |
2e4b9b8c | 2858 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2859 | break; |
3f76745e | 2860 | case DW_OP_deref_size: |
3f76745e | 2861 | case DW_OP_xderef_size: |
2e4b9b8c | 2862 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2863 | break; |
2864 | default: | |
3139472f JM |
2865 | /* Other codes have no operands. */ |
2866 | break; | |
7d9d8943 AM |
2867 | } |
2868 | } | |
2869 | ||
2870 | /* Output a sequence of location operations. */ | |
2871 | ||
2872 | static void | |
2873 | output_loc_sequence (loc) | |
2874 | dw_loc_descr_ref loc; | |
2875 | { | |
2876 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2877 | { | |
2878 | /* Output the opcode. */ | |
2e4b9b8c RH |
2879 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2880 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2881 | |
2882 | /* Output the operand(s) (if any). */ | |
2883 | output_loc_operands (loc); | |
2884 | } | |
2885 | } | |
2886 | ||
2887 | /* This routine will generate the correct assembly data for a location | |
2888 | description based on a cfi entry with a complex address. */ | |
2889 | ||
2890 | static void | |
2891 | output_cfa_loc (cfi) | |
2892 | dw_cfi_ref cfi; | |
2893 | { | |
2894 | dw_loc_descr_ref loc; | |
2895 | unsigned long size; | |
2896 | ||
2897 | /* Output the size of the block. */ | |
2898 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2899 | size = size_of_locs (loc); | |
2e4b9b8c | 2900 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2901 | |
2902 | /* Now output the operations themselves. */ | |
2903 | output_loc_sequence (loc); | |
2904 | } | |
2905 | ||
556273e0 KH |
2906 | /* This function builds a dwarf location descriptor seqeunce from |
2907 | a dw_cfa_location. */ | |
7d9d8943 AM |
2908 | |
2909 | static struct dw_loc_descr_struct * | |
2910 | build_cfa_loc (cfa) | |
2911 | dw_cfa_location *cfa; | |
2912 | { | |
2913 | struct dw_loc_descr_struct *head, *tmp; | |
2914 | ||
2915 | if (cfa->indirect == 0) | |
2916 | abort (); | |
2917 | ||
2918 | if (cfa->base_offset) | |
f299afab HPN |
2919 | { |
2920 | if (cfa->reg <= 31) | |
2921 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2922 | else | |
2923 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2924 | } | |
2925 | else if (cfa->reg <= 31) | |
7d9d8943 | 2926 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2927 | else |
2928 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
7d9d8943 AM |
2929 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2930 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2931 | add_loc_descr (&head, tmp); | |
2932 | if (cfa->offset != 0) | |
2933 | { | |
2934 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2935 | add_loc_descr (&head, tmp); | |
2936 | } | |
2937 | return head; | |
2938 | } | |
2939 | ||
556273e0 | 2940 | /* This function fills in aa dw_cfa_location structure from a |
7d9d8943 AM |
2941 | dwarf location descriptor sequence. */ |
2942 | ||
2943 | static void | |
2944 | get_cfa_from_loc_descr (cfa, loc) | |
2945 | dw_cfa_location *cfa; | |
556273e0 | 2946 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2947 | { |
556273e0 | 2948 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2949 | cfa->offset = 0; |
2950 | cfa->base_offset = 0; | |
2951 | cfa->indirect = 0; | |
2952 | cfa->reg = -1; | |
2953 | ||
2954 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2955 | { | |
2956 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2957 | switch (op) | |
556273e0 | 2958 | { |
7d9d8943 AM |
2959 | case DW_OP_reg0: |
2960 | case DW_OP_reg1: | |
2961 | case DW_OP_reg2: | |
2962 | case DW_OP_reg3: | |
2963 | case DW_OP_reg4: | |
2964 | case DW_OP_reg5: | |
2965 | case DW_OP_reg6: | |
2966 | case DW_OP_reg7: | |
2967 | case DW_OP_reg8: | |
2968 | case DW_OP_reg9: | |
2969 | case DW_OP_reg10: | |
2970 | case DW_OP_reg11: | |
2971 | case DW_OP_reg12: | |
2972 | case DW_OP_reg13: | |
2973 | case DW_OP_reg14: | |
2974 | case DW_OP_reg15: | |
2975 | case DW_OP_reg16: | |
2976 | case DW_OP_reg17: | |
2977 | case DW_OP_reg18: | |
2978 | case DW_OP_reg19: | |
2979 | case DW_OP_reg20: | |
2980 | case DW_OP_reg21: | |
2981 | case DW_OP_reg22: | |
2982 | case DW_OP_reg23: | |
2983 | case DW_OP_reg24: | |
2984 | case DW_OP_reg25: | |
2985 | case DW_OP_reg26: | |
2986 | case DW_OP_reg27: | |
2987 | case DW_OP_reg28: | |
2988 | case DW_OP_reg29: | |
2989 | case DW_OP_reg30: | |
2990 | case DW_OP_reg31: | |
2991 | cfa->reg = op - DW_OP_reg0; | |
2992 | break; | |
2993 | case DW_OP_regx: | |
2994 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2995 | break; | |
2996 | case DW_OP_breg0: | |
2997 | case DW_OP_breg1: | |
2998 | case DW_OP_breg2: | |
2999 | case DW_OP_breg3: | |
3000 | case DW_OP_breg4: | |
3001 | case DW_OP_breg5: | |
3002 | case DW_OP_breg6: | |
3003 | case DW_OP_breg7: | |
3004 | case DW_OP_breg8: | |
3005 | case DW_OP_breg9: | |
3006 | case DW_OP_breg10: | |
3007 | case DW_OP_breg11: | |
3008 | case DW_OP_breg12: | |
3009 | case DW_OP_breg13: | |
3010 | case DW_OP_breg14: | |
3011 | case DW_OP_breg15: | |
3012 | case DW_OP_breg16: | |
3013 | case DW_OP_breg17: | |
3014 | case DW_OP_breg18: | |
3015 | case DW_OP_breg19: | |
3016 | case DW_OP_breg20: | |
3017 | case DW_OP_breg21: | |
3018 | case DW_OP_breg22: | |
3019 | case DW_OP_breg23: | |
3020 | case DW_OP_breg24: | |
3021 | case DW_OP_breg25: | |
3022 | case DW_OP_breg26: | |
3023 | case DW_OP_breg27: | |
3024 | case DW_OP_breg28: | |
3025 | case DW_OP_breg29: | |
3026 | case DW_OP_breg30: | |
3027 | case DW_OP_breg31: | |
3028 | cfa->reg = op - DW_OP_breg0; | |
3029 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3030 | break; | |
3031 | case DW_OP_bregx: | |
3032 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3033 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3034 | break; | |
3035 | case DW_OP_deref: | |
3036 | cfa->indirect = 1; | |
3037 | break; | |
3038 | case DW_OP_plus_uconst: | |
556273e0 | 3039 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3040 | break; |
3041 | default: | |
400500c4 RK |
3042 | internal_error ("DW_LOC_OP %s not implememnted\n", |
3043 | dwarf_stack_op_name (ptr->dw_loc_opc)); | |
7d9d8943 AM |
3044 | } |
3045 | } | |
3046 | } | |
3047 | #endif /* .debug_frame support */ | |
3048 | \f | |
3049 | /* And now, the support for symbolic debugging information. */ | |
3050 | #ifdef DWARF2_DEBUGGING_INFO | |
3051 | ||
3052 | /* NOTE: In the comments in this file, many references are made to | |
3053 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3054 | throughout the remainder of this file. */ | |
3055 | ||
3056 | /* An internal representation of the DWARF output is built, and then | |
3057 | walked to generate the DWARF debugging info. The walk of the internal | |
3058 | representation is done after the entire program has been compiled. | |
3059 | The types below are used to describe the internal representation. */ | |
3060 | ||
3061 | /* Various DIE's use offsets relative to the beginning of the | |
3062 | .debug_info section to refer to each other. */ | |
3063 | ||
3064 | typedef long int dw_offset; | |
3065 | ||
3066 | /* Define typedefs here to avoid circular dependencies. */ | |
3067 | ||
3068 | typedef struct dw_attr_struct *dw_attr_ref; | |
3069 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3070 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3071 | typedef struct pubname_struct *pubname_ref; | |
3072 | typedef dw_die_ref *arange_ref; | |
3073 | ||
3074 | /* Each entry in the line_info_table maintains the file and | |
3075 | line number associated with the label generated for that | |
3076 | entry. The label gives the PC value associated with | |
3077 | the line number entry. */ | |
3078 | ||
3079 | typedef struct dw_line_info_struct | |
3080 | { | |
3081 | unsigned long dw_file_num; | |
3082 | unsigned long dw_line_num; | |
3083 | } | |
3084 | dw_line_info_entry; | |
3085 | ||
3086 | /* Line information for functions in separate sections; each one gets its | |
3087 | own sequence. */ | |
3088 | typedef struct dw_separate_line_info_struct | |
3089 | { | |
3090 | unsigned long dw_file_num; | |
3091 | unsigned long dw_line_num; | |
3092 | unsigned long function; | |
3093 | } | |
3094 | dw_separate_line_info_entry; | |
3095 | ||
3096 | /* Each DIE attribute has a field specifying the attribute kind, | |
3097 | a link to the next attribute in the chain, and an attribute value. | |
3098 | Attributes are typically linked below the DIE they modify. */ | |
3099 | ||
3100 | typedef struct dw_attr_struct | |
3101 | { | |
3102 | enum dwarf_attribute dw_attr; | |
3103 | dw_attr_ref dw_attr_next; | |
3104 | dw_val_node dw_attr_val; | |
3105 | } | |
3106 | dw_attr_node; | |
3107 | ||
3108 | /* The Debugging Information Entry (DIE) structure */ | |
3109 | ||
3110 | typedef struct die_struct | |
3111 | { | |
3112 | enum dwarf_tag die_tag; | |
881c6935 | 3113 | char *die_symbol; |
7d9d8943 AM |
3114 | dw_attr_ref die_attr; |
3115 | dw_die_ref die_parent; | |
3116 | dw_die_ref die_child; | |
3117 | dw_die_ref die_sib; | |
3118 | dw_offset die_offset; | |
3119 | unsigned long die_abbrev; | |
1bfb5f8f | 3120 | int die_mark; |
7d9d8943 AM |
3121 | } |
3122 | die_node; | |
3123 | ||
3124 | /* The pubname structure */ | |
3125 | ||
3126 | typedef struct pubname_struct | |
3127 | { | |
3128 | dw_die_ref die; | |
556273e0 | 3129 | char *name; |
7d9d8943 AM |
3130 | } |
3131 | pubname_entry; | |
3132 | ||
3133 | /* The limbo die list structure. */ | |
3134 | typedef struct limbo_die_struct | |
3135 | { | |
3136 | dw_die_ref die; | |
3137 | struct limbo_die_struct *next; | |
3138 | } | |
3139 | limbo_die_node; | |
3140 | ||
3141 | /* How to start an assembler comment. */ | |
3142 | #ifndef ASM_COMMENT_START | |
3143 | #define ASM_COMMENT_START ";#" | |
3144 | #endif | |
3145 | ||
3146 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3147 | implicitly generated for a tagged type. | |
3148 | ||
3149 | Note that unlike the gcc front end (which generates a NULL named | |
3150 | TYPE_DECL node for each complete tagged type, each array type, and | |
3151 | each function type node created) the g++ front end generates a | |
3152 | _named_ TYPE_DECL node for each tagged type node created. | |
3153 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3154 | generate a DW_TAG_typedef DIE for them. */ | |
3155 | ||
3156 | #define TYPE_DECL_IS_STUB(decl) \ | |
3157 | (DECL_NAME (decl) == NULL_TREE \ | |
3158 | || (DECL_ARTIFICIAL (decl) \ | |
3159 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3160 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3161 | /* This is necessary for stub decls that \ | |
3162 | appear in nested inline functions. */ \ | |
3163 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3164 | && (decl_ultimate_origin (decl) \ | |
3165 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3166 | ||
3167 | /* Information concerning the compilation unit's programming | |
3168 | language, and compiler version. */ | |
3169 | ||
3170 | extern int flag_traditional; | |
3171 | ||
3172 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3173 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3174 | ||
3175 | /* Fixed size portion of debugging line information prolog. */ | |
3176 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3177 | ||
3178 | /* Fixed size portion of public names info. */ | |
3179 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3180 | ||
3181 | /* Fixed size portion of the address range info. */ | |
3182 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3183 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3184 | - DWARF_OFFSET_SIZE) | |
3185 | ||
3186 | /* Size of padding portion in the address range info. It must be | |
3187 | aligned to twice the pointer size. */ | |
3188 | #define DWARF_ARANGES_PAD_SIZE \ | |
3189 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3190 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3191 | ||
9d147085 | 3192 | /* Use assembler line directives if available. */ |
7d9d8943 | 3193 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3194 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3195 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3196 | #else | |
7d9d8943 AM |
3197 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3198 | #endif | |
9d147085 | 3199 | #endif |
7d9d8943 AM |
3200 | |
3201 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3202 | In this implementation of DWARF, this field is used for information | |
3203 | purposes only. Since GCC generates assembly language, we have | |
3204 | no a priori knowledge of how many instruction bytes are generated | |
3205 | for each source line, and therefore can use only the DW_LNE_set_address | |
3206 | and DW_LNS_fixed_advance_pc line information commands. */ | |
3207 | ||
3208 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
3209 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3210 | #endif | |
3211 | ||
3212 | /* Minimum line offset in a special line info. opcode. | |
3213 | This value was chosen to give a reasonable range of values. */ | |
3214 | #define DWARF_LINE_BASE -10 | |
3215 | ||
3216 | /* First special line opcde - leave room for the standard opcodes. */ | |
3217 | #define DWARF_LINE_OPCODE_BASE 10 | |
3218 | ||
3219 | /* Range of line offsets in a special line info. opcode. */ | |
3220 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3221 | ||
3222 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3223 | In the present implementation, we do not mark any lines as | |
3224 | the beginning of a source statement, because that information | |
3225 | is not made available by the GCC front-end. */ | |
3226 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3227 | ||
3228 | /* This location is used by calc_die_sizes() to keep track | |
3229 | the offset of each DIE within the .debug_info section. */ | |
3230 | static unsigned long next_die_offset; | |
3231 | ||
3232 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3233 | static dw_die_ref comp_unit_die; | |
3234 | ||
3235 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3236 | static limbo_die_node *limbo_die_list = 0; | |
3237 | ||
2e18bbae RH |
3238 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3239 | struct file_table | |
3240 | { | |
3241 | char **table; | |
3242 | unsigned allocated; | |
3243 | unsigned in_use; | |
3244 | unsigned last_lookup_index; | |
3245 | }; | |
7d9d8943 AM |
3246 | |
3247 | /* Size (in elements) of increments by which we may expand the filename | |
3248 | table. */ | |
3249 | #define FILE_TABLE_INCREMENT 64 | |
3250 | ||
981975b6 RH |
3251 | /* Filenames referenced by this compilation unit. */ |
3252 | static struct file_table file_table; | |
2e18bbae | 3253 | |
7d9d8943 AM |
3254 | /* Local pointer to the name of the main input file. Initialized in |
3255 | dwarf2out_init. */ | |
3256 | static const char *primary_filename; | |
3257 | ||
3258 | /* A pointer to the base of a table of references to DIE's that describe | |
3259 | declarations. The table is indexed by DECL_UID() which is a unique | |
3260 | number identifying each decl. */ | |
3261 | static dw_die_ref *decl_die_table; | |
3262 | ||
3263 | /* Number of elements currently allocated for the decl_die_table. */ | |
3264 | static unsigned decl_die_table_allocated; | |
3265 | ||
3266 | /* Number of elements in decl_die_table currently in use. */ | |
3267 | static unsigned decl_die_table_in_use; | |
3268 | ||
3269 | /* Size (in elements) of increments by which we may expand the | |
3270 | decl_die_table. */ | |
3271 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3272 | ||
3273 | /* A pointer to the base of a table of references to declaration | |
3274 | scopes. This table is a display which tracks the nesting | |
3275 | of declaration scopes at the current scope and containing | |
3276 | scopes. This table is used to find the proper place to | |
3277 | define type declaration DIE's. */ | |
3278 | static tree *decl_scope_table; | |
3279 | ||
3280 | /* Number of elements currently allocated for the decl_scope_table. */ | |
3281 | static int decl_scope_table_allocated; | |
3282 | ||
3283 | /* Current level of nesting of declaration scopes. */ | |
3284 | static int decl_scope_depth; | |
3285 | ||
3286 | /* Size (in elements) of increments by which we may expand the | |
3287 | decl_scope_table. */ | |
3288 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
3289 | ||
3290 | /* A pointer to the base of a list of references to DIE's that | |
3291 | are uniquely identified by their tag, presence/absence of | |
3292 | children DIE's, and list of attribute/value pairs. */ | |
3293 | static dw_die_ref *abbrev_die_table; | |
3294 | ||
3295 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3296 | static unsigned abbrev_die_table_allocated; | |
3297 | ||
3298 | /* Number of elements in type_die_table currently in use. */ | |
3299 | static unsigned abbrev_die_table_in_use; | |
3300 | ||
3301 | /* Size (in elements) of increments by which we may expand the | |
3302 | abbrev_die_table. */ | |
3303 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3304 | ||
3305 | /* A pointer to the base of a table that contains line information | |
3306 | for each source code line in .text in the compilation unit. */ | |
3307 | static dw_line_info_ref line_info_table; | |
3308 | ||
3309 | /* Number of elements currently allocated for line_info_table. */ | |
3310 | static unsigned line_info_table_allocated; | |
3311 | ||
3312 | /* Number of elements in separate_line_info_table currently in use. */ | |
3313 | static unsigned separate_line_info_table_in_use; | |
3314 | ||
3315 | /* A pointer to the base of a table that contains line information | |
3316 | for each source code line outside of .text in the compilation unit. */ | |
3317 | static dw_separate_line_info_ref separate_line_info_table; | |
3318 | ||
3319 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3320 | static unsigned separate_line_info_table_allocated; | |
3321 | ||
3322 | /* Number of elements in line_info_table currently in use. */ | |
3323 | static unsigned line_info_table_in_use; | |
3324 | ||
3325 | /* Size (in elements) of increments by which we may expand the | |
3326 | line_info_table. */ | |
3327 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3328 | ||
3329 | /* A pointer to the base of a table that contains a list of publicly | |
3330 | accessible names. */ | |
3331 | static pubname_ref pubname_table; | |
3332 | ||
3333 | /* Number of elements currently allocated for pubname_table. */ | |
3334 | static unsigned pubname_table_allocated; | |
3335 | ||
3336 | /* Number of elements in pubname_table currently in use. */ | |
3337 | static unsigned pubname_table_in_use; | |
3338 | ||
3339 | /* Size (in elements) of increments by which we may expand the | |
3340 | pubname_table. */ | |
3341 | #define PUBNAME_TABLE_INCREMENT 64 | |
3342 | ||
3343 | /* A pointer to the base of a table that contains a list of publicly | |
3344 | accessible names. */ | |
3345 | static arange_ref arange_table; | |
3346 | ||
3347 | /* Number of elements currently allocated for arange_table. */ | |
3348 | static unsigned arange_table_allocated; | |
3349 | ||
3350 | /* Number of elements in arange_table currently in use. */ | |
3351 | static unsigned arange_table_in_use; | |
3352 | ||
3353 | /* Size (in elements) of increments by which we may expand the | |
3354 | arange_table. */ | |
3355 | #define ARANGE_TABLE_INCREMENT 64 | |
3356 | ||
63e46568 DB |
3357 | /* Whether we have location lists that need outputting */ |
3358 | static unsigned have_location_lists; | |
3359 | ||
7d9d8943 AM |
3360 | /* A pointer to the base of a list of incomplete types which might be |
3361 | completed at some later time. */ | |
3362 | ||
3363 | static tree *incomplete_types_list; | |
3364 | ||
3365 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
3366 | static unsigned incomplete_types_allocated; | |
3367 | ||
3368 | /* Number of elements of incomplete_types_list currently in use. */ | |
3369 | static unsigned incomplete_types; | |
3370 | ||
3371 | /* Size (in elements) of increments by which we may expand the incomplete | |
3372 | types list. Actually, a single hunk of space of this size should | |
3373 | be enough for most typical programs. */ | |
3374 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
3375 | ||
3376 | /* Record whether the function being analyzed contains inlined functions. */ | |
3377 | static int current_function_has_inlines; | |
3378 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3379 | static int comp_unit_has_inlines; | |
3380 | #endif | |
3381 | ||
3382 | /* Array of RTXes referenced by the debugging information, which therefore | |
3383 | must be kept around forever. We do this rather than perform GC on | |
3384 | the dwarf info because almost all of the dwarf info lives forever, and | |
3385 | it's easier to support non-GC frontends this way. */ | |
3386 | static varray_type used_rtx_varray; | |
3387 | ||
3388 | /* Forward declarations for functions defined in this file. */ | |
3389 | ||
3390 | static int is_pseudo_reg PARAMS ((rtx)); | |
3391 | static tree type_main_variant PARAMS ((tree)); | |
3392 | static int is_tagged_type PARAMS ((tree)); | |
3393 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3394 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3395 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3396 | #if 0 | |
3397 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3398 | #endif | |
3399 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3400 | static tree block_ultimate_origin PARAMS ((tree)); | |
3401 | static tree decl_class_context PARAMS ((tree)); | |
3402 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
3403 | static void add_AT_flag PARAMS ((dw_die_ref, | |
3404 | enum dwarf_attribute, | |
3405 | unsigned)); | |
3406 | static void add_AT_int PARAMS ((dw_die_ref, | |
3407 | enum dwarf_attribute, long)); | |
3408 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
3409 | enum dwarf_attribute, | |
3410 | unsigned long)); | |
3411 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
3412 | enum dwarf_attribute, | |
3413 | unsigned long, | |
3414 | unsigned long)); | |
3415 | static void add_AT_float PARAMS ((dw_die_ref, | |
3416 | enum dwarf_attribute, | |
3417 | unsigned, long *)); | |
3418 | static void add_AT_string PARAMS ((dw_die_ref, | |
3419 | enum dwarf_attribute, | |
3420 | const char *)); | |
3421 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
3422 | enum dwarf_attribute, | |
3423 | dw_die_ref)); | |
3424 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
3425 | enum dwarf_attribute, | |
3426 | unsigned)); | |
3427 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3428 | enum dwarf_attribute, | |
3429 | dw_loc_descr_ref)); | |
63e46568 DB |
3430 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3431 | enum dwarf_attribute, | |
3432 | dw_loc_list_ref)); | |
7d9d8943 AM |
3433 | static void add_AT_addr PARAMS ((dw_die_ref, |
3434 | enum dwarf_attribute, | |
3435 | rtx)); | |
3436 | static void add_AT_lbl_id PARAMS ((dw_die_ref, | |
3437 | enum dwarf_attribute, | |
3438 | const char *)); | |
3439 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3440 | enum dwarf_attribute, | |
3441 | const char *)); | |
3442 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, | |
3443 | enum dwarf_attribute)); | |
3444 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3445 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3446 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3447 | enum dwarf_attribute)); | |
3448 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3449 | enum dwarf_attribute)); | |
3450 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3451 | enum dwarf_attribute)); | |
3452 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3453 | enum dwarf_attribute)); | |
3454 | static int is_c_family PARAMS ((void)); | |
28985b81 | 3455 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3456 | static int is_fortran PARAMS ((void)); |
3457 | static void remove_AT PARAMS ((dw_die_ref, | |
3458 | enum dwarf_attribute)); | |
3459 | static void remove_children PARAMS ((dw_die_ref)); | |
3460 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
3461 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
3462 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
3463 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3464 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3465 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3466 | static void print_spaces PARAMS ((FILE *)); | |
3467 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3468 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3469 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3470 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3471 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3472 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
3473 | static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *)); | |
3474 | static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *)); | |
3475 | static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *)); | |
3476 | static void compute_section_prefix PARAMS ((dw_die_ref)); | |
3477 | static int is_type_die PARAMS ((dw_die_ref)); | |
3478 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3479 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3480 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3481 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3482 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3483 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3484 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3485 | static unsigned long size_of_string PARAMS ((const char *)); |
3486 | static int constant_size PARAMS ((long unsigned)); | |
3487 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3488 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3489 | static void mark_dies PARAMS ((dw_die_ref)); |
3490 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3491 | static unsigned long size_of_pubnames PARAMS ((void)); |
3492 | static unsigned long size_of_aranges PARAMS ((void)); | |
3493 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3494 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3495 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3496 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3497 | static void output_die PARAMS ((dw_die_ref)); |
3498 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3499 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3500 | static const char *dwarf2_name PARAMS ((tree, int)); |
3501 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3502 | static void output_pubnames PARAMS ((void)); | |
3503 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3504 | static void output_aranges PARAMS ((void)); | |
3505 | static void output_line_info PARAMS ((void)); | |
0b34cf1e | 3506 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3507 | static dw_die_ref base_type_die PARAMS ((tree)); |
3508 | static tree root_type PARAMS ((tree)); | |
3509 | static int is_base_type PARAMS ((tree)); | |
3510 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3511 | static int type_is_enum PARAMS ((tree)); | |
3512 | static unsigned int reg_number PARAMS ((rtx)); | |
3513 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3514 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3515 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3516 | static int is_based_loc PARAMS ((rtx)); | |
3517 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3518 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3519 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3520 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3521 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3522 | static tree field_type PARAMS ((tree)); | |
3523 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3524 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3525 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3526 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3527 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3528 | enum dwarf_attribute, rtx)); | |
3529 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3530 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3531 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3532 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3533 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3534 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3535 | static void add_bound_info PARAMS ((dw_die_ref, | |
3536 | enum dwarf_attribute, tree)); | |
3537 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3538 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3539 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3540 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3541 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3542 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3543 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3544 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3545 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3546 | static void push_decl_scope PARAMS ((tree)); | |
3547 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
3548 | static void pop_decl_scope PARAMS ((void)); | |
3549 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
3550 | dw_die_ref)); | |
3551 | static const char *type_tag PARAMS ((tree)); | |
3552 | static tree member_declared_type PARAMS ((tree)); | |
3553 | #if 0 | |
3554 | static const char *decl_start_label PARAMS ((tree)); | |
3555 | #endif | |
3556 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3557 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3558 | #if 0 | |
3559 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3560 | #endif | |
3561 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3562 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3563 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3564 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3565 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3566 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3567 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3568 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3569 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3570 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3571 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3572 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3573 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3574 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3575 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3576 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3577 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3578 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3579 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3580 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3581 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3582 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3583 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3584 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3585 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3586 | static int is_redundant_typedef PARAMS ((tree)); | |
3587 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3588 | static unsigned lookup_filename PARAMS ((const char *)); |
3589 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3590 | static void add_incomplete_type PARAMS ((tree)); |
3591 | static void retry_incomplete_types PARAMS ((void)); | |
3592 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 AM |
3593 | static rtx save_rtx PARAMS ((rtx)); |
3594 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
fc608b03 | 3595 | static int file_info_cmp PARAMS ((const void *, const void *)); |
7d9d8943 AM |
3596 | |
3597 | /* Section names used to hold DWARF debugging information. */ | |
3598 | #ifndef DEBUG_INFO_SECTION | |
3599 | #define DEBUG_INFO_SECTION ".debug_info" | |
3600 | #endif | |
9d2f2c45 RH |
3601 | #ifndef DEBUG_ABBREV_SECTION |
3602 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3603 | #endif |
9d2f2c45 RH |
3604 | #ifndef DEBUG_ARANGES_SECTION |
3605 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3606 | #endif |
9d2f2c45 RH |
3607 | #ifndef DEBUG_MACINFO_SECTION |
3608 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3609 | #endif |
3610 | #ifndef DEBUG_LINE_SECTION | |
3611 | #define DEBUG_LINE_SECTION ".debug_line" | |
3612 | #endif | |
9d2f2c45 RH |
3613 | #ifndef DEBUG_LOC_SECTION |
3614 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3615 | #endif |
9d2f2c45 RH |
3616 | #ifndef DEBUG_PUBNAMES_SECTION |
3617 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3618 | #endif |
9d2f2c45 RH |
3619 | #ifndef DEBUG_STR_SECTION |
3620 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 AM |
3621 | #endif |
3622 | ||
3623 | /* Standard ELF section names for compiled code and data. */ | |
3624 | #ifndef TEXT_SECTION | |
3625 | #define TEXT_SECTION ".text" | |
3626 | #endif | |
3627 | #ifndef DATA_SECTION | |
3628 | #define DATA_SECTION ".data" | |
3629 | #endif | |
3630 | #ifndef BSS_SECTION | |
3631 | #define BSS_SECTION ".bss" | |
3632 | #endif | |
3633 | ||
3634 | /* Labels we insert at beginning sections we can reference instead of | |
556273e0 | 3635 | the section names themselves. */ |
7d9d8943 AM |
3636 | |
3637 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3638 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3639 | #endif |
3640 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3641 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3642 | #endif |
3643 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3644 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3645 | #endif |
9d2f2c45 RH |
3646 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3647 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3648 | #endif |
9d2f2c45 RH |
3649 | #ifndef DEBUG_LOC_SECTION_LABEL |
3650 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3651 | #endif |
7d9d8943 | 3652 | |
7d9d8943 AM |
3653 | /* Definitions of defaults for formats and names of various special |
3654 | (artificial) labels which may be generated within this file (when the -g | |
3655 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3656 | If necessary, these may be overridden from within the tm.h file, but | |
3657 | typically, overriding these defaults is unnecessary. */ | |
3658 | ||
3659 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3660 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3661 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3662 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3663 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
63e46568 | 3664 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7d9d8943 AM |
3665 | #ifndef TEXT_END_LABEL |
3666 | #define TEXT_END_LABEL "Letext" | |
3667 | #endif | |
3668 | #ifndef DATA_END_LABEL | |
3669 | #define DATA_END_LABEL "Ledata" | |
3670 | #endif | |
3671 | #ifndef BSS_END_LABEL | |
3672 | #define BSS_END_LABEL "Lebss" | |
3673 | #endif | |
7d9d8943 AM |
3674 | #ifndef BLOCK_BEGIN_LABEL |
3675 | #define BLOCK_BEGIN_LABEL "LBB" | |
3676 | #endif | |
3677 | #ifndef BLOCK_END_LABEL | |
3678 | #define BLOCK_END_LABEL "LBE" | |
3679 | #endif | |
3680 | #ifndef BODY_BEGIN_LABEL | |
3681 | #define BODY_BEGIN_LABEL "Lbb" | |
3682 | #endif | |
3683 | #ifndef BODY_END_LABEL | |
3684 | #define BODY_END_LABEL "Lbe" | |
3685 | #endif | |
3686 | #ifndef LINE_CODE_LABEL | |
3687 | #define LINE_CODE_LABEL "LM" | |
3688 | #endif | |
3689 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3690 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3691 | #endif | |
3692 | \f | |
3693 | /* We allow a language front-end to designate a function that is to be | |
3694 | called to "demangle" any name before it it put into a DIE. */ | |
3695 | ||
3696 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3697 | ||
3698 | void | |
3699 | dwarf2out_set_demangle_name_func (func) | |
3700 | const char *(*func) PARAMS ((const char *)); | |
3701 | { | |
3702 | demangle_name_func = func; | |
3703 | } | |
3704 | \f | |
3705 | /* Return an rtx like ORIG which lives forever. If we're doing GC, | |
3706 | that means adding it to used_rtx_varray. If not, that means making | |
3707 | a copy on the permanent_obstack. */ | |
3708 | ||
3709 | static rtx | |
3710 | save_rtx (orig) | |
3711 | register rtx orig; | |
3712 | { | |
1f8f4a0b | 3713 | VARRAY_PUSH_RTX (used_rtx_varray, orig); |
7d9d8943 AM |
3714 | |
3715 | return orig; | |
3716 | } | |
3717 | ||
3718 | /* Test if rtl node points to a pseudo register. */ | |
3719 | ||
3720 | static inline int | |
3721 | is_pseudo_reg (rtl) | |
3722 | register rtx rtl; | |
3723 | { | |
3724 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3725 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3726 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3727 | } |
3728 | ||
3729 | /* Return a reference to a type, with its const and volatile qualifiers | |
3730 | removed. */ | |
3731 | ||
3732 | static inline tree | |
3733 | type_main_variant (type) | |
3734 | register tree type; | |
3735 | { | |
3736 | type = TYPE_MAIN_VARIANT (type); | |
3737 | ||
556273e0 | 3738 | /* There really should be only one main variant among any group of variants |
7d9d8943 AM |
3739 | of a given type (and all of the MAIN_VARIANT values for all members of |
3740 | the group should point to that one type) but sometimes the C front-end | |
3741 | messes this up for array types, so we work around that bug here. */ | |
3742 | ||
3743 | if (TREE_CODE (type) == ARRAY_TYPE) | |
3744 | while (type != TYPE_MAIN_VARIANT (type)) | |
3745 | type = TYPE_MAIN_VARIANT (type); | |
3746 | ||
3747 | return type; | |
3748 | } | |
3749 | ||
3750 | /* Return non-zero if the given type node represents a tagged type. */ | |
3751 | ||
3752 | static inline int | |
3753 | is_tagged_type (type) | |
3754 | register tree type; | |
3755 | { | |
3756 | register enum tree_code code = TREE_CODE (type); | |
3757 | ||
3758 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3759 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3760 | } | |
3761 | ||
3762 | /* Convert a DIE tag into its string name. */ | |
3763 | ||
3764 | static const char * | |
3765 | dwarf_tag_name (tag) | |
3766 | register unsigned tag; | |
3767 | { | |
3768 | switch (tag) | |
3769 | { | |
3770 | case DW_TAG_padding: | |
3771 | return "DW_TAG_padding"; | |
3772 | case DW_TAG_array_type: | |
3773 | return "DW_TAG_array_type"; | |
3774 | case DW_TAG_class_type: | |
3775 | return "DW_TAG_class_type"; | |
3776 | case DW_TAG_entry_point: | |
3777 | return "DW_TAG_entry_point"; | |
3778 | case DW_TAG_enumeration_type: | |
3779 | return "DW_TAG_enumeration_type"; | |
3780 | case DW_TAG_formal_parameter: | |
3781 | return "DW_TAG_formal_parameter"; | |
3782 | case DW_TAG_imported_declaration: | |
3783 | return "DW_TAG_imported_declaration"; | |
3784 | case DW_TAG_label: | |
3785 | return "DW_TAG_label"; | |
3786 | case DW_TAG_lexical_block: | |
3787 | return "DW_TAG_lexical_block"; | |
3788 | case DW_TAG_member: | |
3789 | return "DW_TAG_member"; | |
3790 | case DW_TAG_pointer_type: | |
3791 | return "DW_TAG_pointer_type"; | |
3792 | case DW_TAG_reference_type: | |
3793 | return "DW_TAG_reference_type"; | |
3794 | case DW_TAG_compile_unit: | |
3795 | return "DW_TAG_compile_unit"; | |
3796 | case DW_TAG_string_type: | |
3797 | return "DW_TAG_string_type"; | |
3798 | case DW_TAG_structure_type: | |
3799 | return "DW_TAG_structure_type"; | |
3800 | case DW_TAG_subroutine_type: | |
3801 | return "DW_TAG_subroutine_type"; | |
3802 | case DW_TAG_typedef: | |
3803 | return "DW_TAG_typedef"; | |
3804 | case DW_TAG_union_type: | |
3805 | return "DW_TAG_union_type"; | |
3806 | case DW_TAG_unspecified_parameters: | |
3807 | return "DW_TAG_unspecified_parameters"; | |
3808 | case DW_TAG_variant: | |
3809 | return "DW_TAG_variant"; | |
3810 | case DW_TAG_common_block: | |
3811 | return "DW_TAG_common_block"; | |
3812 | case DW_TAG_common_inclusion: | |
3813 | return "DW_TAG_common_inclusion"; | |
3814 | case DW_TAG_inheritance: | |
3815 | return "DW_TAG_inheritance"; | |
3816 | case DW_TAG_inlined_subroutine: | |
3817 | return "DW_TAG_inlined_subroutine"; | |
3818 | case DW_TAG_module: | |
3819 | return "DW_TAG_module"; | |
3820 | case DW_TAG_ptr_to_member_type: | |
3821 | return "DW_TAG_ptr_to_member_type"; | |
3822 | case DW_TAG_set_type: | |
3823 | return "DW_TAG_set_type"; | |
3824 | case DW_TAG_subrange_type: | |
3825 | return "DW_TAG_subrange_type"; | |
3826 | case DW_TAG_with_stmt: | |
3827 | return "DW_TAG_with_stmt"; | |
3828 | case DW_TAG_access_declaration: | |
3829 | return "DW_TAG_access_declaration"; | |
3830 | case DW_TAG_base_type: | |
3831 | return "DW_TAG_base_type"; | |
3832 | case DW_TAG_catch_block: | |
3833 | return "DW_TAG_catch_block"; | |
3834 | case DW_TAG_const_type: | |
3835 | return "DW_TAG_const_type"; | |
3836 | case DW_TAG_constant: | |
3837 | return "DW_TAG_constant"; | |
3838 | case DW_TAG_enumerator: | |
3839 | return "DW_TAG_enumerator"; | |
3840 | case DW_TAG_file_type: | |
3841 | return "DW_TAG_file_type"; | |
3842 | case DW_TAG_friend: | |
3843 | return "DW_TAG_friend"; | |
3844 | case DW_TAG_namelist: | |
3845 | return "DW_TAG_namelist"; | |
3846 | case DW_TAG_namelist_item: | |
3847 | return "DW_TAG_namelist_item"; | |
3848 | case DW_TAG_packed_type: | |
3849 | return "DW_TAG_packed_type"; | |
3850 | case DW_TAG_subprogram: | |
3851 | return "DW_TAG_subprogram"; | |
3852 | case DW_TAG_template_type_param: | |
3853 | return "DW_TAG_template_type_param"; | |
3854 | case DW_TAG_template_value_param: | |
3855 | return "DW_TAG_template_value_param"; | |
3856 | case DW_TAG_thrown_type: | |
3857 | return "DW_TAG_thrown_type"; | |
3858 | case DW_TAG_try_block: | |
3859 | return "DW_TAG_try_block"; | |
3860 | case DW_TAG_variant_part: | |
3861 | return "DW_TAG_variant_part"; | |
3862 | case DW_TAG_variable: | |
3863 | return "DW_TAG_variable"; | |
3864 | case DW_TAG_volatile_type: | |
3865 | return "DW_TAG_volatile_type"; | |
3866 | case DW_TAG_MIPS_loop: | |
3867 | return "DW_TAG_MIPS_loop"; | |
3868 | case DW_TAG_format_label: | |
3869 | return "DW_TAG_format_label"; | |
3870 | case DW_TAG_function_template: | |
3871 | return "DW_TAG_function_template"; | |
3872 | case DW_TAG_class_template: | |
3873 | return "DW_TAG_class_template"; | |
881c6935 JM |
3874 | case DW_TAG_GNU_BINCL: |
3875 | return "DW_TAG_GNU_BINCL"; | |
3876 | case DW_TAG_GNU_EINCL: | |
3877 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3878 | default: |
3879 | return "DW_TAG_<unknown>"; | |
3880 | } | |
3881 | } | |
3882 | ||
3883 | /* Convert a DWARF attribute code into its string name. */ | |
3884 | ||
3885 | static const char * | |
3886 | dwarf_attr_name (attr) | |
3887 | register unsigned attr; | |
3888 | { | |
3889 | switch (attr) | |
3890 | { | |
3891 | case DW_AT_sibling: | |
3892 | return "DW_AT_sibling"; | |
3893 | case DW_AT_location: | |
3894 | return "DW_AT_location"; | |
3895 | case DW_AT_name: | |
3896 | return "DW_AT_name"; | |
3897 | case DW_AT_ordering: | |
3898 | return "DW_AT_ordering"; | |
3899 | case DW_AT_subscr_data: | |
3900 | return "DW_AT_subscr_data"; | |
3901 | case DW_AT_byte_size: | |
3902 | return "DW_AT_byte_size"; | |
3903 | case DW_AT_bit_offset: | |
3904 | return "DW_AT_bit_offset"; | |
3905 | case DW_AT_bit_size: | |
3906 | return "DW_AT_bit_size"; | |
3907 | case DW_AT_element_list: | |
3908 | return "DW_AT_element_list"; | |
3909 | case DW_AT_stmt_list: | |
3910 | return "DW_AT_stmt_list"; | |
3911 | case DW_AT_low_pc: | |
3912 | return "DW_AT_low_pc"; | |
3913 | case DW_AT_high_pc: | |
3914 | return "DW_AT_high_pc"; | |
3915 | case DW_AT_language: | |
3916 | return "DW_AT_language"; | |
3917 | case DW_AT_member: | |
3918 | return "DW_AT_member"; | |
3919 | case DW_AT_discr: | |
3920 | return "DW_AT_discr"; | |
3921 | case DW_AT_discr_value: | |
3922 | return "DW_AT_discr_value"; | |
3923 | case DW_AT_visibility: | |
3924 | return "DW_AT_visibility"; | |
3925 | case DW_AT_import: | |
3926 | return "DW_AT_import"; | |
3927 | case DW_AT_string_length: | |
3928 | return "DW_AT_string_length"; | |
3929 | case DW_AT_common_reference: | |
3930 | return "DW_AT_common_reference"; | |
3931 | case DW_AT_comp_dir: | |
3932 | return "DW_AT_comp_dir"; | |
3933 | case DW_AT_const_value: | |
3934 | return "DW_AT_const_value"; | |
3935 | case DW_AT_containing_type: | |
3936 | return "DW_AT_containing_type"; | |
3937 | case DW_AT_default_value: | |
3938 | return "DW_AT_default_value"; | |
3939 | case DW_AT_inline: | |
3940 | return "DW_AT_inline"; | |
3941 | case DW_AT_is_optional: | |
3942 | return "DW_AT_is_optional"; | |
3943 | case DW_AT_lower_bound: | |
3944 | return "DW_AT_lower_bound"; | |
3945 | case DW_AT_producer: | |
3946 | return "DW_AT_producer"; | |
3947 | case DW_AT_prototyped: | |
3948 | return "DW_AT_prototyped"; | |
3949 | case DW_AT_return_addr: | |
3950 | return "DW_AT_return_addr"; | |
3951 | case DW_AT_start_scope: | |
3952 | return "DW_AT_start_scope"; | |
3953 | case DW_AT_stride_size: | |
3954 | return "DW_AT_stride_size"; | |
3955 | case DW_AT_upper_bound: | |
3956 | return "DW_AT_upper_bound"; | |
3957 | case DW_AT_abstract_origin: | |
3958 | return "DW_AT_abstract_origin"; | |
3959 | case DW_AT_accessibility: | |
3960 | return "DW_AT_accessibility"; | |
3961 | case DW_AT_address_class: | |
3962 | return "DW_AT_address_class"; | |
3963 | case DW_AT_artificial: | |
3964 | return "DW_AT_artificial"; | |
3965 | case DW_AT_base_types: | |
3966 | return "DW_AT_base_types"; | |
3967 | case DW_AT_calling_convention: | |
3968 | return "DW_AT_calling_convention"; | |
3969 | case DW_AT_count: | |
3970 | return "DW_AT_count"; | |
3971 | case DW_AT_data_member_location: | |
3972 | return "DW_AT_data_member_location"; | |
3973 | case DW_AT_decl_column: | |
3974 | return "DW_AT_decl_column"; | |
3975 | case DW_AT_decl_file: | |
3976 | return "DW_AT_decl_file"; | |
3977 | case DW_AT_decl_line: | |
3978 | return "DW_AT_decl_line"; | |
3979 | case DW_AT_declaration: | |
3980 | return "DW_AT_declaration"; | |
3981 | case DW_AT_discr_list: | |
3982 | return "DW_AT_discr_list"; | |
3983 | case DW_AT_encoding: | |
3984 | return "DW_AT_encoding"; | |
3985 | case DW_AT_external: | |
3986 | return "DW_AT_external"; | |
3987 | case DW_AT_frame_base: | |
3988 | return "DW_AT_frame_base"; | |
3989 | case DW_AT_friend: | |
3990 | return "DW_AT_friend"; | |
3991 | case DW_AT_identifier_case: | |
3992 | return "DW_AT_identifier_case"; | |
3993 | case DW_AT_macro_info: | |
3994 | return "DW_AT_macro_info"; | |
3995 | case DW_AT_namelist_items: | |
3996 | return "DW_AT_namelist_items"; | |
3997 | case DW_AT_priority: | |
3998 | return "DW_AT_priority"; | |
3999 | case DW_AT_segment: | |
4000 | return "DW_AT_segment"; | |
4001 | case DW_AT_specification: | |
4002 | return "DW_AT_specification"; | |
4003 | case DW_AT_static_link: | |
4004 | return "DW_AT_static_link"; | |
4005 | case DW_AT_type: | |
4006 | return "DW_AT_type"; | |
4007 | case DW_AT_use_location: | |
4008 | return "DW_AT_use_location"; | |
4009 | case DW_AT_variable_parameter: | |
4010 | return "DW_AT_variable_parameter"; | |
4011 | case DW_AT_virtuality: | |
4012 | return "DW_AT_virtuality"; | |
4013 | case DW_AT_vtable_elem_location: | |
4014 | return "DW_AT_vtable_elem_location"; | |
4015 | ||
4016 | case DW_AT_MIPS_fde: | |
4017 | return "DW_AT_MIPS_fde"; | |
4018 | case DW_AT_MIPS_loop_begin: | |
4019 | return "DW_AT_MIPS_loop_begin"; | |
4020 | case DW_AT_MIPS_tail_loop_begin: | |
4021 | return "DW_AT_MIPS_tail_loop_begin"; | |
4022 | case DW_AT_MIPS_epilog_begin: | |
4023 | return "DW_AT_MIPS_epilog_begin"; | |
4024 | case DW_AT_MIPS_loop_unroll_factor: | |
4025 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4026 | case DW_AT_MIPS_software_pipeline_depth: | |
4027 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4028 | case DW_AT_MIPS_linkage_name: | |
4029 | return "DW_AT_MIPS_linkage_name"; | |
4030 | case DW_AT_MIPS_stride: | |
4031 | return "DW_AT_MIPS_stride"; | |
4032 | case DW_AT_MIPS_abstract_name: | |
4033 | return "DW_AT_MIPS_abstract_name"; | |
4034 | case DW_AT_MIPS_clone_origin: | |
4035 | return "DW_AT_MIPS_clone_origin"; | |
4036 | case DW_AT_MIPS_has_inlines: | |
4037 | return "DW_AT_MIPS_has_inlines"; | |
4038 | ||
4039 | case DW_AT_sf_names: | |
4040 | return "DW_AT_sf_names"; | |
4041 | case DW_AT_src_info: | |
4042 | return "DW_AT_src_info"; | |
4043 | case DW_AT_mac_info: | |
4044 | return "DW_AT_mac_info"; | |
4045 | case DW_AT_src_coords: | |
4046 | return "DW_AT_src_coords"; | |
4047 | case DW_AT_body_begin: | |
4048 | return "DW_AT_body_begin"; | |
4049 | case DW_AT_body_end: | |
4050 | return "DW_AT_body_end"; | |
4051 | default: | |
4052 | return "DW_AT_<unknown>"; | |
4053 | } | |
4054 | } | |
4055 | ||
4056 | /* Convert a DWARF value form code into its string name. */ | |
4057 | ||
4058 | static const char * | |
4059 | dwarf_form_name (form) | |
4060 | register unsigned form; | |
4061 | { | |
4062 | switch (form) | |
4063 | { | |
4064 | case DW_FORM_addr: | |
4065 | return "DW_FORM_addr"; | |
4066 | case DW_FORM_block2: | |
4067 | return "DW_FORM_block2"; | |
4068 | case DW_FORM_block4: | |
4069 | return "DW_FORM_block4"; | |
4070 | case DW_FORM_data2: | |
4071 | return "DW_FORM_data2"; | |
4072 | case DW_FORM_data4: | |
4073 | return "DW_FORM_data4"; | |
4074 | case DW_FORM_data8: | |
4075 | return "DW_FORM_data8"; | |
4076 | case DW_FORM_string: | |
4077 | return "DW_FORM_string"; | |
4078 | case DW_FORM_block: | |
4079 | return "DW_FORM_block"; | |
4080 | case DW_FORM_block1: | |
4081 | return "DW_FORM_block1"; | |
4082 | case DW_FORM_data1: | |
4083 | return "DW_FORM_data1"; | |
4084 | case DW_FORM_flag: | |
4085 | return "DW_FORM_flag"; | |
4086 | case DW_FORM_sdata: | |
4087 | return "DW_FORM_sdata"; | |
4088 | case DW_FORM_strp: | |
4089 | return "DW_FORM_strp"; | |
4090 | case DW_FORM_udata: | |
4091 | return "DW_FORM_udata"; | |
4092 | case DW_FORM_ref_addr: | |
4093 | return "DW_FORM_ref_addr"; | |
4094 | case DW_FORM_ref1: | |
4095 | return "DW_FORM_ref1"; | |
4096 | case DW_FORM_ref2: | |
4097 | return "DW_FORM_ref2"; | |
4098 | case DW_FORM_ref4: | |
4099 | return "DW_FORM_ref4"; | |
4100 | case DW_FORM_ref8: | |
4101 | return "DW_FORM_ref8"; | |
4102 | case DW_FORM_ref_udata: | |
4103 | return "DW_FORM_ref_udata"; | |
4104 | case DW_FORM_indirect: | |
4105 | return "DW_FORM_indirect"; | |
3f76745e | 4106 | default: |
7d9d8943 | 4107 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4108 | } |
4109 | } | |
4110 | ||
3f76745e | 4111 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4112 | |
487a6e06 | 4113 | #if 0 |
d560ee52 | 4114 | static const char * |
3f76745e JM |
4115 | dwarf_type_encoding_name (enc) |
4116 | register unsigned enc; | |
a3f97cbb | 4117 | { |
3f76745e | 4118 | switch (enc) |
a3f97cbb | 4119 | { |
3f76745e JM |
4120 | case DW_ATE_address: |
4121 | return "DW_ATE_address"; | |
4122 | case DW_ATE_boolean: | |
4123 | return "DW_ATE_boolean"; | |
4124 | case DW_ATE_complex_float: | |
4125 | return "DW_ATE_complex_float"; | |
4126 | case DW_ATE_float: | |
4127 | return "DW_ATE_float"; | |
4128 | case DW_ATE_signed: | |
4129 | return "DW_ATE_signed"; | |
4130 | case DW_ATE_signed_char: | |
4131 | return "DW_ATE_signed_char"; | |
4132 | case DW_ATE_unsigned: | |
4133 | return "DW_ATE_unsigned"; | |
4134 | case DW_ATE_unsigned_char: | |
4135 | return "DW_ATE_unsigned_char"; | |
4136 | default: | |
4137 | return "DW_ATE_<unknown>"; | |
4138 | } | |
a3f97cbb | 4139 | } |
487a6e06 | 4140 | #endif |
3f76745e JM |
4141 | \f |
4142 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4143 | instance of an inlined instance of a decl which is local to an inline | |
4144 | function, so we have to trace all of the way back through the origin chain | |
4145 | to find out what sort of node actually served as the original seed for the | |
4146 | given block. */ | |
a3f97cbb | 4147 | |
3f76745e JM |
4148 | static tree |
4149 | decl_ultimate_origin (decl) | |
4150 | register tree decl; | |
a3f97cbb | 4151 | { |
10a11b75 JM |
4152 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4153 | nodes in the function to point to themselves; ignore that if | |
4154 | we're trying to output the abstract instance of this function. */ | |
4155 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4156 | return NULL_TREE; | |
4157 | ||
556273e0 | 4158 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4159 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4160 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4161 | most distant ancestor, this should never happen. */ | |
4162 | abort (); | |
4163 | #endif | |
3f76745e | 4164 | |
02e24c7a | 4165 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4166 | } |
4167 | ||
3f76745e JM |
4168 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4169 | instance of an inlined instance of a block which is local to an inline | |
4170 | function, so we have to trace all of the way back through the origin chain | |
4171 | to find out what sort of node actually served as the original seed for the | |
4172 | given block. */ | |
71dfc51f | 4173 | |
3f76745e JM |
4174 | static tree |
4175 | block_ultimate_origin (block) | |
4176 | register tree block; | |
a3f97cbb | 4177 | { |
3f76745e | 4178 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4179 | |
10a11b75 JM |
4180 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4181 | nodes in the function to point to themselves; ignore that if | |
4182 | we're trying to output the abstract instance of this function. */ | |
4183 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4184 | return NULL_TREE; | |
4185 | ||
3f76745e JM |
4186 | if (immediate_origin == NULL_TREE) |
4187 | return NULL_TREE; | |
4188 | else | |
4189 | { | |
4190 | register tree ret_val; | |
4191 | register tree lookahead = immediate_origin; | |
71dfc51f | 4192 | |
3f76745e JM |
4193 | do |
4194 | { | |
4195 | ret_val = lookahead; | |
4196 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
4197 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
4198 | : NULL; | |
4199 | } | |
4200 | while (lookahead != NULL && lookahead != ret_val); | |
4201 | ||
4202 | return ret_val; | |
4203 | } | |
a3f97cbb JW |
4204 | } |
4205 | ||
3f76745e JM |
4206 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4207 | of a virtual function may refer to a base class, so we check the 'this' | |
4208 | parameter. */ | |
71dfc51f | 4209 | |
3f76745e JM |
4210 | static tree |
4211 | decl_class_context (decl) | |
4212 | tree decl; | |
a3f97cbb | 4213 | { |
3f76745e | 4214 | tree context = NULL_TREE; |
71dfc51f | 4215 | |
3f76745e JM |
4216 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4217 | context = DECL_CONTEXT (decl); | |
4218 | else | |
4219 | context = TYPE_MAIN_VARIANT | |
4220 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4221 | |
2f939d94 | 4222 | if (context && !TYPE_P (context)) |
3f76745e JM |
4223 | context = NULL_TREE; |
4224 | ||
4225 | return context; | |
a3f97cbb JW |
4226 | } |
4227 | \f | |
a96c67ec | 4228 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4229 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4230 | |
4231 | static inline void | |
3f76745e JM |
4232 | add_dwarf_attr (die, attr) |
4233 | register dw_die_ref die; | |
4234 | register dw_attr_ref attr; | |
a3f97cbb | 4235 | { |
3f76745e | 4236 | if (die != NULL && attr != NULL) |
a3f97cbb | 4237 | { |
a96c67ec JM |
4238 | attr->dw_attr_next = die->die_attr; |
4239 | die->die_attr = attr; | |
a3f97cbb JW |
4240 | } |
4241 | } | |
4242 | ||
c6991660 | 4243 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4244 | static inline dw_val_class |
4245 | AT_class (a) | |
4246 | dw_attr_ref a; | |
4247 | { | |
4248 | return a->dw_attr_val.val_class; | |
4249 | } | |
4250 | ||
3f76745e | 4251 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4252 | |
3f76745e JM |
4253 | static inline void |
4254 | add_AT_flag (die, attr_kind, flag) | |
4255 | register dw_die_ref die; | |
4256 | register enum dwarf_attribute attr_kind; | |
4257 | register unsigned flag; | |
a3f97cbb | 4258 | { |
3f76745e | 4259 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4260 | |
3f76745e JM |
4261 | attr->dw_attr_next = NULL; |
4262 | attr->dw_attr = attr_kind; | |
4263 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4264 | attr->dw_attr_val.v.val_flag = flag; | |
4265 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4266 | } |
4267 | ||
c6991660 | 4268 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4269 | static inline unsigned |
4270 | AT_flag (a) | |
4271 | register dw_attr_ref a; | |
4272 | { | |
4273 | if (a && AT_class (a) == dw_val_class_flag) | |
4274 | return a->dw_attr_val.v.val_flag; | |
4275 | ||
40e8cc95 | 4276 | abort (); |
a96c67ec JM |
4277 | } |
4278 | ||
3f76745e | 4279 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4280 | |
3f76745e JM |
4281 | static inline void |
4282 | add_AT_int (die, attr_kind, int_val) | |
4283 | register dw_die_ref die; | |
4284 | register enum dwarf_attribute attr_kind; | |
4285 | register long int int_val; | |
a3f97cbb | 4286 | { |
3f76745e JM |
4287 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4288 | ||
4289 | attr->dw_attr_next = NULL; | |
4290 | attr->dw_attr = attr_kind; | |
4291 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4292 | attr->dw_attr_val.v.val_int = int_val; | |
4293 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4294 | } |
4295 | ||
c6991660 | 4296 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4297 | static inline long int |
4298 | AT_int (a) | |
4299 | register dw_attr_ref a; | |
4300 | { | |
4301 | if (a && AT_class (a) == dw_val_class_const) | |
4302 | return a->dw_attr_val.v.val_int; | |
4303 | ||
40e8cc95 | 4304 | abort (); |
a96c67ec JM |
4305 | } |
4306 | ||
3f76745e | 4307 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4308 | |
3f76745e JM |
4309 | static inline void |
4310 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
4311 | register dw_die_ref die; | |
4312 | register enum dwarf_attribute attr_kind; | |
4313 | register unsigned long unsigned_val; | |
a3f97cbb | 4314 | { |
3f76745e JM |
4315 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4316 | ||
4317 | attr->dw_attr_next = NULL; | |
4318 | attr->dw_attr = attr_kind; | |
4319 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4320 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4321 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4322 | } |
71dfc51f | 4323 | |
c6991660 | 4324 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4325 | static inline unsigned long |
4326 | AT_unsigned (a) | |
4327 | register dw_attr_ref a; | |
4328 | { | |
4329 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4330 | return a->dw_attr_val.v.val_unsigned; | |
4331 | ||
40e8cc95 | 4332 | abort (); |
a96c67ec JM |
4333 | } |
4334 | ||
3f76745e JM |
4335 | /* Add an unsigned double integer attribute value to a DIE. */ |
4336 | ||
4337 | static inline void | |
4338 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 4339 | register dw_die_ref die; |
3f76745e JM |
4340 | register enum dwarf_attribute attr_kind; |
4341 | register unsigned long val_hi; | |
4342 | register unsigned long val_low; | |
a3f97cbb | 4343 | { |
3f76745e | 4344 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4345 | |
3f76745e JM |
4346 | attr->dw_attr_next = NULL; |
4347 | attr->dw_attr = attr_kind; | |
4348 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4349 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4350 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4351 | add_dwarf_attr (die, attr); | |
4352 | } | |
71dfc51f | 4353 | |
3f76745e | 4354 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4355 | |
3f76745e JM |
4356 | static inline void |
4357 | add_AT_float (die, attr_kind, length, array) | |
4358 | register dw_die_ref die; | |
4359 | register enum dwarf_attribute attr_kind; | |
4360 | register unsigned length; | |
4361 | register long *array; | |
4362 | { | |
4363 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4364 | ||
4365 | attr->dw_attr_next = NULL; | |
4366 | attr->dw_attr = attr_kind; | |
4367 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4368 | attr->dw_attr_val.v.val_float.length = length; | |
4369 | attr->dw_attr_val.v.val_float.array = array; | |
4370 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4371 | } |
4372 | ||
3f76745e | 4373 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4374 | |
3f76745e JM |
4375 | static inline void |
4376 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 4377 | register dw_die_ref die; |
3f76745e | 4378 | register enum dwarf_attribute attr_kind; |
d560ee52 | 4379 | register const char *str; |
a3f97cbb | 4380 | { |
3f76745e | 4381 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4382 | |
3f76745e JM |
4383 | attr->dw_attr_next = NULL; |
4384 | attr->dw_attr = attr_kind; | |
4385 | attr->dw_attr_val.val_class = dw_val_class_str; | |
4386 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
4387 | add_dwarf_attr (die, attr); | |
4388 | } | |
71dfc51f | 4389 | |
c6991660 | 4390 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4391 | static inline const char * |
4392 | AT_string (a) | |
4393 | register dw_attr_ref a; | |
4394 | { | |
4395 | if (a && AT_class (a) == dw_val_class_str) | |
4396 | return a->dw_attr_val.v.val_str; | |
4397 | ||
40e8cc95 | 4398 | abort (); |
a96c67ec JM |
4399 | } |
4400 | ||
3f76745e | 4401 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4402 | |
3f76745e JM |
4403 | static inline void |
4404 | add_AT_die_ref (die, attr_kind, targ_die) | |
4405 | register dw_die_ref die; | |
4406 | register enum dwarf_attribute attr_kind; | |
4407 | register dw_die_ref targ_die; | |
4408 | { | |
4409 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4410 | |
3f76745e JM |
4411 | attr->dw_attr_next = NULL; |
4412 | attr->dw_attr = attr_kind; | |
4413 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4414 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4415 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4416 | add_dwarf_attr (die, attr); |
4417 | } | |
b1ccbc24 | 4418 | |
c6991660 | 4419 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4420 | static inline dw_die_ref |
4421 | AT_ref (a) | |
4422 | register dw_attr_ref a; | |
4423 | { | |
4424 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4425 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4426 | |
40e8cc95 | 4427 | abort (); |
a96c67ec JM |
4428 | } |
4429 | ||
881c6935 JM |
4430 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); |
4431 | static inline int | |
4432 | AT_ref_external (a) | |
4433 | register dw_attr_ref a; | |
4434 | { | |
4435 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4436 | return a->dw_attr_val.v.val_die_ref.external; | |
4437 | ||
4438 | return 0; | |
4439 | } | |
4440 | ||
4441 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
4442 | static inline void | |
4443 | set_AT_ref_external (a, i) | |
4444 | register dw_attr_ref a; | |
4445 | int i; | |
4446 | { | |
4447 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4448 | a->dw_attr_val.v.val_die_ref.external = i; | |
4449 | else | |
4450 | abort (); | |
4451 | } | |
4452 | ||
3f76745e | 4453 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4454 | |
3f76745e JM |
4455 | static inline void |
4456 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
4457 | register dw_die_ref die; | |
4458 | register enum dwarf_attribute attr_kind; | |
4459 | register unsigned targ_fde; | |
4460 | { | |
4461 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 4462 | |
3f76745e JM |
4463 | attr->dw_attr_next = NULL; |
4464 | attr->dw_attr = attr_kind; | |
4465 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4466 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4467 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4468 | } |
71dfc51f | 4469 | |
3f76745e | 4470 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4471 | |
3f76745e JM |
4472 | static inline void |
4473 | add_AT_loc (die, attr_kind, loc) | |
4474 | register dw_die_ref die; | |
4475 | register enum dwarf_attribute attr_kind; | |
4476 | register dw_loc_descr_ref loc; | |
4477 | { | |
4478 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4479 | |
3f76745e JM |
4480 | attr->dw_attr_next = NULL; |
4481 | attr->dw_attr = attr_kind; | |
4482 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4483 | attr->dw_attr_val.v.val_loc = loc; | |
4484 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4485 | } |
4486 | ||
c6991660 | 4487 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4488 | static inline dw_loc_descr_ref |
4489 | AT_loc (a) | |
4490 | register dw_attr_ref a; | |
4491 | { | |
4492 | if (a && AT_class (a) == dw_val_class_loc) | |
4493 | return a->dw_attr_val.v.val_loc; | |
4494 | ||
40e8cc95 | 4495 | abort (); |
a96c67ec JM |
4496 | } |
4497 | ||
63e46568 DB |
4498 | static inline void |
4499 | add_AT_loc_list (die, attr_kind, loc_list) | |
4500 | register dw_die_ref die; | |
4501 | register enum dwarf_attribute attr_kind; | |
4502 | register dw_loc_list_ref loc_list; | |
4503 | { | |
4504 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4505 | ||
4506 | attr->dw_attr_next = NULL; | |
4507 | attr->dw_attr = attr_kind; | |
4508 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4509 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4510 | add_dwarf_attr (die, attr); | |
4511 | have_location_lists = 1; | |
4512 | } | |
4513 | ||
4514 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); | |
4515 | ||
4516 | static inline dw_loc_list_ref | |
4517 | AT_loc_list (a) | |
4518 | register dw_attr_ref a; | |
4519 | { | |
4520 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4521 | return a->dw_attr_val.v.val_loc_list; | |
4522 | ||
4523 | abort (); | |
4524 | } | |
4525 | ||
3f76745e | 4526 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4527 | |
3f76745e JM |
4528 | static inline void |
4529 | add_AT_addr (die, attr_kind, addr) | |
4530 | register dw_die_ref die; | |
4531 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 4532 | rtx addr; |
a3f97cbb | 4533 | { |
3f76745e | 4534 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4535 | |
3f76745e JM |
4536 | attr->dw_attr_next = NULL; |
4537 | attr->dw_attr = attr_kind; | |
4538 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4539 | attr->dw_attr_val.v.val_addr = addr; | |
4540 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4541 | } |
4542 | ||
c6991660 | 4543 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 4544 | static inline rtx |
a96c67ec JM |
4545 | AT_addr (a) |
4546 | register dw_attr_ref a; | |
4547 | { | |
4548 | if (a && AT_class (a) == dw_val_class_addr) | |
4549 | return a->dw_attr_val.v.val_addr; | |
4550 | ||
40e8cc95 | 4551 | abort (); |
a96c67ec JM |
4552 | } |
4553 | ||
3f76745e | 4554 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4555 | |
3f76745e JM |
4556 | static inline void |
4557 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
4558 | register dw_die_ref die; | |
4559 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4560 | register const char *lbl_id; |
a3f97cbb | 4561 | { |
3f76745e | 4562 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4563 | |
3f76745e JM |
4564 | attr->dw_attr_next = NULL; |
4565 | attr->dw_attr = attr_kind; | |
4566 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4567 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4568 | add_dwarf_attr (die, attr); | |
4569 | } | |
71dfc51f | 4570 | |
3f76745e JM |
4571 | /* Add a section offset attribute value to a DIE. */ |
4572 | ||
4573 | static inline void | |
8b790721 | 4574 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
4575 | register dw_die_ref die; |
4576 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4577 | register const char *label; |
3f76745e JM |
4578 | { |
4579 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4580 | |
3f76745e JM |
4581 | attr->dw_attr_next = NULL; |
4582 | attr->dw_attr = attr_kind; | |
8b790721 | 4583 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4584 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4585 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4586 | } |
4587 | ||
c6991660 | 4588 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4589 | static inline const char * |
4590 | AT_lbl (a) | |
4591 | register dw_attr_ref a; | |
a3f97cbb | 4592 | { |
a96c67ec JM |
4593 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4594 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4595 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4596 | |
40e8cc95 | 4597 | abort (); |
a3f97cbb JW |
4598 | } |
4599 | ||
3f76745e | 4600 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4601 | |
3f76745e JM |
4602 | static inline dw_attr_ref |
4603 | get_AT (die, attr_kind) | |
4604 | register dw_die_ref die; | |
4605 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 4606 | { |
3f76745e JM |
4607 | register dw_attr_ref a; |
4608 | register dw_die_ref spec = NULL; | |
556273e0 | 4609 | |
3f76745e JM |
4610 | if (die != NULL) |
4611 | { | |
4612 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
4613 | { | |
4614 | if (a->dw_attr == attr_kind) | |
4615 | return a; | |
71dfc51f | 4616 | |
3f76745e JM |
4617 | if (a->dw_attr == DW_AT_specification |
4618 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 4619 | spec = AT_ref (a); |
3f76745e | 4620 | } |
71dfc51f | 4621 | |
3f76745e JM |
4622 | if (spec) |
4623 | return get_AT (spec, attr_kind); | |
4624 | } | |
4625 | ||
4626 | return NULL; | |
f37230f0 JM |
4627 | } |
4628 | ||
3f76745e JM |
4629 | /* Return the "low pc" attribute value, typically associated with |
4630 | a subprogram DIE. Return null if the "low pc" attribute is | |
4631 | either not prsent, or if it cannot be represented as an | |
4632 | assembler label identifier. */ | |
71dfc51f | 4633 | |
a96c67ec | 4634 | static inline const char * |
3f76745e JM |
4635 | get_AT_low_pc (die) |
4636 | register dw_die_ref die; | |
7e23cb16 | 4637 | { |
3f76745e | 4638 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
40e8cc95 | 4639 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4640 | } |
4641 | ||
3f76745e JM |
4642 | /* Return the "high pc" attribute value, typically associated with |
4643 | a subprogram DIE. Return null if the "high pc" attribute is | |
4644 | either not prsent, or if it cannot be represented as an | |
4645 | assembler label identifier. */ | |
71dfc51f | 4646 | |
a96c67ec | 4647 | static inline const char * |
3f76745e | 4648 | get_AT_hi_pc (die) |
a3f97cbb JW |
4649 | register dw_die_ref die; |
4650 | { | |
3f76745e | 4651 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
40e8cc95 | 4652 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4653 | } |
4654 | ||
4655 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4656 | NULL if it is not present. */ | |
71dfc51f | 4657 | |
a96c67ec | 4658 | static inline const char * |
3f76745e JM |
4659 | get_AT_string (die, attr_kind) |
4660 | register dw_die_ref die; | |
4661 | register enum dwarf_attribute attr_kind; | |
4662 | { | |
4663 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4664 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4665 | } |
4666 | ||
3f76745e JM |
4667 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4668 | if it is not present. */ | |
71dfc51f | 4669 | |
3f76745e JM |
4670 | static inline int |
4671 | get_AT_flag (die, attr_kind) | |
4672 | register dw_die_ref die; | |
4673 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4674 | { |
3f76745e | 4675 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4676 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4677 | } |
4678 | ||
3f76745e JM |
4679 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4680 | if it is not present. */ | |
71dfc51f | 4681 | |
3f76745e JM |
4682 | static inline unsigned |
4683 | get_AT_unsigned (die, attr_kind) | |
4684 | register dw_die_ref die; | |
4685 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4686 | { |
3f76745e | 4687 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4688 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4689 | } |
71dfc51f | 4690 | |
a96c67ec JM |
4691 | static inline dw_die_ref |
4692 | get_AT_ref (die, attr_kind) | |
4693 | dw_die_ref die; | |
4694 | register enum dwarf_attribute attr_kind; | |
4695 | { | |
4696 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4697 | return a ? AT_ref (a) : NULL; |
3f76745e | 4698 | } |
71dfc51f | 4699 | |
3f76745e JM |
4700 | static inline int |
4701 | is_c_family () | |
4702 | { | |
4703 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4704 | |
3f76745e JM |
4705 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4706 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4707 | } |
71dfc51f | 4708 | |
3f76745e JM |
4709 | static inline int |
4710 | is_fortran () | |
4711 | { | |
4712 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4713 | |
3f76745e | 4714 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4715 | } |
71dfc51f | 4716 | |
28985b81 AG |
4717 | static inline int |
4718 | is_java () | |
4719 | { | |
4720 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
4721 | ||
4722 | return (lang == DW_LANG_Java); | |
4723 | } | |
4724 | ||
10a11b75 | 4725 | /* Free up the memory used by A. */ |
71dfc51f | 4726 | |
c6991660 | 4727 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4728 | static inline void |
10a11b75 JM |
4729 | free_AT (a) |
4730 | dw_attr_ref a; | |
4731 | { | |
4732 | switch (AT_class (a)) | |
4733 | { | |
10a11b75 JM |
4734 | case dw_val_class_str: |
4735 | case dw_val_class_lbl_id: | |
4736 | case dw_val_class_lbl_offset: | |
4737 | free (a->dw_attr_val.v.val_str); | |
4738 | break; | |
4739 | ||
3724ec07 WC |
4740 | case dw_val_class_float: |
4741 | free (a->dw_attr_val.v.val_float.array); | |
4742 | break; | |
0b34cf1e | 4743 | |
10a11b75 JM |
4744 | default: |
4745 | break; | |
4746 | } | |
4747 | ||
4748 | free (a); | |
556273e0 | 4749 | } |
10a11b75 JM |
4750 | |
4751 | /* Remove the specified attribute if present. */ | |
4752 | ||
4753 | static void | |
3f76745e JM |
4754 | remove_AT (die, attr_kind) |
4755 | register dw_die_ref die; | |
4756 | register enum dwarf_attribute attr_kind; | |
4757 | { | |
a96c67ec | 4758 | register dw_attr_ref *p; |
6d649d26 | 4759 | register dw_attr_ref removed = NULL; |
a3f97cbb | 4760 | |
3f76745e JM |
4761 | if (die != NULL) |
4762 | { | |
a96c67ec JM |
4763 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4764 | if ((*p)->dw_attr == attr_kind) | |
4765 | { | |
4766 | removed = *p; | |
4767 | *p = (*p)->dw_attr_next; | |
4768 | break; | |
4769 | } | |
71dfc51f | 4770 | |
a96c67ec | 4771 | if (removed != 0) |
10a11b75 JM |
4772 | free_AT (removed); |
4773 | } | |
4774 | } | |
71dfc51f | 4775 | |
10a11b75 | 4776 | /* Free up the memory used by DIE. */ |
71dfc51f | 4777 | |
c6991660 | 4778 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
4779 | static inline void |
4780 | free_die (die) | |
4781 | dw_die_ref die; | |
4782 | { | |
4783 | remove_children (die); | |
4784 | free (die); | |
3f76745e | 4785 | } |
71dfc51f | 4786 | |
3f76745e | 4787 | /* Discard the children of this DIE. */ |
71dfc51f | 4788 | |
10a11b75 | 4789 | static void |
3f76745e JM |
4790 | remove_children (die) |
4791 | register dw_die_ref die; | |
4792 | { | |
4793 | register dw_die_ref child_die = die->die_child; | |
4794 | ||
4795 | die->die_child = NULL; | |
3f76745e JM |
4796 | |
4797 | while (child_die != NULL) | |
a3f97cbb | 4798 | { |
3f76745e JM |
4799 | register dw_die_ref tmp_die = child_die; |
4800 | register dw_attr_ref a; | |
71dfc51f | 4801 | |
3f76745e | 4802 | child_die = child_die->die_sib; |
556273e0 KH |
4803 | |
4804 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4805 | { |
3f76745e | 4806 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4807 | |
3f76745e | 4808 | a = a->dw_attr_next; |
10a11b75 | 4809 | free_AT (tmp_a); |
a3f97cbb | 4810 | } |
71dfc51f | 4811 | |
10a11b75 | 4812 | free_die (tmp_die); |
3f76745e JM |
4813 | } |
4814 | } | |
71dfc51f | 4815 | |
a96c67ec | 4816 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4817 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 4818 | |
3f76745e JM |
4819 | static inline void |
4820 | add_child_die (die, child_die) | |
4821 | register dw_die_ref die; | |
4822 | register dw_die_ref child_die; | |
4823 | { | |
4824 | if (die != NULL && child_die != NULL) | |
e90b62db | 4825 | { |
3a88cbd1 JL |
4826 | if (die == child_die) |
4827 | abort (); | |
3f76745e | 4828 | child_die->die_parent = die; |
a96c67ec JM |
4829 | child_die->die_sib = die->die_child; |
4830 | die->die_child = child_die; | |
3f76745e JM |
4831 | } |
4832 | } | |
4833 | ||
2081603c JM |
4834 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4835 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4836 | |
4837 | static void | |
4838 | splice_child_die (parent, child) | |
4839 | dw_die_ref parent, child; | |
4840 | { | |
4841 | dw_die_ref *p; | |
4842 | ||
4843 | /* We want the declaration DIE from inside the class, not the | |
4844 | specification DIE at toplevel. */ | |
4845 | if (child->die_parent != parent) | |
2081603c JM |
4846 | { |
4847 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4848 | if (tmp) | |
4849 | child = tmp; | |
4850 | } | |
10a11b75 | 4851 | |
2081603c JM |
4852 | if (child->die_parent != parent |
4853 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4854 | abort (); |
4855 | ||
5de0e8d4 | 4856 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
4857 | if (*p == child) |
4858 | { | |
4859 | *p = child->die_sib; | |
4860 | break; | |
4861 | } | |
4862 | ||
4863 | child->die_sib = parent->die_child; | |
4864 | parent->die_child = child; | |
4865 | } | |
4866 | ||
3f76745e JM |
4867 | /* Return a pointer to a newly created DIE node. */ |
4868 | ||
4869 | static inline dw_die_ref | |
4870 | new_die (tag_value, parent_die) | |
4871 | register enum dwarf_tag tag_value; | |
4872 | register dw_die_ref parent_die; | |
4873 | { | |
3f4907a6 | 4874 | register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
4875 | |
4876 | die->die_tag = tag_value; | |
3f76745e JM |
4877 | |
4878 | if (parent_die != NULL) | |
4879 | add_child_die (parent_die, die); | |
4880 | else | |
ef76d03b JW |
4881 | { |
4882 | limbo_die_node *limbo_node; | |
4883 | ||
4884 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4885 | limbo_node->die = die; | |
4886 | limbo_node->next = limbo_die_list; | |
4887 | limbo_die_list = limbo_node; | |
4888 | } | |
71dfc51f | 4889 | |
3f76745e JM |
4890 | return die; |
4891 | } | |
71dfc51f | 4892 | |
3f76745e | 4893 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4894 | |
3f76745e JM |
4895 | static inline dw_die_ref |
4896 | lookup_type_die (type) | |
4897 | register tree type; | |
4898 | { | |
4061f623 BS |
4899 | if (TREE_CODE (type) == VECTOR_TYPE) |
4900 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
3f76745e JM |
4901 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
4902 | } | |
e90b62db | 4903 | |
3f76745e | 4904 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4905 | |
10a11b75 | 4906 | static inline void |
3f76745e JM |
4907 | equate_type_number_to_die (type, type_die) |
4908 | register tree type; | |
4909 | register dw_die_ref type_die; | |
4910 | { | |
4911 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4912 | } | |
71dfc51f | 4913 | |
3f76745e | 4914 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4915 | |
3f76745e JM |
4916 | static inline dw_die_ref |
4917 | lookup_decl_die (decl) | |
4918 | register tree decl; | |
4919 | { | |
4920 | register unsigned decl_id = DECL_UID (decl); | |
4921 | ||
4922 | return (decl_id < decl_die_table_in_use | |
4923 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4924 | } |
4925 | ||
3f76745e | 4926 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4927 | |
3f76745e JM |
4928 | static void |
4929 | equate_decl_number_to_die (decl, decl_die) | |
4930 | register tree decl; | |
4931 | register dw_die_ref decl_die; | |
a3f97cbb | 4932 | { |
3f76745e | 4933 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 4934 | register unsigned num_allocated; |
d291dd49 | 4935 | |
3f76745e | 4936 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4937 | { |
3f76745e JM |
4938 | num_allocated |
4939 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4940 | / DECL_DIE_TABLE_INCREMENT) | |
4941 | * DECL_DIE_TABLE_INCREMENT; | |
4942 | ||
4943 | decl_die_table | |
4944 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4945 | sizeof (dw_die_ref) * num_allocated); | |
4946 | ||
961192e1 | 4947 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
4948 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
4949 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4950 | } |
71dfc51f | 4951 | |
3f76745e JM |
4952 | if (decl_id >= decl_die_table_in_use) |
4953 | decl_die_table_in_use = (decl_id + 1); | |
4954 | ||
4955 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 4956 | } |
3f76745e JM |
4957 | \f |
4958 | /* Keep track of the number of spaces used to indent the | |
4959 | output of the debugging routines that print the structure of | |
4960 | the DIE internal representation. */ | |
4961 | static int print_indent; | |
71dfc51f | 4962 | |
3f76745e JM |
4963 | /* Indent the line the number of spaces given by print_indent. */ |
4964 | ||
4965 | static inline void | |
4966 | print_spaces (outfile) | |
4967 | FILE *outfile; | |
4968 | { | |
4969 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4970 | } |
4971 | ||
956d6950 | 4972 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4973 | This routine is a debugging aid only. */ |
71dfc51f | 4974 | |
a3f97cbb | 4975 | static void |
3f76745e JM |
4976 | print_die (die, outfile) |
4977 | dw_die_ref die; | |
4978 | FILE *outfile; | |
a3f97cbb | 4979 | { |
3f76745e JM |
4980 | register dw_attr_ref a; |
4981 | register dw_die_ref c; | |
71dfc51f | 4982 | |
3f76745e | 4983 | print_spaces (outfile); |
2d8b0f3a | 4984 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
4985 | die->die_offset, dwarf_tag_name (die->die_tag)); |
4986 | print_spaces (outfile); | |
2d8b0f3a JL |
4987 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
4988 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
4989 | |
4990 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 4991 | { |
3f76745e JM |
4992 | print_spaces (outfile); |
4993 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
4994 | ||
a96c67ec | 4995 | switch (AT_class (a)) |
3f76745e JM |
4996 | { |
4997 | case dw_val_class_addr: | |
4998 | fprintf (outfile, "address"); | |
4999 | break; | |
5000 | case dw_val_class_loc: | |
5001 | fprintf (outfile, "location descriptor"); | |
5002 | break; | |
63e46568 DB |
5003 | case dw_val_class_loc_list: |
5004 | fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol); | |
5005 | break; | |
3f76745e | 5006 | case dw_val_class_const: |
a96c67ec | 5007 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5008 | break; |
5009 | case dw_val_class_unsigned_const: | |
a96c67ec | 5010 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5011 | break; |
5012 | case dw_val_class_long_long: | |
2d8b0f3a | 5013 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5014 | a->dw_attr_val.v.val_long_long.hi, |
5015 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5016 | break; |
5017 | case dw_val_class_float: | |
5018 | fprintf (outfile, "floating-point constant"); | |
5019 | break; | |
5020 | case dw_val_class_flag: | |
a96c67ec | 5021 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5022 | break; |
5023 | case dw_val_class_die_ref: | |
a96c67ec | 5024 | if (AT_ref (a) != NULL) |
881c6935 | 5025 | { |
1bfb5f8f | 5026 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5027 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5028 | else | |
5029 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5030 | } | |
3f76745e JM |
5031 | else |
5032 | fprintf (outfile, "die -> <null>"); | |
5033 | break; | |
5034 | case dw_val_class_lbl_id: | |
8b790721 | 5035 | case dw_val_class_lbl_offset: |
a96c67ec | 5036 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5037 | break; |
3f76745e | 5038 | case dw_val_class_str: |
a96c67ec JM |
5039 | if (AT_string (a) != NULL) |
5040 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5041 | else |
5042 | fprintf (outfile, "<null>"); | |
5043 | break; | |
e9a25f70 JL |
5044 | default: |
5045 | break; | |
3f76745e JM |
5046 | } |
5047 | ||
5048 | fprintf (outfile, "\n"); | |
5049 | } | |
5050 | ||
5051 | if (die->die_child != NULL) | |
5052 | { | |
5053 | print_indent += 4; | |
5054 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5055 | print_die (c, outfile); | |
71dfc51f | 5056 | |
3f76745e | 5057 | print_indent -= 4; |
a3f97cbb | 5058 | } |
881c6935 JM |
5059 | if (print_indent == 0) |
5060 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5061 | } |
5062 | ||
3f76745e JM |
5063 | /* Print the contents of the source code line number correspondence table. |
5064 | This routine is a debugging aid only. */ | |
71dfc51f | 5065 | |
3f76745e JM |
5066 | static void |
5067 | print_dwarf_line_table (outfile) | |
5068 | FILE *outfile; | |
a3f97cbb | 5069 | { |
3f76745e JM |
5070 | register unsigned i; |
5071 | register dw_line_info_ref line_info; | |
5072 | ||
5073 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
5074 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 5075 | { |
3f76745e JM |
5076 | line_info = &line_info_table[i]; |
5077 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5078 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5079 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5080 | fprintf (outfile, "\n"); |
a3f97cbb | 5081 | } |
3f76745e JM |
5082 | |
5083 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5084 | } |
5085 | ||
3f76745e JM |
5086 | /* Print the information collected for a given DIE. */ |
5087 | ||
5088 | void | |
5089 | debug_dwarf_die (die) | |
5090 | dw_die_ref die; | |
5091 | { | |
5092 | print_die (die, stderr); | |
5093 | } | |
5094 | ||
5095 | /* Print all DWARF information collected for the compilation unit. | |
5096 | This routine is a debugging aid only. */ | |
5097 | ||
5098 | void | |
5099 | debug_dwarf () | |
5100 | { | |
5101 | print_indent = 0; | |
5102 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5103 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5104 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5105 | } |
5106 | \f | |
a96c67ec JM |
5107 | /* We build up the lists of children and attributes by pushing new ones |
5108 | onto the beginning of the list. Reverse the lists for DIE so that | |
5109 | they are in order of addition. */ | |
71dfc51f | 5110 | |
f37230f0 | 5111 | static void |
a96c67ec | 5112 | reverse_die_lists (die) |
3f76745e | 5113 | register dw_die_ref die; |
f37230f0 | 5114 | { |
a96c67ec JM |
5115 | register dw_die_ref c, cp, cn; |
5116 | register dw_attr_ref a, ap, an; | |
71dfc51f | 5117 | |
a96c67ec | 5118 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5119 | { |
5120 | an = a->dw_attr_next; | |
5121 | a->dw_attr_next = ap; | |
5122 | ap = a; | |
a3f97cbb | 5123 | } |
7d9d8943 | 5124 | die->die_attr = ap; |
3f76745e | 5125 | |
7d9d8943 AM |
5126 | for (c = die->die_child, cp = 0; c; c = cn) |
5127 | { | |
5128 | cn = c->die_sib; | |
5129 | c->die_sib = cp; | |
5130 | cp = c; | |
5131 | } | |
5132 | die->die_child = cp; | |
a3f97cbb JW |
5133 | } |
5134 | ||
881c6935 JM |
5135 | /* reverse_die_lists only reverses the single die you pass it. Since |
5136 | we used to reverse all dies in add_sibling_attributes, which runs | |
5137 | through all the dies, it would reverse all the dies. Now, however, | |
5138 | since we don't call reverse_die_lists in add_sibling_attributes, we | |
5139 | need a routine to recursively reverse all the dies. This is that | |
5140 | routine. */ | |
71dfc51f | 5141 | |
7d9d8943 | 5142 | static void |
881c6935 | 5143 | reverse_all_dies (die) |
7d9d8943 | 5144 | register dw_die_ref die; |
a3f97cbb | 5145 | { |
7d9d8943 | 5146 | register dw_die_ref c; |
71dfc51f | 5147 | |
7d9d8943 | 5148 | reverse_die_lists (die); |
3f76745e | 5149 | |
881c6935 JM |
5150 | for (c = die->die_child; c; c = c->die_sib) |
5151 | reverse_all_dies (c); | |
5152 | } | |
5153 | ||
5154 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is | |
5155 | the CU for the enclosing include file, if any. BINCL_DIE is the | |
5156 | DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this | |
5157 | include file. */ | |
5158 | ||
5159 | static dw_die_ref | |
5160 | push_new_compile_unit (old_unit, bincl_die) | |
5161 | dw_die_ref old_unit, bincl_die; | |
5162 | { | |
5163 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5164 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
5165 | new_unit->die_sib = old_unit; | |
5166 | return new_unit; | |
5167 | } | |
5168 | ||
5169 | /* Close an include-file CU and reopen the enclosing one. */ | |
5170 | ||
5171 | static dw_die_ref | |
5172 | pop_compile_unit (old_unit) | |
5173 | dw_die_ref old_unit; | |
5174 | { | |
5175 | dw_die_ref new_unit = old_unit->die_sib; | |
5176 | old_unit->die_sib = NULL; | |
5177 | return new_unit; | |
5178 | } | |
5179 | ||
5180 | #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) | |
5181 | #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
5182 | ||
5183 | /* Calculate the checksum of a location expression. */ | |
5184 | ||
5185 | static inline void | |
5186 | loc_checksum (loc, ctx) | |
5187 | dw_loc_descr_ref loc; | |
5188 | struct md5_ctx *ctx; | |
5189 | { | |
5190 | PROCESS (loc->dw_loc_opc); | |
5191 | PROCESS (loc->dw_loc_oprnd1); | |
5192 | PROCESS (loc->dw_loc_oprnd2); | |
5193 | } | |
5194 | ||
5195 | /* Calculate the checksum of an attribute. */ | |
5196 | ||
5197 | static void | |
5198 | attr_checksum (at, ctx) | |
5199 | dw_attr_ref at; | |
5200 | struct md5_ctx *ctx; | |
5201 | { | |
5202 | dw_loc_descr_ref loc; | |
5203 | rtx r; | |
5204 | ||
5205 | PROCESS (at->dw_attr); | |
5206 | ||
5207 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5208 | if (at->dw_attr == DW_AT_decl_file |
5209 | /* Or that this was compiled with a different compiler snapshot; if | |
5210 | the output is the same, that's what matters. */ | |
5211 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5212 | return; |
5213 | ||
5214 | switch (AT_class (at)) | |
5215 | { | |
5216 | case dw_val_class_const: | |
5217 | PROCESS (at->dw_attr_val.v.val_int); | |
5218 | break; | |
5219 | case dw_val_class_unsigned_const: | |
5220 | PROCESS (at->dw_attr_val.v.val_unsigned); | |
5221 | break; | |
5222 | case dw_val_class_long_long: | |
5223 | PROCESS (at->dw_attr_val.v.val_long_long); | |
5224 | break; | |
5225 | case dw_val_class_float: | |
5226 | PROCESS (at->dw_attr_val.v.val_float); | |
5227 | break; | |
5228 | case dw_val_class_flag: | |
5229 | PROCESS (at->dw_attr_val.v.val_flag); | |
5230 | break; | |
5231 | ||
5232 | case dw_val_class_str: | |
5233 | PROCESS_STRING (AT_string (at)); | |
5234 | break; | |
5235 | case dw_val_class_addr: | |
5236 | r = AT_addr (at); | |
5237 | switch (GET_CODE (r)) | |
5238 | { | |
5239 | case SYMBOL_REF: | |
5240 | PROCESS_STRING (XSTR (r, 0)); | |
5241 | break; | |
5242 | ||
5243 | default: | |
5244 | abort (); | |
5245 | } | |
5246 | break; | |
5247 | ||
5248 | case dw_val_class_loc: | |
5249 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5250 | loc_checksum (loc, ctx); | |
5251 | break; | |
5252 | ||
5253 | case dw_val_class_die_ref: | |
5254 | if (AT_ref (at)->die_offset) | |
5255 | PROCESS (AT_ref (at)->die_offset); | |
5256 | /* FIXME else use target die name or something. */ | |
5257 | ||
5258 | case dw_val_class_fde_ref: | |
5259 | case dw_val_class_lbl_id: | |
5260 | case dw_val_class_lbl_offset: | |
5261 | ||
5262 | default: | |
5263 | break; | |
5264 | } | |
5265 | } | |
5266 | ||
5267 | /* Calculate the checksum of a DIE. */ | |
5268 | ||
5269 | static void | |
5270 | die_checksum (die, ctx) | |
5271 | dw_die_ref die; | |
5272 | struct md5_ctx *ctx; | |
5273 | { | |
5274 | dw_die_ref c; | |
5275 | dw_attr_ref a; | |
5276 | ||
5277 | PROCESS (die->die_tag); | |
5278 | ||
5279 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5280 | attr_checksum (a, ctx); | |
5281 | ||
5282 | for (c = die->die_child; c; c = c->die_sib) | |
5283 | die_checksum (c, ctx); | |
5284 | } | |
5285 | ||
5286 | #undef PROCESS | |
5287 | #undef PROCESS_STRING | |
5288 | ||
5289 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5290 | info section. */ | |
5291 | static char *comdat_symbol_id; | |
5292 | ||
5293 | /* The index of the current symbol within the current comdat CU. */ | |
5294 | static unsigned int comdat_symbol_number; | |
5295 | ||
5296 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5297 | children, and set comdat_symbol_id accordingly. */ | |
5298 | ||
5299 | static void | |
5300 | compute_section_prefix (unit_die) | |
5301 | dw_die_ref unit_die; | |
5302 | { | |
5303 | char *p, *name; | |
5304 | int i; | |
5305 | unsigned char checksum[16]; | |
5306 | struct md5_ctx ctx; | |
5307 | ||
5308 | md5_init_ctx (&ctx); | |
5309 | die_checksum (unit_die, &ctx); | |
5310 | md5_finish_ctx (&ctx, checksum); | |
5311 | ||
b3e68a79 | 5312 | p = lbasename (get_AT_string (unit_die, DW_AT_name)); |
881c6935 JM |
5313 | name = (char *) alloca (strlen (p) + 64); |
5314 | sprintf (name, "%s.", p); | |
5315 | ||
5316 | clean_symbol_name (name); | |
5317 | ||
5318 | p = name + strlen (name); | |
5319 | for (i = 0; i < 4; ++i) | |
5320 | { | |
5321 | sprintf (p, "%.2x", checksum[i]); | |
5322 | p += 2; | |
5323 | } | |
5324 | ||
5325 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5326 | comdat_symbol_number = 0; | |
5327 | } | |
5328 | ||
5329 | /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */ | |
5330 | ||
5331 | static int | |
5332 | is_type_die (die) | |
5333 | dw_die_ref die; | |
5334 | { | |
5335 | switch (die->die_tag) | |
5336 | { | |
5337 | case DW_TAG_array_type: | |
5338 | case DW_TAG_class_type: | |
5339 | case DW_TAG_enumeration_type: | |
5340 | case DW_TAG_pointer_type: | |
5341 | case DW_TAG_reference_type: | |
5342 | case DW_TAG_string_type: | |
5343 | case DW_TAG_structure_type: | |
5344 | case DW_TAG_subroutine_type: | |
5345 | case DW_TAG_union_type: | |
5346 | case DW_TAG_ptr_to_member_type: | |
5347 | case DW_TAG_set_type: | |
5348 | case DW_TAG_subrange_type: | |
5349 | case DW_TAG_base_type: | |
5350 | case DW_TAG_const_type: | |
5351 | case DW_TAG_file_type: | |
5352 | case DW_TAG_packed_type: | |
5353 | case DW_TAG_volatile_type: | |
5354 | return 1; | |
5355 | default: | |
5356 | return 0; | |
5357 | } | |
5358 | } | |
5359 | ||
5360 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5361 | Basically, we want to choose the bits that are likely to be shared between | |
5362 | compilations (types) and leave out the bits that are specific to individual | |
5363 | compilations (functions). */ | |
5364 | ||
5365 | static int | |
5366 | is_comdat_die (c) | |
5367 | dw_die_ref c; | |
5368 | { | |
5369 | #if 1 | |
5370 | /* I think we want to leave base types and __vtbl_ptr_type in the | |
5371 | main CU, as we do for stabs. The advantage is a greater | |
5372 | likelihood of sharing between objects that don't include headers | |
5373 | in the same order (and therefore would put the base types in a | |
5374 | different comdat). jason 8/28/00 */ | |
5375 | if (c->die_tag == DW_TAG_base_type) | |
5376 | return 0; | |
5377 | ||
5378 | if (c->die_tag == DW_TAG_pointer_type | |
5379 | || c->die_tag == DW_TAG_reference_type | |
5380 | || c->die_tag == DW_TAG_const_type | |
5381 | || c->die_tag == DW_TAG_volatile_type) | |
5382 | { | |
5383 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
5384 | return t ? is_comdat_die (t) : 0; | |
5385 | } | |
5386 | #endif | |
5387 | ||
5388 | return is_type_die (c); | |
5389 | } | |
5390 | ||
5391 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5392 | compilation unit. */ | |
5393 | ||
5394 | static int | |
5395 | is_symbol_die (c) | |
5396 | dw_die_ref c; | |
5397 | { | |
5398 | if (is_type_die (c)) | |
5399 | return 1; | |
63e46568 | 5400 | if (get_AT (c, DW_AT_declaration) |
881c6935 JM |
5401 | && ! get_AT (c, DW_AT_specification)) |
5402 | return 1; | |
5403 | return 0; | |
5404 | } | |
5405 | ||
5406 | static char * | |
63e46568 DB |
5407 | gen_internal_sym (prefix) |
5408 | const char *prefix; | |
881c6935 JM |
5409 | { |
5410 | char buf[256]; | |
5411 | static int label_num; | |
63e46568 | 5412 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5413 | return xstrdup (buf); |
5414 | } | |
5415 | ||
5416 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5417 | ||
5418 | static void | |
5419 | assign_symbol_names (die) | |
5420 | register dw_die_ref die; | |
5421 | { | |
5422 | register dw_die_ref c; | |
5423 | ||
5424 | if (is_symbol_die (die)) | |
5425 | { | |
5426 | if (comdat_symbol_id) | |
5427 | { | |
5428 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
5429 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, | |
5430 | comdat_symbol_id, comdat_symbol_number++); | |
5431 | die->die_symbol = xstrdup (p); | |
5432 | } | |
5433 | else | |
63e46568 | 5434 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5435 | } |
5436 | ||
5437 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5438 | assign_symbol_names (c); | |
5439 | } | |
5440 | ||
5441 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5442 | additional compilation units for each of the include files we see | |
5443 | bracketed by BINCL/EINCL. */ | |
5444 | ||
5445 | static void | |
5446 | break_out_includes (die) | |
5447 | register dw_die_ref die; | |
5448 | { | |
5449 | dw_die_ref *ptr; | |
5450 | register dw_die_ref unit = NULL; | |
5451 | limbo_die_node *node; | |
5452 | ||
5453 | for (ptr = &(die->die_child); *ptr; ) | |
5454 | { | |
5455 | register dw_die_ref c = *ptr; | |
5456 | ||
5457 | if (c->die_tag == DW_TAG_GNU_BINCL | |
5458 | || c->die_tag == DW_TAG_GNU_EINCL | |
5459 | || (unit && is_comdat_die (c))) | |
5460 | { | |
5461 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5462 | *ptr = c->die_sib; | |
5463 | ||
5464 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5465 | { | |
5466 | unit = push_new_compile_unit (unit, c); | |
5467 | free_die (c); | |
5468 | } | |
5469 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5470 | { | |
5471 | unit = pop_compile_unit (unit); | |
5472 | free_die (c); | |
5473 | } | |
5474 | else | |
5475 | add_child_die (unit, c); | |
5476 | } | |
5477 | else | |
5478 | { | |
5479 | /* Leave this DIE in the main CU. */ | |
5480 | ptr = &(c->die_sib); | |
5481 | continue; | |
5482 | } | |
5483 | } | |
5484 | ||
5485 | #if 0 | |
5486 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5487 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5488 | if (unit != NULL) |
5489 | abort (); | |
5490 | #endif | |
5491 | ||
5492 | assign_symbol_names (die); | |
5493 | for (node = limbo_die_list; node; node = node->next) | |
5494 | { | |
5495 | compute_section_prefix (node->die); | |
5496 | assign_symbol_names (node->die); | |
5497 | } | |
5498 | } | |
5499 | ||
5500 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5501 | effect of speeding up access to siblings. To save some space, | |
5502 | avoid generating sibling attributes for DIE's without children. */ | |
5503 | ||
5504 | static void | |
5505 | add_sibling_attributes (die) | |
5506 | register dw_die_ref die; | |
5507 | { | |
5508 | register dw_die_ref c; | |
5509 | ||
5510 | if (die->die_tag != DW_TAG_compile_unit | |
5511 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5512 | /* Add the sibling link to the front of the attribute list. */ |
5513 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5514 | ||
5515 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5516 | add_sibling_attributes (c); | |
5517 | } | |
5518 | ||
63e46568 DB |
5519 | /* Output all location lists for the DIE and it's children */ |
5520 | static void | |
5521 | output_location_lists (die) | |
5522 | register dw_die_ref die; | |
5523 | { | |
5524 | dw_die_ref c; | |
5525 | dw_attr_ref d_attr; | |
5526 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) | |
5527 | { | |
5528 | if (AT_class (d_attr) == dw_val_class_loc_list) | |
5529 | { | |
5530 | output_loc_list (AT_loc_list (d_attr)); | |
5531 | } | |
5532 | } | |
5533 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5534 | output_location_lists (c); | |
5535 | ||
5536 | } | |
7d9d8943 AM |
5537 | /* The format of each DIE (and its attribute value pairs) |
5538 | is encoded in an abbreviation table. This routine builds the | |
5539 | abbreviation table and assigns a unique abbreviation id for | |
5540 | each abbreviation entry. The children of each die are visited | |
5541 | recursively. */ | |
5542 | ||
5543 | static void | |
5544 | build_abbrev_table (die) | |
5545 | register dw_die_ref die; | |
5546 | { | |
5547 | register unsigned long abbrev_id; | |
5548 | register unsigned long n_alloc; | |
5549 | register dw_die_ref c; | |
5550 | register dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5551 | |
5552 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5553 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 JM |
5554 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
5555 | { | |
5556 | if (AT_class (d_attr) == dw_val_class_die_ref | |
1bfb5f8f | 5557 | && AT_ref (d_attr)->die_mark == 0) |
881c6935 JM |
5558 | { |
5559 | if (AT_ref (d_attr)->die_symbol == 0) | |
5560 | abort (); | |
5561 | set_AT_ref_external (d_attr, 1); | |
5562 | } | |
5563 | } | |
5564 | ||
7d9d8943 AM |
5565 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5566 | { | |
5567 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
5568 | ||
5569 | if (abbrev->die_tag == die->die_tag) | |
5570 | { | |
5571 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5572 | { | |
5573 | a_attr = abbrev->die_attr; | |
5574 | d_attr = die->die_attr; | |
5575 | ||
5576 | while (a_attr != NULL && d_attr != NULL) | |
5577 | { | |
5578 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5579 | || (value_format (a_attr) != value_format (d_attr))) | |
5580 | break; | |
5581 | ||
5582 | a_attr = a_attr->dw_attr_next; | |
5583 | d_attr = d_attr->dw_attr_next; | |
5584 | } | |
5585 | ||
5586 | if (a_attr == NULL && d_attr == NULL) | |
5587 | break; | |
5588 | } | |
5589 | } | |
5590 | } | |
5591 | ||
5592 | if (abbrev_id >= abbrev_die_table_in_use) | |
5593 | { | |
5594 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5595 | { | |
5596 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5597 | abbrev_die_table |
7d9d8943 AM |
5598 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5599 | sizeof (dw_die_ref) * n_alloc); | |
5600 | ||
961192e1 | 5601 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5602 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5603 | abbrev_die_table_allocated = n_alloc; | |
5604 | } | |
5605 | ||
5606 | ++abbrev_die_table_in_use; | |
5607 | abbrev_die_table[abbrev_id] = die; | |
5608 | } | |
5609 | ||
5610 | die->die_abbrev = abbrev_id; | |
5611 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5612 | build_abbrev_table (c); | |
5613 | } | |
5614 | \f | |
5615 | /* Return the size of a string, including the null byte. | |
5616 | ||
5617 | This used to treat backslashes as escapes, and hence they were not included | |
5618 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
5619 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
5620 | we must include them in the count. */ | |
5621 | ||
5622 | static unsigned long | |
5623 | size_of_string (str) | |
5624 | register const char *str; | |
5625 | { | |
5626 | return strlen (str) + 1; | |
3f76745e JM |
5627 | } |
5628 | ||
5629 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
5630 | ||
5631 | static int | |
5632 | constant_size (value) | |
5633 | long unsigned value; | |
5634 | { | |
5635 | int log; | |
5636 | ||
5637 | if (value == 0) | |
5638 | log = 0; | |
a3f97cbb | 5639 | else |
3f76745e | 5640 | log = floor_log2 (value); |
71dfc51f | 5641 | |
3f76745e JM |
5642 | log = log / 8; |
5643 | log = 1 << (floor_log2 (log) + 1); | |
5644 | ||
5645 | return log; | |
a3f97cbb JW |
5646 | } |
5647 | ||
3f76745e JM |
5648 | /* Return the size of a DIE, as it is represented in the |
5649 | .debug_info section. */ | |
71dfc51f | 5650 | |
3f76745e JM |
5651 | static unsigned long |
5652 | size_of_die (die) | |
a3f97cbb JW |
5653 | register dw_die_ref die; |
5654 | { | |
3f76745e | 5655 | register unsigned long size = 0; |
a3f97cbb | 5656 | register dw_attr_ref a; |
71dfc51f | 5657 | |
3f76745e | 5658 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5659 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5660 | { | |
a96c67ec | 5661 | switch (AT_class (a)) |
a3f97cbb JW |
5662 | { |
5663 | case dw_val_class_addr: | |
a1a4189d | 5664 | size += DWARF2_ADDR_SIZE; |
a3f97cbb JW |
5665 | break; |
5666 | case dw_val_class_loc: | |
3f76745e | 5667 | { |
a96c67ec | 5668 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5669 | |
3f76745e JM |
5670 | /* Block length. */ |
5671 | size += constant_size (lsize); | |
5672 | size += lsize; | |
5673 | } | |
a3f97cbb | 5674 | break; |
63e46568 DB |
5675 | case dw_val_class_loc_list: |
5676 | size += DWARF_OFFSET_SIZE; | |
5677 | break; | |
a3f97cbb | 5678 | case dw_val_class_const: |
25dd13ec | 5679 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5680 | break; |
5681 | case dw_val_class_unsigned_const: | |
a96c67ec | 5682 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5683 | break; |
469ac993 | 5684 | case dw_val_class_long_long: |
2e4b9b8c | 5685 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5686 | break; |
5687 | case dw_val_class_float: | |
3f76745e | 5688 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5689 | break; |
5690 | case dw_val_class_flag: | |
3f76745e | 5691 | size += 1; |
a3f97cbb JW |
5692 | break; |
5693 | case dw_val_class_die_ref: | |
3f76745e | 5694 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5695 | break; |
5696 | case dw_val_class_fde_ref: | |
3f76745e | 5697 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5698 | break; |
5699 | case dw_val_class_lbl_id: | |
a1a4189d | 5700 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5701 | break; |
8b790721 | 5702 | case dw_val_class_lbl_offset: |
3f76745e JM |
5703 | size += DWARF_OFFSET_SIZE; |
5704 | break; | |
5705 | case dw_val_class_str: | |
a96c67ec | 5706 | size += size_of_string (AT_string (a)); |
3f76745e JM |
5707 | break; |
5708 | default: | |
5709 | abort (); | |
5710 | } | |
a3f97cbb | 5711 | } |
3f76745e JM |
5712 | |
5713 | return size; | |
a3f97cbb JW |
5714 | } |
5715 | ||
956d6950 | 5716 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
5717 | Visits the DIE's children recursively. Updates the global |
5718 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 5719 | current value of next_die_offset to update the die_offset |
3f76745e | 5720 | field in each DIE. */ |
71dfc51f | 5721 | |
a3f97cbb | 5722 | static void |
3f76745e JM |
5723 | calc_die_sizes (die) |
5724 | dw_die_ref die; | |
a3f97cbb | 5725 | { |
3f76745e JM |
5726 | register dw_die_ref c; |
5727 | die->die_offset = next_die_offset; | |
5728 | next_die_offset += size_of_die (die); | |
71dfc51f | 5729 | |
3f76745e JM |
5730 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5731 | calc_die_sizes (c); | |
71dfc51f | 5732 | |
3f76745e JM |
5733 | if (die->die_child != NULL) |
5734 | /* Count the null byte used to terminate sibling lists. */ | |
5735 | next_die_offset += 1; | |
a3f97cbb JW |
5736 | } |
5737 | ||
1bfb5f8f | 5738 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5739 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5740 | DIEs in the same CU will be marked. We used to clear out the offset |
5741 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5742 | |
5743 | static void | |
1bfb5f8f | 5744 | mark_dies (die) |
881c6935 JM |
5745 | dw_die_ref die; |
5746 | { | |
5747 | register dw_die_ref c; | |
1bfb5f8f JM |
5748 | die->die_mark = 1; |
5749 | for (c = die->die_child; c; c = c->die_sib) | |
5750 | mark_dies (c); | |
5751 | } | |
5752 | ||
5753 | /* Clear the marks for a die and its children. */ | |
5754 | ||
5755 | static void | |
5756 | unmark_dies (die) | |
5757 | dw_die_ref die; | |
5758 | { | |
5759 | register dw_die_ref c; | |
5760 | die->die_mark = 0; | |
881c6935 | 5761 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5762 | unmark_dies (c); |
881c6935 JM |
5763 | } |
5764 | ||
3f76745e JM |
5765 | /* Return the size of the .debug_pubnames table generated for the |
5766 | compilation unit. */ | |
a94dbf2c | 5767 | |
3f76745e JM |
5768 | static unsigned long |
5769 | size_of_pubnames () | |
a94dbf2c | 5770 | { |
3f76745e JM |
5771 | register unsigned long size; |
5772 | register unsigned i; | |
469ac993 | 5773 | |
3f76745e JM |
5774 | size = DWARF_PUBNAMES_HEADER_SIZE; |
5775 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 5776 | { |
3f76745e JM |
5777 | register pubname_ref p = &pubname_table[i]; |
5778 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
5779 | } |
5780 | ||
3f76745e JM |
5781 | size += DWARF_OFFSET_SIZE; |
5782 | return size; | |
a94dbf2c JM |
5783 | } |
5784 | ||
956d6950 | 5785 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5786 | |
3f76745e JM |
5787 | static unsigned long |
5788 | size_of_aranges () | |
469ac993 | 5789 | { |
3f76745e | 5790 | register unsigned long size; |
469ac993 | 5791 | |
3f76745e | 5792 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5793 | |
3f76745e | 5794 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5795 | size += 2 * DWARF2_ADDR_SIZE; |
5796 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5797 | |
3f76745e | 5798 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5799 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5800 | return size; |
5801 | } | |
5802 | \f | |
5803 | /* Select the encoding of an attribute value. */ | |
5804 | ||
5805 | static enum dwarf_form | |
a96c67ec JM |
5806 | value_format (a) |
5807 | dw_attr_ref a; | |
3f76745e | 5808 | { |
a96c67ec | 5809 | switch (a->dw_attr_val.val_class) |
469ac993 | 5810 | { |
3f76745e JM |
5811 | case dw_val_class_addr: |
5812 | return DW_FORM_addr; | |
63e46568 | 5813 | case dw_val_class_loc_list: |
9d2f2c45 RH |
5814 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
5815 | .debug_loc section */ | |
5816 | return DW_FORM_data4; | |
3f76745e | 5817 | case dw_val_class_loc: |
a96c67ec | 5818 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 5819 | { |
3f76745e JM |
5820 | case 1: |
5821 | return DW_FORM_block1; | |
5822 | case 2: | |
5823 | return DW_FORM_block2; | |
469ac993 JM |
5824 | default: |
5825 | abort (); | |
5826 | } | |
3f76745e | 5827 | case dw_val_class_const: |
25dd13ec | 5828 | return DW_FORM_sdata; |
3f76745e | 5829 | case dw_val_class_unsigned_const: |
a96c67ec | 5830 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5831 | { |
5832 | case 1: | |
5833 | return DW_FORM_data1; | |
5834 | case 2: | |
5835 | return DW_FORM_data2; | |
5836 | case 4: | |
5837 | return DW_FORM_data4; | |
5838 | case 8: | |
5839 | return DW_FORM_data8; | |
5840 | default: | |
5841 | abort (); | |
5842 | } | |
5843 | case dw_val_class_long_long: | |
5844 | return DW_FORM_block1; | |
5845 | case dw_val_class_float: | |
5846 | return DW_FORM_block1; | |
5847 | case dw_val_class_flag: | |
5848 | return DW_FORM_flag; | |
5849 | case dw_val_class_die_ref: | |
881c6935 JM |
5850 | if (AT_ref_external (a)) |
5851 | return DW_FORM_ref_addr; | |
5852 | else | |
5853 | return DW_FORM_ref; | |
3f76745e JM |
5854 | case dw_val_class_fde_ref: |
5855 | return DW_FORM_data; | |
5856 | case dw_val_class_lbl_id: | |
5857 | return DW_FORM_addr; | |
8b790721 | 5858 | case dw_val_class_lbl_offset: |
3f76745e JM |
5859 | return DW_FORM_data; |
5860 | case dw_val_class_str: | |
5861 | return DW_FORM_string; | |
469ac993 JM |
5862 | default: |
5863 | abort (); | |
5864 | } | |
a94dbf2c JM |
5865 | } |
5866 | ||
3f76745e | 5867 | /* Output the encoding of an attribute value. */ |
469ac993 | 5868 | |
3f76745e | 5869 | static void |
a96c67ec JM |
5870 | output_value_format (a) |
5871 | dw_attr_ref a; | |
a94dbf2c | 5872 | { |
a96c67ec | 5873 | enum dwarf_form form = value_format (a); |
2e4b9b8c | 5874 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 5875 | } |
469ac993 | 5876 | |
3f76745e JM |
5877 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5878 | table. */ | |
469ac993 | 5879 | |
3f76745e JM |
5880 | static void |
5881 | output_abbrev_section () | |
5882 | { | |
5883 | unsigned long abbrev_id; | |
71dfc51f | 5884 | |
3f76745e JM |
5885 | dw_attr_ref a_attr; |
5886 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5887 | { | |
5888 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 5889 | |
2e4b9b8c | 5890 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
469ac993 | 5891 | |
2e4b9b8c RH |
5892 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
5893 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 5894 | |
2e4b9b8c RH |
5895 | if (abbrev->die_child != NULL) |
5896 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
5897 | else | |
5898 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
5899 | |
5900 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
5901 | a_attr = a_attr->dw_attr_next) | |
5902 | { | |
2e4b9b8c RH |
5903 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
5904 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 5905 | output_value_format (a_attr); |
469ac993 | 5906 | } |
469ac993 | 5907 | |
2e4b9b8c RH |
5908 | dw2_asm_output_data (1, 0, NULL); |
5909 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 5910 | } |
81f374eb HPN |
5911 | |
5912 | /* Terminate the table. */ | |
2e4b9b8c | 5913 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
5914 | } |
5915 | ||
881c6935 JM |
5916 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
5917 | ||
5918 | static inline void | |
5919 | output_die_symbol (die) | |
5920 | register dw_die_ref die; | |
5921 | { | |
5922 | char *sym = die->die_symbol; | |
5923 | ||
5924 | if (sym == 0) | |
5925 | return; | |
5926 | ||
5927 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
5928 | /* We make these global, not weak; if the target doesn't support | |
5929 | .linkonce, it doesn't support combining the sections, so debugging | |
5930 | will break. */ | |
5931 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
5932 | ASM_OUTPUT_LABEL (asm_out_file, sym); | |
5933 | } | |
5934 | ||
63e46568 DB |
5935 | /* Output the location list given to us */ |
5936 | static void | |
5937 | output_loc_list (list_head) | |
5938 | register dw_loc_list_ref list_head; | |
5939 | { | |
5940 | register dw_loc_list_ref curr; | |
5941 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); | |
5942 | if (strcmp (curr->section, ".text") == 0) | |
5943 | { | |
5944 | if (DWARF2_ADDR_SIZE == 4) | |
5945 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0xffffffff, "Location list base address specifier fake entry"); | |
5946 | else if (DWARF2_ADDR_SIZE == 8) | |
5947 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0xffffffffffffffffLL, "Location list base address specifier fake entry"); | |
5948 | else | |
5949 | abort(); | |
5950 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, "Location list base address specifier base"); | |
5951 | } | |
5952 | for (curr = list_head; curr != NULL; curr=curr->dw_loc_next) | |
5953 | { | |
5954 | int size; | |
5955 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, "Location list begin address (%s)", list_head->ll_symbol); | |
5956 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, "Location list end address (%s)", list_head->ll_symbol); | |
5957 | size = size_of_locs (curr->expr); | |
5958 | ||
5959 | /* Output the block length for this list of location operations. */ | |
5960 | dw2_asm_output_data (constant_size (size), size, "%s", "Location expression size"); | |
5961 | ||
5962 | output_loc_sequence (curr->expr); | |
5963 | } | |
5964 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "Location list terminator begin (%s)", list_head->ll_symbol); | |
5965 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "Location list terminator end (%s)", list_head->ll_symbol); | |
5966 | } | |
3f76745e JM |
5967 | /* Output the DIE and its attributes. Called recursively to generate |
5968 | the definitions of each child DIE. */ | |
71dfc51f | 5969 | |
a3f97cbb | 5970 | static void |
3f76745e JM |
5971 | output_die (die) |
5972 | register dw_die_ref die; | |
a3f97cbb | 5973 | { |
3f76745e JM |
5974 | register dw_attr_ref a; |
5975 | register dw_die_ref c; | |
3f76745e | 5976 | register unsigned long size; |
a94dbf2c | 5977 | |
881c6935 JM |
5978 | /* If someone in another CU might refer to us, set up a symbol for |
5979 | them to point to. */ | |
5980 | if (die->die_symbol) | |
5981 | output_die_symbol (die); | |
5982 | ||
2e4b9b8c RH |
5983 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
5984 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 5985 | |
3f76745e | 5986 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 5987 | { |
2e4b9b8c RH |
5988 | const char *name = dwarf_attr_name (a->dw_attr); |
5989 | ||
a96c67ec | 5990 | switch (AT_class (a)) |
3f76745e JM |
5991 | { |
5992 | case dw_val_class_addr: | |
2e4b9b8c | 5993 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 5994 | break; |
a3f97cbb | 5995 | |
3f76745e | 5996 | case dw_val_class_loc: |
a96c67ec | 5997 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 5998 | |
3f76745e | 5999 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6000 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6001 | |
7d9d8943 | 6002 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6003 | break; |
3f76745e JM |
6004 | |
6005 | case dw_val_class_const: | |
25dd13ec JW |
6006 | /* ??? It would be slightly more efficient to use a scheme like is |
6007 | used for unsigned constants below, but gdb 4.x does not sign | |
6008 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6009 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6010 | break; |
3f76745e JM |
6011 | |
6012 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6013 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6014 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6015 | break; |
3f76745e JM |
6016 | |
6017 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6018 | { |
6019 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6020 | |
2e4b9b8c RH |
6021 | dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, |
6022 | "%s", name); | |
556273e0 | 6023 | |
2e4b9b8c RH |
6024 | if (WORDS_BIG_ENDIAN) |
6025 | { | |
6026 | first = a->dw_attr_val.v.val_long_long.hi; | |
6027 | second = a->dw_attr_val.v.val_long_long.low; | |
6028 | } | |
6029 | else | |
6030 | { | |
6031 | first = a->dw_attr_val.v.val_long_long.low; | |
6032 | second = a->dw_attr_val.v.val_long_long.hi; | |
6033 | } | |
6034 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6035 | first, "long long constant"); | |
6036 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6037 | second, NULL); | |
6038 | } | |
a3f97cbb | 6039 | break; |
3f76745e JM |
6040 | |
6041 | case dw_val_class_float: | |
c84e2712 KG |
6042 | { |
6043 | register unsigned int i; | |
c84e2712 | 6044 | |
2e4b9b8c RH |
6045 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
6046 | "%s", name); | |
c84e2712 | 6047 | |
2e4b9b8c RH |
6048 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) |
6049 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], | |
6050 | "fp constant word %u", i); | |
556273e0 | 6051 | break; |
c84e2712 | 6052 | } |
3f76745e JM |
6053 | |
6054 | case dw_val_class_flag: | |
2e4b9b8c | 6055 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6056 | break; |
63e46568 DB |
6057 | case dw_val_class_loc_list: |
6058 | { | |
6059 | char *sym = AT_loc_list (a)->ll_symbol; | |
6060 | if (sym == 0) | |
6061 | abort(); | |
6062 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name); | |
6063 | } | |
6064 | break; | |
3f76745e | 6065 | case dw_val_class_die_ref: |
881c6935 | 6066 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6067 | { |
6068 | char *sym = AT_ref (a)->die_symbol; | |
6069 | if (sym == 0) | |
6070 | abort (); | |
6071 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6072 | } | |
3f4907a6 JM |
6073 | else if (AT_ref (a)->die_offset == 0) |
6074 | abort (); | |
881c6935 | 6075 | else |
2e4b9b8c RH |
6076 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6077 | "%s", name); | |
a3f97cbb | 6078 | break; |
3f76745e JM |
6079 | |
6080 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6081 | { |
6082 | char l1[20]; | |
2e4b9b8c RH |
6083 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6084 | a->dw_attr_val.v.val_fde_index * 2); | |
6085 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6086 | } |
a3f97cbb | 6087 | break; |
a3f97cbb | 6088 | |
3f76745e | 6089 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6090 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6091 | break; |
71dfc51f | 6092 | |
8b790721 | 6093 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6094 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6095 | break; |
a3f97cbb | 6096 | |
3f76745e | 6097 | case dw_val_class_str: |
2e4b9b8c | 6098 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); |
3f76745e | 6099 | break; |
b2932ae5 | 6100 | |
3f76745e JM |
6101 | default: |
6102 | abort (); | |
6103 | } | |
3f76745e | 6104 | } |
71dfc51f | 6105 | |
3f76745e JM |
6106 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6107 | output_die (c); | |
71dfc51f | 6108 | |
3f76745e | 6109 | if (die->die_child != NULL) |
7e23cb16 | 6110 | { |
556273e0 | 6111 | /* Add null byte to terminate sibling list. */ |
2e4b9b8c RH |
6112 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6113 | die->die_offset); | |
7e23cb16 | 6114 | } |
3f76745e | 6115 | } |
71dfc51f | 6116 | |
3f76745e JM |
6117 | /* Output the compilation unit that appears at the beginning of the |
6118 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6119 | |
3f76745e JM |
6120 | static void |
6121 | output_compilation_unit_header () | |
6122 | { | |
2e4b9b8c RH |
6123 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6124 | "Length of Compilation Unit Info"); | |
71dfc51f | 6125 | |
2e4b9b8c | 6126 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
71dfc51f | 6127 | |
2e4b9b8c RH |
6128 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6129 | "Offset Into Abbrev. Section"); | |
71dfc51f | 6130 | |
2e4b9b8c | 6131 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6132 | } |
6133 | ||
881c6935 JM |
6134 | /* Output the compilation unit DIE and its children. */ |
6135 | ||
6136 | static void | |
6137 | output_comp_unit (die) | |
6138 | dw_die_ref die; | |
6139 | { | |
ce1cc601 | 6140 | const char *secname; |
881c6935 | 6141 | |
db3c0315 MM |
6142 | /* Even if there are no children of this DIE, we must output the |
6143 | information about the compilation unit. Otherwise, on an empty | |
6144 | translation unit, we will generate a present, but empty, | |
6145 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
6146 | examining the file. | |
6147 | ||
6148 | Mark all the DIEs in this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6149 | mark_dies (die); |
6150 | ||
6151 | build_abbrev_table (die); | |
6152 | ||
881c6935 JM |
6153 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
6154 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
6155 | calc_die_sizes (die); | |
6156 | ||
881c6935 JM |
6157 | if (die->die_symbol) |
6158 | { | |
ce1cc601 KG |
6159 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
6160 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); | |
6161 | secname = tmp; | |
881c6935 JM |
6162 | die->die_symbol = NULL; |
6163 | } | |
6164 | else | |
ce1cc601 | 6165 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6166 | |
6167 | /* Output debugging information. */ | |
881c6935 JM |
6168 | ASM_OUTPUT_SECTION (asm_out_file, secname); |
6169 | output_compilation_unit_header (); | |
6170 | output_die (die); | |
6171 | ||
1bfb5f8f JM |
6172 | /* Leave the marks on the main CU, so we can check them in |
6173 | output_pubnames. */ | |
881c6935 | 6174 | if (die->die_symbol) |
1bfb5f8f | 6175 | unmark_dies (die); |
881c6935 JM |
6176 | } |
6177 | ||
a1d7ffe3 JM |
6178 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6179 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6180 | argument list, and maybe the scope. */ | |
6181 | ||
d560ee52 | 6182 | static const char * |
a1d7ffe3 JM |
6183 | dwarf2_name (decl, scope) |
6184 | tree decl; | |
6185 | int scope; | |
6186 | { | |
6187 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6188 | } | |
6189 | ||
d291dd49 | 6190 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6191 | |
d291dd49 JM |
6192 | static void |
6193 | add_pubname (decl, die) | |
6194 | tree decl; | |
6195 | dw_die_ref die; | |
6196 | { | |
6197 | pubname_ref p; | |
6198 | ||
6199 | if (! TREE_PUBLIC (decl)) | |
6200 | return; | |
6201 | ||
6202 | if (pubname_table_in_use == pubname_table_allocated) | |
6203 | { | |
6204 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
6205 | pubname_table = (pubname_ref) xrealloc | |
6206 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
6207 | } | |
71dfc51f | 6208 | |
d291dd49 JM |
6209 | p = &pubname_table[pubname_table_in_use++]; |
6210 | p->die = die; | |
a1d7ffe3 JM |
6211 | |
6212 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
6213 | } |
6214 | ||
a3f97cbb JW |
6215 | /* Output the public names table used to speed up access to externally |
6216 | visible names. For now, only generate entries for externally | |
6217 | visible procedures. */ | |
71dfc51f | 6218 | |
a3f97cbb JW |
6219 | static void |
6220 | output_pubnames () | |
6221 | { | |
d291dd49 | 6222 | register unsigned i; |
71dfc51f RK |
6223 | register unsigned long pubnames_length = size_of_pubnames (); |
6224 | ||
2e4b9b8c RH |
6225 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6226 | "Length of Public Names Info"); | |
71dfc51f | 6227 | |
2e4b9b8c | 6228 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6229 | |
2e4b9b8c RH |
6230 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6231 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6232 | |
2e4b9b8c RH |
6233 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6234 | "Compilation Unit Length"); | |
71dfc51f | 6235 | |
d291dd49 | 6236 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 6237 | { |
d291dd49 | 6238 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6239 | |
881c6935 | 6240 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6241 | if (pub->die->die_mark == 0) |
881c6935 JM |
6242 | abort (); |
6243 | ||
2e4b9b8c RH |
6244 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6245 | "DIE offset"); | |
71dfc51f | 6246 | |
2e4b9b8c | 6247 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6248 | } |
71dfc51f | 6249 | |
2e4b9b8c | 6250 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6251 | } |
6252 | ||
d291dd49 | 6253 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6254 | |
d291dd49 JM |
6255 | static void |
6256 | add_arange (decl, die) | |
6257 | tree decl; | |
6258 | dw_die_ref die; | |
6259 | { | |
6260 | if (! DECL_SECTION_NAME (decl)) | |
6261 | return; | |
6262 | ||
6263 | if (arange_table_in_use == arange_table_allocated) | |
6264 | { | |
6265 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
6266 | arange_table |
6267 | = (arange_ref) xrealloc (arange_table, | |
6268 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6269 | } |
71dfc51f | 6270 | |
d291dd49 JM |
6271 | arange_table[arange_table_in_use++] = die; |
6272 | } | |
6273 | ||
a3f97cbb JW |
6274 | /* Output the information that goes into the .debug_aranges table. |
6275 | Namely, define the beginning and ending address range of the | |
6276 | text section generated for this compilation unit. */ | |
71dfc51f | 6277 | |
a3f97cbb JW |
6278 | static void |
6279 | output_aranges () | |
6280 | { | |
d291dd49 | 6281 | register unsigned i; |
71dfc51f RK |
6282 | register unsigned long aranges_length = size_of_aranges (); |
6283 | ||
2e4b9b8c RH |
6284 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6285 | "Length of Address Ranges Info"); | |
71dfc51f | 6286 | |
2e4b9b8c | 6287 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6288 | |
2e4b9b8c RH |
6289 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6290 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6291 | |
2e4b9b8c | 6292 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
71dfc51f | 6293 | |
2e4b9b8c | 6294 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6295 | |
262b6384 SC |
6296 | /* We need to align to twice the pointer size here. */ |
6297 | if (DWARF_ARANGES_PAD_SIZE) | |
6298 | { | |
2e4b9b8c RH |
6299 | /* Pad using a 2 byte words so that padding is correct for any |
6300 | pointer size. */ | |
6301 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6302 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6303 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6304 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6305 | } |
71dfc51f | 6306 | |
8e7fa2c8 | 6307 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6308 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6309 | text_section_label, "Length"); | |
71dfc51f | 6310 | |
d291dd49 JM |
6311 | for (i = 0; i < arange_table_in_use; ++i) |
6312 | { | |
e689ae67 | 6313 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6314 | |
881c6935 | 6315 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6316 | if (die->die_mark == 0) |
881c6935 JM |
6317 | abort (); |
6318 | ||
e689ae67 | 6319 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6320 | { |
8e7fa2c8 | 6321 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
2e4b9b8c RH |
6322 | "Address"); |
6323 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), | |
6324 | get_AT_low_pc (die), "Length"); | |
6325 | } | |
d291dd49 | 6326 | else |
a1d7ffe3 | 6327 | { |
e689ae67 JM |
6328 | /* A static variable; extract the symbol from DW_AT_location. |
6329 | Note that this code isn't currently hit, as we only emit | |
6330 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 6331 | |
e689ae67 JM |
6332 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6333 | dw_loc_descr_ref loc; | |
a96c67ec | 6334 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6335 | abort (); |
6336 | ||
a96c67ec | 6337 | loc = AT_loc (a); |
e689ae67 JM |
6338 | if (loc->dw_loc_opc != DW_OP_addr) |
6339 | abort (); | |
6340 | ||
2e4b9b8c RH |
6341 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6342 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6343 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6344 | get_AT_unsigned (die, DW_AT_byte_size), | |
6345 | "Length"); | |
a1d7ffe3 | 6346 | } |
d291dd49 | 6347 | } |
71dfc51f | 6348 | |
a3f97cbb | 6349 | /* Output the terminator words. */ |
2e4b9b8c RH |
6350 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6351 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6352 | } |
6353 | ||
0b34cf1e UD |
6354 | |
6355 | /* Data structure containing information about input files. */ | |
6356 | struct file_info | |
6357 | { | |
6358 | char *path; /* Complete file name. */ | |
6359 | char *fname; /* File name part. */ | |
6360 | int length; /* Length of entire string. */ | |
6361 | int file_idx; /* Index in input file table. */ | |
6362 | int dir_idx; /* Index in directory table. */ | |
6363 | }; | |
6364 | ||
6365 | /* Data structure containing information about directories with source | |
6366 | files. */ | |
6367 | struct dir_info | |
6368 | { | |
6369 | char *path; /* Path including directory name. */ | |
6370 | int length; /* Path length. */ | |
6371 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6372 | int count; /* Number of files in this directory. */ |
6373 | int dir_idx; /* Index of directory used as base. */ | |
6374 | int used; /* Used in the end? */ | |
6375 | }; | |
6376 | ||
6377 | /* Callback function for file_info comparison. We sort by looking at | |
6378 | the directories in the path. */ | |
6379 | static int | |
6380 | file_info_cmp (p1, p2) | |
6381 | const void *p1; | |
6382 | const void *p2; | |
6383 | { | |
6384 | const struct file_info *s1 = p1; | |
6385 | const struct file_info *s2 = p2; | |
6386 | unsigned char *cp1; | |
6387 | unsigned char *cp2; | |
6388 | ||
6389 | /* Take care of file names without directories. */ | |
6390 | if (s1->path == s1->fname) | |
6391 | return -1; | |
6392 | else if (s2->path == s2->fname) | |
6393 | return 1; | |
6394 | ||
6395 | cp1 = (unsigned char *) s1->path; | |
6396 | cp2 = (unsigned char *) s2->path; | |
6397 | ||
6398 | while (1) | |
6399 | { | |
6400 | ++cp1; | |
6401 | ++cp2; | |
6402 | /* Reached the end of the first path? */ | |
6403 | if (cp1 == (unsigned char *) s1->fname) | |
6404 | /* It doesn't really matter in which order files from the | |
6405 | same directory are sorted in. Therefore don't test for | |
6406 | the second path reaching the end. */ | |
6407 | return -1; | |
6408 | else if (cp2 == (unsigned char *) s2->fname) | |
6409 | return 1; | |
6410 | ||
6411 | /* Character of current path component the same? */ | |
6412 | if (*cp1 != *cp2) | |
6413 | return *cp1 - *cp2; | |
6414 | } | |
6415 | } | |
6416 | ||
6417 | /* Output the directory table and the file name table. We try to minimize | |
6418 | the total amount of memory needed. A heuristic is used to avoid large | |
6419 | slowdowns with many input files. */ | |
6420 | static void | |
6421 | output_file_names () | |
6422 | { | |
6423 | struct file_info *files; | |
6424 | struct dir_info *dirs; | |
6425 | int *saved; | |
6426 | int *savehere; | |
6427 | int *backmap; | |
6428 | int ndirs; | |
6429 | int idx_offset; | |
6430 | int i; | |
6431 | int idx; | |
6432 | ||
6433 | /* Allocate the various arrays we need. */ | |
981975b6 | 6434 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6435 | * sizeof (struct file_info)); |
981975b6 | 6436 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6437 | * sizeof (struct dir_info)); |
6438 | ||
6439 | /* Sort the file names. */ | |
981975b6 | 6440 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6441 | { |
6442 | char *f; | |
6443 | ||
6444 | /* Skip all leading "./". */ | |
981975b6 | 6445 | f = file_table.table[i]; |
0b34cf1e UD |
6446 | while (f[0] == '.' && f[1] == '/') |
6447 | f += 2; | |
6448 | ||
6449 | /* Create a new array entry. */ | |
6450 | files[i].path = f; | |
6451 | files[i].length = strlen (f); | |
6452 | files[i].file_idx = i; | |
6453 | ||
6454 | /* Search for the file name part. */ | |
6455 | f = strrchr (f, '/'); | |
6456 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6457 | } | |
981975b6 | 6458 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6459 | |
6460 | /* Find all the different directories used. */ | |
6461 | dirs[0].path = files[1].path; | |
6462 | dirs[0].length = files[1].fname - files[1].path; | |
6463 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6464 | dirs[0].count = 1; |
6465 | dirs[0].dir_idx = 0; | |
6466 | dirs[0].used = 0; | |
6467 | files[1].dir_idx = 0; | |
6468 | ndirs = 1; | |
6469 | ||
981975b6 | 6470 | for (i = 2; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6471 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6472 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6473 | dirs[ndirs - 1].length) == 0) | |
6474 | { | |
6475 | /* Same directory as last entry. */ | |
6476 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6477 | ++dirs[ndirs - 1].count; |
6478 | } | |
6479 | else | |
6480 | { | |
6481 | int j; | |
6482 | ||
6483 | /* This is a new directory. */ | |
6484 | dirs[ndirs].path = files[i].path; | |
6485 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6486 | dirs[ndirs].count = 1; |
6487 | dirs[ndirs].dir_idx = ndirs; | |
6488 | dirs[ndirs].used = 0; | |
6489 | files[i].dir_idx = ndirs; | |
6490 | ||
6491 | /* Search for a prefix. */ | |
981975b6 | 6492 | dirs[ndirs].prefix = -1; |
0b34cf1e | 6493 | for (j = 0; j < ndirs; ++j) |
981975b6 RH |
6494 | if (dirs[j].length < dirs[ndirs].length |
6495 | && dirs[j].length > 1 | |
6496 | && (dirs[ndirs].prefix == -1 | |
6497 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6498 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6499 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6500 | |
6501 | ++ndirs; | |
6502 | } | |
6503 | ||
6504 | /* Now to the actual work. We have to find a subset of the | |
6505 | directories which allow expressing the file name using references | |
6506 | to the directory table with the least amount of characters. We | |
6507 | do not do an exhaustive search where we would have to check out | |
6508 | every combination of every single possible prefix. Instead we | |
6509 | use a heuristic which provides nearly optimal results in most | |
6510 | cases and never is much off. */ | |
6511 | saved = (int *) alloca (ndirs * sizeof (int)); | |
6512 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6513 | ||
6514 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
6515 | for (i = 0; i < ndirs; ++i) | |
6516 | { | |
6517 | int j; | |
6518 | int total; | |
6519 | ||
981975b6 | 6520 | /* We can always save some space for the current directory. But |
0b34cf1e UD |
6521 | this does not mean it will be enough to justify adding the |
6522 | directory. */ | |
6523 | savehere[i] = dirs[i].length; | |
6524 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6525 | ||
6526 | for (j = i + 1; j < ndirs; ++j) | |
6527 | { | |
6528 | savehere[j] = 0; | |
6529 | ||
6530 | if (saved[j] < dirs[i].length) | |
6531 | { | |
6532 | /* Determine whether the dirs[i] path is a prefix of the | |
6533 | dirs[j] path. */ | |
6534 | int k; | |
6535 | ||
981975b6 RH |
6536 | k = dirs[j].prefix; |
6537 | while (k != -1 && k != i) | |
6538 | k = dirs[k].prefix; | |
6539 | ||
6540 | if (k == i) | |
6541 | { | |
6542 | /* Yes it is. We can possibly safe some memory but | |
6543 | writing the filenames in dirs[j] relative to | |
6544 | dirs[i]. */ | |
6545 | savehere[j] = dirs[i].length; | |
6546 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6547 | } | |
0b34cf1e UD |
6548 | } |
6549 | } | |
6550 | ||
6551 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6552 | directory. */ | |
6553 | if (total > dirs[i].length + 1) | |
6554 | { | |
981975b6 | 6555 | /* It's worthwhile adding. */ |
0b34cf1e UD |
6556 | for (j = i; j < ndirs; ++j) |
6557 | if (savehere[j] > 0) | |
6558 | { | |
6559 | /* Remember how much we saved for this directory so far. */ | |
6560 | saved[j] = savehere[j]; | |
6561 | ||
6562 | /* Remember the prefix directory. */ | |
6563 | dirs[j].dir_idx = i; | |
6564 | } | |
6565 | } | |
6566 | } | |
6567 | ||
981975b6 | 6568 | /* We have to emit them in the order they appear in the file_table |
0b34cf1e UD |
6569 | array since the index is used in the debug info generation. To |
6570 | do this efficiently we generate a back-mapping of the indices | |
6571 | first. */ | |
981975b6 RH |
6572 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
6573 | for (i = 1; i < (int) file_table.in_use; ++i) | |
0b34cf1e UD |
6574 | { |
6575 | backmap[files[i].file_idx] = i; | |
6576 | /* Mark this directory as used. */ | |
6577 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6578 | } | |
6579 | ||
6580 | /* That was it. We are ready to emit the information. First the | |
6581 | directory name table. Here we have to make sure that the first | |
6582 | actually emitted directory name has the index one. Zero is | |
6583 | reserved for the current working directory. Make sure we do not | |
6584 | confuse these indices with the one for the constructed table | |
6585 | (even though most of the time they are identical). */ | |
6586 | idx = 1; | |
e57cabac | 6587 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
0b34cf1e UD |
6588 | for (i = 1 - idx_offset; i < ndirs; ++i) |
6589 | if (dirs[i].used != 0) | |
6590 | { | |
6591 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6592 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6593 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6594 | } |
2e4b9b8c RH |
6595 | dw2_asm_output_data (1, 0, "End directory table"); |
6596 | ||
0b34cf1e UD |
6597 | /* Correct the index for the current working directory entry if it |
6598 | exists. */ | |
6599 | if (idx_offset == 0) | |
6600 | dirs[0].used = 0; | |
0b34cf1e UD |
6601 | |
6602 | /* Now write all the file names. */ | |
981975b6 | 6603 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6604 | { |
6605 | int file_idx = backmap[i]; | |
6606 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
6607 | ||
2e4b9b8c RH |
6608 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
6609 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
6610 | |
6611 | /* Include directory index. */ | |
2e4b9b8c | 6612 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
6613 | |
6614 | /* Modification time. */ | |
2e4b9b8c | 6615 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
6616 | |
6617 | /* File length in bytes. */ | |
2e4b9b8c | 6618 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 6619 | } |
2e4b9b8c | 6620 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
6621 | } |
6622 | ||
6623 | ||
a3f97cbb | 6624 | /* Output the source line number correspondence information. This |
14a774a9 | 6625 | information goes into the .debug_line section. */ |
71dfc51f | 6626 | |
a3f97cbb JW |
6627 | static void |
6628 | output_line_info () | |
6629 | { | |
981975b6 | 6630 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
6631 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6632 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6633 | register unsigned opc; | |
6634 | register unsigned n_op_args; | |
a3f97cbb JW |
6635 | register unsigned long lt_index; |
6636 | register unsigned long current_line; | |
6637 | register long line_offset; | |
6638 | register long line_delta; | |
6639 | register unsigned long current_file; | |
e90b62db | 6640 | register unsigned long function; |
71dfc51f | 6641 | |
2e4b9b8c RH |
6642 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
6643 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
6644 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
6645 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 6646 | |
2e4b9b8c RH |
6647 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
6648 | "Length of Source Line Info"); | |
6649 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 6650 | |
2e4b9b8c | 6651 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6652 | |
981975b6 RH |
6653 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
6654 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 6655 | |
2e4b9b8c RH |
6656 | dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH, |
6657 | "Minimum Instruction Length"); | |
71dfc51f | 6658 | |
2e4b9b8c RH |
6659 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
6660 | "Default is_stmt_start flag"); | |
71dfc51f | 6661 | |
2e4b9b8c RH |
6662 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
6663 | "Line Base Value (Special Opcodes)"); | |
71dfc51f | 6664 | |
2e4b9b8c RH |
6665 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
6666 | "Line Range Value (Special Opcodes)"); | |
6667 | ||
6668 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, | |
6669 | "Special Opcode Base"); | |
71dfc51f | 6670 | |
a3f97cbb JW |
6671 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) |
6672 | { | |
6673 | switch (opc) | |
6674 | { | |
6675 | case DW_LNS_advance_pc: | |
6676 | case DW_LNS_advance_line: | |
6677 | case DW_LNS_set_file: | |
6678 | case DW_LNS_set_column: | |
6679 | case DW_LNS_fixed_advance_pc: | |
6680 | n_op_args = 1; | |
6681 | break; | |
6682 | default: | |
6683 | n_op_args = 0; | |
6684 | break; | |
6685 | } | |
2e4b9b8c RH |
6686 | |
6687 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
6688 | opc, n_op_args); | |
a3f97cbb | 6689 | } |
71dfc51f | 6690 | |
0b34cf1e UD |
6691 | /* Write out the information about the files we use. */ |
6692 | output_file_names (); | |
981975b6 | 6693 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 6694 | |
2f22d404 JM |
6695 | /* We used to set the address register to the first location in the text |
6696 | section here, but that didn't accomplish anything since we already | |
6697 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
6698 | |
6699 | /* Generate the line number to PC correspondence table, encoded as | |
6700 | a series of state machine operations. */ | |
6701 | current_file = 1; | |
6702 | current_line = 1; | |
8b790721 | 6703 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
6704 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
6705 | { | |
2f22d404 JM |
6706 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
6707 | ||
10a11b75 JM |
6708 | #if 0 |
6709 | /* Disable this optimization for now; GDB wants to see two line notes | |
6710 | at the beginning of a function so it can find the end of the | |
6711 | prologue. */ | |
6712 | ||
2f22d404 JM |
6713 | /* Don't emit anything for redundant notes. Just updating the |
6714 | address doesn't accomplish anything, because we already assume | |
6715 | that anything after the last address is this line. */ | |
6716 | if (line_info->dw_line_num == current_line | |
6717 | && line_info->dw_file_num == current_file) | |
6718 | continue; | |
10a11b75 | 6719 | #endif |
71dfc51f | 6720 | |
2e4b9b8c RH |
6721 | /* Emit debug info for the address of the current line. |
6722 | ||
6723 | Unfortunately, we have little choice here currently, and must always | |
6724 | use the most general form. Gcc does not know the address delta | |
6725 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length | |
6726 | attributes which will give an upper bound on the address range. We | |
6727 | could perhaps use length attributes to determine when it is safe to | |
6728 | use DW_LNS_fixed_advance_pc. */ | |
6729 | ||
5c90448c | 6730 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
6731 | if (0) |
6732 | { | |
6733 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
6734 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6735 | "DW_LNS_fixed_advance_pc"); | |
6736 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6737 | } |
6738 | else | |
6739 | { | |
a1a4189d JB |
6740 | /* This can handle any delta. This takes |
6741 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
6742 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6743 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6744 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6745 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 JW |
6746 | } |
6747 | strcpy (prev_line_label, line_label); | |
6748 | ||
6749 | /* Emit debug info for the source file of the current line, if | |
6750 | different from the previous line. */ | |
a3f97cbb JW |
6751 | if (line_info->dw_file_num != current_file) |
6752 | { | |
6753 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6754 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6755 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 6756 | file_table.table[current_file]); |
a3f97cbb | 6757 | } |
71dfc51f | 6758 | |
f19a6894 JW |
6759 | /* Emit debug info for the current line number, choosing the encoding |
6760 | that uses the least amount of space. */ | |
2f22d404 | 6761 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 6762 | { |
2f22d404 JM |
6763 | line_offset = line_info->dw_line_num - current_line; |
6764 | line_delta = line_offset - DWARF_LINE_BASE; | |
6765 | current_line = line_info->dw_line_num; | |
6766 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6767 | { | |
6768 | /* This can handle deltas from -10 to 234, using the current | |
6769 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
6770 | takes 1 byte. */ | |
2e4b9b8c RH |
6771 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
6772 | "line %lu", current_line); | |
2f22d404 JM |
6773 | } |
6774 | else | |
6775 | { | |
6776 | /* This can handle any delta. This takes at least 4 bytes, | |
6777 | depending on the value being encoded. */ | |
2e4b9b8c RH |
6778 | dw2_asm_output_data (1, DW_LNS_advance_line, |
6779 | "advance to line %lu", current_line); | |
6780 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
6781 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 6782 | } |
a94dbf2c JM |
6783 | } |
6784 | else | |
6785 | { | |
2f22d404 | 6786 | /* We still need to start a new row, so output a copy insn. */ |
2e4b9b8c | 6787 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
a3f97cbb | 6788 | } |
a3f97cbb JW |
6789 | } |
6790 | ||
f19a6894 JW |
6791 | /* Emit debug info for the address of the end of the function. */ |
6792 | if (0) | |
6793 | { | |
2e4b9b8c RH |
6794 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6795 | "DW_LNS_fixed_advance_pc"); | |
6796 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
6797 | } |
6798 | else | |
6799 | { | |
2e4b9b8c RH |
6800 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6801 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6802 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6803 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 6804 | } |
bdb669cb | 6805 | |
2e4b9b8c RH |
6806 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
6807 | dw2_asm_output_data_uleb128 (1, NULL); | |
6808 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
6809 | |
6810 | function = 0; | |
6811 | current_file = 1; | |
6812 | current_line = 1; | |
556273e0 | 6813 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db JM |
6814 | { |
6815 | register dw_separate_line_info_ref line_info | |
6816 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 6817 | |
10a11b75 | 6818 | #if 0 |
2f22d404 JM |
6819 | /* Don't emit anything for redundant notes. */ |
6820 | if (line_info->dw_line_num == current_line | |
6821 | && line_info->dw_file_num == current_file | |
6822 | && line_info->function == function) | |
6823 | goto cont; | |
10a11b75 | 6824 | #endif |
2f22d404 | 6825 | |
f19a6894 JW |
6826 | /* Emit debug info for the address of the current line. If this is |
6827 | a new function, or the first line of a function, then we need | |
6828 | to handle it differently. */ | |
5c90448c JM |
6829 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
6830 | lt_index); | |
e90b62db JM |
6831 | if (function != line_info->function) |
6832 | { | |
6833 | function = line_info->function; | |
71dfc51f | 6834 | |
e90b62db | 6835 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
6836 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6837 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6838 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6839 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
6840 | } |
6841 | else | |
6842 | { | |
f19a6894 JW |
6843 | /* ??? See the DW_LNS_advance_pc comment above. */ |
6844 | if (0) | |
6845 | { | |
2e4b9b8c RH |
6846 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6847 | "DW_LNS_fixed_advance_pc"); | |
6848 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6849 | } |
6850 | else | |
6851 | { | |
2e4b9b8c RH |
6852 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6853 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6854 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6855 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 6856 | } |
e90b62db | 6857 | } |
f19a6894 | 6858 | strcpy (prev_line_label, line_label); |
71dfc51f | 6859 | |
f19a6894 JW |
6860 | /* Emit debug info for the source file of the current line, if |
6861 | different from the previous line. */ | |
e90b62db JM |
6862 | if (line_info->dw_file_num != current_file) |
6863 | { | |
6864 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6865 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6866 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 6867 | file_table.table[current_file]); |
e90b62db | 6868 | } |
71dfc51f | 6869 | |
f19a6894 JW |
6870 | /* Emit debug info for the current line number, choosing the encoding |
6871 | that uses the least amount of space. */ | |
e90b62db JM |
6872 | if (line_info->dw_line_num != current_line) |
6873 | { | |
6874 | line_offset = line_info->dw_line_num - current_line; | |
6875 | line_delta = line_offset - DWARF_LINE_BASE; | |
6876 | current_line = line_info->dw_line_num; | |
6877 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
6878 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
6879 | "line %lu", current_line); | |
e90b62db JM |
6880 | else |
6881 | { | |
2e4b9b8c RH |
6882 | dw2_asm_output_data (1, DW_LNS_advance_line, |
6883 | "advance to line %lu", current_line); | |
6884 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
6885 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
6886 | } |
6887 | } | |
2f22d404 | 6888 | else |
2e4b9b8c | 6889 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 6890 | |
10a11b75 | 6891 | #if 0 |
2f22d404 | 6892 | cont: |
10a11b75 | 6893 | #endif |
e90b62db | 6894 | ++lt_index; |
e90b62db JM |
6895 | |
6896 | /* If we're done with a function, end its sequence. */ | |
6897 | if (lt_index == separate_line_info_table_in_use | |
6898 | || separate_line_info_table[lt_index].function != function) | |
6899 | { | |
6900 | current_file = 1; | |
6901 | current_line = 1; | |
71dfc51f | 6902 | |
f19a6894 | 6903 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 6904 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
6905 | if (0) |
6906 | { | |
2e4b9b8c RH |
6907 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6908 | "DW_LNS_fixed_advance_pc"); | |
6909 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6910 | } |
6911 | else | |
6912 | { | |
2e4b9b8c RH |
6913 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6914 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6915 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6916 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 6917 | } |
e90b62db JM |
6918 | |
6919 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
6920 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
6921 | dw2_asm_output_data_uleb128 (1, NULL); | |
6922 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
6923 | } |
6924 | } | |
f19f17e0 JM |
6925 | |
6926 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 6927 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
6928 | } |
6929 | \f | |
a3f97cbb JW |
6930 | /* Given a pointer to a tree node for some base type, return a pointer to |
6931 | a DIE that describes the given type. | |
6932 | ||
6933 | This routine must only be called for GCC type nodes that correspond to | |
6934 | Dwarf base (fundamental) types. */ | |
71dfc51f | 6935 | |
a3f97cbb JW |
6936 | static dw_die_ref |
6937 | base_type_die (type) | |
6938 | register tree type; | |
6939 | { | |
a9d38797 | 6940 | register dw_die_ref base_type_result; |
ec0ce6e2 | 6941 | register const char *type_name; |
a9d38797 | 6942 | register enum dwarf_type encoding; |
71dfc51f | 6943 | register tree name = TYPE_NAME (type); |
a3f97cbb | 6944 | |
a9d38797 JM |
6945 | if (TREE_CODE (type) == ERROR_MARK |
6946 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
6947 | return 0; |
6948 | ||
405f63da MM |
6949 | if (name) |
6950 | { | |
6951 | if (TREE_CODE (name) == TYPE_DECL) | |
6952 | name = DECL_NAME (name); | |
6953 | ||
6954 | type_name = IDENTIFIER_POINTER (name); | |
6955 | } | |
6956 | else | |
6957 | type_name = "__unknown__"; | |
a9d38797 | 6958 | |
a3f97cbb JW |
6959 | switch (TREE_CODE (type)) |
6960 | { | |
a3f97cbb | 6961 | case INTEGER_TYPE: |
a9d38797 | 6962 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 6963 | up if the language is not C. Note that we check only for the names |
556273e0 | 6964 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 6965 | languages. */ |
a9d38797 JM |
6966 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
6967 | && (type == char_type_node | |
6968 | || ! strcmp (type_name, "signed char") | |
6969 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 6970 | { |
a9d38797 JM |
6971 | if (TREE_UNSIGNED (type)) |
6972 | encoding = DW_ATE_unsigned; | |
6973 | else | |
6974 | encoding = DW_ATE_signed; | |
6975 | break; | |
a3f97cbb | 6976 | } |
556273e0 | 6977 | /* else fall through. */ |
a3f97cbb | 6978 | |
a9d38797 JM |
6979 | case CHAR_TYPE: |
6980 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
6981 | if (TREE_UNSIGNED (type)) | |
6982 | encoding = DW_ATE_unsigned_char; | |
6983 | else | |
6984 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
6985 | break; |
6986 | ||
6987 | case REAL_TYPE: | |
a9d38797 | 6988 | encoding = DW_ATE_float; |
a3f97cbb JW |
6989 | break; |
6990 | ||
405f63da MM |
6991 | /* Dwarf2 doesn't know anything about complex ints, so use |
6992 | a user defined type for it. */ | |
a3f97cbb | 6993 | case COMPLEX_TYPE: |
405f63da MM |
6994 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
6995 | encoding = DW_ATE_complex_float; | |
6996 | else | |
6997 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
6998 | break; |
6999 | ||
7000 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7001 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7002 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7003 | break; |
7004 | ||
7005 | default: | |
a9d38797 | 7006 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
7007 | } |
7008 | ||
a9d38797 | 7009 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
7010 | if (demangle_name_func) |
7011 | type_name = (*demangle_name_func) (type_name); | |
7012 | ||
a9d38797 JM |
7013 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7014 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7015 | int_size_in_bytes (type)); |
a9d38797 | 7016 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7017 | |
7018 | return base_type_result; | |
7019 | } | |
7020 | ||
7021 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7022 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7023 | a given type is generally the same as the given type, except that if the | |
7024 | given type is a pointer or reference type, then the root type of the given | |
7025 | type is the root type of the "basis" type for the pointer or reference | |
7026 | type. (This definition of the "root" type is recursive.) Also, the root | |
7027 | type of a `const' qualified type or a `volatile' qualified type is the | |
7028 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7029 | |
a3f97cbb JW |
7030 | static tree |
7031 | root_type (type) | |
7032 | register tree type; | |
7033 | { | |
7034 | if (TREE_CODE (type) == ERROR_MARK) | |
7035 | return error_mark_node; | |
7036 | ||
7037 | switch (TREE_CODE (type)) | |
7038 | { | |
7039 | case ERROR_MARK: | |
7040 | return error_mark_node; | |
7041 | ||
7042 | case POINTER_TYPE: | |
7043 | case REFERENCE_TYPE: | |
7044 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7045 | ||
7046 | default: | |
7047 | return type_main_variant (type); | |
7048 | } | |
7049 | } | |
7050 | ||
7051 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7052 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7053 | |
7054 | static inline int | |
a3f97cbb JW |
7055 | is_base_type (type) |
7056 | register tree type; | |
7057 | { | |
7058 | switch (TREE_CODE (type)) | |
7059 | { | |
7060 | case ERROR_MARK: | |
7061 | case VOID_TYPE: | |
7062 | case INTEGER_TYPE: | |
7063 | case REAL_TYPE: | |
7064 | case COMPLEX_TYPE: | |
7065 | case BOOLEAN_TYPE: | |
7066 | case CHAR_TYPE: | |
7067 | return 1; | |
7068 | ||
7069 | case SET_TYPE: | |
7070 | case ARRAY_TYPE: | |
7071 | case RECORD_TYPE: | |
7072 | case UNION_TYPE: | |
7073 | case QUAL_UNION_TYPE: | |
7074 | case ENUMERAL_TYPE: | |
7075 | case FUNCTION_TYPE: | |
7076 | case METHOD_TYPE: | |
7077 | case POINTER_TYPE: | |
7078 | case REFERENCE_TYPE: | |
7079 | case FILE_TYPE: | |
7080 | case OFFSET_TYPE: | |
7081 | case LANG_TYPE: | |
604bb87d | 7082 | case VECTOR_TYPE: |
a3f97cbb JW |
7083 | return 0; |
7084 | ||
7085 | default: | |
7086 | abort (); | |
7087 | } | |
71dfc51f | 7088 | |
a3f97cbb JW |
7089 | return 0; |
7090 | } | |
7091 | ||
7092 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7093 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7094 | |
a3f97cbb JW |
7095 | static dw_die_ref |
7096 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
7097 | register tree type; | |
7098 | register int is_const_type; | |
7099 | register int is_volatile_type; | |
7100 | register dw_die_ref context_die; | |
7101 | { | |
7102 | register enum tree_code code = TREE_CODE (type); | |
7103 | register dw_die_ref mod_type_die = NULL; | |
7104 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 7105 | register tree item_type = NULL; |
a3f97cbb JW |
7106 | |
7107 | if (code != ERROR_MARK) | |
7108 | { | |
5101b304 MM |
7109 | tree qualified_type; |
7110 | ||
7111 | /* See if we already have the appropriately qualified variant of | |
7112 | this type. */ | |
7113 | qualified_type | |
7114 | = get_qualified_type (type, | |
7115 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
7116 | | (is_volatile_type | |
7117 | ? TYPE_QUAL_VOLATILE : 0))); | |
7118 | /* If we do, then we can just use its DIE, if it exists. */ | |
7119 | if (qualified_type) | |
7120 | { | |
7121 | mod_type_die = lookup_type_die (qualified_type); | |
7122 | if (mod_type_die) | |
7123 | return mod_type_die; | |
7124 | } | |
bdb669cb | 7125 | |
556273e0 | 7126 | /* Handle C typedef types. */ |
5101b304 MM |
7127 | if (qualified_type && TYPE_NAME (qualified_type) |
7128 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL | |
7129 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7130 | { |
5101b304 MM |
7131 | tree type_name = TYPE_NAME (qualified_type); |
7132 | tree dtype = TREE_TYPE (type_name); | |
7133 | if (qualified_type == dtype) | |
a94dbf2c JM |
7134 | { |
7135 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7136 | gen_type_die (qualified_type, context_die); |
7137 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c | 7138 | } |
71dfc51f | 7139 | |
a94dbf2c JM |
7140 | else if (is_const_type < TYPE_READONLY (dtype) |
7141 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7142 | /* cv-unqualified version of named type. Just use the unnamed | |
7143 | type to which it refers. */ | |
71dfc51f | 7144 | mod_type_die |
5101b304 | 7145 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7146 | is_const_type, is_volatile_type, |
7147 | context_die); | |
7148 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
7149 | } |
7150 | ||
7151 | if (mod_type_die) | |
556273e0 KH |
7152 | /* OK. */ |
7153 | ; | |
a94dbf2c | 7154 | else if (is_const_type) |
a3f97cbb | 7155 | { |
ab72d377 | 7156 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 7157 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7158 | } |
7159 | else if (is_volatile_type) | |
7160 | { | |
ab72d377 | 7161 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 7162 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7163 | } |
7164 | else if (code == POINTER_TYPE) | |
7165 | { | |
ab72d377 | 7166 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 7167 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7168 | #if 0 |
a3f97cbb | 7169 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7170 | #endif |
a3f97cbb | 7171 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7172 | } |
7173 | else if (code == REFERENCE_TYPE) | |
7174 | { | |
ab72d377 | 7175 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 7176 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7177 | #if 0 |
a3f97cbb | 7178 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7179 | #endif |
a3f97cbb | 7180 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7181 | } |
7182 | else if (is_base_type (type)) | |
71dfc51f | 7183 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7184 | else |
7185 | { | |
4b674448 JM |
7186 | gen_type_die (type, context_die); |
7187 | ||
a3f97cbb JW |
7188 | /* We have to get the type_main_variant here (and pass that to the |
7189 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7190 | might simply be a *copy* of some original type node (where the | |
7191 | copy was created to help us keep track of typedef names) and | |
7192 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7193 | ..._TYPE node. */ |
a3f97cbb | 7194 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7195 | if (mod_type_die == NULL) |
7196 | abort (); | |
a3f97cbb | 7197 | } |
3d2999ba MK |
7198 | |
7199 | /* We want to equate the qualified type to the die below. */ | |
7200 | if (qualified_type) | |
7201 | type = qualified_type; | |
a3f97cbb | 7202 | } |
71dfc51f | 7203 | |
dfcf9891 JW |
7204 | equate_type_number_to_die (type, mod_type_die); |
7205 | if (item_type) | |
71dfc51f RK |
7206 | /* We must do this after the equate_type_number_to_die call, in case |
7207 | this is a recursive type. This ensures that the modified_type_die | |
7208 | recursion will terminate even if the type is recursive. Recursive | |
7209 | types are possible in Ada. */ | |
7210 | sub_die = modified_type_die (item_type, | |
7211 | TYPE_READONLY (item_type), | |
7212 | TYPE_VOLATILE (item_type), | |
7213 | context_die); | |
7214 | ||
a3f97cbb | 7215 | if (sub_die != NULL) |
71dfc51f RK |
7216 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7217 | ||
a3f97cbb JW |
7218 | return mod_type_die; |
7219 | } | |
7220 | ||
a3f97cbb JW |
7221 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
7222 | an enumerated type. */ | |
71dfc51f RK |
7223 | |
7224 | static inline int | |
a3f97cbb JW |
7225 | type_is_enum (type) |
7226 | register tree type; | |
7227 | { | |
7228 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7229 | } | |
7230 | ||
7d9d8943 AM |
7231 | /* Return the register number described by a given RTL node. */ |
7232 | ||
7233 | static unsigned int | |
7234 | reg_number (rtl) | |
7235 | register rtx rtl; | |
7236 | { | |
7237 | register unsigned regno = REGNO (rtl); | |
7238 | ||
7239 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7240 | { | |
7241 | warning ("internal regno botch: regno = %d\n", regno); | |
7242 | regno = 0; | |
7243 | } | |
7244 | ||
7245 | regno = DBX_REGISTER_NUMBER (regno); | |
7246 | return regno; | |
7247 | } | |
7248 | ||
a3f97cbb | 7249 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 7250 | |
a3f97cbb JW |
7251 | static dw_loc_descr_ref |
7252 | reg_loc_descriptor (rtl) | |
7253 | register rtx rtl; | |
7254 | { | |
7255 | register dw_loc_descr_ref loc_result = NULL; | |
7256 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 7257 | |
85066503 | 7258 | if (reg <= 31) |
71dfc51f | 7259 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7260 | else |
71dfc51f RK |
7261 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7262 | ||
a3f97cbb JW |
7263 | return loc_result; |
7264 | } | |
7265 | ||
d8041cc8 RH |
7266 | /* Return a location descriptor that designates a constant. */ |
7267 | ||
7268 | static dw_loc_descr_ref | |
7269 | int_loc_descriptor (i) | |
7270 | HOST_WIDE_INT i; | |
7271 | { | |
7272 | enum dwarf_location_atom op; | |
7273 | ||
7274 | /* Pick the smallest representation of a constant, rather than just | |
7275 | defaulting to the LEB encoding. */ | |
7276 | if (i >= 0) | |
7277 | { | |
7278 | if (i <= 31) | |
7279 | op = DW_OP_lit0 + i; | |
7280 | else if (i <= 0xff) | |
7281 | op = DW_OP_const1u; | |
7282 | else if (i <= 0xffff) | |
7283 | op = DW_OP_const2u; | |
7284 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7285 | || i <= 0xffffffff) | |
7286 | op = DW_OP_const4u; | |
7287 | else | |
7288 | op = DW_OP_constu; | |
7289 | } | |
7290 | else | |
7291 | { | |
7292 | if (i >= -0x80) | |
7293 | op = DW_OP_const1s; | |
7294 | else if (i >= -0x8000) | |
7295 | op = DW_OP_const2s; | |
7296 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7297 | || i >= -0x80000000) | |
7298 | op = DW_OP_const4s; | |
7299 | else | |
7300 | op = DW_OP_consts; | |
7301 | } | |
7302 | ||
7303 | return new_loc_descr (op, i, 0); | |
7304 | } | |
7305 | ||
a3f97cbb | 7306 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7307 | |
a3f97cbb JW |
7308 | static dw_loc_descr_ref |
7309 | based_loc_descr (reg, offset) | |
7310 | unsigned reg; | |
7311 | long int offset; | |
7312 | { | |
7313 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
7314 | /* For the "frame base", we use the frame pointer or stack pointer |
7315 | registers, since the RTL for local variables is relative to one of | |
7316 | them. */ | |
7317 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 7318 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 7319 | : STACK_POINTER_REGNUM); |
71dfc51f | 7320 | |
a3f97cbb | 7321 | if (reg == fp_reg) |
71dfc51f | 7322 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7323 | else if (reg <= 31) |
71dfc51f | 7324 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7325 | else |
71dfc51f RK |
7326 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7327 | ||
a3f97cbb JW |
7328 | return loc_result; |
7329 | } | |
7330 | ||
7331 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7332 | |
7333 | static inline int | |
a3f97cbb JW |
7334 | is_based_loc (rtl) |
7335 | register rtx rtl; | |
7336 | { | |
71dfc51f RK |
7337 | return (GET_CODE (rtl) == PLUS |
7338 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7339 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7340 | } |
7341 | ||
7342 | /* The following routine converts the RTL for a variable or parameter | |
7343 | (resident in memory) into an equivalent Dwarf representation of a | |
7344 | mechanism for getting the address of that same variable onto the top of a | |
7345 | hypothetical "address evaluation" stack. | |
71dfc51f | 7346 | |
a3f97cbb JW |
7347 | When creating memory location descriptors, we are effectively transforming |
7348 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7349 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7350 | it into Dwarf postfix code as it goes. |
7351 | ||
7352 | MODE is the mode of the memory reference, needed to handle some | |
7353 | autoincrement addressing modes. */ | |
71dfc51f | 7354 | |
a3f97cbb | 7355 | static dw_loc_descr_ref |
e60d4d7b | 7356 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 7357 | register rtx rtl; |
e60d4d7b | 7358 | enum machine_mode mode; |
a3f97cbb JW |
7359 | { |
7360 | dw_loc_descr_ref mem_loc_result = NULL; | |
556273e0 | 7361 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7362 | description of here will be the lowest numbered location which is |
7363 | actually within the array. That's *not* necessarily the same as the | |
7364 | zeroth element of the array. */ | |
71dfc51f | 7365 | |
1865dbb5 JM |
7366 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7367 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7368 | #endif | |
7369 | ||
a3f97cbb JW |
7370 | switch (GET_CODE (rtl)) |
7371 | { | |
e60d4d7b JL |
7372 | case POST_INC: |
7373 | case POST_DEC: | |
e2134eea | 7374 | case POST_MODIFY: |
e60d4d7b JL |
7375 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7376 | just fall into the SUBREG code. */ | |
7377 | ||
556273e0 | 7378 | /* Fall through. */ |
e60d4d7b | 7379 | |
a3f97cbb JW |
7380 | case SUBREG: |
7381 | /* The case of a subreg may arise when we have a local (register) | |
7382 | variable or a formal (register) parameter which doesn't quite fill | |
7383 | up an entire register. For now, just assume that it is | |
7384 | legitimate to make the Dwarf info refer to the whole register which | |
7385 | contains the given subreg. */ | |
ddef6bc7 | 7386 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7387 | |
556273e0 | 7388 | /* Fall through. */ |
a3f97cbb JW |
7389 | |
7390 | case REG: | |
7391 | /* Whenever a register number forms a part of the description of the | |
7392 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7393 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7394 | a "base register". This distinction is not based in any way upon |
7395 | what category of register the hardware believes the given register | |
7396 | belongs to. This is strictly DWARF terminology we're dealing with | |
7397 | here. Note that in cases where the location of a memory-resident | |
7398 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7399 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7400 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7401 | the object in question was allocated to a register (rather than in | |
7402 | memory) so DWARF consumers need to be aware of the subtle | |
7403 | distinction between OP_REG and OP_BASEREG. */ | |
7404 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
7405 | break; | |
7406 | ||
7407 | case MEM: | |
f7d2b0ed RH |
7408 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
7409 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7410 | break; |
7411 | ||
d8041cc8 RH |
7412 | case LABEL_REF: |
7413 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7414 | the symbol ref is too far away and has to be dumped into a constant |
7415 | pool. */ | |
a3f97cbb JW |
7416 | case CONST: |
7417 | case SYMBOL_REF: | |
c6f9b9a1 NC |
7418 | /* Alternatively, the symbol in the constant pool can be referenced |
7419 | by a different symbol. */ | |
7420 | if (GET_CODE (rtl) == SYMBOL_REF | |
79cdfa4b TM |
7421 | && CONSTANT_POOL_ADDRESS_P (rtl)) |
7422 | { | |
7423 | rtx tmp = get_pool_constant (rtl); | |
7424 | /* Doesn't work for floating point constants. */ | |
7425 | if (! (GET_CODE (tmp) == CONST_DOUBLE && GET_MODE (tmp) != VOIDmode)) | |
7426 | rtl = tmp; | |
7427 | } | |
7428 | ||
c6f9b9a1 | 7429 | |
a3f97cbb JW |
7430 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7431 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 7432 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
7433 | break; |
7434 | ||
e2134eea JH |
7435 | case PRE_MODIFY: |
7436 | /* Extract the PLUS expression nested inside and fall into | |
7437 | PLUS code bellow. */ | |
7438 | rtl = XEXP (rtl, 1); | |
7439 | goto plus; | |
7440 | ||
e60d4d7b JL |
7441 | case PRE_INC: |
7442 | case PRE_DEC: | |
7443 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7444 | below. */ | |
7445 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7446 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7447 | ? GET_MODE_UNIT_SIZE (mode) |
7448 | : -GET_MODE_UNIT_SIZE (mode))); | |
7449 | ||
7450 | /* Fall through. */ | |
e60d4d7b | 7451 | |
a3f97cbb | 7452 | case PLUS: |
e2134eea | 7453 | plus: |
a3f97cbb | 7454 | if (is_based_loc (rtl)) |
71dfc51f RK |
7455 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7456 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7457 | else |
7458 | { | |
d8041cc8 RH |
7459 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
7460 | ||
7461 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7462 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
7463 | { | |
7464 | add_loc_descr (&mem_loc_result, | |
7465 | new_loc_descr (DW_OP_plus_uconst, | |
7466 | INTVAL (XEXP (rtl, 1)), 0)); | |
7467 | } | |
7468 | else | |
7469 | { | |
7470 | add_loc_descr (&mem_loc_result, | |
7471 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7472 | add_loc_descr (&mem_loc_result, | |
7473 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7474 | } | |
a3f97cbb JW |
7475 | } |
7476 | break; | |
7477 | ||
dd2478ae JW |
7478 | case MULT: |
7479 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7480 | be replaced with a MEM containing a multiply. */ | |
d8041cc8 RH |
7481 | add_loc_descr (&mem_loc_result, |
7482 | mem_loc_descriptor (XEXP (rtl, 0), mode)); | |
7483 | add_loc_descr (&mem_loc_result, | |
7484 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
7485 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
7486 | break; | |
7487 | ||
a3f97cbb | 7488 | case CONST_INT: |
d8041cc8 | 7489 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7490 | break; |
7491 | ||
7492 | default: | |
7493 | abort (); | |
7494 | } | |
71dfc51f | 7495 | |
a3f97cbb JW |
7496 | return mem_loc_result; |
7497 | } | |
7498 | ||
956d6950 | 7499 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7500 | This is typically a complex variable. */ |
7501 | ||
7502 | static dw_loc_descr_ref | |
7503 | concat_loc_descriptor (x0, x1) | |
7504 | register rtx x0, x1; | |
7505 | { | |
7506 | dw_loc_descr_ref cc_loc_result = NULL; | |
7507 | ||
7508 | if (!is_pseudo_reg (x0) | |
7509 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
7510 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
7511 | add_loc_descr (&cc_loc_result, | |
7512 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
7513 | ||
7514 | if (!is_pseudo_reg (x1) | |
7515 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
7516 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
7517 | add_loc_descr (&cc_loc_result, | |
7518 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
7519 | ||
7520 | return cc_loc_result; | |
7521 | } | |
7522 | ||
a3f97cbb JW |
7523 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7524 | which is either allocated in a register or in a memory location. For a | |
7525 | register, we just generate an OP_REG and the register number. For a | |
7526 | memory location we provide a Dwarf postfix expression describing how to | |
7527 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 7528 | |
a3f97cbb JW |
7529 | static dw_loc_descr_ref |
7530 | loc_descriptor (rtl) | |
7531 | register rtx rtl; | |
7532 | { | |
7533 | dw_loc_descr_ref loc_result = NULL; | |
7534 | switch (GET_CODE (rtl)) | |
7535 | { | |
7536 | case SUBREG: | |
a3f97cbb JW |
7537 | /* The case of a subreg may arise when we have a local (register) |
7538 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7539 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7540 | legitimate to make the Dwarf info refer to the whole register which |
7541 | contains the given subreg. */ | |
ddef6bc7 | 7542 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7543 | |
556273e0 | 7544 | /* Fall through. */ |
a3f97cbb JW |
7545 | |
7546 | case REG: | |
5c90448c | 7547 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7548 | break; |
7549 | ||
7550 | case MEM: | |
e60d4d7b | 7551 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7552 | break; |
7553 | ||
4401bf24 JL |
7554 | case CONCAT: |
7555 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7556 | break; | |
7557 | ||
a3f97cbb | 7558 | default: |
71dfc51f | 7559 | abort (); |
a3f97cbb | 7560 | } |
71dfc51f | 7561 | |
a3f97cbb JW |
7562 | return loc_result; |
7563 | } | |
7564 | ||
d8041cc8 RH |
7565 | /* Similar, but generate the descriptor from trees instead of rtl. |
7566 | This comes up particularly with variable length arrays. */ | |
7567 | ||
7568 | static dw_loc_descr_ref | |
7569 | loc_descriptor_from_tree (loc, addressp) | |
7570 | tree loc; | |
7571 | int addressp; | |
7572 | { | |
7573 | dw_loc_descr_ref ret = NULL; | |
7574 | int indirect_size = 0; | |
7575 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); | |
7576 | enum dwarf_location_atom op; | |
7577 | ||
7578 | /* ??? Most of the time we do not take proper care for sign/zero | |
7579 | extending the values properly. Hopefully this won't be a real | |
7580 | problem... */ | |
7581 | ||
7582 | switch (TREE_CODE (loc)) | |
7583 | { | |
7584 | case ERROR_MARK: | |
7585 | break; | |
7586 | ||
b4ae5201 RK |
7587 | case WITH_RECORD_EXPR: |
7588 | /* This case involves extracting fields from an object to determine the | |
7589 | position of other fields. We don't try to encode this here. The | |
7590 | only user of this is Ada, which encodes the needed information using | |
7591 | the names of types. */ | |
7592 | return ret; | |
7593 | ||
d8041cc8 RH |
7594 | case VAR_DECL: |
7595 | case PARM_DECL: | |
7596 | { | |
7597 | rtx rtl = rtl_for_decl_location (loc); | |
7598 | enum machine_mode mode = DECL_MODE (loc); | |
7599 | ||
a97c9600 RH |
7600 | if (rtl == NULL_RTX) |
7601 | break; | |
7602 | else if (CONSTANT_P (rtl)) | |
d8041cc8 RH |
7603 | { |
7604 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
7605 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
7606 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
7607 | indirect_size = GET_MODE_SIZE (mode); | |
7608 | } | |
7609 | else | |
7610 | { | |
7611 | if (GET_CODE (rtl) == MEM) | |
7612 | { | |
7613 | indirect_size = GET_MODE_SIZE (mode); | |
7614 | rtl = XEXP (rtl, 0); | |
7615 | } | |
7616 | ret = mem_loc_descriptor (rtl, mode); | |
7617 | } | |
7618 | } | |
7619 | break; | |
7620 | ||
7621 | case INDIRECT_REF: | |
7622 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7623 | indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc))); | |
7624 | break; | |
7625 | ||
ed972b14 RK |
7626 | case NOP_EXPR: |
7627 | case CONVERT_EXPR: | |
7628 | case NON_LVALUE_EXPR: | |
b4ae5201 | 7629 | case SAVE_EXPR: |
ed972b14 | 7630 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 7631 | |
d8041cc8 RH |
7632 | case COMPONENT_REF: |
7633 | case BIT_FIELD_REF: | |
7634 | case ARRAY_REF: | |
b4e3fabb | 7635 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
7636 | { |
7637 | tree obj, offset; | |
7638 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
7639 | enum machine_mode mode; | |
7640 | int volatilep; | |
7641 | unsigned int alignment; | |
7642 | ||
7643 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
7644 | &unsignedp, &volatilep, &alignment); | |
7645 | ret = loc_descriptor_from_tree (obj, 1); | |
7646 | ||
7647 | if (offset != NULL_TREE) | |
7648 | { | |
7649 | /* Variable offset. */ | |
7650 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
7651 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7652 | } | |
7653 | ||
7654 | if (addressp) | |
7655 | { | |
7656 | /* We cannot address anything not on a unit boundary. */ | |
7657 | if (bitpos % BITS_PER_UNIT != 0) | |
7658 | abort (); | |
7659 | } | |
7660 | else | |
7661 | { | |
7662 | if (bitpos % BITS_PER_UNIT != 0 | |
7663 | || bitsize % BITS_PER_UNIT != 0) | |
7664 | { | |
7665 | /* ??? We could handle this by loading and shifting etc. | |
7666 | Wait until someone needs it before expending the effort. */ | |
7667 | abort (); | |
7668 | } | |
7669 | ||
7670 | indirect_size = bitsize / BITS_PER_UNIT; | |
7671 | } | |
7672 | ||
7673 | bytepos = bitpos / BITS_PER_UNIT; | |
7674 | if (bytepos > 0) | |
7675 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
7676 | else if (bytepos < 0) | |
7677 | { | |
7678 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
7679 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7680 | } | |
7681 | break; | |
7682 | } | |
7683 | ||
7684 | case INTEGER_CST: | |
7685 | if (host_integerp (loc, 0)) | |
7686 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
7687 | break; | |
d8041cc8 RH |
7688 | |
7689 | case BIT_AND_EXPR: | |
7690 | op = DW_OP_and; | |
7691 | goto do_binop; | |
7692 | case BIT_XOR_EXPR: | |
7693 | op = DW_OP_xor; | |
7694 | goto do_binop; | |
7695 | case BIT_IOR_EXPR: | |
7696 | op = DW_OP_or; | |
7697 | goto do_binop; | |
7698 | case TRUNC_DIV_EXPR: | |
7699 | op = DW_OP_div; | |
7700 | goto do_binop; | |
7701 | case MINUS_EXPR: | |
7702 | op = DW_OP_minus; | |
7703 | goto do_binop; | |
7704 | case TRUNC_MOD_EXPR: | |
7705 | op = DW_OP_mod; | |
7706 | goto do_binop; | |
7707 | case MULT_EXPR: | |
7708 | op = DW_OP_mul; | |
7709 | goto do_binop; | |
7710 | case LSHIFT_EXPR: | |
7711 | op = DW_OP_shl; | |
7712 | goto do_binop; | |
7713 | case RSHIFT_EXPR: | |
7714 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
7715 | goto do_binop; | |
7716 | case PLUS_EXPR: | |
7717 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
7718 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
7719 | { | |
7720 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7721 | add_loc_descr (&ret, | |
7722 | new_loc_descr (DW_OP_plus_uconst, | |
7723 | tree_low_cst (TREE_OPERAND (loc, 1), | |
7724 | 0), | |
7725 | 0)); | |
7726 | break; | |
7727 | } | |
7728 | op = DW_OP_plus; | |
7729 | goto do_binop; | |
7730 | case LE_EXPR: | |
7731 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7732 | break; | |
7733 | op = DW_OP_le; | |
7734 | goto do_binop; | |
7735 | case GE_EXPR: | |
7736 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7737 | break; | |
7738 | op = DW_OP_ge; | |
7739 | goto do_binop; | |
7740 | case LT_EXPR: | |
7741 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7742 | break; | |
7743 | op = DW_OP_lt; | |
7744 | goto do_binop; | |
7745 | case GT_EXPR: | |
7746 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7747 | break; | |
7748 | op = DW_OP_gt; | |
7749 | goto do_binop; | |
7750 | case EQ_EXPR: | |
7751 | op = DW_OP_eq; | |
7752 | goto do_binop; | |
7753 | case NE_EXPR: | |
7754 | op = DW_OP_ne; | |
7755 | goto do_binop; | |
7756 | ||
7757 | do_binop: | |
7758 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7759 | add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0)); | |
7760 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7761 | break; | |
7762 | ||
7763 | case BIT_NOT_EXPR: | |
7764 | op = DW_OP_not; | |
7765 | goto do_unop; | |
7766 | case ABS_EXPR: | |
7767 | op = DW_OP_abs; | |
7768 | goto do_unop; | |
7769 | case NEGATE_EXPR: | |
7770 | op = DW_OP_neg; | |
7771 | goto do_unop; | |
7772 | ||
7773 | do_unop: | |
7774 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7775 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7776 | break; | |
7777 | ||
7778 | case MAX_EXPR: | |
7779 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
7780 | build (LT_EXPR, integer_type_node, | |
7781 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
7782 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
7783 | /* FALLTHRU */ | |
7784 | ||
7785 | case COND_EXPR: | |
7786 | { | |
7787 | dw_loc_descr_ref bra_node, jump_node, tmp; | |
7788 | ||
7789 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7790 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); | |
7791 | add_loc_descr (&ret, bra_node); | |
7792 | ||
7793 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
7794 | add_loc_descr (&ret, tmp); | |
7795 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); | |
7796 | add_loc_descr (&ret, jump_node); | |
7797 | ||
7798 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
7799 | add_loc_descr (&ret, tmp); | |
7800 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7801 | bra_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7802 | ||
7803 | /* ??? Need a node to point the skip at. Use a nop. */ | |
7804 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
7805 | add_loc_descr (&ret, tmp); | |
7806 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7807 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7808 | } | |
7809 | break; | |
7810 | ||
7811 | default: | |
7812 | abort (); | |
7813 | } | |
7814 | ||
7815 | /* If we can't fill the request for an address, die. */ | |
7816 | if (addressp && indirect_size == 0) | |
7817 | abort (); | |
7818 | ||
7819 | /* If we've got an address and don't want one, dereference. */ | |
7820 | if (!addressp && indirect_size > 0) | |
7821 | { | |
7822 | if (indirect_size > DWARF2_ADDR_SIZE) | |
7823 | abort (); | |
7824 | if (indirect_size == DWARF2_ADDR_SIZE) | |
7825 | op = DW_OP_deref; | |
7826 | else | |
7827 | op = DW_OP_deref_size; | |
7828 | add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0)); | |
7829 | } | |
7830 | ||
7831 | return ret; | |
7832 | } | |
7833 | ||
665f2503 | 7834 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 7835 | which is not less than the value itself. */ |
71dfc51f | 7836 | |
665f2503 | 7837 | static inline HOST_WIDE_INT |
a3f97cbb | 7838 | ceiling (value, boundary) |
665f2503 RK |
7839 | HOST_WIDE_INT value; |
7840 | unsigned int boundary; | |
a3f97cbb JW |
7841 | { |
7842 | return (((value + boundary - 1) / boundary) * boundary); | |
7843 | } | |
7844 | ||
7845 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
7846 | pointer to the declared type for the relevant field variable, or return | |
7847 | `integer_type_node' if the given node turns out to be an | |
7848 | ERROR_MARK node. */ | |
71dfc51f RK |
7849 | |
7850 | static inline tree | |
a3f97cbb JW |
7851 | field_type (decl) |
7852 | register tree decl; | |
7853 | { | |
7854 | register tree type; | |
7855 | ||
7856 | if (TREE_CODE (decl) == ERROR_MARK) | |
7857 | return integer_type_node; | |
7858 | ||
7859 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 7860 | if (type == NULL_TREE) |
a3f97cbb JW |
7861 | type = TREE_TYPE (decl); |
7862 | ||
7863 | return type; | |
7864 | } | |
7865 | ||
5f446d21 DD |
7866 | /* Given a pointer to a tree node, return the alignment in bits for |
7867 | it, or else return BITS_PER_WORD if the node actually turns out to | |
7868 | be an ERROR_MARK node. */ | |
71dfc51f RK |
7869 | |
7870 | static inline unsigned | |
a3f97cbb JW |
7871 | simple_type_align_in_bits (type) |
7872 | register tree type; | |
7873 | { | |
7874 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
7875 | } | |
7876 | ||
5f446d21 DD |
7877 | static inline unsigned |
7878 | simple_decl_align_in_bits (decl) | |
7879 | register tree decl; | |
7880 | { | |
7881 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
7882 | } | |
7883 | ||
a3f97cbb JW |
7884 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
7885 | node, return the size in bits for the type if it is a constant, or else | |
7886 | return the alignment for the type if the type's size is not constant, or | |
7887 | else return BITS_PER_WORD if the type actually turns out to be an | |
7888 | ERROR_MARK node. */ | |
71dfc51f | 7889 | |
665f2503 | 7890 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
7891 | simple_type_size_in_bits (type) |
7892 | register tree type; | |
7893 | { | |
3df18884 RH |
7894 | tree type_size_tree; |
7895 | ||
a3f97cbb JW |
7896 | if (TREE_CODE (type) == ERROR_MARK) |
7897 | return BITS_PER_WORD; | |
3df18884 | 7898 | type_size_tree = TYPE_SIZE (type); |
a3f97cbb | 7899 | |
3df18884 RH |
7900 | if (type_size_tree == NULL_TREE) |
7901 | return 0; | |
7902 | if (! host_integerp (type_size_tree, 1)) | |
7903 | return TYPE_ALIGN (type); | |
7904 | return tree_low_cst (type_size_tree, 1); | |
a3f97cbb JW |
7905 | } |
7906 | ||
7907 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
7908 | return the byte offset of the lowest addressed byte of the "containing | |
7909 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
7910 | determine what that offset is, either because the argument turns out to | |
7911 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
7912 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 7913 | |
665f2503 | 7914 | static HOST_WIDE_INT |
a3f97cbb JW |
7915 | field_byte_offset (decl) |
7916 | register tree decl; | |
7917 | { | |
665f2503 | 7918 | unsigned int type_align_in_bits; |
5f446d21 | 7919 | unsigned int decl_align_in_bits; |
665f2503 | 7920 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 RK |
7921 | HOST_WIDE_INT object_offset_in_bits; |
7922 | HOST_WIDE_INT object_offset_in_bytes; | |
7923 | tree type; | |
7924 | tree field_size_tree; | |
7925 | HOST_WIDE_INT bitpos_int; | |
7926 | HOST_WIDE_INT deepest_bitpos; | |
7927 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
7928 | |
7929 | if (TREE_CODE (decl) == ERROR_MARK) | |
7930 | return 0; | |
7931 | ||
7932 | if (TREE_CODE (decl) != FIELD_DECL) | |
7933 | abort (); | |
7934 | ||
7935 | type = field_type (decl); | |
a3f97cbb JW |
7936 | field_size_tree = DECL_SIZE (decl); |
7937 | ||
3df18884 RH |
7938 | /* The size could be unspecified if there was an error, or for |
7939 | a flexible array member. */ | |
50352c9c | 7940 | if (! field_size_tree) |
3df18884 | 7941 | field_size_tree = bitsize_zero_node; |
50352c9c | 7942 | |
556273e0 | 7943 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
7944 | for now, when we see such things, we simply return 0. Someday, we may |
7945 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 7946 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 7947 | return 0; |
14a774a9 | 7948 | |
665f2503 | 7949 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 7950 | |
3df18884 | 7951 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
7952 | if (host_integerp (field_size_tree, 1)) |
7953 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
7954 | else |
7955 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
7956 | |
7957 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 7958 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 7959 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb JW |
7960 | |
7961 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
7962 | the starting bit offset (relative to the start of the containing | |
7963 | structure type) of the hypothetical "containing object" for a bit- | |
7964 | field. Thus, when computing the byte offset value for the start of the | |
556273e0 | 7965 | "containing object" of a bit-field, we must deduce this information on |
a3f97cbb JW |
7966 | our own. This can be rather tricky to do in some cases. For example, |
7967 | handling the following structure type definition when compiling for an | |
7968 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
7969 | can be very tricky: | |
7970 | ||
7971 | struct S { int field1; long long field2:31; }; | |
7972 | ||
7973 | Fortunately, there is a simple rule-of-thumb which can be | |
7974 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
556273e0 | 7975 | 8 bytes for the structure shown above. It decides to do this based upon |
a3f97cbb JW |
7976 | one simple rule for bit-field allocation. Quite simply, GCC allocates |
7977 | each "containing object" for each bit-field at the first (i.e. lowest | |
7978 | addressed) legitimate alignment boundary (based upon the required | |
7979 | minimum alignment for the declared type of the field) which it can | |
7980 | possibly use, subject to the condition that there is still enough | |
7981 | available space remaining in the containing object (when allocated at | |
7982 | the selected point) to fully accommodate all of the bits of the | |
7983 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
7984 | 8 bytes for each object of the structure type shown above. When looking | |
7985 | for a place to allocate the "containing object" for `field2', the | |
7986 | compiler simply tries to allocate a 64-bit "containing object" at each | |
7987 | successive 32-bit boundary (starting at zero) until it finds a place to | |
7988 | allocate that 64- bit field such that at least 31 contiguous (and | |
7989 | previously unallocated) bits remain within that selected 64 bit field. | |
7990 | (As it turns out, for the example above, the compiler finds that it is | |
7991 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
7992 | within the structure type.) Here we attempt to work backwards from the | |
556273e0 | 7993 | limited set of facts we're given, and we try to deduce from those facts, |
a3f97cbb | 7994 | where GCC must have believed that the containing object started (within |
556273e0 KH |
7995 | the structure type). The value we deduce is then used (by the callers of |
7996 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
a3f97cbb JW |
7997 | for fields (both bit-fields and, in the case of DW_AT_location, regular |
7998 | fields as well). */ | |
7999 | ||
8000 | /* Figure out the bit-distance from the start of the structure to the | |
8001 | "deepest" bit of the bit-field. */ | |
8002 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8003 | ||
8004 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8005 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8006 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8007 | ||
8008 | /* Round up to type_align by default. This works best for bitfields. */ | |
8009 | object_offset_in_bits += type_align_in_bits - 1; | |
8010 | object_offset_in_bits /= type_align_in_bits; | |
8011 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8012 | |
5f446d21 DD |
8013 | if (object_offset_in_bits > bitpos_int) |
8014 | { | |
8015 | /* Sigh, the decl must be packed. */ | |
8016 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8017 | ||
8018 | /* Round up to decl_align instead. */ | |
8019 | object_offset_in_bits += decl_align_in_bits - 1; | |
8020 | object_offset_in_bits /= decl_align_in_bits; | |
8021 | object_offset_in_bits *= decl_align_in_bits; | |
8022 | } | |
a3f97cbb | 8023 | |
5f446d21 | 8024 | object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb JW |
8025 | |
8026 | return object_offset_in_bytes; | |
8027 | } | |
a3f97cbb | 8028 | \f |
71dfc51f RK |
8029 | /* The following routines define various Dwarf attributes and any data |
8030 | associated with them. */ | |
a3f97cbb | 8031 | |
ef76d03b | 8032 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8033 | |
ef76d03b | 8034 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8035 | whole parameters. Note that the location attributes for struct fields are |
8036 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8037 | |
a3f97cbb | 8038 | static void |
ef76d03b | 8039 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8040 | dw_die_ref die; |
ef76d03b | 8041 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
8042 | register rtx rtl; |
8043 | { | |
a3f97cbb JW |
8044 | /* Handle a special case. If we are about to output a location descriptor |
8045 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 8046 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
8047 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
8048 | Currently, in some rare cases, variables can have DECL_RTL values which | |
8049 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
556273e0 | 8050 | elsewhere in the compiler. We treat such cases as if the variable(s) in |
6a7a9f01 | 8051 | question had been optimized out of existence. */ |
a3f97cbb | 8052 | |
6a7a9f01 JM |
8053 | if (is_pseudo_reg (rtl) |
8054 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 8055 | && is_pseudo_reg (XEXP (rtl, 0))) |
556273e0 | 8056 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
bce8fed7 JL |
8057 | references the internal argument pointer (a pseudo) in a function |
8058 | where all references to the internal argument pointer were | |
8059 | eliminated via the optimizers. */ | |
8060 | || (GET_CODE (rtl) == MEM | |
8061 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
8062 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
8063 | || (GET_CODE (rtl) == CONCAT |
8064 | && is_pseudo_reg (XEXP (rtl, 0)) | |
8065 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 8066 | return; |
a3f97cbb | 8067 | |
6a7a9f01 | 8068 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
8069 | } |
8070 | ||
8071 | /* Attach the specialized form of location attribute used for data | |
8072 | members of struct and union types. In the special case of a | |
8073 | FIELD_DECL node which represents a bit-field, the "offset" part | |
8074 | of this special location descriptor must indicate the distance | |
8075 | in bytes from the lowest-addressed byte of the containing struct | |
8076 | or union type to the lowest-addressed byte of the "containing | |
8077 | object" for the bit-field. (See the `field_byte_offset' function | |
8078 | above).. For any given bit-field, the "containing object" is a | |
8079 | hypothetical object (of some integral or enum type) within which | |
8080 | the given bit-field lives. The type of this hypothetical | |
8081 | "containing object" is always the same as the declared type of | |
8082 | the individual bit-field itself (for GCC anyway... the DWARF | |
8083 | spec doesn't actually mandate this). Note that it is the size | |
8084 | (in bytes) of the hypothetical "containing object" which will | |
8085 | be given in the DW_AT_byte_size attribute for this bit-field. | |
8086 | (See the `byte_size_attribute' function below.) It is also used | |
8087 | when calculating the value of the DW_AT_bit_offset attribute. | |
8088 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 8089 | |
a3f97cbb JW |
8090 | static void |
8091 | add_data_member_location_attribute (die, decl) | |
8092 | register dw_die_ref die; | |
8093 | register tree decl; | |
8094 | { | |
61b32c02 | 8095 | register unsigned long offset; |
a3f97cbb JW |
8096 | register dw_loc_descr_ref loc_descr; |
8097 | register enum dwarf_location_atom op; | |
8098 | ||
61b32c02 | 8099 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 8100 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
8101 | else |
8102 | offset = field_byte_offset (decl); | |
8103 | ||
a3f97cbb JW |
8104 | /* The DWARF2 standard says that we should assume that the structure address |
8105 | is already on the stack, so we can specify a structure field address | |
8106 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 8107 | |
a3f97cbb JW |
8108 | #ifdef MIPS_DEBUGGING_INFO |
8109 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
8110 | correctly. It works only if we leave the offset on the stack. */ | |
8111 | op = DW_OP_constu; | |
8112 | #else | |
8113 | op = DW_OP_plus_uconst; | |
8114 | #endif | |
71dfc51f | 8115 | |
a3f97cbb JW |
8116 | loc_descr = new_loc_descr (op, offset, 0); |
8117 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
8118 | } | |
8119 | ||
8120 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8121 | does not have a "location" either in memory or in a register. These | |
8122 | things can arise in GNU C when a constant is passed as an actual parameter | |
8123 | to an inlined function. They can also arise in C++ where declared | |
8124 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8125 | |
a3f97cbb JW |
8126 | static void |
8127 | add_const_value_attribute (die, rtl) | |
8128 | register dw_die_ref die; | |
8129 | register rtx rtl; | |
8130 | { | |
8131 | switch (GET_CODE (rtl)) | |
8132 | { | |
8133 | case CONST_INT: | |
2e4b9b8c RH |
8134 | /* Note that a CONST_INT rtx could represent either an integer |
8135 | or a floating-point constant. A CONST_INT is used whenever | |
8136 | the constant will fit into a single word. In all such | |
8137 | cases, the original mode of the constant value is wiped | |
8138 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8139 | { | |
8140 | HOST_WIDE_INT val = INTVAL (rtl); | |
8141 | ||
8142 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8143 | if (val < 0) | |
8144 | { | |
8145 | if ((long) val != val) | |
8146 | abort (); | |
8147 | add_AT_int (die, DW_AT_const_value, (long) val); | |
8148 | } | |
8149 | else | |
8150 | { | |
8151 | if ((unsigned long) val != (unsigned HOST_WIDE_INT) val) | |
8152 | abort (); | |
8153 | add_AT_int (die, DW_AT_const_value, (unsigned long) val); | |
8154 | } | |
8155 | } | |
a3f97cbb JW |
8156 | break; |
8157 | ||
8158 | case CONST_DOUBLE: | |
8159 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8160 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8161 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8162 | represented. We output CONST_DOUBLEs as blocks. */ |
8163 | { | |
8164 | register enum machine_mode mode = GET_MODE (rtl); | |
8165 | ||
8166 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8167 | { | |
e389897b | 8168 | register unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8169 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8170 | REAL_VALUE_TYPE rv; |
469ac993 | 8171 | |
71dfc51f | 8172 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8173 | switch (mode) |
8174 | { | |
8175 | case SFmode: | |
71dfc51f | 8176 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8177 | break; |
8178 | ||
8179 | case DFmode: | |
71dfc51f | 8180 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8181 | break; |
8182 | ||
8183 | case XFmode: | |
8184 | case TFmode: | |
71dfc51f | 8185 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8186 | break; |
8187 | ||
8188 | default: | |
8189 | abort (); | |
8190 | } | |
8191 | ||
469ac993 JM |
8192 | add_AT_float (die, DW_AT_const_value, length, array); |
8193 | } | |
8194 | else | |
2e4b9b8c RH |
8195 | { |
8196 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8197 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8198 | abort (); | |
8199 | add_AT_long_long (die, DW_AT_const_value, | |
8200 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8201 | } | |
469ac993 | 8202 | } |
a3f97cbb JW |
8203 | break; |
8204 | ||
8205 | case CONST_STRING: | |
8206 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8207 | break; | |
8208 | ||
8209 | case SYMBOL_REF: | |
8210 | case LABEL_REF: | |
8211 | case CONST: | |
1865dbb5 | 8212 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
8213 | break; |
8214 | ||
8215 | case PLUS: | |
8216 | /* In cases where an inlined instance of an inline function is passed | |
8217 | the address of an `auto' variable (which is local to the caller) we | |
8218 | can get a situation where the DECL_RTL of the artificial local | |
8219 | variable (for the inlining) which acts as a stand-in for the | |
8220 | corresponding formal parameter (of the inline function) will look | |
8221 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8222 | exactly a compile-time constant expression, but it isn't the address |
8223 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8224 | *value* which the artificial local variable always has during its |
556273e0 | 8225 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8226 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8227 | break; |
8228 | ||
8229 | default: | |
8230 | /* No other kinds of rtx should be possible here. */ | |
8231 | abort (); | |
8232 | } | |
8233 | ||
8234 | } | |
8235 | ||
d8041cc8 RH |
8236 | static rtx |
8237 | rtl_for_decl_location (decl) | |
8238 | tree decl; | |
a3f97cbb JW |
8239 | { |
8240 | register rtx rtl; | |
71dfc51f | 8241 | |
a3f97cbb JW |
8242 | /* Here we have to decide where we are going to say the parameter "lives" |
8243 | (as far as the debugger is concerned). We only have a couple of | |
8244 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8245 | |
556273e0 | 8246 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8247 | activation of the function. If optimization is enabled however, this |
556273e0 | 8248 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8249 | that the parameter doesn't really live anywhere (as far as the code |
8250 | generation parts of GCC are concerned) during most of the function's | |
8251 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8252 | referenced within the function. |
8253 | ||
8254 | We could just generate a location descriptor here for all non-NULL | |
8255 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8256 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8257 | where DECL_RTL is NULL or is a pseudo-reg. | |
8258 | ||
8259 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8260 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8261 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8262 | we can be sure that the parameter was passed using the same type as it is | |
8263 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8264 | points us to a place where a value of that type is passed. | |
8265 | ||
8266 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8267 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8268 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8269 | type which is *different* from the type of the parameter itself. Thus, | |
8270 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8271 | such cases, the debugger would end up (for example) trying to fetch a | |
8272 | `float' from a place which actually contains the first part of a | |
8273 | `double'. That would lead to really incorrect and confusing | |
8274 | output at debug-time. | |
8275 | ||
8276 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8277 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8278 | are a couple of exceptions however. On little-endian machines we can | |
8279 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8280 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8281 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8282 | when (on a little-endian machine) a non-prototyped function has a | |
8283 | parameter declared to be of type `short' or `char'. In such cases, | |
8284 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8285 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8286 | passed `int' value. If the debugger then uses that address to fetch | |
8287 | a `short' or a `char' (on a little-endian machine) the result will be | |
8288 | the correct data, so we allow for such exceptional cases below. | |
8289 | ||
8290 | Note that our goal here is to describe the place where the given formal | |
8291 | parameter lives during most of the function's activation (i.e. between | |
8292 | the end of the prologue and the start of the epilogue). We'll do that | |
8293 | as best as we can. Note however that if the given formal parameter is | |
8294 | modified sometime during the execution of the function, then a stack | |
8295 | backtrace (at debug-time) will show the function as having been | |
8296 | called with the *new* value rather than the value which was | |
8297 | originally passed in. This happens rarely enough that it is not | |
8298 | a major problem, but it *is* a problem, and I'd like to fix it. | |
8299 | ||
8300 | A future version of dwarf2out.c may generate two additional | |
8301 | attributes for any given DW_TAG_formal_parameter DIE which will | |
8302 | describe the "passed type" and the "passed location" for the | |
8303 | given formal parameter in addition to the attributes we now | |
8304 | generate to indicate the "declared type" and the "active | |
8305 | location" for each parameter. This additional set of attributes | |
8306 | could be used by debuggers for stack backtraces. Separately, note | |
8307 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
8308 | NULL also. This happens (for example) for inlined-instances of | |
8309 | inline function formal parameters which are never referenced. | |
8310 | This really shouldn't be happening. All PARM_DECL nodes should | |
8311 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
8312 | doesn't currently generate these values for inlined instances of | |
8313 | inline function parameters, so when we see such cases, we are | |
956d6950 | 8314 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
8315 | gets fixed). */ |
8316 | ||
8317 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8318 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb JW |
8319 | |
8320 | if (TREE_CODE (decl) == PARM_DECL) | |
8321 | { | |
8322 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8323 | { | |
d8041cc8 RH |
8324 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8325 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8326 | |
71dfc51f | 8327 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
8328 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
8329 | all* cases where (rtl == NULL_RTX) just below. */ | |
8330 | if (declared_type == passed_type) | |
71dfc51f RK |
8331 | rtl = DECL_INCOMING_RTL (decl); |
8332 | else if (! BYTES_BIG_ENDIAN | |
8333 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8334 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8335 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8336 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8337 | } |
5a904a61 JW |
8338 | |
8339 | /* If the parm was passed in registers, but lives on the stack, then | |
8340 | make a big endian correction if the mode of the type of the | |
8341 | parameter is not the same as the mode of the rtl. */ | |
8342 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8343 | we reach the big endian correction code there. It isn't clear if all | |
8344 | of these checks are necessary here, but keeping them all is the safe | |
8345 | thing to do. */ | |
8346 | else if (GET_CODE (rtl) == MEM | |
8347 | && XEXP (rtl, 0) != const0_rtx | |
8348 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8349 | /* Not passed in memory. */ | |
8350 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8351 | /* Not passed by invisible reference. */ | |
8352 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8353 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8354 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8355 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8356 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8357 | #endif | |
8358 | ) | |
8359 | /* Big endian correction check. */ | |
8360 | && BYTES_BIG_ENDIAN | |
8361 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8362 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8363 | < UNITS_PER_WORD)) | |
8364 | { | |
8365 | int offset = (UNITS_PER_WORD | |
8366 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
8367 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
8368 | plus_constant (XEXP (rtl, 0), offset)); | |
8369 | } | |
a3f97cbb | 8370 | } |
71dfc51f | 8371 | |
d8041cc8 RH |
8372 | if (rtl != NULL_RTX) |
8373 | { | |
8374 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8375 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8376 | if (current_function_uses_only_leaf_regs) |
8377 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8378 | #endif |
d8041cc8 RH |
8379 | } |
8380 | ||
8381 | return rtl; | |
8382 | } | |
8383 | ||
8384 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8385 | data attribute for a variable or a parameter. We generate the | |
8386 | DW_AT_const_value attribute only in those cases where the given variable | |
8387 | or parameter does not have a true "location" either in memory or in a | |
8388 | register. This can happen (for example) when a constant is passed as an | |
8389 | actual argument in a call to an inline function. (It's possible that | |
8390 | these things can crop up in other ways also.) Note that one type of | |
8391 | constant value which can be passed into an inlined function is a constant | |
8392 | pointer. This can happen for example if an actual argument in an inlined | |
8393 | function call evaluates to a compile-time constant address. */ | |
8394 | ||
8395 | static void | |
8396 | add_location_or_const_value_attribute (die, decl) | |
8397 | register dw_die_ref die; | |
8398 | register tree decl; | |
8399 | { | |
8400 | register rtx rtl; | |
8401 | ||
8402 | if (TREE_CODE (decl) == ERROR_MARK) | |
8403 | return; | |
8404 | ||
8405 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
8406 | abort (); | |
8407 | ||
8408 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8409 | if (rtl == NULL_RTX) |
8410 | return; | |
6a7a9f01 | 8411 | |
a3f97cbb JW |
8412 | switch (GET_CODE (rtl)) |
8413 | { | |
e9a25f70 JL |
8414 | case ADDRESSOF: |
8415 | /* The address of a variable that was optimized away; don't emit | |
8416 | anything. */ | |
8417 | break; | |
8418 | ||
a3f97cbb JW |
8419 | case CONST_INT: |
8420 | case CONST_DOUBLE: | |
8421 | case CONST_STRING: | |
8422 | case SYMBOL_REF: | |
8423 | case LABEL_REF: | |
8424 | case CONST: | |
8425 | case PLUS: | |
8426 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8427 | add_const_value_attribute (die, rtl); | |
8428 | break; | |
8429 | ||
8430 | case MEM: | |
8431 | case REG: | |
8432 | case SUBREG: | |
4401bf24 | 8433 | case CONCAT: |
ef76d03b | 8434 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8435 | break; |
8436 | ||
8437 | default: | |
71dfc51f | 8438 | abort (); |
a3f97cbb JW |
8439 | } |
8440 | } | |
8441 | ||
1bfb5f8f JM |
8442 | /* If we don't have a copy of this variable in memory for some reason (such |
8443 | as a C++ member constant that doesn't have an out-of-line definition), | |
8444 | we should tell the debugger about the constant value. */ | |
8445 | ||
8446 | static void | |
8447 | tree_add_const_value_attribute (var_die, decl) | |
8448 | dw_die_ref var_die; | |
8449 | tree decl; | |
8450 | { | |
8451 | tree init = DECL_INITIAL (decl); | |
8452 | tree type = TREE_TYPE (decl); | |
8453 | ||
8454 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8455 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8456 | /* OK */; | |
8457 | else | |
8458 | return; | |
8459 | ||
8460 | switch (TREE_CODE (type)) | |
8461 | { | |
8462 | case INTEGER_TYPE: | |
8463 | if (host_integerp (init, 0)) | |
8464 | add_AT_unsigned (var_die, DW_AT_const_value, | |
8465 | TREE_INT_CST_LOW (init)); | |
8466 | else | |
8467 | add_AT_long_long (var_die, DW_AT_const_value, | |
8468 | TREE_INT_CST_HIGH (init), | |
8469 | TREE_INT_CST_LOW (init)); | |
8470 | break; | |
8471 | ||
8472 | default:; | |
8473 | } | |
8474 | } | |
0b34cf1e | 8475 | |
a3f97cbb JW |
8476 | /* Generate an DW_AT_name attribute given some string value to be included as |
8477 | the value of the attribute. */ | |
71dfc51f RK |
8478 | |
8479 | static inline void | |
a3f97cbb JW |
8480 | add_name_attribute (die, name_string) |
8481 | register dw_die_ref die; | |
d560ee52 | 8482 | register const char *name_string; |
a3f97cbb | 8483 | { |
71dfc51f | 8484 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8485 | { |
8486 | if (demangle_name_func) | |
8487 | name_string = (*demangle_name_func) (name_string); | |
8488 | ||
8489 | add_AT_string (die, DW_AT_name, name_string); | |
8490 | } | |
a3f97cbb JW |
8491 | } |
8492 | ||
8493 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8494 | a representation for that bound. */ |
71dfc51f | 8495 | |
a3f97cbb JW |
8496 | static void |
8497 | add_bound_info (subrange_die, bound_attr, bound) | |
8498 | register dw_die_ref subrange_die; | |
8499 | register enum dwarf_attribute bound_attr; | |
8500 | register tree bound; | |
8501 | { | |
ef76d03b JW |
8502 | /* If this is an Ada unconstrained array type, then don't emit any debug |
8503 | info because the array bounds are unknown. They are parameterized when | |
8504 | the type is instantiated. */ | |
8505 | if (contains_placeholder_p (bound)) | |
8506 | return; | |
8507 | ||
a3f97cbb JW |
8508 | switch (TREE_CODE (bound)) |
8509 | { | |
8510 | case ERROR_MARK: | |
8511 | return; | |
8512 | ||
8513 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
8514 | case INTEGER_CST: | |
665f2503 RK |
8515 | if (! host_integerp (bound, 0) |
8516 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 8517 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
8518 | || (is_fortran () && integer_onep (bound))))) |
8519 | /* use the default */ | |
8520 | ; | |
141719a8 | 8521 | else |
665f2503 | 8522 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
8523 | break; |
8524 | ||
b1ccbc24 | 8525 | case CONVERT_EXPR: |
a3f97cbb | 8526 | case NOP_EXPR: |
b1ccbc24 RK |
8527 | case NON_LVALUE_EXPR: |
8528 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
8529 | break; | |
556273e0 | 8530 | |
a3f97cbb JW |
8531 | case SAVE_EXPR: |
8532 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
8533 | access the upper bound values may be bogus. If they refer to a |
8534 | register, they may only describe how to get at these values at the | |
8535 | points in the generated code right after they have just been | |
8536 | computed. Worse yet, in the typical case, the upper bound values | |
8537 | will not even *be* computed in the optimized code (though the | |
8538 | number of elements will), so these SAVE_EXPRs are entirely | |
8539 | bogus. In order to compensate for this fact, we check here to see | |
8540 | if optimization is enabled, and if so, we don't add an attribute | |
8541 | for the (unknown and unknowable) upper bound. This should not | |
8542 | cause too much trouble for existing (stupid?) debuggers because | |
8543 | they have to deal with empty upper bounds location descriptions | |
8544 | anyway in order to be able to deal with incomplete array types. | |
8545 | Of course an intelligent debugger (GDB?) should be able to | |
8546 | comprehend that a missing upper bound specification in a array | |
8547 | type used for a storage class `auto' local array variable | |
8548 | indicates that the upper bound is both unknown (at compile- time) | |
8549 | and unknowable (at run-time) due to optimization. | |
8550 | ||
8551 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
8552 | value there unless it was going to be used repeatedly in the | |
8553 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
8554 | if (SAVE_EXPR_RTL (bound) |
8555 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 8556 | { |
466446b0 JM |
8557 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
8558 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
8559 | register rtx loc = SAVE_EXPR_RTL (bound); |
8560 | ||
8561 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
8562 | it references an outer function's frame. */ | |
8563 | ||
8564 | if (GET_CODE (loc) == MEM) | |
8565 | { | |
8566 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
8567 | ||
8568 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 8569 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
8570 | } |
8571 | ||
466446b0 JM |
8572 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
8573 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 8574 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 8575 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 8576 | } |
71dfc51f RK |
8577 | |
8578 | /* Else leave out the attribute. */ | |
a3f97cbb | 8579 | break; |
3f76745e | 8580 | |
ef76d03b | 8581 | case VAR_DECL: |
d8041cc8 RH |
8582 | case PARM_DECL: |
8583 | { | |
8584 | dw_die_ref decl_die = lookup_decl_die (bound); | |
8585 | ||
8586 | /* ??? Can this happen, or should the variable have been bound | |
8587 | first? Probably it can, since I imagine that we try to create | |
8588 | the types of parameters in the order in which they exist in | |
0b34cf1e | 8589 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
8590 | later parameter. */ |
8591 | if (decl_die != NULL) | |
8592 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8593 | break; | |
8594 | } | |
ef76d03b | 8595 | |
3f76745e | 8596 | default: |
d8041cc8 RH |
8597 | { |
8598 | /* Otherwise try to create a stack operation procedure to | |
8599 | evaluate the value of the array bound. */ | |
8600 | ||
8601 | dw_die_ref ctx, decl_die; | |
8602 | dw_loc_descr_ref loc; | |
8603 | ||
8604 | loc = loc_descriptor_from_tree (bound, 0); | |
8605 | if (loc == NULL) | |
8606 | break; | |
8607 | ||
8608 | ctx = lookup_decl_die (current_function_decl); | |
8609 | ||
8610 | decl_die = new_die (DW_TAG_variable, ctx); | |
8611 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
8612 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
8613 | add_AT_loc (decl_die, DW_AT_location, loc); | |
8614 | ||
8615 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8616 | break; | |
8617 | } | |
a3f97cbb JW |
8618 | } |
8619 | } | |
8620 | ||
8621 | /* Note that the block of subscript information for an array type also | |
8622 | includes information about the element type of type given array type. */ | |
71dfc51f | 8623 | |
a3f97cbb JW |
8624 | static void |
8625 | add_subscript_info (type_die, type) | |
8626 | register dw_die_ref type_die; | |
8627 | register tree type; | |
8628 | { | |
081f5e7e | 8629 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 8630 | register unsigned dimension_number; |
081f5e7e | 8631 | #endif |
a3f97cbb JW |
8632 | register tree lower, upper; |
8633 | register dw_die_ref subrange_die; | |
8634 | ||
556273e0 | 8635 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
8636 | one dimensional array types whose element types are themselves array |
8637 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 8638 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
8639 | Dwarf specification say that we are allowed to do this kind of |
8640 | compression in C (because there is no difference between an array or | |
556273e0 | 8641 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 8642 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 8643 | |
a3f97cbb JW |
8644 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
8645 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
8646 | We work around this by disabling this feature. See also | |
8647 | gen_array_type_die. */ | |
8648 | #ifndef MIPS_DEBUGGING_INFO | |
8649 | for (dimension_number = 0; | |
8650 | TREE_CODE (type) == ARRAY_TYPE; | |
8651 | type = TREE_TYPE (type), dimension_number++) | |
8652 | { | |
8653 | #endif | |
8654 | register tree domain = TYPE_DOMAIN (type); | |
8655 | ||
8656 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 8657 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb JW |
8658 | here. */ |
8659 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
8660 | if (domain) | |
8661 | { | |
8662 | /* We have an array type with specified bounds. */ | |
8663 | lower = TYPE_MIN_VALUE (domain); | |
8664 | upper = TYPE_MAX_VALUE (domain); | |
8665 | ||
a9d38797 JM |
8666 | /* define the index type. */ |
8667 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
8668 | { |
8669 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
8670 | TREE_TYPE field. We can't emit debug info for this | |
8671 | because it is an unnamed integral type. */ | |
8672 | if (TREE_CODE (domain) == INTEGER_TYPE | |
8673 | && TYPE_NAME (domain) == NULL_TREE | |
8674 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
8675 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 8676 | ; |
ef76d03b JW |
8677 | else |
8678 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
8679 | type_die); | |
8680 | } | |
a9d38797 | 8681 | |
e1ee5cdc RH |
8682 | /* ??? If upper is NULL, the array has unspecified length, |
8683 | but it does have a lower bound. This happens with Fortran | |
8684 | dimension arr(N:*) | |
8685 | Since the debugger is definitely going to need to know N | |
8686 | to produce useful results, go ahead and output the lower | |
8687 | bound solo, and hope the debugger can cope. */ | |
8688 | ||
141719a8 | 8689 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
8690 | if (upper) |
8691 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
8692 | } |
8693 | else | |
71dfc51f | 8694 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
8695 | spec does not say how to handle this; let's just leave out the |
8696 | bounds. */ | |
e49a1d2e | 8697 | {;} |
71dfc51f | 8698 | |
a3f97cbb JW |
8699 | #ifndef MIPS_DEBUGGING_INFO |
8700 | } | |
8701 | #endif | |
8702 | } | |
8703 | ||
8704 | static void | |
8705 | add_byte_size_attribute (die, tree_node) | |
8706 | dw_die_ref die; | |
8707 | register tree tree_node; | |
8708 | { | |
8709 | register unsigned size; | |
8710 | ||
8711 | switch (TREE_CODE (tree_node)) | |
8712 | { | |
8713 | case ERROR_MARK: | |
8714 | size = 0; | |
8715 | break; | |
8716 | case ENUMERAL_TYPE: | |
8717 | case RECORD_TYPE: | |
8718 | case UNION_TYPE: | |
8719 | case QUAL_UNION_TYPE: | |
8720 | size = int_size_in_bytes (tree_node); | |
8721 | break; | |
8722 | case FIELD_DECL: | |
8723 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
8724 | generally given as the number of bytes normally allocated for an | |
8725 | object of the *declared* type of the member itself. This is true | |
8726 | even for bit-fields. */ | |
8727 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
8728 | break; | |
8729 | default: | |
8730 | abort (); | |
8731 | } | |
8732 | ||
8733 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
8734 | indicates that the byte size of the entity in question is variable. We | |
8735 | have no good way of expressing this fact in Dwarf at the present time, | |
8736 | so just let the -1 pass on through. */ | |
8737 | ||
8738 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
8739 | } | |
8740 | ||
8741 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
8742 | which specifies the distance in bits from the highest order bit of the | |
8743 | "containing object" for the bit-field to the highest order bit of the | |
8744 | bit-field itself. | |
8745 | ||
b2932ae5 JM |
8746 | For any given bit-field, the "containing object" is a hypothetical |
8747 | object (of some integral or enum type) within which the given bit-field | |
8748 | lives. The type of this hypothetical "containing object" is always the | |
8749 | same as the declared type of the individual bit-field itself. The | |
8750 | determination of the exact location of the "containing object" for a | |
8751 | bit-field is rather complicated. It's handled by the | |
8752 | `field_byte_offset' function (above). | |
a3f97cbb JW |
8753 | |
8754 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
8755 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
8756 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
8757 | |
8758 | static inline void | |
a3f97cbb JW |
8759 | add_bit_offset_attribute (die, decl) |
8760 | register dw_die_ref die; | |
8761 | register tree decl; | |
8762 | { | |
665f2503 RK |
8763 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
8764 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
8765 | HOST_WIDE_INT bitpos_int; | |
8766 | HOST_WIDE_INT highest_order_object_bit_offset; | |
8767 | HOST_WIDE_INT highest_order_field_bit_offset; | |
8768 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 8769 | |
3a88cbd1 JL |
8770 | /* Must be a field and a bit field. */ |
8771 | if (!type | |
8772 | || TREE_CODE (decl) != FIELD_DECL) | |
8773 | abort (); | |
a3f97cbb JW |
8774 | |
8775 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
8776 | encounter such things, just return without generating any attribute | |
665f2503 RK |
8777 | whatsoever. Likewise for variable or too large size. */ |
8778 | if (! host_integerp (bit_position (decl), 0) | |
8779 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
8780 | return; |
8781 | ||
665f2503 | 8782 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
8783 | |
8784 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
8785 | highest-order bit of the "containing object" to the highest-order bit of |
8786 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
8787 | is different on big-endian and little-endian machines, the computation |
8788 | below must take account of these differences. */ | |
8789 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
8790 | highest_order_field_bit_offset = bitpos_int; | |
8791 | ||
71dfc51f | 8792 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 8793 | { |
665f2503 | 8794 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
8795 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
8796 | } | |
71dfc51f RK |
8797 | |
8798 | bit_offset | |
8799 | = (! BYTES_BIG_ENDIAN | |
8800 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
8801 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
8802 | |
8803 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
8804 | } | |
8805 | ||
8806 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
8807 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
8808 | |
8809 | static inline void | |
a3f97cbb JW |
8810 | add_bit_size_attribute (die, decl) |
8811 | register dw_die_ref die; | |
8812 | register tree decl; | |
8813 | { | |
3a88cbd1 JL |
8814 | /* Must be a field and a bit field. */ |
8815 | if (TREE_CODE (decl) != FIELD_DECL | |
8816 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
8817 | abort (); | |
665f2503 RK |
8818 | |
8819 | if (host_integerp (DECL_SIZE (decl), 1)) | |
8820 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
8821 | } |
8822 | ||
88dad228 | 8823 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 8824 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
8825 | |
8826 | static inline void | |
a3f97cbb JW |
8827 | add_prototyped_attribute (die, func_type) |
8828 | register dw_die_ref die; | |
8829 | register tree func_type; | |
8830 | { | |
88dad228 JM |
8831 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
8832 | && TYPE_ARG_TYPES (func_type) != NULL) | |
8833 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
8834 | } |
8835 | ||
a3f97cbb JW |
8836 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
8837 | by looking in either the type declaration or object declaration | |
8838 | equate table. */ | |
71dfc51f RK |
8839 | |
8840 | static inline void | |
a3f97cbb JW |
8841 | add_abstract_origin_attribute (die, origin) |
8842 | register dw_die_ref die; | |
8843 | register tree origin; | |
8844 | { | |
8845 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 8846 | |
d10b8e05 | 8847 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
8848 | { |
8849 | /* We may have gotten separated from the block for the inlined | |
8850 | function, if we're in an exception handler or some such; make | |
8851 | sure that the abstract function has been written out. | |
8852 | ||
8853 | Doing this for nested functions is wrong, however; functions are | |
8854 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
8855 | tree fn = origin; |
8856 | if (TYPE_P (fn)) | |
8857 | fn = TYPE_STUB_DECL (fn); | |
8858 | fn = decl_function_context (fn); | |
e40a1c67 | 8859 | if (fn) |
1edf43d6 | 8860 | dwarf2out_abstract_function (fn); |
e40a1c67 | 8861 | } |
44db1d9c | 8862 | |
2f939d94 | 8863 | if (DECL_P (origin)) |
71dfc51f | 8864 | origin_die = lookup_decl_die (origin); |
2f939d94 | 8865 | else if (TYPE_P (origin)) |
71dfc51f RK |
8866 | origin_die = lookup_type_die (origin); |
8867 | ||
bbc6ae08 | 8868 | if (origin_die == NULL) |
1ae8994f | 8869 | abort (); |
556273e0 | 8870 | |
a3f97cbb JW |
8871 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
8872 | } | |
8873 | ||
bdb669cb JM |
8874 | /* We do not currently support the pure_virtual attribute. */ |
8875 | ||
71dfc51f | 8876 | static inline void |
a3f97cbb JW |
8877 | add_pure_or_virtual_attribute (die, func_decl) |
8878 | register dw_die_ref die; | |
8879 | register tree func_decl; | |
8880 | { | |
a94dbf2c | 8881 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 8882 | { |
bdb669cb | 8883 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
8884 | |
8885 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
8886 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
8887 | new_loc_descr (DW_OP_constu, | |
8888 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
8889 | 0)); | |
71dfc51f | 8890 | |
a94dbf2c JM |
8891 | /* GNU extension: Record what type this method came from originally. */ |
8892 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
8893 | add_AT_die_ref (die, DW_AT_containing_type, | |
8894 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
8895 | } |
8896 | } | |
8897 | \f | |
b2932ae5 | 8898 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 8899 | |
b2932ae5 JM |
8900 | static void |
8901 | add_src_coords_attributes (die, decl) | |
8902 | register dw_die_ref die; | |
8903 | register tree decl; | |
8904 | { | |
981975b6 | 8905 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 8906 | |
b2932ae5 JM |
8907 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
8908 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8909 | } | |
8910 | ||
a3f97cbb JW |
8911 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
8912 | given decl, but only if it actually has a name. */ | |
71dfc51f | 8913 | |
a3f97cbb JW |
8914 | static void |
8915 | add_name_and_src_coords_attributes (die, decl) | |
8916 | register dw_die_ref die; | |
8917 | register tree decl; | |
8918 | { | |
61b32c02 | 8919 | register tree decl_name; |
71dfc51f | 8920 | |
556273e0 | 8921 | decl_name = DECL_NAME (decl); |
71dfc51f | 8922 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 8923 | { |
a1d7ffe3 | 8924 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
8925 | if (! DECL_ARTIFICIAL (decl)) |
8926 | add_src_coords_attributes (die, decl); | |
e689ae67 | 8927 | |
a1d7ffe3 | 8928 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 8929 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
8930 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
8931 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
8932 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
8933 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
8934 | } |
8935 | } | |
8936 | ||
556273e0 | 8937 | /* Push a new declaration scope. */ |
71dfc51f | 8938 | |
a3f97cbb JW |
8939 | static void |
8940 | push_decl_scope (scope) | |
8941 | tree scope; | |
8942 | { | |
8943 | /* Make room in the decl_scope_table, if necessary. */ | |
8944 | if (decl_scope_table_allocated == decl_scope_depth) | |
8945 | { | |
8946 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 8947 | decl_scope_table |
777ad4c2 JM |
8948 | = (tree *) xrealloc (decl_scope_table, |
8949 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 8950 | } |
71dfc51f | 8951 | |
777ad4c2 | 8952 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 8953 | decl_scope_depth++; |
a3f97cbb JW |
8954 | } |
8955 | ||
777ad4c2 JM |
8956 | /* Pop a declaration scope. */ |
8957 | static inline void | |
8958 | pop_decl_scope () | |
8959 | { | |
8960 | if (decl_scope_depth <= 0) | |
8961 | abort (); | |
8962 | --decl_scope_depth; | |
8963 | } | |
8964 | ||
8965 | /* Return the DIE for the scope that immediately contains this type. | |
8966 | Non-named types get global scope. Named types nested in other | |
8967 | types get their containing scope if it's open, or global scope | |
8968 | otherwise. All other types (i.e. function-local named types) get | |
8969 | the current active scope. */ | |
71dfc51f | 8970 | |
a3f97cbb | 8971 | static dw_die_ref |
ab72d377 | 8972 | scope_die_for (t, context_die) |
556273e0 KH |
8973 | register tree t; |
8974 | register dw_die_ref context_die; | |
a3f97cbb JW |
8975 | { |
8976 | register dw_die_ref scope_die = NULL; | |
8977 | register tree containing_scope; | |
e3e7774e | 8978 | register int i; |
a3f97cbb | 8979 | |
777ad4c2 JM |
8980 | /* Non-types always go in the current scope. */ |
8981 | if (! TYPE_P (t)) | |
8982 | abort (); | |
8983 | ||
8984 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 8985 | |
2addbe1d JM |
8986 | /* Ignore namespaces for the moment. */ |
8987 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
8988 | containing_scope = NULL_TREE; | |
8989 | ||
5f2f160c JM |
8990 | /* Ignore function type "scopes" from the C frontend. They mean that |
8991 | a tagged type is local to a parmlist of a function declarator, but | |
8992 | that isn't useful to DWARF. */ | |
8993 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
8994 | containing_scope = NULL_TREE; | |
8995 | ||
71dfc51f RK |
8996 | if (containing_scope == NULL_TREE) |
8997 | scope_die = comp_unit_die; | |
777ad4c2 | 8998 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 8999 | { |
777ad4c2 JM |
9000 | /* For types, we can just look up the appropriate DIE. But |
9001 | first we check to see if we're in the middle of emitting it | |
9002 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
9003 | |
9004 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 9005 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
9006 | break; |
9007 | ||
9008 | if (i < 0) | |
9009 | { | |
348bb3c7 JM |
9010 | if (debug_info_level > DINFO_LEVEL_TERSE |
9011 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9012 | abort (); | |
9013 | ||
9014 | /* If none of the current dies are suitable, we get file scope. */ | |
9015 | scope_die = comp_unit_die; | |
9016 | } | |
9017 | else | |
777ad4c2 | 9018 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9019 | } |
a3f97cbb | 9020 | else |
777ad4c2 | 9021 | scope_die = context_die; |
71dfc51f | 9022 | |
a3f97cbb JW |
9023 | return scope_die; |
9024 | } | |
9025 | ||
777ad4c2 JM |
9026 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
9027 | ||
c6991660 | 9028 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
9029 | static inline int |
9030 | local_scope_p (context_die) | |
9031 | dw_die_ref context_die; | |
a3f97cbb | 9032 | { |
777ad4c2 JM |
9033 | for (; context_die; context_die = context_die->die_parent) |
9034 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9035 | || context_die->die_tag == DW_TAG_subprogram) | |
9036 | return 1; | |
9037 | return 0; | |
a3f97cbb JW |
9038 | } |
9039 | ||
9765e357 JM |
9040 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
9041 | ||
c6991660 | 9042 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
9043 | static inline int |
9044 | class_scope_p (context_die) | |
9045 | dw_die_ref context_die; | |
9046 | { | |
9047 | return (context_die | |
9048 | && (context_die->die_tag == DW_TAG_structure_type | |
9049 | || context_die->die_tag == DW_TAG_union_type)); | |
9050 | } | |
9051 | ||
a3f97cbb JW |
9052 | /* Many forms of DIEs require a "type description" attribute. This |
9053 | routine locates the proper "type descriptor" die for the type given | |
9054 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9055 | |
a3f97cbb JW |
9056 | static void |
9057 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
9058 | register dw_die_ref object_die; | |
9059 | register tree type; | |
9060 | register int decl_const; | |
9061 | register int decl_volatile; | |
9062 | register dw_die_ref context_die; | |
9063 | { | |
9064 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
9065 | register dw_die_ref type_die = NULL; |
9066 | ||
ef76d03b JW |
9067 | /* ??? If this type is an unnamed subrange type of an integral or |
9068 | floating-point type, use the inner type. This is because we have no | |
9069 | support for unnamed types in base_type_die. This can happen if this is | |
9070 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9071 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9072 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9073 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9074 | ||
a3f97cbb | 9075 | if (code == ERROR_MARK) |
b1ccbc24 | 9076 | return; |
a3f97cbb JW |
9077 | |
9078 | /* Handle a special case. For functions whose return type is void, we | |
9079 | generate *no* type attribute. (Note that no object may have type | |
9080 | `void', so this only applies to function return types). */ | |
9081 | if (code == VOID_TYPE) | |
b1ccbc24 | 9082 | return; |
a3f97cbb | 9083 | |
a3f97cbb JW |
9084 | type_die = modified_type_die (type, |
9085 | decl_const || TYPE_READONLY (type), | |
9086 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9087 | context_die); |
a3f97cbb | 9088 | if (type_die != NULL) |
71dfc51f | 9089 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9090 | } |
9091 | ||
9092 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9093 | a pointer to the (string) tag name for the given type, or zero if the type | |
9094 | was declared without a tag. */ | |
71dfc51f | 9095 | |
d3e3972c | 9096 | static const char * |
a3f97cbb JW |
9097 | type_tag (type) |
9098 | register tree type; | |
9099 | { | |
d3e3972c | 9100 | register const char *name = 0; |
a3f97cbb JW |
9101 | |
9102 | if (TYPE_NAME (type) != 0) | |
9103 | { | |
9104 | register tree t = 0; | |
9105 | ||
9106 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9107 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9108 | t = TYPE_NAME (type); | |
bdb669cb | 9109 | |
556273e0 | 9110 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9111 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9112 | involved. */ |
a94dbf2c JM |
9113 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9114 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9115 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9116 | |
a3f97cbb JW |
9117 | /* Now get the name as a string, or invent one. */ |
9118 | if (t != 0) | |
a94dbf2c | 9119 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9120 | } |
71dfc51f | 9121 | |
a3f97cbb JW |
9122 | return (name == 0 || *name == '\0') ? 0 : name; |
9123 | } | |
9124 | ||
9125 | /* Return the type associated with a data member, make a special check | |
9126 | for bit field types. */ | |
71dfc51f RK |
9127 | |
9128 | static inline tree | |
a3f97cbb JW |
9129 | member_declared_type (member) |
9130 | register tree member; | |
9131 | { | |
71dfc51f RK |
9132 | return (DECL_BIT_FIELD_TYPE (member) |
9133 | ? DECL_BIT_FIELD_TYPE (member) | |
9134 | : TREE_TYPE (member)); | |
a3f97cbb JW |
9135 | } |
9136 | ||
d291dd49 | 9137 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9138 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9139 | |
487a6e06 | 9140 | #if 0 |
d3e3972c | 9141 | static const char * |
d291dd49 | 9142 | decl_start_label (decl) |
a3f97cbb JW |
9143 | register tree decl; |
9144 | { | |
9145 | rtx x; | |
d3e3972c | 9146 | const char *fnname; |
a3f97cbb JW |
9147 | x = DECL_RTL (decl); |
9148 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9149 | abort (); |
9150 | ||
a3f97cbb JW |
9151 | x = XEXP (x, 0); |
9152 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9153 | abort (); |
9154 | ||
a3f97cbb JW |
9155 | fnname = XSTR (x, 0); |
9156 | return fnname; | |
9157 | } | |
487a6e06 | 9158 | #endif |
a3f97cbb | 9159 | \f |
956d6950 | 9160 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9161 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9162 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9163 | |
9164 | static void | |
9165 | gen_array_type_die (type, context_die) | |
9166 | register tree type; | |
9167 | register dw_die_ref context_die; | |
9168 | { | |
ab72d377 | 9169 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 9170 | register dw_die_ref array_die; |
a3f97cbb | 9171 | register tree element_type; |
bdb669cb | 9172 | |
a9d38797 JM |
9173 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9174 | the inner array type comes before the outer array type. Thus we must | |
9175 | call gen_type_die before we call new_die. See below also. */ | |
9176 | #ifdef MIPS_DEBUGGING_INFO | |
9177 | gen_type_die (TREE_TYPE (type), context_die); | |
9178 | #endif | |
9179 | ||
9180 | array_die = new_die (DW_TAG_array_type, scope_die); | |
9181 | ||
a3f97cbb JW |
9182 | #if 0 |
9183 | /* We default the array ordering. SDB will probably do | |
9184 | the right things even if DW_AT_ordering is not present. It's not even | |
9185 | an issue until we start to get into multidimensional arrays anyway. If | |
9186 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9187 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9188 | and when we find out that we need to put these in, we will only do so | |
9189 | for multidimensional arrays. */ | |
9190 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9191 | #endif | |
9192 | ||
a9d38797 | 9193 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9194 | /* The SGI compilers handle arrays of unknown bound by setting |
9195 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9196 | if (! TYPE_DOMAIN (type)) |
9197 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9198 | else | |
9199 | #endif | |
9200 | add_subscript_info (array_die, type); | |
a3f97cbb | 9201 | |
14a774a9 | 9202 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9203 | equate_type_number_to_die (type, array_die); |
9204 | ||
9205 | /* Add representation of the type of the elements of this array type. */ | |
9206 | element_type = TREE_TYPE (type); | |
71dfc51f | 9207 | |
a3f97cbb JW |
9208 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9209 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9210 | We work around this by disabling this feature. See also | |
9211 | add_subscript_info. */ | |
9212 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9213 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9214 | element_type = TREE_TYPE (element_type); | |
9215 | ||
a3f97cbb | 9216 | gen_type_die (element_type, context_die); |
a9d38797 | 9217 | #endif |
a3f97cbb JW |
9218 | |
9219 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9220 | } | |
9221 | ||
9222 | static void | |
9223 | gen_set_type_die (type, context_die) | |
9224 | register tree type; | |
9225 | register dw_die_ref context_die; | |
9226 | { | |
71dfc51f RK |
9227 | register dw_die_ref type_die |
9228 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
9229 | ||
a3f97cbb | 9230 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9231 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9232 | } | |
9233 | ||
d6f4ec51 | 9234 | #if 0 |
a3f97cbb JW |
9235 | static void |
9236 | gen_entry_point_die (decl, context_die) | |
9237 | register tree decl; | |
9238 | register dw_die_ref context_die; | |
9239 | { | |
9240 | register tree origin = decl_ultimate_origin (decl); | |
9241 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
9242 | if (origin != NULL) | |
71dfc51f | 9243 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9244 | else |
9245 | { | |
9246 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9247 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9248 | 0, 0, context_die); | |
9249 | } | |
71dfc51f | 9250 | |
a3f97cbb | 9251 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9252 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9253 | else |
71dfc51f | 9254 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9255 | } |
d6f4ec51 | 9256 | #endif |
a3f97cbb | 9257 | |
8a8c3656 JM |
9258 | /* Remember a type in the incomplete_types_list. */ |
9259 | ||
9260 | static void | |
9261 | add_incomplete_type (type) | |
9262 | tree type; | |
9263 | { | |
9264 | if (incomplete_types == incomplete_types_allocated) | |
9265 | { | |
9266 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
9267 | incomplete_types_list | |
9268 | = (tree *) xrealloc (incomplete_types_list, | |
9269 | sizeof (tree) * incomplete_types_allocated); | |
9270 | } | |
9271 | ||
9272 | incomplete_types_list[incomplete_types++] = type; | |
9273 | } | |
9274 | ||
9275 | /* Walk through the list of incomplete types again, trying once more to | |
9276 | emit full debugging info for them. */ | |
9277 | ||
9278 | static void | |
9279 | retry_incomplete_types () | |
9280 | { | |
9281 | register tree type; | |
9282 | ||
9283 | while (incomplete_types) | |
9284 | { | |
9285 | --incomplete_types; | |
9286 | type = incomplete_types_list[incomplete_types]; | |
9287 | gen_type_die (type, comp_unit_die); | |
9288 | } | |
9289 | } | |
9290 | ||
a3f97cbb | 9291 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9292 | |
a3f97cbb JW |
9293 | static void |
9294 | gen_inlined_enumeration_type_die (type, context_die) | |
9295 | register tree type; | |
9296 | register dw_die_ref context_die; | |
9297 | { | |
71dfc51f | 9298 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 9299 | context_die); |
bbc6ae08 NC |
9300 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9301 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9302 | add_abstract_origin_attribute (type_die, type); |
9303 | } | |
9304 | ||
9305 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9306 | |
a3f97cbb JW |
9307 | static void |
9308 | gen_inlined_structure_type_die (type, context_die) | |
9309 | register tree type; | |
9310 | register dw_die_ref context_die; | |
9311 | { | |
777ad4c2 JM |
9312 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
9313 | ||
bbc6ae08 NC |
9314 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9315 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9316 | add_abstract_origin_attribute (type_die, type); |
9317 | } | |
9318 | ||
9319 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9320 | |
a3f97cbb JW |
9321 | static void |
9322 | gen_inlined_union_type_die (type, context_die) | |
9323 | register tree type; | |
9324 | register dw_die_ref context_die; | |
9325 | { | |
777ad4c2 JM |
9326 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
9327 | ||
bbc6ae08 NC |
9328 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9329 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9330 | add_abstract_origin_attribute (type_die, type); |
9331 | } | |
9332 | ||
9333 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9334 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9335 | enumerated type name/value is listed as a child of the enumerated type |
9336 | DIE. */ | |
71dfc51f | 9337 | |
a3f97cbb | 9338 | static void |
273dbe67 | 9339 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 9340 | register tree type; |
a3f97cbb JW |
9341 | register dw_die_ref context_die; |
9342 | { | |
273dbe67 JM |
9343 | register dw_die_ref type_die = lookup_type_die (type); |
9344 | ||
a3f97cbb JW |
9345 | if (type_die == NULL) |
9346 | { | |
9347 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 9348 | scope_die_for (type, context_die)); |
a3f97cbb JW |
9349 | equate_type_number_to_die (type, type_die); |
9350 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9351 | } |
273dbe67 JM |
9352 | else if (! TYPE_SIZE (type)) |
9353 | return; | |
9354 | else | |
9355 | remove_AT (type_die, DW_AT_declaration); | |
9356 | ||
9357 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9358 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9359 | attribute or the DW_AT_element_list attribute. */ | |
9360 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9361 | { |
273dbe67 | 9362 | register tree link; |
71dfc51f | 9363 | |
a082c85a | 9364 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9365 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9366 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9367 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9368 | |
ef76d03b JW |
9369 | /* If the first reference to this type was as the return type of an |
9370 | inline function, then it may not have a parent. Fix this now. */ | |
9371 | if (type_die->die_parent == NULL) | |
9372 | add_child_die (scope_die_for (type, context_die), type_die); | |
9373 | ||
273dbe67 JM |
9374 | for (link = TYPE_FIELDS (type); |
9375 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9376 | { |
273dbe67 | 9377 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 9378 | |
273dbe67 JM |
9379 | add_name_attribute (enum_die, |
9380 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9381 | |
9382 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9383 | { |
9384 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9385 | add_AT_int (enum_die, DW_AT_const_value, | |
9386 | tree_low_cst (TREE_VALUE (link), 0)); | |
9387 | else | |
9388 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9389 | tree_low_cst (TREE_VALUE (link), 0)); | |
9390 | } | |
a3f97cbb JW |
9391 | } |
9392 | } | |
273dbe67 JM |
9393 | else |
9394 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9395 | } |
9396 | ||
a3f97cbb JW |
9397 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9398 | represent just the type of some formal parameter position in some function | |
9399 | type. | |
71dfc51f | 9400 | |
a3f97cbb JW |
9401 | Note that this routine is a bit unusual because its argument may be a |
9402 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9403 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9404 | node. If it's the former then this function is being called to output a | |
9405 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9406 | it's the latter, then this function is only being called to output a | |
9407 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9408 | argument type of some subprogram type. */ | |
71dfc51f | 9409 | |
a94dbf2c | 9410 | static dw_die_ref |
a3f97cbb JW |
9411 | gen_formal_parameter_die (node, context_die) |
9412 | register tree node; | |
9413 | register dw_die_ref context_die; | |
9414 | { | |
71dfc51f RK |
9415 | register dw_die_ref parm_die |
9416 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 9417 | register tree origin; |
71dfc51f | 9418 | |
a3f97cbb JW |
9419 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9420 | { | |
a3f97cbb JW |
9421 | case 'd': |
9422 | origin = decl_ultimate_origin (node); | |
9423 | if (origin != NULL) | |
a94dbf2c | 9424 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9425 | else |
9426 | { | |
9427 | add_name_and_src_coords_attributes (parm_die, node); | |
9428 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9429 | TREE_READONLY (node), | |
9430 | TREE_THIS_VOLATILE (node), | |
9431 | context_die); | |
bdb669cb JM |
9432 | if (DECL_ARTIFICIAL (node)) |
9433 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9434 | } |
71dfc51f | 9435 | |
141719a8 JM |
9436 | equate_decl_number_to_die (node, parm_die); |
9437 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9438 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9439 | |
a3f97cbb JW |
9440 | break; |
9441 | ||
a3f97cbb | 9442 | case 't': |
71dfc51f | 9443 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9444 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9445 | break; | |
9446 | ||
a3f97cbb JW |
9447 | default: |
9448 | abort (); | |
9449 | } | |
71dfc51f | 9450 | |
a94dbf2c | 9451 | return parm_die; |
a3f97cbb JW |
9452 | } |
9453 | ||
9454 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9455 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9456 | |
a3f97cbb JW |
9457 | static void |
9458 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 9459 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9460 | register dw_die_ref context_die; |
9461 | { | |
487a6e06 | 9462 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
9463 | } |
9464 | ||
9465 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9466 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9467 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9468 | those which appear as part of a function *definition*). */ |
71dfc51f | 9469 | |
a3f97cbb JW |
9470 | static void |
9471 | gen_formal_types_die (function_or_method_type, context_die) | |
9472 | register tree function_or_method_type; | |
9473 | register dw_die_ref context_die; | |
9474 | { | |
9475 | register tree link; | |
9476 | register tree formal_type = NULL; | |
5daf7c0a JM |
9477 | register tree first_parm_type; |
9478 | tree arg; | |
a3f97cbb | 9479 | |
5daf7c0a JM |
9480 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
9481 | { | |
9482 | arg = DECL_ARGUMENTS (function_or_method_type); | |
9483 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
9484 | } | |
9485 | else | |
9486 | arg = NULL_TREE; | |
9487 | ||
9488 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
a3f97cbb | 9489 | |
556273e0 | 9490 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 9491 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 9492 | for (link = first_parm_type; link; ) |
a3f97cbb | 9493 | { |
a94dbf2c | 9494 | register dw_die_ref parm_die; |
556273e0 | 9495 | |
a3f97cbb JW |
9496 | formal_type = TREE_VALUE (link); |
9497 | if (formal_type == void_type_node) | |
9498 | break; | |
9499 | ||
9500 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 9501 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
9502 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
9503 | && link == first_parm_type) | |
9504 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 9505 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
9506 | |
9507 | link = TREE_CHAIN (link); | |
9508 | if (arg) | |
9509 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
9510 | } |
9511 | ||
9512 | /* If this function type has an ellipsis, add a | |
9513 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9514 | if (formal_type != void_type_node) | |
9515 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9516 | ||
556273e0 | 9517 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9518 | and output DIEs to represent those types (as necessary). */ |
9519 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
9520 | link; | |
9521 | link = TREE_CHAIN (link)) | |
9522 | { | |
9523 | formal_type = TREE_VALUE (link); | |
9524 | if (formal_type == void_type_node) | |
9525 | break; | |
9526 | ||
b50c02f9 | 9527 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
9528 | } |
9529 | } | |
9530 | ||
10a11b75 JM |
9531 | /* We want to generate the DIE for TYPE so that we can generate the |
9532 | die for MEMBER, which has been defined; we will need to refer back | |
9533 | to the member declaration nested within TYPE. If we're trying to | |
9534 | generate minimal debug info for TYPE, processing TYPE won't do the | |
9535 | trick; we need to attach the member declaration by hand. */ | |
9536 | ||
9537 | static void | |
9538 | gen_type_die_for_member (type, member, context_die) | |
9539 | tree type, member; | |
9540 | dw_die_ref context_die; | |
9541 | { | |
9542 | gen_type_die (type, context_die); | |
9543 | ||
9544 | /* If we're trying to avoid duplicate debug info, we may not have | |
9545 | emitted the member decl for this function. Emit it now. */ | |
9546 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
9547 | && ! lookup_decl_die (member)) | |
9548 | { | |
9549 | if (decl_ultimate_origin (member)) | |
9550 | abort (); | |
9551 | ||
9552 | push_decl_scope (type); | |
9553 | if (TREE_CODE (member) == FUNCTION_DECL) | |
9554 | gen_subprogram_die (member, lookup_type_die (type)); | |
9555 | else | |
9556 | gen_variable_die (member, lookup_type_die (type)); | |
9557 | pop_decl_scope (); | |
9558 | } | |
9559 | } | |
9560 | ||
9561 | /* Generate the DWARF2 info for the "abstract" instance | |
9562 | of a function which we may later generate inlined and/or | |
9563 | out-of-line instances of. */ | |
9564 | ||
1edf43d6 JM |
9565 | void |
9566 | dwarf2out_abstract_function (decl) | |
10a11b75 JM |
9567 | tree decl; |
9568 | { | |
5daf7c0a | 9569 | register dw_die_ref old_die; |
777ad4c2 | 9570 | tree save_fn; |
5daf7c0a JM |
9571 | tree context; |
9572 | int was_abstract = DECL_ABSTRACT (decl); | |
9573 | ||
9574 | /* Make sure we have the actual abstract inline, not a clone. */ | |
9575 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 9576 | |
5daf7c0a | 9577 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
9578 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
9579 | /* We've already generated the abstract instance. */ | |
9580 | return; | |
9581 | ||
5daf7c0a JM |
9582 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
9583 | we don't get confused by DECL_ABSTRACT. */ | |
9584 | context = decl_class_context (decl); | |
9585 | if (context) | |
9586 | gen_type_die_for_member | |
9587 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
9588 | ||
9589 | /* Pretend we've just finished compiling this function. */ | |
777ad4c2 JM |
9590 | save_fn = current_function_decl; |
9591 | current_function_decl = decl; | |
9592 | ||
10a11b75 JM |
9593 | set_decl_abstract_flags (decl, 1); |
9594 | dwarf2out_decl (decl); | |
5daf7c0a JM |
9595 | if (! was_abstract) |
9596 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
9597 | |
9598 | current_function_decl = save_fn; | |
10a11b75 JM |
9599 | } |
9600 | ||
a3f97cbb JW |
9601 | /* Generate a DIE to represent a declared function (either file-scope or |
9602 | block-local). */ | |
71dfc51f | 9603 | |
a3f97cbb JW |
9604 | static void |
9605 | gen_subprogram_die (decl, context_die) | |
9606 | register tree decl; | |
9607 | register dw_die_ref context_die; | |
9608 | { | |
9609 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9610 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 9611 | register dw_die_ref subr_die; |
b1ccbc24 | 9612 | register rtx fp_reg; |
a3f97cbb JW |
9613 | register tree fn_arg_types; |
9614 | register tree outer_scope; | |
a94dbf2c | 9615 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9616 | register int declaration = (current_function_decl != decl |
9617 | || class_scope_p (context_die)); | |
a3f97cbb | 9618 | |
10a11b75 JM |
9619 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
9620 | be true, if we started to generate the abstract instance of an inline, | |
9621 | decided to output its containing class, and proceeded to emit the | |
9622 | declaration of the inline from the member list for the class. In that | |
9623 | case, `declaration' takes priority; we'll get back to the abstract | |
9624 | instance when we're done with the class. */ | |
9625 | ||
1cfdcc15 JM |
9626 | /* The class-scope declaration DIE must be the primary DIE. */ |
9627 | if (origin && declaration && class_scope_p (context_die)) | |
9628 | { | |
9629 | origin = NULL; | |
9630 | if (old_die) | |
9631 | abort (); | |
9632 | } | |
9633 | ||
a3f97cbb JW |
9634 | if (origin != NULL) |
9635 | { | |
777ad4c2 | 9636 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
9637 | abort (); |
9638 | ||
8d8238b6 JM |
9639 | /* Fixup die_parent for the abstract instance of a nested |
9640 | inline function. */ | |
9641 | if (old_die && old_die->die_parent == NULL) | |
9642 | add_child_die (context_die, old_die); | |
9643 | ||
4b674448 | 9644 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
9645 | add_abstract_origin_attribute (subr_die, origin); |
9646 | } | |
bdb669cb JM |
9647 | else if (old_die) |
9648 | { | |
981975b6 | 9649 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 9650 | |
1edf43d6 JM |
9651 | if (!get_AT_flag (old_die, DW_AT_declaration) |
9652 | /* We can have a normal definition following an inline one in the | |
9653 | case of redefinition of GNU C extern inlines. | |
9654 | It seems reasonable to use AT_specification in this case. */ | |
9655 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
9656 | { |
9657 | /* ??? This can happen if there is a bug in the program, for | |
9658 | instance, if it has duplicate function definitions. Ideally, | |
9659 | we should detect this case and ignore it. For now, if we have | |
9660 | already reported an error, any error at all, then assume that | |
9661 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
9662 | if (errorcount) |
9663 | return; | |
9664 | abort (); | |
9665 | } | |
4b674448 JM |
9666 | |
9667 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
9668 | maybe use the old DIE. We always want the DIE for this function |
9669 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
9670 | debugger can find it. We also need to do this for abstract |
9671 | instances of inlines, since the spec requires the out-of-line copy | |
9672 | to have the same parent. For local class methods, this doesn't | |
9673 | apply; we just use the old DIE. */ | |
9674 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
9675 | && (DECL_ARTIFICIAL (decl) |
9676 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
9677 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9678 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 9679 | { |
4b674448 JM |
9680 | subr_die = old_die; |
9681 | ||
9682 | /* Clear out the declaration attribute and the parm types. */ | |
9683 | remove_AT (subr_die, DW_AT_declaration); | |
9684 | remove_children (subr_die); | |
9685 | } | |
9686 | else | |
9687 | { | |
9688 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
9689 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
9690 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9691 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
9692 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9693 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
9694 | add_AT_unsigned |
9695 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9696 | } | |
9697 | } | |
a3f97cbb JW |
9698 | else |
9699 | { | |
777ad4c2 | 9700 | subr_die = new_die (DW_TAG_subprogram, context_die); |
556273e0 | 9701 | |
273dbe67 JM |
9702 | if (TREE_PUBLIC (decl)) |
9703 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 9704 | |
a3f97cbb | 9705 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
9706 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9707 | { | |
9708 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 9709 | |
4927276d JM |
9710 | add_prototyped_attribute (subr_die, type); |
9711 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
9712 | } | |
71dfc51f | 9713 | |
a3f97cbb | 9714 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
9715 | if (DECL_ARTIFICIAL (decl)) |
9716 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
9717 | if (TREE_PROTECTED (decl)) |
9718 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
9719 | else if (TREE_PRIVATE (decl)) | |
9720 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9721 | } |
4edb7b60 | 9722 | |
a94dbf2c JM |
9723 | if (declaration) |
9724 | { | |
1edf43d6 JM |
9725 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
9726 | { | |
9727 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
9728 | ||
9729 | /* The first time we see a member function, it is in the context of | |
9730 | the class to which it belongs. We make sure of this by emitting | |
9731 | the class first. The next time is the definition, which is | |
9732 | handled above. The two may come from the same source text. */ | |
9733 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
9734 | equate_decl_number_to_die (decl, subr_die); | |
9735 | } | |
a94dbf2c JM |
9736 | } |
9737 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 9738 | { |
10a11b75 | 9739 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 9740 | { |
10a11b75 JM |
9741 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
9742 | inline functions, but not for extern inline functions. | |
9743 | We can't get this completely correct because information | |
9744 | about whether the function was declared inline is not | |
9745 | saved anywhere. */ | |
9746 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
9747 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
9748 | else | |
10a11b75 | 9749 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 9750 | } |
61b32c02 | 9751 | else |
10a11b75 | 9752 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 9753 | |
a3f97cbb JW |
9754 | equate_decl_number_to_die (decl, subr_die); |
9755 | } | |
9756 | else if (!DECL_EXTERNAL (decl)) | |
9757 | { | |
1edf43d6 | 9758 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
ba7b35df | 9759 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 9760 | |
5c90448c JM |
9761 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
9762 | current_funcdef_number); | |
7d4440be | 9763 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
9764 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
9765 | current_funcdef_number); | |
a3f97cbb JW |
9766 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
9767 | ||
d291dd49 JM |
9768 | add_pubname (decl, subr_die); |
9769 | add_arange (decl, subr_die); | |
9770 | ||
a3f97cbb | 9771 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
9772 | /* Add a reference to the FDE for this routine. */ |
9773 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
9774 | #endif | |
9775 | ||
810429b7 JM |
9776 | /* Define the "frame base" location for this routine. We use the |
9777 | frame pointer or stack pointer registers, since the RTL for local | |
9778 | variables is relative to one of them. */ | |
b1ccbc24 RK |
9779 | fp_reg |
9780 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
9781 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 9782 | |
ef76d03b JW |
9783 | #if 0 |
9784 | /* ??? This fails for nested inline functions, because context_display | |
9785 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 9786 | if (current_function_needs_context) |
ef76d03b JW |
9787 | add_AT_location_description (subr_die, DW_AT_static_link, |
9788 | lookup_static_chain (decl)); | |
9789 | #endif | |
a3f97cbb JW |
9790 | } |
9791 | ||
9792 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 9793 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
9794 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
9795 | `...' at the end of the formal parameter list. In order to find out if | |
9796 | there was a trailing ellipsis or not, we must instead look at the type | |
9797 | associated with the FUNCTION_DECL. This will be a node of type | |
9798 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 9799 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 9800 | an ellipsis at the end. */ |
71dfc51f | 9801 | |
a3f97cbb | 9802 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 9803 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 9804 | its formal parameters. */ |
4927276d | 9805 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 9806 | ; |
4edb7b60 | 9807 | else if (declaration) |
5daf7c0a | 9808 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
9809 | else |
9810 | { | |
9811 | /* Generate DIEs to represent all known formal parameters */ | |
9812 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
9813 | register tree parm; | |
9814 | ||
9815 | /* When generating DIEs, generate the unspecified_parameters DIE | |
9816 | instead if we come across the arg "__builtin_va_alist" */ | |
9817 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
9818 | if (TREE_CODE (parm) == PARM_DECL) |
9819 | { | |
db3cf6fb MS |
9820 | if (DECL_NAME (parm) |
9821 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
9822 | "__builtin_va_alist")) | |
71dfc51f RK |
9823 | gen_unspecified_parameters_die (parm, subr_die); |
9824 | else | |
9825 | gen_decl_die (parm, subr_die); | |
9826 | } | |
a3f97cbb JW |
9827 | |
9828 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
556273e0 | 9829 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
9830 | this is detectable when the end of the arg list is not a |
9831 | void_type_node 2) an unprototyped function declaration (not a | |
9832 | definition). This just means that we have no info about the | |
9833 | parameters at all. */ | |
9834 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 9835 | if (fn_arg_types != NULL) |
a3f97cbb JW |
9836 | { |
9837 | /* this is the prototyped case, check for ... */ | |
9838 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 9839 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 9840 | } |
71dfc51f RK |
9841 | else if (DECL_INITIAL (decl) == NULL_TREE) |
9842 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
9843 | } |
9844 | ||
9845 | /* Output Dwarf info for all of the stuff within the body of the function | |
9846 | (if it has one - it may be just a declaration). */ | |
9847 | outer_scope = DECL_INITIAL (decl); | |
9848 | ||
d7248bff JM |
9849 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
9850 | node created to represent a function. This outermost BLOCK actually | |
9851 | represents the outermost binding contour for the function, i.e. the | |
9852 | contour in which the function's formal parameters and labels get | |
9853 | declared. Curiously, it appears that the front end doesn't actually | |
9854 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
9855 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
9856 | list for the function instead.) The BLOCK_VARS list for the | |
9857 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
9858 | the function however, and we output DWARF info for those in | |
9859 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
9860 | node representing the function's outermost pair of curly braces, and | |
9861 | any blocks used for the base and member initializers of a C++ | |
9862 | constructor function. */ | |
4edb7b60 | 9863 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
9864 | { |
9865 | current_function_has_inlines = 0; | |
9866 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 9867 | |
ce61cc73 | 9868 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
9869 | if (current_function_has_inlines) |
9870 | { | |
9871 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
9872 | if (! comp_unit_has_inlines) | |
9873 | { | |
9874 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
9875 | comp_unit_has_inlines = 1; | |
9876 | } | |
9877 | } | |
9878 | #endif | |
9879 | } | |
a3f97cbb JW |
9880 | } |
9881 | ||
9882 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 9883 | |
a3f97cbb JW |
9884 | static void |
9885 | gen_variable_die (decl, context_die) | |
9886 | register tree decl; | |
9887 | register dw_die_ref context_die; | |
9888 | { | |
9889 | register tree origin = decl_ultimate_origin (decl); | |
9890 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 9891 | |
bdb669cb | 9892 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9893 | int declaration = (DECL_EXTERNAL (decl) |
9894 | || class_scope_p (context_die)); | |
4edb7b60 | 9895 | |
a3f97cbb | 9896 | if (origin != NULL) |
71dfc51f | 9897 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
9898 | /* Loop unrolling can create multiple blocks that refer to the same |
9899 | static variable, so we must test for the DW_AT_declaration flag. */ | |
9900 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
9901 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
9902 | sharing them. */ | |
9903 | else if (old_die && TREE_STATIC (decl) | |
9904 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 9905 | { |
e689ae67 | 9906 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
9907 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
9908 | if (DECL_NAME (decl)) | |
9909 | { | |
981975b6 | 9910 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9911 | |
bdb669cb JM |
9912 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9913 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 9914 | |
bdb669cb | 9915 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 9916 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
9917 | |
9918 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
9919 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
9920 | } |
9921 | } | |
a3f97cbb JW |
9922 | else |
9923 | { | |
9924 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
9925 | add_type_attribute (var_die, TREE_TYPE (decl), |
9926 | TREE_READONLY (decl), | |
9927 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 9928 | |
273dbe67 JM |
9929 | if (TREE_PUBLIC (decl)) |
9930 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 9931 | |
273dbe67 JM |
9932 | if (DECL_ARTIFICIAL (decl)) |
9933 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 9934 | |
a94dbf2c JM |
9935 | if (TREE_PROTECTED (decl)) |
9936 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 9937 | |
a94dbf2c JM |
9938 | else if (TREE_PRIVATE (decl)) |
9939 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9940 | } |
4edb7b60 JM |
9941 | |
9942 | if (declaration) | |
9943 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 9944 | |
9765e357 | 9945 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
9946 | equate_decl_number_to_die (decl, var_die); |
9947 | ||
9948 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
9949 | { |
9950 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 9951 | add_pubname (decl, var_die); |
a3f97cbb | 9952 | } |
1bfb5f8f JM |
9953 | else |
9954 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
9955 | } |
9956 | ||
9957 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 9958 | |
a3f97cbb JW |
9959 | static void |
9960 | gen_label_die (decl, context_die) | |
9961 | register tree decl; | |
9962 | register dw_die_ref context_die; | |
9963 | { | |
9964 | register tree origin = decl_ultimate_origin (decl); | |
9965 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
9966 | register rtx insn; | |
9967 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 9968 | |
a3f97cbb | 9969 | if (origin != NULL) |
71dfc51f | 9970 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 9971 | else |
71dfc51f RK |
9972 | add_name_and_src_coords_attributes (lbl_die, decl); |
9973 | ||
a3f97cbb | 9974 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9975 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
9976 | else |
9977 | { | |
9978 | insn = DECL_RTL (decl); | |
088e7160 NC |
9979 | |
9980 | /* Deleted labels are programmer specified labels which have been | |
9981 | eliminated because of various optimisations. We still emit them | |
9982 | here so that it is possible to put breakpoints on them. */ | |
9983 | if (GET_CODE (insn) == CODE_LABEL | |
9984 | || ((GET_CODE (insn) == NOTE | |
9985 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 9986 | { |
556273e0 KH |
9987 | /* When optimization is enabled (via -O) some parts of the compiler |
9988 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
9989 | represent source-level labels which were explicitly declared by |
9990 | the user. This really shouldn't be happening though, so catch | |
9991 | it if it ever does happen. */ | |
9992 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
9993 | abort (); |
9994 | ||
66234570 | 9995 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
9996 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
9997 | } | |
9998 | } | |
9999 | } | |
10000 | ||
10001 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10002 | |
a3f97cbb | 10003 | static void |
d7248bff | 10004 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10005 | register tree stmt; |
10006 | register dw_die_ref context_die; | |
d7248bff | 10007 | int depth; |
a3f97cbb JW |
10008 | { |
10009 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
10010 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
10011 | |
10012 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10013 | { |
5c90448c | 10014 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10015 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10016 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
18c038b9 MM |
10017 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10018 | BLOCK_NUMBER (stmt)); | |
a3f97cbb JW |
10019 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
10020 | } | |
71dfc51f | 10021 | |
d7248bff | 10022 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10023 | } |
10024 | ||
10025 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10026 | |
a3f97cbb | 10027 | static void |
d7248bff | 10028 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
10029 | register tree stmt; |
10030 | register dw_die_ref context_die; | |
d7248bff | 10031 | int depth; |
a3f97cbb | 10032 | { |
71dfc51f | 10033 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10034 | { |
71dfc51f RK |
10035 | register dw_die_ref subr_die |
10036 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 10037 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 10038 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10039 | |
10a11b75 | 10040 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10041 | dwarf2out_abstract_function (decl); |
10a11b75 | 10042 | |
ab72d377 | 10043 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10044 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10045 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10046 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10047 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10048 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10049 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10050 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10051 | current_function_has_inlines = 1; |
a3f97cbb | 10052 | } |
a3f97cbb JW |
10053 | } |
10054 | ||
10055 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10056 | |
a3f97cbb JW |
10057 | static void |
10058 | gen_field_die (decl, context_die) | |
10059 | register tree decl; | |
10060 | register dw_die_ref context_die; | |
10061 | { | |
10062 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 10063 | |
a3f97cbb | 10064 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10065 | add_type_attribute (decl_die, member_declared_type (decl), |
10066 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10067 | context_die); | |
71dfc51f | 10068 | |
a3f97cbb JW |
10069 | /* If this is a bit field... */ |
10070 | if (DECL_BIT_FIELD_TYPE (decl)) | |
10071 | { | |
10072 | add_byte_size_attribute (decl_die, decl); | |
10073 | add_bit_size_attribute (decl_die, decl); | |
10074 | add_bit_offset_attribute (decl_die, decl); | |
10075 | } | |
71dfc51f | 10076 | |
a94dbf2c JM |
10077 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10078 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10079 | |
273dbe67 JM |
10080 | if (DECL_ARTIFICIAL (decl)) |
10081 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10082 | |
a94dbf2c JM |
10083 | if (TREE_PROTECTED (decl)) |
10084 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10085 | |
a94dbf2c JM |
10086 | else if (TREE_PRIVATE (decl)) |
10087 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10088 | } |
10089 | ||
ab72d377 JM |
10090 | #if 0 |
10091 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10092 | Use modified_type_die instead. | |
a3f97cbb JW |
10093 | We keep this code here just in case these types of DIEs may be needed to |
10094 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10095 | static void | |
10096 | gen_pointer_type_die (type, context_die) | |
10097 | register tree type; | |
10098 | register dw_die_ref context_die; | |
10099 | { | |
71dfc51f RK |
10100 | register dw_die_ref ptr_die |
10101 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
10102 | ||
a3f97cbb | 10103 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10104 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10105 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10106 | } |
10107 | ||
ab72d377 JM |
10108 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10109 | Use modified_type_die instead. | |
a3f97cbb JW |
10110 | We keep this code here just in case these types of DIEs may be needed to |
10111 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10112 | static void | |
10113 | gen_reference_type_die (type, context_die) | |
10114 | register tree type; | |
10115 | register dw_die_ref context_die; | |
10116 | { | |
71dfc51f RK |
10117 | register dw_die_ref ref_die |
10118 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
10119 | ||
a3f97cbb | 10120 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10121 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10122 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10123 | } |
ab72d377 | 10124 | #endif |
a3f97cbb JW |
10125 | |
10126 | /* Generate a DIE for a pointer to a member type. */ | |
10127 | static void | |
10128 | gen_ptr_to_mbr_type_die (type, context_die) | |
10129 | register tree type; | |
10130 | register dw_die_ref context_die; | |
10131 | { | |
71dfc51f RK |
10132 | register dw_die_ref ptr_die |
10133 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
10134 | ||
a3f97cbb | 10135 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10136 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10137 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10138 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10139 | } | |
10140 | ||
10141 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10142 | |
a96c67ec JM |
10143 | static dw_die_ref |
10144 | gen_compile_unit_die (filename) | |
10145 | register const char *filename; | |
a3f97cbb | 10146 | { |
a96c67ec | 10147 | register dw_die_ref die; |
a3f97cbb | 10148 | char producer[250]; |
d3e3972c | 10149 | const char *wd = getpwd (); |
a96c67ec | 10150 | int language; |
a3f97cbb | 10151 | |
a96c67ec JM |
10152 | die = new_die (DW_TAG_compile_unit, NULL); |
10153 | add_name_attribute (die, filename); | |
bdb669cb | 10154 | |
a96c67ec JM |
10155 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10156 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10157 | |
10158 | sprintf (producer, "%s %s", language_string, version_string); | |
10159 | ||
10160 | #ifdef MIPS_DEBUGGING_INFO | |
10161 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10162 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10163 | not appear in the producer string, the debugger reaches the conclusion | |
10164 | that the object file is stripped and has no debugging information. | |
10165 | To get the MIPS/SGI debugger to believe that there is debugging | |
10166 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10167 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10168 | strcat (producer, " -g"); | |
a3f97cbb JW |
10169 | #endif |
10170 | ||
a96c67ec | 10171 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10172 | |
a3f97cbb | 10173 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10174 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10175 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10176 | language = DW_LANG_Ada83; |
a9d38797 | 10177 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10178 | language = DW_LANG_Fortran77; |
bc28c45b | 10179 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10180 | language = DW_LANG_Pascal83; |
28985b81 AG |
10181 | else if (strcmp (language_string, "GNU Java") == 0) |
10182 | language = DW_LANG_Java; | |
a3f97cbb | 10183 | else if (flag_traditional) |
a96c67ec | 10184 | language = DW_LANG_C; |
a3f97cbb | 10185 | else |
a96c67ec | 10186 | language = DW_LANG_C89; |
a9d38797 | 10187 | |
a96c67ec JM |
10188 | add_AT_unsigned (die, DW_AT_language, language); |
10189 | ||
10190 | return die; | |
a3f97cbb JW |
10191 | } |
10192 | ||
10193 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10194 | |
a3f97cbb JW |
10195 | static void |
10196 | gen_string_type_die (type, context_die) | |
10197 | register tree type; | |
10198 | register dw_die_ref context_die; | |
10199 | { | |
71dfc51f RK |
10200 | register dw_die_ref type_die |
10201 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
10202 | ||
bdb669cb | 10203 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10204 | |
10205 | /* Fudge the string length attribute for now. */ | |
556273e0 | 10206 | |
a3f97cbb | 10207 | /* TODO: add string length info. |
71dfc51f | 10208 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
10209 | bound_representation (upper_bound, 0, 'u'); */ |
10210 | } | |
10211 | ||
61b32c02 | 10212 | /* Generate the DIE for a base class. */ |
71dfc51f | 10213 | |
61b32c02 JM |
10214 | static void |
10215 | gen_inheritance_die (binfo, context_die) | |
10216 | register tree binfo; | |
10217 | register dw_die_ref context_die; | |
10218 | { | |
10219 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 10220 | |
61b32c02 JM |
10221 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10222 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10223 | |
61b32c02 JM |
10224 | if (TREE_VIA_VIRTUAL (binfo)) |
10225 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
10226 | if (TREE_VIA_PUBLIC (binfo)) | |
10227 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10228 | else if (TREE_VIA_PROTECTED (binfo)) | |
10229 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10230 | } | |
10231 | ||
956d6950 | 10232 | /* Generate a DIE for a class member. */ |
71dfc51f | 10233 | |
a3f97cbb JW |
10234 | static void |
10235 | gen_member_die (type, context_die) | |
10236 | register tree type; | |
10237 | register dw_die_ref context_die; | |
10238 | { | |
61b32c02 | 10239 | register tree member; |
10a11b75 | 10240 | dw_die_ref child; |
71dfc51f | 10241 | |
a3f97cbb JW |
10242 | /* If this is not an incomplete type, output descriptions of each of its |
10243 | members. Note that as we output the DIEs necessary to represent the | |
10244 | members of this record or union type, we will also be trying to output | |
10245 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 KH |
10246 | function (above) will specifically avoid generating type DIEs for member |
10247 | types *within* the list of member DIEs for this (containing) type execpt | |
a3f97cbb JW |
10248 | for those types (of members) which are explicitly marked as also being |
10249 | members of this (containing) type themselves. The g++ front- end can | |
10250 | force any given type to be treated as a member of some other | |
556273e0 | 10251 | (containing) type by setting the TYPE_CONTEXT of the given (member) type |
a3f97cbb JW |
10252 | to point to the TREE node representing the appropriate (containing) |
10253 | type. */ | |
10254 | ||
61b32c02 JM |
10255 | /* First output info about the base classes. */ |
10256 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10257 | { |
61b32c02 JM |
10258 | register tree bases = TYPE_BINFO_BASETYPES (type); |
10259 | register int n_bases = TREE_VEC_LENGTH (bases); | |
10260 | register int i; | |
10261 | ||
10262 | for (i = 0; i < n_bases; i++) | |
10263 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10264 | } |
10265 | ||
61b32c02 JM |
10266 | /* Now output info about the data members and type members. */ |
10267 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10268 | { |
10269 | /* If we thought we were generating minimal debug info for TYPE | |
10270 | and then changed our minds, some of the member declarations | |
10271 | may have already been defined. Don't define them again, but | |
10272 | do put them in the right order. */ | |
10273 | ||
10274 | child = lookup_decl_die (member); | |
10275 | if (child) | |
10276 | splice_child_die (context_die, child); | |
10277 | else | |
10278 | gen_decl_die (member, context_die); | |
10279 | } | |
61b32c02 | 10280 | |
a3f97cbb | 10281 | /* Now output info about the function members (if any). */ |
61b32c02 | 10282 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10283 | { |
5daf7c0a JM |
10284 | /* Don't include clones in the member list. */ |
10285 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10286 | continue; | |
10287 | ||
10a11b75 JM |
10288 | child = lookup_decl_die (member); |
10289 | if (child) | |
10290 | splice_child_die (context_die, child); | |
10291 | else | |
10292 | gen_decl_die (member, context_die); | |
10293 | } | |
a3f97cbb JW |
10294 | } |
10295 | ||
10a11b75 JM |
10296 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10297 | is set, we pretend that the type was never defined, so we only get the | |
10298 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10299 | |
a3f97cbb | 10300 | static void |
273dbe67 | 10301 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 10302 | register tree type; |
a3f97cbb JW |
10303 | register dw_die_ref context_die; |
10304 | { | |
273dbe67 | 10305 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
10306 | register dw_die_ref scope_die = 0; |
10307 | register int nested = 0; | |
10a11b75 | 10308 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10309 | && (! TYPE_STUB_DECL (type) |
10310 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10311 | |
10a11b75 | 10312 | if (type_die && ! complete) |
273dbe67 | 10313 | return; |
a082c85a | 10314 | |
71dfc51f | 10315 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10316 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10317 | nested = 1; |
10318 | ||
a94dbf2c | 10319 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10320 | |
10321 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10322 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10323 | { |
273dbe67 | 10324 | register dw_die_ref old_die = type_die; |
71dfc51f | 10325 | |
a3f97cbb JW |
10326 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10327 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 10328 | scope_die); |
a3f97cbb | 10329 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10330 | if (old_die) |
10331 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10332 | else |
10333 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10334 | } |
4b674448 | 10335 | else |
273dbe67 | 10336 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10337 | |
10338 | /* If this type has been completed, then give it a byte_size attribute and | |
10339 | then give a list of members. */ | |
2081603c | 10340 | if (complete) |
a3f97cbb | 10341 | { |
556273e0 | 10342 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10343 | this type is expressed in terms of this type itself. */ |
10344 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10345 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10346 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10347 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10348 | |
ef76d03b JW |
10349 | /* If the first reference to this type was as the return type of an |
10350 | inline function, then it may not have a parent. Fix this now. */ | |
10351 | if (type_die->die_parent == NULL) | |
10352 | add_child_die (scope_die, type_die); | |
10353 | ||
273dbe67 JM |
10354 | push_decl_scope (type); |
10355 | gen_member_die (type, type_die); | |
10356 | pop_decl_scope (); | |
71dfc51f | 10357 | |
a94dbf2c JM |
10358 | /* GNU extension: Record what type our vtable lives in. */ |
10359 | if (TYPE_VFIELD (type)) | |
10360 | { | |
10361 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10362 | |
de6e505e JM |
10363 | gen_type_die (vtype, context_die); |
10364 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10365 | lookup_type_die (vtype)); | |
a94dbf2c | 10366 | } |
a3f97cbb | 10367 | } |
4b674448 | 10368 | else |
8a8c3656 JM |
10369 | { |
10370 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10371 | |
9765e357 | 10372 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 10373 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 10374 | add_incomplete_type (type); |
8a8c3656 | 10375 | } |
a3f97cbb JW |
10376 | } |
10377 | ||
10378 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10379 | |
a3f97cbb JW |
10380 | static void |
10381 | gen_subroutine_type_die (type, context_die) | |
10382 | register tree type; | |
10383 | register dw_die_ref context_die; | |
10384 | { | |
10385 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
10386 | register dw_die_ref subr_die |
10387 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
10388 | ||
a3f97cbb JW |
10389 | equate_type_number_to_die (type, subr_die); |
10390 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10391 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10392 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10393 | } |
10394 | ||
10395 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10396 | |
a3f97cbb JW |
10397 | static void |
10398 | gen_typedef_die (decl, context_die) | |
10399 | register tree decl; | |
10400 | register dw_die_ref context_die; | |
10401 | { | |
a3f97cbb | 10402 | register dw_die_ref type_die; |
a94dbf2c JM |
10403 | register tree origin; |
10404 | ||
10405 | if (TREE_ASM_WRITTEN (decl)) | |
10406 | return; | |
10407 | TREE_ASM_WRITTEN (decl) = 1; | |
10408 | ||
777ad4c2 | 10409 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 10410 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10411 | if (origin != NULL) |
a94dbf2c | 10412 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10413 | else |
10414 | { | |
a94dbf2c | 10415 | register tree type; |
a3f97cbb | 10416 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10417 | if (DECL_ORIGINAL_TYPE (decl)) |
10418 | { | |
10419 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10420 | |
10421 | if (type == TREE_TYPE (decl)) | |
10422 | abort (); | |
10423 | else | |
10424 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10425 | } |
10426 | else | |
10427 | type = TREE_TYPE (decl); | |
10428 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
10429 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10430 | } |
71dfc51f | 10431 | |
a3f97cbb | 10432 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10433 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10434 | } |
10435 | ||
10436 | /* Generate a type description DIE. */ | |
71dfc51f | 10437 | |
a3f97cbb JW |
10438 | static void |
10439 | gen_type_die (type, context_die) | |
10440 | register tree type; | |
10441 | register dw_die_ref context_die; | |
10442 | { | |
348bb3c7 JM |
10443 | int need_pop; |
10444 | ||
71dfc51f RK |
10445 | if (type == NULL_TREE || type == error_mark_node) |
10446 | return; | |
a3f97cbb | 10447 | |
38e01259 | 10448 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10449 | this type (i.e. without any const or volatile qualifiers) so get the |
10450 | main variant (i.e. the unqualified version) of this type now. */ | |
10451 | type = type_main_variant (type); | |
10452 | ||
10453 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10454 | return; |
a3f97cbb | 10455 | |
a94dbf2c JM |
10456 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10457 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10458 | { |
a94dbf2c JM |
10459 | TREE_ASM_WRITTEN (type) = 1; |
10460 | gen_decl_die (TYPE_NAME (type), context_die); | |
10461 | return; | |
10462 | } | |
10463 | ||
a3f97cbb JW |
10464 | switch (TREE_CODE (type)) |
10465 | { | |
10466 | case ERROR_MARK: | |
10467 | break; | |
10468 | ||
10469 | case POINTER_TYPE: | |
10470 | case REFERENCE_TYPE: | |
956d6950 JL |
10471 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10472 | ensures that the gen_type_die recursion will terminate even if the | |
10473 | type is recursive. Recursive types are possible in Ada. */ | |
10474 | /* ??? We could perhaps do this for all types before the switch | |
10475 | statement. */ | |
10476 | TREE_ASM_WRITTEN (type) = 1; | |
10477 | ||
a3f97cbb JW |
10478 | /* For these types, all that is required is that we output a DIE (or a |
10479 | set of DIEs) to represent the "basis" type. */ | |
10480 | gen_type_die (TREE_TYPE (type), context_die); | |
10481 | break; | |
10482 | ||
10483 | case OFFSET_TYPE: | |
556273e0 | 10484 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10485 | Output a description of the relevant class type. */ |
a3f97cbb | 10486 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10487 | |
a3f97cbb JW |
10488 | /* Output a description of the type of the object pointed to. */ |
10489 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10490 | |
a3f97cbb JW |
10491 | /* Now output a DIE to represent this pointer-to-data-member type |
10492 | itself. */ | |
10493 | gen_ptr_to_mbr_type_die (type, context_die); | |
10494 | break; | |
10495 | ||
10496 | case SET_TYPE: | |
10497 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10498 | gen_set_type_die (type, context_die); | |
10499 | break; | |
10500 | ||
10501 | case FILE_TYPE: | |
10502 | gen_type_die (TREE_TYPE (type), context_die); | |
10503 | abort (); /* No way to represent these in Dwarf yet! */ | |
10504 | break; | |
10505 | ||
10506 | case FUNCTION_TYPE: | |
10507 | /* Force out return type (in case it wasn't forced out already). */ | |
10508 | gen_type_die (TREE_TYPE (type), context_die); | |
10509 | gen_subroutine_type_die (type, context_die); | |
10510 | break; | |
10511 | ||
10512 | case METHOD_TYPE: | |
10513 | /* Force out return type (in case it wasn't forced out already). */ | |
10514 | gen_type_die (TREE_TYPE (type), context_die); | |
10515 | gen_subroutine_type_die (type, context_die); | |
10516 | break; | |
10517 | ||
10518 | case ARRAY_TYPE: | |
10519 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
10520 | { | |
10521 | gen_type_die (TREE_TYPE (type), context_die); | |
10522 | gen_string_type_die (type, context_die); | |
10523 | } | |
10524 | else | |
71dfc51f | 10525 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
10526 | break; |
10527 | ||
4061f623 BS |
10528 | case VECTOR_TYPE: |
10529 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
10530 | break; | |
10531 | ||
a3f97cbb JW |
10532 | case ENUMERAL_TYPE: |
10533 | case RECORD_TYPE: | |
10534 | case UNION_TYPE: | |
10535 | case QUAL_UNION_TYPE: | |
a082c85a | 10536 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
10537 | written out yet, writing it out will cover this one, too. |
10538 | This does not apply to instantiations of member class templates; | |
10539 | they need to be added to the containing class as they are | |
777ad4c2 | 10540 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
10541 | from multiple TUs, since we can't predict what set of template |
10542 | instantiations we'll get. */ | |
a082c85a | 10543 | if (TYPE_CONTEXT (type) |
5f2f160c | 10544 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 10545 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
10546 | { |
10547 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
10548 | ||
348bb3c7 | 10549 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
10550 | return; |
10551 | ||
10552 | /* If that failed, attach ourselves to the stub. */ | |
10553 | push_decl_scope (TYPE_CONTEXT (type)); | |
10554 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 10555 | need_pop = 1; |
a94dbf2c | 10556 | } |
348bb3c7 JM |
10557 | else |
10558 | need_pop = 0; | |
a94dbf2c JM |
10559 | |
10560 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 10561 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 10562 | else |
273dbe67 | 10563 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 10564 | |
348bb3c7 | 10565 | if (need_pop) |
a94dbf2c JM |
10566 | pop_decl_scope (); |
10567 | ||
4b674448 | 10568 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
10569 | it up if it is ever completed. gen_*_type_die will set it for us |
10570 | when appropriate. */ | |
10571 | return; | |
a3f97cbb JW |
10572 | |
10573 | case VOID_TYPE: | |
10574 | case INTEGER_TYPE: | |
10575 | case REAL_TYPE: | |
10576 | case COMPLEX_TYPE: | |
10577 | case BOOLEAN_TYPE: | |
10578 | case CHAR_TYPE: | |
10579 | /* No DIEs needed for fundamental types. */ | |
10580 | break; | |
10581 | ||
10582 | case LANG_TYPE: | |
10583 | /* No Dwarf representation currently defined. */ | |
10584 | break; | |
10585 | ||
10586 | default: | |
10587 | abort (); | |
10588 | } | |
10589 | ||
10590 | TREE_ASM_WRITTEN (type) = 1; | |
10591 | } | |
10592 | ||
10593 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 10594 | |
a3f97cbb JW |
10595 | static void |
10596 | gen_tagged_type_instantiation_die (type, context_die) | |
10597 | register tree type; | |
10598 | register dw_die_ref context_die; | |
10599 | { | |
71dfc51f RK |
10600 | if (type == NULL_TREE || type == error_mark_node) |
10601 | return; | |
a3f97cbb | 10602 | |
38e01259 | 10603 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10604 | this type (i.e. without any const or volatile qualifiers) so make sure |
10605 | that we have the main variant (i.e. the unqualified version) of this | |
10606 | type now. */ | |
bbc6ae08 | 10607 | if (type != type_main_variant (type)) |
3a88cbd1 | 10608 | abort (); |
a3f97cbb | 10609 | |
203588e7 | 10610 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 10611 | an instance of an unresolved type. */ |
556273e0 | 10612 | |
a3f97cbb JW |
10613 | switch (TREE_CODE (type)) |
10614 | { | |
10615 | case ERROR_MARK: | |
10616 | break; | |
10617 | ||
10618 | case ENUMERAL_TYPE: | |
10619 | gen_inlined_enumeration_type_die (type, context_die); | |
10620 | break; | |
10621 | ||
10622 | case RECORD_TYPE: | |
10623 | gen_inlined_structure_type_die (type, context_die); | |
10624 | break; | |
10625 | ||
10626 | case UNION_TYPE: | |
10627 | case QUAL_UNION_TYPE: | |
10628 | gen_inlined_union_type_die (type, context_die); | |
10629 | break; | |
10630 | ||
10631 | default: | |
71dfc51f | 10632 | abort (); |
a3f97cbb JW |
10633 | } |
10634 | } | |
10635 | ||
10636 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
10637 | things which are local to the given block. */ | |
71dfc51f | 10638 | |
a3f97cbb | 10639 | static void |
d7248bff | 10640 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10641 | register tree stmt; |
10642 | register dw_die_ref context_die; | |
d7248bff | 10643 | int depth; |
a3f97cbb JW |
10644 | { |
10645 | register int must_output_die = 0; | |
10646 | register tree origin; | |
10647 | register tree decl; | |
10648 | register enum tree_code origin_code; | |
10649 | ||
10650 | /* Ignore blocks never really used to make RTL. */ | |
10651 | ||
1e7f092a JM |
10652 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
10653 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 10654 | return; |
a3f97cbb JW |
10655 | |
10656 | /* Determine the "ultimate origin" of this block. This block may be an | |
10657 | inlined instance of an inlined instance of inline function, so we have | |
10658 | to trace all of the way back through the origin chain to find out what | |
10659 | sort of node actually served as the original seed for the creation of | |
10660 | the current block. */ | |
10661 | origin = block_ultimate_origin (stmt); | |
10662 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
10663 | ||
10664 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
10665 | block. */ | |
10666 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
10667 | /* The outer scopes for inlinings *must* always be represented. We |
10668 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
10669 | must_output_die = 1; | |
a3f97cbb JW |
10670 | else |
10671 | { | |
10672 | /* In the case where the current block represents an inlining of the | |
556273e0 | 10673 | "body block" of an inline function, we must *NOT* output any DIE for |
a3f97cbb JW |
10674 | this block because we have already output a DIE to represent the |
10675 | whole inlined function scope and the "body block" of any function | |
10676 | doesn't really represent a different scope according to ANSI C | |
10677 | rules. So we check here to make sure that this block does not | |
10678 | represent a "body block inlining" before trying to set the | |
10679 | `must_output_die' flag. */ | |
d7248bff | 10680 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
10681 | { |
10682 | /* Determine if this block directly contains any "significant" | |
10683 | local declarations which we will need to output DIEs for. */ | |
10684 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
10685 | /* We are not in terse mode so *any* local declaration counts |
10686 | as being a "significant" one. */ | |
10687 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 10688 | else |
71dfc51f RK |
10689 | /* We are in terse mode, so only local (nested) function |
10690 | definitions count as "significant" local declarations. */ | |
10691 | for (decl = BLOCK_VARS (stmt); | |
10692 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10693 | if (TREE_CODE (decl) == FUNCTION_DECL | |
10694 | && DECL_INITIAL (decl)) | |
a3f97cbb | 10695 | { |
71dfc51f RK |
10696 | must_output_die = 1; |
10697 | break; | |
a3f97cbb | 10698 | } |
a3f97cbb JW |
10699 | } |
10700 | } | |
10701 | ||
10702 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
10703 | DIE for any block which contains no significant local declarations at | |
10704 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
10705 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
10706 | that in terse mode, our definition of what constitutes a "significant" | |
10707 | local declaration gets restricted to include only inlined function | |
10708 | instances and local (nested) function definitions. */ | |
10709 | if (must_output_die) | |
10710 | { | |
10711 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 10712 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 10713 | else |
71dfc51f | 10714 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
10715 | } |
10716 | else | |
d7248bff | 10717 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
10718 | } |
10719 | ||
10720 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 10721 | all of its sub-blocks. */ |
71dfc51f | 10722 | |
a3f97cbb | 10723 | static void |
d7248bff | 10724 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
10725 | register tree stmt; |
10726 | register dw_die_ref context_die; | |
d7248bff | 10727 | int depth; |
a3f97cbb JW |
10728 | { |
10729 | register tree decl; | |
10730 | register tree subblocks; | |
71dfc51f | 10731 | |
a3f97cbb | 10732 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
10733 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
10734 | return; | |
10735 | ||
88dad228 JM |
10736 | /* Output the DIEs to represent all of the data objects and typedefs |
10737 | declared directly within this block but not within any nested | |
10738 | sub-blocks. Also, nested function and tag DIEs have been | |
10739 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
10740 | for (decl = BLOCK_VARS (stmt); |
10741 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10742 | { | |
a94dbf2c JM |
10743 | register dw_die_ref die; |
10744 | ||
88dad228 | 10745 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 10746 | die = lookup_decl_die (decl); |
88dad228 | 10747 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
10748 | die = lookup_type_die (TREE_TYPE (decl)); |
10749 | else | |
10750 | die = NULL; | |
10751 | ||
71dfc51f | 10752 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 10753 | add_child_die (context_die, die); |
88dad228 JM |
10754 | else |
10755 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
10756 | } |
10757 | ||
10758 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
10759 | therein) of this block. */ | |
10760 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
10761 | subblocks != NULL; | |
10762 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 10763 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
10764 | } |
10765 | ||
a94dbf2c | 10766 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
10767 | |
10768 | static inline int | |
a94dbf2c JM |
10769 | is_redundant_typedef (decl) |
10770 | register tree decl; | |
10771 | { | |
10772 | if (TYPE_DECL_IS_STUB (decl)) | |
10773 | return 1; | |
71dfc51f | 10774 | |
a94dbf2c JM |
10775 | if (DECL_ARTIFICIAL (decl) |
10776 | && DECL_CONTEXT (decl) | |
10777 | && is_tagged_type (DECL_CONTEXT (decl)) | |
10778 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
10779 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
10780 | /* Also ignore the artificial member typedef for the class name. */ | |
10781 | return 1; | |
71dfc51f | 10782 | |
a94dbf2c JM |
10783 | return 0; |
10784 | } | |
10785 | ||
a3f97cbb | 10786 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 10787 | |
a3f97cbb JW |
10788 | static void |
10789 | gen_decl_die (decl, context_die) | |
10790 | register tree decl; | |
10791 | register dw_die_ref context_die; | |
10792 | { | |
10793 | register tree origin; | |
71dfc51f | 10794 | |
a3f97cbb | 10795 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 10796 | return; |
a3f97cbb | 10797 | |
fcd7f76b JM |
10798 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
10799 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 10800 | return; |
a3f97cbb | 10801 | |
a3f97cbb JW |
10802 | switch (TREE_CODE (decl)) |
10803 | { | |
10804 | case CONST_DECL: | |
556273e0 | 10805 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
10806 | the Dwarf representation of the relevant enum type itself. */ |
10807 | break; | |
10808 | ||
10809 | case FUNCTION_DECL: | |
4edb7b60 JM |
10810 | /* Don't output any DIEs to represent mere function declarations, |
10811 | unless they are class members or explicit block externs. */ | |
10812 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 10813 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 10814 | break; |
bdb669cb | 10815 | |
5daf7c0a JM |
10816 | /* If we're emitting a clone, emit info for the abstract instance. */ |
10817 | if (DECL_ORIGIN (decl) != decl) | |
10818 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
1cfdcc15 JM |
10819 | /* If we're emitting an out-of-line copy of an inline function, |
10820 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
10821 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
10822 | && ! class_scope_p (context_die) | |
10823 | /* dwarf2out_abstract_function won't emit a die if this is just | |
10824 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
10825 | that case, because that works only if we have a die. */ | |
10826 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 10827 | { |
1edf43d6 | 10828 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
10829 | set_decl_origin_self (decl); |
10830 | } | |
5daf7c0a JM |
10831 | /* Otherwise we're emitting the primary DIE for this decl. */ |
10832 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
10833 | { |
10834 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
10835 | have described its return type. */ | |
10836 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
10837 | ||
2081603c JM |
10838 | /* And its virtual context. */ |
10839 | if (DECL_VINDEX (decl) != NULL_TREE) | |
10840 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
10841 | ||
a94dbf2c JM |
10842 | /* And its containing type. */ |
10843 | origin = decl_class_context (decl); | |
71dfc51f | 10844 | if (origin != NULL_TREE) |
10a11b75 | 10845 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10846 | } |
a3f97cbb JW |
10847 | |
10848 | /* Now output a DIE to represent the function itself. */ | |
10849 | gen_subprogram_die (decl, context_die); | |
10850 | break; | |
10851 | ||
10852 | case TYPE_DECL: | |
10853 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 10854 | actual typedefs. */ |
a3f97cbb | 10855 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 10856 | break; |
a3f97cbb | 10857 | |
556273e0 | 10858 | /* In the special case of a TYPE_DECL node representing the |
5c90448c | 10859 | declaration of some type tag, if the given TYPE_DECL is marked as |
a3f97cbb JW |
10860 | having been instantiated from some other (original) TYPE_DECL node |
10861 | (e.g. one which was generated within the original definition of an | |
10862 | inline function) we have to generate a special (abbreviated) | |
556273e0 | 10863 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 10864 | DIE here. */ |
2081603c | 10865 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
10866 | { |
10867 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
10868 | break; | |
10869 | } | |
a3f97cbb | 10870 | |
a94dbf2c JM |
10871 | if (is_redundant_typedef (decl)) |
10872 | gen_type_die (TREE_TYPE (decl), context_die); | |
10873 | else | |
71dfc51f RK |
10874 | /* Output a DIE to represent the typedef itself. */ |
10875 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
10876 | break; |
10877 | ||
10878 | case LABEL_DECL: | |
10879 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 10880 | gen_label_die (decl, context_die); |
a3f97cbb JW |
10881 | break; |
10882 | ||
10883 | case VAR_DECL: | |
10884 | /* If we are in terse mode, don't generate any DIEs to represent any | |
10885 | variable declarations or definitions. */ | |
10886 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 10887 | break; |
a3f97cbb JW |
10888 | |
10889 | /* Output any DIEs that are needed to specify the type of this data | |
10890 | object. */ | |
10891 | gen_type_die (TREE_TYPE (decl), context_die); | |
10892 | ||
a94dbf2c JM |
10893 | /* And its containing type. */ |
10894 | origin = decl_class_context (decl); | |
71dfc51f | 10895 | if (origin != NULL_TREE) |
10a11b75 | 10896 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10897 | |
a3f97cbb JW |
10898 | /* Now output the DIE to represent the data object itself. This gets |
10899 | complicated because of the possibility that the VAR_DECL really | |
10900 | represents an inlined instance of a formal parameter for an inline | |
10901 | function. */ | |
10902 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
10903 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
10904 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 10905 | else |
71dfc51f | 10906 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
10907 | break; |
10908 | ||
10909 | case FIELD_DECL: | |
a94dbf2c JM |
10910 | /* Ignore the nameless fields that are used to skip bits, but |
10911 | handle C++ anonymous unions. */ | |
71dfc51f RK |
10912 | if (DECL_NAME (decl) != NULL_TREE |
10913 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
10914 | { |
10915 | gen_type_die (member_declared_type (decl), context_die); | |
10916 | gen_field_die (decl, context_die); | |
10917 | } | |
10918 | break; | |
10919 | ||
10920 | case PARM_DECL: | |
10921 | gen_type_die (TREE_TYPE (decl), context_die); | |
10922 | gen_formal_parameter_die (decl, context_die); | |
10923 | break; | |
10924 | ||
348bb3c7 JM |
10925 | case NAMESPACE_DECL: |
10926 | /* Ignore for now. */ | |
10927 | break; | |
10928 | ||
a3f97cbb JW |
10929 | default: |
10930 | abort (); | |
10931 | } | |
a3f97cbb JW |
10932 | } |
10933 | \f | |
14a774a9 RK |
10934 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
10935 | ||
10936 | void | |
10937 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
10938 | const char *filename; |
10939 | const char *context_list; | |
14a774a9 RK |
10940 | { |
10941 | unsigned int file_index; | |
10942 | ||
10943 | if (filename != NULL) | |
10944 | { | |
10945 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
556273e0 | 10946 | tree context_list_decl |
14a774a9 RK |
10947 | = build_decl (LABEL_DECL, get_identifier (context_list), |
10948 | void_type_node); | |
10949 | ||
10950 | TREE_PUBLIC (context_list_decl) = TRUE; | |
10951 | add_name_attribute (unit_die, context_list); | |
981975b6 | 10952 | file_index = lookup_filename (filename); |
14a774a9 RK |
10953 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
10954 | add_pubname (context_list_decl, unit_die); | |
10955 | } | |
10956 | } | |
10957 | ||
71dfc51f RK |
10958 | /* Write the debugging output for DECL. */ |
10959 | ||
a3f97cbb | 10960 | void |
88dad228 | 10961 | dwarf2out_decl (decl) |
a3f97cbb | 10962 | register tree decl; |
a3f97cbb | 10963 | { |
88dad228 JM |
10964 | register dw_die_ref context_die = comp_unit_die; |
10965 | ||
a3f97cbb | 10966 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 10967 | return; |
a3f97cbb | 10968 | |
fcd7f76b | 10969 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 10970 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 10971 | return; |
a3f97cbb JW |
10972 | |
10973 | switch (TREE_CODE (decl)) | |
10974 | { | |
10975 | case FUNCTION_DECL: | |
556273e0 | 10976 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
10977 | builtin function. Explicit programmer-supplied declarations of |
10978 | these same functions should NOT be ignored however. */ | |
9765e357 | 10979 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 10980 | return; |
a3f97cbb JW |
10981 | |
10982 | /* What we would really like to do here is to filter out all mere | |
10983 | file-scope declarations of file-scope functions which are never | |
10984 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
10985 | that *are* referenced later on) but we aren't clairvoyant, so we have |
10986 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 10987 | on within the current translation unit). So here we just ignore all |
556273e0 | 10988 | file-scope function declarations which are not also definitions. If |
956d6950 | 10989 | and when the debugger needs to know something about these functions, |
556273e0 | 10990 | it will have to hunt around and find the DWARF information associated |
bbc6ae08 | 10991 | with the definition of the function. Note that we can't just check |
a3f97cbb JW |
10992 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
10993 | definitions and which ones represent mere declarations. We have to | |
10994 | check `DECL_INITIAL' instead. That's because the C front-end | |
10995 | supports some weird semantics for "extern inline" function | |
10996 | definitions. These can get inlined within the current translation | |
10997 | unit (an thus, we need to generate DWARF info for their abstract | |
10998 | instances so that the DWARF info for the concrete inlined instances | |
556273e0 | 10999 | can have something to refer to) but the compiler never generates any |
a3f97cbb JW |
11000 | out-of-lines instances of such things (despite the fact that they |
11001 | *are* definitions). The important point is that the C front-end | |
11002 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 11003 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb | 11004 | plays some similar games for inline function definitions appearing |
556273e0 | 11005 | within include files which also contain |
a3f97cbb JW |
11006 | `#pragma interface' pragmas. */ |
11007 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 11008 | return; |
88dad228 | 11009 | |
9c6cd30e JM |
11010 | /* If we're a nested function, initially use a parent of NULL; if we're |
11011 | a plain function, this will be fixed up in decls_for_scope. If | |
11012 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11013 | if (decl_function_context (decl)) |
9c6cd30e | 11014 | context_die = NULL; |
88dad228 | 11015 | |
a3f97cbb JW |
11016 | break; |
11017 | ||
11018 | case VAR_DECL: | |
556273e0 | 11019 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11020 | declaration and if the declaration was never even referenced from |
11021 | within this entire compilation unit. We suppress these DIEs in | |
11022 | order to save space in the .debug section (by eliminating entries | |
11023 | which are probably useless). Note that we must not suppress | |
11024 | block-local extern declarations (whether used or not) because that | |
11025 | would screw-up the debugger's name lookup mechanism and cause it to | |
11026 | miss things which really ought to be in scope at a given point. */ | |
11027 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11028 | return; |
a3f97cbb JW |
11029 | |
11030 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11031 | variable declarations or definitions. */ | |
11032 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11033 | return; |
a3f97cbb JW |
11034 | break; |
11035 | ||
11036 | case TYPE_DECL: | |
57fb7689 JM |
11037 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11038 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11039 | return; | |
11040 | ||
a3f97cbb | 11041 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11042 | normal built-in types for the language we are compiling. */ |
11043 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11044 | { |
11045 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11046 | comparisons have. */ | |
11047 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11048 | == DW_LANG_C_plus_plus) | |
11049 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
11050 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 11051 | |
a94dbf2c JM |
11052 | return; |
11053 | } | |
a3f97cbb | 11054 | |
88dad228 | 11055 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11056 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11057 | return; |
88dad228 JM |
11058 | |
11059 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11060 | this will be fixed up in decls_for_scope. */ | |
11061 | if (decl_function_context (decl)) | |
3f76745e | 11062 | context_die = NULL; |
88dad228 | 11063 | |
a3f97cbb JW |
11064 | break; |
11065 | ||
11066 | default: | |
11067 | return; | |
11068 | } | |
11069 | ||
88dad228 | 11070 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11071 | } |
11072 | ||
11073 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11074 | a lexical block. */ | |
71dfc51f | 11075 | |
a3f97cbb | 11076 | void |
9a666dda | 11077 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
11078 | register unsigned blocknum; |
11079 | { | |
a3f97cbb | 11080 | function_section (current_function_decl); |
8215347e | 11081 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11082 | } |
11083 | ||
11084 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11085 | lexical block. */ | |
71dfc51f | 11086 | |
a3f97cbb | 11087 | void |
9a666dda | 11088 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
11089 | register unsigned blocknum; |
11090 | { | |
a3f97cbb | 11091 | function_section (current_function_decl); |
8215347e | 11092 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11093 | } |
11094 | ||
64b59a80 JM |
11095 | /* Returns nonzero if it is appropriate not to emit any debugging |
11096 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11097 | |
64b59a80 JM |
11098 | Don't allow this for blocks with nested functions or local classes |
11099 | as we would end up with orphans, and in the presence of scheduling | |
11100 | we may end up calling them anyway. */ | |
11101 | ||
11102 | int | |
fcd7f76b JM |
11103 | dwarf2out_ignore_block (block) |
11104 | tree block; | |
11105 | { | |
11106 | tree decl; | |
11107 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
64b59a80 JM |
11108 | if (TREE_CODE (decl) == FUNCTION_DECL |
11109 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11110 | return 0; | |
11111 | return 1; | |
fcd7f76b JM |
11112 | } |
11113 | ||
a3f97cbb | 11114 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 11115 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
11116 | just a unique number which is associated with only that one filename. |
11117 | We need such numbers for the sake of generating labels | |
11118 | (in the .debug_sfnames section) and references to those | |
11119 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
11120 | If the filename given as an argument is not found in our current list, | |
11121 | add it to the list and assign it the next available unique index number. | |
11122 | In order to speed up searches, we remember the index of the filename | |
11123 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 11124 | |
a3f97cbb | 11125 | static unsigned |
981975b6 | 11126 | lookup_filename (file_name) |
d560ee52 | 11127 | const char *file_name; |
a3f97cbb | 11128 | { |
a3f97cbb JW |
11129 | register unsigned i; |
11130 | ||
981975b6 RH |
11131 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11132 | if (strcmp (file_name, "<internal>") == 0 | |
11133 | || strcmp (file_name, "<built-in>") == 0) | |
11134 | return 0; | |
11135 | ||
2e18bbae RH |
11136 | /* Check to see if the file name that was searched on the previous |
11137 | call matches this file name. If so, return the index. */ | |
981975b6 RH |
11138 | if (file_table.last_lookup_index != 0) |
11139 | if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0) | |
11140 | return file_table.last_lookup_index; | |
a3f97cbb JW |
11141 | |
11142 | /* Didn't match the previous lookup, search the table */ | |
981975b6 RH |
11143 | for (i = 1; i < file_table.in_use; ++i) |
11144 | if (strcmp (file_name, file_table.table[i]) == 0) | |
71dfc51f | 11145 | { |
981975b6 | 11146 | file_table.last_lookup_index = i; |
71dfc51f RK |
11147 | return i; |
11148 | } | |
a3f97cbb | 11149 | |
556273e0 | 11150 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11151 | the table to do so. If not, expand the current table. */ |
981975b6 | 11152 | if (i == file_table.allocated) |
a3f97cbb | 11153 | { |
981975b6 RH |
11154 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11155 | file_table.table = (char **) | |
11156 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11157 | } |
11158 | ||
71dfc51f | 11159 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11160 | file_table.table[i] = xstrdup (file_name); |
11161 | file_table.in_use = i + 1; | |
11162 | file_table.last_lookup_index = i; | |
2e18bbae | 11163 | |
acc187f5 RH |
11164 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11165 | fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name); | |
11166 | ||
2e18bbae RH |
11167 | return i; |
11168 | } | |
11169 | ||
11170 | static void | |
981975b6 | 11171 | init_file_table () |
2e18bbae RH |
11172 | { |
11173 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11174 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11175 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11176 | |
2e18bbae | 11177 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11178 | file_table.in_use = 1; |
11179 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11180 | } |
11181 | ||
11182 | /* Output a label to mark the beginning of a source code line entry | |
11183 | and record information relating to this source line, in | |
11184 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11185 | |
a3f97cbb | 11186 | void |
9a666dda | 11187 | dwarf2out_line (filename, line) |
d560ee52 | 11188 | register const char *filename; |
a3f97cbb JW |
11189 | register unsigned line; |
11190 | { | |
a3f97cbb JW |
11191 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11192 | { | |
11193 | function_section (current_function_decl); | |
a3f97cbb | 11194 | |
b2244e22 JW |
11195 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11196 | { | |
981975b6 | 11197 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11198 | |
981975b6 | 11199 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11200 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11201 | |
11202 | /* Indicate that line number info exists. */ | |
11203 | ++line_info_table_in_use; | |
11204 | ||
11205 | /* Indicate that multiple line number tables exist. */ | |
11206 | if (DECL_SECTION_NAME (current_function_decl)) | |
11207 | ++separate_line_info_table_in_use; | |
11208 | } | |
11209 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11210 | { |
e90b62db | 11211 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
11212 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11213 | separate_line_info_table_in_use); | |
ac260b05 | 11214 | if (flag_debug_asm) |
2e4b9b8c | 11215 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, |
00a42e21 | 11216 | filename, line); |
e90b62db JM |
11217 | |
11218 | /* expand the line info table if necessary */ | |
11219 | if (separate_line_info_table_in_use | |
11220 | == separate_line_info_table_allocated) | |
11221 | { | |
11222 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11223 | separate_line_info_table | |
71dfc51f RK |
11224 | = (dw_separate_line_info_ref) |
11225 | xrealloc (separate_line_info_table, | |
11226 | separate_line_info_table_allocated | |
11227 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11228 | } |
71dfc51f RK |
11229 | |
11230 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11231 | line_info |
11232 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11233 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11234 | line_info->dw_line_num = line; |
11235 | line_info->function = current_funcdef_number; | |
11236 | } | |
11237 | else | |
11238 | { | |
11239 | register dw_line_info_ref line_info; | |
71dfc51f | 11240 | |
5c90448c JM |
11241 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11242 | line_info_table_in_use); | |
ac260b05 | 11243 | if (flag_debug_asm) |
2e4b9b8c | 11244 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, |
00a42e21 | 11245 | filename, line); |
e90b62db | 11246 | |
71dfc51f | 11247 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11248 | if (line_info_table_in_use == line_info_table_allocated) |
11249 | { | |
11250 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11251 | line_info_table | |
71dfc51f RK |
11252 | = (dw_line_info_ref) |
11253 | xrealloc (line_info_table, | |
11254 | (line_info_table_allocated | |
11255 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11256 | } |
71dfc51f RK |
11257 | |
11258 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11259 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11260 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11261 | line_info->dw_line_num = line; |
a3f97cbb | 11262 | } |
a3f97cbb JW |
11263 | } |
11264 | } | |
11265 | ||
11266 | /* Record the beginning of a new source file, for later output | |
11267 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 11268 | |
a3f97cbb | 11269 | void |
9a666dda | 11270 | dwarf2out_start_source_file (filename) |
d560ee52 | 11271 | register const char *filename ATTRIBUTE_UNUSED; |
a3f97cbb | 11272 | { |
881c6935 JM |
11273 | if (flag_eliminate_dwarf2_dups) |
11274 | { | |
11275 | /* Record the beginning of the file for break_out_includes. */ | |
11276 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die); | |
11277 | add_AT_string (bincl_die, DW_AT_name, filename); | |
11278 | } | |
a3f97cbb JW |
11279 | } |
11280 | ||
9a666dda | 11281 | /* Record the end of a source file, for later output |
a3f97cbb | 11282 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 11283 | |
a3f97cbb | 11284 | void |
9a666dda | 11285 | dwarf2out_end_source_file () |
a3f97cbb | 11286 | { |
881c6935 JM |
11287 | if (flag_eliminate_dwarf2_dups) |
11288 | { | |
11289 | /* Record the end of the file for break_out_includes. */ | |
11290 | new_die (DW_TAG_GNU_EINCL, comp_unit_die); | |
0b34cf1e | 11291 | } |
a3f97cbb JW |
11292 | } |
11293 | ||
11294 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
11295 | the tail part of the directive line, i.e. the part which is past the | |
11296 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11297 | |
a3f97cbb | 11298 | void |
9a666dda | 11299 | dwarf2out_define (lineno, buffer) |
2618f955 | 11300 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11301 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11302 | { |
11303 | static int initialized = 0; | |
11304 | if (!initialized) | |
11305 | { | |
9a666dda | 11306 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
11307 | initialized = 1; |
11308 | } | |
11309 | } | |
11310 | ||
11311 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
11312 | the tail part of the directive line, i.e. the part which is past the | |
11313 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11314 | |
a3f97cbb | 11315 | void |
9a666dda | 11316 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 11317 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11318 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11319 | { |
11320 | } | |
11321 | ||
11322 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11323 | |
a3f97cbb | 11324 | void |
9a666dda | 11325 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb | 11326 | register FILE *asm_out_file; |
d3e3972c | 11327 | register const char *main_input_filename; |
a3f97cbb | 11328 | { |
acc187f5 RH |
11329 | init_file_table (); |
11330 | ||
a3f97cbb JW |
11331 | /* Remember the name of the primary input file. */ |
11332 | primary_filename = main_input_filename; | |
11333 | ||
acc187f5 RH |
11334 | /* Add it to the file table first, under the assumption that we'll |
11335 | be emitting line number data for it first, which avoids having | |
11336 | to add an initial DW_LNS_set_file. */ | |
11337 | lookup_filename (main_input_filename); | |
a3f97cbb | 11338 | |
a3f97cbb JW |
11339 | /* Allocate the initial hunk of the decl_die_table. */ |
11340 | decl_die_table | |
3de90026 | 11341 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11342 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11343 | decl_die_table_in_use = 0; | |
11344 | ||
11345 | /* Allocate the initial hunk of the decl_scope_table. */ | |
11346 | decl_scope_table | |
777ad4c2 | 11347 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
11348 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
11349 | decl_scope_depth = 0; | |
11350 | ||
11351 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11352 | abbrev_die_table | |
3de90026 RH |
11353 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11354 | sizeof (dw_die_ref)); | |
a3f97cbb | 11355 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11356 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11357 | abbrev_die_table_in_use = 1; |
11358 | ||
11359 | /* Allocate the initial hunk of the line_info_table. */ | |
11360 | line_info_table | |
3de90026 RH |
11361 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11362 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11363 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 11364 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11365 | line_info_table_in_use = 1; |
11366 | ||
556273e0 | 11367 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11368 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11369 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11370 | taken as being relative to the directory from which the compiler was |
11371 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11372 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11373 | |
1f8f4a0b MM |
11374 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11375 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11376 | |
5c90448c | 11377 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
11378 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
11379 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
11380 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11381 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11382 | else | |
11383 | strcpy (text_section_label, stripattributes (TEXT_SECTION)); | |
556273e0 | 11384 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11385 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11386 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 11387 | DEBUG_LINE_SECTION_LABEL, 0); |
9d2f2c45 RH |
11388 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0); |
11389 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); | |
63e46568 | 11390 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); |
9d2f2c45 | 11391 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
8b790721 | 11392 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
b366352b | 11393 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
a96c67ec JM |
11394 | { |
11395 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
11396 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11397 | } | |
8b790721 JM |
11398 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
11399 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); | |
11400 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
11401 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); | |
a3f97cbb JW |
11402 | } |
11403 | ||
11404 | /* Output stuff that dwarf requires at the end of every file, | |
11405 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 11406 | |
a3f97cbb | 11407 | void |
9a666dda | 11408 | dwarf2out_finish () |
a3f97cbb | 11409 | { |
ef76d03b JW |
11410 | limbo_die_node *node, *next_node; |
11411 | dw_die_ref die; | |
ef76d03b JW |
11412 | |
11413 | /* Traverse the limbo die list, and add parent/child links. The only | |
11414 | dies without parents that should be here are concrete instances of | |
11415 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
11416 | For concrete instances, we can get the parent die from the abstract | |
11417 | instance. */ | |
11418 | for (node = limbo_die_list; node; node = next_node) | |
11419 | { | |
11420 | next_node = node->next; | |
11421 | die = node->die; | |
11422 | ||
11423 | if (die->die_parent == NULL) | |
11424 | { | |
a96c67ec JM |
11425 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
11426 | if (origin) | |
11427 | add_child_die (origin->die_parent, die); | |
ef76d03b | 11428 | else if (die == comp_unit_die) |
a96c67ec | 11429 | ; |
ef76d03b JW |
11430 | else |
11431 | abort (); | |
11432 | } | |
11433 | free (node); | |
11434 | } | |
a96c67ec | 11435 | limbo_die_list = NULL; |
ef76d03b | 11436 | |
8a8c3656 JM |
11437 | /* Walk through the list of incomplete types again, trying once more to |
11438 | emit full debugging info for them. */ | |
11439 | retry_incomplete_types (); | |
11440 | ||
881c6935 JM |
11441 | /* We need to reverse all the dies before break_out_includes, or |
11442 | we'll see the end of an include file before the beginning. */ | |
11443 | reverse_all_dies (comp_unit_die); | |
11444 | ||
11445 | /* Generate separate CUs for each of the include files we've seen. | |
11446 | They will go into limbo_die_list. */ | |
5f632b5e JM |
11447 | if (flag_eliminate_dwarf2_dups) |
11448 | break_out_includes (comp_unit_die); | |
881c6935 JM |
11449 | |
11450 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
11451 | that have children. */ | |
a3f97cbb | 11452 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
11453 | for (node = limbo_die_list; node; node = node->next) |
11454 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
11455 | |
11456 | /* Output a terminator label for the .text section. */ | |
a3f97cbb | 11457 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); |
5c90448c | 11458 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 11459 | |
bdb669cb | 11460 | #if 0 |
a3f97cbb | 11461 | /* Output a terminator label for the .data section. */ |
a3f97cbb | 11462 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); |
5c90448c | 11463 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
11464 | |
11465 | /* Output a terminator label for the .bss section. */ | |
a3f97cbb | 11466 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); |
5c90448c | 11467 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 11468 | #endif |
a3f97cbb | 11469 | |
db3c0315 MM |
11470 | /* Output the source line correspondence table. We must do this |
11471 | even if there is no line information. Otherwise, on an empty | |
11472 | translation unit, we will generate a present, but empty, | |
11473 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
11474 | examining the file. */ | |
11475 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 11476 | { |
db3c0315 MM |
11477 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
11478 | output_line_info (); | |
11479 | } | |
71dfc51f | 11480 | |
db3c0315 MM |
11481 | /* We can only use the low/high_pc attributes if all of the code was |
11482 | in .text. */ | |
11483 | if (separate_line_info_table_in_use == 0) | |
11484 | { | |
11485 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
11486 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db JM |
11487 | } |
11488 | ||
fe7cd37f RH |
11489 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11490 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
11491 | debug_line_section_label); | |
db3c0315 | 11492 | |
a96c67ec JM |
11493 | #if 0 /* unimplemented */ |
11494 | if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary) | |
11495 | add_AT_unsigned (die, DW_AT_macro_info, 0); | |
11496 | #endif | |
11497 | ||
881c6935 JM |
11498 | /* Output all of the compilation units. We put the main one last so that |
11499 | the offsets are available to output_pubnames. */ | |
11500 | for (node = limbo_die_list; node; node = node->next) | |
11501 | output_comp_unit (node->die); | |
11502 | output_comp_unit (comp_unit_die); | |
11503 | ||
a3f97cbb | 11504 | /* Output the abbreviation table. */ |
9d2f2c45 | 11505 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
a3f97cbb JW |
11506 | output_abbrev_section (); |
11507 | ||
d291dd49 JM |
11508 | if (pubname_table_in_use) |
11509 | { | |
11510 | /* Output public names table. */ | |
9d2f2c45 | 11511 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
d291dd49 JM |
11512 | output_pubnames (); |
11513 | } | |
11514 | ||
e689ae67 JM |
11515 | /* We only put functions in the arange table, so don't write it out if |
11516 | we don't have any. */ | |
a3f97cbb JW |
11517 | if (fde_table_in_use) |
11518 | { | |
a3f97cbb | 11519 | /* Output the address range information. */ |
9d2f2c45 | 11520 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
a3f97cbb JW |
11521 | output_aranges (); |
11522 | } | |
63e46568 DB |
11523 | /* Output location list section if necessary */ |
11524 | if (have_location_lists) | |
11525 | { | |
11526 | /* Output the location lists info. */ | |
9d2f2c45 | 11527 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); |
63e46568 DB |
11528 | output_location_lists (die); |
11529 | have_location_lists = 0; | |
11530 | } | |
11531 | ||
a3f97cbb | 11532 | } |
9a666dda | 11533 | #endif /* DWARF2_DEBUGGING_INFO */ |